rez_core 1.0.60 → 1.0.62
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/module/enterprise/entity/enterprise.entity.d.ts +7 -7
- package/dist/module/enterprise/entity/enterprise.entity.js +7 -7
- package/dist/module/enterprise/entity/enterprise.entity.js.map +1 -1
- package/dist/module/enterprise/repository/enterprise.repository.d.ts +8 -0
- package/dist/module/enterprise/repository/enterprise.repository.js +48 -0
- package/dist/module/enterprise/repository/enterprise.repository.js.map +1 -0
- package/dist/module/enterprise/service/enterprise.service.d.ts +8 -0
- package/dist/module/enterprise/service/enterprise.service.js +31 -0
- package/dist/module/enterprise/service/enterprise.service.js.map +1 -0
- package/dist/module/meta/controller/view-master.controller.d.ts +7 -0
- package/dist/module/meta/controller/view-master.controller.js +62 -0
- package/dist/module/meta/controller/view-master.controller.js.map +1 -0
- package/dist/module/meta/entity/view-master.entity.d.ts +2 -0
- package/dist/module/meta/entity/view-master.entity.js +8 -0
- package/dist/module/meta/entity/view-master.entity.js.map +1 -1
- package/dist/module/meta/entity.module.js +4 -1
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/meta/repository/view-master.repository.d.ts +7 -0
- package/dist/module/meta/repository/view-master.repository.js +38 -0
- package/dist/module/meta/repository/view-master.repository.js.map +1 -0
- package/dist/module/meta/service/entity-list.service.d.ts +1 -1
- package/dist/module/meta/service/entity-list.service.js.map +1 -1
- package/dist/module/meta/service/entity-master.service.d.ts +1 -1
- package/dist/module/meta/service/entity-master.service.js +11 -6
- package/dist/module/meta/service/entity-master.service.js.map +1 -1
- package/dist/module/meta/service/view-master.service.d.ts +13 -2
- package/dist/module/meta/service/view-master.service.js +41 -22
- package/dist/module/meta/service/view-master.service.js.map +1 -1
- package/dist/module/module/controller/module-access.controller.d.ts +1 -37
- package/dist/module/module/controller/module-access.controller.js +2 -34
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +1 -35
- package/dist/module/module/repository/module-access.repository.js +2 -104
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +1 -36
- package/dist/module/module/service/module-access.service.js +2 -44
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/module/user/controller/role.controller.d.ts +41 -0
- package/dist/module/user/controller/role.controller.js +63 -0
- package/dist/module/user/controller/role.controller.js.map +1 -0
- package/dist/module/user/repository/role.repository.d.ts +35 -1
- package/dist/module/user/repository/role.repository.js +105 -2
- package/dist/module/user/repository/role.repository.js.map +1 -1
- package/dist/module/user/service/role.service.d.ts +35 -1
- package/dist/module/user/service/role.service.js +39 -2
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/service/user.service.js +2 -1
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/module/user/user.module.js +4 -2
- package/dist/module/user/user.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/enterprise/entity/enterprise.entity.ts +7 -7
- package/src/module/enterprise/repository/enterprise.repository.ts +31 -0
- package/src/module/enterprise/service/enterprise.service.ts +16 -0
- package/src/module/meta/controller/view-master.controller.ts +48 -0
- package/src/module/meta/entity/view-master.entity.ts +6 -0
- package/src/module/meta/entity.module.ts +4 -1
- package/src/module/meta/repository/view-master.repository.ts +24 -0
- package/src/module/meta/service/entity-list.service.ts +2 -2
- package/src/module/meta/service/entity-master.service.ts +15 -11
- package/src/module/meta/service/view-master.service.ts +51 -28
- package/src/module/module/controller/module-access.controller.ts +2 -36
- package/src/module/module/repository/module-access.repository.ts +0 -151
- package/src/module/module/service/module-access.service.ts +1 -62
- package/src/module/user/controller/role.controller.ts +55 -0
- package/src/module/user/repository/role.repository.ts +157 -1
- package/src/module/user/service/role.service.ts +70 -2
- package/src/module/user/service/user.service.ts +6 -3
- package/src/module/user/user.module.ts +4 -2
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export class EnterpriseData {
|
|
|
6
6
|
id: number;
|
|
7
7
|
|
|
8
8
|
@Column({ name: 'entity_type', type: 'varchar', nullable: true, length: 50 })
|
|
9
|
-
|
|
9
|
+
entity_type: string;
|
|
10
10
|
|
|
11
11
|
@Column({ name: 'code', type: 'varchar', nullable: true, length: 50 })
|
|
12
12
|
code: string;
|
|
@@ -18,20 +18,20 @@ export class EnterpriseData {
|
|
|
18
18
|
status: string;
|
|
19
19
|
|
|
20
20
|
@Column({ name: 'created_by', type: 'int', nullable: true })
|
|
21
|
-
|
|
21
|
+
created_by: number;
|
|
22
22
|
|
|
23
23
|
@Column({ name: 'modified_by', type: 'int', nullable: true })
|
|
24
|
-
|
|
24
|
+
modified_by: number;
|
|
25
25
|
|
|
26
26
|
@Column({ name: 'created_date', type: 'datetime', nullable: true })
|
|
27
|
-
|
|
27
|
+
created_date: Date;
|
|
28
28
|
|
|
29
29
|
@Column({ name: 'modified_date', type: 'datetime', nullable: true })
|
|
30
|
-
|
|
30
|
+
modified_date: Date;
|
|
31
31
|
|
|
32
32
|
@Column({ name: 'app_code', type: 'varchar', nullable: true, length: 50 })
|
|
33
|
-
|
|
33
|
+
app_code: string;
|
|
34
34
|
|
|
35
35
|
@Column({ name: 'app_url_name', type: 'varchar', nullable: true, length: 50 })
|
|
36
|
-
|
|
36
|
+
app_url_name: string;
|
|
37
37
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { EnterpriseData } from '../entity/enterprise.entity';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class EnterpriseRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(EnterpriseData)
|
|
10
|
+
private readonly enterpriseRepository: Repository<EnterpriseData>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async save(enterpriseData: EnterpriseData) {
|
|
14
|
+
enterpriseData.created_date = new Date();
|
|
15
|
+
return await this.enterpriseRepository.save(enterpriseData);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async update(enterpriseData: EnterpriseData): Promise<EnterpriseData | null> {
|
|
19
|
+
const existingEnterprise = await this.enterpriseRepository.findOne({
|
|
20
|
+
where: { id: enterpriseData.id },
|
|
21
|
+
});
|
|
22
|
+
if (!existingEnterprise) {
|
|
23
|
+
throw new Error(`Enterprise with id ${enterpriseData.id} not found`);
|
|
24
|
+
}
|
|
25
|
+
enterpriseData.modified_date = new Date();
|
|
26
|
+
await this.enterpriseRepository.update(enterpriseData.id, enterpriseData);
|
|
27
|
+
return await this.enterpriseRepository.findOne({
|
|
28
|
+
where: { id: enterpriseData.id },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { EnterpriseRepository } from '../repository/enterprise.repository';
|
|
3
|
+
import { EnterpriseData } from '../entity/enterprise.entity';
|
|
4
|
+
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class EnterpriseService {
|
|
7
|
+
constructor(private readonly enterpriseRepository: EnterpriseRepository) {}
|
|
8
|
+
|
|
9
|
+
async create(enterpriseData: EnterpriseData): Promise<EnterpriseData> {
|
|
10
|
+
return await this.enterpriseRepository.save(enterpriseData);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async update(enterpriseData: EnterpriseData): Promise<EnterpriseData|null> {
|
|
14
|
+
return await this.enterpriseRepository.update(enterpriseData);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Controller,
|
|
3
|
+
Get,
|
|
4
|
+
Query,
|
|
5
|
+
Res,
|
|
6
|
+
HttpStatus,
|
|
7
|
+
UseGuards,
|
|
8
|
+
Inject,
|
|
9
|
+
} from '@nestjs/common';
|
|
10
|
+
import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
|
|
11
|
+
import { Response } from 'express';
|
|
12
|
+
import { ViewMasterService } from '../service/view-master.service';
|
|
13
|
+
|
|
14
|
+
@Controller('entity')
|
|
15
|
+
@UseGuards(JwtAuthGuard)
|
|
16
|
+
export class ViewMasterController {
|
|
17
|
+
constructor(@Inject("ViewMasterService") private readonly viewMaster: ViewMasterService) {}
|
|
18
|
+
|
|
19
|
+
@Get('viewMaster')
|
|
20
|
+
async getEntityJsonByType(
|
|
21
|
+
@Query('entity_type') entityType: string,
|
|
22
|
+
@Query('type') type:string,
|
|
23
|
+
@Res() res: Response,
|
|
24
|
+
) {
|
|
25
|
+
try {
|
|
26
|
+
if (!entityType || !type) {
|
|
27
|
+
return res.status(HttpStatus.BAD_REQUEST).json({
|
|
28
|
+
success: false,
|
|
29
|
+
message: 'Missing entity_type or type query parameter',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result = await this.viewMaster.getEntityJson(entityType, type);
|
|
34
|
+
|
|
35
|
+
return res.status(HttpStatus.OK).json({
|
|
36
|
+
success: true,
|
|
37
|
+
message: 'Entity data fetched successfully',
|
|
38
|
+
data: result,
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
42
|
+
success: false,
|
|
43
|
+
message: error.message || 'Error fetching entity data',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
@@ -24,6 +24,12 @@ export class ViewMaster extends BaseEntity {
|
|
|
24
24
|
@Column({type: 'json', nullable: true})
|
|
25
25
|
published_form_fields: string;
|
|
26
26
|
|
|
27
|
+
@Column({type: 'json',nullable:true})
|
|
28
|
+
meta_json:string;
|
|
29
|
+
|
|
30
|
+
@Column({ nullable:true})
|
|
31
|
+
type: string;
|
|
32
|
+
|
|
27
33
|
@Column({type: 'int'})
|
|
28
34
|
is_default: number;
|
|
29
35
|
}
|
|
@@ -32,6 +32,8 @@ import { SectionMaster } from './entity/section-master.entity';
|
|
|
32
32
|
import { FieldGroup } from './entity/field-group.entity';
|
|
33
33
|
import { FieldGroupService } from './service/field-group.service';
|
|
34
34
|
import { ViewMasterService } from './service/view-master.service';
|
|
35
|
+
import { ViewMasterController } from './controller/view-master.controller';
|
|
36
|
+
import { ViewMaterRespository } from './repository/view-master.repository';
|
|
35
37
|
|
|
36
38
|
@Module({
|
|
37
39
|
imports: [
|
|
@@ -67,6 +69,7 @@ import { ViewMasterService } from './service/view-master.service';
|
|
|
67
69
|
AttributeMasterService,
|
|
68
70
|
SectionMasterService,
|
|
69
71
|
FieldGroupService,
|
|
72
|
+
ViewMaterRespository,
|
|
70
73
|
{ provide: 'ViewMasterService', useClass: ViewMasterService },
|
|
71
74
|
],
|
|
72
75
|
exports: [
|
|
@@ -81,6 +84,6 @@ import { ViewMasterService } from './service/view-master.service';
|
|
|
81
84
|
FieldGroupService,
|
|
82
85
|
'ViewMasterService',
|
|
83
86
|
],
|
|
84
|
-
controllers: [EntityController, MasterController, MediaController],
|
|
87
|
+
controllers: [EntityController, MasterController, MediaController, ViewMasterController],
|
|
85
88
|
})
|
|
86
89
|
export class EntityModule {}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { BaseEntity, Repository } from 'typeorm';
|
|
4
|
+
import { ViewMaster } from '../entity/view-master.entity';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class ViewMaterRespository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(ViewMaster)
|
|
10
|
+
private readonly viewMasterRepository: Repository<ViewMaster>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async getEntityJson(
|
|
14
|
+
entityType: string,
|
|
15
|
+
type: string,
|
|
16
|
+
): Promise<ViewMaster | null> {
|
|
17
|
+
const viewMaster = await this.viewMasterRepository.findOneBy({
|
|
18
|
+
mapped_entity_type: entityType,
|
|
19
|
+
type: type,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return viewMaster;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -148,8 +148,8 @@ export class EntityListService {
|
|
|
148
148
|
|
|
149
149
|
public async getMaxSequenceNumber(
|
|
150
150
|
tableName: string,
|
|
151
|
-
parentType: string,
|
|
152
|
-
parentId: number,
|
|
151
|
+
parentType: string | null,
|
|
152
|
+
parentId: number | null,
|
|
153
153
|
) {
|
|
154
154
|
let query = `SELECT COUNT(1) seq_no
|
|
155
155
|
FROM ${tableName} WHERE 1=1 `;
|
|
@@ -10,18 +10,22 @@ export class EntityMasterService {
|
|
|
10
10
|
private entityMasterRepository: Repository<EntityMaster>,
|
|
11
11
|
) {}
|
|
12
12
|
|
|
13
|
-
async getEntityData(mappedEntityType: string): Promise<EntityMaster> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
async getEntityData(mappedEntityType: string|null): Promise<EntityMaster> {
|
|
14
|
+
if (mappedEntityType) {
|
|
15
|
+
const entityMaster = await this.entityMasterRepository.findOne({
|
|
16
|
+
where: { mapped_entity_type: mappedEntityType },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (!entityMaster) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Entity with mappedEntityType "${mappedEntityType}" not found.`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return entityMaster;
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error();
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
return entityMaster;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
async getEntityByTableName(tableName: string) {
|
|
@@ -8,17 +8,19 @@ import { SectionMasterService } from './section-master.service';
|
|
|
8
8
|
import { SectionMaster } from '../entity/section-master.entity';
|
|
9
9
|
import { FieldGroup } from '../entity/field-group.entity';
|
|
10
10
|
import { FieldGroupService } from './field-group.service';
|
|
11
|
+
import { ViewMaterRespository } from '../repository/view-master.repository';
|
|
11
12
|
@Injectable()
|
|
12
13
|
export class ViewMasterService extends EntityServiceImpl {
|
|
13
14
|
constructor(
|
|
14
15
|
private readonly sectionMasterService: SectionMasterService,
|
|
15
16
|
private readonly fieldGroupService: FieldGroupService,
|
|
17
|
+
private readonly viewMasterRepoService: ViewMaterRespository
|
|
16
18
|
) {
|
|
17
19
|
super();
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
async createEntity(
|
|
21
|
-
entityData:
|
|
23
|
+
entityData: ViewMaster,
|
|
22
24
|
loggedInUser: UserData | null,
|
|
23
25
|
manager?: EntityManager,
|
|
24
26
|
): Promise<BaseEntity> {
|
|
@@ -33,40 +35,45 @@ export class ViewMasterService extends EntityServiceImpl {
|
|
|
33
35
|
loggedInUser,
|
|
34
36
|
manager,
|
|
35
37
|
);
|
|
36
|
-
let viewMaster = savedEntity as ViewMaster;
|
|
37
38
|
|
|
38
|
-
let
|
|
39
|
+
let viewMaster = savedEntity as ViewMaster;
|
|
40
|
+
if (entityData.type === 'form') {
|
|
41
|
+
let layout = viewMaster.published_form_layout;
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const stepsData = this.sectionMasterService.parseLayout(layout);
|
|
44
|
+
for (var step of stepsData) {
|
|
45
|
+
let sectionMaster = new SectionMaster();
|
|
46
|
+
sectionMaster.name = step.stepLabel;
|
|
47
|
+
sectionMaster.position = step.stepPosition;
|
|
48
|
+
sectionMaster.description = step.stepLabel;
|
|
49
|
+
sectionMaster.parent_id = viewMaster.id;
|
|
50
|
+
sectionMaster.parent_type = viewMaster.entity_type;
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const savedSectionMaster = await this.sectionMasterService.createEntity(
|
|
53
|
+
sectionMaster,
|
|
54
|
+
loggedInUser,
|
|
55
|
+
manager,
|
|
56
|
+
);
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
const fieldGroups = step.fieldsGroup;
|
|
59
|
+
console.log('fieldGroups', fieldGroups);
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
for (var fieldGroup of fieldGroups) {
|
|
62
|
+
let fieldsGroup = new FieldGroup();
|
|
63
|
+
fieldsGroup.view_id = viewMaster.id;
|
|
64
|
+
fieldsGroup.parent_id = savedSectionMaster.id;
|
|
65
|
+
fieldsGroup.field_type = fieldGroup.type;
|
|
66
|
+
fieldsGroup.label = fieldGroup.label;
|
|
67
|
+
fieldsGroup.description = fieldGroup.label;
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
this.fieldGroupService.createEntity(
|
|
70
|
+
fieldsGroup,
|
|
71
|
+
loggedInUser,
|
|
72
|
+
manager,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
67
75
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
76
|
+
}
|
|
70
77
|
return savedEntity;
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -76,4 +83,20 @@ export class ViewMasterService extends EntityServiceImpl {
|
|
|
76
83
|
): Promise<BaseEntity> {
|
|
77
84
|
return entityData;
|
|
78
85
|
}
|
|
86
|
+
|
|
87
|
+
async getEntityJson(entityType: string, type: string) {
|
|
88
|
+
|
|
89
|
+
const res= await this.viewMasterRepoService.getEntityJson(entityType,type)
|
|
90
|
+
|
|
91
|
+
if(type=="form"){
|
|
92
|
+
return {
|
|
93
|
+
formLayoutJson:res?.published_form_layout,
|
|
94
|
+
formFieldJson:res?.published_form_fields
|
|
95
|
+
}
|
|
96
|
+
}else{
|
|
97
|
+
return {
|
|
98
|
+
metaJson:res?.meta_json
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
79
102
|
}
|
|
@@ -8,9 +8,7 @@ import { UserData } from '../../user/entity/user.entity';
|
|
|
8
8
|
@Controller('module-access')
|
|
9
9
|
@UseGuards(JwtAuthGuard)
|
|
10
10
|
export class ModuleAccessController {
|
|
11
|
-
constructor(private readonly moduleAccessService: ModuleAccessService
|
|
12
|
-
@Inject('UserService') private readonly userService: UserService,
|
|
13
|
-
) {}
|
|
11
|
+
constructor(private readonly moduleAccessService: ModuleAccessService) {}
|
|
14
12
|
|
|
15
13
|
@Get('roles')
|
|
16
14
|
async getRoles() {
|
|
@@ -39,39 +37,7 @@ export class ModuleAccessController {
|
|
|
39
37
|
return this.moduleAccessService.updateModuleAccess(moduleAccessData);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
async createRole(
|
|
44
|
-
@Body()
|
|
45
|
-
body: {
|
|
46
|
-
name: string;
|
|
47
|
-
description?: string;
|
|
48
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
49
|
-
copyFromRoleId?: number;
|
|
50
|
-
},
|
|
51
|
-
@Req() req: Request & {user: any}
|
|
52
|
-
) {
|
|
53
|
-
|
|
54
|
-
let requestedUser = req.user;
|
|
55
|
-
let loggedInUser = await this.userService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
|
|
56
|
-
return this.moduleAccessService.createRole(body, loggedInUser as UserData);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
@Post('update-role/:id')
|
|
60
|
-
async updateRole(
|
|
61
|
-
@Param('id') id: number,
|
|
62
|
-
@Body()
|
|
63
|
-
body: {
|
|
64
|
-
name?: string;
|
|
65
|
-
description?: string;
|
|
66
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
67
|
-
copyFromRoleId?: number; // <-- ADD THIS
|
|
68
|
-
},
|
|
69
|
-
@Req() req: Request & {user: any}
|
|
70
|
-
) {
|
|
71
|
-
let requestedUser = req.user;
|
|
72
|
-
let loggedInUser = await this.userService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
|
|
73
|
-
return this.moduleAccessService.updateRole(id, body, loggedInUser as UserData);
|
|
74
|
-
}
|
|
40
|
+
|
|
75
41
|
|
|
76
42
|
|
|
77
43
|
}
|
|
@@ -19,7 +19,6 @@ export class ModuleAccessRepository {
|
|
|
19
19
|
private readonly moduleAccessRepo: Repository<ModuleAccess>,
|
|
20
20
|
@InjectRepository(ModuleAction)
|
|
21
21
|
private readonly moduleActionRepo: Repository<ModuleAction>,
|
|
22
|
-
private readonly clockIDGenService: ClockIDGenService,
|
|
23
22
|
) {}
|
|
24
23
|
|
|
25
24
|
async getRoles() {
|
|
@@ -141,155 +140,5 @@ export class ModuleAccessRepository {
|
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
async createRole(
|
|
145
|
-
{
|
|
146
|
-
name,
|
|
147
|
-
description,
|
|
148
|
-
status = 'ACTIVE',
|
|
149
|
-
copyFromRoleId,
|
|
150
|
-
}: {
|
|
151
|
-
name: string;
|
|
152
|
-
description?: string;
|
|
153
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
154
|
-
copyFromRoleId?: number;
|
|
155
|
-
},
|
|
156
|
-
loggedInUser: UserData,
|
|
157
|
-
) {
|
|
158
|
-
if (await this.isRoleNameExists(name)) {
|
|
159
|
-
throw new BadRequestException('Role name already exists.');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const sourceRole = copyFromRoleId
|
|
163
|
-
? await this.roleRepo.findOne({ where: { id: copyFromRoleId } })
|
|
164
|
-
: null;
|
|
165
|
-
|
|
166
|
-
if (copyFromRoleId && !sourceRole) {
|
|
167
|
-
throw new BadRequestException('Source role not found.');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const newRole = this.roleRepo.create({
|
|
171
|
-
name,
|
|
172
|
-
description,
|
|
173
|
-
status,
|
|
174
|
-
created_by: loggedInUser.id,
|
|
175
|
-
created_date: new Date(),
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const savedRole = await this.roleRepo.save(newRole);
|
|
179
|
-
savedRole.code = `ROL${savedRole.id}`;
|
|
180
|
-
await this.roleRepo.save(savedRole);
|
|
181
|
-
|
|
182
|
-
if (sourceRole) {
|
|
183
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
184
|
-
where: { role_code: sourceRole.code },
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
const clonedPermissions = sourcePermissions.map(perm =>
|
|
188
|
-
this.moduleAccessRepo.create({
|
|
189
|
-
role_code: savedRole.code,
|
|
190
|
-
module_code: perm.module_code,
|
|
191
|
-
action_type: perm.action_type,
|
|
192
|
-
access_flag: perm.access_flag,
|
|
193
|
-
app_code: perm.app_code,
|
|
194
|
-
}),
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
await this.moduleAccessRepo.save(clonedPermissions);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
success: true,
|
|
202
|
-
msg: 'Role created successfully',
|
|
203
|
-
role: {
|
|
204
|
-
id: savedRole.id,
|
|
205
|
-
name: savedRole.name,
|
|
206
|
-
status: savedRole.status,
|
|
207
|
-
code: savedRole.code,
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
async updateRole(
|
|
213
|
-
roleId: number,
|
|
214
|
-
{
|
|
215
|
-
name,
|
|
216
|
-
description,
|
|
217
|
-
status = 'ACTIVE',
|
|
218
|
-
copyFromRoleId,
|
|
219
|
-
}: {
|
|
220
|
-
name: string;
|
|
221
|
-
description?: string;
|
|
222
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
223
|
-
copyFromRoleId?: number;
|
|
224
|
-
},
|
|
225
|
-
loggedInUser: UserData,
|
|
226
|
-
) {
|
|
227
|
-
if (await this.isRoleNameExists(name, roleId)) {
|
|
228
|
-
throw new BadRequestException('Role name already exists.');
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const role = await this.roleRepo.findOne({ where: { id: roleId } });
|
|
232
|
-
if (!role) {
|
|
233
|
-
throw new BadRequestException('Role not found');
|
|
234
|
-
}
|
|
235
143
|
|
|
236
|
-
Object.assign(role, {
|
|
237
|
-
name,
|
|
238
|
-
description: description || '',
|
|
239
|
-
status,
|
|
240
|
-
modified_by: loggedInUser.id,
|
|
241
|
-
modified_date: new Date(),
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
await this.roleRepo.save(role);
|
|
245
|
-
|
|
246
|
-
if (copyFromRoleId) {
|
|
247
|
-
const sourceRole = await this.roleRepo.findOne({ where: { id: copyFromRoleId } });
|
|
248
|
-
if (!sourceRole) {
|
|
249
|
-
throw new BadRequestException('Source role not found');
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
await this.moduleAccessRepo.delete({ role_code: role.code });
|
|
253
|
-
|
|
254
|
-
const sourcePermissions = await this.moduleAccessRepo.find({
|
|
255
|
-
where: { role_code: sourceRole.code },
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
const clonedPermissions = sourcePermissions.map(perm =>
|
|
259
|
-
this.moduleAccessRepo.create({
|
|
260
|
-
role_code: role.code,
|
|
261
|
-
module_code: perm.module_code,
|
|
262
|
-
action_type: perm.action_type,
|
|
263
|
-
access_flag: perm.access_flag,
|
|
264
|
-
app_code: perm.app_code,
|
|
265
|
-
}),
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
await this.moduleAccessRepo.save(clonedPermissions);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
success: true,
|
|
273
|
-
msg: 'Role updated successfully',
|
|
274
|
-
role: {
|
|
275
|
-
id: role.id,
|
|
276
|
-
name: role.name,
|
|
277
|
-
status: role.status,
|
|
278
|
-
code: role.code,
|
|
279
|
-
},
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
private async isRoleNameExists(name: string, excludeRoleId?: number): Promise<boolean> {
|
|
284
|
-
const query = this.roleRepo
|
|
285
|
-
.createQueryBuilder('role')
|
|
286
|
-
.where('role.name = :name', { name });
|
|
287
|
-
|
|
288
|
-
if (excludeRoleId) {
|
|
289
|
-
query.andWhere('role.id != :excludeRoleId', { excludeRoleId });
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const existingRole = await query.getOne();
|
|
293
|
-
return !!existingRole;
|
|
294
|
-
}
|
|
295
144
|
}
|
|
@@ -11,8 +11,6 @@ import { UserData } from 'src/module/user/entity/user.entity';
|
|
|
11
11
|
export class ModuleAccessService {
|
|
12
12
|
constructor(
|
|
13
13
|
private readonly moduleAccessRepository: ModuleAccessRepository,
|
|
14
|
-
@Inject('RoleService') private readonly roleService: RoleService,
|
|
15
|
-
private readonly entityManager: EntityManager,
|
|
16
14
|
) {}
|
|
17
15
|
|
|
18
16
|
async getRoles() {
|
|
@@ -48,64 +46,5 @@ export class ModuleAccessService {
|
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
|
|
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);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async updateRole(
|
|
64
|
-
id: number,
|
|
65
|
-
body: {
|
|
66
|
-
name?: string;
|
|
67
|
-
description?: string;
|
|
68
|
-
status?: 'ACTIVE' | 'INACTIVE';
|
|
69
|
-
copyFromRoleId?: number;
|
|
70
|
-
},
|
|
71
|
-
loggedInUser: UserData,
|
|
72
|
-
) {
|
|
73
|
-
if (!body.name) {
|
|
74
|
-
throw new BadRequestException('Role name is required');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (body.status === 'INACTIVE') {
|
|
78
|
-
//get role by id
|
|
79
|
-
const entityData = await this.roleService.getEntityData(
|
|
80
|
-
ENTITYTYPE_ROLE,
|
|
81
|
-
id,
|
|
82
|
-
);
|
|
83
|
-
|
|
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}`);
|
|
88
|
-
|
|
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
|
-
}
|
|
103
|
-
|
|
104
|
-
return this.moduleAccessRepository.updateRole(id, {
|
|
105
|
-
name: body.name,
|
|
106
|
-
description: body.description,
|
|
107
|
-
status: body.status,
|
|
108
|
-
copyFromRoleId: body.copyFromRoleId,
|
|
109
|
-
}, loggedInUser);
|
|
110
|
-
}
|
|
49
|
+
|
|
111
50
|
}
|