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.
Files changed (392) hide show
  1. package/.vscode/configurationCache.log +1 -0
  2. package/.vscode/dryrun.log +6 -0
  3. package/.vscode/settings.json +3 -0
  4. package/.vscode/targets.log +239 -0
  5. package/CONTRIBUTORS.md +61 -0
  6. package/README.kr.md +122 -167
  7. package/README.md +118 -163
  8. package/bin/cli.js +1 -1
  9. package/lib/default/.swcrc +0 -3
  10. package/lib/default/Dockerfile.dev +18 -0
  11. package/lib/default/Dockerfile.prod +18 -0
  12. package/lib/default/Makefile +29 -16
  13. package/lib/default/docker-compose.yml +8 -8
  14. package/lib/default/package.json +3 -1
  15. package/lib/default/src/app.ts +4 -5
  16. package/lib/default/src/controllers/auth.controller.ts +9 -11
  17. package/lib/default/src/controllers/users.controller.ts +11 -13
  18. package/lib/default/src/dtos/users.dto.ts +12 -1
  19. package/lib/default/src/interfaces/users.interface.ts +2 -2
  20. package/lib/default/src/middlewares/auth.middleware.ts +16 -10
  21. package/lib/default/src/middlewares/error.middleware.ts +2 -4
  22. package/lib/default/src/middlewares/validation.middleware.ts +22 -20
  23. package/lib/default/src/models/users.model.ts +6 -8
  24. package/lib/default/src/routes/auth.route.ts +8 -11
  25. package/lib/default/src/routes/users.route.ts +10 -12
  26. package/lib/default/src/server.ts +6 -7
  27. package/lib/default/src/services/auth.service.ts +22 -33
  28. package/lib/default/src/services/users.service.ts +16 -25
  29. package/lib/{graphql/src/tests → default/src/test}/auth.test.ts +21 -21
  30. package/lib/default/src/test/users.test.ts +62 -0
  31. package/lib/default/src/utils/validateEnv.ts +1 -3
  32. package/lib/default/tsconfig.json +1 -1
  33. package/lib/graphql/.env.development.local +6 -6
  34. package/lib/graphql/.env.production.local +6 -6
  35. package/lib/graphql/.env.test.local +6 -6
  36. package/lib/graphql/.swcrc +1 -1
  37. package/lib/graphql/Dockerfile.dev +19 -0
  38. package/lib/graphql/Dockerfile.prod +19 -0
  39. package/lib/graphql/Makefile +32 -15
  40. package/lib/graphql/docker-compose.yml +23 -15
  41. package/lib/graphql/package.json +2 -1
  42. package/lib/graphql/src/app.ts +14 -13
  43. package/lib/graphql/src/config/index.ts +2 -2
  44. package/lib/graphql/src/{databases → database}/index.ts +6 -6
  45. package/lib/graphql/src/dtos/users.dto.ts +14 -1
  46. package/lib/graphql/src/interfaces/users.interface.ts +2 -2
  47. package/lib/graphql/src/middlewares/auth.middleware.ts +16 -6
  48. package/lib/graphql/src/middlewares/error.middleware.ts +2 -4
  49. package/lib/graphql/src/repositories/auth.repository.ts +16 -24
  50. package/lib/graphql/src/repositories/users.repository.ts +5 -14
  51. package/lib/graphql/src/resolvers/auth.resolver.ts +2 -2
  52. package/lib/graphql/src/resolvers/users.resolver.ts +4 -4
  53. package/lib/graphql/src/server.ts +6 -7
  54. package/lib/graphql/src/test/auth.test.ts +10 -0
  55. package/lib/graphql/src/test/users.test.ts +11 -0
  56. package/lib/graphql/src/typedefs/users.type.ts +2 -2
  57. package/lib/graphql/src/utils/logger.ts +2 -0
  58. package/lib/graphql/src/utils/validateEnv.ts +1 -3
  59. package/lib/graphql/tsconfig.json +2 -2
  60. package/lib/knex/.env.development.local +2 -2
  61. package/lib/knex/.env.production.local +3 -3
  62. package/lib/knex/.env.test.local +3 -3
  63. package/lib/knex/.swcrc +1 -1
  64. package/lib/knex/Dockerfile.dev +19 -0
  65. package/lib/knex/Dockerfile.prod +19 -0
  66. package/lib/knex/Makefile +32 -15
  67. package/lib/knex/docker-compose.yml +19 -14
  68. package/lib/knex/knexfile.ts +7 -9
  69. package/lib/knex/package.json +2 -0
  70. package/lib/knex/src/app.ts +6 -7
  71. package/lib/knex/src/config/index.ts +2 -1
  72. package/lib/knex/src/controllers/auth.controller.ts +9 -11
  73. package/lib/knex/src/controllers/users.controller.ts +10 -12
  74. package/lib/knex/src/{databases → database}/index.ts +4 -4
  75. package/lib/knex/src/database/migrations/20210713110926_initial.ts +17 -0
  76. package/lib/knex/src/dtos/users.dto.ts +12 -1
  77. package/lib/knex/src/interfaces/users.interface.ts +2 -2
  78. package/lib/knex/src/middlewares/auth.middleware.ts +17 -10
  79. package/lib/knex/src/middlewares/error.middleware.ts +2 -4
  80. package/lib/knex/src/middlewares/validation.middleware.ts +22 -20
  81. package/lib/knex/src/models/users.model.ts +2 -2
  82. package/lib/knex/src/routes/auth.route.ts +8 -10
  83. package/lib/knex/src/routes/users.route.ts +10 -12
  84. package/lib/knex/src/server.ts +6 -7
  85. package/lib/knex/src/services/auth.service.ts +24 -33
  86. package/lib/knex/src/services/users.service.ts +14 -19
  87. package/lib/knex/src/{tests → test}/auth.test.ts +2 -2
  88. package/lib/knex/src/{tests → test}/users.test.ts +2 -2
  89. package/lib/knex/src/utils/validateEnv.ts +1 -3
  90. package/lib/knex/tsconfig.json +2 -2
  91. package/lib/mikro-orm/.env.production.local +1 -1
  92. package/lib/mikro-orm/.env.test.local +1 -1
  93. package/lib/mikro-orm/.swcrc +1 -1
  94. package/lib/mikro-orm/Dockerfile.dev +19 -0
  95. package/lib/mikro-orm/Dockerfile.prod +19 -0
  96. package/lib/mikro-orm/Makefile +32 -15
  97. package/lib/mikro-orm/docker-compose.yml +20 -11
  98. package/lib/mikro-orm/package.json +2 -0
  99. package/lib/mikro-orm/src/app.ts +10 -12
  100. package/lib/mikro-orm/src/config/index.ts +2 -1
  101. package/lib/mikro-orm/src/controllers/auth.controller.ts +9 -11
  102. package/lib/mikro-orm/src/controllers/users.controller.ts +11 -13
  103. package/lib/mikro-orm/src/dtos/users.dto.ts +12 -1
  104. package/lib/mikro-orm/src/interfaces/users.interface.ts +1 -1
  105. package/lib/mikro-orm/src/middlewares/auth.middleware.ts +17 -10
  106. package/lib/mikro-orm/src/middlewares/error.middleware.ts +2 -4
  107. package/lib/mikro-orm/src/middlewares/validation.middleware.ts +22 -20
  108. package/lib/mikro-orm/src/routes/auth.route.ts +8 -10
  109. package/lib/mikro-orm/src/routes/users.route.ts +9 -11
  110. package/lib/mikro-orm/src/server.ts +6 -7
  111. package/lib/mikro-orm/src/services/auth.service.ts +19 -29
  112. package/lib/mikro-orm/src/services/users.service.ts +8 -16
  113. package/lib/mikro-orm/src/{tests → test}/auth.test.ts +3 -4
  114. package/lib/mikro-orm/src/{tests → test}/users.test.ts +4 -5
  115. package/lib/mikro-orm/src/utils/validateEnv.ts +1 -3
  116. package/lib/mikro-orm/tsconfig.json +2 -2
  117. package/lib/mongoose/.env.production.local +1 -1
  118. package/lib/mongoose/.env.test.local +1 -1
  119. package/lib/mongoose/.swcrc +1 -1
  120. package/lib/mongoose/Dockerfile.dev +19 -0
  121. package/lib/mongoose/Dockerfile.prod +19 -0
  122. package/lib/mongoose/Makefile +32 -15
  123. package/lib/mongoose/docker-compose.yml +20 -11
  124. package/lib/mongoose/package.json +2 -0
  125. package/lib/mongoose/src/app.ts +6 -7
  126. package/lib/mongoose/src/config/index.ts +2 -1
  127. package/lib/mongoose/src/controllers/auth.controller.ts +9 -11
  128. package/lib/mongoose/src/controllers/users.controller.ts +11 -13
  129. package/lib/mongoose/src/dtos/users.dto.ts +12 -1
  130. package/lib/mongoose/src/interfaces/users.interface.ts +1 -1
  131. package/lib/mongoose/src/middlewares/auth.middleware.ts +16 -9
  132. package/lib/mongoose/src/middlewares/error.middleware.ts +2 -4
  133. package/lib/mongoose/src/middlewares/validation.middleware.ts +22 -20
  134. package/lib/mongoose/src/models/users.model.ts +2 -4
  135. package/lib/mongoose/src/routes/auth.route.ts +8 -10
  136. package/lib/mongoose/src/routes/users.route.ts +9 -11
  137. package/lib/mongoose/src/server.ts +6 -7
  138. package/lib/mongoose/src/services/auth.service.ts +22 -33
  139. package/lib/mongoose/src/services/users.service.ts +14 -24
  140. package/lib/{typegoose/src/tests → mongoose/src/test}/users.test.ts +7 -7
  141. package/lib/mongoose/src/utils/validateEnv.ts +1 -3
  142. package/lib/mongoose/tsconfig.json +2 -2
  143. package/lib/node-postgres/.dockerignore +18 -0
  144. package/lib/node-postgres/.editorconfig +9 -0
  145. package/lib/node-postgres/.env.development.local +13 -0
  146. package/lib/node-postgres/.env.production.local +13 -0
  147. package/lib/node-postgres/.env.test.local +13 -0
  148. package/lib/node-postgres/.eslintignore +1 -0
  149. package/lib/node-postgres/.eslintrc +18 -0
  150. package/lib/node-postgres/.huskyrc +5 -0
  151. package/lib/node-postgres/.lintstagedrc.json +5 -0
  152. package/lib/node-postgres/.prettierrc +8 -0
  153. package/lib/node-postgres/.swcrc +39 -0
  154. package/lib/node-postgres/.vscode/launch.json +35 -0
  155. package/lib/node-postgres/.vscode/settings.json +6 -0
  156. package/lib/node-postgres/Dockerfile.dev +17 -0
  157. package/lib/node-postgres/Dockerfile.prod +17 -0
  158. package/lib/node-postgres/Makefile +46 -0
  159. package/lib/node-postgres/docker-compose.yml +61 -0
  160. package/lib/node-postgres/ecosystem.config.js +57 -0
  161. package/lib/node-postgres/jest.config.js +12 -0
  162. package/lib/node-postgres/nginx.conf +40 -0
  163. package/lib/node-postgres/nodemon.json +12 -0
  164. package/lib/node-postgres/package.json +78 -0
  165. package/lib/node-postgres/src/app.ts +87 -0
  166. package/lib/node-postgres/src/config/index.ts +6 -0
  167. package/lib/node-postgres/src/controllers/auth.controller.ts +44 -0
  168. package/lib/node-postgres/src/controllers/users.controller.ts +63 -0
  169. package/lib/node-postgres/src/database/index.ts +6 -0
  170. package/lib/node-postgres/src/database/init.sql +110 -0
  171. package/lib/node-postgres/src/dtos/users.dto.ts +20 -0
  172. package/lib/node-postgres/src/http/auth.http +27 -0
  173. package/lib/node-postgres/src/http/users.http +34 -0
  174. package/lib/node-postgres/src/interfaces/auth.interface.ts +15 -0
  175. package/lib/node-postgres/src/interfaces/routes.interface.ts +6 -0
  176. package/lib/node-postgres/src/interfaces/users.interface.ts +5 -0
  177. package/lib/node-postgres/src/middlewares/auth.middleware.ts +38 -0
  178. package/lib/node-postgres/src/middlewares/error.middleware.ts +15 -0
  179. package/lib/node-postgres/src/middlewares/validation.middleware.ts +27 -0
  180. package/lib/node-postgres/src/models/users.model.ts +9 -0
  181. package/lib/node-postgres/src/routes/auth.route.ts +21 -0
  182. package/lib/node-postgres/src/routes/users.route.ts +23 -0
  183. package/lib/node-postgres/src/server.ts +10 -0
  184. package/lib/node-postgres/src/services/auth.service.ts +52 -0
  185. package/lib/node-postgres/src/services/users.service.ts +51 -0
  186. package/lib/{default/src/tests → node-postgres/src/test}/auth.test.ts +2 -2
  187. package/lib/{default/src/tests → node-postgres/src/test}/users.test.ts +5 -5
  188. package/lib/node-postgres/src/utils/logger.ts +65 -0
  189. package/lib/node-postgres/src/utils/validateEnv.ts +8 -0
  190. package/lib/node-postgres/swagger.yaml +123 -0
  191. package/lib/node-postgres/tsconfig.json +40 -0
  192. package/lib/prisma/.env.production.local +1 -1
  193. package/lib/prisma/.env.test.local +1 -1
  194. package/lib/prisma/Dockerfile.dev +19 -0
  195. package/lib/prisma/Dockerfile.prod +19 -0
  196. package/lib/prisma/Makefile +32 -15
  197. package/lib/prisma/docker-compose.yml +15 -14
  198. package/lib/prisma/package.json +2 -0
  199. package/lib/prisma/src/app.ts +4 -5
  200. package/lib/prisma/src/controllers/auth.controller.ts +10 -12
  201. package/lib/prisma/src/controllers/users.controller.ts +12 -14
  202. package/lib/prisma/src/dtos/users.dto.ts +12 -1
  203. package/lib/prisma/src/interfaces/auth.interface.ts +1 -1
  204. package/lib/prisma/src/interfaces/users.interface.ts +5 -0
  205. package/lib/prisma/src/middlewares/auth.middleware.ts +16 -11
  206. package/lib/prisma/src/middlewares/error.middleware.ts +2 -4
  207. package/lib/prisma/src/middlewares/validation.middleware.ts +22 -20
  208. package/lib/prisma/src/routes/auth.route.ts +8 -10
  209. package/lib/prisma/src/routes/users.route.ts +9 -11
  210. package/lib/prisma/src/server.ts +6 -7
  211. package/lib/prisma/src/services/auth.service.ts +6 -12
  212. package/lib/prisma/src/services/users.service.ts +15 -23
  213. package/lib/prisma/src/utils/validateEnv.ts +1 -3
  214. package/lib/prisma/tsconfig.json +1 -1
  215. package/lib/routing-controllers/Dockerfile.dev +19 -0
  216. package/lib/routing-controllers/Dockerfile.prod +19 -0
  217. package/lib/routing-controllers/Makefile +29 -16
  218. package/lib/routing-controllers/docker-compose.yml +9 -9
  219. package/lib/routing-controllers/package.json +1 -0
  220. package/lib/routing-controllers/src/app.ts +4 -6
  221. package/lib/routing-controllers/src/controllers/auth.controller.ts +13 -12
  222. package/lib/routing-controllers/src/controllers/users.controller.ts +15 -13
  223. package/lib/routing-controllers/src/dtos/users.dto.ts +12 -1
  224. package/lib/routing-controllers/src/interfaces/users.interface.ts +1 -1
  225. package/lib/routing-controllers/src/middlewares/auth.middleware.ts +16 -10
  226. package/lib/routing-controllers/src/middlewares/error.middleware.ts +2 -5
  227. package/lib/routing-controllers/src/middlewares/validation.middleware.ts +23 -27
  228. package/lib/routing-controllers/src/models/users.model.ts +1 -3
  229. package/lib/routing-controllers/src/server.ts +5 -6
  230. package/lib/routing-controllers/src/services/auth.service.ts +21 -31
  231. package/lib/routing-controllers/src/services/users.service.ts +13 -21
  232. package/lib/routing-controllers/src/{tests → test}/auth.test.ts +1 -1
  233. package/lib/routing-controllers/src/{tests → test}/users.test.ts +10 -10
  234. package/lib/routing-controllers/src/utils/validateEnv.ts +1 -3
  235. package/lib/routing-controllers/tsconfig.json +1 -1
  236. package/lib/sequelize/.env.development.local +2 -2
  237. package/lib/sequelize/.env.production.local +3 -3
  238. package/lib/sequelize/.env.test.local +3 -3
  239. package/lib/sequelize/.swcrc +1 -1
  240. package/lib/sequelize/Dockerfile.dev +23 -0
  241. package/lib/sequelize/Dockerfile.prod +23 -0
  242. package/lib/sequelize/Makefile +32 -15
  243. package/lib/sequelize/docker-compose.yml +19 -14
  244. package/lib/sequelize/package.json +2 -0
  245. package/lib/sequelize/src/app.ts +5 -6
  246. package/lib/sequelize/src/config/index.ts +2 -1
  247. package/lib/sequelize/src/controllers/auth.controller.ts +7 -8
  248. package/lib/sequelize/src/controllers/users.controller.ts +9 -10
  249. package/lib/sequelize/src/{databases → database}/index.ts +1 -3
  250. package/lib/sequelize/src/dtos/users.dto.ts +12 -1
  251. package/lib/sequelize/src/interfaces/users.interface.ts +1 -1
  252. package/lib/sequelize/src/middlewares/auth.middleware.ts +16 -10
  253. package/lib/sequelize/src/middlewares/error.middleware.ts +2 -4
  254. package/lib/sequelize/src/middlewares/validation.middleware.ts +22 -20
  255. package/lib/sequelize/src/routes/auth.route.ts +8 -11
  256. package/lib/sequelize/src/routes/users.route.ts +9 -11
  257. package/lib/sequelize/src/server.ts +6 -7
  258. package/lib/sequelize/src/services/auth.service.ts +20 -31
  259. package/lib/sequelize/src/services/users.service.ts +14 -25
  260. package/lib/sequelize/src/{tests → test}/auth.test.ts +2 -2
  261. package/lib/sequelize/src/{tests → test}/users.test.ts +2 -2
  262. package/lib/sequelize/src/utils/validateEnv.ts +1 -3
  263. package/lib/sequelize/tsconfig.json +2 -2
  264. package/lib/starter.js +17 -26
  265. package/lib/typegoose/.env.production.local +1 -1
  266. package/lib/typegoose/.env.test.local +1 -1
  267. package/lib/typegoose/.swcrc +1 -1
  268. package/lib/typegoose/Dockerfile.dev +19 -0
  269. package/lib/typegoose/Dockerfile.prod +19 -0
  270. package/lib/typegoose/Makefile +32 -15
  271. package/lib/typegoose/docker-compose.yml +20 -11
  272. package/lib/typegoose/package.json +2 -0
  273. package/lib/typegoose/src/app.ts +3 -2
  274. package/lib/typegoose/src/config/index.ts +2 -1
  275. package/lib/typegoose/src/controllers/auth.controller.ts +9 -11
  276. package/lib/typegoose/src/controllers/users.controller.ts +11 -13
  277. package/lib/typegoose/src/database/index.ts +11 -0
  278. package/lib/typegoose/src/dtos/users.dto.ts +12 -1
  279. package/lib/typegoose/src/interfaces/users.interface.ts +1 -1
  280. package/lib/typegoose/src/middlewares/auth.middleware.ts +16 -10
  281. package/lib/typegoose/src/middlewares/error.middleware.ts +2 -4
  282. package/lib/typegoose/src/middlewares/validation.middleware.ts +22 -20
  283. package/lib/typegoose/src/models/users.model.ts +1 -3
  284. package/lib/typegoose/src/routes/auth.route.ts +8 -11
  285. package/lib/typegoose/src/routes/users.route.ts +9 -11
  286. package/lib/typegoose/src/server.ts +5 -6
  287. package/lib/typegoose/src/services/auth.service.ts +23 -32
  288. package/lib/typegoose/src/services/users.service.ts +12 -21
  289. package/lib/typegoose/src/{tests → test}/auth.test.ts +2 -2
  290. package/lib/{mongoose/src/tests → typegoose/src/test}/users.test.ts +7 -7
  291. package/lib/typegoose/src/utils/validateEnv.ts +1 -3
  292. package/lib/typegoose/tsconfig.json +2 -2
  293. package/lib/typeorm/.env.development.local +2 -2
  294. package/lib/typeorm/.env.production.local +3 -3
  295. package/lib/typeorm/.env.test.local +3 -3
  296. package/lib/typeorm/.swcrc +1 -1
  297. package/lib/typeorm/Dockerfile.dev +19 -0
  298. package/lib/typeorm/Dockerfile.prod +19 -0
  299. package/lib/typeorm/Makefile +32 -15
  300. package/lib/typeorm/docker-compose.yml +21 -14
  301. package/lib/typeorm/package.json +1 -0
  302. package/lib/typeorm/src/app.ts +6 -8
  303. package/lib/typeorm/src/config/index.ts +2 -1
  304. package/lib/typeorm/src/controllers/auth.controller.ts +9 -11
  305. package/lib/typeorm/src/controllers/users.controller.ts +11 -13
  306. package/lib/typeorm/src/{databases → database}/index.ts +3 -3
  307. package/lib/typeorm/src/dtos/users.dto.ts +12 -1
  308. package/lib/typeorm/src/exceptions/httpException.ts +10 -0
  309. package/lib/typeorm/src/interfaces/users.interface.ts +1 -1
  310. package/lib/typeorm/src/middlewares/auth.middleware.ts +14 -7
  311. package/lib/typeorm/src/middlewares/error.middleware.ts +2 -4
  312. package/lib/typeorm/src/middlewares/validation.middleware.ts +22 -20
  313. package/lib/typeorm/src/routes/auth.route.ts +8 -11
  314. package/lib/typeorm/src/routes/users.route.ts +9 -11
  315. package/lib/typeorm/src/server.ts +6 -7
  316. package/lib/typeorm/src/services/auth.service.ts +20 -28
  317. package/lib/typeorm/src/services/users.service.ts +6 -16
  318. package/lib/typeorm/src/{tests → test}/auth.test.ts +5 -5
  319. package/lib/typeorm/src/{tests → test}/users.test.ts +5 -5
  320. package/lib/typeorm/src/utils/validateEnv.ts +1 -3
  321. package/lib/typeorm/tsconfig.json +2 -2
  322. package/package.json +2 -1
  323. package/lib/default/Dockerfile +0 -24
  324. package/lib/default/src/controllers/index.controller.ts +0 -13
  325. package/lib/default/src/routes/index.route.ts +0 -19
  326. package/lib/default/src/utils/util.ts +0 -19
  327. package/lib/graphql/Dockerfile +0 -24
  328. package/lib/graphql/src/tests/index.test.ts +0 -18
  329. package/lib/graphql/src/tests/users.test.ts +0 -71
  330. package/lib/graphql/src/utils/util.ts +0 -19
  331. package/lib/knex/Dockerfile +0 -24
  332. package/lib/knex/src/controllers/index.controller.ts +0 -13
  333. package/lib/knex/src/databases/migrations/20210713110926_initial.ts +0 -13
  334. package/lib/knex/src/routes/index.route.ts +0 -19
  335. package/lib/knex/src/tests/index.test.ts +0 -17
  336. package/lib/knex/src/utils/util.ts +0 -19
  337. package/lib/mikro-orm/Dockerfile +0 -24
  338. package/lib/mikro-orm/src/controllers/index.controller.ts +0 -13
  339. package/lib/mikro-orm/src/routes/index.route.ts +0 -19
  340. package/lib/mikro-orm/src/tests/index.test.ts +0 -18
  341. package/lib/mikro-orm/src/utils/util.ts +0 -19
  342. package/lib/mongoose/Dockerfile +0 -24
  343. package/lib/mongoose/src/controllers/index.controller.ts +0 -13
  344. package/lib/mongoose/src/routes/index.route.ts +0 -19
  345. package/lib/mongoose/src/utils/util.ts +0 -19
  346. package/lib/prisma/Dockerfile +0 -24
  347. package/lib/prisma/src/controllers/index.controller.ts +0 -13
  348. package/lib/prisma/src/routes/index.route.ts +0 -19
  349. package/lib/prisma/src/tests/index.test.ts +0 -18
  350. package/lib/prisma/src/utils/util.ts +0 -19
  351. package/lib/routing-controllers/Dockerfile +0 -24
  352. package/lib/routing-controllers/src/controllers/index.controller.ts +0 -9
  353. package/lib/routing-controllers/src/tests/index.test.ts +0 -17
  354. package/lib/routing-controllers/src/utils/util.ts +0 -19
  355. package/lib/sequelize/Dockerfile +0 -28
  356. package/lib/sequelize/src/controllers/index.controller.ts +0 -13
  357. package/lib/sequelize/src/routes/index.route.ts +0 -19
  358. package/lib/sequelize/src/tests/index.test.ts +0 -18
  359. package/lib/sequelize/src/utils/util.ts +0 -19
  360. package/lib/typegoose/Dockerfile +0 -24
  361. package/lib/typegoose/src/controllers/index.controller.ts +0 -13
  362. package/lib/typegoose/src/databases/index.ts +0 -3
  363. package/lib/typegoose/src/routes/index.route.ts +0 -19
  364. package/lib/typegoose/src/tests/index.test.ts +0 -18
  365. package/lib/typegoose/src/utils/util.ts +0 -19
  366. package/lib/typeorm/Dockerfile +0 -24
  367. package/lib/typeorm/src/controllers/index.controller.ts +0 -13
  368. package/lib/typeorm/src/routes/index.route.ts +0 -19
  369. package/lib/typeorm/src/tests/index.test.ts +0 -18
  370. package/lib/typeorm/src/utils/util.ts +0 -19
  371. package/lib/default/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
  372. package/lib/graphql/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
  373. package/lib/knex/src/{databases → database}/migrations/.gitkeep +0 -0
  374. package/lib/knex/src/{databases → database}/seeds/.gitkeep +0 -0
  375. package/lib/knex/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
  376. package/lib/mikro-orm/src/{databases → database}/index.ts +0 -0
  377. package/lib/mikro-orm/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
  378. package/lib/mongoose/src/{databases → database}/index.ts +0 -0
  379. package/lib/mongoose/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
  380. package/lib/mongoose/src/{tests → test}/auth.test.ts +0 -0
  381. package/lib/{default/src/tests → mongoose/src/test}/index.test.ts +0 -0
  382. package/lib/{prisma/src/exceptions/HttpException.ts → node-postgres/src/exceptions/httpException.ts} +0 -0
  383. package/lib/{sequelize/src/exceptions/HttpException.ts → prisma/src/exceptions/httpException.ts} +0 -0
  384. package/lib/prisma/src/{tests → test}/auth.test.ts +1 -1
  385. package/lib/{mongoose/src/tests → prisma/src/test}/index.test.ts +0 -0
  386. package/lib/prisma/src/{tests → test}/users.test.ts +1 -1
  387. /package/lib/routing-controllers/src/exceptions/{HttpException.ts → httpException.ts} +0 -0
  388. /package/lib/sequelize/src/{migrations → database/migrations}/.gitkeep +0 -0
  389. /package/lib/sequelize/src/{seeders → database/seeders}/.gitkeep +0 -0
  390. /package/lib/{typegoose/src/exceptions/HttpException.ts → sequelize/src/exceptions/httpException.ts} +0 -0
  391. /package/lib/{typeorm/src/exceptions/HttpException.ts → typegoose/src/exceptions/httpException.ts} +0 -0
  392. /package/lib/typeorm/src/{migration → database/migrations}/.gitkeep +0 -0
