typescript-express-starter 9.1.2 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/configurationCache.log +1 -0
- package/.vscode/dryrun.log +6 -0
- package/.vscode/settings.json +3 -0
- package/.vscode/targets.log +239 -0
- package/CONTRIBUTORS.md +61 -0
- package/README.kr.md +122 -161
- package/README.md +118 -157
- package/bin/cli.js +1 -1
- package/lib/default/.swcrc +0 -3
- package/lib/default/Dockerfile.dev +18 -0
- package/lib/default/Dockerfile.prod +18 -0
- package/lib/default/Makefile +29 -16
- package/lib/default/docker-compose.yml +8 -8
- package/lib/default/jest.config.js +1 -1
- package/lib/default/package.json +42 -40
- package/lib/default/src/app.ts +4 -5
- package/lib/default/src/controllers/auth.controller.ts +9 -11
- package/lib/default/src/controllers/users.controller.ts +11 -13
- package/lib/default/src/dtos/users.dto.ts +12 -1
- package/lib/default/src/interfaces/users.interface.ts +2 -2
- package/lib/default/src/middlewares/auth.middleware.ts +16 -10
- package/lib/default/src/middlewares/error.middleware.ts +2 -4
- package/lib/default/src/middlewares/validation.middleware.ts +22 -20
- package/lib/default/src/models/users.model.ts +6 -8
- package/lib/default/src/routes/auth.route.ts +8 -11
- package/lib/default/src/routes/users.route.ts +10 -12
- package/lib/default/src/server.ts +6 -7
- package/lib/default/src/services/auth.service.ts +25 -36
- package/lib/default/src/services/users.service.ts +20 -29
- package/lib/{graphql/src/tests → default/src/test}/auth.test.ts +21 -21
- package/lib/default/src/test/users.test.ts +62 -0
- package/lib/default/src/utils/validateEnv.ts +1 -3
- package/lib/default/tsconfig.json +1 -1
- package/lib/graphql/.env.development.local +6 -6
- package/lib/graphql/.env.production.local +6 -6
- package/lib/graphql/.env.test.local +6 -6
- package/lib/graphql/.swcrc +1 -1
- package/lib/graphql/Dockerfile.dev +19 -0
- package/lib/graphql/Dockerfile.prod +19 -0
- package/lib/graphql/Makefile +32 -15
- package/lib/graphql/docker-compose.yml +23 -15
- package/lib/graphql/jest.config.js +1 -1
- package/lib/graphql/package.json +42 -41
- package/lib/graphql/src/app.ts +14 -13
- package/lib/graphql/src/config/index.ts +2 -2
- package/lib/{typeorm/src/databases → graphql/src/database}/index.ts +6 -6
- package/lib/graphql/src/dtos/users.dto.ts +14 -1
- package/lib/graphql/src/interfaces/users.interface.ts +2 -2
- package/lib/graphql/src/middlewares/auth.middleware.ts +16 -6
- package/lib/graphql/src/middlewares/error.middleware.ts +2 -4
- package/lib/graphql/src/repositories/auth.repository.ts +19 -27
- package/lib/graphql/src/repositories/users.repository.ts +9 -18
- package/lib/graphql/src/resolvers/auth.resolver.ts +2 -2
- package/lib/graphql/src/resolvers/users.resolver.ts +4 -4
- package/lib/graphql/src/server.ts +6 -7
- package/lib/graphql/src/test/auth.test.ts +10 -0
- package/lib/graphql/src/test/users.test.ts +11 -0
- package/lib/graphql/src/typedefs/users.type.ts +2 -2
- package/lib/graphql/src/utils/logger.ts +2 -0
- package/lib/graphql/src/utils/validateEnv.ts +1 -3
- package/lib/graphql/tsconfig.json +2 -2
- package/lib/knex/.env.development.local +2 -2
- package/lib/knex/.env.production.local +3 -3
- package/lib/knex/.env.test.local +3 -3
- package/lib/knex/.swcrc +1 -1
- package/lib/knex/Dockerfile.dev +19 -0
- package/lib/knex/Dockerfile.prod +19 -0
- package/lib/knex/Makefile +32 -15
- package/lib/knex/docker-compose.yml +19 -14
- package/lib/knex/jest.config.js +1 -1
- package/lib/knex/knexfile.ts +8 -8
- package/lib/knex/package.json +44 -42
- package/lib/knex/src/app.ts +6 -7
- package/lib/knex/src/config/index.ts +2 -1
- package/lib/knex/src/controllers/auth.controller.ts +9 -11
- package/lib/knex/src/controllers/users.controller.ts +10 -12
- package/lib/knex/src/{databases → database}/index.ts +4 -4
- package/lib/knex/src/database/migrations/20210713110926_initial.ts +17 -0
- package/lib/knex/src/dtos/users.dto.ts +12 -1
- package/lib/knex/src/interfaces/users.interface.ts +2 -2
- package/lib/knex/src/middlewares/auth.middleware.ts +17 -10
- package/lib/knex/src/middlewares/error.middleware.ts +2 -4
- package/lib/knex/src/middlewares/validation.middleware.ts +22 -20
- package/lib/knex/src/models/users.model.ts +2 -2
- package/lib/knex/src/routes/auth.route.ts +8 -10
- package/lib/knex/src/routes/users.route.ts +10 -12
- package/lib/knex/src/server.ts +6 -7
- package/lib/knex/src/services/auth.service.ts +27 -36
- package/lib/knex/src/services/users.service.ts +18 -23
- package/lib/knex/src/{tests → test}/auth.test.ts +2 -2
- package/lib/knex/src/{tests → test}/users.test.ts +2 -2
- package/lib/knex/src/utils/validateEnv.ts +1 -3
- package/lib/knex/tsconfig.json +2 -2
- package/lib/mikro-orm/.env.production.local +1 -1
- package/lib/mikro-orm/.env.test.local +1 -1
- package/lib/mikro-orm/.swcrc +1 -1
- package/lib/mikro-orm/Dockerfile.dev +19 -0
- package/lib/mikro-orm/Dockerfile.prod +19 -0
- package/lib/mikro-orm/Makefile +32 -15
- package/lib/mikro-orm/docker-compose.yml +20 -11
- package/lib/mikro-orm/package.json +42 -40
- package/lib/mikro-orm/src/app.ts +10 -12
- package/lib/mikro-orm/src/config/index.ts +2 -1
- package/lib/mikro-orm/src/controllers/auth.controller.ts +9 -11
- package/lib/mikro-orm/src/controllers/users.controller.ts +11 -13
- package/lib/mikro-orm/src/dtos/users.dto.ts +12 -1
- package/lib/mikro-orm/src/interfaces/users.interface.ts +1 -1
- package/lib/mikro-orm/src/middlewares/auth.middleware.ts +17 -10
- package/lib/mikro-orm/src/middlewares/error.middleware.ts +2 -4
- package/lib/mikro-orm/src/middlewares/validation.middleware.ts +22 -20
- package/lib/mikro-orm/src/routes/auth.route.ts +8 -10
- package/lib/mikro-orm/src/routes/users.route.ts +9 -11
- package/lib/mikro-orm/src/server.ts +6 -7
- package/lib/mikro-orm/src/services/auth.service.ts +23 -33
- package/lib/mikro-orm/src/services/users.service.ts +13 -21
- package/lib/mikro-orm/src/{tests → test}/auth.test.ts +3 -4
- package/lib/mikro-orm/src/{tests → test}/users.test.ts +4 -5
- package/lib/mikro-orm/src/utils/validateEnv.ts +1 -3
- package/lib/mikro-orm/tsconfig.json +2 -2
- package/lib/mongoose/.env.production.local +1 -1
- package/lib/mongoose/.env.test.local +1 -1
- package/lib/mongoose/.swcrc +1 -1
- package/lib/mongoose/Dockerfile.dev +19 -0
- package/lib/mongoose/Dockerfile.prod +19 -0
- package/lib/mongoose/Makefile +32 -15
- package/lib/mongoose/docker-compose.yml +20 -11
- package/lib/mongoose/jest.config.js +1 -1
- package/lib/mongoose/package.json +43 -41
- package/lib/mongoose/src/app.ts +6 -7
- package/lib/mongoose/src/config/index.ts +2 -1
- package/lib/mongoose/src/controllers/auth.controller.ts +9 -11
- package/lib/mongoose/src/controllers/users.controller.ts +11 -13
- package/lib/mongoose/src/{databases → database}/index.ts +1 -2
- package/lib/mongoose/src/dtos/users.dto.ts +12 -1
- package/lib/mongoose/src/interfaces/users.interface.ts +1 -1
- package/lib/mongoose/src/middlewares/auth.middleware.ts +16 -9
- package/lib/mongoose/src/middlewares/error.middleware.ts +2 -4
- package/lib/mongoose/src/middlewares/validation.middleware.ts +22 -20
- package/lib/mongoose/src/models/users.model.ts +2 -4
- package/lib/mongoose/src/routes/auth.route.ts +8 -10
- package/lib/mongoose/src/routes/users.route.ts +9 -11
- package/lib/mongoose/src/server.ts +6 -7
- package/lib/mongoose/src/services/auth.service.ts +26 -37
- package/lib/mongoose/src/services/users.service.ts +19 -29
- package/lib/{typegoose/src/tests → mongoose/src/test}/users.test.ts +7 -7
- package/lib/mongoose/src/utils/validateEnv.ts +1 -3
- package/lib/mongoose/tsconfig.json +2 -2
- package/lib/node-postgres/.dockerignore +18 -0
- package/lib/node-postgres/.editorconfig +9 -0
- package/lib/node-postgres/.env.development.local +13 -0
- package/lib/node-postgres/.env.production.local +13 -0
- package/lib/node-postgres/.env.test.local +13 -0
- package/lib/node-postgres/.eslintignore +1 -0
- package/lib/node-postgres/.eslintrc +18 -0
- package/lib/node-postgres/.huskyrc +5 -0
- package/lib/node-postgres/.lintstagedrc.json +5 -0
- package/lib/node-postgres/.prettierrc +8 -0
- package/lib/node-postgres/.swcrc +39 -0
- package/lib/node-postgres/.vscode/launch.json +35 -0
- package/lib/node-postgres/.vscode/settings.json +6 -0
- package/lib/node-postgres/Dockerfile.dev +17 -0
- package/lib/node-postgres/Dockerfile.prod +17 -0
- package/lib/node-postgres/Makefile +46 -0
- package/lib/node-postgres/docker-compose.yml +61 -0
- package/lib/node-postgres/ecosystem.config.js +57 -0
- package/lib/node-postgres/jest.config.js +12 -0
- package/lib/node-postgres/nginx.conf +40 -0
- package/lib/node-postgres/nodemon.json +12 -0
- package/lib/node-postgres/package.json +78 -0
- package/lib/node-postgres/src/app.ts +87 -0
- package/lib/node-postgres/src/config/index.ts +6 -0
- package/lib/node-postgres/src/controllers/auth.controller.ts +44 -0
- package/lib/node-postgres/src/controllers/users.controller.ts +63 -0
- package/lib/node-postgres/src/database/index.ts +6 -0
- package/lib/node-postgres/src/database/init.sql +110 -0
- package/lib/node-postgres/src/dtos/users.dto.ts +20 -0
- package/lib/node-postgres/src/http/auth.http +27 -0
- package/lib/node-postgres/src/http/users.http +34 -0
- package/lib/node-postgres/src/interfaces/auth.interface.ts +15 -0
- package/lib/node-postgres/src/interfaces/routes.interface.ts +6 -0
- package/lib/node-postgres/src/interfaces/users.interface.ts +5 -0
- package/lib/node-postgres/src/middlewares/auth.middleware.ts +38 -0
- package/lib/node-postgres/src/middlewares/error.middleware.ts +15 -0
- package/lib/node-postgres/src/middlewares/validation.middleware.ts +27 -0
- package/lib/node-postgres/src/models/users.model.ts +9 -0
- package/lib/node-postgres/src/routes/auth.route.ts +21 -0
- package/lib/node-postgres/src/routes/users.route.ts +23 -0
- package/lib/node-postgres/src/server.ts +10 -0
- package/lib/node-postgres/src/services/auth.service.ts +52 -0
- package/lib/node-postgres/src/services/users.service.ts +51 -0
- package/lib/{default/src/tests → node-postgres/src/test}/auth.test.ts +2 -2
- package/lib/{default/src/tests → node-postgres/src/test}/users.test.ts +5 -5
- package/lib/node-postgres/src/utils/logger.ts +65 -0
- package/lib/node-postgres/src/utils/validateEnv.ts +8 -0
- package/lib/node-postgres/swagger.yaml +123 -0
- package/lib/node-postgres/tsconfig.json +40 -0
- package/lib/prisma/.env.production.local +1 -1
- package/lib/prisma/.env.test.local +1 -1
- package/lib/prisma/Dockerfile.dev +19 -0
- package/lib/prisma/Dockerfile.prod +19 -0
- package/lib/prisma/Makefile +32 -15
- package/lib/prisma/docker-compose.yml +15 -14
- package/lib/prisma/jest.config.js +1 -1
- package/lib/prisma/package.json +43 -41
- package/lib/prisma/src/app.ts +4 -5
- package/lib/prisma/src/controllers/auth.controller.ts +10 -12
- package/lib/prisma/src/controllers/users.controller.ts +12 -14
- package/lib/prisma/src/dtos/users.dto.ts +12 -1
- package/lib/prisma/src/interfaces/auth.interface.ts +1 -1
- package/lib/prisma/src/interfaces/users.interface.ts +5 -0
- package/lib/prisma/src/middlewares/auth.middleware.ts +16 -11
- package/lib/prisma/src/middlewares/error.middleware.ts +2 -4
- package/lib/prisma/src/middlewares/validation.middleware.ts +22 -20
- package/lib/prisma/src/routes/auth.route.ts +8 -10
- package/lib/prisma/src/routes/users.route.ts +9 -11
- package/lib/prisma/src/server.ts +6 -7
- package/lib/prisma/src/services/auth.service.ts +10 -16
- package/lib/prisma/src/services/users.service.ts +19 -27
- package/lib/prisma/src/utils/validateEnv.ts +1 -3
- package/lib/prisma/tsconfig.json +1 -1
- package/lib/routing-controllers/Dockerfile.dev +19 -0
- package/lib/routing-controllers/Dockerfile.prod +19 -0
- package/lib/routing-controllers/Makefile +29 -16
- package/lib/routing-controllers/docker-compose.yml +9 -9
- package/lib/routing-controllers/jest.config.js +1 -1
- package/lib/routing-controllers/package.json +41 -40
- package/lib/routing-controllers/src/app.ts +4 -6
- package/lib/routing-controllers/src/controllers/auth.controller.ts +13 -12
- package/lib/routing-controllers/src/controllers/users.controller.ts +15 -13
- package/lib/routing-controllers/src/dtos/users.dto.ts +12 -1
- package/lib/routing-controllers/src/interfaces/users.interface.ts +1 -1
- package/lib/routing-controllers/src/middlewares/auth.middleware.ts +16 -10
- package/lib/routing-controllers/src/middlewares/error.middleware.ts +2 -5
- package/lib/routing-controllers/src/middlewares/validation.middleware.ts +23 -27
- package/lib/routing-controllers/src/models/users.model.ts +1 -3
- package/lib/routing-controllers/src/server.ts +5 -6
- package/lib/routing-controllers/src/services/auth.service.ts +25 -35
- package/lib/routing-controllers/src/services/users.service.ts +17 -25
- package/lib/routing-controllers/src/{tests → test}/auth.test.ts +1 -1
- package/lib/routing-controllers/src/{tests → test}/users.test.ts +10 -10
- package/lib/routing-controllers/src/utils/validateEnv.ts +1 -3
- package/lib/routing-controllers/tsconfig.json +1 -1
- package/lib/sequelize/.env.development.local +2 -2
- package/lib/sequelize/.env.production.local +3 -3
- package/lib/sequelize/.env.test.local +3 -3
- package/lib/sequelize/.swcrc +1 -1
- package/lib/sequelize/Dockerfile.dev +23 -0
- package/lib/sequelize/Dockerfile.prod +23 -0
- package/lib/sequelize/Makefile +32 -15
- package/lib/sequelize/docker-compose.yml +19 -14
- package/lib/sequelize/jest.config.js +1 -1
- package/lib/sequelize/package.json +45 -43
- package/lib/sequelize/src/app.ts +5 -6
- package/lib/sequelize/src/config/index.ts +2 -1
- package/lib/sequelize/src/controllers/auth.controller.ts +7 -8
- package/lib/sequelize/src/controllers/users.controller.ts +9 -10
- package/lib/sequelize/src/{databases → database}/index.ts +1 -3
- package/lib/sequelize/src/dtos/users.dto.ts +12 -1
- package/lib/sequelize/src/interfaces/users.interface.ts +1 -1
- package/lib/sequelize/src/middlewares/auth.middleware.ts +16 -10
- package/lib/sequelize/src/middlewares/error.middleware.ts +2 -4
- package/lib/sequelize/src/middlewares/validation.middleware.ts +22 -20
- package/lib/sequelize/src/routes/auth.route.ts +8 -11
- package/lib/sequelize/src/routes/users.route.ts +9 -11
- package/lib/sequelize/src/server.ts +6 -7
- package/lib/sequelize/src/services/auth.service.ts +24 -35
- package/lib/sequelize/src/services/users.service.ts +18 -29
- package/lib/sequelize/src/{tests → test}/auth.test.ts +2 -2
- package/lib/sequelize/src/{tests → test}/users.test.ts +2 -2
- package/lib/sequelize/src/utils/validateEnv.ts +1 -3
- package/lib/sequelize/tsconfig.json +2 -2
- package/lib/starter.js +18 -27
- package/lib/typegoose/.env.production.local +1 -1
- package/lib/typegoose/.env.test.local +1 -1
- package/lib/typegoose/.swcrc +1 -1
- package/lib/typegoose/Dockerfile.dev +19 -0
- package/lib/typegoose/Dockerfile.prod +19 -0
- package/lib/typegoose/Makefile +32 -15
- package/lib/typegoose/docker-compose.yml +20 -11
- package/lib/typegoose/jest.config.js +1 -1
- package/lib/typegoose/package.json +41 -39
- package/lib/typegoose/src/app.ts +3 -2
- package/lib/typegoose/src/config/index.ts +2 -1
- package/lib/typegoose/src/controllers/auth.controller.ts +9 -11
- package/lib/typegoose/src/controllers/users.controller.ts +11 -13
- package/lib/typegoose/src/database/index.ts +11 -0
- package/lib/typegoose/src/dtos/users.dto.ts +12 -1
- package/lib/typegoose/src/interfaces/users.interface.ts +1 -1
- package/lib/typegoose/src/middlewares/auth.middleware.ts +16 -10
- package/lib/typegoose/src/middlewares/error.middleware.ts +2 -4
- package/lib/typegoose/src/middlewares/validation.middleware.ts +22 -20
- package/lib/typegoose/src/models/users.model.ts +1 -3
- package/lib/typegoose/src/routes/auth.route.ts +8 -11
- package/lib/typegoose/src/routes/users.route.ts +9 -11
- package/lib/typegoose/src/server.ts +5 -6
- package/lib/typegoose/src/services/auth.service.ts +27 -36
- package/lib/typegoose/src/services/users.service.ts +17 -26
- package/lib/typegoose/src/{tests → test}/auth.test.ts +2 -2
- package/lib/{mongoose/src/tests → typegoose/src/test}/users.test.ts +7 -7
- package/lib/typegoose/src/utils/validateEnv.ts +1 -3
- package/lib/typegoose/tsconfig.json +2 -2
- package/lib/typeorm/.env.development.local +2 -2
- package/lib/typeorm/.env.production.local +3 -3
- package/lib/typeorm/.env.test.local +3 -3
- package/lib/typeorm/.swcrc +1 -1
- package/lib/typeorm/Dockerfile.dev +19 -0
- package/lib/typeorm/Dockerfile.prod +19 -0
- package/lib/typeorm/Makefile +32 -15
- package/lib/typeorm/docker-compose.yml +21 -14
- package/lib/typeorm/jest.config.js +1 -1
- package/lib/typeorm/package.json +42 -41
- package/lib/typeorm/src/app.ts +6 -8
- package/lib/typeorm/src/config/index.ts +2 -1
- package/lib/typeorm/src/controllers/auth.controller.ts +9 -11
- package/lib/typeorm/src/controllers/users.controller.ts +11 -13
- package/lib/{graphql/src/databases → typeorm/src/database}/index.ts +3 -3
- package/lib/typeorm/src/dtos/users.dto.ts +12 -1
- package/lib/typeorm/src/exceptions/httpException.ts +10 -0
- package/lib/typeorm/src/interfaces/users.interface.ts +1 -1
- package/lib/typeorm/src/middlewares/auth.middleware.ts +14 -7
- package/lib/typeorm/src/middlewares/error.middleware.ts +2 -4
- package/lib/typeorm/src/middlewares/validation.middleware.ts +22 -20
- package/lib/typeorm/src/routes/auth.route.ts +8 -11
- package/lib/typeorm/src/routes/users.route.ts +9 -11
- package/lib/typeorm/src/server.ts +6 -7
- package/lib/typeorm/src/services/auth.service.ts +24 -32
- package/lib/typeorm/src/services/users.service.ts +10 -20
- package/lib/typeorm/src/{tests → test}/auth.test.ts +10 -11
- package/lib/typeorm/src/{tests → test}/users.test.ts +34 -38
- package/lib/typeorm/src/utils/validateEnv.ts +1 -3
- package/lib/typeorm/tsconfig.json +2 -2
- package/package.json +3 -3
- package/lib/default/Dockerfile +0 -24
- package/lib/default/src/controllers/index.controller.ts +0 -13
- package/lib/default/src/routes/index.route.ts +0 -19
- package/lib/default/src/utils/util.ts +0 -19
- package/lib/graphql/Dockerfile +0 -24
- package/lib/graphql/src/tests/index.test.ts +0 -18
- package/lib/graphql/src/tests/users.test.ts +0 -71
- package/lib/graphql/src/utils/util.ts +0 -19
- package/lib/knex/Dockerfile +0 -24
- package/lib/knex/src/controllers/index.controller.ts +0 -13
- package/lib/knex/src/databases/migrations/20210713110926_initial.ts +0 -13
- package/lib/knex/src/routes/index.route.ts +0 -19
- package/lib/knex/src/tests/index.test.ts +0 -17
- package/lib/knex/src/utils/util.ts +0 -19
- package/lib/mikro-orm/Dockerfile +0 -24
- package/lib/mikro-orm/src/controllers/index.controller.ts +0 -13
- package/lib/mikro-orm/src/routes/index.route.ts +0 -19
- package/lib/mikro-orm/src/tests/index.test.ts +0 -18
- package/lib/mikro-orm/src/utils/util.ts +0 -19
- package/lib/mongoose/Dockerfile +0 -24
- package/lib/mongoose/src/controllers/index.controller.ts +0 -13
- package/lib/mongoose/src/routes/index.route.ts +0 -19
- package/lib/mongoose/src/utils/util.ts +0 -19
- package/lib/prisma/Dockerfile +0 -24
- package/lib/prisma/src/controllers/index.controller.ts +0 -13
- package/lib/prisma/src/routes/index.route.ts +0 -19
- package/lib/prisma/src/tests/index.test.ts +0 -18
- package/lib/prisma/src/utils/util.ts +0 -19
- package/lib/routing-controllers/Dockerfile +0 -24
- package/lib/routing-controllers/src/controllers/index.controller.ts +0 -9
- package/lib/routing-controllers/src/tests/index.test.ts +0 -17
- package/lib/routing-controllers/src/utils/util.ts +0 -19
- package/lib/sequelize/Dockerfile +0 -28
- package/lib/sequelize/src/controllers/index.controller.ts +0 -13
- package/lib/sequelize/src/routes/index.route.ts +0 -19
- package/lib/sequelize/src/tests/index.test.ts +0 -18
- package/lib/sequelize/src/utils/util.ts +0 -19
- package/lib/typegoose/Dockerfile +0 -24
- package/lib/typegoose/src/controllers/index.controller.ts +0 -13
- package/lib/typegoose/src/databases/index.ts +0 -3
- package/lib/typegoose/src/routes/index.route.ts +0 -19
- package/lib/typegoose/src/tests/index.test.ts +0 -18
- package/lib/typegoose/src/utils/util.ts +0 -19
- package/lib/typeorm/Dockerfile +0 -24
- package/lib/typeorm/src/controllers/index.controller.ts +0 -13
- package/lib/typeorm/src/routes/index.route.ts +0 -19
- package/lib/typeorm/src/tests/index.test.ts +0 -18
- package/lib/typeorm/src/utils/util.ts +0 -19
- package/lib/default/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
- package/lib/graphql/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
- package/lib/knex/src/{databases → database}/migrations/.gitkeep +0 -0
- package/lib/knex/src/{databases → database}/seeds/.gitkeep +0 -0
- package/lib/knex/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
- package/lib/mikro-orm/src/{databases → database}/index.ts +0 -0
- package/lib/mikro-orm/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
- package/lib/mongoose/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
- package/lib/mongoose/src/{tests → test}/auth.test.ts +0 -0
- package/lib/{default/src/tests → mongoose/src/test}/index.test.ts +0 -0
- package/lib/{prisma/src/exceptions/HttpException.ts → node-postgres/src/exceptions/httpException.ts} +0 -0
- package/lib/{sequelize/src/exceptions/HttpException.ts → prisma/src/exceptions/httpException.ts} +0 -0
- package/lib/prisma/src/{tests → test}/auth.test.ts +1 -1
- package/lib/{mongoose/src/tests → prisma/src/test}/index.test.ts +0 -0
- package/lib/prisma/src/{tests → test}/users.test.ts +1 -1
- /package/lib/routing-controllers/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
- /package/lib/sequelize/src/{migrations → database/migrations}/.gitkeep +0 -0
- /package/lib/sequelize/src/{seeders → database/seeders}/.gitkeep +0 -0
- /package/lib/{typegoose/src/exceptions/HttpException.ts → sequelize/src/exceptions/httpException.ts} +0 -0
- /package/lib/{typeorm/src/exceptions/HttpException.ts → typegoose/src/exceptions/httpException.ts} +0 -0
- /package/lib/typeorm/src/{migration → database/migrations}/.gitkeep +0 -0
package/lib/prisma/tsconfig.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# NodeJS Version 16
|
|
2
|
+
FROM node:16.18-buster-slim
|
|
3
|
+
|
|
4
|
+
# Copy Dir
|
|
5
|
+
COPY . ./app
|
|
6
|
+
|
|
7
|
+
# Work to Dir
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
|
|
10
|
+
# Install Node Package
|
|
11
|
+
RUN npm install --legacy-peer-deps
|
|
12
|
+
|
|
13
|
+
# Set Env
|
|
14
|
+
ENV NODE_ENV development
|
|
15
|
+
|
|
16
|
+
EXPOSE 3000
|
|
17
|
+
|
|
18
|
+
# Cmd script
|
|
19
|
+
CMD ["npm", "run", "dev"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# NodeJS Version 16
|
|
2
|
+
FROM node:16.18-buster-slim
|
|
3
|
+
|
|
4
|
+
# Copy Dir
|
|
5
|
+
COPY . ./app
|
|
6
|
+
|
|
7
|
+
# Work to Dir
|
|
8
|
+
WORKDIR /app
|
|
9
|
+
|
|
10
|
+
# Install Node Package
|
|
11
|
+
RUN npm install --legacy-peer-deps
|
|
12
|
+
|
|
13
|
+
# Set Env
|
|
14
|
+
ENV NODE_ENV production
|
|
15
|
+
|
|
16
|
+
EXPOSE 3000
|
|
17
|
+
|
|
18
|
+
# Cmd script
|
|
19
|
+
CMD ["npm", "run", "start"]
|
|
@@ -2,28 +2,41 @@
|
|
|
2
2
|
# ex) production-stage: make build APP_NAME=<APP_NAME>
|
|
3
3
|
# ex) development-stage: make build-dev APP_NAME=<APP_NAME>
|
|
4
4
|
|
|
5
|
+
SHELL := /bin/bash
|
|
6
|
+
|
|
5
7
|
APP_NAME = typescript-express
|
|
6
8
|
APP_NAME := $(APP_NAME)
|
|
7
9
|
|
|
8
|
-
.PHONY:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
.PHONY: help start clean db test
|
|
11
|
+
|
|
12
|
+
help:
|
|
13
|
+
@grep -E '^[1-9a-zA-Z_-]+:.*?## .*$$|(^#--)' $(MAKEFILE_LIST) \
|
|
14
|
+
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m %-43s\033[0m %s\n", $$1, $$2}' \
|
|
15
|
+
| sed -e 's/\[32m #-- /[33m/'
|
|
16
|
+
|
|
17
|
+
#-- Docker
|
|
18
|
+
up: ## Up the container images
|
|
19
|
+
docker-compose up -d
|
|
20
|
+
|
|
21
|
+
down: ## Down the container images
|
|
22
|
+
docker-compose down
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
build:
|
|
24
|
+
build: ## Build the container image - Production
|
|
17
25
|
docker build -t ${APP_NAME}\
|
|
18
|
-
|
|
19
|
-
-f Dockerfile .
|
|
26
|
+
-f Dockerfile.prod .
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
build-dev: ## Build the container image - Dvelopment
|
|
29
|
+
docker build -t ${APP_NAME}\
|
|
30
|
+
-f Dockerfile.dev .
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
run:
|
|
32
|
+
run: ## Run the container image
|
|
27
33
|
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
pause: ## Pause the containers
|
|
36
|
+
docker container rm -f ${APP_NAME}
|
|
37
|
+
|
|
38
|
+
clean: ## Clean the images
|
|
39
|
+
docker rmi -f ${APP_NAME}
|
|
40
|
+
|
|
41
|
+
remove: ## Remove the volumes
|
|
42
|
+
docker volume rm -f ${APP_NAME}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
version:
|
|
1
|
+
version: "3.9"
|
|
2
2
|
|
|
3
3
|
services:
|
|
4
4
|
proxy:
|
|
5
|
-
image: nginx:alpine
|
|
6
5
|
container_name: proxy
|
|
6
|
+
image: nginx:alpine
|
|
7
7
|
ports:
|
|
8
|
-
-
|
|
8
|
+
- "80:80"
|
|
9
9
|
volumes:
|
|
10
10
|
- ./nginx.conf:/etc/nginx/nginx.conf
|
|
11
|
-
restart:
|
|
11
|
+
restart: "unless-stopped"
|
|
12
12
|
networks:
|
|
13
13
|
- backend
|
|
14
|
+
|
|
14
15
|
server:
|
|
16
|
+
container_name: server
|
|
15
17
|
build:
|
|
16
18
|
context: ./
|
|
17
|
-
|
|
18
|
-
dockerfile: Dockerfile
|
|
19
|
-
container_name: server
|
|
19
|
+
dockerfile: Dockerfile.dev
|
|
20
20
|
ports:
|
|
21
|
-
-
|
|
21
|
+
- "3000:3000"
|
|
22
22
|
volumes:
|
|
23
23
|
- ./:/app
|
|
24
24
|
- /app/node_modules
|
|
25
|
-
restart:
|
|
25
|
+
restart: "unless-stopped"
|
|
26
26
|
networks:
|
|
27
27
|
- backend
|
|
28
28
|
|
|
@@ -18,59 +18,60 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"bcrypt": "^5.0.1",
|
|
20
20
|
"class-transformer": "^0.5.1",
|
|
21
|
-
"class-validator": "^0.13.
|
|
22
|
-
"class-validator-jsonschema": "^3.
|
|
21
|
+
"class-validator": "^0.13.2",
|
|
22
|
+
"class-validator-jsonschema": "^3.1.1",
|
|
23
23
|
"compression": "^1.7.4",
|
|
24
|
-
"cookie-parser": "^1.4.
|
|
24
|
+
"cookie-parser": "^1.4.6",
|
|
25
25
|
"cors": "^2.8.5",
|
|
26
|
-
"dotenv": "^
|
|
27
|
-
"envalid": "^7.1
|
|
28
|
-
"express": "^4.
|
|
29
|
-
"helmet": "^
|
|
26
|
+
"dotenv": "^16.0.1",
|
|
27
|
+
"envalid": "^7.3.1",
|
|
28
|
+
"express": "^4.18.1",
|
|
29
|
+
"helmet": "^5.1.1",
|
|
30
30
|
"hpp": "^0.2.3",
|
|
31
31
|
"jsonwebtoken": "^8.5.1",
|
|
32
32
|
"morgan": "^1.10.0",
|
|
33
33
|
"reflect-metadata": "^0.1.13",
|
|
34
34
|
"routing-controllers": "^0.9.0",
|
|
35
|
-
"routing-controllers-openapi": "^3.
|
|
36
|
-
"swagger-ui-express": "^4.
|
|
37
|
-
"
|
|
38
|
-
"winston
|
|
35
|
+
"routing-controllers-openapi": "^3.1.0",
|
|
36
|
+
"swagger-ui-express": "^4.5.0",
|
|
37
|
+
"typedi": "^0.10.0",
|
|
38
|
+
"winston": "^3.8.1",
|
|
39
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@swc/cli": "^0.1.
|
|
42
|
-
"@swc/core": "^1.2.
|
|
42
|
+
"@swc/cli": "^0.1.57",
|
|
43
|
+
"@swc/core": "^1.2.220",
|
|
43
44
|
"@types/bcrypt": "^5.0.0",
|
|
44
|
-
"@types/compression": "^1.7.
|
|
45
|
-
"@types/cookie-parser": "^1.4.
|
|
46
|
-
"@types/cors": "^2.8.
|
|
45
|
+
"@types/compression": "^1.7.2",
|
|
46
|
+
"@types/cookie-parser": "^1.4.3",
|
|
47
|
+
"@types/cors": "^2.8.12",
|
|
47
48
|
"@types/express": "^4.17.13",
|
|
48
|
-
"@types/hpp": "^0.2.
|
|
49
|
-
"@types/jest": "
|
|
50
|
-
"@types/jsonwebtoken": "^8.5.
|
|
49
|
+
"@types/hpp": "^0.2.2",
|
|
50
|
+
"@types/jest": "^28.1.6",
|
|
51
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
51
52
|
"@types/morgan": "^1.9.3",
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"@types/supertest": "^2.0.
|
|
53
|
+
"@types/node": "^17.0.45",
|
|
54
|
+
"@types/supertest": "^2.0.12",
|
|
54
55
|
"@types/swagger-ui-express": "^4.1.3",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
56
|
-
"@typescript-eslint/parser": "^
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
57
58
|
"cross-env": "^7.0.3",
|
|
58
|
-
"eslint": "^
|
|
59
|
-
"eslint-config-prettier": "^8.
|
|
60
|
-
"eslint-plugin-prettier": "^
|
|
61
|
-
"husky": "^
|
|
62
|
-
"jest": "
|
|
63
|
-
"lint-staged": "^
|
|
59
|
+
"eslint": "^8.20.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
62
|
+
"husky": "^8.0.1",
|
|
63
|
+
"jest": "^28.1.1",
|
|
64
|
+
"lint-staged": "^13.0.3",
|
|
64
65
|
"node-config": "^0.0.2",
|
|
65
|
-
"node-gyp": "^
|
|
66
|
-
"nodemon": "^2.0.
|
|
67
|
-
"pm2": "^5.
|
|
68
|
-
"prettier": "^2.
|
|
69
|
-
"supertest": "^6.2.
|
|
70
|
-
"ts-jest": "^
|
|
71
|
-
"ts-node": "^10.
|
|
72
|
-
"tsc-alias": "^1.
|
|
73
|
-
"tsconfig-paths": "^
|
|
74
|
-
"typescript": "^4.
|
|
66
|
+
"node-gyp": "^9.1.0",
|
|
67
|
+
"nodemon": "^2.0.19",
|
|
68
|
+
"pm2": "^5.2.0",
|
|
69
|
+
"prettier": "^2.7.1",
|
|
70
|
+
"supertest": "^6.2.4",
|
|
71
|
+
"ts-jest": "^28.0.7",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"tsc-alias": "^1.7.0",
|
|
74
|
+
"tsconfig-paths": "^4.0.0",
|
|
75
|
+
"typescript": "^4.7.4"
|
|
75
76
|
}
|
|
76
|
-
}
|
|
77
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { defaultMetadataStorage } from 'class-transformer';
|
|
2
|
+
import { defaultMetadataStorage } from 'class-transformer/cjs/storage';
|
|
3
3
|
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
|
|
4
4
|
import compression from 'compression';
|
|
5
5
|
import cookieParser from 'cookie-parser';
|
|
@@ -11,10 +11,10 @@ import { useExpressServer, getMetadataArgsStorage } from 'routing-controllers';
|
|
|
11
11
|
import { routingControllersToSpec } from 'routing-controllers-openapi';
|
|
12
12
|
import swaggerUi from 'swagger-ui-express';
|
|
13
13
|
import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
|
|
14
|
-
import
|
|
14
|
+
import { ErrorMiddleware } from '@middlewares/error.middleware';
|
|
15
15
|
import { logger, stream } from '@utils/logger';
|
|
16
16
|
|
|
17
|
-
class App {
|
|
17
|
+
export class App {
|
|
18
18
|
public app: express.Application;
|
|
19
19
|
public env: string;
|
|
20
20
|
public port: string | number;
|
|
@@ -96,8 +96,6 @@ class App {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
private initializeErrorHandling() {
|
|
99
|
-
this.app.use(
|
|
99
|
+
this.app.use(ErrorMiddleware);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
export default App;
|
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
import { Response } from 'express';
|
|
2
2
|
import { Controller, Req, Body, Post, UseBefore, HttpCode, Res } from 'routing-controllers';
|
|
3
|
+
import { Container } from 'typedi';
|
|
3
4
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
5
|
import { RequestWithUser } from '@interfaces/auth.interface';
|
|
5
6
|
import { User } from '@interfaces/users.interface';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import AuthService from '@services/auth.service';
|
|
7
|
+
import { AuthMiddleware } from '@middlewares/auth.middleware';
|
|
8
|
+
import { ValidationMiddleware } from '@middlewares/validation.middleware';
|
|
9
|
+
import { AuthService } from '@services/auth.service';
|
|
9
10
|
|
|
10
11
|
@Controller()
|
|
11
12
|
export class AuthController {
|
|
12
|
-
public
|
|
13
|
+
public auth = Container.get(AuthService);
|
|
13
14
|
|
|
14
15
|
@Post('/signup')
|
|
15
|
-
@UseBefore(
|
|
16
|
+
@UseBefore(ValidationMiddleware(CreateUserDto, 'body'))
|
|
16
17
|
@HttpCode(201)
|
|
17
|
-
async signUp(@Body() userData:
|
|
18
|
-
const signUpUserData: User = await this.
|
|
18
|
+
async signUp(@Body() userData: User) {
|
|
19
|
+
const signUpUserData: User = await this.auth.signup(userData);
|
|
19
20
|
return { data: signUpUserData, message: 'signup' };
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
@Post('/login')
|
|
23
|
-
@UseBefore(
|
|
24
|
-
async logIn(@Res() res: Response, @Body() userData:
|
|
25
|
-
const { cookie, findUser } = await this.
|
|
24
|
+
@UseBefore(ValidationMiddleware(CreateUserDto, 'body'))
|
|
25
|
+
async logIn(@Res() res: Response, @Body() userData: User) {
|
|
26
|
+
const { cookie, findUser } = await this.auth.login(userData);
|
|
26
27
|
|
|
27
28
|
res.setHeader('Set-Cookie', [cookie]);
|
|
28
29
|
return { data: findUser, message: 'login' };
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
@Post('/logout')
|
|
32
|
-
@UseBefore(
|
|
33
|
+
@UseBefore(AuthMiddleware)
|
|
33
34
|
async logOut(@Req() req: RequestWithUser, @Res() res: Response) {
|
|
34
35
|
const userData: User = req.user;
|
|
35
|
-
const logOutUserData: User = await this.
|
|
36
|
+
const logOutUserData: User = await this.auth.logout(userData);
|
|
36
37
|
|
|
37
38
|
res.setHeader('Set-Cookie', ['Authorization=; Max-age=0']);
|
|
38
39
|
return { data: logOutUserData, message: 'logout' };
|
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
import { Controller, Param, Body, Get, Post, Put, Delete, HttpCode, UseBefore } from 'routing-controllers';
|
|
2
2
|
import { OpenAPI } from 'routing-controllers-openapi';
|
|
3
|
+
import { Container } from 'typedi';
|
|
3
4
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
5
|
import { User } from '@interfaces/users.interface';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
6
|
+
import { ValidationMiddleware } from '@middlewares/validation.middleware';
|
|
7
|
+
import { UserService } from '@services/users.service';
|
|
7
8
|
|
|
8
9
|
@Controller()
|
|
9
|
-
export class
|
|
10
|
-
public
|
|
10
|
+
export class UserController {
|
|
11
|
+
public path = '/users'
|
|
12
|
+
public user = Container.get(UserService);
|
|
11
13
|
|
|
12
14
|
@Get('/users')
|
|
13
15
|
@OpenAPI({ summary: 'Return a list of users' })
|
|
14
16
|
async getUsers() {
|
|
15
|
-
const findAllUsersData: User[] = await this.
|
|
17
|
+
const findAllUsersData: User[] = await this.user.findAllUser();
|
|
16
18
|
return { data: findAllUsersData, message: 'findAll' };
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
@Get('/users/:id')
|
|
20
22
|
@OpenAPI({ summary: 'Return find a user' })
|
|
21
23
|
async getUserById(@Param('id') userId: number) {
|
|
22
|
-
const findOneUserData: User = await this.
|
|
24
|
+
const findOneUserData: User = await this.user.findUserById(userId);
|
|
23
25
|
return { data: findOneUserData, message: 'findOne' };
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
@Post('/users')
|
|
27
29
|
@HttpCode(201)
|
|
28
|
-
@UseBefore(
|
|
30
|
+
@UseBefore(ValidationMiddleware(CreateUserDto, 'body'))
|
|
29
31
|
@OpenAPI({ summary: 'Create a new user' })
|
|
30
|
-
async createUser(@Body() userData:
|
|
31
|
-
const createUserData: User = await this.
|
|
32
|
+
async createUser(@Body() userData: User) {
|
|
33
|
+
const createUserData: User = await this.user.createUser(userData);
|
|
32
34
|
return { data: createUserData, message: 'created' };
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
@Put('/users/:id')
|
|
36
|
-
@UseBefore(
|
|
38
|
+
@UseBefore(ValidationMiddleware(CreateUserDto, 'body', true))
|
|
37
39
|
@OpenAPI({ summary: 'Update a user' })
|
|
38
|
-
async updateUser(@Param('id') userId: number, @Body() userData:
|
|
39
|
-
const updateUserData: User[] = await this.
|
|
40
|
+
async updateUser(@Param('id') userId: number, @Body() userData: User) {
|
|
41
|
+
const updateUserData: User[] = await this.user.updateUser(userId, userData);
|
|
40
42
|
return { data: updateUserData, message: 'updated' };
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
@Delete('/users/:id')
|
|
44
46
|
@OpenAPI({ summary: 'Delete a user' })
|
|
45
47
|
async deleteUser(@Param('id') userId: number) {
|
|
46
|
-
const deleteUserData: User[] = await this.
|
|
48
|
+
const deleteUserData: User[] = await this.user.deleteUser(userId);
|
|
47
49
|
return { data: deleteUserData, message: 'deleted' };
|
|
48
50
|
}
|
|
49
51
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { IsEmail, IsString } from 'class-validator';
|
|
1
|
+
import { IsEmail, IsString, IsNotEmpty, MinLength, MaxLength } from 'class-validator';
|
|
2
2
|
|
|
3
3
|
export class CreateUserDto {
|
|
4
4
|
@IsEmail()
|
|
5
5
|
public email: string;
|
|
6
6
|
|
|
7
7
|
@IsString()
|
|
8
|
+
@IsNotEmpty()
|
|
9
|
+
@MinLength(9)
|
|
10
|
+
@MaxLength(32)
|
|
11
|
+
public password: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class UpdateUserDto {
|
|
15
|
+
@IsString()
|
|
16
|
+
@IsNotEmpty()
|
|
17
|
+
@MinLength(9)
|
|
18
|
+
@MaxLength(32)
|
|
8
19
|
public password: string;
|
|
9
20
|
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { NextFunction, Response } from 'express';
|
|
2
2
|
import { verify } from 'jsonwebtoken';
|
|
3
3
|
import { SECRET_KEY } from '@config';
|
|
4
|
-
import { HttpException } from '@exceptions/
|
|
4
|
+
import { HttpException } from '@exceptions/httpException';
|
|
5
5
|
import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
|
|
6
|
-
import
|
|
6
|
+
import { UserModel } from '@models/users.model';
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const getAuthorization = (req) => {
|
|
9
|
+
const coockie = req.cookies['Authorization'];
|
|
10
|
+
if (coockie) return coockie;
|
|
11
|
+
|
|
12
|
+
const header = req.header('Authorization');
|
|
13
|
+
if (header) return header.split('Bearer ')[1];
|
|
14
|
+
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const AuthMiddleware = async (req: RequestWithUser, res: Response, next: NextFunction) => {
|
|
9
19
|
try {
|
|
10
|
-
const Authorization =
|
|
20
|
+
const Authorization = getAuthorization(req);
|
|
11
21
|
|
|
12
22
|
if (Authorization) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const userId = verificationResponse.id;
|
|
16
|
-
const findUser = userModel.find(user => user.id === userId);
|
|
23
|
+
const { id } = (await verify(Authorization, SECRET_KEY)) as DataStoredInToken;
|
|
24
|
+
const findUser = UserModel.find(user => user.id === id);
|
|
17
25
|
|
|
18
26
|
if (findUser) {
|
|
19
27
|
req.user = findUser;
|
|
@@ -28,5 +36,3 @@ const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFun
|
|
|
28
36
|
next(new HttpException(401, 'Wrong authentication token'));
|
|
29
37
|
}
|
|
30
38
|
};
|
|
31
|
-
|
|
32
|
-
export default authMiddleware;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import { HttpException } from '@exceptions/
|
|
2
|
+
import { HttpException } from '@exceptions/httpException';
|
|
3
3
|
import { logger } from '@utils/logger';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
export const ErrorMiddleware = (error: HttpException, req: Request, res: Response, next: NextFunction) => {
|
|
6
6
|
try {
|
|
7
7
|
const status: number = error.status || 500;
|
|
8
8
|
const message: string = error.message || 'Something went wrong';
|
|
9
9
|
|
|
10
|
-
console.error(`[${req.method}] ${req.path} >> StatusCode:: ${status}, Message:: ${message}`);
|
|
11
10
|
logger.error(`[${req.method}] ${req.path} >> StatusCode:: ${status}, Message:: ${message}`);
|
|
12
11
|
res.status(status).json({ message });
|
|
13
12
|
} catch (error) {
|
|
14
13
|
next(error);
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
export default errorMiddleware;
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { HttpException } from '@exceptions/
|
|
1
|
+
import { plainToInstance } from 'class-transformer';
|
|
2
|
+
import { validateOrReject, ValidationError } from 'class-validator';
|
|
3
|
+
import { NextFunction, Request, Response } from 'express';
|
|
4
|
+
import { HttpException } from '@exceptions/httpException';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return (req, res, next) => {
|
|
21
|
-
const obj = plainToClass(type, req[value]);
|
|
22
|
-
validate(obj, { skipMissingProperties, whitelist, forbidNonWhitelisted }).then((errors: ValidationError[]) => {
|
|
23
|
-
if (errors.length > 0) {
|
|
24
|
-
const message = errors.map(getAllNestedErrors).join(', ');
|
|
25
|
-
next(new HttpException(400, message));
|
|
26
|
-
} else {
|
|
6
|
+
/**
|
|
7
|
+
* @name ValidationMiddleware
|
|
8
|
+
* @description Allows use of decorator and non-decorator based validation
|
|
9
|
+
* @param type dto
|
|
10
|
+
* @param skipMissingProperties When skipping missing properties
|
|
11
|
+
* @param whitelist Even if your object is an instance of a validation class it can contain additional properties that are not defined
|
|
12
|
+
* @param forbidNonWhitelisted If you would rather to have an error thrown when any non-whitelisted properties are present
|
|
13
|
+
*/
|
|
14
|
+
export const ValidationMiddleware = (type: any, skipMissingProperties = false, whitelist = false, forbidNonWhitelisted = false) => {
|
|
15
|
+
return (req: Request, res: Response, next: NextFunction) => {
|
|
16
|
+
const dto = plainToInstance(type, req.body);
|
|
17
|
+
validateOrReject(dto, { skipMissingProperties, whitelist, forbidNonWhitelisted })
|
|
18
|
+
.then(() => {
|
|
19
|
+
req.body = dto;
|
|
27
20
|
next();
|
|
28
|
-
}
|
|
29
|
-
|
|
21
|
+
})
|
|
22
|
+
.catch((errors: ValidationError[]) => {
|
|
23
|
+
const message = errors.map((error: ValidationError) => Object.values(error.constraints)).join(', ');
|
|
24
|
+
next(new HttpException(400, message));
|
|
25
|
+
});
|
|
30
26
|
};
|
|
31
27
|
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { User } from '@interfaces/users.interface';
|
|
2
2
|
|
|
3
3
|
// password: password
|
|
4
|
-
const
|
|
4
|
+
export const UserModel: User[] = [
|
|
5
5
|
{ id: 1, email: 'example1@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
6
6
|
{ id: 2, email: 'example2@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
7
7
|
{ id: 3, email: 'example3@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
8
8
|
{ id: 4, email: 'example4@email.com', password: '$2b$10$TBEfaCe1oo.2jfkBDWcj/usBj4oECsW2wOoDXpCa2IH9xqCpEK/hC' },
|
|
9
9
|
];
|
|
10
|
-
|
|
11
|
-
export default userModel;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import App from '@/app';
|
|
1
|
+
import { App } from '@/app';
|
|
2
2
|
import { AuthController } from '@controllers/auth.controller';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import validateEnv from '@utils/validateEnv';
|
|
3
|
+
import { UserController } from '@controllers/users.controller';
|
|
4
|
+
import { ValidateEnv } from '@utils/validateEnv';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
ValidateEnv();
|
|
8
7
|
|
|
9
|
-
const app = new App([AuthController,
|
|
8
|
+
const app = new App([AuthController, UserController]);
|
|
10
9
|
app.listen();
|