diff --git a/api/.env.example b/api/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/api/nodemon.json b/api/nodemon.json index c0cfcfa..73656a9 100644 --- a/api/nodemon.json +++ b/api/nodemon.json @@ -1,5 +1,5 @@ { - "watch": ["."], + "watch": ["src"], "ext": "ts", - "exec": "ts-node ./index.ts" + "exec": "ts-node src/server.ts" } diff --git a/api/package.json b/api/package.json index edb8078..4aea1a4 100644 --- a/api/package.json +++ b/api/package.json @@ -4,9 +4,9 @@ "description": "Simple Rest API for manage the project", "main": "index.js", "scripts": { + "dev": "nodemon src/server.ts", "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon", - "tsc": "tsc" + "build": "tsc -p src" }, "repository": { "type": "git", diff --git a/api/src/app.ts b/api/src/app.ts new file mode 100644 index 0000000..4f5dcd1 --- /dev/null +++ b/api/src/app.ts @@ -0,0 +1,26 @@ +import express from 'express'; + +import AuthRoutes from './routes/auth.route'; +import UsersRoutes from './routes/users.route'; + +class App { + public express: express.Application; + + public constructor() { + this.express = express(); + + this.middlewares(); + this.routes(); + } + + private middlewares(): void { + this.express.use(express.json()); + } + + private routes(): void { + this.express.use('/', AuthRoutes.router); + this.express.use('/api/user', UsersRoutes.router); + } +} + +export default new App().express; \ No newline at end of file diff --git a/api/src/controllers/auth.controller.ts b/api/src/controllers/auth.controller.ts new file mode 100644 index 0000000..070e4e2 --- /dev/null +++ b/api/src/controllers/auth.controller.ts @@ -0,0 +1,11 @@ +import { Request, Response } from 'express'; + +class AuthController { + public async token(req: Request, res: Response): Promise { + const a = req.body; + + return res.send("Send your credentials"); + } +} + +export default new AuthController(); diff --git a/api/src/controllers/users.controller.ts b/api/src/controllers/users.controller.ts new file mode 100644 index 0000000..e3ad1a2 --- /dev/null +++ b/api/src/controllers/users.controller.ts @@ -0,0 +1,12 @@ +import { Request, Response } from 'express'; + +class UsersController { + /** + * Usual names for CRUD methods are: index, store, update, delete + */ + public async index(_req: Request, res: Response): Promise { + return res.send("Hellow world"); + } +} + +export default new UsersController(); diff --git a/api/src/routes/auth.route.ts b/api/src/routes/auth.route.ts new file mode 100644 index 0000000..c0dd0a1 --- /dev/null +++ b/api/src/routes/auth.route.ts @@ -0,0 +1,19 @@ +import { Router } from 'express'; + +import AuthController from '../controllers/auth.controller'; + +class AuthRoutes { + public router: Router; + public authController = AuthController; + + constructor() { + this.router = Router(); + this.routes(); + } + + private routes() { + this.router.post('/token', AuthController.token); + } +} + +export default new AuthRoutes(); \ No newline at end of file diff --git a/api/src/routes/users.route.ts b/api/src/routes/users.route.ts new file mode 100644 index 0000000..abe0b86 --- /dev/null +++ b/api/src/routes/users.route.ts @@ -0,0 +1,19 @@ +import { Router } from 'express'; + +import UsersController from '../controllers/users.controller'; + +class UsersRoutes { + public router: Router; + public usersController = UsersController; + + constructor() { + this.router = Router(); + this.routes(); + } + + private routes() { + this.router.get('/', UsersController.index); + } +} + +export default new UsersRoutes(); \ No newline at end of file diff --git a/api/src/server.ts b/api/src/server.ts new file mode 100644 index 0000000..f6030a9 --- /dev/null +++ b/api/src/server.ts @@ -0,0 +1,3 @@ +import app from './app'; + +app.listen(process.env.PORT || 3333); \ No newline at end of file diff --git a/api/src/services/auth/interfaces/auth.interface.ts b/api/src/services/auth/interfaces/auth.interface.ts new file mode 100644 index 0000000..e69de29 diff --git a/api/tsconfig.json b/api/tsconfig.json index e259c99..05a55f5 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -12,7 +12,7 @@ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - // "outDir": "./", /* Redirect output structure to the directory. */ + "outDir": "./dist", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ @@ -24,7 +24,7 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ @@ -33,10 +33,10 @@ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + "noUnusedLocals": true, /* Report errors on unused locals. */ + "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ /* Module Resolution Options */ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ @@ -62,5 +62,11 @@ /* Advanced Options */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ - } + }, + "include": [ + "./src/" + ], + "exclude": [ + "node_modules" + ] }