@urbansolv/create-nestjs-app 1.2.3 → 1.2.6
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/dist/templates/nestjs-app/src/common/prisma/prisma.service.ts +0 -1
- package/dist/templates/nestjs-app/src/main.ts +1 -2
- package/dist/templates/nestjs-app/src/modules/auth/controllers/v1/auth.controller.ts +4 -0
- package/dist/templates/nestjs-app/src/modules/users/controllers/v1/users.controller.ts +2 -2
- package/package.json +2 -1
- package/templates/nestjs-app/.editorconfig +12 -0
- package/templates/nestjs-app/.env.example +24 -0
- package/templates/nestjs-app/.eslintrc.js +25 -0
- package/templates/nestjs-app/.prettierrc +8 -0
- package/templates/nestjs-app/README.md +133 -0
- package/templates/nestjs-app/nest-cli.json +10 -0
- package/templates/nestjs-app/package.json +88 -0
- package/templates/nestjs-app/prisma/schema.prisma +79 -0
- package/templates/nestjs-app/prisma/seed.ts +153 -0
- package/templates/nestjs-app/src/app.module.ts +68 -0
- package/templates/nestjs-app/src/common/constants/permissions.constant.ts +27 -0
- package/templates/nestjs-app/src/common/decorators/api-response.decorator.ts +44 -0
- package/templates/nestjs-app/src/common/decorators/get-user.decorator.ts +11 -0
- package/templates/nestjs-app/src/common/decorators/permissions.decorator.ts +5 -0
- package/templates/nestjs-app/src/common/decorators/public.decorator.ts +4 -0
- package/templates/nestjs-app/src/common/dto/api-response.dto.ts +21 -0
- package/templates/nestjs-app/src/common/dto/pagination.dto.ts +33 -0
- package/templates/nestjs-app/src/common/filters/http-exception.filter.ts +56 -0
- package/templates/nestjs-app/src/common/guards/jwt-auth.guard.ts +32 -0
- package/templates/nestjs-app/src/common/guards/permissions.guard.ts +53 -0
- package/templates/nestjs-app/src/common/interceptors/logging.interceptor.ts +37 -0
- package/templates/nestjs-app/src/common/interceptors/transform.interceptor.ts +55 -0
- package/templates/nestjs-app/src/common/prisma/prisma.module.ts +9 -0
- package/templates/nestjs-app/src/common/prisma/prisma.service.ts +45 -0
- package/templates/nestjs-app/src/common/utils/password.util.ts +13 -0
- package/templates/nestjs-app/src/config/app.config.ts +10 -0
- package/templates/nestjs-app/src/config/database.config.ts +5 -0
- package/templates/nestjs-app/src/config/env.validation.ts +30 -0
- package/templates/nestjs-app/src/config/jwt.config.ts +8 -0
- package/templates/nestjs-app/src/config/swagger.config.ts +6 -0
- package/templates/nestjs-app/src/main.ts +93 -0
- package/templates/nestjs-app/src/modules/auth/auth.module.ts +28 -0
- package/templates/nestjs-app/src/modules/auth/auth.service.ts +180 -0
- package/templates/nestjs-app/src/modules/auth/controllers/v1/auth.controller.ts +37 -0
- package/templates/nestjs-app/src/modules/auth/core/dto/auth-response.dto.ts +19 -0
- package/templates/nestjs-app/src/modules/auth/core/dto/login-response.dto.ts +10 -0
- package/templates/nestjs-app/src/modules/auth/core/dto/login.dto.ts +15 -0
- package/templates/nestjs-app/src/modules/auth/core/dto/register.dto.ts +30 -0
- package/templates/nestjs-app/src/modules/auth/core/interfaces/jwt-payload.interface.ts +7 -0
- package/templates/nestjs-app/src/modules/auth/core/strategies/jwt.strategy.ts +54 -0
- package/templates/nestjs-app/src/modules/health/health.controller.ts +29 -0
- package/templates/nestjs-app/src/modules/health/health.module.ts +7 -0
- package/templates/nestjs-app/src/modules/users/controllers/v1/users.controller.ts +118 -0
- package/templates/nestjs-app/src/modules/users/core/dto/change-position.dto.ts +9 -0
- package/templates/nestjs-app/src/modules/users/core/dto/create-user.dto.ts +35 -0
- package/templates/nestjs-app/src/modules/users/core/dto/manage-permissions.dto.ts +13 -0
- package/templates/nestjs-app/src/modules/users/core/dto/update-user.dto.ts +30 -0
- package/templates/nestjs-app/src/modules/users/core/dto/user-query.dto.ts +22 -0
- package/templates/nestjs-app/src/modules/users/core/dto/user-response.dto.ts +32 -0
- package/templates/nestjs-app/src/modules/users/core/entities/user.entity.ts +45 -0
- package/templates/nestjs-app/src/modules/users/core/helpers/user-transform.helper.ts +31 -0
- package/templates/nestjs-app/src/modules/users/users.module.ts +10 -0
- package/templates/nestjs-app/src/modules/users/users.service.ts +340 -0
- package/templates/nestjs-app/test/app.e2e-spec.ts +40 -0
- package/templates/nestjs-app/test/jest-e2e.json +9 -0
- package/templates/nestjs-app/tsconfig.json +26 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { User as PrismaUser, Position } from '@prisma/client';
|
|
3
|
+
import { Exclude } from 'class-transformer';
|
|
4
|
+
|
|
5
|
+
export class UserEntity implements Partial<PrismaUser> {
|
|
6
|
+
@ApiProperty()
|
|
7
|
+
id: number;
|
|
8
|
+
|
|
9
|
+
@ApiProperty()
|
|
10
|
+
email: string;
|
|
11
|
+
|
|
12
|
+
@Exclude()
|
|
13
|
+
password: string;
|
|
14
|
+
|
|
15
|
+
@ApiProperty()
|
|
16
|
+
first_name: string;
|
|
17
|
+
|
|
18
|
+
@ApiProperty()
|
|
19
|
+
last_name: string;
|
|
20
|
+
|
|
21
|
+
@ApiProperty()
|
|
22
|
+
is_active: boolean;
|
|
23
|
+
|
|
24
|
+
@ApiProperty()
|
|
25
|
+
position_id: number;
|
|
26
|
+
|
|
27
|
+
@ApiPropertyOptional()
|
|
28
|
+
position?: Partial<Position>;
|
|
29
|
+
|
|
30
|
+
@ApiPropertyOptional()
|
|
31
|
+
permissions?: string[];
|
|
32
|
+
|
|
33
|
+
@ApiProperty()
|
|
34
|
+
created_at: Date;
|
|
35
|
+
|
|
36
|
+
@ApiProperty()
|
|
37
|
+
updated_at: Date;
|
|
38
|
+
|
|
39
|
+
@ApiPropertyOptional()
|
|
40
|
+
deleted_at: Date | null;
|
|
41
|
+
|
|
42
|
+
constructor(partial: Partial<UserEntity>) {
|
|
43
|
+
Object.assign(this, partial);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { User, Position, PositionPermission, Permission } from '@prisma/client';
|
|
2
|
+
import { UserEntity } from '../entities/user.entity';
|
|
3
|
+
type UserWithRelations = User & {
|
|
4
|
+
position?: Position & {
|
|
5
|
+
position_permissions?: (PositionPermission & {
|
|
6
|
+
permission: Permission;
|
|
7
|
+
})[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class UserTransformHelper {
|
|
12
|
+
static toEntity(user: UserWithRelations): UserEntity {
|
|
13
|
+
const permissions = user.position?.position_permissions?.map(
|
|
14
|
+
(pp) => pp.permission.name,
|
|
15
|
+
) || [];
|
|
16
|
+
|
|
17
|
+
return new UserEntity({
|
|
18
|
+
...user,
|
|
19
|
+
permissions,
|
|
20
|
+
position: user.position ? {
|
|
21
|
+
id: user.position.id,
|
|
22
|
+
name: user.position.name,
|
|
23
|
+
description: user.position.description,
|
|
24
|
+
} : undefined,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static toEntities(users: UserWithRelations[]): UserEntity[] {
|
|
29
|
+
return users.map((user) => this.toEntity(user));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { UsersService } from './users.service';
|
|
3
|
+
import { UsersController } from './controllers/v1/users.controller';
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
controllers: [UsersController],
|
|
7
|
+
providers: [UsersService],
|
|
8
|
+
exports: [UsersService],
|
|
9
|
+
})
|
|
10
|
+
export class UsersModule {}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
NotFoundException,
|
|
4
|
+
ConflictException,
|
|
5
|
+
BadRequestException,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import { PrismaService } from '@common/prisma/prisma.service';
|
|
8
|
+
import { PasswordUtil } from '@common/utils/password.util';
|
|
9
|
+
import { CreateUserDto } from './core/dto/create-user.dto';
|
|
10
|
+
import { UpdateUserDto } from './core/dto/update-user.dto';
|
|
11
|
+
import { ChangePositionDto } from './core/dto/change-position.dto';
|
|
12
|
+
import { ManagePermissionsDto } from './core/dto/manage-permissions.dto';
|
|
13
|
+
import { UserQueryDto } from './core/dto/user-query.dto';
|
|
14
|
+
import { UserEntity } from './core/entities/user.entity';
|
|
15
|
+
import { UserTransformHelper } from './core/helpers/user-transform.helper';
|
|
16
|
+
import { PaginatedResponseDto } from '@common/dto/pagination.dto';
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class UsersService {
|
|
20
|
+
constructor(private prisma: PrismaService) {}
|
|
21
|
+
|
|
22
|
+
async create(createUserDto: CreateUserDto): Promise<UserEntity> {
|
|
23
|
+
const { email, password, position_id, ...userData } = createUserDto;
|
|
24
|
+
|
|
25
|
+
// Check if email already exists
|
|
26
|
+
const existingUser = await this.prisma.user.findUnique({
|
|
27
|
+
where: { email },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (existingUser) {
|
|
31
|
+
throw new ConflictException('Email already exists');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Validate position exists
|
|
35
|
+
const position = await this.prisma.position.findUnique({
|
|
36
|
+
where: { id: position_id },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (!position) {
|
|
40
|
+
throw new BadRequestException('Invalid position ID');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Hash password
|
|
44
|
+
const hashedPassword = await PasswordUtil.hash(password);
|
|
45
|
+
|
|
46
|
+
// Create user
|
|
47
|
+
const user = await this.prisma.user.create({
|
|
48
|
+
data: {
|
|
49
|
+
email,
|
|
50
|
+
password: hashedPassword,
|
|
51
|
+
position_id,
|
|
52
|
+
...userData,
|
|
53
|
+
},
|
|
54
|
+
include: {
|
|
55
|
+
position: {
|
|
56
|
+
include: {
|
|
57
|
+
position_permissions: {
|
|
58
|
+
include: {
|
|
59
|
+
permission: true,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return UserTransformHelper.toEntity(user);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async findAll(query: UserQueryDto): Promise<PaginatedResponseDto<UserEntity>> {
|
|
71
|
+
const { page = 1, limit = 10, search, is_active, position_id } = query;
|
|
72
|
+
const skip = (page - 1) * limit;
|
|
73
|
+
|
|
74
|
+
const where: any = {
|
|
75
|
+
deleted_at: null,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (search) {
|
|
79
|
+
where.OR = [
|
|
80
|
+
{ first_name: { contains: search, mode: 'insensitive' } },
|
|
81
|
+
{ last_name: { contains: search, mode: 'insensitive' } },
|
|
82
|
+
{ email: { contains: search, mode: 'insensitive' } },
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (is_active !== undefined) {
|
|
87
|
+
where.is_active = is_active;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (position_id) {
|
|
91
|
+
where.position_id = position_id;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const [users, total] = await Promise.all([
|
|
95
|
+
this.prisma.user.findMany({
|
|
96
|
+
where,
|
|
97
|
+
skip,
|
|
98
|
+
take: limit,
|
|
99
|
+
include: {
|
|
100
|
+
position: {
|
|
101
|
+
include: {
|
|
102
|
+
position_permissions: {
|
|
103
|
+
include: {
|
|
104
|
+
permission: true,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
orderBy: {
|
|
111
|
+
created_at: 'desc',
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
this.prisma.user.count({ where }),
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
data: UserTransformHelper.toEntities(users),
|
|
119
|
+
meta: {
|
|
120
|
+
total,
|
|
121
|
+
page,
|
|
122
|
+
limit,
|
|
123
|
+
totalPages: Math.ceil(total / limit),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async findOne(id: number): Promise<UserEntity> {
|
|
129
|
+
const user = await this.prisma.user.findFirst({
|
|
130
|
+
where: { id, deleted_at: null },
|
|
131
|
+
include: {
|
|
132
|
+
position: {
|
|
133
|
+
include: {
|
|
134
|
+
position_permissions: {
|
|
135
|
+
include: {
|
|
136
|
+
permission: true,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (!user) {
|
|
145
|
+
throw new NotFoundException(`User with ID ${id} not found`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return UserTransformHelper.toEntity(user);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async update(id: number, updateUserDto: UpdateUserDto): Promise<UserEntity> {
|
|
152
|
+
const user = await this.prisma.user.findFirst({
|
|
153
|
+
where: { id, deleted_at: null },
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (!user) {
|
|
157
|
+
throw new NotFoundException(`User with ID ${id} not found`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const { email, password, ...updateData } = updateUserDto;
|
|
161
|
+
|
|
162
|
+
// Check email uniqueness if changing email
|
|
163
|
+
if (email && email !== user.email) {
|
|
164
|
+
const existingUser = await this.prisma.user.findUnique({
|
|
165
|
+
where: { email },
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (existingUser) {
|
|
169
|
+
throw new ConflictException('Email already exists');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Hash password if provided
|
|
174
|
+
let hashedPassword: string | undefined;
|
|
175
|
+
if (password) {
|
|
176
|
+
hashedPassword = await PasswordUtil.hash(password);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const updatedUser = await this.prisma.user.update({
|
|
180
|
+
where: { id },
|
|
181
|
+
data: {
|
|
182
|
+
...updateData,
|
|
183
|
+
...(email && { email }),
|
|
184
|
+
...(hashedPassword && { password: hashedPassword }),
|
|
185
|
+
},
|
|
186
|
+
include: {
|
|
187
|
+
position: {
|
|
188
|
+
include: {
|
|
189
|
+
position_permissions: {
|
|
190
|
+
include: {
|
|
191
|
+
permission: true,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return UserTransformHelper.toEntity(updatedUser);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async remove(id: number): Promise<void> {
|
|
203
|
+
const user = await this.prisma.user.findFirst({
|
|
204
|
+
where: { id, deleted_at: null },
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (!user) {
|
|
208
|
+
throw new NotFoundException(`User with ID ${id} not found`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Soft delete
|
|
212
|
+
await this.prisma.user.update({
|
|
213
|
+
where: { id },
|
|
214
|
+
data: { deleted_at: new Date() },
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async changePosition(id: number, changePositionDto: ChangePositionDto): Promise<UserEntity> {
|
|
219
|
+
const user = await this.prisma.user.findFirst({
|
|
220
|
+
where: { id, deleted_at: null },
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
if (!user) {
|
|
224
|
+
throw new NotFoundException(`User with ID ${id} not found`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Validate position exists
|
|
228
|
+
const position = await this.prisma.position.findUnique({
|
|
229
|
+
where: { id: changePositionDto.position_id },
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (!position) {
|
|
233
|
+
throw new BadRequestException('Invalid position ID');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const updatedUser = await this.prisma.user.update({
|
|
237
|
+
where: { id },
|
|
238
|
+
data: { position_id: changePositionDto.position_id },
|
|
239
|
+
include: {
|
|
240
|
+
position: {
|
|
241
|
+
include: {
|
|
242
|
+
position_permissions: {
|
|
243
|
+
include: {
|
|
244
|
+
permission: true,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
return UserTransformHelper.toEntity(updatedUser);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async assignPermissions(
|
|
256
|
+
userId: number,
|
|
257
|
+
managePermissionsDto: ManagePermissionsDto,
|
|
258
|
+
): Promise<UserEntity> {
|
|
259
|
+
const user = await this.prisma.user.findFirst({
|
|
260
|
+
where: { id: userId, deleted_at: null },
|
|
261
|
+
include: { position: true },
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
if (!user) {
|
|
265
|
+
throw new NotFoundException(`User with ID ${userId} not found`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Validate all permissions exist
|
|
269
|
+
const permissions = await this.prisma.permission.findMany({
|
|
270
|
+
where: { name: { in: managePermissionsDto.permissions } },
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
if (permissions.length !== managePermissionsDto.permissions.length) {
|
|
274
|
+
throw new BadRequestException('One or more permissions are invalid');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Get current permissions for the position
|
|
278
|
+
const currentPermissions = await this.prisma.positionPermission.findMany({
|
|
279
|
+
where: { position_id: user.position_id },
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const currentPermissionIds = currentPermissions.map((pp) => pp.permission_id);
|
|
283
|
+
const newPermissionIds = permissions.map((p) => p.id);
|
|
284
|
+
|
|
285
|
+
// Find permissions to add
|
|
286
|
+
const permissionsToAdd = newPermissionIds.filter(
|
|
287
|
+
(id) => !currentPermissionIds.includes(id),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
// Add new permissions
|
|
291
|
+
if (permissionsToAdd.length > 0) {
|
|
292
|
+
await this.prisma.positionPermission.createMany({
|
|
293
|
+
data: permissionsToAdd.map((permission_id) => ({
|
|
294
|
+
position_id: user.position_id,
|
|
295
|
+
permission_id,
|
|
296
|
+
})),
|
|
297
|
+
skipDuplicates: true,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Return updated user
|
|
302
|
+
return this.findOne(userId);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async revokePermissions(
|
|
306
|
+
userId: number,
|
|
307
|
+
managePermissionsDto: ManagePermissionsDto,
|
|
308
|
+
): Promise<UserEntity> {
|
|
309
|
+
const user = await this.prisma.user.findFirst({
|
|
310
|
+
where: { id: userId, deleted_at: null },
|
|
311
|
+
include: { position: true },
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
if (!user) {
|
|
315
|
+
throw new NotFoundException(`User with ID ${userId} not found`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Validate all permissions exist
|
|
319
|
+
const permissions = await this.prisma.permission.findMany({
|
|
320
|
+
where: { name: { in: managePermissionsDto.permissions } },
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
if (permissions.length !== managePermissionsDto.permissions.length) {
|
|
324
|
+
throw new BadRequestException('One or more permissions are invalid');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const permissionIds = permissions.map((p) => p.id);
|
|
328
|
+
|
|
329
|
+
// Remove permissions
|
|
330
|
+
await this.prisma.positionPermission.deleteMany({
|
|
331
|
+
where: {
|
|
332
|
+
position_id: user.position_id,
|
|
333
|
+
permission_id: { in: permissionIds },
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// Return updated user
|
|
338
|
+
return this.findOne(userId);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { INestApplication } from '@nestjs/common';
|
|
3
|
+
import * as request from 'supertest';
|
|
4
|
+
import { AppModule } from './../src/app.module';
|
|
5
|
+
|
|
6
|
+
describe('AppController (e2e)', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
11
|
+
imports: [AppModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = moduleFixture.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('/health (GET)', () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.get('/health')
|
|
21
|
+
.expect(200)
|
|
22
|
+
.expect((res) => {
|
|
23
|
+
expect(res.body).toHaveProperty('status', 'ok');
|
|
24
|
+
expect(res.body).toHaveProperty('timestamp');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('/ping (GET)', () => {
|
|
29
|
+
return request(app.getHttpServer())
|
|
30
|
+
.get('/ping')
|
|
31
|
+
.expect(200)
|
|
32
|
+
.expect((res) => {
|
|
33
|
+
expect(res.body).toHaveProperty('message', 'pong');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterAll(async () => {
|
|
38
|
+
await app.close();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "ES2021",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"strictNullChecks": false,
|
|
16
|
+
"noImplicitAny": false,
|
|
17
|
+
"strictBindCallApply": false,
|
|
18
|
+
"forceConsistentCasingInFileNames": false,
|
|
19
|
+
"noFallthroughCasesInSwitch": false,
|
|
20
|
+
"paths": {
|
|
21
|
+
"@common/*": ["src/common/*"],
|
|
22
|
+
"@config/*": ["src/config/*"],
|
|
23
|
+
"@modules/*": ["src/modules/*"]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|