@nest-extended/cli 0.0.2-beta-14 → 0.0.2-beta-15

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 (43) hide show
  1. package/README.md +73 -9
  2. package/package.json +1 -1
  3. package/src/commands/generate-app.js +145 -30
  4. package/src/commands/generate-app.js.map +1 -1
  5. package/src/commands/generate-service.js +204 -15
  6. package/src/commands/generate-service.js.map +1 -1
  7. package/src/lib/generate-prisma-auth-services.d.ts +1 -0
  8. package/src/lib/generate-prisma-auth-services.js +38 -0
  9. package/src/lib/generate-prisma-auth-services.js.map +1 -0
  10. package/src/templates/dto-class-validator.template.d.ts +1 -0
  11. package/src/templates/dto-class-validator.template.js +93 -0
  12. package/src/templates/dto-class-validator.template.js.map +1 -0
  13. package/src/templates/dto.template.js +19 -0
  14. package/src/templates/dto.template.js.map +1 -1
  15. package/src/templates/prisma-auth.template.d.ts +9 -0
  16. package/src/templates/prisma-auth.template.js +190 -0
  17. package/src/templates/prisma-auth.template.js.map +1 -0
  18. package/src/templates/prisma-controller.template.d.ts +1 -0
  19. package/src/templates/prisma-controller.template.js +53 -0
  20. package/src/templates/prisma-controller.template.js.map +1 -0
  21. package/src/templates/prisma-dto-class-validator.template.d.ts +1 -0
  22. package/src/templates/prisma-dto-class-validator.template.js +93 -0
  23. package/src/templates/prisma-dto-class-validator.template.js.map +1 -0
  24. package/src/templates/prisma-dto.template.d.ts +1 -0
  25. package/src/templates/prisma-dto.template.js +55 -0
  26. package/src/templates/prisma-dto.template.js.map +1 -0
  27. package/src/templates/prisma-model.template.d.ts +7 -0
  28. package/src/templates/prisma-model.template.js +27 -0
  29. package/src/templates/prisma-model.template.js.map +1 -0
  30. package/src/templates/prisma-module.template.d.ts +1 -0
  31. package/src/templates/prisma-module.template.js +18 -0
  32. package/src/templates/prisma-module.template.js.map +1 -0
  33. package/src/templates/prisma-service.template.d.ts +1 -0
  34. package/src/templates/prisma-service.template.js +15 -0
  35. package/src/templates/prisma-service.template.js.map +1 -0
  36. package/src/templates/prisma-setup.template.d.ts +6 -0
  37. package/src/templates/prisma-setup.template.js +34 -0
  38. package/src/templates/prisma-setup.template.js.map +1 -0
  39. package/src/templates/prisma-users.template.d.ts +8 -0
  40. package/src/templates/prisma-users.template.js +135 -0
  41. package/src/templates/prisma-users.template.js.map +1 -0
  42. package/src/templates/schema.template.js +8 -4
  43. package/src/templates/schema.template.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-auth.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-auth.template.ts"],"names":[],"mappings":";AACA;;;GAGG;;;AAEI,MAAM,uBAAuB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCpD,CAAC;AAvCW,QAAA,uBAAuB,2BAuClC;AAEK,MAAM,oBAAoB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCjD,CAAC;AAzCW,QAAA,oBAAoB,wBAyC/B;AAEK,MAAM,mBAAmB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BhD,CAAC;AA7BW,QAAA,mBAAmB,uBA6B9B;AAEK,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0D/C,CAAC;AA1DW,QAAA,kBAAkB,sBA0D7B;AAEK,MAAM,qBAAqB,GAAG,GAAW,EAAE,CAAC;;;;;CAKlD,CAAC;AALW,QAAA,qBAAqB,yBAKhC"}
