rez_core 1.0.62 → 1.0.63
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/dist/module/auth/guards/role.guard.js +3 -3
- package/dist/module/listmaster/controller/list-master.controller.d.ts +1 -1
- package/dist/module/listmaster/controller/list-master.controller.js +3 -4
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/service/list-master.service.d.ts +4 -2
- package/dist/module/listmaster/service/list-master.service.js +16 -14
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/module/user/entity/role.entity.d.ts +1 -0
- package/dist/module/user/entity/role.entity.js +5 -0
- package/dist/module/user/entity/role.entity.js.map +1 -1
- package/dist/module/user/repository/role.repository.d.ts +2 -35
- package/dist/module/user/repository/role.repository.js +2 -95
- package/dist/module/user/repository/role.repository.js.map +1 -1
- package/dist/module/user/service/role.service.d.ts +5 -32
- package/dist/module/user/service/role.service.js +71 -24
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/user.module.js +8 -3
- package/dist/module/user/user.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/app.controller.ts +12 -12
- package/src/app.service.ts +8 -8
- 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/organization.entity.ts +80 -80
- package/src/module/listmaster/controller/list-master.controller.ts +2 -2
- package/src/module/listmaster/service/list-master.service.ts +18 -15
- 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/entity/module-access.entity.ts +22 -22
- 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/role.entity.ts +4 -0
- package/src/module/user/entity/user-session.entity.ts +61 -61
- package/src/module/user/repository/role.repository.ts +2 -142
- package/src/module/user/repository/userSession.repository.ts +33 -33
- package/src/module/user/service/role.service.ts +92 -42
- package/src/module/user/user.module.ts +8 -3
- 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
- package/dist/module/user/controller/role.controller.d.ts +0 -41
- package/dist/module/user/controller/role.controller.js +0 -63
- package/dist/module/user/controller/role.controller.js.map +0 -1
- package/src/module/user/controller/role.controller.ts +0 -55
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { BaseEntity } from './base-entity.entity';
|
|
2
|
-
import { Column, Entity } from 'typeorm';
|
|
3
|
-
import { ENTITYTYPE_PREFERENCEMASTER } from '../../../constant/global.constant';
|
|
4
|
-
|
|
5
|
-
@Entity({ name: 'cr_preference_master' })
|
|
6
|
-
export class PreferenceMaster extends BaseEntity {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
this.entity_type = ENTITYTYPE_PREFERENCEMASTER;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@Column({ name: 'appcode', type: 'varchar', length: 200, nullable: true })
|
|
13
|
-
appCode: string;
|
|
14
|
-
|
|
15
|
-
@Column({
|
|
16
|
-
name: 'display_name',
|
|
17
|
-
type: 'varchar',
|
|
18
|
-
length: 200,
|
|
19
|
-
nullable: true,
|
|
20
|
-
})
|
|
21
|
-
display_name: string;
|
|
22
|
-
|
|
23
|
-
@Column({
|
|
24
|
-
name: 'preference_key',
|
|
25
|
-
type: 'varchar',
|
|
26
|
-
length: 200,
|
|
27
|
-
nullable: true,
|
|
28
|
-
})
|
|
29
|
-
preference_key: string;
|
|
30
|
-
|
|
31
|
-
@Column({
|
|
32
|
-
name: 'preference_value',
|
|
33
|
-
type: 'varchar',
|
|
34
|
-
length: 200,
|
|
35
|
-
nullable: true,
|
|
36
|
-
})
|
|
37
|
-
preference_value: string;
|
|
38
|
-
|
|
39
|
-
@Column({
|
|
40
|
-
name: 'description',
|
|
41
|
-
type: 'varchar',
|
|
42
|
-
length: 2000,
|
|
43
|
-
nullable: true,
|
|
44
|
-
})
|
|
45
|
-
description: string;
|
|
46
|
-
|
|
47
|
-
@Column({ name: 'reflect_on', type: 'varchar', length: 200, nullable: true })
|
|
48
|
-
reflect_on: string;
|
|
49
|
-
|
|
50
|
-
@Column({
|
|
51
|
-
name: 'default_value',
|
|
52
|
-
type: 'varchar',
|
|
53
|
-
length: 200,
|
|
54
|
-
nullable: true,
|
|
55
|
-
})
|
|
56
|
-
default_value: string;
|
|
57
|
-
|
|
58
|
-
@Column({
|
|
59
|
-
name: 'possible_values',
|
|
60
|
-
type: 'varchar',
|
|
61
|
-
length: 200,
|
|
62
|
-
nullable: true,
|
|
63
|
-
})
|
|
64
|
-
possible_values: string;
|
|
65
|
-
}
|
|
1
|
+
import { BaseEntity } from './base-entity.entity';
|
|
2
|
+
import { Column, Entity } from 'typeorm';
|
|
3
|
+
import { ENTITYTYPE_PREFERENCEMASTER } from '../../../constant/global.constant';
|
|
4
|
+
|
|
5
|
+
@Entity({ name: 'cr_preference_master' })
|
|
6
|
+
export class PreferenceMaster extends BaseEntity {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.entity_type = ENTITYTYPE_PREFERENCEMASTER;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Column({ name: 'appcode', type: 'varchar', length: 200, nullable: true })
|
|
13
|
+
appCode: string;
|
|
14
|
+
|
|
15
|
+
@Column({
|
|
16
|
+
name: 'display_name',
|
|
17
|
+
type: 'varchar',
|
|
18
|
+
length: 200,
|
|
19
|
+
nullable: true,
|
|
20
|
+
})
|
|
21
|
+
display_name: string;
|
|
22
|
+
|
|
23
|
+
@Column({
|
|
24
|
+
name: 'preference_key',
|
|
25
|
+
type: 'varchar',
|
|
26
|
+
length: 200,
|
|
27
|
+
nullable: true,
|
|
28
|
+
})
|
|
29
|
+
preference_key: string;
|
|
30
|
+
|
|
31
|
+
@Column({
|
|
32
|
+
name: 'preference_value',
|
|
33
|
+
type: 'varchar',
|
|
34
|
+
length: 200,
|
|
35
|
+
nullable: true,
|
|
36
|
+
})
|
|
37
|
+
preference_value: string;
|
|
38
|
+
|
|
39
|
+
@Column({
|
|
40
|
+
name: 'description',
|
|
41
|
+
type: 'varchar',
|
|
42
|
+
length: 2000,
|
|
43
|
+
nullable: true,
|
|
44
|
+
})
|
|
45
|
+
description: string;
|
|
46
|
+
|
|
47
|
+
@Column({ name: 'reflect_on', type: 'varchar', length: 200, nullable: true })
|
|
48
|
+
reflect_on: string;
|
|
49
|
+
|
|
50
|
+
@Column({
|
|
51
|
+
name: 'default_value',
|
|
52
|
+
type: 'varchar',
|
|
53
|
+
length: 200,
|
|
54
|
+
nullable: true,
|
|
55
|
+
})
|
|
56
|
+
default_value: string;
|
|
57
|
+
|
|
58
|
+
@Column({
|
|
59
|
+
name: 'possible_values',
|
|
60
|
+
type: 'varchar',
|
|
61
|
+
length: 200,
|
|
62
|
+
nullable: true,
|
|
63
|
+
})
|
|
64
|
+
possible_values: string;
|
|
65
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
-
import { PreferenceMaster } from '../entity/preference.entity';
|
|
4
|
-
import { Repository } from 'typeorm';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class PreferenceRepository {
|
|
8
|
-
constructor(
|
|
9
|
-
@InjectRepository(PreferenceMaster)
|
|
10
|
-
private readonly preferenceRepository: Repository<PreferenceMaster>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findByPreferenceKey(
|
|
14
|
-
preferenceKey: string,
|
|
15
|
-
): Promise<PreferenceMaster | null> {
|
|
16
|
-
return await this.preferenceRepository.findOne({
|
|
17
|
-
where: { preference_key: preferenceKey },
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { PreferenceMaster } from '../entity/preference.entity';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class PreferenceRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(PreferenceMaster)
|
|
10
|
+
private readonly preferenceRepository: Repository<PreferenceMaster>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findByPreferenceKey(
|
|
14
|
+
preferenceKey: string,
|
|
15
|
+
): Promise<PreferenceMaster | null> {
|
|
16
|
+
return await this.preferenceRepository.findOne({
|
|
17
|
+
where: { preference_key: preferenceKey },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Controller, Get, Request, UseGuards } from '@nestjs/common';
|
|
2
|
-
import { MenuService } from '../service/menu.service';
|
|
3
|
-
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
4
|
-
|
|
5
|
-
@Controller('menu')
|
|
6
|
-
export class MenuController {
|
|
7
|
-
constructor(private readonly menuService: MenuService) {}
|
|
8
|
-
|
|
9
|
-
@UseGuards(JwtAuthGuard)
|
|
10
|
-
@Get()
|
|
11
|
-
async getMenu(@Request() req) {
|
|
12
|
-
const userId = req.user.userId;
|
|
13
|
-
return this.menuService.getUserMenu(userId);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import { Controller, Get, Request, UseGuards } from '@nestjs/common';
|
|
2
|
+
import { MenuService } from '../service/menu.service';
|
|
3
|
+
import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
|
|
4
|
+
|
|
5
|
+
@Controller('menu')
|
|
6
|
+
export class MenuController {
|
|
7
|
+
constructor(private readonly menuService: MenuService) {}
|
|
8
|
+
|
|
9
|
+
@UseGuards(JwtAuthGuard)
|
|
10
|
+
@Get()
|
|
11
|
+
async getMenu(@Request() req) {
|
|
12
|
+
const userId = req.user.userId;
|
|
13
|
+
return this.menuService.getUserMenu(userId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
-
|
|
3
|
-
@Entity({ name: 'cr_module_access' })
|
|
4
|
-
export class ModuleAccess {
|
|
5
|
-
@PrimaryGeneratedColumn()
|
|
6
|
-
id: number;
|
|
7
|
-
|
|
8
|
-
@Column({type: 'varchar', length: 100, nullable: true})
|
|
9
|
-
module_code: string;
|
|
10
|
-
|
|
11
|
-
@Column({type: 'varchar', length: 100, nullable: true })
|
|
12
|
-
role_code: string;
|
|
13
|
-
|
|
14
|
-
@Column({type: 'int', nullable: true })
|
|
15
|
-
access_flag: number;
|
|
16
|
-
|
|
17
|
-
@Column({type: 'varchar', length: 100, nullable: true })
|
|
18
|
-
action_type: string;
|
|
19
|
-
|
|
20
|
-
@Column({type: 'varchar', length: 100, nullable: true})
|
|
21
|
-
app_code: string;
|
|
22
|
-
}
|
|
1
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
@Entity({ name: 'cr_module_access' })
|
|
4
|
+
export class ModuleAccess {
|
|
5
|
+
@PrimaryGeneratedColumn()
|
|
6
|
+
id: number;
|
|
7
|
+
|
|
8
|
+
@Column({type: 'varchar', length: 100, nullable: true})
|
|
9
|
+
module_code: string;
|
|
10
|
+
|
|
11
|
+
@Column({type: 'varchar', length: 100, nullable: true })
|
|
12
|
+
role_code: string;
|
|
13
|
+
|
|
14
|
+
@Column({type: 'int', nullable: true })
|
|
15
|
+
access_flag: number;
|
|
16
|
+
|
|
17
|
+
@Column({type: 'varchar', length: 100, nullable: true })
|
|
18
|
+
action_type: string;
|
|
19
|
+
|
|
20
|
+
@Column({type: 'varchar', length: 100, nullable: true})
|
|
21
|
+
app_code: string;
|
|
22
|
+
}
|
|
@@ -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,6 +1,7 @@
|
|
|
1
1
|
import { BaseEntity } from '../../meta/entity/base-entity.entity';
|
|
2
2
|
import { ENTITYTYPE_ROLE } from '../../../constant/global.constant';
|
|
3
3
|
import { Column, Entity } from 'typeorm';
|
|
4
|
+
import { Exclude } from 'class-transformer';
|
|
4
5
|
|
|
5
6
|
@Entity({ name: 'cr_role' })
|
|
6
7
|
export class Role extends BaseEntity {
|
|
@@ -17,4 +18,7 @@ export class Role extends BaseEntity {
|
|
|
17
18
|
|
|
18
19
|
@Column({ type: 'varchar', length: 250, nullable: true })
|
|
19
20
|
description: string;
|
|
21
|
+
|
|
22
|
+
@Exclude()
|
|
23
|
+
copy_from_role_id: number;
|
|
20
24
|
}
|
|
@@ -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
|
+
}
|
|
@@ -9,155 +9,15 @@ import { UserData } from '../entity/user.entity';
|
|
|
9
9
|
export class RoleRepository {
|
|
10
10
|
constructor(
|
|
11
11
|
@InjectRepository(Role)
|
|
12
|
-
private readonly roleRepo: Repository<Role
|
|
13
|
-
@InjectRepository(ModuleAccess)
|
|
14
|
-
private readonly moduleAccessRepo: Repository<ModuleAccess>
|
|
12
|
+
private readonly roleRepo: Repository<Role>
|
|
15
13
|
) {}
|
|
16
14
|
|
|
17
15
|
async findByCode(code: string): Promise<Role | null> {
|
|
18
16
|
return this.roleRepo.findOne({ where: { code } });
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
async createRole(
|
|
22
|
-
{
|
|
23
|
-
name,
|
|
24
|
-
description,
|
|
25
|
-
status = 'ACTIVE',
|
|
26
|
-
copyFromRoleId,
|
|
27
|
-
}: {
|
|
28
|
-
name: string;
|
|
29
|
-
description?: string;
|
|
30
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
31
|
-
copyFromRoleId?: number;
|
|
32
|
-
},
|
|
33
|
-
loggedInUser: UserData,
|
|
34
|
-
) {
|
|
35
|
-
if (await this.isRoleNameExists(name)) {
|
|
36
|
-
throw new BadRequestException('Role name already exists.');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const sourceRole = copyFromRoleId
|
|
40
|
-
? await this.roleRepo.findOne({ where: { id: copyFromRoleId } })
|
|
41
|
-
: null;
|
|
42
|
-
|
|
43
|
-
if (copyFromRoleId && !sourceRole) {
|
|
44
|
-
throw new BadRequestException('Source role not found.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const newRole = this.roleRepo.create({
|
|
48
|
-
name,
|
|
49
|
-
description,
|
|
50
|
-
status,
|
|
51
|
-
created_by: loggedInUser.id,
|
|
52
|
-
created_date: new Date(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const savedRole = await this.roleRepo.save(newRole);
|
|
56
|
-
savedRole.code = `ROL${savedRole.id}`;
|
|
57
|
-
await this.roleRepo.save(savedRole);
|
|
58
|
-
|
|
59
|
-
if (sourceRole) {
|
|
60
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
61
|
-
where: { role_code: sourceRole.code },
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const clonedPermissions = sourcePermissions.map(perm =>
|
|
65
|
-
this.moduleAccessRepo.create({
|
|
66
|
-
role_code: savedRole.code,
|
|
67
|
-
module_code: perm.module_code,
|
|
68
|
-
action_type: perm.action_type,
|
|
69
|
-
access_flag: perm.access_flag,
|
|
70
|
-
app_code: perm.app_code,
|
|
71
|
-
}),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
await this.moduleAccessRepo.save(clonedPermissions);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
success: true,
|
|
79
|
-
msg: 'Role created successfully',
|
|
80
|
-
role: {
|
|
81
|
-
id: savedRole.id,
|
|
82
|
-
name: savedRole.name,
|
|
83
|
-
status: savedRole.status,
|
|
84
|
-
code: savedRole.code,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async updateRole(
|
|
90
|
-
roleId: number,
|
|
91
|
-
{
|
|
92
|
-
name,
|
|
93
|
-
description,
|
|
94
|
-
status = 'ACTIVE',
|
|
95
|
-
copyFromRoleId,
|
|
96
|
-
}: {
|
|
97
|
-
name: string;
|
|
98
|
-
description?: string;
|
|
99
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
100
|
-
copyFromRoleId?: number;
|
|
101
|
-
},
|
|
102
|
-
loggedInUser: UserData,
|
|
103
|
-
) {
|
|
104
|
-
if (await this.isRoleNameExists(name, roleId)) {
|
|
105
|
-
throw new BadRequestException('Role name already exists.');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const role = await this.roleRepo.findOne({ where: { id: roleId } });
|
|
109
|
-
if (!role) {
|
|
110
|
-
throw new BadRequestException('Role not found');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Object.assign(role, {
|
|
114
|
-
name,
|
|
115
|
-
description: description || '',
|
|
116
|
-
status,
|
|
117
|
-
modified_by: loggedInUser.id,
|
|
118
|
-
modified_date: new Date(),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await this.roleRepo.save(role);
|
|
122
|
-
|
|
123
|
-
if (copyFromRoleId) {
|
|
124
|
-
const sourceRole = await this.roleRepo.findOne({ where: { id: copyFromRoleId } });
|
|
125
|
-
if (!sourceRole) {
|
|
126
|
-
throw new BadRequestException('Source role not found');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await this.moduleAccessRepo.delete({ role_code: role.code });
|
|
130
|
-
|
|
131
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
132
|
-
where: { role_code: sourceRole.code },
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const clonedPermissions = sourcePermissions.map(perm =>
|
|
136
|
-
this.moduleAccessRepo.create({
|
|
137
|
-
role_code: role.code,
|
|
138
|
-
module_code: perm.module_code,
|
|
139
|
-
action_type: perm.action_type,
|
|
140
|
-
access_flag: perm.access_flag,
|
|
141
|
-
app_code: perm.app_code,
|
|
142
|
-
}),
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
await this.moduleAccessRepo.save(clonedPermissions);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
success: true,
|
|
150
|
-
msg: 'Role updated successfully',
|
|
151
|
-
role: {
|
|
152
|
-
id: role.id,
|
|
153
|
-
name: role.name,
|
|
154
|
-
status: role.status,
|
|
155
|
-
code: role.code,
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
19
|
|
|
160
|
-
|
|
20
|
+
public async isRoleNameExists(name: string, excludeRoleId?: number): Promise<boolean> {
|
|
161
21
|
const query = this.roleRepo
|
|
162
22
|
.createQueryBuilder('role')
|
|
163
23
|
.where('role.name = :name', { name });
|
|
@@ -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
|
+
}
|