@@ -12,10 +12,10 @@ import { createConnection } from 'typeorm';
12
12
  import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
13
13
  import { dbConnection } from '@databases';
14
14
  import { Routes } from '@interfaces/routes.interface';
15
- import errorMiddleware from '@middlewares/error.middleware';
15
+ import { ErrorMiddleware } from '@middlewares/error.middleware';
16
16
  import { logger, stream } 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;
@@ -25,7 +25,7 @@ class App {
25
25
  this.env = NODE_ENV || 'development';
26
26
  this.port = PORT || 3000;
27
27
 
28
- this.env !== 'test' && this.connectToDatabase();
28
+ this.connectToDatabase();
29
29
  this.initializeMiddlewares();
30
30
  this.initializeRoutes(routes);
31
31
  this.initializeSwagger();
@@ -45,8 +45,8 @@ class App {
45
45
  return this.app;
46
46
  }
47
47
 
48
- private connectToDatabase() {
49
- createConnection(dbConnection);
48
+ private async connectToDatabase() {
49
+ await createConnection(dbConnection)
50
50
  }
51
51
 
52
52
  private initializeMiddlewares() {
@@ -83,8 +83,6 @@ class App {
83
83
  }
84
84
 
85
85
  private initializeErrorHandling() {
86
- this.app.use(errorMiddleware);
86
+ this.app.use(ErrorMiddleware);
87
87
  }
88
88
  }
89
-
90
- export default App;
@@ -2,4 +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 { NODE_ENV, PORT, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE, SECRET_KEY, LOG_FORMAT, LOG_DIR, ORIGIN } = process.env;
5
+ export const { NODE_ENV, PORT, SECRET_KEY, LOG_FORMAT, LOG_DIR, ORIGIN } = process.env;
6
+ export const { DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE } = process.env;
@@ -1,16 +1,16 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
- import { CreateUserDto } from '@dtos/users.dto';
2
+ import { Container } from 'typedi';
3
3
  import { RequestWithUser } from '@interfaces/auth.interface';
4
4
  import { User } from '@interfaces/users.interface';
5
- import AuthService from '@services/auth.service';
5
+ import { AuthService } from '@services/auth.service';
6
6
 
7
- class AuthController {
8
- public authService = new AuthService();
7
+ export class AuthController {
8
+ public auth = Container.get(AuthService);
9
9
 
10
10
  public signUp = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
11
11
  try {
12
- const userData: CreateUserDto = req.body;
13
- const signUpUserData: User = await this.authService.signup(userData);
12
+ const userData: User = req.body;
13
+ const signUpUserData: User = await this.auth.signup(userData);
14
14
 
15
15
  res.status(201).json({ data: signUpUserData, message: 'signup' });
16
16
  } catch (error) {
@@ -20,8 +20,8 @@ class AuthController {
20
20
 
21
21
  public logIn = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
22
22
  try {
23
- const userData: CreateUserDto = req.body;
24
- const { cookie, findUser } = await this.authService.login(userData);
23
+ const userData: User = req.body;
24
+ const { cookie, findUser } = await this.auth.login(userData);
25
25
 
26
26
  res.setHeader('Set-Cookie', [cookie]);
27
27
  res.status(200).json({ data: findUser, message: 'login' });
@@ -33,7 +33,7 @@ class AuthController {
33
33
  public logOut = async (req: RequestWithUser, res: Response, next: NextFunction): Promise<void> => {
34
34
  try {
35
35
  const userData: User = req.user;
36
- const logOutUserData: User = await this.authService.logout(userData);
36
+ const logOutUserData: User = await this.auth.logout(userData);
37
37
 
38
38
  res.setHeader('Set-Cookie', ['Authorization=; Max-age=0']);
39
39
  res.status(200).json({ data: logOutUserData, message: 'logout' });
@@ -42,5 +42,3 @@ class AuthController {
42
42
  }
43
43
  };
44
44
  }
45
-
46
- export default AuthController;
@@ -1,14 +1,14 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
- import { CreateUserDto } from '@dtos/users.dto';
2
+ import { Container } from 'typedi';
3
3
  import { User } from '@interfaces/users.interface';
4
- import userService from '@services/users.service';
4
+ import { UserService } from '@services/users.service';
5
5
 
6
- class UsersController {
7
- public userService = new userService();
6
+ export class UserController {
7
+ public user = Container.get(UserService);
8
8
 
9
9
  public getUsers = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
10
10
  try {
11
- const findAllUsersData: User[] = await this.userService.findAllUser();
11
+ const findAllUsersData: User[] = await this.user.findAllUser();
12
12
 
13
13
  res.status(200).json({ data: findAllUsersData, message: 'findAll' });
14
14
  } catch (error) {
@@ -19,7 +19,7 @@ class UsersController {
19
19
  public getUserById = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
20
20
  try {
21
21
  const userId = Number(req.params.id);
22
- const findOneUserData: User = await this.userService.findUserById(userId);
22
+ const findOneUserData: User = await this.user.findUserById(userId);
23
23
 
24
24
  res.status(200).json({ data: findOneUserData, message: 'findOne' });
25
25
  } catch (error) {
@@ -29,8 +29,8 @@ class UsersController {
29
29
 
30
30
  public createUser = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
31
31
  try {
32
- const userData: CreateUserDto = req.body;
33
- const createUserData: User = await this.userService.createUser(userData);
32
+ const userData: User = req.body;
33
+ const createUserData: User = await this.user.createUser(userData);
34
34
 
35
35
  res.status(201).json({ data: createUserData, message: 'created' });
36
36
  } catch (error) {
@@ -41,8 +41,8 @@ class UsersController {
41
41
  public updateUser = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
42
42
  try {
43
43
  const userId = Number(req.params.id);
44
- const userData: CreateUserDto = req.body;
45
- const updateUserData: User = await this.userService.updateUser(userId, userData);
44
+ const userData: User = req.body;
45
+ const updateUserData: User = await this.user.updateUser(userId, userData);
46
46
 
47
47
  res.status(200).json({ data: updateUserData, message: 'updated' });
48
48
  } catch (error) {
@@ -53,7 +53,7 @@ class UsersController {
53
53
  public deleteUser = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
54
54
  try {
55
55
  const userId = Number(req.params.id);
56
- const deleteUserData: User = await this.userService.deleteUser(userId);
56
+ const deleteUserData: User = await this.user.deleteUser(userId);
57
57
 
58
58
  res.status(200).json({ data: deleteUserData, message: 'deleted' });
59
59
  } catch (error) {
@@ -61,5 +61,3 @@ class UsersController {
61
61
  }
62
62
  };
63
63
  }
64
-
65
- export default UsersController;
@@ -1,13 +1,13 @@
1
1
  import { join } from 'path';
2
2
  import { ConnectionOptions } from 'typeorm';
3
- import { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } from '@config';
3
+ import { DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE } from '@config';
4
4
 
5
5
  export const dbConnection: ConnectionOptions = {
6
6
  type: 'postgres',
7
- host: DB_HOST,
8
- port: Number(DB_PORT),
9
7
  username: DB_USER,
10
8
  password: DB_PASSWORD,
9
+ host: DB_HOST,
10
+ port: Number(DB_PORT),
11
11
  database: DB_DATABASE,
12
12
  synchronize: true,
13
13
  logging: false,
@@ -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
  }
@@ -0,0 +1,10 @@
1
+ export class HttpException extends Error {
2
+ public status: number;
3
+ public message: string;
4
+
5
+ constructor(status: number, message: string) {
6
+ super(message);
7
+ this.status = status;
8
+ this.message = message;
9
+ }
10
+ }
@@ -1,5 +1,5 @@
1
1
  export interface User {
2
- id: number;
2
+ id?: number;
3
3
  email: string;
4
4
  password: string;
5
5
  }
@@ -2,16 +2,25 @@ import { NextFunction, Response } from 'express';
2
2
  import { verify } from 'jsonwebtoken';
3
3
  import { SECRET_KEY } from '@config';
4
4
  import { UserEntity } from '@entities/users.entity';
5
- import { HttpException } from '@exceptions/HttpException';
5
+ import { HttpException } from '@/exceptions/httpException';
6
6
  import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
7
7
 
8
- const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFunction) => {
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 = req.cookies['Authorization'] || (req.header('Authorization') ? req.header('Authorization').split('Bearer ')[1] : null);
20
+ const Authorization = getAuthorization(req);
11
21
 
12
22
  if (Authorization) {
13
- const secretKey: string = SECRET_KEY;
14
- const { id } = (await verify(Authorization, secretKey)) as DataStoredInToken;
23
+ const { id } = (await verify(Authorization, SECRET_KEY)) as DataStoredInToken;
15
24
  const findUser = await UserEntity.findOne(id, { select: ['id', 'email', 'password'] });
16
25
 
17
26
  if (findUser) {
@@ -27,5 +36,3 @@ const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFun
27
36
  next(new HttpException(401, 'Wrong authentication token'));
28
37
  }
29
38
  };
30
-
31
- export default authMiddleware;
@@ -1,8 +1,8 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
- import { HttpException } from '@exceptions/HttpException';
2
+ import { HttpException } from '@/exceptions/httpException';
3
3
  import { logger } from '@utils/logger';
4
4
 
5
- const errorMiddleware = (error: HttpException, req: Request, res: Response, next: NextFunction) => {
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;
@@ -1,25 +1,27 @@
1
- import { plainToClass } from 'class-transformer';
2
- import { validate, ValidationError } from 'class-validator';
3
- import { RequestHandler } from 'express';
4
- import { HttpException } from '@exceptions/HttpException';
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
- const validationMiddleware = (
7
- type: any,
8
- value: string | 'body' | 'query' | 'params' = 'body',
9
- skipMissingProperties = false,
10
- whitelist = true,
11
- forbidNonWhitelisted = true,
12
- ): RequestHandler => {
13
- return (req, res, next) => {
14
- validate(plainToClass(type, req[value]), { skipMissingProperties, whitelist, forbidNonWhitelisted }).then((errors: ValidationError[]) => {
15
- if (errors.length > 0) {
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;
20
+ next();
21
+ })
22
+ .catch((errors: ValidationError[]) => {
16
23
  const message = errors.map((error: ValidationError) => Object.values(error.constraints)).join(', ');
17
24
  next(new HttpException(400, message));
18
- } else {
19
- next();
20
- }
21
- });
25
+ });
22
26
  };
23
27
  };
24
-
25
- export default validationMiddleware;
@@ -1,24 +1,21 @@
1
1
  import { Router } from 'express';
2
- import AuthController from '@controllers/auth.controller';
2
+ import { AuthController } from '@controllers/auth.controller';
3
3
  import { CreateUserDto } from '@dtos/users.dto';
4
4
  import { Routes } from '@interfaces/routes.interface';
5
- import authMiddleware from '@middlewares/auth.middleware';
6
- import validationMiddleware from '@middlewares/validation.middleware';
5
+ import { AuthMiddleware } from '@middlewares/auth.middleware';
6
+ import { ValidationMiddleware } from '@middlewares/validation.middleware';
7
7
 
8
- class AuthRoute implements Routes {
9
- public path = '/';
8
+ export class AuthRoute implements Routes {
10
9
  public router = Router();
11
- public authController = new AuthController();
10
+ public auth = new AuthController();
12
11
 
13
12
  constructor() {
14
13
  this.initializeRoutes();
15
14
  }
16
15
 
17
16
  private initializeRoutes() {
18
- this.router.post(`${this.path}signup`, validationMiddleware(CreateUserDto, 'body'), this.authController.signUp);
19
- this.router.post(`${this.path}login`, validationMiddleware(CreateUserDto, 'body'), this.authController.logIn);
20
- this.router.post(`${this.path}logout`, authMiddleware, this.authController.logOut);
17
+ this.router.post('/signup', ValidationMiddleware(CreateUserDto, 'body'), this.auth.signUp);
18
+ this.router.post('/login', ValidationMiddleware(CreateUserDto, 'body'), this.auth.logIn);
19
+ this.router.post('/logout', AuthMiddleware, this.auth.logOut);
21
20
  }
22
21
  }
23
-
24
- export default AuthRoute;
@@ -1,25 +1,23 @@
1
1
  import { Router } from 'express';
2
- import UsersController from '@controllers/users.controller';
2
+ import { UserController } from '@controllers/users.controller';
3
3
  import { CreateUserDto } from '@dtos/users.dto';
4
4
  import { Routes } from '@interfaces/routes.interface';
5
- import validationMiddleware from '@middlewares/validation.middleware';
5
+ import { ValidationMiddleware } from '@middlewares/validation.middleware';
6
6
 
7
- class UsersRoute implements Routes {
7
+ export class UserRoute implements Routes {
8
8
  public path = '/users';
9
9
  public router = Router();
10
- public usersController = new UsersController();
10
+ public user = new UserController();
11
11
 
12
12
  constructor() {
13
13
  this.initializeRoutes();
14
14
  }
15
15
 
16
16
  private initializeRoutes() {
17
- this.router.get(`${this.path}`, this.usersController.getUsers);
18
- this.router.get(`${this.path}/:id(\\d+)`, this.usersController.getUserById);
19
- this.router.post(`${this.path}`, validationMiddleware(CreateUserDto, 'body'), this.usersController.createUser);
20
- this.router.put(`${this.path}/:id(\\d+)`, validationMiddleware(CreateUserDto, 'body', true), this.usersController.updateUser);
21
- this.router.delete(`${this.path}/:id(\\d+)`, this.usersController.deleteUser);
17
+ this.router.get(`${this.path}`, this.user.getUsers);
18
+ this.router.get(`${this.path}/:id(\\d+)`, this.user.getUserById);
19
+ this.router.post(`${this.path}`, ValidationMiddleware(CreateUserDto, 'body'), this.user.createUser);
20
+ this.router.put(`${this.path}/:id(\\d+)`, ValidationMiddleware(CreateUserDto, 'body', true), this.user.updateUser);
21
+ this.router.delete(`${this.path}/:id(\\d+)`, this.user.deleteUser);
22
22
  }
23
23
  }
24
-
25
- export default UsersRoute;
@@ -1,11 +1,10 @@
1
- import App from '@/app';
2
- import AuthRoute from '@routes/auth.route';
3
- import IndexRoute from '@routes/index.route';
4
- import UsersRoute from '@routes/users.route';
5
- import validateEnv from '@utils/validateEnv';
1
+ import { App } from '@/app';
2
+ import { AuthRoute } from '@routes/auth.route';
3
+ import { UserRoute } from '@routes/users.route';
4
+ import { ValidateEnv } from '@utils/validateEnv';
6
5
 
7
- validateEnv();
6
+ ValidateEnv();
8
7
 
9
- const app = new App([new IndexRoute(), new UsersRoute(), new AuthRoute()]);
8
+ const app = new App([new AuthRoute(), new UserRoute()]);
10
9
 
11
10
  app.listen();
@@ -1,19 +1,29 @@
1
1
  import { compare, hash } from 'bcrypt';
2
2
  import { sign } from 'jsonwebtoken';
3
+ import { Service } from 'typedi';
3
4
  import { EntityRepository, Repository } from 'typeorm';
4
5
  import { SECRET_KEY } from '@config';
5
- import { CreateUserDto } from '@dtos/users.dto';
6
6
  import { UserEntity } from '@entities/users.entity';
7
- import { HttpException } from '@exceptions/HttpException';
7
+ import { HttpException } from '@/exceptions/httpException';
8
8
  import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
9
9
  import { User } from '@interfaces/users.interface';
10
- import { isEmpty } from '@utils/util';
11
10
 
12
- @EntityRepository()
13
- class AuthService extends Repository<UserEntity> {
14
- public async signup(userData: CreateUserDto): Promise<User> {
15
- if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
11
+ const createToken = (user: User): TokenData => {
12
+ const dataStoredInToken: DataStoredInToken = { id: user.id };
13
+ const secretKey: string = SECRET_KEY;
14
+ const expiresIn: number = 60 * 60;
15
+
16
+ return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
17
+ }
16
18
 
19
+ const createCookie = (tokenData: TokenData): string => {
20
+ return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
21
+ }
22
+
23
+ @Service()
24
+ @EntityRepository()
25
+ export class AuthService extends Repository<UserEntity> {
26
+ public async signup(userData: User): Promise<User> {
17
27
  const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
18
28
  if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
19
29
 
@@ -22,41 +32,23 @@ class AuthService extends Repository<UserEntity> {
22
32
  return createUserData;
23
33
  }
24
34
 
25
- public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
26
- if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
27
-
35
+ public async login(userData: User): Promise<{ cookie: string; findUser: User }> {
28
36
  const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
29
37
  if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
30
38
 
31
39
  const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
32
40
  if (!isPasswordMatching) throw new HttpException(409, "Password not matching");
33
41
 
34
- const tokenData = this.createToken(findUser);
35
- const cookie = this.createCookie(tokenData);
42
+ const tokenData = createToken(findUser);
43
+ const cookie = createCookie(tokenData);
36
44
 
37
45
  return { cookie, findUser };
38
46
  }
39
47
 
40
48
  public async logout(userData: User): Promise<User> {
41
- if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
42
-
43
49
  const findUser: User = await UserEntity.findOne({ where: { email: userData.email, password: userData.password } });
44
50
  if (!findUser) throw new HttpException(409, "User doesn't exist");
45
51
 
46
52
  return findUser;
47
53
  }
48
-
49
- public createToken(user: User): TokenData {
50
- const dataStoredInToken: DataStoredInToken = { id: user.id };
51
- const secretKey: string = SECRET_KEY;
52
- const expiresIn: number = 60 * 60;
53
-
54
- return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
55
- }
56
-
57
- public createCookie(tokenData: TokenData): string {
58
- return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
59
- }
60
54
  }
61
-
62
- export default AuthService;
@@ -1,30 +1,26 @@
1
1
  import { hash } from 'bcrypt';
2
2
  import { EntityRepository, Repository } from 'typeorm';
3
- import { CreateUserDto } from '@dtos/users.dto';
3
+ import { Service } from 'typedi';
4
4
  import { UserEntity } from '@entities/users.entity';
5
- import { HttpException } from '@exceptions/HttpException';
5
+ import { HttpException } from '@/exceptions/httpException';
6
6
  import { User } from '@interfaces/users.interface';
7
- import { isEmpty } from '@utils/util';
8
7
 
8
+ @Service()
9
9
  @EntityRepository()
10
- class UserService extends Repository<UserEntity> {
10
+ export class UserService extends Repository<UserEntity> {
11
11
  public async findAllUser(): Promise<User[]> {
12
12
  const users: User[] = await UserEntity.find();
13
13
  return users;
14
14
  }
15
15
 
16
16
  public async findUserById(userId: number): Promise<User> {
17
- if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
18
-
19
17
  const findUser: User = await UserEntity.findOne({ where: { id: userId } });
20
18
  if (!findUser) throw new HttpException(409, "User doesn't exist");
21
19
 
22
20
  return findUser;
23
21
  }
24
22
 
25
- public async createUser(userData: CreateUserDto): Promise<User> {
26
- if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
27
-
23
+ public async createUser(userData: User): Promise<User> {
28
24
  const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
29
25
  if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
30
26
 
@@ -34,9 +30,7 @@ class UserService extends Repository<UserEntity> {
34
30
  return createUserData;
35
31
  }
36
32
 
37
- public async updateUser(userId: number, userData: CreateUserDto): Promise<User> {
38
- if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
39
-
33
+ public async updateUser(userId: number, userData: User): Promise<User> {
40
34
  const findUser: User = await UserEntity.findOne({ where: { id: userId } });
41
35
  if (!findUser) throw new HttpException(409, "User doesn't exist");
42
36
 
@@ -48,8 +42,6 @@ class UserService extends Repository<UserEntity> {
48
42
  }
49
43
 
50
44
  public async deleteUser(userId: number): Promise<User> {
51
- if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
52
-
53
45
  const findUser: User = await UserEntity.findOne({ where: { id: userId } });
54
46
  if (!findUser) throw new HttpException(409, "User doesn't exist");
55
47
 
@@ -57,5 +49,3 @@ class UserService extends Repository<UserEntity> {
57
49
  return findUser;
58
50
  }
59
51
  }
60
-
61
- export default UserService;
@@ -1,15 +1,15 @@
1
1
  import bcrypt from 'bcrypt';
2
2
  import request from 'supertest';
3
3
  import { createConnection, getConnection, Repository } from 'typeorm';
4
- import App from '@/app';
4
+ import { App } from '@/app';
5
5
  import { dbConnection } from '@databases';
6
6
  import { CreateUserDto } from '@dtos/users.dto';
7
7
  import { UserEntity } from '@entities/users.entity';
8
- import AuthRoute from '@routes/auth.route';
8
+ import { AuthRoute } from '@routes/auth.route';
9
9
 
10
- beforeAll(async () => {
11
- await createConnection(dbConnection);
12
- });
10
+ // beforeAll(async () => {
11
+ // await createConnection(dbConnection);
12
+ // });
13
13
 
14
14
  afterAll(async () => {
15
15
  await getConnection().close();
@@ -1,15 +1,15 @@
1
1
  import bcrypt from 'bcrypt';
2
2
  import request from 'supertest';
3
3
  import { createConnection, getConnection, Repository } from 'typeorm';
4
- import App from '@/app';
4
+ import { App } from '@/app';
5
5
  import { dbConnection } from '@databases';
6
6
  import { CreateUserDto } from '@dtos/users.dto';
7
7
  import { UserEntity } from '@entities/users.entity';
8
- import UserRoute from '@routes/users.route';
8
+ import { UserRoute } from '@routes/users.route';
9
9
 
10
- beforeAll(async () => {
11
- await createConnection(dbConnection);
12
- });
10
+ // beforeAll(async () => {
11
+ // await createConnection(dbConnection);
12
+ // });
13
13
 
14
14
  afterAll(async () => {
15
15
  await getConnection().close();
@@ -1,10 +1,8 @@
1
1
  import { cleanEnv, port, str } from 'envalid';
2
2
 
3
- const validateEnv = () => {
3
+ export const ValidateEnv = () => {
4
4
  cleanEnv(process.env, {
5
5
  NODE_ENV: str(),
6
6
  PORT: port(),
7
7
  });
8
8
  };
9
-
10
- export default validateEnv;
@@ -24,7 +24,7 @@
24
24
  "@/*": ["*"],
25
25
  "@config": ["config"],
26
26
  "@controllers/*": ["controllers/*"],
27
- "@databases": ["databases"],
27
+ "@database": ["database"],
28
28
  "@dtos/*": ["dtos/*"],
29
29
  "@entities/*": ["entities/*"],
30
30
  "@exceptions/*": ["exceptions/*"],
@@ -36,5 +36,5 @@
36
36
  }
37
37
  },
38
38
  "include": ["src/**/*.ts", "src/**/*.json", ".env"],
39
- "exclude": ["node_modules", "src/http", "src/logs", "src/tests"]
39
+ "exclude": ["node_modules", "src/http", "src/logs"]
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-express-starter",
3
- "version": "9.2.0",
3
+ "version": "10.0.0",
4
4
  "description": "Quick and Easy TypeScript Express Starter",
5
5
  "author": "AGUMON <ljlm0402@gmail.com>",
6
6
  "license": "MIT",
@@ -16,6 +16,7 @@
16
16
  "typegoose",
17
17
  "mikro-orm",
18
18
  "routing-controllers",
19
+ "node-postgres",
19
20
  "logger",
20
21
  "swagger",
21
22
  "jest",