@urbansolv/create-nestjs-app 1.0.2 → 1.2.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.
- package/dist/templates/nestjs-app/.editorconfig +12 -12
- package/dist/templates/nestjs-app/.env.example +24 -24
- package/dist/templates/nestjs-app/.eslintrc.js +25 -25
- package/dist/templates/nestjs-app/package.json +40 -30
- package/dist/templates/nestjs-app/prisma/schema.prisma +79 -79
- package/dist/templates/nestjs-app/prisma/seed.ts +153 -154
- package/dist/templates/nestjs-app/src/app.module.ts +68 -68
- package/dist/templates/nestjs-app/src/common/constants/permissions.constant.ts +27 -27
- package/dist/templates/nestjs-app/src/common/decorators/api-response.decorator.ts +44 -44
- package/dist/templates/nestjs-app/src/common/decorators/get-user.decorator.ts +11 -11
- package/dist/templates/nestjs-app/src/common/decorators/permissions.decorator.ts +5 -5
- package/dist/templates/nestjs-app/src/common/decorators/public.decorator.ts +4 -4
- package/dist/templates/nestjs-app/src/common/dto/api-response.dto.ts +21 -21
- package/dist/templates/nestjs-app/src/common/dto/pagination.dto.ts +33 -33
- package/dist/templates/nestjs-app/src/common/filters/http-exception.filter.ts +56 -56
- package/dist/templates/nestjs-app/src/common/guards/jwt-auth.guard.ts +32 -32
- package/dist/templates/nestjs-app/src/common/guards/permissions.guard.ts +53 -53
- package/dist/templates/nestjs-app/src/common/interceptors/logging.interceptor.ts +37 -37
- package/dist/templates/nestjs-app/src/common/interceptors/transform.interceptor.ts +55 -55
- package/dist/templates/nestjs-app/src/common/prisma/prisma.module.ts +9 -9
- package/dist/templates/nestjs-app/src/common/prisma/prisma.service.ts +46 -46
- package/dist/templates/nestjs-app/src/common/utils/password.util.ts +13 -13
- package/dist/templates/nestjs-app/src/config/app.config.ts +10 -10
- package/dist/templates/nestjs-app/src/config/database.config.ts +5 -5
- package/dist/templates/nestjs-app/src/config/env.validation.ts +30 -30
- package/dist/templates/nestjs-app/src/config/jwt.config.ts +8 -8
- package/dist/templates/nestjs-app/src/config/swagger.config.ts +6 -6
- package/dist/templates/nestjs-app/src/main.ts +94 -91
- package/dist/templates/nestjs-app/src/modules/auth/auth.module.ts +28 -27
- package/dist/templates/nestjs-app/src/modules/auth/auth.service.ts +180 -54
- package/dist/templates/nestjs-app/src/modules/auth/controllers/v1/auth.controller.ts +33 -33
- package/dist/templates/nestjs-app/src/modules/auth/{dto → core/dto}/auth-response.dto.ts +19 -19
- package/dist/templates/nestjs-app/src/modules/auth/core/dto/login-response.dto.ts +10 -0
- package/dist/templates/nestjs-app/src/modules/auth/{dto → core/dto}/login.dto.ts +15 -15
- package/dist/templates/nestjs-app/src/modules/auth/{dto → core/dto}/register.dto.ts +30 -30
- package/dist/templates/nestjs-app/src/modules/auth/{interfaces → core/interfaces}/jwt-payload.interface.ts +7 -7
- package/dist/templates/nestjs-app/src/modules/auth/{strategies → core/strategies}/jwt.strategy.ts +54 -54
- package/dist/templates/nestjs-app/src/modules/health/health.controller.ts +29 -29
- package/dist/templates/nestjs-app/src/modules/health/health.module.ts +7 -7
- package/dist/templates/nestjs-app/src/modules/users/controllers/v1/users.controller.ts +118 -114
- package/dist/templates/nestjs-app/src/modules/users/core/dto/change-position.dto.ts +9 -9
- package/dist/templates/nestjs-app/src/modules/users/core/dto/create-user.dto.ts +35 -35
- package/dist/templates/nestjs-app/src/modules/users/core/dto/manage-permissions.dto.ts +13 -13
- package/dist/templates/nestjs-app/src/modules/users/core/dto/update-user.dto.ts +30 -30
- package/dist/templates/nestjs-app/src/modules/users/core/dto/user-query.dto.ts +22 -22
- package/dist/templates/nestjs-app/src/modules/users/core/dto/user-response.dto.ts +32 -0
- package/dist/templates/nestjs-app/src/modules/users/core/entities/user.entity.ts +45 -45
- package/dist/templates/nestjs-app/src/modules/users/core/helpers/user-transform.helper.ts +31 -31
- package/dist/templates/nestjs-app/src/modules/users/users.module.ts +10 -10
- package/dist/templates/nestjs-app/src/modules/users/users.service.ts +340 -340
- package/package.json +2 -2
|
@@ -1,114 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Controller,
|
|
3
|
-
Get,
|
|
4
|
-
Post,
|
|
5
|
-
Body,
|
|
6
|
-
Patch,
|
|
7
|
-
Param,
|
|
8
|
-
Delete,
|
|
9
|
-
Query,
|
|
10
|
-
ParseIntPipe,
|
|
11
|
-
HttpCode,
|
|
12
|
-
HttpStatus,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
@
|
|
28
|
-
@
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
@
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
@
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
1
|
+
import {
|
|
2
|
+
Controller,
|
|
3
|
+
Get,
|
|
4
|
+
Post,
|
|
5
|
+
Body,
|
|
6
|
+
Patch,
|
|
7
|
+
Param,
|
|
8
|
+
Delete,
|
|
9
|
+
Query,
|
|
10
|
+
ParseIntPipe,
|
|
11
|
+
HttpCode,
|
|
12
|
+
HttpStatus,
|
|
13
|
+
UseGuards,
|
|
14
|
+
} from '@nestjs/common';
|
|
15
|
+
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
|
|
16
|
+
import { UsersService } from '../../users.service';
|
|
17
|
+
import { CreateUserDto } from '@modules/users/core/dto/create-user.dto';
|
|
18
|
+
import { UpdateUserDto } from '@modules/users/core/dto/update-user.dto';
|
|
19
|
+
import { ChangePositionDto } from '@modules/users/core/dto/change-position.dto';
|
|
20
|
+
import { ManagePermissionsDto } from '@modules/users/core/dto/manage-permissions.dto';
|
|
21
|
+
import { UserQueryDto } from '@modules/users/core/dto/user-query.dto';
|
|
22
|
+
import { UserEntity } from '../../core//entities/user.entity';
|
|
23
|
+
import { Permissions } from '@common/decorators/permissions.decorator';
|
|
24
|
+
import { PERMISSIONS } from '@common/constants/permissions.constant';
|
|
25
|
+
import { ApiSuccessResponse, ApiSuccessArrayResponse } from '@common/decorators/api-response.decorator';
|
|
26
|
+
import { PaginatedResponseDto } from '@common/dto/pagination.dto';
|
|
27
|
+
import { AuthGuard } from '@nestjs/passport';
|
|
28
|
+
import { PermissionsGuard } from '@common/guards/permissions.guard';
|
|
29
|
+
|
|
30
|
+
@ApiTags('Users')
|
|
31
|
+
@ApiBearerAuth('JWT-auth')
|
|
32
|
+
@Controller({ path: 'users', version: '1' })
|
|
33
|
+
@UseGuards(AuthGuard('jwt'), PermissionsGuard)
|
|
34
|
+
export class UsersController {
|
|
35
|
+
constructor(private readonly usersService: UsersService) {}
|
|
36
|
+
|
|
37
|
+
@Post()
|
|
38
|
+
@Permissions(PERMISSIONS.USER.ADD)
|
|
39
|
+
@ApiOperation({ summary: 'Create a new user' })
|
|
40
|
+
@ApiSuccessResponse(UserEntity)
|
|
41
|
+
async create(@Body() createUserDto: CreateUserDto): Promise<UserEntity> {
|
|
42
|
+
return this.usersService.create(createUserDto);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Get()
|
|
46
|
+
@Permissions(PERMISSIONS.USER.VIEW)
|
|
47
|
+
@ApiOperation({ summary: 'Get all users with pagination and filters' })
|
|
48
|
+
@ApiSuccessResponse(PaginatedResponseDto<UserEntity>)
|
|
49
|
+
async findAll(@Query() query: UserQueryDto): Promise<PaginatedResponseDto<UserEntity>> {
|
|
50
|
+
return this.usersService.findAll(query);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Get(':id')
|
|
54
|
+
@Permissions(PERMISSIONS.USER.VIEW)
|
|
55
|
+
@ApiOperation({ summary: 'Get user by ID' })
|
|
56
|
+
@ApiParam({ name: 'id', type: Number })
|
|
57
|
+
@ApiSuccessResponse(UserEntity)
|
|
58
|
+
async findOne(@Param('id', ParseIntPipe) id: number): Promise<UserEntity> {
|
|
59
|
+
return this.usersService.findOne(id);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Patch(':id')
|
|
63
|
+
@Permissions(PERMISSIONS.USER.UPDATE)
|
|
64
|
+
@ApiOperation({ summary: 'Update user' })
|
|
65
|
+
@ApiParam({ name: 'id', type: Number })
|
|
66
|
+
@ApiSuccessResponse(UserEntity)
|
|
67
|
+
async update(
|
|
68
|
+
@Param('id', ParseIntPipe) id: number,
|
|
69
|
+
@Body() updateUserDto: UpdateUserDto,
|
|
70
|
+
): Promise<UserEntity> {
|
|
71
|
+
return this.usersService.update(id, updateUserDto);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Delete(':id')
|
|
75
|
+
@Permissions(PERMISSIONS.USER.DELETE)
|
|
76
|
+
@HttpCode(HttpStatus.NO_CONTENT)
|
|
77
|
+
@ApiOperation({ summary: 'Delete user (soft delete)' })
|
|
78
|
+
@ApiParam({ name: 'id', type: Number })
|
|
79
|
+
async remove(@Param('id', ParseIntPipe) id: number): Promise<void> {
|
|
80
|
+
return this.usersService.remove(id);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Patch(':id/position')
|
|
84
|
+
@Permissions(PERMISSIONS.USER.CHANGE_POSITION)
|
|
85
|
+
@ApiOperation({ summary: 'Change user position/role' })
|
|
86
|
+
@ApiParam({ name: 'id', type: Number })
|
|
87
|
+
@ApiSuccessResponse(UserEntity)
|
|
88
|
+
async changePosition(
|
|
89
|
+
@Param('id', ParseIntPipe) id: number,
|
|
90
|
+
@Body() changePositionDto: ChangePositionDto,
|
|
91
|
+
): Promise<UserEntity> {
|
|
92
|
+
return this.usersService.changePosition(id, changePositionDto);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Post(':id/permissions/assign')
|
|
96
|
+
@Permissions(PERMISSIONS.USER.MANAGE_PERMISSION)
|
|
97
|
+
@ApiOperation({ summary: 'Assign permissions to user position' })
|
|
98
|
+
@ApiParam({ name: 'id', type: Number })
|
|
99
|
+
@ApiSuccessResponse(UserEntity)
|
|
100
|
+
async assignPermissions(
|
|
101
|
+
@Param('id', ParseIntPipe) id: number,
|
|
102
|
+
@Body() managePermissionsDto: ManagePermissionsDto,
|
|
103
|
+
): Promise<UserEntity> {
|
|
104
|
+
return this.usersService.assignPermissions(id, managePermissionsDto);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Post(':id/permissions/revoke')
|
|
108
|
+
@Permissions(PERMISSIONS.USER.MANAGE_PERMISSION)
|
|
109
|
+
@ApiOperation({ summary: 'Revoke permissions from user position' })
|
|
110
|
+
@ApiParam({ name: 'id', type: Number })
|
|
111
|
+
@ApiSuccessResponse(UserEntity)
|
|
112
|
+
async revokePermissions(
|
|
113
|
+
@Param('id', ParseIntPipe) id: number,
|
|
114
|
+
@Body() managePermissionsDto: ManagePermissionsDto,
|
|
115
|
+
): Promise<UserEntity> {
|
|
116
|
+
return this.usersService.revokePermissions(id, managePermissionsDto);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
-
import { IsInt, IsNotEmpty } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export class ChangePositionDto {
|
|
5
|
-
@ApiProperty({ example: 2, description: 'New position ID' })
|
|
6
|
-
@IsInt({ message: 'Position ID must be an integer' })
|
|
7
|
-
@IsNotEmpty({ message: 'Position ID is required' })
|
|
8
|
-
position_id: number;
|
|
9
|
-
}
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import { IsInt, IsNotEmpty } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
export class ChangePositionDto {
|
|
5
|
+
@ApiProperty({ example: 2, description: 'New position ID' })
|
|
6
|
+
@IsInt({ message: 'Position ID must be an integer' })
|
|
7
|
+
@IsNotEmpty({ message: 'Position ID is required' })
|
|
8
|
+
position_id: number;
|
|
9
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
-
import { IsEmail, IsNotEmpty, IsString, MinLength, IsInt, IsBoolean, IsOptional } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export class CreateUserDto {
|
|
5
|
-
@ApiProperty({ example: 'bhagaskoro@urbansolv.co.id' })
|
|
6
|
-
@IsEmail({}, { message: 'Please provide a valid email address' })
|
|
7
|
-
@IsNotEmpty({ message: 'Email is required' })
|
|
8
|
-
email: string;
|
|
9
|
-
|
|
10
|
-
@ApiProperty({ example: 'password123' })
|
|
11
|
-
@IsString()
|
|
12
|
-
@IsNotEmpty({ message: 'Password is required' })
|
|
13
|
-
@MinLength(6, { message: 'Password must be at least 6 characters long' })
|
|
14
|
-
password: string;
|
|
15
|
-
|
|
16
|
-
@ApiProperty({ example: 'Bhagas' })
|
|
17
|
-
@IsString()
|
|
18
|
-
@IsNotEmpty({ message: 'First name is required' })
|
|
19
|
-
first_name: string;
|
|
20
|
-
|
|
21
|
-
@ApiProperty({ example: 'Koro' })
|
|
22
|
-
@IsString()
|
|
23
|
-
@IsNotEmpty({ message: 'Last name is required' })
|
|
24
|
-
last_name: string;
|
|
25
|
-
|
|
26
|
-
@ApiProperty({ example: 2, description: 'Position ID' })
|
|
27
|
-
@IsInt({ message: 'Position ID must be an integer' })
|
|
28
|
-
@IsNotEmpty({ message: 'Position ID is required' })
|
|
29
|
-
position_id: number;
|
|
30
|
-
|
|
31
|
-
@ApiProperty({ example: true, default: true })
|
|
32
|
-
@IsBoolean()
|
|
33
|
-
@IsOptional()
|
|
34
|
-
is_active?: boolean = true;
|
|
35
|
-
}
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import { IsEmail, IsNotEmpty, IsString, MinLength, IsInt, IsBoolean, IsOptional } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
export class CreateUserDto {
|
|
5
|
+
@ApiProperty({ example: 'bhagaskoro@urbansolv.co.id' })
|
|
6
|
+
@IsEmail({}, { message: 'Please provide a valid email address' })
|
|
7
|
+
@IsNotEmpty({ message: 'Email is required' })
|
|
8
|
+
email: string;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ example: 'password123' })
|
|
11
|
+
@IsString()
|
|
12
|
+
@IsNotEmpty({ message: 'Password is required' })
|
|
13
|
+
@MinLength(6, { message: 'Password must be at least 6 characters long' })
|
|
14
|
+
password: string;
|
|
15
|
+
|
|
16
|
+
@ApiProperty({ example: 'Bhagas' })
|
|
17
|
+
@IsString()
|
|
18
|
+
@IsNotEmpty({ message: 'First name is required' })
|
|
19
|
+
first_name: string;
|
|
20
|
+
|
|
21
|
+
@ApiProperty({ example: 'Koro' })
|
|
22
|
+
@IsString()
|
|
23
|
+
@IsNotEmpty({ message: 'Last name is required' })
|
|
24
|
+
last_name: string;
|
|
25
|
+
|
|
26
|
+
@ApiProperty({ example: 2, description: 'Position ID' })
|
|
27
|
+
@IsInt({ message: 'Position ID must be an integer' })
|
|
28
|
+
@IsNotEmpty({ message: 'Position ID is required' })
|
|
29
|
+
position_id: number;
|
|
30
|
+
|
|
31
|
+
@ApiProperty({ example: true, default: true })
|
|
32
|
+
@IsBoolean()
|
|
33
|
+
@IsOptional()
|
|
34
|
+
is_active?: boolean = true;
|
|
35
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
-
import { IsArray, ArrayNotEmpty, IsString } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export class ManagePermissionsDto {
|
|
5
|
-
@ApiProperty({
|
|
6
|
-
example: ['VIEW_USER', 'ADD_USER'],
|
|
7
|
-
description: 'Array of permission names to assign or revoke'
|
|
8
|
-
})
|
|
9
|
-
@IsArray()
|
|
10
|
-
@ArrayNotEmpty({ message: 'Permissions array cannot be empty' })
|
|
11
|
-
@IsString({ each: true })
|
|
12
|
-
permissions: string[];
|
|
13
|
-
}
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import { IsArray, ArrayNotEmpty, IsString } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
export class ManagePermissionsDto {
|
|
5
|
+
@ApiProperty({
|
|
6
|
+
example: ['VIEW_USER', 'ADD_USER'],
|
|
7
|
+
description: 'Array of permission names to assign or revoke'
|
|
8
|
+
})
|
|
9
|
+
@IsArray()
|
|
10
|
+
@ArrayNotEmpty({ message: 'Permissions array cannot be empty' })
|
|
11
|
+
@IsString({ each: true })
|
|
12
|
+
permissions: string[];
|
|
13
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
-
import { IsEmail, IsString, MinLength, IsBoolean, IsOptional } from 'class-validator';
|
|
3
|
-
|
|
4
|
-
export class UpdateUserDto {
|
|
5
|
-
@ApiPropertyOptional({ example: 'bhagaskoro@urbansolv.co.id' })
|
|
6
|
-
@IsEmail({}, { message: 'Please provide a valid email address' })
|
|
7
|
-
@IsOptional()
|
|
8
|
-
email?: string;
|
|
9
|
-
|
|
10
|
-
@ApiPropertyOptional({ example: 'newpassword123' })
|
|
11
|
-
@IsString()
|
|
12
|
-
@MinLength(6, { message: 'Password must be at least 6 characters long' })
|
|
13
|
-
@IsOptional()
|
|
14
|
-
password?: string;
|
|
15
|
-
|
|
16
|
-
@ApiPropertyOptional({ example: 'Bhagas' })
|
|
17
|
-
@IsString()
|
|
18
|
-
@IsOptional()
|
|
19
|
-
first_name?: string;
|
|
20
|
-
|
|
21
|
-
@ApiPropertyOptional({ example: 'Koro' })
|
|
22
|
-
@IsString()
|
|
23
|
-
@IsOptional()
|
|
24
|
-
last_name?: string;
|
|
25
|
-
|
|
26
|
-
@ApiPropertyOptional({ example: true })
|
|
27
|
-
@IsBoolean()
|
|
28
|
-
@IsOptional()
|
|
29
|
-
is_active?: boolean;
|
|
30
|
-
}
|
|
1
|
+
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { IsEmail, IsString, MinLength, IsBoolean, IsOptional } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
export class UpdateUserDto {
|
|
5
|
+
@ApiPropertyOptional({ example: 'bhagaskoro@urbansolv.co.id' })
|
|
6
|
+
@IsEmail({}, { message: 'Please provide a valid email address' })
|
|
7
|
+
@IsOptional()
|
|
8
|
+
email?: string;
|
|
9
|
+
|
|
10
|
+
@ApiPropertyOptional({ example: 'newpassword123' })
|
|
11
|
+
@IsString()
|
|
12
|
+
@MinLength(6, { message: 'Password must be at least 6 characters long' })
|
|
13
|
+
@IsOptional()
|
|
14
|
+
password?: string;
|
|
15
|
+
|
|
16
|
+
@ApiPropertyOptional({ example: 'Bhagas' })
|
|
17
|
+
@IsString()
|
|
18
|
+
@IsOptional()
|
|
19
|
+
first_name?: string;
|
|
20
|
+
|
|
21
|
+
@ApiPropertyOptional({ example: 'Koro' })
|
|
22
|
+
@IsString()
|
|
23
|
+
@IsOptional()
|
|
24
|
+
last_name?: string;
|
|
25
|
+
|
|
26
|
+
@ApiPropertyOptional({ example: true })
|
|
27
|
+
@IsBoolean()
|
|
28
|
+
@IsOptional()
|
|
29
|
+
is_active?: boolean;
|
|
30
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
-
import { IsOptional, IsString, IsBoolean } from 'class-validator';
|
|
3
|
-
import { Type } from 'class-transformer';
|
|
4
|
-
import { PaginationDto } from '@common/dto/pagination.dto';
|
|
5
|
-
|
|
6
|
-
export class UserQueryDto extends PaginationDto {
|
|
7
|
-
@ApiPropertyOptional({ example: 'bhagas' })
|
|
8
|
-
@IsOptional()
|
|
9
|
-
@IsString()
|
|
10
|
-
search?: string;
|
|
11
|
-
|
|
12
|
-
@ApiPropertyOptional({ example: true })
|
|
13
|
-
@IsOptional()
|
|
14
|
-
@Type(() => Boolean)
|
|
15
|
-
@IsBoolean()
|
|
16
|
-
is_active?: boolean;
|
|
17
|
-
|
|
18
|
-
@ApiPropertyOptional({ example: 1 })
|
|
19
|
-
@IsOptional()
|
|
20
|
-
@Type(() => Number)
|
|
21
|
-
position_id?: number;
|
|
22
|
-
}
|
|
1
|
+
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { IsOptional, IsString, IsBoolean } from 'class-validator';
|
|
3
|
+
import { Type } from 'class-transformer';
|
|
4
|
+
import { PaginationDto } from '@common/dto/pagination.dto';
|
|
5
|
+
|
|
6
|
+
export class UserQueryDto extends PaginationDto {
|
|
7
|
+
@ApiPropertyOptional({ example: 'bhagas' })
|
|
8
|
+
@IsOptional()
|
|
9
|
+
@IsString()
|
|
10
|
+
search?: string;
|
|
11
|
+
|
|
12
|
+
@ApiPropertyOptional({ example: true })
|
|
13
|
+
@IsOptional()
|
|
14
|
+
@Type(() => Boolean)
|
|
15
|
+
@IsBoolean()
|
|
16
|
+
is_active?: boolean;
|
|
17
|
+
|
|
18
|
+
@ApiPropertyOptional({ example: 1 })
|
|
19
|
+
@IsOptional()
|
|
20
|
+
@Type(() => Number)
|
|
21
|
+
position_id?: number;
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import { Exclude } from 'class-transformer';
|
|
3
|
+
|
|
4
|
+
export class UserResponseDto {
|
|
5
|
+
@ApiProperty()
|
|
6
|
+
id: number;
|
|
7
|
+
|
|
8
|
+
@ApiProperty()
|
|
9
|
+
email: string;
|
|
10
|
+
|
|
11
|
+
@ApiProperty({ required: false })
|
|
12
|
+
first_name?: string;
|
|
13
|
+
|
|
14
|
+
@ApiProperty({ required: false })
|
|
15
|
+
last_name?: string;
|
|
16
|
+
|
|
17
|
+
@ApiProperty()
|
|
18
|
+
is_active: boolean;
|
|
19
|
+
|
|
20
|
+
@ApiProperty()
|
|
21
|
+
created_at: Date;
|
|
22
|
+
|
|
23
|
+
@ApiProperty()
|
|
24
|
+
updated_at: Date;
|
|
25
|
+
|
|
26
|
+
@Exclude()
|
|
27
|
+
password: string;
|
|
28
|
+
|
|
29
|
+
constructor(partial: Partial<UserResponseDto>) {
|
|
30
|
+
Object.assign(this, partial);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,45 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,31 +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
|
-
}
|
|
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
|
+
}
|