@nest-extended/cli 0.0.2-beta-13 → 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.
- package/README.md +73 -9
- package/package.json +1 -1
- package/src/commands/generate-app.js +145 -30
- package/src/commands/generate-app.js.map +1 -1
- package/src/commands/generate-service.js +211 -13
- package/src/commands/generate-service.js.map +1 -1
- package/src/lib/generate-prisma-auth-services.d.ts +1 -0
- package/src/lib/generate-prisma-auth-services.js +38 -0
- package/src/lib/generate-prisma-auth-services.js.map +1 -0
- package/src/lib/update-app-module.d.ts +1 -1
- package/src/lib/update-app-module.js +3 -3
- package/src/lib/update-app-module.js.map +1 -1
- package/src/templates/controller.template.d.ts +1 -1
- package/src/templates/controller.template.js +2 -2
- package/src/templates/controller.template.js.map +1 -1
- package/src/templates/dto-class-validator.template.d.ts +1 -0
- package/src/templates/dto-class-validator.template.js +93 -0
- package/src/templates/dto-class-validator.template.js.map +1 -0
- package/src/templates/dto.template.js +19 -0
- package/src/templates/dto.template.js.map +1 -1
- package/src/templates/module.template.d.ts +1 -1
- package/src/templates/module.template.js +2 -2
- package/src/templates/module.template.js.map +1 -1
- package/src/templates/prisma-auth.template.d.ts +9 -0
- package/src/templates/prisma-auth.template.js +190 -0
- package/src/templates/prisma-auth.template.js.map +1 -0
- package/src/templates/prisma-controller.template.d.ts +1 -0
- package/src/templates/prisma-controller.template.js +53 -0
- package/src/templates/prisma-controller.template.js.map +1 -0
- package/src/templates/prisma-dto-class-validator.template.d.ts +1 -0
- package/src/templates/prisma-dto-class-validator.template.js +93 -0
- package/src/templates/prisma-dto-class-validator.template.js.map +1 -0
- package/src/templates/prisma-dto.template.d.ts +1 -0
- package/src/templates/prisma-dto.template.js +55 -0
- package/src/templates/prisma-dto.template.js.map +1 -0
- package/src/templates/prisma-model.template.d.ts +7 -0
- package/src/templates/prisma-model.template.js +27 -0
- package/src/templates/prisma-model.template.js.map +1 -0
- package/src/templates/prisma-module.template.d.ts +1 -0
- package/src/templates/prisma-module.template.js +18 -0
- package/src/templates/prisma-module.template.js.map +1 -0
- package/src/templates/prisma-service.template.d.ts +1 -0
- package/src/templates/prisma-service.template.js +15 -0
- package/src/templates/prisma-service.template.js.map +1 -0
- package/src/templates/prisma-setup.template.d.ts +6 -0
- package/src/templates/prisma-setup.template.js +34 -0
- package/src/templates/prisma-setup.template.js.map +1 -0
- package/src/templates/prisma-users.template.d.ts +8 -0
- package/src/templates/prisma-users.template.js +135 -0
- package/src/templates/prisma-users.template.js.map +1 -0
- package/src/templates/schema.template.d.ts +1 -1
- package/src/templates/schema.template.js +14 -6
- package/src/templates/schema.template.js.map +1 -1
- package/src/templates/service.template.d.ts +1 -1
- package/src/templates/service.template.js +2 -2
- package/src/templates/service.template.js.map +1 -1
|
@@ -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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getSchema: (Name: string, UserEntity?: string, isAuthGenerated?: boolean) => string;
|
|
1
|
+
export declare const getSchema: (Name: string, UserEntity?: string, isAuthGenerated?: boolean, dirPath?: string) => string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSchema = void 0;
|
|
4
|
-
const getSchema = (Name, UserEntity = 'Users', isAuthGenerated = true) => {
|
|
4
|
+
const getSchema = (Name, UserEntity = 'Users', isAuthGenerated = true, dirPath = '') => {
|
|
5
5
|
const authFields = isAuthGenerated ? `
|
|
6
6
|
@Prop({
|
|
7
7
|
type: Types.ObjectId,
|
|
@@ -13,20 +13,26 @@ const getSchema = (Name, UserEntity = 'Users', isAuthGenerated = true) => {
|
|
|
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
|
` : '';
|
|
29
|
+
// Calculate schema depth correctly from schemas folder rather than services folder
|
|
30
|
+
// For `src/schemas/qna/category.schema.ts`, dirPath is `qna`, depth is `../`
|
|
31
|
+
const schemaDepth = dirPath ? dirPath.split('/').map(() => '../').join('') : './';
|
|
32
|
+
const relativeUserPath = schemaDepth + 'users.schema';
|
|
27
33
|
return `import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
28
34
|
import { HydratedDocument, Types } from 'mongoose';
|
|
29
|
-
import { ${UserEntity} } from '
|
|
35
|
+
import { ${UserEntity} } from '${relativeUserPath}';
|
|
30
36
|
import { EnsureObjectId } from '@nest-extended/mongoose';
|
|
31
37
|
|
|
32
38
|
export type ${Name}Document = HydratedDocument<${Name}>;
|
|
@@ -40,13 +46,15 @@ export class ${Name} {
|
|
|
40
46
|
${authFields}
|
|
41
47
|
@Prop({
|
|
42
48
|
type: Boolean,
|
|
43
|
-
default: null
|
|
49
|
+
default: null,
|
|
50
|
+
select: false,
|
|
44
51
|
})
|
|
45
52
|
deleted?: Boolean;
|
|
46
53
|
|
|
47
54
|
@Prop({
|
|
48
55
|
type: Date,
|
|
49
|
-
default: null
|
|
56
|
+
default: null,
|
|
57
|
+
select: false,
|
|
50
58
|
})
|
|
51
59
|
deletedAt?: Date;
|
|
52
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,EAAU,EAAE;
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getService: (Name: string, name: string) => string;
|
|
1
|
+
export declare const getService: (Name: string, name: string, fullPath?: string) => string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getService = void 0;
|
|
4
|
-
const getService = (Name, name) => `import { Model } from 'mongoose';
|
|
4
|
+
const getService = (Name, name, fullPath = name) => `import { Model } from 'mongoose';
|
|
5
5
|
import { Injectable } from '@nestjs/common';
|
|
6
6
|
import { InjectModel } from '@nestjs/mongoose';
|
|
7
7
|
import { NestService } from '@nest-extended/mongoose';
|
|
8
|
-
import { ${Name}, ${Name}Document } from 'src/schemas/${
|
|
8
|
+
import { ${Name}, ${Name}Document } from 'src/schemas/${fullPath}.schema';
|
|
9
9
|
|
|
10
10
|
@Injectable()
|
|
11
11
|
export class ${Name}Service extends NestService<${Name}, ${Name}Document> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/service.template.ts"],"names":[],"mappings":";;;AACO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"service.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/service.template.ts"],"names":[],"mappings":";;;AACO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,WAAmB,IAAI,EAAU,EAAE,CAAC;;;;WAIhF,IAAI,KAAK,IAAI,gCAAgC,QAAQ;;;eAGjD,IAAI,+BAA+B,IAAI,KAAK,IAAI;;mBAE5C,IAAI,2BAA2B,IAAI,gBAAgB,IAAI;;YAE9D,IAAI;;EAEd,CAAC;AAbU,QAAA,UAAU,cAapB"}
|