nestjs-archi-cli 1.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 (67) hide show
  1. package/License.yaml +0 -0
  2. package/README.md +140 -0
  3. package/dist/index.js +29 -0
  4. package/package.json +47 -0
  5. package/template/.dockerignore +6 -0
  6. package/template/.env.example +12 -0
  7. package/template/.prettierrc +4 -0
  8. package/template/Dockerfile +48 -0
  9. package/template/README.md +99 -0
  10. package/template/aborescence.txt +238 -0
  11. package/template/docker-compose-dev.yml +22 -0
  12. package/template/docker-compose-prod.yml +20 -0
  13. package/template/dockerfile.dev +25 -0
  14. package/template/eslint.config.mjs +35 -0
  15. package/template/nest-cli.json +8 -0
  16. package/template/package.json +98 -0
  17. package/template/pnpm-lock.yaml +7665 -0
  18. package/template/prisma/schema.prisma +48 -0
  19. package/template/src/app.controller.spec.ts +22 -0
  20. package/template/src/app.controller.ts +20 -0
  21. package/template/src/app.module.ts +49 -0
  22. package/template/src/app.service.ts +8 -0
  23. package/template/src/common/auth/auth.controller.ts +51 -0
  24. package/template/src/common/auth/auth.module.ts +24 -0
  25. package/template/src/common/auth/auth.service.ts +72 -0
  26. package/template/src/common/auth/dto/create-auth.dto.ts +12 -0
  27. package/template/src/common/auth/dto/update-auth.dto.ts +11 -0
  28. package/template/src/common/auth/jwt/auth.guard.ts +45 -0
  29. package/template/src/common/auth/jwt/constant.ts +3 -0
  30. package/template/src/common/auth/jwt/jwt.guard.ts +6 -0
  31. package/template/src/common/auth/jwt/jwt.strategy.ts +46 -0
  32. package/template/src/common/auth/role/role.decorators.ts +3 -0
  33. package/template/src/common/auth/role/role.enum.ts +7 -0
  34. package/template/src/common/auth/role/role.guard.ts +34 -0
  35. package/template/src/common/http/http-client.module.ts +23 -0
  36. package/template/src/common/http/http-client.service.ts +127 -0
  37. package/template/src/common/logger/error.logging.ts +29 -0
  38. package/template/src/common/logger/logging.interceptor.ts +22 -0
  39. package/template/src/common/notification/notification.module.ts +12 -0
  40. package/template/src/common/notification/notification.service.ts +74 -0
  41. package/template/src/config/db.module.ts +15 -0
  42. package/template/src/config/db.ts +22 -0
  43. package/template/src/config/env.validation.ts +35 -0
  44. package/template/src/features/kafka/kafka.consumer.controller.ts +66 -0
  45. package/template/src/features/kafka/kafka.consumer.service.ts +89 -0
  46. package/template/src/features/kafka/kafka.module.ts +20 -0
  47. package/template/src/features/kafka/kafka.producer.service.ts +29 -0
  48. package/template/src/features/user/core/dto/create-user.dto.ts +28 -0
  49. package/template/src/features/user/core/dto/update-user.dto.ts +66 -0
  50. package/template/src/features/user/core/interface/user.repository.interface.ts +20 -0
  51. package/template/src/features/user/core/use-case/user.service.ts +101 -0
  52. package/template/src/features/user/inBound/user.controller.ts +117 -0
  53. package/template/src/features/user/outBound/user.repository.ts +332 -0
  54. package/template/src/features/user/user.module.ts +14 -0
  55. package/template/src/main.ts +59 -0
  56. package/template/src/utils/crypt.ts +36 -0
  57. package/template/src/utils/generate.ts +90 -0
  58. package/template/src/utils/logging.prisma.ts +17 -0
  59. package/template/src/utils/validation-fields.ts +15 -0
  60. package/template/src/utils/validation-option.ts +94 -0
  61. package/template/src/utils/validators/phoneNumber.validate.ts +22 -0
  62. package/template/test/app.e2e-spec.js +19 -0
  63. package/template/test/app.e2e-spec.ts +25 -0
  64. package/template/test/jest-e2e.json +9 -0
  65. package/template/tsconfig.build.json +27 -0
  66. package/template/tsconfig.build.tsbuildinfo +1 -0
  67. package/template/tsconfig.json +29 -0
