├── frontend ├── src │ ├── Header.js │ ├── assets │ │ ├── heroes.png │ │ └── logo.svg │ ├── services │ │ └── api.js │ ├── App.js │ ├── index.js │ ├── pages │ │ ├── Logon │ │ │ ├── styles.css │ │ │ └── index.js │ │ ├── NewIncident │ │ │ ├── styles.css │ │ │ └── index.js │ │ ├── Register │ │ │ ├── styles.css │ │ │ └── index.js │ │ └── Profile │ │ │ ├── styles.css │ │ │ └── index.js │ ├── routes.js │ └── global.css ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── .gitignore ├── package.json └── README.md ├── backend ├── .gitignore ├── src │ ├── server.js │ ├── database │ │ ├── db.sqlite │ │ ├── test.sqlite │ │ ├── connection.js │ │ └── migrations │ │ │ ├── 20200324114619_create_ongs.js │ │ │ └── 20200324115253_create_incidents.js │ ├── app.js │ ├── app │ │ └── validators │ │ │ ├── Sessions │ │ │ └── index.js │ │ │ ├── OngIncidents │ │ │ └── index.js │ │ │ ├── Ongs │ │ │ └── index.js │ │ │ └── Incidents │ │ │ └── index.js │ ├── controllers │ │ ├── ProfileController.js │ │ ├── SessionController.js │ │ ├── OngController.js │ │ └── IncidentController.js │ └── routes.js ├── .prettierrc ├── utils │ └── generateUniqueId.js ├── .editorconfig ├── tests │ ├── unit │ │ └── generateUniqueId.spec.js │ └── integration │ │ └── ong.spec.js ├── .eslintrc.js ├── package.json └── knexfile.js ├── .github ├── Desktop.gif ├── Mobile.gif ├── preview.jpg ├── week-11.png └── logo.svg ├── mobile ├── assets │ ├── icon.png │ └── splash.png ├── src │ ├── assets │ │ ├── logo.png │ │ ├── logo@2x.png │ │ └── logo@3x.png │ ├── services │ │ └── api.js │ ├── routes.js │ └── pages │ │ ├── Detail │ │ ├── styles.js │ │ └── index.js │ │ └── Incidents │ │ ├── styles.js │ │ └── index.js ├── babel.config.js ├── App.js ├── .expo-shared │ └── assets.json ├── .gitignore ├── app.json ├── package.json └── README.md ├── LICENSE.md ├── README.md └── Insomnia_2020-03-24.json /frontend/src/Header.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules -------------------------------------------------------------------------------- /backend/src/server.js: -------------------------------------------------------------------------------- 1 | const app = require('./app') 2 | 3 | app.listen(3333); -------------------------------------------------------------------------------- /.github/Desktop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/.github/Desktop.gif -------------------------------------------------------------------------------- /.github/Mobile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/.github/Mobile.gif -------------------------------------------------------------------------------- /.github/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/.github/preview.jpg -------------------------------------------------------------------------------- /.github/week-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/.github/week-11.png -------------------------------------------------------------------------------- /backend/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "es5", 4 | "semi": false 5 | } 6 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /mobile/assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/mobile/assets/icon.png -------------------------------------------------------------------------------- /mobile/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/mobile/assets/splash.png -------------------------------------------------------------------------------- /mobile/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/mobile/src/assets/logo.png -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/frontend/public/logo512.png -------------------------------------------------------------------------------- /mobile/src/assets/logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/mobile/src/assets/logo@2x.png -------------------------------------------------------------------------------- /mobile/src/assets/logo@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/mobile/src/assets/logo@3x.png -------------------------------------------------------------------------------- /backend/src/database/db.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/backend/src/database/db.sqlite -------------------------------------------------------------------------------- /frontend/src/assets/heroes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/frontend/src/assets/heroes.png -------------------------------------------------------------------------------- /backend/src/database/test.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielObara/SemanaOmnistack11/HEAD/backend/src/database/test.sqlite -------------------------------------------------------------------------------- /mobile/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function(api) { 2 | api.cache(true); 3 | return { 4 | presets: ['babel-preset-expo'], 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /mobile/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import Routes from "./src/routes"; 4 | 5 | export default function App() { 6 | return ; 7 | } 8 | -------------------------------------------------------------------------------- /frontend/src/services/api.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const api = axios.create({ 4 | baseURL: "http://localhost:3333" 5 | }); 6 | 7 | export default api; 8 | -------------------------------------------------------------------------------- /mobile/src/services/api.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const api = axios.create({ 4 | baseURL: "http://192.168.0.156:3333" 5 | }); 6 | 7 | export default api; 8 | -------------------------------------------------------------------------------- /backend/utils/generateUniqueId.js: -------------------------------------------------------------------------------- 1 | const crypto = require("crypto"); 2 | 3 | module.exports = function generateUniqueId() { 4 | return crypto.randomBytes(4).toString("HEX"); 5 | }; 6 | -------------------------------------------------------------------------------- /mobile/.expo-shared/assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "f9155ac790fd02fadcdeca367b02581c04a353aa6d5aa84409a59f6804c87acd": true, 3 | "89ed26367cdb9b771858e026f2eb95bfdb90e5ae943e716575327ec325f39c44": true 4 | } -------------------------------------------------------------------------------- /backend/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "./global.css"; 3 | 4 | import Routes from "./routes"; 5 | 6 | function App() { 7 | return ; 8 | } 9 | 10 | export default App; 11 | -------------------------------------------------------------------------------- /mobile/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/**/* 2 | .expo/* 3 | npm-debug.* 4 | *.jks 5 | *.p8 6 | *.p12 7 | *.key 8 | *.mobileprovision 9 | *.orig.* 10 | web-build/ 11 | web-report/ 12 | 13 | # macOS 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./App"; 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ); 11 | -------------------------------------------------------------------------------- /backend/src/app.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const cors = require("cors"); 3 | const routes = require("./routes"); 4 | 5 | const app = express(); 6 | app.use(cors()); 7 | app.use(express.json()); 8 | app.use(routes); 9 | 10 | 11 | module.exports = app; -------------------------------------------------------------------------------- /backend/src/app/validators/Sessions/index.js: -------------------------------------------------------------------------------- 1 | import { celebrate, Segments, Joi } from 'celebrate' 2 | 3 | export const create = () => { 4 | celebrate({ 5 | [Segments.BODY]: Joi.object().keys({ 6 | id: Joi.string().required(), 7 | }), 8 | }) 9 | } 10 | -------------------------------------------------------------------------------- /backend/src/database/connection.js: -------------------------------------------------------------------------------- 1 | const knex = require("knex"); 2 | const configuration = require("../../knexfile"); 3 | 4 | const config = 5 | process.env.NODE_ENV === "test" 6 | ? configuration.test 7 | : configuration.development; 8 | 9 | const connection = knex(config); 10 | 11 | module.exports = connection; 12 | -------------------------------------------------------------------------------- /backend/src/app/validators/OngIncidents/index.js: -------------------------------------------------------------------------------- 1 | import { celebrate, Segments, Joi } from 'celebrate' 2 | 3 | export const get = () => { 4 | celebrate({ 5 | [Segments.HEADERS]: Joi.object({ 6 | authorization: Joi.string().required(), 7 | }).unknown(), 8 | [Segments.QUERY]: Joi.object().keys({ 9 | page: Joi.number(), 10 | }), 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /backend/src/controllers/ProfileController.js: -------------------------------------------------------------------------------- 1 | const connection = require('../database/connection') 2 | 3 | module.exports = { 4 | async index(req, res) { 5 | const ong_id = req.headers.authorization 6 | const incidents = await connection('incidents') 7 | .where('ong_id', ong_id) 8 | .select('*') 9 | return res.json(incidents) 10 | }, 11 | } 12 | -------------------------------------------------------------------------------- /backend/tests/unit/generateUniqueId.spec.js: -------------------------------------------------------------------------------- 1 | /* This test should test whether the function 2 | returns a unique ID for each record 3 | * */ 4 | 5 | const generateUniqueId = require('../../utils/generateUniqueId') 6 | 7 | describe('Generate Unique ID', () => { 8 | it('should generate an unique ID', () => { 9 | const id = generateUniqueId() 10 | 11 | expect(id).toHaveLength(8) 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /backend/src/controllers/SessionController.js: -------------------------------------------------------------------------------- 1 | const connection = require("../database/connection"); 2 | 3 | module.exports = { 4 | async create(req, res) { 5 | const { id } = req.body; 6 | const ong = await connection("ongs") 7 | .where("id", id) 8 | .select("name") 9 | .first(); 10 | 11 | if (!ong) { 12 | return res.status(400).json({ error: "No ONG found with this ID" }); 13 | } 14 | 15 | return res.json(ong); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /backend/src/database/migrations/20200324114619_create_ongs.js: -------------------------------------------------------------------------------- 1 | exports.up = function(knex) { 2 | return knex.schema.createTable("ongs", function(table) { 3 | table.string("id").primary(); 4 | table.string("name").notNullable(); 5 | table.string("email").notNullable(); 6 | table.string("whatsapp").notNullable(); 7 | table.string("city").notNullable(); 8 | table.string("uf").notNullable(); 9 | }); 10 | }; 11 | 12 | exports.down = function(knex) { 13 | return knex.schema.dropTable("ongs"); 14 | }; 15 | -------------------------------------------------------------------------------- /frontend/src/pages/Logon/styles.css: -------------------------------------------------------------------------------- 1 | .logon-container { 2 | width: 100%; 3 | max-width: 1120px; 4 | height: 100vh; 5 | margin: 0 auto; 6 | display: flex; 7 | align-items: center; 8 | justify-content: space-between; 9 | } 10 | 11 | .logon-container section.form { 12 | width: 100%; 13 | max-width: 350px; 14 | margin-right: 30px; 15 | } 16 | 17 | .logon-container section.form form { 18 | margin-top: 100px; 19 | } 20 | 21 | .logon-container section.form form h1 { 22 | font-size: 32px; 23 | margin-bottom: 32px; 24 | } -------------------------------------------------------------------------------- /backend/src/database/migrations/20200324115253_create_incidents.js: -------------------------------------------------------------------------------- 1 | exports.up = function(knex) { 2 | return knex.schema.createTable("incidents", function(table) { 3 | table.increments(); 4 | table.string("title").notNullable(); 5 | table.string("description").notNullable(); 6 | table.decimal("value").notNullable(); 7 | 8 | table.string("ong_id").notNullable(); 9 | 10 | table 11 | .foreign("ong_id") 12 | .references("id") 13 | .inTable("ongs"); 14 | }); 15 | }; 16 | 17 | exports.down = function(knex) { 18 | return knex.schema.dropTable("incidents"); 19 | }; 20 | -------------------------------------------------------------------------------- /backend/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | es6: true, 4 | node: true, 5 | }, 6 | extends: ['airbnb-base', 'prettier'], 7 | plugins: ['prettier'], 8 | globals: { 9 | Atomics: 'readonly', 10 | SharedArrayBuffer: 'readonly', 11 | }, 12 | parserOptions: { 13 | ecmaVersion: 2018, 14 | sourceType: 'module', 15 | }, 16 | rules: { 17 | 'prettier/prettier': 'error', 18 | 'class-methods-use-this': 'off', 19 | 'no-param-reassign': 'off', 20 | camelcase: 'off', 21 | 'no-unused-vars': ['error', { argsIgnorePattern: 'next' }], 22 | semi: 'off', 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /backend/src/controllers/OngController.js: -------------------------------------------------------------------------------- 1 | const generateUniqueId = require('../../utils/generateUniqueId') 2 | 3 | const connection = require('../database/connection') 4 | 5 | module.exports = { 6 | async index(req, res) { 7 | const ongs = await connection('ongs').select('*') 8 | 9 | return res.json(ongs) 10 | }, 11 | 12 | async create(req, res) { 13 | const { name, email, whatsapp, city, uf } = req.body 14 | 15 | const id = generateUniqueId() 16 | 17 | await connection('ongs').insert({ 18 | id, 19 | name, 20 | email, 21 | whatsapp, 22 | city, 23 | uf, 24 | }) 25 | 26 | return res.json({ id }) 27 | }, 28 | } 29 | -------------------------------------------------------------------------------- /mobile/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "name": "Be the Hero", 4 | "slug": "bethehero", 5 | "privacy": "public", 6 | "sdkVersion": "36.0.0", 7 | "platforms": [ 8 | "ios", 9 | "android", 10 | "web" 11 | ], 12 | "version": "1.0.0", 13 | "orientation": "portrait", 14 | "icon": "./assets/icon.png", 15 | "splash": { 16 | "image": "./assets/splash.png", 17 | "resizeMode": "contain", 18 | "backgroundColor": "#E02041" 19 | }, 20 | "updates": { 21 | "fallbackToCacheTimeout": 0 22 | }, 23 | "assetBundlePatterns": [ 24 | "**/*" 25 | ], 26 | "ios": { 27 | "supportsTablet": true 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mobile/src/routes.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import { NavigationContainer } from "@react-navigation/native"; 4 | import { createStackNavigator } from "@react-navigation/stack"; 5 | 6 | const AppStack = createStackNavigator(); 7 | 8 | import Incidents from "./pages/Incidents"; 9 | import Detail from "./pages/Detail"; 10 | 11 | export default function Routes() { 12 | return ( 13 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /frontend/src/routes.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { BrowserRouter, Route, Switch } from "react-router-dom"; 3 | 4 | import Logon from "./pages/Logon"; 5 | import Register from "./pages/Register"; 6 | import Profile from "./pages/Profile"; 7 | import NewIncident from "./pages/NewIncident"; 8 | 9 | export default function Routes() { 10 | return ( 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /backend/src/app/validators/Ongs/index.js: -------------------------------------------------------------------------------- 1 | const { celebrate, Segments, Joi } = requite('celebrate') 2 | 3 | module.exports = { 4 | get (){ 5 | celebrate({ 6 | [Segments.QUERY]: Joi.object().keys({ 7 | page: Joi.number(), 8 | }), 9 | }) 10 | }, 11 | 12 | show = () => { 13 | celebrate({ 14 | [Segments.QUERY]: Joi.object().keys({ 15 | id: Joi.string().required(), 16 | }), 17 | }) 18 | }, 19 | 20 | create = () => { 21 | celebrate({ 22 | [Segments.BODY]: Joi.object().keys({ 23 | name: Joi.string().required(), 24 | email: Joi.string().required().email(), 25 | whatsapp: Joi.string().required().min(10).max(11), 26 | city: Joi.string().required(), 27 | uf: Joi.string().required().length(2), 28 | }), 29 | }) 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /backend/tests/integration/ong.spec.js: -------------------------------------------------------------------------------- 1 | const request = require('supertest') 2 | const app = require('../../src/app') 3 | const connection = require('../../src/database/connection') 4 | 5 | /* eslint-disable no-undef */ 6 | describe('ONG', () => { 7 | beforeEach(async () => { 8 | await connection.migrate.rollback() 9 | await connection.migrate.latest() 10 | }) 11 | 12 | afterAll(async () => { 13 | await connection.destroy() 14 | }) 15 | it('should be able to create a new ONG', async () => { 16 | const response = await request(app).post('/ongs').send({ 17 | name: 'Test', 18 | email: 'test@test.com.jp', 19 | whatsapp: '00000000000', 20 | city: 'Okazaki', 21 | uf: 'JP', 22 | }) 23 | 24 | expect(response.body).toHaveProperty('id') 25 | expect(response.body.id).toHaveLength(8) 26 | }) 27 | }) 28 | -------------------------------------------------------------------------------- /backend/src/routes.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | 3 | const OngController = require('./controllers/OngController') 4 | const IncidentController = require('./controllers/IncidentController') 5 | const ProfileController = require('./controllers/ProfileController') 6 | const SessionController = require('./controllers/SessionController') 7 | 8 | const routes = express.Router() 9 | 10 | routes.post('/sessions', SessionController.create) 11 | 12 | routes.get('/ongs', OngController.index) 13 | routes.post('/ongs', OngController.create) 14 | 15 | routes.get('/incidents', IncidentController.index) 16 | routes.get('/incidents/:id', IncidentController.show) 17 | routes.post('/incidents', IncidentController.create) 18 | routes.delete('/incidents/:id', IncidentController.delete) 19 | 20 | routes.get('/profile', ProfileController.index) 21 | 22 | module.exports = routes 23 | -------------------------------------------------------------------------------- /backend/src/app/validators/Incidents/index.js: -------------------------------------------------------------------------------- 1 | const { celebrate, Segments, Joi } = require('celebrate') 2 | 3 | export const store = () => { 4 | celebrate({ 5 | [Segments.BODY]: Joi.object().keys({ 6 | title: Joi.string().min(3).required(), 7 | description: Joi.string().min(10).required(), 8 | value: Joi.number().required(), 9 | }), 10 | [Segments.HEADERS]: Joi.object({ 11 | authorization: Joi.string().required(), 12 | }).unknown(), 13 | }) 14 | } 15 | 16 | export const get = () => { 17 | celebrate({ 18 | [Segments.QUERY]: Joi.object().keys({ 19 | page: Joi.number(), 20 | }), 21 | }) 22 | } 23 | 24 | export const show = () => { 25 | celebrate({ 26 | [Segments.PARAMS]: Joi.object().keys({ 27 | id: Joi.string().required(), 28 | }), 29 | }) 30 | } 31 | 32 | export const del = () => { 33 | celebrate({ 34 | [Segments.PARAMS]: Joi.object().keys({ 35 | id: Joi.number().required(), 36 | }), 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "axios": "^0.19.2", 10 | "react": "^16.13.1", 11 | "react-dom": "^16.13.1", 12 | "react-icons": "^3.9.0", 13 | "react-router-dom": "^5.1.2", 14 | "react-scripts": "3.4.1" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /frontend/src/pages/NewIncident/styles.css: -------------------------------------------------------------------------------- 1 | .new-incident-container { 2 | width: 100%; 3 | max-width: 1120px; 4 | height: 100vh; 5 | margin: 0 auto; 6 | display: flex; 7 | align-items: center; 8 | justify-content: center; 9 | } 10 | 11 | .new-incident-container .content { 12 | width: 100%; 13 | padding: 96px; 14 | background: #f0f0f5; 15 | box-shadow: 0 0 100px rgba(0, 0, 0, 0.1); 16 | display: flex; 17 | justify-content: space-between; 18 | align-items: center; 19 | } 20 | 21 | .new-incident-container .content section { 22 | width: 100%; 23 | max-width: 380px; 24 | } 25 | 26 | .new-incident-container .content section h1 { 27 | margin: 64px 0 32px; 28 | font-size: 32px; 29 | } 30 | 31 | .new-incident-container .content section p { 32 | font-size: 18px; 33 | color: #737380; 34 | line-height: 32px; 35 | } 36 | 37 | .new-incident-container .content form { 38 | width: 100%; 39 | max-width: 450px; 40 | } 41 | 42 | .new-incident-container .content form input, .new-incident-container .content form textarea { 43 | margin-top: 8px; 44 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rocketseat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "dev": "nodemon src/server.js", 8 | "test": "cross-env NODE_ENV=test jest" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/DanielObara/SemanaOmnistack11.git" 13 | }, 14 | "author": "Daniel Tsutomu Obara ", 15 | "homepage": "https://github.com/DanielObara/SemanaOmnistack11#readme", 16 | "dependencies": { 17 | "axios": "^0.19.2", 18 | "celebrate": "^12.0.1", 19 | "cors": "^2.8.5", 20 | "cross-env": "^7.0.2", 21 | "express": "^4.17.1", 22 | "knex": "^0.20.13", 23 | "sqlite3": "^4.1.1" 24 | }, 25 | "devDependencies": { 26 | "eslint": "^6.8.0", 27 | "eslint-config-airbnb-base": "^14.1.0", 28 | "eslint-config-prettier": "^6.10.1", 29 | "eslint-plugin-import": "^2.20.2", 30 | "eslint-plugin-prettier": "^3.1.2", 31 | "jest": "^25.2.4", 32 | "prettier": "^2.0.2", 33 | "nodemon": "^2.0.2", 34 | "supertest": "^4.0.2" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mobile/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "node_modules/expo/AppEntry.js", 3 | "scripts": { 4 | "start": "expo start", 5 | "android": "expo start --android", 6 | "ios": "expo start --ios", 7 | "web": "expo start --web", 8 | "eject": "expo eject" 9 | }, 10 | "dependencies": { 11 | "@react-native-community/masked-view": "0.1.5", 12 | "@react-navigation/native": "^5.1.3", 13 | "@react-navigation/stack": "^5.2.7", 14 | "axios": "^0.19.2", 15 | "expo": "~36.0.0", 16 | "expo-constants": "^9.0.0", 17 | "expo-mail-composer": "^8.1.0", 18 | "intl": "^1.2.5", 19 | "react": "~16.9.0", 20 | "react-dom": "~16.9.0", 21 | "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz", 22 | "react-native-gesture-handler": "~1.5.0", 23 | "react-native-reanimated": "~1.4.0", 24 | "react-native-safe-area-context": "0.6.0", 25 | "react-native-screens": "2.0.0-alpha.12", 26 | "react-native-web": "~0.11.7" 27 | }, 28 | "devDependencies": { 29 | "@babel/core": "^7.0.0", 30 | "babel-preset-expo": "~8.0.0" 31 | }, 32 | "private": true 33 | } 34 | -------------------------------------------------------------------------------- /frontend/src/pages/Register/styles.css: -------------------------------------------------------------------------------- 1 | .register-container { 2 | width: 100%; 3 | max-width: 1120px; 4 | height: 100vh; 5 | margin: 0 auto; 6 | display: flex; 7 | align-items: center; 8 | justify-content: center; 9 | } 10 | 11 | .register-container .content { 12 | width: 100%; 13 | padding: 96px; 14 | background: #f0f0f5; 15 | box-shadow: 0 0 100px rgba(0, 0, 0, 0.1); 16 | display: flex; 17 | justify-content: space-between; 18 | align-items: center; 19 | } 20 | 21 | .register-container .content section { 22 | width: 100%; 23 | max-width: 380px; 24 | } 25 | 26 | .register-container .content section h1 { 27 | margin: 64px 0 32px; 28 | font-size: 32px; 29 | } 30 | 31 | .register-container .content section p { 32 | font-size: 18px; 33 | color: #737380; 34 | line-height: 32px; 35 | } 36 | 37 | .register-container .content form { 38 | width: 100%; 39 | max-width: 450px; 40 | } 41 | 42 | .register-container .content form input { 43 | margin-top: 8px; 44 | } 45 | 46 | .register-container .content .input-group { 47 | display: flex; 48 | } 49 | 50 | .register-container .content .input-group input+input { 51 | margin-left: 8px; 52 | } -------------------------------------------------------------------------------- /backend/knexfile.js: -------------------------------------------------------------------------------- 1 | // Update with your config settings. 2 | 3 | module.exports = { 4 | development: { 5 | client: "sqlite3", 6 | connection: { 7 | filename: "./src/database/db.sqlite" 8 | }, 9 | migrations: { 10 | directory: "./src/database/migrations" 11 | }, 12 | useNullAsDefault: true 13 | }, 14 | 15 | test: { 16 | client: "sqlite3", 17 | connection: { 18 | filename: "./src/database/test.sqlite" 19 | }, 20 | migrations: { 21 | directory: "./src/database/migrations" 22 | }, 23 | useNullAsDefault: true 24 | }, 25 | 26 | staging: { 27 | client: "postgresql", 28 | connection: { 29 | database: "my_db", 30 | user: "username", 31 | password: "password" 32 | }, 33 | pool: { 34 | min: 2, 35 | max: 10 36 | }, 37 | migrations: { 38 | tableName: "knex_migrations" 39 | } 40 | }, 41 | 42 | production: { 43 | client: "postgresql", 44 | connection: { 45 | database: "my_db", 46 | user: "username", 47 | password: "password" 48 | }, 49 | pool: { 50 | min: 2, 51 | max: 10 52 | }, 53 | migrations: { 54 | tableName: "knex_migrations" 55 | } 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /mobile/src/pages/Detail/styles.js: -------------------------------------------------------------------------------- 1 | import { 2 | StyleSheet 3 | } 4 | 5 | from "react-native"; 6 | import Constants from "expo-constants"; 7 | export default StyleSheet.create( { 8 | container: { 9 | flex: 1, paddingHorizontal: 24, paddingTop: Constants.statusBarHeight + 20 10 | } 11 | , header: { 12 | flexDirection: "row", justifyContent: "space-between", alignItems: "center" 13 | } 14 | , incident: { 15 | padding: 24, borderRadius: 8, backgroundColor: "#FFF", marginBottom: 16, marginTop: 48 16 | } 17 | , incidentProperty: { 18 | fontSize: 14, color: "#41414d", fontWeight: "bold", marginTop: 24 19 | } 20 | , incidentValue: { 21 | marginTop: 8, fontSize: 15, color: "#737380" 22 | } 23 | , contactBox: { 24 | padding: 24, borderRadius: 8, backgroundColor: "#FFF", marginBottom: 16 25 | } 26 | , heroTitle: { 27 | fontWeight: "bold", fontSize: 20, color: "#13131a", lineHeight: 30 28 | } 29 | , heroDescription: { 30 | fontSize: 15, color: "#737380", marginTop: 16 31 | } 32 | , actions: { 33 | marginTop: 16, flexDirection: "row", justifyContent: "space-between" 34 | } 35 | , action: { 36 | backgroundColor: "#e02041", borderRadius: 8, height: 50, width: "48%", justifyContent: "center", alignItems: "center" 37 | } 38 | , actionText: { 39 | color: "#FFF", fontSize: 15, fontWeight: "bold" 40 | } 41 | } 42 | 43 | ); -------------------------------------------------------------------------------- /mobile/src/pages/Incidents/styles.js: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from "react-native"; 2 | import Constants from "expo-constants"; 3 | 4 | export default StyleSheet.create({ 5 | container: { 6 | flex: 1, 7 | paddingHorizontal: 24, 8 | paddingTop: Constants.statusBarHeight + 20 9 | }, 10 | 11 | header: { 12 | flexDirection: "row", 13 | justifyContent: "space-between", 14 | alignItems: "center" 15 | }, 16 | 17 | headerText: { 18 | fontSize: 15, 19 | color: "#737380" 20 | }, 21 | 22 | headerTextBold: { 23 | fontWeight: "bold" 24 | }, 25 | 26 | title: { 27 | fontSize: 30, 28 | marginBottom: 16, 29 | marginTop: 48, 30 | color: "#13131a", 31 | fontWeight: "bold" 32 | }, 33 | 34 | description: { 35 | fontSize: 16, 36 | lineHeight: 24, 37 | color: "#737380" 38 | }, 39 | 40 | incidentList: { 41 | marginTop: 32 42 | }, 43 | 44 | incident: { 45 | padding: 24, 46 | borderRadius: 8, 47 | backgroundColor: "#FFF", 48 | marginBottom: 16 49 | }, 50 | 51 | incidentProperty: { 52 | fontSize: 14, 53 | color: "#41414d", 54 | fontWeight: "bold" 55 | }, 56 | 57 | incidentValue: { 58 | marginTop: 8, 59 | fontSize: 15, 60 | marginBottom: 24, 61 | color: "#737380" 62 | }, 63 | 64 | detailsButton: { 65 | flexDirection: "row", 66 | justifyContent: "space-between", 67 | alignItems: "center" 68 | }, 69 | 70 | detailsButtonText: { 71 | color: "#e02041", 72 | fontSize: 15, 73 | fontWeight: "bold" 74 | } 75 | }); 76 | -------------------------------------------------------------------------------- /frontend/src/global.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap"); 2 | * { 3 | margin: 0; 4 | padding: 0; 5 | outline: 0; 6 | box-sizing: border-box; 7 | } 8 | 9 | body { 10 | font: 400 14px Roboto, sans-serif; 11 | background: #f0f0f5; 12 | -webkit-font-smoothing: antialiased; 13 | } 14 | 15 | input, button, textarea { 16 | font: 400 18px Roboto, sans-serif; 17 | } 18 | 19 | button { 20 | cursor: pointer; 21 | } 22 | 23 | form input { 24 | width: 100%; 25 | height: 60px; 26 | color: #333; 27 | border: 1px solid #dcdce6; 28 | border-radius: 8px; 29 | padding: 0 24px; 30 | } 31 | 32 | form textarea { 33 | width: 100%; 34 | height: 140px; 35 | color: #333; 36 | border: 1px solid #dcdce6; 37 | border-radius: 8px; 38 | padding: 16px 24px; 39 | line-height: 24px; 40 | } 41 | 42 | .button { 43 | width: 100%; 44 | height: 60px; 45 | background: #e02041; 46 | border: 0; 47 | border-radius: 8px; 48 | color: #fff; 49 | font-weight: 700; 50 | margin-top: 16px; 51 | display: inline-block; 52 | text-align: center; 53 | text-decoration: none; 54 | font-size: 18px; 55 | line-height: 60px; 56 | transition: ease 0.2s; 57 | } 58 | 59 | .button:hover { 60 | filter: brightness(90%); 61 | } 62 | 63 | .back-link { 64 | display: flex; 65 | align-items: center; 66 | margin-top: 40px; 67 | color: #41414d; 68 | font-size: 18px; 69 | text-decoration: none; 70 | font-weight: 500; 71 | transition: opacity 0.2s; 72 | } 73 | 74 | .back-link svg { 75 | margin-right: 8px; 76 | } 77 | 78 | .back-link:hover { 79 | opacity: 0.8; 80 | } -------------------------------------------------------------------------------- /frontend/src/pages/Profile/styles.css: -------------------------------------------------------------------------------- 1 | .profile-container { 2 | width: 100%; 3 | max-width: 1180px; 4 | padding: 0 30px; 5 | margin: 32px auto; 6 | } 7 | 8 | .profile-container header { 9 | display: flex; 10 | align-items: center; 11 | } 12 | 13 | .profile-container header span { 14 | font-size: 20px; 15 | margin-left: 24px; 16 | } 17 | 18 | .profile-container header a { 19 | width: 260px; 20 | margin-left: auto; 21 | margin-top: 0; 22 | } 23 | 24 | .profile-container header button { 25 | width: 60px; 26 | height: 60px; 27 | border-radius: 4px; 28 | border: 1px solid #dcdce6; 29 | background: transparent; 30 | margin-left: 16px; 31 | } 32 | 33 | .profile-container header button:hover { 34 | border-color: #999; 35 | } 36 | 37 | .profile-container h1 { 38 | margin-top: 80px; 39 | margin-bottom: 24px; 40 | } 41 | 42 | .profile-container ul { 43 | display: grid; 44 | grid-template-columns: repeat(2, 1fr); 45 | grid-gap: 24px; 46 | list-style: none; 47 | } 48 | 49 | .profile-container ul li { 50 | background: #fff; 51 | padding: 24px; 52 | border-radius: 8px; 53 | position: relative; 54 | } 55 | 56 | .profile-container ul li button { 57 | position: absolute; 58 | right: 24px; 59 | top: 24px; 60 | border: 0; 61 | } 62 | 63 | .profile-container ul li button:hover { 64 | opacity: 0.8; 65 | } 66 | 67 | .profile-container ul li strong { 68 | display: block; 69 | margin-bottom: 16px; 70 | color: #41414d; 71 | } 72 | 73 | .profile-container ul li p+strong { 74 | margin-top: 32px; 75 | } 76 | 77 | .profile-container ul li p { 78 | color: #737380; 79 | line-height: 21px; 80 | font-size: 16px; 81 | } -------------------------------------------------------------------------------- /frontend/src/pages/Logon/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { Link, useHistory } from "react-router-dom"; 3 | import { FiLogIn } from "react-icons/fi"; 4 | 5 | import heroesImg from "../../assets/heroes.png"; 6 | import logoImg from "../../assets/logo.svg"; 7 | import api from "../../services/api"; 8 | 9 | import "./styles.css"; 10 | 11 | export default function Logon() { 12 | const [id, setId] = useState(""); 13 | 14 | const history = useHistory(); 15 | 16 | async function handleLogin(e) { 17 | e.preventDefault(); 18 | 19 | try { 20 | const response = await api.post("/sessions", { id }); 21 | 22 | localStorage.setItem("ongId", id); 23 | localStorage.setItem("ongName", response.data.name); 24 | 25 | history.push("/profile"); 26 | } catch (err) { 27 | console.log(err); 28 | alert("Falha no login, tente novamente."); 29 | } 30 | } 31 | return ( 32 |
33 |
34 | Be The Hero 35 | 36 |
37 |

Faça seu logon

38 | 39 | setId(e.target.value)} 43 | /> 44 | 47 | 48 | 49 | Não tenho cadastro 50 | 51 | 52 |
53 | Heroes 54 |
55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /backend/src/controllers/IncidentController.js: -------------------------------------------------------------------------------- 1 | const connection = require('../database/connection') 2 | 3 | module.exports = { 4 | async index(request, response) { 5 | const { page = 1 } = request.query 6 | const [count] = await connection('incidents').count() 7 | const incidents = await connection('incidents') 8 | .join('ongs', 'ongs.id', '=', 'incidents.ong_id') 9 | .limit(5) 10 | .offset((page - 1) * 5) 11 | .select([ 12 | 'incidents.*', 13 | 'ongs.name', 14 | 'ongs.email', 15 | 'ongs.whatsapp', 16 | 'ongs.city', 17 | 'ongs.uf', 18 | ]) 19 | 20 | response.header('X-Total-Count', count['count(*)']) 21 | return response.json(incidents) 22 | }, 23 | 24 | async show(request, response) { 25 | const { id } = request.params 26 | const incident = await connection('incidents').where('id', id).first() 27 | 28 | if (!incident) { 29 | return response.status(404).json({ 30 | error: { 31 | message: 'Incident not found', 32 | }, 33 | }) 34 | } 35 | 36 | return response.json(incident) 37 | }, 38 | 39 | async create(request, response) { 40 | const { title, description, value } = request.body 41 | 42 | const ong_id = request.headers.authorization 43 | 44 | const [id] = await connection('incidents').insert({ 45 | title, 46 | description, 47 | value, 48 | ong_id, 49 | }) 50 | 51 | return response.json({ id }) 52 | }, 53 | 54 | async delete(request, response) { 55 | const { id } = request.params 56 | 57 | const ong_id = request.headers.authorization 58 | 59 | const incident = await connection('incidents') 60 | .where('id', id) 61 | .select('ong_id') 62 | .first() 63 | 64 | if (!incident) response.status(404).json({ error: 'Incident not found' }) 65 | 66 | if (incident.ong_id !== ong_id) 67 | response.status(401).json({ error: 'Operation not permitted' }) 68 | 69 | await connection('incidents').where('id', id).delete() 70 | 71 | return response 72 | .status(200) 73 | .send({ msg: 'Incident was successfully deleted' }) 74 | }, 75 | } 76 | -------------------------------------------------------------------------------- /frontend/src/pages/NewIncident/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { Link, useHistory } from "react-router-dom"; 3 | import { FiArrowLeft } from "react-icons/fi"; 4 | 5 | import api from "../../services/api"; 6 | 7 | import "./styles.css"; 8 | 9 | import logoImg from "../../assets/logo.svg"; 10 | 11 | export default function NewIncident() { 12 | const [title, setTitle] = useState(""); 13 | const [description, setDescription] = useState(""); 14 | const [value, setValue] = useState(""); 15 | 16 | const ongId = localStorage.getItem("ongId"); 17 | 18 | const history = useHistory(); 19 | 20 | async function handleNewIncident(e) { 21 | e.preventDefault(); 22 | 23 | const data = { 24 | title, 25 | description, 26 | value 27 | }; 28 | 29 | try { 30 | await api.post("/incidents", data, { 31 | headers: { Authorization: ongId } 32 | }); 33 | 34 | history.push("/profile"); 35 | } catch (err) { 36 | console.log(err); 37 | alert("Erro no cadastro, tente novamente"); 38 | } 39 | } 40 | return ( 41 |
42 |
43 |
44 | Be The Hero 45 |

Cadastrar novo caso

46 |

47 | Descreva o caso detalhadamente para encontrar um herói para resolver 48 | isso. 49 |

50 | 51 | 52 | 53 | Voltar para home 54 | 55 |
56 | 57 |
58 | setTitle(e.target.value)} 62 | /> 63 |