typescript-express-starter 9.2.0 → 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 -167
- package/README.md +118 -163
- 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/package.json +3 -1
- 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 +22 -33
- package/lib/default/src/services/users.service.ts +16 -25
- 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/package.json +2 -1
- package/lib/graphql/src/app.ts +14 -13
- package/lib/graphql/src/config/index.ts +2 -2
- package/lib/graphql/src/{databases → 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 +16 -24
- package/lib/graphql/src/repositories/users.repository.ts +5 -14
- 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/knexfile.ts +7 -9
- package/lib/knex/package.json +2 -0
- 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 +24 -33
- package/lib/knex/src/services/users.service.ts +14 -19
- 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 +2 -0
- 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 +19 -29
- package/lib/mikro-orm/src/services/users.service.ts +8 -16
- 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/package.json +2 -0
- 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/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 +22 -33
- package/lib/mongoose/src/services/users.service.ts +14 -24
- 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/package.json +2 -0
- 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 +6 -12
- package/lib/prisma/src/services/users.service.ts +15 -23
- 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/package.json +1 -0
- 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 +21 -31
- package/lib/routing-controllers/src/services/users.service.ts +13 -21
- 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/package.json +2 -0
- 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 +20 -31
- package/lib/sequelize/src/services/users.service.ts +14 -25
- 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 +17 -26
- 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/package.json +2 -0
- 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 +23 -32
- package/lib/typegoose/src/services/users.service.ts +12 -21
- 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/package.json +1 -0
- 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/typeorm/src/{databases → 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 +20 -28
- package/lib/typeorm/src/services/users.service.ts +6 -16
- package/lib/typeorm/src/{tests → test}/auth.test.ts +5 -5
- package/lib/typeorm/src/{tests → test}/users.test.ts +5 -5
- package/lib/typeorm/src/utils/validateEnv.ts +1 -3
- package/lib/typeorm/tsconfig.json +2 -2
- package/package.json +2 -1
- 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/{databases → database}/index.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
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
PORT = 3000
|
|
3
3
|
|
|
4
4
|
# DATABASE
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
POSTGRES_USER = root
|
|
6
|
+
POSTGRES_PASSWORD = password
|
|
7
|
+
POSTGRES_HOST = localhost
|
|
8
|
+
POSTGRES_PORT = 5432
|
|
9
|
+
POSTGRES_DB = dev
|
|
10
10
|
|
|
11
11
|
# TOKEN
|
|
12
12
|
SECRET_KEY = secretKey
|
|
@@ -16,5 +16,5 @@ LOG_FORMAT = dev
|
|
|
16
16
|
LOG_DIR = ../logs
|
|
17
17
|
|
|
18
18
|
# CORS
|
|
19
|
-
ORIGIN =
|
|
19
|
+
ORIGIN = *
|
|
20
20
|
CREDENTIALS = true
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
PORT = 3000
|
|
3
3
|
|
|
4
4
|
# DATABASE
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
POSTGRES_USER = root
|
|
6
|
+
POSTGRES_PASSWORD = password
|
|
7
|
+
POSTGRES_HOST = localhost
|
|
8
|
+
POSTGRES_PORT = 5432
|
|
9
|
+
POSTGRES_DB = dev
|
|
10
10
|
|
|
11
11
|
# TOKEN
|
|
12
12
|
SECRET_KEY = secretKey
|
|
@@ -16,5 +16,5 @@ LOG_FORMAT = combined
|
|
|
16
16
|
LOG_DIR = ../logs
|
|
17
17
|
|
|
18
18
|
# CORS
|
|
19
|
-
ORIGIN =
|
|
19
|
+
ORIGIN = your.domain.com
|
|
20
20
|
CREDENTIALS = true
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
PORT = 3000
|
|
3
3
|
|
|
4
4
|
# DATABASE
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
POSTGRES_USER = root
|
|
6
|
+
POSTGRES_PASSWORD = password
|
|
7
|
+
POSTGRES_HOST = localhost
|
|
8
|
+
POSTGRES_PORT = 5432
|
|
9
|
+
POSTGRES_DB = dev
|
|
10
10
|
|
|
11
11
|
# TOKEN
|
|
12
12
|
SECRET_KEY = secretKey
|
|
@@ -16,5 +16,5 @@ LOG_FORMAT = dev
|
|
|
16
16
|
LOG_DIR = ../logs
|
|
17
17
|
|
|
18
18
|
# CORS
|
|
19
|
-
ORIGIN =
|
|
19
|
+
ORIGIN = *
|
|
20
20
|
CREDENTIALS = true
|
package/lib/graphql/.swcrc
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"]
|
package/lib/graphql/Makefile
CHANGED
|
@@ -2,28 +2,45 @@
|
|
|
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
|
-
|
|
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
|
|
23
|
+
|
|
24
|
+
build: ## Build the container image - Production
|
|
11
25
|
docker build -t ${APP_NAME}\
|
|
12
|
-
|
|
13
|
-
-f Dockerfile .
|
|
26
|
+
-f Dockerfile.prod .
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
build:
|
|
28
|
+
build-dev: ## Build the container image - Dvelopment
|
|
17
29
|
docker build -t ${APP_NAME}\
|
|
18
|
-
|
|
19
|
-
-f Dockerfile .
|
|
30
|
+
-f Dockerfile.dev .
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
run: ## Run the container image
|
|
33
|
+
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
34
|
+
|
|
35
|
+
pause: ## Pause the containers
|
|
36
|
+
docker container rm -f ${APP_NAME}
|
|
37
|
+
|
|
38
|
+
clean: ## Clean the images
|
|
23
39
|
docker rmi -f ${APP_NAME}
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
docker run -d -it -p 3000:3000 ${APP_NAME}
|
|
41
|
+
remove: ## Remove the volumes
|
|
42
|
+
docker volume rm -f ${APP_NAME}
|
|
28
43
|
|
|
29
|
-
|
|
44
|
+
#-- Database
|
|
45
|
+
db: ## Start the local database PostgreSQL
|
|
46
|
+
docker-compose up -d pg
|
|
@@ -1,43 +1,51 @@
|
|
|
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
|
+
environment:
|
|
23
|
+
POSTGRES_USER: root
|
|
24
|
+
POSTGRES_PASSWORD: password
|
|
25
|
+
POSTGRES_HOST: pg
|
|
26
|
+
POSTGRES_PORT: 5432
|
|
27
|
+
POSTGRES_DB: dev
|
|
22
28
|
volumes:
|
|
23
29
|
- ./:/app
|
|
24
30
|
- /app/node_modules
|
|
25
|
-
restart:
|
|
31
|
+
restart: "unless-stopped"
|
|
26
32
|
networks:
|
|
27
33
|
- backend
|
|
28
34
|
links:
|
|
29
35
|
- pg
|
|
30
36
|
depends_on:
|
|
31
37
|
- pg
|
|
38
|
+
|
|
32
39
|
pg:
|
|
33
|
-
image: bitnami/postgresql:11-debian-9
|
|
34
40
|
container_name: pg
|
|
35
|
-
|
|
36
|
-
POSTGRESQL_USERNAME: root
|
|
37
|
-
POSTGRESQL_PASSWORD: password
|
|
38
|
-
POSTGRESQL_DATABASE: test
|
|
41
|
+
image: postgres:14.5-alpine
|
|
39
42
|
ports:
|
|
40
|
-
-
|
|
43
|
+
- "5432:5432"
|
|
44
|
+
environment:
|
|
45
|
+
POSTGRES_USER: root
|
|
46
|
+
POSTGRES_PASSWORD: password
|
|
47
|
+
POSTGRES_DB: dev
|
|
48
|
+
restart: "always"
|
|
41
49
|
networks:
|
|
42
50
|
- backend
|
|
43
51
|
|
package/lib/graphql/package.json
CHANGED
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
"dotenv": "^16.0.1",
|
|
27
27
|
"envalid": "^7.3.1",
|
|
28
28
|
"express": "^4.18.1",
|
|
29
|
-
"graphql": "^
|
|
29
|
+
"graphql": "^15.8.0",
|
|
30
30
|
"helmet": "^5.1.1",
|
|
31
31
|
"hpp": "^0.2.3",
|
|
32
32
|
"jsonwebtoken": "^8.5.1",
|
|
33
33
|
"pg": "^8.7.3",
|
|
34
34
|
"reflect-metadata": "^0.1.13",
|
|
35
35
|
"type-graphql": "^1.1.1",
|
|
36
|
+
"typedi": "^0.10.0",
|
|
36
37
|
"typeorm": "^0.2.45",
|
|
37
38
|
"winston": "^3.8.1",
|
|
38
39
|
"winston-daily-rotate-file": "^4.7.1"
|
package/lib/graphql/src/app.ts
CHANGED
|
@@ -10,12 +10,12 @@ import hpp from 'hpp';
|
|
|
10
10
|
import { buildSchema } from 'type-graphql';
|
|
11
11
|
import { createConnection } from 'typeorm';
|
|
12
12
|
import { NODE_ENV, PORT, ORIGIN, CREDENTIALS } from '@config';
|
|
13
|
-
import { dbConnection } from '@
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
13
|
+
import { dbConnection } from '@database';
|
|
14
|
+
import { AuthMiddleware, AuthCheckerMiddleware } from '@middlewares/auth.middleware';
|
|
15
|
+
import { ErrorMiddleware } from '@middlewares/error.middleware';
|
|
16
16
|
import { logger, responseLogger, errorLogger } from '@utils/logger';
|
|
17
17
|
|
|
18
|
-
class App {
|
|
18
|
+
export class App {
|
|
19
19
|
public app: express.Application;
|
|
20
20
|
public env: string;
|
|
21
21
|
public port: string | number;
|
|
@@ -65,7 +65,7 @@ class App {
|
|
|
65
65
|
private async initApolloServer(resolvers) {
|
|
66
66
|
const schema = await buildSchema({
|
|
67
67
|
resolvers: resolvers,
|
|
68
|
-
authChecker:
|
|
68
|
+
authChecker: AuthCheckerMiddleware,
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
const apolloServer = new ApolloServer({
|
|
@@ -77,7 +77,7 @@ class App {
|
|
|
77
77
|
],
|
|
78
78
|
context: async ({ req }) => {
|
|
79
79
|
try {
|
|
80
|
-
const user = await
|
|
80
|
+
const user = await AuthMiddleware(req);
|
|
81
81
|
return { user };
|
|
82
82
|
} catch (error) {
|
|
83
83
|
throw new Error(error);
|
|
@@ -89,19 +89,20 @@ class App {
|
|
|
89
89
|
return response;
|
|
90
90
|
},
|
|
91
91
|
formatError: error => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
try {
|
|
93
|
+
errorLogger(error);
|
|
94
|
+
return error;
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return new Error(err);
|
|
97
|
+
}
|
|
95
98
|
},
|
|
96
99
|
});
|
|
97
100
|
|
|
98
101
|
await apolloServer.start();
|
|
99
|
-
apolloServer.applyMiddleware({ app: this.app, cors:
|
|
102
|
+
apolloServer.applyMiddleware({ app: this.app, cors: false, path: '/graphql' });
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
private initializeErrorHandling() {
|
|
103
|
-
this.app.use(
|
|
106
|
+
this.app.use(ErrorMiddleware);
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
|
-
|
|
107
|
-
export default App;
|
|
@@ -2,5 +2,5 @@ import { config } from 'dotenv';
|
|
|
2
2
|
config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });
|
|
3
3
|
|
|
4
4
|
export const CREDENTIALS = process.env.CREDENTIALS === 'true';
|
|
5
|
-
export const ORIGIN = process.env
|
|
6
|
-
export const {
|
|
5
|
+
export const { NODE_ENV, PORT, SECRET_KEY, LOG_FORMAT, LOG_DIR, ORIGIN } = process.env;
|
|
6
|
+
export const { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB } = process.env;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { ConnectionOptions } from 'typeorm';
|
|
3
|
-
import {
|
|
3
|
+
import { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB } from '@config';
|
|
4
4
|
|
|
5
5
|
export const dbConnection: ConnectionOptions = {
|
|
6
6
|
type: 'postgres',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
database:
|
|
7
|
+
username: POSTGRES_USER,
|
|
8
|
+
password: POSTGRES_PASSWORD,
|
|
9
|
+
host: POSTGRES_HOST,
|
|
10
|
+
port: Number(POSTGRES_PORT),
|
|
11
|
+
database: POSTGRES_DB,
|
|
12
12
|
synchronize: true,
|
|
13
13
|
logging: false,
|
|
14
14
|
entities: [join(__dirname, '../**/*.entity{.ts,.js}')],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsEmail, IsString } from 'class-validator';
|
|
1
|
+
import { IsEmail, IsString, IsNotEmpty, MinLength, MaxLength } from 'class-validator';
|
|
2
2
|
import { InputType, Field } from 'type-graphql';
|
|
3
3
|
import { User } from '@typedefs/users.type';
|
|
4
4
|
|
|
@@ -10,5 +10,18 @@ export class CreateUserDto implements Partial<User> {
|
|
|
10
10
|
|
|
11
11
|
@Field()
|
|
12
12
|
@IsString()
|
|
13
|
+
@IsNotEmpty()
|
|
14
|
+
@MinLength(9)
|
|
15
|
+
@MaxLength(32)
|
|
16
|
+
password: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@InputType()
|
|
20
|
+
export class UpdateUserDto implements Partial<User> {
|
|
21
|
+
@Field()
|
|
22
|
+
@IsString()
|
|
23
|
+
@IsNotEmpty()
|
|
24
|
+
@MinLength(9)
|
|
25
|
+
@MaxLength(32)
|
|
13
26
|
password: string;
|
|
14
27
|
}
|
|
@@ -3,15 +3,25 @@ import { AuthChecker } from 'type-graphql';
|
|
|
3
3
|
import { getRepository } from 'typeorm';
|
|
4
4
|
import { SECRET_KEY } from '@config';
|
|
5
5
|
import { UserEntity } from '@entities/users.entity';
|
|
6
|
-
import { HttpException } from '@exceptions/
|
|
6
|
+
import { HttpException } from '@exceptions/httpException';
|
|
7
7
|
import { RequestWithUser, DataStoredInToken } from '@interfaces/auth.interface';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const getAuthorization = req => {
|
|
10
|
+
const cookie = req.cookies['Authorization'];
|
|
11
|
+
if (cookie) return cookie;
|
|
12
|
+
|
|
13
|
+
const header = req.header('Authorization');
|
|
14
|
+
if (header) return header.split('Bearer ')[1];
|
|
15
|
+
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const AuthMiddleware = async req => {
|
|
10
20
|
try {
|
|
11
|
-
const Authorization =
|
|
21
|
+
const Authorization = getAuthorization(req);
|
|
22
|
+
|
|
12
23
|
if (Authorization) {
|
|
13
|
-
const
|
|
14
|
-
const { id } = (await verify(Authorization, secretKey)) as DataStoredInToken;
|
|
24
|
+
const { id } = verify(Authorization, SECRET_KEY) as DataStoredInToken;
|
|
15
25
|
const userRepository = getRepository(UserEntity);
|
|
16
26
|
const findUser = await userRepository.findOne(id, { select: ['id', 'email', 'password'] });
|
|
17
27
|
return findUser;
|
|
@@ -23,7 +33,7 @@ export const authMiddleware = async req => {
|
|
|
23
33
|
}
|
|
24
34
|
};
|
|
25
35
|
|
|
26
|
-
export const
|
|
36
|
+
export const AuthCheckerMiddleware: AuthChecker<RequestWithUser> = async ({ context: { user } }) => {
|
|
27
37
|
if (!user) {
|
|
28
38
|
throw new HttpException(404, 'Authentication token missing');
|
|
29
39
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
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';
|
|
@@ -13,5 +13,3 @@ const errorMiddleware = (error: HttpException, req: Request, res: Response, next
|
|
|
13
13
|
next(error);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
export default errorMiddleware;
|
|
@@ -4,16 +4,24 @@ import { EntityRepository } from 'typeorm';
|
|
|
4
4
|
import { SECRET_KEY } from '@config';
|
|
5
5
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
6
6
|
import { UserEntity } from '@entities/users.entity';
|
|
7
|
-
import { HttpException } from '@exceptions/
|
|
7
|
+
import { HttpException } from '@exceptions/httpException';
|
|
8
8
|
import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
|
|
9
9
|
import { User } from '@interfaces/users.interface';
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
const createToken = (user: User): TokenData => {
|
|
12
|
+
const dataStoredInToken: DataStoredInToken = { id: user.id };
|
|
13
|
+
const expiresIn: number = 60 * 60;
|
|
14
|
+
|
|
15
|
+
return { expiresIn, token: sign(dataStoredInToken, SECRET_KEY, { expiresIn }) };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const createCookie = (tokenData: TokenData): string => {
|
|
19
|
+
return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
|
|
20
|
+
};
|
|
11
21
|
|
|
12
22
|
@EntityRepository(UserEntity)
|
|
13
|
-
export
|
|
23
|
+
export class AuthRepository {
|
|
14
24
|
public async userSignUp(userData: CreateUserDto): Promise<User> {
|
|
15
|
-
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
16
|
-
|
|
17
25
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
18
26
|
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
19
27
|
|
|
@@ -24,38 +32,22 @@ export default class AuthRepository {
|
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
public async userLogIn(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
27
|
-
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
28
|
-
|
|
29
35
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
30
36
|
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
31
37
|
|
|
32
38
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
33
|
-
if (!isPasswordMatching) throw new HttpException(409,
|
|
39
|
+
if (!isPasswordMatching) throw new HttpException(409, 'Password is not matching');
|
|
34
40
|
|
|
35
|
-
const tokenData =
|
|
36
|
-
const cookie =
|
|
41
|
+
const tokenData = createToken(findUser);
|
|
42
|
+
const cookie = createCookie(tokenData);
|
|
37
43
|
|
|
38
44
|
return { cookie, findUser };
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
public async userLogOut(userId: number): Promise<User> {
|
|
42
|
-
if (isEmpty(userId)) throw new HttpException(400, "userId is empty");
|
|
43
|
-
|
|
44
48
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
45
49
|
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
46
50
|
|
|
47
51
|
return findUser;
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
public createToken(user: User): TokenData {
|
|
51
|
-
const dataStoredInToken: DataStoredInToken = { id: user.id };
|
|
52
|
-
const secretKey: string = SECRET_KEY;
|
|
53
|
-
const expiresIn: number = 60 * 60;
|
|
54
|
-
|
|
55
|
-
return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public createCookie(tokenData: TokenData): string {
|
|
59
|
-
return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
|
|
60
|
-
}
|
|
61
53
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { hash } from 'bcrypt';
|
|
2
2
|
import { EntityRepository } from 'typeorm';
|
|
3
|
-
import { CreateUserDto } from '@dtos/users.dto';
|
|
3
|
+
import { CreateUserDto, UpdateUserDto } from '@dtos/users.dto';
|
|
4
4
|
import { UserEntity } from '@entities/users.entity';
|
|
5
|
-
import { HttpException } from '@exceptions/
|
|
5
|
+
import { HttpException } from '@exceptions/httpException';
|
|
6
6
|
import { User } from '@interfaces/users.interface';
|
|
7
|
-
import { isEmpty } from '@utils/util';
|
|
8
7
|
|
|
9
|
-
@EntityRepository()
|
|
10
|
-
export
|
|
8
|
+
@EntityRepository(UserEntity)
|
|
9
|
+
export class UserRepository {
|
|
11
10
|
public async userFindAll(): Promise<User[]> {
|
|
12
11
|
const users: User[] = await UserEntity.find();
|
|
13
12
|
|
|
@@ -15,8 +14,6 @@ export default class UserRepository {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
public async userFindById(userId: number): Promise<User> {
|
|
18
|
-
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
19
|
-
|
|
20
17
|
const user: User = await UserEntity.findOne({ where: { id: userId } });
|
|
21
18
|
if (!user) throw new HttpException(409, "User doesn't exist");
|
|
22
19
|
|
|
@@ -24,8 +21,6 @@ export default class UserRepository {
|
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
public async userCreate(userData: CreateUserDto): Promise<User> {
|
|
27
|
-
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
28
|
-
|
|
29
24
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
30
25
|
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
31
26
|
|
|
@@ -35,9 +30,7 @@ export default class UserRepository {
|
|
|
35
30
|
return createUserData;
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
public async userUpdate(userId: number, userData:
|
|
39
|
-
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
40
|
-
|
|
33
|
+
public async userUpdate(userId: number, userData: UpdateUserDto): Promise<User> {
|
|
41
34
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
42
35
|
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
43
36
|
|
|
@@ -49,8 +42,6 @@ export default class UserRepository {
|
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
public async userDelete(userId: number): Promise<User> {
|
|
52
|
-
if (isEmpty(userId)) throw new HttpException(400, "User doesn't existId");
|
|
53
|
-
|
|
54
45
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
55
46
|
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
56
47
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Authorized, Arg, Ctx, Mutation, Resolver } from 'type-graphql';
|
|
2
2
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
3
|
-
import AuthRepository from '@repositories/auth.repository';
|
|
3
|
+
import { AuthRepository } from '@repositories/auth.repository';
|
|
4
4
|
import { User } from '@typedefs/users.type';
|
|
5
5
|
|
|
6
6
|
@Resolver()
|
|
7
|
-
export class
|
|
7
|
+
export class AuthResolver extends AuthRepository {
|
|
8
8
|
@Mutation(() => User, {
|
|
9
9
|
description: 'User signup',
|
|
10
10
|
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Arg, Mutation, Query, Resolver } from 'type-graphql';
|
|
2
|
-
import { CreateUserDto } from '@dtos/users.dto';
|
|
3
|
-
import UserRepository from '@repositories/users.repository';
|
|
2
|
+
import { CreateUserDto, UpdateUserDto } from '@dtos/users.dto';
|
|
3
|
+
import { UserRepository } from '@repositories/users.repository';
|
|
4
4
|
import { User } from '@typedefs/users.type';
|
|
5
5
|
|
|
6
6
|
@Resolver()
|
|
7
|
-
export class
|
|
7
|
+
export class UserResolver extends UserRepository {
|
|
8
8
|
@Query(() => [User], {
|
|
9
9
|
description: 'User find list',
|
|
10
10
|
})
|
|
@@ -32,7 +32,7 @@ export class userResolver extends UserRepository {
|
|
|
32
32
|
@Mutation(() => User, {
|
|
33
33
|
description: 'User update',
|
|
34
34
|
})
|
|
35
|
-
async updateUser(@Arg('userId') userId: number, @Arg('userData') userData:
|
|
35
|
+
async updateUser(@Arg('userId') userId: number, @Arg('userData') userData: UpdateUserDto): Promise<User> {
|
|
36
36
|
const user: User = await this.userUpdate(userId, userData);
|
|
37
37
|
return user;
|
|
38
38
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import App from '@/app';
|
|
2
|
-
import
|
|
1
|
+
import { App } from '@/app';
|
|
2
|
+
import { AuthResolver } from '@resolvers/auth.resolver';
|
|
3
|
+
import { UserResolver } from '@resolvers/users.resolver';
|
|
4
|
+
import { ValidateEnv } from '@utils/validateEnv';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
import { userResolver } from '@resolvers/users.resolver';
|
|
6
|
+
ValidateEnv();
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const app = new App([authResolver, userResolver]);
|
|
8
|
+
const app = new App([AuthResolver, UserResolver]);
|
|
10
9
|
|
|
11
10
|
app.listen();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import { App } from '@/app';
|
|
3
|
+
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
|
+
|
|
5
|
+
afterAll(async () => {
|
|
6
|
+
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe('Testing Auth', () => {
|
|
10
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import { App } from '@app';
|
|
3
|
+
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
|
+
import { User } from '@interfaces/users.interface';
|
|
5
|
+
|
|
6
|
+
afterAll(async () => {
|
|
7
|
+
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('Testing Users', () => {
|
|
11
|
+
});
|