typescript-express-starter 10.2.1 → 11.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 (607) hide show
  1. package/README.kr.md +136 -287
  2. package/README.md +134 -274
  3. package/bin/ast-utils.js +226 -0
  4. package/bin/common.js +312 -0
  5. package/bin/config.js +80 -0
  6. package/bin/db-map.js +169 -0
  7. package/bin/errors.js +129 -0
  8. package/bin/performance.js +203 -0
  9. package/bin/starter.js +359 -0
  10. package/bin/validators.js +146 -0
  11. package/devtools/biome/.biome.json +34 -0
  12. package/devtools/biome/.biomeignore +29 -0
  13. package/devtools/docker/.dockerignore +27 -0
  14. package/devtools/docker/Dockerfile.dev +20 -0
  15. package/devtools/docker/Dockerfile.prod +35 -0
  16. package/{lib/default → devtools/docker}/Makefile +3 -0
  17. package/devtools/docker/nginx.conf +67 -0
  18. package/devtools/eslint/eslint.config.cjs +23 -0
  19. package/devtools/husky/.husky/commit-msg +4 -0
  20. package/devtools/husky/.husky/pre-commit +4 -0
  21. package/devtools/husky/.husky/pre-push +4 -0
  22. package/devtools/jest/jest.config.cjs +2 -0
  23. package/devtools/jest/jest.config.ts +25 -0
  24. package/devtools/jest/src/test/e2e/auth.e2e.spec.ts +40 -0
  25. package/devtools/jest/src/test/e2e/users.e2e.spec.ts +63 -0
  26. package/devtools/jest/src/test/setup.ts +31 -0
  27. package/devtools/jest/src/test/unit/entities/user.entity.spec.ts +279 -0
  28. package/devtools/jest/src/test/unit/services/auth.service.spec.ts +75 -0
  29. package/devtools/jest/src/test/unit/services/users.service.spec.ts +109 -0
  30. package/devtools/oxlint/.oxlintrc.json +57 -0
  31. package/devtools/pm2/ecosystem.config.js +59 -0
  32. package/devtools/swagger/swagger.yaml +124 -0
  33. package/{lib/prisma → devtools/swc}/.swcrc +2 -1
  34. package/devtools/tsup/tsup.config.ts +15 -0
  35. package/devtools/vitest/src/test/e2e/auth.e2e.spec.ts +41 -0
  36. package/devtools/vitest/src/test/e2e/users.e2e.spec.ts +64 -0
  37. package/devtools/vitest/src/test/setup.ts +31 -0
  38. package/devtools/vitest/src/test/unit/services/auth.service.spec.ts +70 -0
  39. package/devtools/vitest/src/test/unit/services/users.service.spec.ts +90 -0
  40. package/devtools/vitest/vitest.config.ts +22 -0
  41. package/package.json +24 -11
  42. package/templates/default/nodemon.json +7 -0
  43. package/templates/default/package.json +48 -0
  44. package/templates/default/src/app.ts +118 -0
  45. package/templates/default/src/config/env.ts +78 -0
  46. package/templates/default/src/controllers/auth.controller.ts +40 -0
  47. package/templates/default/src/controllers/users.controller.ts +46 -0
  48. package/templates/default/src/dtos/users.dto.ts +42 -0
  49. package/templates/default/src/entities/user.entity.ts +190 -0
  50. package/templates/default/src/exceptions/httpException.ts +14 -0
  51. package/{lib/knex → templates/default}/src/interfaces/auth.interface.ts +3 -3
  52. package/templates/default/src/interfaces/users.interface.ts +9 -0
  53. package/templates/default/src/middlewares/auth.middleware.ts +49 -0
  54. package/templates/default/src/middlewares/error.middleware.ts +89 -0
  55. package/templates/default/src/middlewares/notFound.middleware.ts +6 -0
  56. package/templates/default/src/middlewares/validation.middleware.ts +15 -0
  57. package/templates/default/src/repositories/users.repository.ts +55 -0
  58. package/templates/default/src/routes/auth.route.ts +31 -0
  59. package/templates/default/src/routes/users.route.ts +32 -0
  60. package/templates/default/src/server.ts +35 -0
  61. package/templates/default/src/services/auth.service.ts +67 -0
  62. package/templates/default/src/services/users.service.ts +48 -0
  63. package/templates/default/src/utils/asyncHandler.ts +8 -0
  64. package/templates/default/src/utils/logger.ts +113 -0
  65. package/{lib/typeorm → templates/default}/tsconfig.json +23 -22
  66. package/CONTRIBUTORS.md +0 -69
  67. package/bin/cli.js +0 -18
  68. package/lib/default/.dockerignore +0 -18
  69. package/lib/default/.editorconfig +0 -9
  70. package/lib/default/.env.development.local +0 -13
  71. package/lib/default/.env.production.local +0 -13
  72. package/lib/default/.env.test.local +0 -13
  73. package/lib/default/.eslintignore +0 -1
  74. package/lib/default/.eslintrc +0 -18
  75. package/lib/default/.huskyrc +0 -5
  76. package/lib/default/.lintstagedrc.json +0 -5
  77. package/lib/default/.prettierrc +0 -8
  78. package/lib/default/.swcrc +0 -39
  79. package/lib/default/.vscode/launch.json +0 -35
  80. package/lib/default/.vscode/settings.json +0 -6
  81. package/lib/default/Dockerfile.dev +0 -18
  82. package/lib/default/Dockerfile.prod +0 -18
  83. package/lib/default/docker-compose.yml +0 -35
  84. package/lib/default/ecosystem.config.js +0 -57
  85. package/lib/default/jest.config.js +0 -12
  86. package/lib/default/nginx.conf +0 -40
  87. package/lib/default/nodemon.json +0 -12
  88. package/lib/default/package.json +0 -76
  89. package/lib/default/src/app.ts +0 -81
  90. package/lib/default/src/config/index.ts +0 -5
  91. package/lib/default/src/controllers/auth.controller.ts +0 -44
  92. package/lib/default/src/controllers/users.controller.ts +0 -63
  93. package/lib/default/src/dtos/users.dto.ts +0 -20
  94. package/lib/default/src/exceptions/HttpException.ts +0 -10
  95. package/lib/default/src/http/auth.http +0 -27
  96. package/lib/default/src/http/users.http +0 -34
  97. package/lib/default/src/interfaces/auth.interface.ts +0 -15
  98. package/lib/default/src/interfaces/users.interface.ts +0 -5
  99. package/lib/default/src/middlewares/auth.middleware.ts +0 -38
  100. package/lib/default/src/middlewares/error.middleware.ts +0 -15
  101. package/lib/default/src/middlewares/validation.middleware.ts +0 -27
  102. package/lib/default/src/models/users.model.ts +0 -9
  103. package/lib/default/src/routes/auth.route.ts +0 -21
  104. package/lib/default/src/routes/users.route.ts +0 -23
  105. package/lib/default/src/server.ts +0 -10
  106. package/lib/default/src/services/auth.service.ts +0 -52
  107. package/lib/default/src/services/users.service.ts +0 -51
  108. package/lib/default/src/test/auth.test.ts +0 -52
  109. package/lib/default/src/test/users.test.ts +0 -62
  110. package/lib/default/src/utils/logger.ts +0 -65
  111. package/lib/default/src/utils/validateEnv.ts +0 -8
  112. package/lib/default/swagger.yaml +0 -123
  113. package/lib/default/tsconfig.json +0 -39
  114. package/lib/graphql/.dockerignore +0 -18
  115. package/lib/graphql/.editorconfig +0 -9
  116. package/lib/graphql/.env.development.local +0 -20
  117. package/lib/graphql/.env.production.local +0 -20
  118. package/lib/graphql/.env.test.local +0 -20
  119. package/lib/graphql/.eslintignore +0 -1
  120. package/lib/graphql/.eslintrc +0 -18
  121. package/lib/graphql/.huskyrc +0 -5
  122. package/lib/graphql/.lintstagedrc.json +0 -5
  123. package/lib/graphql/.prettierrc +0 -8
  124. package/lib/graphql/.swcrc +0 -40
  125. package/lib/graphql/.vscode/launch.json +0 -35
  126. package/lib/graphql/.vscode/settings.json +0 -6
  127. package/lib/graphql/Dockerfile.dev +0 -19
  128. package/lib/graphql/Dockerfile.prod +0 -19
  129. package/lib/graphql/Makefile +0 -46
  130. package/lib/graphql/docker-compose.yml +0 -58
  131. package/lib/graphql/ecosystem.config.js +0 -59
  132. package/lib/graphql/jest.config.js +0 -12
  133. package/lib/graphql/nginx.conf +0 -40
  134. package/lib/graphql/nodemon.json +0 -12
  135. package/lib/graphql/package.json +0 -75
  136. package/lib/graphql/src/app.ts +0 -107
  137. package/lib/graphql/src/config/index.ts +0 -6
  138. package/lib/graphql/src/database/index.ts +0 -26
  139. package/lib/graphql/src/dtos/users.dto.ts +0 -27
  140. package/lib/graphql/src/entities/users.entity.ts +0 -26
  141. package/lib/graphql/src/exceptions/HttpException.ts +0 -10
  142. package/lib/graphql/src/http/auth.http +0 -49
  143. package/lib/graphql/src/http/users.http +0 -78
  144. package/lib/graphql/src/interfaces/auth.interface.ts +0 -14
  145. package/lib/graphql/src/interfaces/users.interface.ts +0 -5
  146. package/lib/graphql/src/middlewares/auth.middleware.ts +0 -42
  147. package/lib/graphql/src/middlewares/error.middleware.ts +0 -15
  148. package/lib/graphql/src/repositories/auth.repository.ts +0 -53
  149. package/lib/graphql/src/repositories/users.repository.ts +0 -51
  150. package/lib/graphql/src/resolvers/auth.resolver.ts +0 -32
  151. package/lib/graphql/src/resolvers/users.resolver.ts +0 -47
  152. package/lib/graphql/src/server.ts +0 -10
  153. package/lib/graphql/src/test/auth.test.ts +0 -10
  154. package/lib/graphql/src/test/users.test.ts +0 -11
  155. package/lib/graphql/src/typedefs/users.type.ts +0 -13
  156. package/lib/graphql/src/utils/logger.ts +0 -77
  157. package/lib/graphql/src/utils/validateEnv.ts +0 -8
  158. package/lib/graphql/tsconfig.json +0 -40
  159. package/lib/knex/.dockerignore +0 -18
  160. package/lib/knex/.editorconfig +0 -9
  161. package/lib/knex/.env.development.local +0 -20
  162. package/lib/knex/.env.production.local +0 -20
  163. package/lib/knex/.env.test.local +0 -20
  164. package/lib/knex/.eslintignore +0 -1
  165. package/lib/knex/.eslintrc +0 -18
  166. package/lib/knex/.huskyrc +0 -5
  167. package/lib/knex/.lintstagedrc.json +0 -5
  168. package/lib/knex/.prettierrc +0 -8
  169. package/lib/knex/.swcrc +0 -40
  170. package/lib/knex/.vscode/launch.json +0 -35
  171. package/lib/knex/.vscode/settings.json +0 -6
  172. package/lib/knex/Dockerfile.dev +0 -19
  173. package/lib/knex/Dockerfile.prod +0 -19
  174. package/lib/knex/Makefile +0 -46
  175. package/lib/knex/docker-compose.yml +0 -55
  176. package/lib/knex/ecosystem.config.js +0 -57
  177. package/lib/knex/jest.config.js +0 -12
  178. package/lib/knex/knexfile.ts +0 -23
  179. package/lib/knex/nginx.conf +0 -40
  180. package/lib/knex/nodemon.json +0 -12
  181. package/lib/knex/package.json +0 -85
  182. package/lib/knex/src/app.ts +0 -87
  183. package/lib/knex/src/config/index.ts +0 -6
  184. package/lib/knex/src/controllers/auth.controller.ts +0 -44
  185. package/lib/knex/src/controllers/users.controller.ts +0 -63
  186. package/lib/knex/src/database/index.ts +0 -24
  187. package/lib/knex/src/database/migrations/.gitkeep +0 -0
  188. package/lib/knex/src/database/migrations/20210713110926_initial.ts +0 -17
  189. package/lib/knex/src/database/seeds/.gitkeep +0 -0
  190. package/lib/knex/src/dtos/users.dto.ts +0 -20
  191. package/lib/knex/src/exceptions/HttpException.ts +0 -10
  192. package/lib/knex/src/http/auth.http +0 -27
  193. package/lib/knex/src/http/users.http +0 -34
  194. package/lib/knex/src/interfaces/routes.interface.ts +0 -6
  195. package/lib/knex/src/interfaces/users.interface.ts +0 -5
  196. package/lib/knex/src/middlewares/auth.middleware.ts +0 -40
  197. package/lib/knex/src/middlewares/error.middleware.ts +0 -15
  198. package/lib/knex/src/middlewares/validation.middleware.ts +0 -27
  199. package/lib/knex/src/models/users.model.ts +0 -13
  200. package/lib/knex/src/routes/auth.route.ts +0 -22
  201. package/lib/knex/src/routes/users.route.ts +0 -23
  202. package/lib/knex/src/server.ts +0 -10
  203. package/lib/knex/src/services/auth.service.ts +0 -60
  204. package/lib/knex/src/services/users.service.ts +0 -55
  205. package/lib/knex/src/test/auth.test.ts +0 -51
  206. package/lib/knex/src/test/users.test.ts +0 -65
  207. package/lib/knex/src/utils/logger.ts +0 -65
  208. package/lib/knex/src/utils/validateEnv.ts +0 -8
  209. package/lib/knex/swagger.yaml +0 -123
  210. package/lib/knex/tsconfig.json +0 -40
  211. package/lib/mikro-orm/.dockerignore +0 -18
  212. package/lib/mikro-orm/.editorconfig +0 -9
  213. package/lib/mikro-orm/.env.development.local +0 -18
  214. package/lib/mikro-orm/.env.production.local +0 -18
  215. package/lib/mikro-orm/.env.test.local +0 -18
  216. package/lib/mikro-orm/.eslintignore +0 -1
  217. package/lib/mikro-orm/.eslintrc +0 -18
  218. package/lib/mikro-orm/.huskyrc +0 -5
  219. package/lib/mikro-orm/.lintstagedrc.json +0 -5
  220. package/lib/mikro-orm/.prettierrc +0 -8
  221. package/lib/mikro-orm/.swcrc +0 -41
  222. package/lib/mikro-orm/.vscode/launch.json +0 -35
  223. package/lib/mikro-orm/.vscode/settings.json +0 -6
  224. package/lib/mikro-orm/Dockerfile.dev +0 -19
  225. package/lib/mikro-orm/Dockerfile.prod +0 -19
  226. package/lib/mikro-orm/Makefile +0 -46
  227. package/lib/mikro-orm/docker-compose.yml +0 -55
  228. package/lib/mikro-orm/ecosystem.config.js +0 -57
  229. package/lib/mikro-orm/jest.config.js +0 -12
  230. package/lib/mikro-orm/nginx.conf +0 -40
  231. package/lib/mikro-orm/nodemon.json +0 -12
  232. package/lib/mikro-orm/package.json +0 -79
  233. package/lib/mikro-orm/src/app.ts +0 -97
  234. package/lib/mikro-orm/src/config/index.ts +0 -6
  235. package/lib/mikro-orm/src/controllers/auth.controller.ts +0 -44
  236. package/lib/mikro-orm/src/controllers/users.controller.ts +0 -63
  237. package/lib/mikro-orm/src/database/index.ts +0 -19
  238. package/lib/mikro-orm/src/dtos/users.dto.ts +0 -20
  239. package/lib/mikro-orm/src/entities/base.entity.ts +0 -16
  240. package/lib/mikro-orm/src/entities/users.entity.ts +0 -17
  241. package/lib/mikro-orm/src/exceptions/HttpException.ts +0 -10
  242. package/lib/mikro-orm/src/http/auth.http +0 -32
  243. package/lib/mikro-orm/src/http/users.http +0 -34
  244. package/lib/mikro-orm/src/interfaces/auth.interface.ts +0 -15
  245. package/lib/mikro-orm/src/interfaces/routes.interface.ts +0 -6
  246. package/lib/mikro-orm/src/interfaces/users.interface.ts +0 -5
  247. package/lib/mikro-orm/src/middlewares/auth.middleware.ts +0 -39
  248. package/lib/mikro-orm/src/middlewares/error.middleware.ts +0 -15
  249. package/lib/mikro-orm/src/middlewares/validation.middleware.ts +0 -27
  250. package/lib/mikro-orm/src/routes/auth.route.ts +0 -22
  251. package/lib/mikro-orm/src/routes/users.route.ts +0 -23
  252. package/lib/mikro-orm/src/server.ts +0 -10
  253. package/lib/mikro-orm/src/services/auth.service.ts +0 -53
  254. package/lib/mikro-orm/src/services/users.service.ts +0 -60
  255. package/lib/mikro-orm/src/test/auth.test.ts +0 -65
  256. package/lib/mikro-orm/src/test/users.test.ts +0 -69
  257. package/lib/mikro-orm/src/utils/logger.ts +0 -65
  258. package/lib/mikro-orm/src/utils/validateEnv.ts +0 -8
  259. package/lib/mikro-orm/swagger.yaml +0 -122
  260. package/lib/mikro-orm/tsconfig.json +0 -41
  261. package/lib/mongoose/.dockerignore +0 -18
  262. package/lib/mongoose/.editorconfig +0 -9
  263. package/lib/mongoose/.env.development.local +0 -18
  264. package/lib/mongoose/.env.production.local +0 -18
  265. package/lib/mongoose/.env.test.local +0 -18
  266. package/lib/mongoose/.eslintignore +0 -1
  267. package/lib/mongoose/.eslintrc +0 -18
  268. package/lib/mongoose/.huskyrc +0 -5
  269. package/lib/mongoose/.lintstagedrc.json +0 -5
  270. package/lib/mongoose/.prettierrc +0 -8
  271. package/lib/mongoose/.swcrc +0 -40
  272. package/lib/mongoose/.vscode/launch.json +0 -35
  273. package/lib/mongoose/.vscode/settings.json +0 -6
  274. package/lib/mongoose/Dockerfile.dev +0 -19
  275. package/lib/mongoose/Dockerfile.prod +0 -19
  276. package/lib/mongoose/Makefile +0 -46
  277. package/lib/mongoose/docker-compose.yml +0 -55
  278. package/lib/mongoose/ecosystem.config.js +0 -57
  279. package/lib/mongoose/jest.config.js +0 -12
  280. package/lib/mongoose/nginx.conf +0 -40
  281. package/lib/mongoose/nodemon.json +0 -12
  282. package/lib/mongoose/package.json +0 -78
  283. package/lib/mongoose/src/app.ts +0 -87
  284. package/lib/mongoose/src/config/index.ts +0 -6
  285. package/lib/mongoose/src/controllers/auth.controller.ts +0 -44
  286. package/lib/mongoose/src/controllers/users.controller.ts +0 -63
  287. package/lib/mongoose/src/database/index.ts +0 -18
  288. package/lib/mongoose/src/dtos/users.dto.ts +0 -20
  289. package/lib/mongoose/src/exceptions/HttpException.ts +0 -10
  290. package/lib/mongoose/src/http/auth.http +0 -27
  291. package/lib/mongoose/src/http/users.http +0 -34
  292. package/lib/mongoose/src/interfaces/auth.interface.ts +0 -15
  293. package/lib/mongoose/src/interfaces/routes.interface.ts +0 -6
  294. package/lib/mongoose/src/interfaces/users.interface.ts +0 -5
  295. package/lib/mongoose/src/middlewares/auth.middleware.ts +0 -39
  296. package/lib/mongoose/src/middlewares/error.middleware.ts +0 -15
  297. package/lib/mongoose/src/middlewares/validation.middleware.ts +0 -27
  298. package/lib/mongoose/src/models/users.model.ts +0 -16
  299. package/lib/mongoose/src/routes/auth.route.ts +0 -22
  300. package/lib/mongoose/src/routes/users.route.ts +0 -23
  301. package/lib/mongoose/src/server.ts +0 -10
  302. package/lib/mongoose/src/services/auth.service.ts +0 -52
  303. package/lib/mongoose/src/services/users.service.ts +0 -54
  304. package/lib/mongoose/src/test/auth.test.ts +0 -83
  305. package/lib/mongoose/src/test/index.test.ts +0 -18
  306. package/lib/mongoose/src/test/users.test.ts +0 -133
  307. package/lib/mongoose/src/utils/logger.ts +0 -65
  308. package/lib/mongoose/src/utils/validateEnv.ts +0 -8
  309. package/lib/mongoose/swagger.yaml +0 -120
  310. package/lib/mongoose/tsconfig.json +0 -40
  311. package/lib/node-postgres/.dockerignore +0 -18
  312. package/lib/node-postgres/.editorconfig +0 -9
  313. package/lib/node-postgres/.env.development.local +0 -20
  314. package/lib/node-postgres/.env.production.local +0 -20
  315. package/lib/node-postgres/.env.test.local +0 -20
  316. package/lib/node-postgres/.eslintignore +0 -1
  317. package/lib/node-postgres/.eslintrc +0 -18
  318. package/lib/node-postgres/.huskyrc +0 -5
  319. package/lib/node-postgres/.lintstagedrc.json +0 -5
  320. package/lib/node-postgres/.prettierrc +0 -8
  321. package/lib/node-postgres/.swcrc +0 -38
  322. package/lib/node-postgres/.vscode/launch.json +0 -35
  323. package/lib/node-postgres/.vscode/settings.json +0 -6
  324. package/lib/node-postgres/Dockerfile.dev +0 -17
  325. package/lib/node-postgres/Dockerfile.prod +0 -17
  326. package/lib/node-postgres/Makefile +0 -46
  327. package/lib/node-postgres/docker-compose.yml +0 -61
  328. package/lib/node-postgres/ecosystem.config.js +0 -57
  329. package/lib/node-postgres/jest.config.js +0 -12
  330. package/lib/node-postgres/nginx.conf +0 -40
  331. package/lib/node-postgres/nodemon.json +0 -12
  332. package/lib/node-postgres/package.json +0 -78
  333. package/lib/node-postgres/src/app.ts +0 -81
  334. package/lib/node-postgres/src/config/index.ts +0 -6
  335. package/lib/node-postgres/src/controllers/auth.controller.ts +0 -44
  336. package/lib/node-postgres/src/controllers/users.controller.ts +0 -63
  337. package/lib/node-postgres/src/database/index.ts +0 -10
  338. package/lib/node-postgres/src/database/init.sql +0 -13
  339. package/lib/node-postgres/src/dtos/users.dto.ts +0 -20
  340. package/lib/node-postgres/src/exceptions/httpException.ts +0 -10
  341. package/lib/node-postgres/src/http/auth.http +0 -27
  342. package/lib/node-postgres/src/http/users.http +0 -34
  343. package/lib/node-postgres/src/interfaces/auth.interface.ts +0 -15
  344. package/lib/node-postgres/src/interfaces/routes.interface.ts +0 -6
  345. package/lib/node-postgres/src/interfaces/users.interface.ts +0 -5
  346. package/lib/node-postgres/src/middlewares/auth.middleware.ts +0 -46
  347. package/lib/node-postgres/src/middlewares/error.middleware.ts +0 -15
  348. package/lib/node-postgres/src/middlewares/validation.middleware.ts +0 -27
  349. package/lib/node-postgres/src/routes/auth.route.ts +0 -21
  350. package/lib/node-postgres/src/routes/users.route.ts +0 -23
  351. package/lib/node-postgres/src/server.ts +0 -10
  352. package/lib/node-postgres/src/services/auth.service.ts +0 -103
  353. package/lib/node-postgres/src/services/users.service.ts +0 -133
  354. package/lib/node-postgres/src/test/auth.test.ts +0 -57
  355. package/lib/node-postgres/src/test/users.test.ts +0 -72
  356. package/lib/node-postgres/src/utils/logger.ts +0 -65
  357. package/lib/node-postgres/src/utils/validateEnv.ts +0 -8
  358. package/lib/node-postgres/swagger.yaml +0 -123
  359. package/lib/node-postgres/tsconfig.json +0 -39
  360. package/lib/prisma/.dockerignore +0 -18
  361. package/lib/prisma/.editorconfig +0 -9
  362. package/lib/prisma/.env.development.local +0 -16
  363. package/lib/prisma/.env.production.local +0 -16
  364. package/lib/prisma/.env.test.local +0 -16
  365. package/lib/prisma/.eslintignore +0 -1
  366. package/lib/prisma/.eslintrc +0 -18
  367. package/lib/prisma/.huskyrc +0 -5
  368. package/lib/prisma/.lintstagedrc.json +0 -5
  369. package/lib/prisma/.prettierrc +0 -8
  370. package/lib/prisma/.vscode/launch.json +0 -35
  371. package/lib/prisma/.vscode/settings.json +0 -6
  372. package/lib/prisma/Dockerfile.dev +0 -19
  373. package/lib/prisma/Dockerfile.prod +0 -19
  374. package/lib/prisma/Makefile +0 -46
  375. package/lib/prisma/docker-compose.yml +0 -51
  376. package/lib/prisma/ecosystem.config.js +0 -57
  377. package/lib/prisma/jest.config.js +0 -12
  378. package/lib/prisma/nginx.conf +0 -40
  379. package/lib/prisma/nodemon.json +0 -12
  380. package/lib/prisma/package.json +0 -84
  381. package/lib/prisma/src/app.ts +0 -81
  382. package/lib/prisma/src/config/index.ts +0 -5
  383. package/lib/prisma/src/controllers/auth.controller.ts +0 -44
  384. package/lib/prisma/src/controllers/users.controller.ts +0 -63
  385. package/lib/prisma/src/dtos/users.dto.ts +0 -20
  386. package/lib/prisma/src/exceptions/HttpException.ts +0 -10
  387. package/lib/prisma/src/http/auth.http +0 -27
  388. package/lib/prisma/src/http/users.http +0 -34
  389. package/lib/prisma/src/interfaces/auth.interface.ts +0 -15
  390. package/lib/prisma/src/interfaces/routes.interface.ts +0 -6
  391. package/lib/prisma/src/interfaces/users.interface.ts +0 -5
  392. package/lib/prisma/src/middlewares/auth.middleware.ts +0 -39
  393. package/lib/prisma/src/middlewares/error.middleware.ts +0 -15
  394. package/lib/prisma/src/middlewares/validation.middleware.ts +0 -27
  395. package/lib/prisma/src/prisma/migrations/20210314081925_initial/migration.sql +0 -9
  396. package/lib/prisma/src/prisma/migrations/migration_lock.toml +0 -3
  397. package/lib/prisma/src/prisma/schema.prisma +0 -17
  398. package/lib/prisma/src/routes/auth.route.ts +0 -22
  399. package/lib/prisma/src/routes/users.route.ts +0 -23
  400. package/lib/prisma/src/server.ts +0 -10
  401. package/lib/prisma/src/services/auth.service.ts +0 -56
  402. package/lib/prisma/src/services/users.service.ts +0 -49
  403. package/lib/prisma/src/test/auth.test.ts +0 -81
  404. package/lib/prisma/src/test/index.test.ts +0 -18
  405. package/lib/prisma/src/test/users.test.ts +0 -134
  406. package/lib/prisma/src/utils/logger.ts +0 -65
  407. package/lib/prisma/src/utils/validateEnv.ts +0 -8
  408. package/lib/prisma/swagger.yaml +0 -123
  409. package/lib/prisma/tsconfig.json +0 -38
  410. package/lib/routing-controllers/.dockerignore +0 -18
  411. package/lib/routing-controllers/.editorconfig +0 -9
  412. package/lib/routing-controllers/.env.development.local +0 -13
  413. package/lib/routing-controllers/.env.production.local +0 -13
  414. package/lib/routing-controllers/.env.test.local +0 -13
  415. package/lib/routing-controllers/.eslintignore +0 -1
  416. package/lib/routing-controllers/.eslintrc +0 -18
  417. package/lib/routing-controllers/.huskyrc +0 -5
  418. package/lib/routing-controllers/.lintstagedrc.json +0 -5
  419. package/lib/routing-controllers/.prettierrc +0 -8
  420. package/lib/routing-controllers/.swcrc +0 -38
  421. package/lib/routing-controllers/.vscode/launch.json +0 -35
  422. package/lib/routing-controllers/.vscode/settings.json +0 -6
  423. package/lib/routing-controllers/Dockerfile.dev +0 -19
  424. package/lib/routing-controllers/Dockerfile.prod +0 -19
  425. package/lib/routing-controllers/Makefile +0 -42
  426. package/lib/routing-controllers/docker-compose.yml +0 -35
  427. package/lib/routing-controllers/ecosystem.config.js +0 -57
  428. package/lib/routing-controllers/jest.config.js +0 -12
  429. package/lib/routing-controllers/nginx.conf +0 -40
  430. package/lib/routing-controllers/nodemon.json +0 -12
  431. package/lib/routing-controllers/package.json +0 -77
  432. package/lib/routing-controllers/src/app.ts +0 -101
  433. package/lib/routing-controllers/src/config/index.ts +0 -5
  434. package/lib/routing-controllers/src/controllers/auth.controller.ts +0 -41
  435. package/lib/routing-controllers/src/controllers/users.controller.ts +0 -51
  436. package/lib/routing-controllers/src/dtos/users.dto.ts +0 -20
  437. package/lib/routing-controllers/src/exceptions/HttpException.ts +0 -12
  438. package/lib/routing-controllers/src/http/auth.http +0 -27
  439. package/lib/routing-controllers/src/http/users.http +0 -34
  440. package/lib/routing-controllers/src/interfaces/auth.interface.ts +0 -15
  441. package/lib/routing-controllers/src/interfaces/users.interface.ts +0 -5
  442. package/lib/routing-controllers/src/middlewares/auth.middleware.ts +0 -38
  443. package/lib/routing-controllers/src/middlewares/error.middleware.ts +0 -15
  444. package/lib/routing-controllers/src/middlewares/validation.middleware.ts +0 -27
  445. package/lib/routing-controllers/src/models/users.model.ts +0 -9
  446. package/lib/routing-controllers/src/server.ts +0 -9
  447. package/lib/routing-controllers/src/services/auth.service.ts +0 -53
  448. package/lib/routing-controllers/src/services/users.service.ts +0 -52
  449. package/lib/routing-controllers/src/test/auth.test.ts +0 -49
  450. package/lib/routing-controllers/src/test/users.test.ts +0 -65
  451. package/lib/routing-controllers/src/utils/logger.ts +0 -65
  452. package/lib/routing-controllers/src/utils/validateEnv.ts +0 -8
  453. package/lib/routing-controllers/tsconfig.json +0 -38
  454. package/lib/sequelize/.dockerignore +0 -18
  455. package/lib/sequelize/.editorconfig +0 -9
  456. package/lib/sequelize/.env.development.local +0 -20
  457. package/lib/sequelize/.env.production.local +0 -20
  458. package/lib/sequelize/.env.test.local +0 -20
  459. package/lib/sequelize/.eslintignore +0 -1
  460. package/lib/sequelize/.eslintrc +0 -18
  461. package/lib/sequelize/.huskyrc +0 -5
  462. package/lib/sequelize/.lintstagedrc.json +0 -5
  463. package/lib/sequelize/.prettierrc +0 -8
  464. package/lib/sequelize/.sequelizerc +0 -8
  465. package/lib/sequelize/.swcrc +0 -40
  466. package/lib/sequelize/.vscode/launch.json +0 -35
  467. package/lib/sequelize/.vscode/settings.json +0 -6
  468. package/lib/sequelize/Dockerfile.dev +0 -23
  469. package/lib/sequelize/Dockerfile.prod +0 -23
  470. package/lib/sequelize/Makefile +0 -46
  471. package/lib/sequelize/docker-compose.yml +0 -55
  472. package/lib/sequelize/docker-entrypoint.sh +0 -5
  473. package/lib/sequelize/ecosystem.config.js +0 -57
  474. package/lib/sequelize/jest.config.js +0 -12
  475. package/lib/sequelize/nginx.conf +0 -40
  476. package/lib/sequelize/nodemon.json +0 -12
  477. package/lib/sequelize/package.json +0 -82
  478. package/lib/sequelize/src/app.ts +0 -87
  479. package/lib/sequelize/src/config/index.ts +0 -6
  480. package/lib/sequelize/src/config/sequelize-cli.js +0 -15
  481. package/lib/sequelize/src/controllers/auth.controller.ts +0 -45
  482. package/lib/sequelize/src/controllers/users.controller.ts +0 -64
  483. package/lib/sequelize/src/database/index.ts +0 -34
  484. package/lib/sequelize/src/database/migrations/.gitkeep +0 -0
  485. package/lib/sequelize/src/database/seeders/.gitkeep +0 -0
  486. package/lib/sequelize/src/dtos/users.dto.ts +0 -20
  487. package/lib/sequelize/src/exceptions/HttpException.ts +0 -10
  488. package/lib/sequelize/src/http/auth.http +0 -27
  489. package/lib/sequelize/src/http/users.http +0 -34
  490. package/lib/sequelize/src/interfaces/auth.interface.ts +0 -15
  491. package/lib/sequelize/src/interfaces/routes.interface.ts +0 -6
  492. package/lib/sequelize/src/interfaces/users.interface.ts +0 -5
  493. package/lib/sequelize/src/middlewares/auth.middleware.ts +0 -38
  494. package/lib/sequelize/src/middlewares/error.middleware.ts +0 -15
  495. package/lib/sequelize/src/middlewares/validation.middleware.ts +0 -27
  496. package/lib/sequelize/src/models/users.model.ts +0 -39
  497. package/lib/sequelize/src/routes/auth.route.ts +0 -21
  498. package/lib/sequelize/src/routes/users.route.ts +0 -23
  499. package/lib/sequelize/src/server.ts +0 -10
  500. package/lib/sequelize/src/services/auth.service.ts +0 -52
  501. package/lib/sequelize/src/services/users.service.ts +0 -50
  502. package/lib/sequelize/src/test/auth.test.ts +0 -71
  503. package/lib/sequelize/src/test/users.test.ts +0 -131
  504. package/lib/sequelize/src/utils/logger.ts +0 -65
  505. package/lib/sequelize/src/utils/validateEnv.ts +0 -8
  506. package/lib/sequelize/swagger.yaml +0 -123
  507. package/lib/sequelize/tsconfig.json +0 -40
  508. package/lib/starter.js +0 -262
  509. package/lib/typegoose/.dockerignore +0 -18
  510. package/lib/typegoose/.editorconfig +0 -9
  511. package/lib/typegoose/.env.development.local +0 -18
  512. package/lib/typegoose/.env.production.local +0 -18
  513. package/lib/typegoose/.env.test.local +0 -18
  514. package/lib/typegoose/.eslintignore +0 -1
  515. package/lib/typegoose/.eslintrc +0 -18
  516. package/lib/typegoose/.huskyrc +0 -5
  517. package/lib/typegoose/.lintstagedrc.json +0 -5
  518. package/lib/typegoose/.prettierrc +0 -8
  519. package/lib/typegoose/.swcrc +0 -40
  520. package/lib/typegoose/.vscode/launch.json +0 -35
  521. package/lib/typegoose/.vscode/settings.json +0 -6
  522. package/lib/typegoose/Dockerfile.dev +0 -19
  523. package/lib/typegoose/Dockerfile.prod +0 -19
  524. package/lib/typegoose/Makefile +0 -46
  525. package/lib/typegoose/docker-compose.yml +0 -55
  526. package/lib/typegoose/ecosystem.config.js +0 -57
  527. package/lib/typegoose/jest.config.js +0 -12
  528. package/lib/typegoose/nginx.conf +0 -40
  529. package/lib/typegoose/nodemon.json +0 -12
  530. package/lib/typegoose/package.json +0 -79
  531. package/lib/typegoose/src/app.ts +0 -90
  532. package/lib/typegoose/src/config/index.ts +0 -6
  533. package/lib/typegoose/src/controllers/auth.controller.ts +0 -44
  534. package/lib/typegoose/src/controllers/users.controller.ts +0 -63
  535. package/lib/typegoose/src/database/index.ts +0 -18
  536. package/lib/typegoose/src/dtos/users.dto.ts +0 -20
  537. package/lib/typegoose/src/exceptions/HttpException.ts +0 -10
  538. package/lib/typegoose/src/http/auth.http +0 -27
  539. package/lib/typegoose/src/http/users.http +0 -34
  540. package/lib/typegoose/src/interfaces/auth.interface.ts +0 -15
  541. package/lib/typegoose/src/interfaces/routes.interface.ts +0 -6
  542. package/lib/typegoose/src/interfaces/users.interface.ts +0 -5
  543. package/lib/typegoose/src/middlewares/auth.middleware.ts +0 -38
  544. package/lib/typegoose/src/middlewares/error.middleware.ts +0 -15
  545. package/lib/typegoose/src/middlewares/validation.middleware.ts +0 -27
  546. package/lib/typegoose/src/models/users.model.ts +0 -16
  547. package/lib/typegoose/src/routes/auth.route.ts +0 -21
  548. package/lib/typegoose/src/routes/users.route.ts +0 -23
  549. package/lib/typegoose/src/server.ts +0 -10
  550. package/lib/typegoose/src/services/auth.service.ts +0 -52
  551. package/lib/typegoose/src/services/users.service.ts +0 -55
  552. package/lib/typegoose/src/test/auth.test.ts +0 -83
  553. package/lib/typegoose/src/test/users.test.ts +0 -133
  554. package/lib/typegoose/src/utils/logger.ts +0 -65
  555. package/lib/typegoose/src/utils/validateEnv.ts +0 -8
  556. package/lib/typegoose/swagger.yaml +0 -120
  557. package/lib/typegoose/tsconfig.json +0 -40
  558. package/lib/typeorm/.dockerignore +0 -18
  559. package/lib/typeorm/.editorconfig +0 -9
  560. package/lib/typeorm/.env.development.local +0 -20
  561. package/lib/typeorm/.env.production.local +0 -20
  562. package/lib/typeorm/.env.test.local +0 -20
  563. package/lib/typeorm/.eslintignore +0 -1
  564. package/lib/typeorm/.eslintrc +0 -18
  565. package/lib/typeorm/.huskyrc +0 -5
  566. package/lib/typeorm/.lintstagedrc.json +0 -5
  567. package/lib/typeorm/.prettierrc +0 -8
  568. package/lib/typeorm/.swcrc +0 -40
  569. package/lib/typeorm/.vscode/launch.json +0 -35
  570. package/lib/typeorm/.vscode/settings.json +0 -6
  571. package/lib/typeorm/Dockerfile.dev +0 -19
  572. package/lib/typeorm/Dockerfile.prod +0 -19
  573. package/lib/typeorm/Makefile +0 -46
  574. package/lib/typeorm/docker-compose.yml +0 -57
  575. package/lib/typeorm/ecosystem.config.js +0 -57
  576. package/lib/typeorm/jest.config.js +0 -12
  577. package/lib/typeorm/nginx.conf +0 -40
  578. package/lib/typeorm/nodemon.json +0 -12
  579. package/lib/typeorm/package.json +0 -78
  580. package/lib/typeorm/src/app.ts +0 -87
  581. package/lib/typeorm/src/config/index.ts +0 -6
  582. package/lib/typeorm/src/controllers/auth.controller.ts +0 -44
  583. package/lib/typeorm/src/controllers/users.controller.ts +0 -63
  584. package/lib/typeorm/src/database/index.ts +0 -26
  585. package/lib/typeorm/src/database/migrations/.gitkeep +0 -0
  586. package/lib/typeorm/src/dtos/users.dto.ts +0 -20
  587. package/lib/typeorm/src/entities/users.entity.ts +0 -26
  588. package/lib/typeorm/src/exceptions/HttpException.ts +0 -10
  589. package/lib/typeorm/src/http/auth.http +0 -27
  590. package/lib/typeorm/src/http/users.http +0 -34
  591. package/lib/typeorm/src/interfaces/auth.interface.ts +0 -15
  592. package/lib/typeorm/src/interfaces/routes.interface.ts +0 -6
  593. package/lib/typeorm/src/interfaces/users.interface.ts +0 -5
  594. package/lib/typeorm/src/middlewares/auth.middleware.ts +0 -38
  595. package/lib/typeorm/src/middlewares/error.middleware.ts +0 -15
  596. package/lib/typeorm/src/middlewares/validation.middleware.ts +0 -27
  597. package/lib/typeorm/src/routes/auth.route.ts +0 -21
  598. package/lib/typeorm/src/routes/users.route.ts +0 -23
  599. package/lib/typeorm/src/server.ts +0 -10
  600. package/lib/typeorm/src/services/auth.service.ts +0 -54
  601. package/lib/typeorm/src/services/users.service.ts +0 -51
  602. package/lib/typeorm/src/test/auth.test.ts +0 -75
  603. package/lib/typeorm/src/test/users.test.ts +0 -136
  604. package/lib/typeorm/src/utils/logger.ts +0 -65
  605. package/lib/typeorm/src/utils/validateEnv.ts +0 -8
  606. package/lib/typeorm/swagger.yaml +0 -123
  607. /package/{lib → templates}/default/src/interfaces/routes.interface.ts +0 -0