@@ -0,0 +1 @@
1
+ export declare const getPrismaController: (Name: string, name: string, url: string) => string;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrismaController = void 0;
4
+ const getPrismaController = (Name, name, url) => `import {
5
+ Controller,
6
+ Delete,
7
+ Get,
8
+ Param,
9
+ Patch,
10
+ Post,
11
+ Query,
12
+ } from '@nestjs/common';
13
+ import { ${Name}Service } from './${name}.service';
14
+ import { User, ModifyBody, setCreatedBy } from '@nest-extended/decorators';
15
+
16
+ @Controller('${url}')
17
+ export class ${Name}Controller {
18
+ constructor(private readonly ${name}Service: ${Name}Service) { }
19
+
20
+ @Get()
21
+ async find(@Query() query: Record<string, any>) {
22
+ return await this.${name}Service._find(query);
23
+ }
24
+
25
+ @Get('/:id')
26
+ async get(@Query() query: Record<string, any>, @Param('id') id: string) {
27
+ return await this.${name}Service._get(id, query);
28
+ }
29
+
30
+ @Post()
31
+ async create(
32
+ @ModifyBody(setCreatedBy()) create${Name}Dto: any
33
+ ) {
34
+ return await this.${name}Service._create(create${Name}Dto);
35
+ }
36
+
37
+ @Patch('/:id')
38
+ async patch(
39
+ @Query() query: Record<string, any>,
40
+ @ModifyBody(setCreatedBy('updatedBy')) patch${Name}Dto: any,
41
+ @Param('id') id: string,
42
+ ) {
43
+ return await this.${name}Service._patch(id, patch${Name}Dto, query);
44
+ }
45
+
46
+ @Delete('/:id')
47
+ async delete(@Param('id') id: string, @Query() query: Record<string, any>, @User() user: Record<string, unknown>) {
48
+ return await this.${name}Service._remove(id, query, user);
49
+ }
50
+ }
51
+ `;
52
+ exports.getPrismaController = getPrismaController;
53
+ //# sourceMappingURL=prisma-controller.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-controller.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-controller.template.ts"],"names":[],"mappings":";;;AACO,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,GAAW,EAAU,EAAE,CAAC;;;;;;;;;WAS7E,IAAI,qBAAqB,IAAI;;;eAGzB,GAAG;eACH,IAAI;iCACc,IAAI,YAAY,IAAI;;;;wBAI7B,IAAI;;;;;wBAKJ,IAAI;;;;;wCAKY,IAAI;;wBAEpB,IAAI,yBAAyB,IAAI;;;;;;kDAMP,IAAI;;;wBAG9B,IAAI,2BAA2B,IAAI;;;;;wBAKnC,IAAI;;;CAG3B,CAAC;AA/CW,QAAA,mBAAmB,uBA+C9B"}
@@ -0,0 +1 @@
1
+ export declare const getPrismaDtoClassValidator: (Name: string) => string;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrismaDtoClassValidator = void 0;
4
+ const getPrismaDtoClassValidator = (Name) => `import { IsString, IsOptional, IsBoolean, IsDate } from 'class-validator';
5
+ import { Type } from 'class-transformer';
6
+
7
+ /**
8
+ * Usage: To enable class-validator validation, add the following to your main.ts:
9
+ *
10
+ * import { ValidationPipe } from '@nestjs/common';
11
+ * app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
12
+ *
13
+ * Or apply per-route using @UsePipes(new ValidationPipe({ transform: true }))
14
+ */
15
+
16
+ export class Create${Name}Dto {
17
+ @IsString()
18
+ @IsOptional()
19
+ name?: string;
20
+
21
+ @IsString()
22
+ @IsOptional()
23
+ createdBy?: string;
24
+
25
+ @IsDate()
26
+ @IsOptional()
27
+ @Type(() => Date)
28
+ createdAt?: Date;
29
+
30
+ @IsDate()
31
+ @IsOptional()
32
+ @Type(() => Date)
33
+ updatedAt?: Date;
34
+
35
+ @IsBoolean()
36
+ @IsOptional()
37
+ deleted?: boolean;
38
+
39
+ @IsString()
40
+ @IsOptional()
41
+ deletedBy?: string;
42
+
43
+ @IsDate()
44
+ @IsOptional()
45
+ @Type(() => Date)
46
+ deletedAt?: Date;
47
+ }
48
+
49
+ export class Patch${Name}Dto {
50
+ @IsString()
51
+ @IsOptional()
52
+ name?: string;
53
+
54
+ @IsDate()
55
+ @IsOptional()
56
+ @Type(() => Date)
57
+ updatedAt?: Date;
58
+
59
+ @IsDate()
60
+ @IsOptional()
61
+ @Type(() => Date)
62
+ createdAt?: Date;
63
+
64
+ @IsBoolean()
65
+ @IsOptional()
66
+ deleted?: boolean;
67
+
68
+ @IsString()
69
+ @IsOptional()
70
+ deletedBy?: string;
71
+
72
+ @IsDate()
73
+ @IsOptional()
74
+ @Type(() => Date)
75
+ deletedAt?: Date;
76
+ }
77
+
78
+ export class Remove${Name}Dto {
79
+ @IsString()
80
+ id: string;
81
+
82
+ @IsString()
83
+ @IsOptional()
84
+ deletedBy?: string;
85
+
86
+ @IsDate()
87
+ @IsOptional()
88
+ @Type(() => Date)
89
+ deletedAt?: Date;
90
+ }
91
+ `;
92
+ exports.getPrismaDtoClassValidator = getPrismaDtoClassValidator;
93
+ //# sourceMappingURL=prisma-dto-class-validator.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-dto-class-validator.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-dto-class-validator.template.ts"],"names":[],"mappings":";;;AACO,MAAM,0BAA0B,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;;;;;;;;;;qBAY/C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAiCL,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6BH,IAAI;;;;;;;;;;;;;CAaxB,CAAC;AAvFW,QAAA,0BAA0B,8BAuFrC"}
@@ -0,0 +1 @@
1
+ export declare const getPrismaDto: (Name: string) => string;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrismaDto = void 0;
4
+ const getPrismaDto = (Name) => `import { z } from 'zod';
5
+
6
+ /**
7
+ * Usage: To enable Zod validation, create a ZodValidationPipe and apply it globally or per-route.
8
+ *
9
+ * // zod-validation.pipe.ts
10
+ * import { PipeTransform, BadRequestException } from '@nestjs/common';
11
+ * import { ZodSchema } from 'zod';
12
+ * export class ZodValidationPipe implements PipeTransform {
13
+ * constructor(private schema: ZodSchema) {}
14
+ * transform(value: unknown) {
15
+ * const result = this.schema.safeParse(value);
16
+ * if (!result.success) throw new BadRequestException(result.error);
17
+ * return result.data;
18
+ * }
19
+ * }
20
+ *
21
+ * // Then in your controller:
22
+ * @UsePipes(new ZodValidationPipe(Create${Name}Validation))
23
+ */
24
+
25
+ export const Create${Name}Validation = z.object({
26
+ name: z.string().optional(),
27
+ createdBy: z.string().optional(),
28
+ createdAt: z.date().optional(),
29
+ updatedAt: z.date().optional(),
30
+ deleted: z.boolean().optional().default(false),
31
+ deletedBy: z.string().optional(),
32
+ deletedAt: z.date().optional(),
33
+ });
34
+
35
+ export const Patch${Name}Validation = z.object({
36
+ name: z.string().optional(),
37
+ updatedAt: z.date().optional(),
38
+ createdAt: z.date().optional(),
39
+ deleted: z.boolean().optional(),
40
+ deletedBy: z.string().optional(),
41
+ deletedAt: z.date().optional(),
42
+ });
43
+
44
+ export const Remove${Name}Validation = z.object({
45
+ id: z.string(),
46
+ deletedBy: z.string().optional(),
47
+ deletedAt: z.date().optional(),
48
+ });
49
+
50
+ export type Create${Name}DTO = z.infer<typeof Create${Name}Validation>;
51
+ export type Patch${Name}DTO = z.infer<typeof Patch${Name}Validation>;
52
+ export type Remove${Name}DTO = z.infer<typeof Remove${Name}Validation>;
53
+ `;
54
+ exports.getPrismaDto = getPrismaDto;
55
+ //# sourceMappingURL=prisma-dto.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-dto.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-dto.template.ts"],"names":[],"mappings":";;;AACO,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;;;;;;;;;;;;;;;;6CAkBT,IAAI;;;qBAG5B,IAAI;;;;;;;;;;oBAUL,IAAI;;;;;;;;;qBASH,IAAI;;;;;;oBAML,IAAI,8BAA8B,IAAI;mBACvC,IAAI,6BAA6B,IAAI;oBACpC,IAAI,8BAA8B,IAAI;CACzD,CAAC;AAjDW,QAAA,YAAY,gBAiDvB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generates a Prisma model block to append to schema.prisma.
3
+ *
4
+ * @param Name - PascalCase model name
5
+ * @param isAuthGenerated - Whether auth module exists (adds createdBy/updatedBy/deletedBy)
6
+ */
7
+ export declare const getPrismaModel: (Name: string, isAuthGenerated?: boolean) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrismaModel = void 0;
4
+ /**
5
+ * Generates a Prisma model block to append to schema.prisma.
6
+ *
7
+ * @param Name - PascalCase model name
8
+ * @param isAuthGenerated - Whether auth module exists (adds createdBy/updatedBy/deletedBy)
9
+ */
10
+ const getPrismaModel = (Name, isAuthGenerated = true) => {
11
+ const authFields = isAuthGenerated ? `
12
+ createdBy String?
13
+ updatedBy String?
14
+ deletedBy String?` : '';
15
+ return `
16
+ model ${Name} {
17
+ id String @id @default(cuid())
18
+ name String?
19
+ deleted Boolean? @default(false)
20
+ deletedAt DateTime?${authFields}
21
+ createdAt DateTime @default(now())
22
+ updatedAt DateTime @updatedAt
23
+ }
24
+ `;
25
+ };
26
+ exports.getPrismaModel = getPrismaModel;
27
+ //# sourceMappingURL=prisma-model.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-model.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-model.template.ts"],"names":[],"mappings":";;;AACA;;;;;GAKG;AACI,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,kBAA2B,IAAI,EAAU,EAAE;IACpF,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC;;;oBAGrB,CAAC,CAAC,CAAC,EAAE,CAAC;IAEtB,OAAO;QACH,IAAI;;;;uBAIW,UAAU;;;;CAIhC,CAAC;AACF,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB"}
@@ -0,0 +1 @@
1
+ export declare const getPrismaModule: (Name: string, name: string) => string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrismaModule = void 0;
4
+ const getPrismaModule = (Name, name) => `import { Module } from '@nestjs/common';
5
+ import { ${Name}Controller } from './${name}.controller';
6
+ import { ${Name}Service } from './${name}.service';
7
+
8
+ @Module({
9
+ controllers: [${Name}Controller],
10
+ providers: [
11
+ ${Name}Service,
12
+ ],
13
+ exports: [${Name}Service],
14
+ })
15
+ export class ${Name}Module {}
16
+ `;
17
+ exports.getPrismaModule = getPrismaModule;
18
+ //# sourceMappingURL=prisma-module.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-module.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-module.template.ts"],"names":[],"mappings":";;;AACO,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;WAC5D,IAAI,wBAAwB,IAAI;WAChC,IAAI,qBAAqB,IAAI;;;kBAGtB,IAAI;;MAEhB,IAAI;;cAEI,IAAI;;eAEH,IAAI;CAClB,CAAC;AAZW,QAAA,eAAe,mBAY1B"}
@@ -0,0 +1 @@
1
+ export declare const getPrismaService: (Name: string, name: string) => string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPrismaService = void 0;
4
+ const getPrismaService = (Name, name) => `import { Injectable } from '@nestjs/common';
5
+ import { PrismaService } from 'src/prisma/prisma.service';
6
+ import { NestService } from '@nest-extended/prisma';
7
+
8
+ @Injectable()
9
+ export class ${Name}Service extends NestService<any> {
10
+ constructor(private readonly prisma: PrismaService) {
11
+ super(prisma.${name});
12
+ }
13
+ }`;
14
+ exports.getPrismaService = getPrismaService;
15
+ //# sourceMappingURL=prisma-service.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-service.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-service.template.ts"],"names":[],"mappings":";;;AACO,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;;;;;eAKzD,IAAI;;mBAEA,IAAI;;EAErB,CAAC;AATU,QAAA,gBAAgB,oBAS1B"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates PrismaService (extends PrismaClient) and PrismaModule.
3
+ * Created once per project — shared across all Prisma-based services.
4
+ */
5
+ export declare const getPrismaServiceFile: () => string;
6
+ export declare const getPrismaModuleFile: () => string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /**
3
+ * Generates PrismaService (extends PrismaClient) and PrismaModule.
4
+ * Created once per project — shared across all Prisma-based services.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getPrismaModuleFile = exports.getPrismaServiceFile = void 0;
8
+ const getPrismaServiceFile = () => `import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
9
+ import { PrismaClient } from '@prisma/client';
10
+
11
+ @Injectable()
12
+ export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
13
+ async onModuleInit() {
14
+ await this.$connect();
15
+ }
16
+
17
+ async onModuleDestroy() {
18
+ await this.$disconnect();
19
+ }
20
+ }
21
+ `;
22
+ exports.getPrismaServiceFile = getPrismaServiceFile;
23
+ const getPrismaModuleFile = () => `import { Global, Module } from '@nestjs/common';
24
+ import { PrismaService } from './prisma.service';
25
+
26
+ @Global()
27
+ @Module({
28
+ providers: [PrismaService],
29
+ exports: [PrismaService],
30
+ })
31
+ export class PrismaModule {}
32
+ `;
33
+ exports.getPrismaModuleFile = getPrismaModuleFile;
34
+ //# sourceMappingURL=prisma-setup.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-setup.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-setup.template.ts"],"names":[],"mappings":";AACA;;;GAGG;;;AAEI,MAAM,oBAAoB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;CAajD,CAAC;AAbW,QAAA,oBAAoB,wBAa/B;AAEK,MAAM,mBAAmB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;CAShD,CAAC;AATW,QAAA,mBAAmB,uBAS9B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Prisma-compatible Users templates.
3
+ * Same functionality as the Mongoose users templates but using Prisma.
4
+ */
5
+ export declare const getPrismaUsersModel: () => string;
6
+ export declare const getPrismaUsersService: () => string;
7
+ export declare const getPrismaUsersController: () => string;
8
+ export declare const getPrismaUsersModule: () => string;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * Prisma-compatible Users templates.
4
+ * Same functionality as the Mongoose users templates but using Prisma.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getPrismaUsersModule = exports.getPrismaUsersController = exports.getPrismaUsersService = exports.getPrismaUsersModel = void 0;
8
+ const getPrismaUsersModel = () => `
9
+ model Users {
10
+ id String @id @default(cuid())
11
+ firstName String
12
+ lastName String
13
+ email String @unique
14
+ password String
15
+ phone String?
16
+ role Int @default(1)
17
+ deleted Boolean? @default(false)
18
+ deletedAt DateTime?
19
+ deletedBy String?
20
+ createdAt DateTime @default(now())
21
+ updatedAt DateTime @updatedAt
22
+ }
23
+ `;
24
+ exports.getPrismaUsersModel = getPrismaUsersModel;
25
+ const getPrismaUsersService = () => `import { Injectable } from '@nestjs/common';
26
+ import { PrismaService } from '../../prisma/prisma.service';
27
+ import { NestService } from '@nest-extended/prisma';
28
+
29
+ @Injectable()
30
+ export class UsersService extends NestService<any> {
31
+ constructor(private readonly prisma: PrismaService) {
32
+ super(prisma.users);
33
+ }
34
+
35
+ sanitizeUser(user: Record<string, any>) {
36
+ const sanitized = { ...user };
37
+ delete sanitized['password'];
38
+ return sanitized;
39
+ }
40
+ }
41
+ `;
42
+ exports.getPrismaUsersService = getPrismaUsersService;
43
+ const getPrismaUsersController = () => `import {
44
+ BadRequestException,
45
+ Body,
46
+ Controller,
47
+ Get,
48
+ Param,
49
+ Patch,
50
+ Post,
51
+ Query,
52
+ } from '@nestjs/common';
53
+ import { UsersService } from './users.service';
54
+ import { Public } from '@nest-extended/decorators';
55
+ import * as bcrypt from 'bcrypt';
56
+ import { JwtService } from '@nestjs/jwt';
57
+
58
+ @Controller('users')
59
+ export class UsersController {
60
+ constructor(
61
+ private readonly usersService: UsersService,
62
+ private readonly jwtService: JwtService,
63
+ ) {}
64
+
65
+ @Get()
66
+ async find(@Query() query: Record<string, any>) {
67
+ return await this.usersService._find(query);
68
+ }
69
+
70
+ @Get('/:id')
71
+ async get(@Query() query: Record<string, any>, @Param('id') id: string) {
72
+ return await this.usersService._get(id, query);
73
+ }
74
+
75
+ @Public()
76
+ @Post()
77
+ async create(@Body() createUsersDto: Record<string, any>) {
78
+ if (!createUsersDto.email || !createUsersDto.password) {
79
+ throw new BadRequestException('Email or Password not provided!');
80
+ }
81
+
82
+ const saltOrRounds = 10;
83
+ const password = await bcrypt.hash(createUsersDto.password, saltOrRounds);
84
+
85
+ const user = await this.usersService._create({
86
+ ...createUsersDto,
87
+ password,
88
+ }) as Record<string, any>;
89
+
90
+ const sanitizedUser = this.usersService.sanitizeUser(user);
91
+ const payload = { sub: { id: user.id }, user };
92
+
93
+ return {
94
+ accessToken: await this.jwtService.signAsync(payload),
95
+ user: sanitizedUser,
96
+ };
97
+ }
98
+
99
+ @Patch('/:id')
100
+ async patch(
101
+ @Query() query: Record<string, any>,
102
+ @Body() patchUsersDto: Record<string, any>,
103
+ @Param('id') id: string,
104
+ ) {
105
+ delete patchUsersDto.email;
106
+ return await this.usersService._patch(id, patchUsersDto, query);
107
+ }
108
+
109
+ @Patch('/:id/block')
110
+ async block(
111
+ @Body() patchUsersDto: { blocked: boolean },
112
+ @Param('id') id: string,
113
+ ) {
114
+ return await this.usersService._patch(
115
+ id,
116
+ { blocked: patchUsersDto?.blocked ?? true },
117
+ {},
118
+ );
119
+ }
120
+ }
121
+ `;
122
+ exports.getPrismaUsersController = getPrismaUsersController;
123
+ const getPrismaUsersModule = () => `import { Module } from '@nestjs/common';
124
+ import { UsersController } from './users.controller';
125
+ import { UsersService } from './users.service';
126
+
127
+ @Module({
128
+ controllers: [UsersController],
129
+ providers: [UsersService],
130
+ exports: [UsersService],
131
+ })
132
+ export class UsersModule {}
133
+ `;
134
+ exports.getPrismaUsersModule = getPrismaUsersModule;
135
+ //# sourceMappingURL=prisma-users.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-users.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/prisma-users.template.ts"],"names":[],"mappings":";AACA;;;GAGG;;;AAEI,MAAM,mBAAmB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;CAehD,CAAC;AAfW,QAAA,mBAAmB,uBAe9B;AAEK,MAAM,qBAAqB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;CAgBlD,CAAC;AAhBW,QAAA,qBAAqB,yBAgBhC;AAEK,MAAM,wBAAwB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8ErD,CAAC;AA9EW,QAAA,wBAAwB,4BA8EnC;AAEK,MAAM,oBAAoB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;CAUjD,CAAC;AAVW,QAAA,oBAAoB,wBAU/B"}
@@ -13,14 +13,16 @@ const getSchema = (Name, UserEntity = 'Users', isAuthGenerated = true, dirPath =
13
13
  @Prop({
14
14
  type: Types.ObjectId,
15
15
  ref: ${UserEntity}.name,
16
- default: null
16
+ default: null,
17
+ select: false,
17
18
  })
18
19
  updatedBy?: Types.ObjectId;
19
20
 
20
21
  @Prop({
21
22
  type: Types.ObjectId,
22
23
  ref: ${UserEntity}.name,
23
- default: null
24
+ default: null,
25
+ select: false,
24
26
  })
25
27
  deletedBy?: Types.ObjectId;
26
28
  ` : '';
@@ -44,13 +46,15 @@ export class ${Name} {
44
46
  ${authFields}
45
47
  @Prop({
46
48
  type: Boolean,
47
- default: null
49
+ default: null,
50
+ select: false,
48
51
  })
49
52
  deleted?: Boolean;
50
53
 
51
54
  @Prop({
52
55
  type: Date,
53
- default: null
56
+ default: null,
57
+ select: false,
54
58
  })
55
59
  deletedAt?: Date;
56
60
 
@@ -1 +1 @@
1
- {"version":3,"file":"schema.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/schema.template.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,aAAqB,OAAO,EAAE,kBAA2B,IAAI,EAAE,UAAkB,EAAE,EAAU,EAAE;IACrI,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC;;;WAG5B,UAAU;;;;;;;WAOV,UAAU;;;;;;;WAOV,UAAU;;;;CAIpB,CAAC,CAAC,CAAC,EAAE,CAAC;IAEL,mFAAmF;IACnF,6EAA6E;IAC7E,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAClF,MAAM,gBAAgB,GAAG,WAAW,GAAG,cAAc,CAAC;IAEtD,OAAO;;WAEE,UAAU,YAAY,gBAAgB;;;cAGnC,IAAI,+BAA+B,IAAI;;;;;eAKtC,IAAI;;;IAGf,UAAU;;;;;;;;;;;;;;;eAeC,IAAI,yCAAyC,IAAI;CAC/D,CAAC;AACF,CAAC,CAAC;AA3DW,QAAA,SAAS,aA2DpB"}
1
+ {"version":3,"file":"schema.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/schema.template.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,aAAqB,OAAO,EAAE,kBAA2B,IAAI,EAAE,UAAkB,EAAE,EAAU,EAAE;IACrI,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC;;;WAG5B,UAAU;;;;;;;WAOV,UAAU;;;;;;;;WAQV,UAAU;;;;;CAKpB,CAAC,CAAC,CAAC,EAAE,CAAC;IAEL,mFAAmF;IACnF,6EAA6E;IAC7E,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAClF,MAAM,gBAAgB,GAAG,WAAW,GAAG,cAAc,CAAC;IAEtD,OAAO;;WAEE,UAAU,YAAY,gBAAgB;;;cAGnC,IAAI,+BAA+B,IAAI;;;;;eAKtC,IAAI;;;IAGf,UAAU;;;;;;;;;;;;;;;;;eAiBC,IAAI,yCAAyC,IAAI;CAC/D,CAAC;AACF,CAAC,CAAC;AA/DW,QAAA,SAAS,aA+DpB"}