@@ -0,0 +1,94 @@
1
+ import {
2
+ HttpException,
3
+ HttpStatus,
4
+ Injectable,
5
+ ValidationError,
6
+ ValidationPipeOptions,
7
+ } from '@nestjs/common';
8
+ import { PrismaService } from 'nestjs-prisma';
9
+ // import * as bcrypt from 'bcrypt';
10
+
11
+ function generateErrors(errors: ValidationError[]) {
12
+ return errors.reduce(
13
+ (accumulator, currentValue) => ({
14
+ ...accumulator,
15
+ [currentValue.property]:
16
+ (currentValue.children?.length ?? 0) > 0
17
+ ? generateErrors(currentValue.children ?? [])
18
+ : Object.values(currentValue.constraints ?? {}).join(', '),
19
+ }),
20
+ {},
21
+ );
22
+ }
23
+
24
+ export const validationOptions: ValidationPipeOptions = {
25
+ transform: true,
26
+ whitelist: true,
27
+ enableDebugMessages: true,
28
+ disableErrorMessages: false,
29
+ forbidNonWhitelisted: true,
30
+ errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
31
+ exceptionFactory: (errors: ValidationError[]) => {
32
+ return new HttpException(
33
+ {
34
+ status: HttpStatus.UNPROCESSABLE_ENTITY,
35
+ errors: generateErrors(errors),
36
+ },
37
+ HttpStatus.UNPROCESSABLE_ENTITY,
38
+ );
39
+ },
40
+ };
41
+
42
+ // export default validationOptions;
43
+
44
+
45
+ @Injectable()
46
+ export class SuperAdminSeederService {
47
+
48
+ constructor(private readonly prisma: PrismaService) {}
49
+
50
+ async seedRoler() {
51
+ console.log('Seeding roles...');
52
+ const existingUser = await this.prisma.role.findFirst({
53
+ where: { name: 'USER' },
54
+ });
55
+ const existDelivery = await this.prisma.role.findFirst({
56
+ where: { name: 'DELIVERY' },
57
+ });
58
+ const existAdmin = await this.prisma.role.findFirst({
59
+ where: { name: 'ADMIN' },
60
+ });
61
+ const existSuperAdmin = await this.prisma.role.findFirst({
62
+ where: { name: 'SUPERADMIN' },
63
+ });
64
+
65
+ await Promise.all([
66
+ !existAdmin &&
67
+ this.prisma.role.create({
68
+ data: {
69
+ name: 'ADMIN',
70
+ },
71
+ }),
72
+ !existingUser &&
73
+ this.prisma.role.create({
74
+ data: {
75
+ name: 'USER',
76
+ },
77
+ }),
78
+ !existDelivery &&
79
+ this.prisma.role.create({
80
+ data: {
81
+ name: 'DELIVERY',
82
+ },
83
+ }),
84
+ !existSuperAdmin &&
85
+ this.prisma.role.create({
86
+ data: {
87
+ name: 'SUPERADMIN',
88
+ },
89
+ }),
90
+ ]);
91
+
92
+ console.log('Roles seeded.');
93
+ }
94
+ }
@@ -0,0 +1,22 @@
1
+ import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'
2
+ import { parsePhoneNumberFromString } from 'libphonenumber-js'
3
+
4
+ export function IsPhoneNumberCI(validationOptions?: ValidationOptions) {
5
+ return function (object: Object, propertyName: string) {
6
+ registerDecorator({
7
+ name: 'isPhoneNumberCI',
8
+ target: object.constructor,
9
+ propertyName: propertyName,
10
+ options: validationOptions,
11
+ validator: {
12
+ validate(value: any) {
13
+ const phoneNumber = parsePhoneNumberFromString(value, 'CI')
14
+ return phoneNumber?.isValid() ?? false
15
+ },
16
+ defaultMessage(args: ValidationArguments) {
17
+ return `${args.property} doit être un numéro de téléphone valide de Côte d'Ivoire`
18
+ }
19
+ }
20
+ })
21
+ }
22
+ }
@@ -0,0 +1,19 @@
1
+ import { Test } from '@nestjs/testing';
2
+ import * as request from 'supertest';
3
+ import { AppModule } from './../src/app.module';
4
+ describe('AppController (e2e)', () => {
5
+ let app;
6
+ beforeEach(async () => {
7
+ const moduleFixture = await Test.createTestingModule({
8
+ imports: [AppModule],
9
+ }).compile();
10
+ app = moduleFixture.createNestApplication();
11
+ await app.init();
12
+ });
13
+ it('/ (GET)', () => {
14
+ return request(app.getHttpServer())
15
+ .get('/')
16
+ .expect(200)
17
+ .expect('Hello World!');
18
+ });
19
+ });
@@ -0,0 +1,25 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+ import { INestApplication } from '@nestjs/common';
3
+ import * as request from 'supertest';
4
+ import { App } from 'supertest/types';
5
+ import { AppModule } from './../src/app.module';
6
+
7
+ describe('AppController (e2e)', () => {
8
+ let app: INestApplication<App>;
9
+
10
+ beforeEach(async () => {
11
+ const moduleFixture: TestingModule = await Test.createTestingModule({
12
+ imports: [AppModule],
13
+ }).compile();
14
+
15
+ app = moduleFixture.createNestApplication();
16
+ await app.init();
17
+ });
18
+
19
+ it('/ (GET)', () => {
20
+ return request(app.getHttpServer())
21
+ .get('/')
22
+ .expect(200)
23
+ .expect('Hello World!');
24
+ });
25
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "moduleFileExtensions": ["js", "json", "ts"],
3
+ "rootDir": ".",
4
+ "testEnvironment": "node",
5
+ "testRegex": ".e2e-spec.ts$",
6
+ "transform": {
7
+ "^.+\\.(t|j)s$": "ts-jest"
8
+ }
9
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist",
4
+ "rootDir": "./",
5
+ "baseUrl": "./src",
6
+ "paths": {
7
+ "features/*": ["features/*"],
8
+ "config/*": ["config/*"],
9
+ "common/*": ["common/*"],
10
+ "utils/*": ["utils/*"]
11
+ },
12
+ "resolveJsonModule": true,
13
+ "esModuleInterop": true
14
+ },
15
+ "include": [
16
+ "src/**/*.ts"
17
+ ],
18
+ "extends": "./tsconfig.json",
19
+ "exclude": [
20
+ "node_modules",
21
+ "dist",
22
+ "test",
23
+ "**/*.spec.ts",
24
+ "**/*.test.ts",
25
+ "**/__mocks__/**"
26
+ ]
27
+ }