@@ -1,15 +0,0 @@
1
- import { Request } from 'express';
2
- import { User } from '@interfaces/users.interface';
3
-
4
- export interface DataStoredInToken {
5
- id: number;
6
- }
7
-
8
- export interface TokenData {
9
- token: string;
10
- expiresIn: number;
11
- }
12
-
13
- export interface RequestWithUser extends Request {
14
- user: User;
15
- }
@@ -1,6 +0,0 @@
1
- import { Router } from 'express';
2
-
3
- export interface Routes {
4
- path?: string;
5
- router: Router;
6
- }
@@ -1,5 +0,0 @@
1
- export interface User {
2
- id?: number;
3
- email: string;
4
- password: string;
5
- }
@@ -1,46 +0,0 @@
1
- import { NextFunction, Response } from 'express';
2
- import { verify } from 'jsonwebtoken';
3
- import { SECRET_KEY } from '@config';
4
- import pg from '@database';
5
- import { HttpException } from '@exceptions/httpException';
6
- import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
7
-
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) => {
19
- try {
20
- const Authorization = getAuthorization(req);
21
-
22
- if (Authorization) {
23
- const { id } = (await verify(Authorization, SECRET_KEY)) as DataStoredInToken;
24
- const { rows, rowCount } = await pg.query(`
25
- SELECT
26
- "email",
27
- "password"
28
- FROM
29
- users
30
- WHERE
31
- "id" = $1
32
- `, id);
33
-
34
- if (rowCount) {
35
- req.user = rows[0];
36
- next();
37
- } else {
38
- next(new HttpException(401, 'Wrong authentication token'));
39
- }
40
- } else {
41
- next(new HttpException(404, 'Authentication token missing'));
42
- }
43
- } catch (error) {
44
- next(new HttpException(401, 'Wrong authentication token'));
45
- }
46
- };
@@ -1,15 +0,0 @@
1
- import { NextFunction, Request, Response } from 'express';
2
- import { HttpException } from '@exceptions/httpException';
3
- import { logger } from '@utils/logger';
4
-
5
- export const ErrorMiddleware = (error: HttpException, req: Request, res: Response, next: NextFunction) => {
6
- try {
7
- const status: number = error.status || 500;
8
- const message: string = error.message || 'Something went wrong';
9
-
10
- logger.error(`[${req.method}] ${req.path} >> StatusCode:: ${status}, Message:: ${message}`);
11
- res.status(status).json({ message });
12
- } catch (error) {
13
- next(error);
14
- }
15
- };
@@ -1,27 +0,0 @@
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
-
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[]) => {
23
- const message = errors.map((error: ValidationError) => Object.values(error.constraints)).join(', ');
24
- next(new HttpException(400, message));
25
- });
26
- };
27
- };
@@ -1,21 +0,0 @@
1
- import { Router } from 'express';
2
- import { AuthController } from '@controllers/auth.controller';
3
- import { CreateUserDto } from '@dtos/users.dto';
4
- import { Routes } from '@interfaces/routes.interface';
5
- import { AuthMiddleware } from '@middlewares/auth.middleware';
6
- import { ValidationMiddleware } from '@middlewares/validation.middleware';
7
-
8
- export class AuthRoute implements Routes {
9
- public router = Router();
10
- public auth = new AuthController();
11
-
12
- constructor() {
13
- this.initializeRoutes();
14
- }
15
-
16
- private initializeRoutes() {
17
- this.router.post('/signup', ValidationMiddleware(CreateUserDto), this.auth.signUp);
18
- this.router.post('/login', ValidationMiddleware(CreateUserDto), this.auth.logIn);
19
- this.router.post('/logout', AuthMiddleware, this.auth.logOut);
20
- }
21
- }
@@ -1,23 +0,0 @@
1
- import { Router } from 'express';
2
- import { UserController } from '@controllers/users.controller';
3
- import { CreateUserDto } from '@dtos/users.dto';
4
- import { Routes } from '@interfaces/routes.interface';
5
- import { ValidationMiddleware } from '@middlewares/validation.middleware';
6
-
7
- export class UserRoute implements Routes {
8
- public path = '/users';
9
- public router = Router();
10
- public user = new UserController();
11
-
12
- constructor() {
13
- this.initializeRoutes();
14
- }
15
-
16
- private initializeRoutes() {
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), this.user.createUser);
20
- this.router.put(`${this.path}/:id(\\d+)`, ValidationMiddleware(CreateUserDto, true), this.user.updateUser);
21
- this.router.delete(`${this.path}/:id(\\d+)`, this.user.deleteUser);
22
- }
23
- }
@@ -1,10 +0,0 @@
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';
5
-
6
- ValidateEnv();
7
-
8
- const app = new App([new AuthRoute(), new UserRoute()]);
9
-
10
- app.listen();
@@ -1,103 +0,0 @@
1
- import { hash, compare } from 'bcrypt';
2
- import { sign } from 'jsonwebtoken';
3
- import { Service } from 'typedi';
4
- import { SECRET_KEY } from '@config';
5
- import pg from '@database';
6
- import { HttpException } from '@exceptions/httpException';
7
- import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
8
- import { User } from '@interfaces/users.interface';
9
-
10
- const createToken = (user: User): TokenData => {
11
- const dataStoredInToken: DataStoredInToken = { id: user.id };
12
- const expiresIn: number = 60 * 60;
13
-
14
- return { expiresIn, token: sign(dataStoredInToken, SECRET_KEY, { expiresIn }) };
15
- };
16
-
17
- const createCookie = (tokenData: TokenData): string => {
18
- return `Authorization=${tokenData.token}; HttpOnly; Max-Age=${tokenData.expiresIn};`;
19
- };
20
-
21
- @Service()
22
- export class AuthService {
23
- public async signup(userData: User): Promise<User> {
24
- const { email, password } = userData;
25
-
26
- const { rows: findUser } = await pg.query(
27
- `
28
- SELECT EXISTS(
29
- SELECT
30
- "email"
31
- FROM
32
- users
33
- WHERE
34
- "email" = $1
35
- )`,
36
- [email],
37
- );
38
- if (findUser[0].exists) throw new HttpException(409, `This email ${userData.email} already exists`);
39
-
40
- const hashedPassword = await hash(password, 10);
41
- const { rows: signUpUserData } = await pg.query(
42
- `
43
- INSERT INTO
44
- users(
45
- "email",
46
- "password"
47
- )
48
- VALUES ($1, $2)
49
- RETURNING "email", "password"
50
- `,
51
- [email, hashedPassword],
52
- );
53
-
54
- return signUpUserData[0];
55
- }
56
-
57
- public async login(userData: User): Promise<{ cookie: string; findUser: User }> {
58
- const { email, password } = userData;
59
-
60
- const { rows, rowCount } = await pg.query(
61
- `
62
- SELECT
63
- "email",
64
- "password"
65
- FROM
66
- users
67
- WHERE
68
- "email" = $1
69
- `,
70
- [email],
71
- );
72
- if (!rowCount) throw new HttpException(409, `This email ${email} was not found`);
73
-
74
- const isPasswordMatching: boolean = await compare(password, rows[0].password);
75
- if (!isPasswordMatching) throw new HttpException(409, "You're password not matching");
76
-
77
- const tokenData = createToken(rows[0]);
78
- const cookie = createCookie(tokenData);
79
- return { cookie, findUser: rows[0] };
80
- }
81
-
82
- public async logout(userData: User): Promise<User> {
83
- const { email, password } = userData;
84
-
85
- const { rows, rowCount } = await pg.query(
86
- `
87
- SELECT
88
- "email",
89
- "password"
90
- FROM
91
- users
92
- WHERE
93
- "email" = $1
94
- AND
95
- "password" = $2
96
- `,
97
- [email, password],
98
- );
99
- if (!rowCount) throw new HttpException(409, "User doesn't exist");
100
-
101
- return rows[0];
102
- }
103
- }
@@ -1,133 +0,0 @@
1
- import { hash } from 'bcrypt';
2
- import { Service } from 'typedi';
3
- import pg from '@database';
4
- import { HttpException } from '@exceptions/httpException';
5
- import { User } from '@interfaces/users.interface';
6
-
7
- @Service()
8
- export class UserService {
9
- public async findAllUser(): Promise<User[]> {
10
- const { rows } = await pg.query(`
11
- SELECT
12
- *
13
- FROM
14
- users
15
- `);
16
- return rows;
17
- }
18
-
19
- public async findUserById(userId: number): Promise<User> {
20
- const { rows, rowCount } = await pg.query(
21
- `
22
- SELECT
23
- *
24
- FROM
25
- users
26
- WHERE
27
- id = $1
28
- `,
29
- [userId],
30
- );
31
- if (!rowCount) throw new HttpException(409, "User doesn't exist");
32
-
33
- return rows[0];
34
- }
35
-
36
- public async createUser(userData: User): Promise<User> {
37
- const { email, password } = userData;
38
-
39
- const { rows } = await pg.query(
40
- `
41
- SELECT EXISTS(
42
- SELECT
43
- "email"
44
- FROM
45
- users
46
- WHERE
47
- "email" = $1
48
- )`,
49
- [email],
50
- );
51
- if (rows[0].exists) throw new HttpException(409, `This email ${email} already exists`);
52
-
53
- const hashedPassword = await hash(password, 10);
54
- const { rows: createUserData } = await pg.query(
55
- `
56
- INSERT INTO
57
- users(
58
- "email",
59
- "password"
60
- )
61
- VALUES ($1, $2)
62
- RETURNING "email", "password"
63
- `,
64
- [email, hashedPassword],
65
- );
66
-
67
- return createUserData[0];
68
- }
69
-
70
- public async updateUser(userId: number, userData: User): Promise<User[]> {
71
- const { rows: findUser } = await pg.query(
72
- `
73
- SELECT EXISTS(
74
- SELECT
75
- "id"
76
- FROM
77
- users
78
- WHERE
79
- "id" = $1
80
- )`,
81
- [userId],
82
- );
83
- if (findUser[0].exists) throw new HttpException(409, "User doesn't exist");
84
-
85
- const { email, password } = userData;
86
- const hashedPassword = await hash(password, 10);
87
- const { rows: updateUserData } = await pg.query(
88
- `
89
- UPDATE
90
- users
91
- SET
92
- "email" = $2,
93
- "password" = $3
94
- WHERE
95
- "id" = $1
96
- RETURNING "email", "password"
97
- `,
98
- [userId, email, hashedPassword],
99
- );
100
-
101
- return updateUserData;
102
- }
103
-
104
- public async deleteUser(userId: number): Promise<User[]> {
105
- const { rows: findUser } = await pg.query(
106
- `
107
- SELECT EXISTS(
108
- SELECT
109
- "id"
110
- FROM
111
- users
112
- WHERE
113
- "id" = $1
114
- )`,
115
- [userId],
116
- );
117
- if (findUser[0].exists) throw new HttpException(409, "User doesn't exist");
118
-
119
- const { rows: deleteUserData } = await pg.query(
120
- `
121
- DELETE
122
- FROM
123
- users
124
- WHERE
125
- id = $1
126
- RETURNING "email", "password"
127
- `,
128
- [userId],
129
- );
130
-
131
- return deleteUserData;
132
- }
133
- }
@@ -1,57 +0,0 @@
1
- import request from 'supertest';
2
- import { App } from '@/app';
3
- import pg from '@database';
4
- import { CreateUserDto } from '@dtos/users.dto';
5
- import { AuthRoute } from '@routes/auth.route';
6
-
7
- afterAll(async () => {
8
- await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
9
- pg.end();
10
- });
11
-
12
- describe('Testing Auth', () => {
13
- describe('[POST] /signup', () => {
14
- it('response should have the Create userData', async () => {
15
- const userData: CreateUserDto = {
16
- email: 'example@email.com',
17
- password: 'password',
18
- };
19
- const authRoute = new AuthRoute();
20
- const app = new App([authRoute]);
21
-
22
- return await request(app.getServer())
23
- .post('/signup')
24
- .send(userData)
25
- .expect(201);
26
- });
27
- });
28
-
29
- describe('[POST] /login', () => {
30
- it('response should have the Set-Cookie header with the Authorization token', async () => {
31
- const userData: CreateUserDto = {
32
- email: 'example1@email.com',
33
- password: 'password',
34
- };
35
-
36
- const authRoute = new AuthRoute();
37
- const app = new App([authRoute]);
38
-
39
- return await request(app.getServer())
40
- .post('/login')
41
- .send(userData)
42
- .expect('Set-Cookie', /^Authorization=.+/);
43
- });
44
- });
45
-
46
- // error: StatusCode : 404, Message : Authentication token missing
47
- // describe('[POST] /logout', () => {
48
- // it('logout Set-Cookie Authorization=; Max-age=0', () => {
49
- // const authRoute = new AuthRoute();
50
- // const app = new App([authRoute]);
51
-
52
- // return request(app.getServer())
53
- // .post('/logout')
54
- // .expect('Set-Cookie', /^Authorization=\;/);
55
- // });
56
- // });
57
- });
@@ -1,72 +0,0 @@
1
- import request from 'supertest';
2
- import { App } from '@/app';
3
- import pg from '@database';
4
- import { CreateUserDto } from '@dtos/users.dto';
5
- import { UserRoute } from '@routes/users.route';
6
-
7
- afterAll(async () => {
8
- await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
9
- pg.end();
10
- });
11
-
12
- describe('Testing Users', () => {
13
- describe('[GET] /users', () => {
14
- it('response statusCode 200 / findAll', async () => {
15
- const usersRoute = new UserRoute();
16
- const app = new App([usersRoute]);
17
-
18
- return await request(app.getServer()).get(`${usersRoute.path}`).expect(200);
19
- });
20
- });
21
-
22
- describe('[GET] /users/:id', () => {
23
- it('response statusCode 200 / findOne', async () => {
24
- const usersRoute = new UserRoute();
25
- const app = new App([usersRoute]);
26
-
27
- return await request(app.getServer())
28
- .get(`${usersRoute.path}`)
29
- .query({
30
- userId: 1,
31
- })
32
- .expect(200);
33
- });
34
- });
35
-
36
- describe('[POST] /users', () => {
37
- it('response statusCode 201 / created', async () => {
38
- const userData: CreateUserDto = {
39
- email: 'example@email.com',
40
- password: 'password',
41
- };
42
- const usersRoute = new UserRoute();
43
- const app = new App([usersRoute]);
44
-
45
- return await request(app.getServer()).post(`${usersRoute.path}`).send(userData).expect(201);
46
- });
47
- });
48
-
49
- describe('[PUT] /users/:id', () => {
50
- it('response statusCode 200 / updated', async () => {
51
- const userId = 1;
52
- const userData: CreateUserDto = {
53
- email: 'example@email.com',
54
- password: 'password',
55
- };
56
- const usersRoute = new UserRoute();
57
- const app = new App([usersRoute]);
58
-
59
- return await request(app.getServer()).put(`${usersRoute.path}/${userId}`).send(userData).expect(200);
60
- });
61
- });
62
-
63
- describe('[DELETE] /users/:id', () => {
64
- it('response statusCode 200 / deleted', async () => {
65
- const userId = 1;
66
- const usersRoute = new UserRoute();
67
- const app = new App([usersRoute]);
68
-
69
- return await request(app.getServer()).delete(`${usersRoute.path}/${userId}`).expect(200);
70
- });
71
- });
72
- });
@@ -1,65 +0,0 @@
1
- import { existsSync, mkdirSync } from 'fs';
2
- import { join } from 'path';
3
- import winston from 'winston';
4
- import winstonDaily from 'winston-daily-rotate-file';
5
- import { LOG_DIR } from '@config';
6
-
7
- // logs dir
8
- const logDir: string = join(__dirname, LOG_DIR);
9
-
10
- if (!existsSync(logDir)) {
11
- mkdirSync(logDir);
12
- }
13
-
14
- // Define log format
15
- const logFormat = winston.format.printf(({ timestamp, level, message }) => `${timestamp} ${level}: ${message}`);
16
-
17
- /*
18
- * Log Level
19
- * error: 0, warn: 1, info: 2, http: 3, verbose: 4, debug: 5, silly: 6
20
- */
21
- const logger = winston.createLogger({
22
- format: winston.format.combine(
23
- winston.format.timestamp({
24
- format: 'YYYY-MM-DD HH:mm:ss',
25
- }),
26
- logFormat,
27
- ),
28
- transports: [
29
- // debug log setting
30
- new winstonDaily({
31
- level: 'debug',
32
- datePattern: 'YYYY-MM-DD',
33
- dirname: logDir + '/debug', // log file /logs/debug/*.log in save
34
- filename: `%DATE%.log`,
35
- maxFiles: 30, // 30 Days saved
36
- json: false,
37
- zippedArchive: true,
38
- }),
39
- // error log setting
40
- new winstonDaily({
41
- level: 'error',
42
- datePattern: 'YYYY-MM-DD',
43
- dirname: logDir + '/error', // log file /logs/error/*.log in save
44
- filename: `%DATE%.log`,
45
- maxFiles: 30, // 30 Days saved
46
- handleExceptions: true,
47
- json: false,
48
- zippedArchive: true,
49
- }),
50
- ],
51
- });
52
-
53
- logger.add(
54
- new winston.transports.Console({
55
- format: winston.format.combine(winston.format.splat(), winston.format.colorize()),
56
- }),
57
- );
58
-
59
- const stream = {
60
- write: (message: string) => {
61
- logger.info(message.substring(0, message.lastIndexOf('\n')));
62
- },
63
- };
64
-
65
- export { logger, stream };
@@ -1,8 +0,0 @@
1
- import { cleanEnv, port, str } from 'envalid';
2
-
3
- export const ValidateEnv = () => {
4
- cleanEnv(process.env, {
5
- NODE_ENV: str(),
6
- PORT: port(),
7
- });
8
- };