rez_core 1.0.48 → 1.0.49
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/.idea/250218_nodejs_core.iml +12 -0
- package/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/dataSources.xml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/data/master.xlsx +0 -0
- package/dist/constant/global.constant.d.ts +1 -0
- package/dist/constant/global.constant.js +2 -1
- package/dist/constant/global.constant.js.map +1 -1
- package/dist/module/auth/guards/role.guard.js +3 -3
- package/dist/module/master/service/master.service.js +14 -0
- package/dist/module/master/service/master.service.js.map +1 -1
- package/dist/module/meta/controller/entity.controller.d.ts +6 -2
- package/dist/module/meta/controller/entity.controller.js +13 -6
- package/dist/module/meta/controller/entity.controller.js.map +1 -1
- package/dist/module/module/controller/module-access.controller.d.ts +7 -1
- package/dist/module/module/controller/module-access.controller.js +19 -8
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +3 -2
- package/dist/module/module/repository/module-access.repository.js +30 -13
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +6 -3
- package/dist/module/module/service/module-access.service.js +25 -13
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/module/user/entity/user-role-mapping.entity.d.ts +1 -0
- package/dist/module/user/entity/user-role-mapping.entity.js +6 -0
- package/dist/module/user/entity/user-role-mapping.entity.js.map +1 -1
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/constant/global.constant.ts +2 -0
- package/src/module/auth/guards/jwt.guard.ts +22 -22
- package/src/module/auth/guards/role.guard.ts +68 -68
- package/src/module/auth/services/jwt.service.ts +11 -11
- package/src/module/auth/strategies/local.strategy.ts +13 -13
- package/src/module/dev/dev.module.ts +12 -12
- package/src/module/dev/service/dev.service.ts +7 -7
- package/src/module/enterprise/entity/enterprise.entity.ts +37 -37
- package/src/module/enterprise/entity/organization.entity.ts +80 -80
- package/src/module/master/service/master.service.ts +14 -0
- package/src/module/meta/controller/entity.controller.ts +14 -3
- package/src/module/meta/dto/entity-list-data.dto.ts +6 -6
- package/src/module/meta/entity/preference.entity.ts +65 -65
- package/src/module/meta/repository/preference.repository.ts +20 -20
- package/src/module/module/controller/menu.controller.ts +15 -15
- package/src/module/module/controller/module-access.controller.ts +16 -4
- package/src/module/module/entity/module-access.entity.ts +22 -22
- package/src/module/module/entity/module-action.entity.ts +19 -19
- package/src/module/module/repository/module-access.repository.ts +81 -47
- package/src/module/module/service/module-access.service.ts +39 -19
- package/src/module/user/controller/user.controller.ts +28 -28
- package/src/module/user/dto/update-user.dto.ts +4 -4
- package/src/module/user/entity/user-role-mapping.entity.ts +5 -0
- package/src/module/user/entity/user-session.entity.ts +61 -61
- package/src/module/user/repository/userSession.repository.ts +33 -33
- package/src/module/user/service/role.service.ts +1 -0
- package/src/resources/dev.properties.yaml +6 -6
- package/src/utils/service/encryptUtil.service.ts +97 -97
- package/src/utils/service/excelUtil.service.ts +15 -15
- package/src/utils/service/reflection-helper.service.ts +53 -53
|
@@ -4,12 +4,15 @@ import { RoleRepository } from 'src/module/user/repository/role.repository';
|
|
|
4
4
|
import { RoleService } from '../../user/service/role.service';
|
|
5
5
|
import { ENTITYTYPE_ROLE } from '../../../constant/global.constant';
|
|
6
6
|
import { Role } from '../../user/entity/role.entity';
|
|
7
|
+
import { EntityManager } from 'typeorm';
|
|
8
|
+
import { UserData } from 'src/module/user/entity/user.entity';
|
|
7
9
|
|
|
8
10
|
@Injectable()
|
|
9
11
|
export class ModuleAccessService {
|
|
10
12
|
constructor(
|
|
11
13
|
private readonly moduleAccessRepository: ModuleAccessRepository,
|
|
12
14
|
@Inject('RoleService') private readonly roleService: RoleService,
|
|
15
|
+
private readonly entityManager: EntityManager,
|
|
13
16
|
) {}
|
|
14
17
|
|
|
15
18
|
async getRoles() {
|
|
@@ -45,13 +48,16 @@ export class ModuleAccessService {
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
async createRole(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
async createRole(
|
|
52
|
+
body: {
|
|
53
|
+
name: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
status?: 'ACTIVE' | 'INACTIVE';
|
|
56
|
+
copyFromRoleId?: number;
|
|
57
|
+
},
|
|
58
|
+
loggedInUser: UserData,
|
|
59
|
+
) {
|
|
60
|
+
return this.moduleAccessRepository.createRole(body, loggedInUser);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
async updateRole(
|
|
@@ -62,30 +68,44 @@ export class ModuleAccessService {
|
|
|
62
68
|
status?: 'ACTIVE' | 'INACTIVE';
|
|
63
69
|
copyFromRoleId?: number;
|
|
64
70
|
},
|
|
71
|
+
loggedInUser: UserData,
|
|
65
72
|
) {
|
|
66
73
|
if (!body.name) {
|
|
67
74
|
throw new BadRequestException('Role name is required');
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
if (body.status === 'INACTIVE') {
|
|
78
|
+
//get role by id
|
|
79
|
+
const entityData = await this.roleService.getEntityData(
|
|
80
|
+
ENTITYTYPE_ROLE,
|
|
81
|
+
id,
|
|
82
|
+
);
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (body.status === 'INACTIVE' && role.is_system === 1) {
|
|
78
|
-
throw new BadRequestException('Cannot deactivate system role');
|
|
79
|
-
}
|
|
84
|
+
const associatedUsers = await this.entityManager.query(`SELECT map.*
|
|
85
|
+
FROM cr_user_role_mapping map
|
|
86
|
+
JOIN cr_user usr ON map.user_id = usr.id
|
|
87
|
+
WHERE usr.status = 'ACTIVE' and map.role_id = ${entityData?.id}`);
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
if (associatedUsers.length > 0) {
|
|
90
|
+
throw new BadRequestException(
|
|
91
|
+
'Cannot deactivate role as it is associated with active users',
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!entityData) {
|
|
96
|
+
throw new BadRequestException('Role not found');
|
|
97
|
+
}
|
|
98
|
+
const role = entityData as Role;
|
|
99
|
+
if (role.is_system === 1) {
|
|
100
|
+
throw new BadRequestException('Cannot deactivate system role');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
83
103
|
|
|
84
104
|
return this.moduleAccessRepository.updateRole(id, {
|
|
85
105
|
name: body.name,
|
|
86
106
|
description: body.description,
|
|
87
107
|
status: body.status,
|
|
88
108
|
copyFromRoleId: body.copyFromRoleId,
|
|
89
|
-
});
|
|
109
|
+
}, loggedInUser);
|
|
90
110
|
}
|
|
91
111
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Body,
|
|
3
|
-
Controller,
|
|
4
|
-
HttpStatus,
|
|
5
|
-
Inject,
|
|
6
|
-
Post,
|
|
7
|
-
Res,
|
|
8
|
-
ValidationPipe,
|
|
9
|
-
} from '@nestjs/common';
|
|
10
|
-
import { UserService } from '../service/user.service';
|
|
11
|
-
import { CreateUserDto } from '../dto/create-user.dto';
|
|
12
|
-
import { Response } from 'express';
|
|
13
|
-
|
|
14
|
-
@Controller('user')
|
|
15
|
-
export class UserController {
|
|
16
|
-
constructor(
|
|
17
|
-
@Inject('UserService') private readonly userService: UserService,
|
|
18
|
-
) {}
|
|
19
|
-
|
|
20
|
-
@Post('signup')
|
|
21
|
-
async signup(
|
|
22
|
-
@Body(new ValidationPipe()) createUserDto: CreateUserDto,
|
|
23
|
-
@Res() res: Response,
|
|
24
|
-
) {
|
|
25
|
-
const result = await this.userService.createEntity(createUserDto, null);
|
|
26
|
-
res.status(HttpStatus.OK).json(result);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Body,
|
|
3
|
+
Controller,
|
|
4
|
+
HttpStatus,
|
|
5
|
+
Inject,
|
|
6
|
+
Post,
|
|
7
|
+
Res,
|
|
8
|
+
ValidationPipe,
|
|
9
|
+
} from '@nestjs/common';
|
|
10
|
+
import { UserService } from '../service/user.service';
|
|
11
|
+
import { CreateUserDto } from '../dto/create-user.dto';
|
|
12
|
+
import { Response } from 'express';
|
|
13
|
+
|
|
14
|
+
@Controller('user')
|
|
15
|
+
export class UserController {
|
|
16
|
+
constructor(
|
|
17
|
+
@Inject('UserService') private readonly userService: UserService,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
@Post('signup')
|
|
21
|
+
async signup(
|
|
22
|
+
@Body(new ValidationPipe()) createUserDto: CreateUserDto,
|
|
23
|
+
@Res() res: Response,
|
|
24
|
+
) {
|
|
25
|
+
const result = await this.userService.createEntity(createUserDto, null);
|
|
26
|
+
res.status(HttpStatus.OK).json(result);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PartialType } from '@nestjs/mapped-types';
|
|
2
|
-
import { CreateUserDto } from './create-user.dto';
|
|
3
|
-
|
|
4
|
-
export class UpdateUserDto extends PartialType(CreateUserDto) {}
|
|
1
|
+
import { PartialType } from '@nestjs/mapped-types';
|
|
2
|
+
import { CreateUserDto } from './create-user.dto';
|
|
3
|
+
|
|
4
|
+
export class UpdateUserDto extends PartialType(CreateUserDto) {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ENTITYTYPE_USRROLMAP } from 'src/constant/global.constant';
|
|
1
2
|
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
3
|
|
|
3
4
|
@Entity({ name: 'cr_user_role_mapping' })
|
|
@@ -5,11 +6,15 @@ export class UserRoleMapping {
|
|
|
5
6
|
constructor(user_id: number, role_id: number) {
|
|
6
7
|
this.user_id = user_id;
|
|
7
8
|
this.role_id = role_id;
|
|
9
|
+
this.entity_type = ENTITYTYPE_USRROLMAP;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
@PrimaryGeneratedColumn()
|
|
11
13
|
id: number;
|
|
12
14
|
|
|
15
|
+
@Column({type: 'varchar'})
|
|
16
|
+
entity_type: string;
|
|
17
|
+
|
|
13
18
|
@Column({ type: 'bigint', nullable: true })
|
|
14
19
|
user_id: number;
|
|
15
20
|
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
-
|
|
3
|
-
@Entity({ name: 'cr_user_session' })
|
|
4
|
-
export class UserSession {
|
|
5
|
-
@PrimaryGeneratedColumn()
|
|
6
|
-
id: number;
|
|
7
|
-
|
|
8
|
-
@Column({
|
|
9
|
-
name: 'is_session_loggedout',
|
|
10
|
-
nullable: true,
|
|
11
|
-
type: 'int',
|
|
12
|
-
})
|
|
13
|
-
is_session_loggedout: number;
|
|
14
|
-
|
|
15
|
-
@Column({
|
|
16
|
-
name: 'login_id',
|
|
17
|
-
nullable: true,
|
|
18
|
-
length: 50,
|
|
19
|
-
})
|
|
20
|
-
login_id: string;
|
|
21
|
-
|
|
22
|
-
@Column({
|
|
23
|
-
name: 'login_time',
|
|
24
|
-
nullable: true,
|
|
25
|
-
})
|
|
26
|
-
login_time: Date;
|
|
27
|
-
|
|
28
|
-
@Column({
|
|
29
|
-
name: 'logout_time',
|
|
30
|
-
nullable: true,
|
|
31
|
-
})
|
|
32
|
-
logout_time: Date;
|
|
33
|
-
|
|
34
|
-
@Column({
|
|
35
|
-
name: 'session_key',
|
|
36
|
-
nullable: true,
|
|
37
|
-
length: 100,
|
|
38
|
-
})
|
|
39
|
-
session_key: string;
|
|
40
|
-
|
|
41
|
-
@Column({
|
|
42
|
-
name: 'user_id',
|
|
43
|
-
nullable: true,
|
|
44
|
-
type: 'bigint',
|
|
45
|
-
})
|
|
46
|
-
user_id: number;
|
|
47
|
-
|
|
48
|
-
@Column({
|
|
49
|
-
name: 'access_token',
|
|
50
|
-
nullable: true,
|
|
51
|
-
type: 'varchar',
|
|
52
|
-
length: 5000,
|
|
53
|
-
})
|
|
54
|
-
access_token: string;
|
|
55
|
-
|
|
56
|
-
@Column({
|
|
57
|
-
name: 'expiry_date',
|
|
58
|
-
nullable: true,
|
|
59
|
-
})
|
|
60
|
-
expiry_date: Date;
|
|
61
|
-
}
|
|
1
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
@Entity({ name: 'cr_user_session' })
|
|
4
|
+
export class UserSession {
|
|
5
|
+
@PrimaryGeneratedColumn()
|
|
6
|
+
id: number;
|
|
7
|
+
|
|
8
|
+
@Column({
|
|
9
|
+
name: 'is_session_loggedout',
|
|
10
|
+
nullable: true,
|
|
11
|
+
type: 'int',
|
|
12
|
+
})
|
|
13
|
+
is_session_loggedout: number;
|
|
14
|
+
|
|
15
|
+
@Column({
|
|
16
|
+
name: 'login_id',
|
|
17
|
+
nullable: true,
|
|
18
|
+
length: 50,
|
|
19
|
+
})
|
|
20
|
+
login_id: string;
|
|
21
|
+
|
|
22
|
+
@Column({
|
|
23
|
+
name: 'login_time',
|
|
24
|
+
nullable: true,
|
|
25
|
+
})
|
|
26
|
+
login_time: Date;
|
|
27
|
+
|
|
28
|
+
@Column({
|
|
29
|
+
name: 'logout_time',
|
|
30
|
+
nullable: true,
|
|
31
|
+
})
|
|
32
|
+
logout_time: Date;
|
|
33
|
+
|
|
34
|
+
@Column({
|
|
35
|
+
name: 'session_key',
|
|
36
|
+
nullable: true,
|
|
37
|
+
length: 100,
|
|
38
|
+
})
|
|
39
|
+
session_key: string;
|
|
40
|
+
|
|
41
|
+
@Column({
|
|
42
|
+
name: 'user_id',
|
|
43
|
+
nullable: true,
|
|
44
|
+
type: 'bigint',
|
|
45
|
+
})
|
|
46
|
+
user_id: number;
|
|
47
|
+
|
|
48
|
+
@Column({
|
|
49
|
+
name: 'access_token',
|
|
50
|
+
nullable: true,
|
|
51
|
+
type: 'varchar',
|
|
52
|
+
length: 5000,
|
|
53
|
+
})
|
|
54
|
+
access_token: string;
|
|
55
|
+
|
|
56
|
+
@Column({
|
|
57
|
+
name: 'expiry_date',
|
|
58
|
+
nullable: true,
|
|
59
|
+
})
|
|
60
|
+
expiry_date: Date;
|
|
61
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Repository } from 'typeorm';
|
|
2
|
-
import { UserSession } from '../entity/user-session.entity';
|
|
3
|
-
import { Injectable } from '@nestjs/common';
|
|
4
|
-
import { InjectRepository } from '@nestjs/typeorm';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class UserSessionRepository {
|
|
8
|
-
constructor(
|
|
9
|
-
@InjectRepository(UserSession)
|
|
10
|
-
private userSessionRepo: Repository<UserSession>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findBySessionKey(sessionKey: string): Promise<UserSession | null> {
|
|
14
|
-
return this.userSessionRepo.findOne({ where: { session_key: sessionKey } });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async findActiveSessionByUserId(userId: number): Promise<UserSession | null> {
|
|
18
|
-
return this.userSessionRepo.findOne({
|
|
19
|
-
where: { user_id: userId, is_session_loggedout: 0 },
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async saveSession(session: UserSession): Promise<UserSession> {
|
|
24
|
-
return this.userSessionRepo.save(session);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async logoutSession(sessionKey: string): Promise<void> {
|
|
28
|
-
await this.userSessionRepo.update(
|
|
29
|
-
{ session_key: sessionKey },
|
|
30
|
-
{ is_session_loggedout: 1, logout_time: new Date() },
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { UserSession } from '../entity/user-session.entity';
|
|
3
|
+
import { Injectable } from '@nestjs/common';
|
|
4
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class UserSessionRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(UserSession)
|
|
10
|
+
private userSessionRepo: Repository<UserSession>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findBySessionKey(sessionKey: string): Promise<UserSession | null> {
|
|
14
|
+
return this.userSessionRepo.findOne({ where: { session_key: sessionKey } });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async findActiveSessionByUserId(userId: number): Promise<UserSession | null> {
|
|
18
|
+
return this.userSessionRepo.findOne({
|
|
19
|
+
where: { user_id: userId, is_session_loggedout: 0 },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async saveSession(session: UserSession): Promise<UserSession> {
|
|
24
|
+
return this.userSessionRepo.save(session);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async logoutSession(sessionKey: string): Promise<void> {
|
|
28
|
+
await this.userSessionRepo.update(
|
|
29
|
+
{ session_key: sessionKey },
|
|
30
|
+
{ is_session_loggedout: 1, logout_time: new Date() },
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -13,9 +13,9 @@ OTP_EXPIRY: "10"
|
|
|
13
13
|
OTP_LENGTH: "6"
|
|
14
14
|
VERIFY_OTP: "false"
|
|
15
15
|
DEFAULT_OTP: "123456"
|
|
16
|
-
AWS:
|
|
17
|
-
S3:
|
|
18
|
-
AWS_ACCESS_KEY_ID: "AKIAYYKIBDDSQF3KILGE"
|
|
19
|
-
AWS_SECRET_KEY: "PPDMAeO2mVUY1w2f46n/dlt5l9+7NY7E9twJb9LU"
|
|
20
|
-
AWS_REGION: "ap-south-1"
|
|
21
|
-
BUCKET_NAME: "testether"
|
|
16
|
+
#AWS:
|
|
17
|
+
# S3:
|
|
18
|
+
# AWS_ACCESS_KEY_ID: "AKIAYYKIBDDSQF3KILGE"
|
|
19
|
+
# AWS_SECRET_KEY: "PPDMAeO2mVUY1w2f46n/dlt5l9+7NY7E9twJb9LU"
|
|
20
|
+
# AWS_REGION: "ap-south-1"
|
|
21
|
+
# BUCKET_NAME: "testether"
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
2
|
-
import * as crypto from 'crypto';
|
|
3
|
-
|
|
4
|
-
const CryptoJS = require('crypto-js');
|
|
5
|
-
const encryptionType = 'aes-256-cbc';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class EncryptUtilService {
|
|
9
|
-
constructor() {}
|
|
10
|
-
|
|
11
|
-
static encryptGCM(data: any, Datakey: string, Dataiv: string) {
|
|
12
|
-
try {
|
|
13
|
-
const cipher = crypto.createCipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
14
|
-
let encrypted = Buffer.concat([
|
|
15
|
-
cipher.update(data, 'utf8'),
|
|
16
|
-
cipher.final(),
|
|
17
|
-
]);
|
|
18
|
-
const tag = cipher.getAuthTag();
|
|
19
|
-
return Buffer.concat([encrypted, tag]).toString('base64');
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static decryptGCM(data: any, Datakey: any, Dataiv: any) {
|
|
26
|
-
try {
|
|
27
|
-
data = Buffer.from(data, 'base64');
|
|
28
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
29
|
-
const tag = data.slice(data.length - 16);
|
|
30
|
-
decipher.setAuthTag(tag);
|
|
31
|
-
data = data.slice(0, data.length - 16);
|
|
32
|
-
let decrypted = decipher.update(data, 'utf8') + decipher.final('utf8');
|
|
33
|
-
return decrypted;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static encryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
40
|
-
let encryptedRequest;
|
|
41
|
-
try {
|
|
42
|
-
let cipher = CryptoJS.AES.encrypt(data, Datakey, {
|
|
43
|
-
iv: Dataiv,
|
|
44
|
-
mode: CryptoJS.mode.CBC,
|
|
45
|
-
});
|
|
46
|
-
encryptedRequest = cipher.toString();
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.log(error);
|
|
49
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
50
|
-
}
|
|
51
|
-
return encryptedRequest;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static decryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
55
|
-
let decryptRequest;
|
|
56
|
-
try {
|
|
57
|
-
let cipher = CryptoJS.AES.decrypt(data, Datakey, {
|
|
58
|
-
iv: Dataiv,
|
|
59
|
-
mode: CryptoJS.mode.CBC,
|
|
60
|
-
});
|
|
61
|
-
decryptRequest = cipher.toString(CryptoJS.enc.Utf8);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
64
|
-
}
|
|
65
|
-
return decryptRequest;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static encryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
69
|
-
try {
|
|
70
|
-
switch (type) {
|
|
71
|
-
case 'GCM':
|
|
72
|
-
return this.encryptGCM(data, Datakey, Dataiv);
|
|
73
|
-
case 'CBC':
|
|
74
|
-
return this.encryptCBC(data, Datakey, Dataiv);
|
|
75
|
-
default:
|
|
76
|
-
return this.encryptCBC(data, Datakey, Dataiv);
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static decryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
84
|
-
try {
|
|
85
|
-
switch (type) {
|
|
86
|
-
case 'GCM':
|
|
87
|
-
return this.decryptGCM(data, Datakey, Dataiv);
|
|
88
|
-
case 'CBC':
|
|
89
|
-
return this.decryptCBC(data, Datakey, Dataiv);
|
|
90
|
-
default:
|
|
91
|
-
return this.decryptCBC(data, Datakey, Dataiv);
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
throw new InternalServerErrorException('Encryption process failed');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
1
|
+
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
2
|
+
import * as crypto from 'crypto';
|
|
3
|
+
|
|
4
|
+
const CryptoJS = require('crypto-js');
|
|
5
|
+
const encryptionType = 'aes-256-cbc';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class EncryptUtilService {
|
|
9
|
+
constructor() {}
|
|
10
|
+
|
|
11
|
+
static encryptGCM(data: any, Datakey: string, Dataiv: string) {
|
|
12
|
+
try {
|
|
13
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
14
|
+
let encrypted = Buffer.concat([
|
|
15
|
+
cipher.update(data, 'utf8'),
|
|
16
|
+
cipher.final(),
|
|
17
|
+
]);
|
|
18
|
+
const tag = cipher.getAuthTag();
|
|
19
|
+
return Buffer.concat([encrypted, tag]).toString('base64');
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static decryptGCM(data: any, Datakey: any, Dataiv: any) {
|
|
26
|
+
try {
|
|
27
|
+
data = Buffer.from(data, 'base64');
|
|
28
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', Datakey, Dataiv);
|
|
29
|
+
const tag = data.slice(data.length - 16);
|
|
30
|
+
decipher.setAuthTag(tag);
|
|
31
|
+
data = data.slice(0, data.length - 16);
|
|
32
|
+
let decrypted = decipher.update(data, 'utf8') + decipher.final('utf8');
|
|
33
|
+
return decrypted;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static encryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
40
|
+
let encryptedRequest;
|
|
41
|
+
try {
|
|
42
|
+
let cipher = CryptoJS.AES.encrypt(data, Datakey, {
|
|
43
|
+
iv: Dataiv,
|
|
44
|
+
mode: CryptoJS.mode.CBC,
|
|
45
|
+
});
|
|
46
|
+
encryptedRequest = cipher.toString();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.log(error);
|
|
49
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
50
|
+
}
|
|
51
|
+
return encryptedRequest;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static decryptCBC(data: any, Datakey: any, Dataiv: any) {
|
|
55
|
+
let decryptRequest;
|
|
56
|
+
try {
|
|
57
|
+
let cipher = CryptoJS.AES.decrypt(data, Datakey, {
|
|
58
|
+
iv: Dataiv,
|
|
59
|
+
mode: CryptoJS.mode.CBC,
|
|
60
|
+
});
|
|
61
|
+
decryptRequest = cipher.toString(CryptoJS.enc.Utf8);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
64
|
+
}
|
|
65
|
+
return decryptRequest;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static encryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
69
|
+
try {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case 'GCM':
|
|
72
|
+
return this.encryptGCM(data, Datakey, Dataiv);
|
|
73
|
+
case 'CBC':
|
|
74
|
+
return this.encryptCBC(data, Datakey, Dataiv);
|
|
75
|
+
default:
|
|
76
|
+
return this.encryptCBC(data, Datakey, Dataiv);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static decryptRequest(data: any, Datakey: any, Dataiv: any, type?: any) {
|
|
84
|
+
try {
|
|
85
|
+
switch (type) {
|
|
86
|
+
case 'GCM':
|
|
87
|
+
return this.decryptGCM(data, Datakey, Dataiv);
|
|
88
|
+
case 'CBC':
|
|
89
|
+
return this.decryptCBC(data, Datakey, Dataiv);
|
|
90
|
+
default:
|
|
91
|
+
return this.decryptCBC(data, Datakey, Dataiv);
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new InternalServerErrorException('Encryption process failed');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as xlsx from 'xlsx';
|
|
2
|
-
|
|
3
|
-
export class ExcelUtil {
|
|
4
|
-
static readExcel(fileBuffer: Buffer): Record<string, any[]> {
|
|
5
|
-
const workbook = xlsx.read(fileBuffer, { type: 'buffer' });
|
|
6
|
-
const data: Record<string, any[]> = {};
|
|
7
|
-
|
|
8
|
-
workbook.SheetNames.forEach((sheetName) => {
|
|
9
|
-
const sheet = workbook.Sheets[sheetName];
|
|
10
|
-
data[sheetName] = xlsx.utils.sheet_to_json(sheet);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import * as xlsx from 'xlsx';
|
|
2
|
+
|
|
3
|
+
export class ExcelUtil {
|
|
4
|
+
static readExcel(fileBuffer: Buffer): Record<string, any[]> {
|
|
5
|
+
const workbook = xlsx.read(fileBuffer, { type: 'buffer' });
|
|
6
|
+
const data: Record<string, any[]> = {};
|
|
7
|
+
|
|
8
|
+
workbook.SheetNames.forEach((sheetName) => {
|
|
9
|
+
const sheet = workbook.Sheets[sheetName];
|
|
10
|
+
data[sheetName] = xlsx.utils.sheet_to_json(sheet);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
}
|