rez_core 2.0.42 → 2.0.43

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.
Files changed (47) hide show
  1. package/dist/module/enterprise/controller/organization.controller.d.ts +3 -0
  2. package/dist/module/enterprise/controller/organization.controller.js +14 -0
  3. package/dist/module/enterprise/controller/organization.controller.js.map +1 -1
  4. package/dist/module/enterprise/enterprise.module.js +10 -1
  5. package/dist/module/enterprise/enterprise.module.js.map +1 -1
  6. package/dist/module/enterprise/entity/school.entity.js +11 -0
  7. package/dist/module/enterprise/entity/school.entity.js.map +1 -1
  8. package/dist/module/enterprise/repository/brand.repository.d.ts +8 -0
  9. package/dist/module/enterprise/repository/brand.repository.js +39 -0
  10. package/dist/module/enterprise/repository/brand.repository.js.map +1 -0
  11. package/dist/module/enterprise/repository/school.repository.d.ts +10 -0
  12. package/dist/module/enterprise/repository/school.repository.js +146 -0
  13. package/dist/module/enterprise/repository/school.repository.js.map +1 -0
  14. package/dist/module/enterprise/service/organization.service.d.ts +8 -1
  15. package/dist/module/enterprise/service/organization.service.js +15 -2
  16. package/dist/module/enterprise/service/organization.service.js.map +1 -1
  17. package/dist/module/meta/controller/app-master.controller.d.ts +9 -0
  18. package/dist/module/meta/controller/app-master.controller.js +51 -0
  19. package/dist/module/meta/controller/app-master.controller.js.map +1 -0
  20. package/dist/module/meta/entity/app-master.entity.d.ts +6 -1
  21. package/dist/module/meta/entity/app-master.entity.js +26 -6
  22. package/dist/module/meta/entity/app-master.entity.js.map +1 -1
  23. package/dist/module/meta/entity.module.js +13 -0
  24. package/dist/module/meta/entity.module.js.map +1 -1
  25. package/dist/module/meta/repository/app-master.repository.d.ts +7 -0
  26. package/dist/module/meta/repository/app-master.repository.js +36 -0
  27. package/dist/module/meta/repository/app-master.repository.js.map +1 -0
  28. package/dist/module/meta/service/app-master.service.d.ts +8 -0
  29. package/dist/module/meta/service/app-master.service.js +42 -0
  30. package/dist/module/meta/service/app-master.service.js.map +1 -0
  31. package/dist/module/user/repository/user-role-mapping.repository.d.ts +3 -0
  32. package/dist/module/user/repository/user-role-mapping.repository.js +9 -0
  33. package/dist/module/user/repository/user-role-mapping.repository.js.map +1 -1
  34. package/dist/tsconfig.build.tsbuildinfo +1 -1
  35. package/package.json +1 -1
  36. package/src/module/enterprise/controller/organization.controller.ts +11 -0
  37. package/src/module/enterprise/enterprise.module.ts +10 -1
  38. package/src/module/enterprise/entity/school.entity.ts +3 -1
  39. package/src/module/enterprise/repository/brand.repository.ts +23 -0
  40. package/src/module/enterprise/repository/school.repository.ts +155 -0
  41. package/src/module/enterprise/service/organization.service.ts +13 -2
  42. package/src/module/meta/controller/app-master.controller.ts +38 -0
  43. package/src/module/meta/entity/app-master.entity.ts +17 -2
  44. package/src/module/meta/entity.module.ts +13 -0
  45. package/src/module/meta/repository/app-master.repository.ts +20 -0
  46. package/src/module/meta/service/app-master.service.ts +34 -0
  47. package/src/module/user/repository/user-role-mapping.repository.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.0.42",
3
+ "version": "2.0.43",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -20,4 +20,15 @@ export class OrganizationController {
20
20
  // const enterpriseId = req.user['enterpriseId']; // or adapt based on your user structure
21
21
  return this.orgService.findById(userData?.organization_id);
22
22
  }
23
+
24
+ @UseGuards(JwtAuthGuard)
25
+ @Get('hierarchy')
26
+ async getOrganizationHierarchy(@Req() req: Request & { user: any }) {
27
+ const userId = req.user.userData?.id;
28
+ const appcode = req.user.userData?.appcode;
29
+
30
+ console.log(userId, appcode, 'userId, appcode');
31
+
32
+ return await this.orgService.getOrganizationHierarchy(userId, appcode);
33
+ }
23
34
  }
@@ -8,6 +8,9 @@ import { OrganizationAppMappingService } from './service/organization-app-mappin
8
8
  import { OrganizationAppMapping } from './entity/organization-app-mapping.entity';
9
9
  import { BrandData } from './entity/brand.entity';
10
10
  import { SchoolData } from './entity/school.entity';
11
+ import { BrandRepository } from './repository/brand.repository';
12
+ import { SchoolRepository } from './repository/school.repository';
13
+ import { UtilsModule } from 'src/utils/utils.module';
11
14
 
12
15
  @Module({
13
16
  imports: [
@@ -18,9 +21,15 @@ import { SchoolData } from './entity/school.entity';
18
21
  SchoolData,
19
22
  ]),
20
23
  UserModule,
24
+ UtilsModule,
21
25
  ],
22
26
  controllers: [OrganizationController],
23
- providers: [OrganizationService, OrganizationAppMappingService],
27
+ providers: [
28
+ OrganizationService,
29
+ OrganizationAppMappingService,
30
+ BrandRepository,
31
+ SchoolRepository,
32
+ ],
24
33
  exports: [OrganizationService],
25
34
  })
26
35
  export class EnterpriseModule {}
@@ -1,9 +1,11 @@
1
1
  import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
2
- import { Entity } from 'typeorm';
2
+ import { Column, Entity } from 'typeorm';
3
3
 
4
4
  @Entity({ name: 'cr_school' })
5
5
  export class SchoolData extends BaseEntity {
6
+ @Column({ name: 'brand_id', nullable: true })
6
7
  brand_id: number;
7
8
 
9
+ @Column({ name: 'brand_code', nullable: true })
8
10
  brand_code: string;
9
11
  }
@@ -0,0 +1,23 @@
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
+ import { BrandData } from '../entity/brand.entity';
6
+
7
+ @Injectable()
8
+ export class BrandRepository {
9
+ constructor(
10
+ @InjectRepository(BrandData)
11
+ private readonly brandRepository: Repository<BrandData>,
12
+ ) {}
13
+
14
+ async findAllByOrgId(orgId: number): Promise<BrandData[]> {
15
+ return await this.brandRepository.find({
16
+ where: { organization_id: orgId },
17
+ });
18
+ }
19
+
20
+ async findOne(id: number): Promise<BrandData | null> {
21
+ return await this.brandRepository.findOne({ where: { id } });
22
+ }
23
+ }
@@ -0,0 +1,155 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { DataSource, Repository } from 'typeorm';
4
+ import { SchoolData } from '../entity/school.entity';
5
+ import { UserRoleMapping } from 'src/module/user/entity/user-role-mapping.entity';
6
+
7
+ @Injectable()
8
+ export class SchoolRepository {
9
+ constructor(
10
+ @InjectRepository(SchoolData)
11
+ private readonly schoolRepo: Repository<SchoolData>,
12
+ private readonly dataSource: DataSource,
13
+ ) {}
14
+
15
+ async findAllByOrgId(brdId: number): Promise<SchoolData[]> {
16
+ return await this.schoolRepo.find({
17
+ where: { brand_id: brdId },
18
+ });
19
+ }
20
+
21
+ async findAllByBrandId(brdId: number): Promise<SchoolData[]> {
22
+ return await this.schoolRepo.find({
23
+ where: { brand_id: brdId },
24
+ });
25
+ }
26
+
27
+ async getUserContextDropdown(userId: number, appCode: string) {
28
+ const userRoleRepo = this.dataSource.getRepository(UserRoleMapping);
29
+
30
+ // Check if user has any org level access for the app
31
+ const hasOrgAccess = await userRoleRepo
32
+ .createQueryBuilder('urm')
33
+ .where('urm.user_id = :userId', { userId })
34
+ .andWhere('urm.appcode = :appCode', { appCode })
35
+ .andWhere('urm.level_type = :levelType', { levelType: 'ORG' })
36
+ .getRawMany();
37
+
38
+ console.log(hasOrgAccess);
39
+ if (hasOrgAccess.length > 0) {
40
+ // Return nested Org -> Brand -> School structure
41
+ const schools = await this.dataSource
42
+ .createQueryBuilder()
43
+ .select([
44
+ 'org.id AS org_id',
45
+ 'org.name AS org_name',
46
+ 'br.id AS brand_id',
47
+ 'br.name AS brand_name',
48
+ 'sch.id AS school_id',
49
+ 'sch.name AS school_name',
50
+ ])
51
+ .from('cr_school', 'sch')
52
+ .innerJoin('cr_brand', 'br', 'sch.brand_id = br.id')
53
+ .innerJoin('cr_organization', 'org', 'br.organization_id = org.id')
54
+ .where('org.id = :orgId', { orgId: hasOrgAccess[0].urm_level_id })
55
+ .getRawMany();
56
+ const result = {};
57
+
58
+ for (const row of schools) {
59
+ const {
60
+ org_id,
61
+ org_name,
62
+ brand_id,
63
+ brand_name,
64
+ school_id,
65
+ school_name,
66
+ } = row;
67
+
68
+ if (!result[org_id]) {
69
+ result[org_id] = {
70
+ org_id,
71
+ org_name,
72
+ brands: {},
73
+ };
74
+ }
75
+ if (!result[org_id].brands[brand_id]) {
76
+ result[org_id].brands[brand_id] = {
77
+ brand_id,
78
+ brand_name,
79
+ schools: [],
80
+ };
81
+ }
82
+ result[org_id].brands[brand_id].schools.push({
83
+ school_id,
84
+ school_name,
85
+ });
86
+ }
87
+
88
+ return Object.values(result).map((org: { [key: string]: any }) => ({
89
+ ...org,
90
+ brands: Object.values(org.brands),
91
+ }));
92
+ } else {
93
+ // 1. Get schools via BRN-level access
94
+ const brnMappings = await this.dataSource
95
+ .createQueryBuilder()
96
+ .select([
97
+ 'brand.id AS brand_id',
98
+ 'brand.name AS brand_name',
99
+ 'school.id AS school_id',
100
+ 'school.name AS school_name',
101
+ ])
102
+ .from('cr_user_role_mapping', 'urm')
103
+ .innerJoin('cr_brand', 'brand', 'brand.id = urm.level_id')
104
+ .innerJoin('cr_school', 'school', 'school.brand_id = brand.id')
105
+ .where('urm.user_id = :userId', { userId })
106
+ .andWhere('urm.appcode = :appCode', { appCode })
107
+ .andWhere('urm.level_type = :levelType', { levelType: 'BRN' })
108
+ .getRawMany();
109
+
110
+ // 2. Get directly mapped schools via SCH-level access
111
+ const schMappings = await this.dataSource
112
+ .createQueryBuilder()
113
+ .select([
114
+ 'brand.id AS brand_id',
115
+ 'brand.name AS brand_name',
116
+ 'school.id AS school_id',
117
+ 'school.name AS school_name',
118
+ ])
119
+ .from('cr_user_role_mapping', 'urm')
120
+ .innerJoin('cr_school', 'school', 'school.id = urm.level_id')
121
+ .innerJoin('cr_brand', 'brand', 'brand.id = school.brand_id')
122
+ .where('urm.user_id = :userId', { userId })
123
+ .andWhere('urm.appcode = :appCode', { appCode })
124
+ .andWhere('urm.level_type = :levelType', { levelType: 'SCH' })
125
+ .getRawMany();
126
+
127
+ // 3. Combine both mappings
128
+ const allMappings = [...brnMappings, ...schMappings];
129
+
130
+ // 4. Group by brand
131
+ const result = {};
132
+ for (const row of allMappings) {
133
+ const { brand_id, brand_name, school_id, school_name } = row;
134
+
135
+ if (!result[brand_id]) {
136
+ result[brand_id] = {
137
+ brand_id,
138
+ brand_name,
139
+ schools: [],
140
+ };
141
+ }
142
+
143
+ // prevent duplicates if needed
144
+ if (
145
+ school_id &&
146
+ !result[brand_id].schools.some((s) => s.school_id === school_id)
147
+ ) {
148
+ result[brand_id].schools.push({ school_id, school_name });
149
+ }
150
+ }
151
+
152
+ return Object.values(result);
153
+ }
154
+ }
155
+ }
@@ -1,15 +1,22 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { Inject, Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { EntityManager, Repository } from 'typeorm';
4
4
  import { OrganizationData } from '../entity/organization.entity';
5
5
  import { ClockIDGenService } from 'src/utils/service/clockIDGenUtil.service';
6
+ import { UserService } from 'src/module/user/service/user.service';
7
+ import { ENTITYTYPE_USER } from 'src/constant/global.constant';
8
+ import { BrandRepository } from '../repository/brand.repository';
9
+ import { SchoolRepository } from '../repository/school.repository';
6
10
 
7
11
  @Injectable()
8
12
  export class OrganizationService {
9
13
  constructor(
10
14
  @InjectRepository(OrganizationData)
11
15
  private readonly organizationRepository: Repository<OrganizationData>,
16
+ private readonly brandRepository: BrandRepository,
17
+ private readonly schoolRepository: SchoolRepository,
12
18
  private readonly idGen: ClockIDGenService,
19
+ @Inject('UserService') private readonly userService: UserService,
13
20
  ) {}
14
21
 
15
22
  async create(
@@ -46,7 +53,7 @@ export class OrganizationService {
46
53
  return await repo.findOne({ where: { id } });
47
54
  }
48
55
 
49
- async findById(id:number | undefined){
56
+ async findById(id: number | undefined) {
50
57
  return await this.organizationRepository.find({ where: { id } });
51
58
  }
52
59
 
@@ -70,4 +77,8 @@ export class OrganizationService {
70
77
 
71
78
  await repo.delete(id);
72
79
  }
80
+
81
+ async getOrganizationHierarchy(userId: number, appCode: string) {
82
+ return await this.schoolRepository.getUserContextDropdown(userId, appCode);
83
+ }
73
84
  }
@@ -0,0 +1,38 @@
1
+ import {
2
+ Controller,
3
+ Get,
4
+ Query,
5
+ Res,
6
+ HttpStatus,
7
+ UseGuards,
8
+ Inject,
9
+ Req,
10
+ } from '@nestjs/common';
11
+ import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
12
+ import { Response } from 'express';
13
+ import { AppMasterService } from '../service/app-master.service';
14
+
15
+ @Controller('apps')
16
+ @UseGuards(JwtAuthGuard)
17
+ export class AppMasterController {
18
+ constructor(private appMasterService: AppMasterService) {}
19
+
20
+ @Get('')
21
+ async getAppByAppCode(
22
+ @Req() req: Request & { user: any },
23
+ @Res() res: Response,
24
+ ) {
25
+ try {
26
+ const id = req.user.userData.id;
27
+
28
+ const data = await this.appMasterService.getAppMasterDataByAppCode(id);
29
+
30
+ return res.status(HttpStatus.OK).json(data);
31
+ } catch (error) {
32
+ return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
33
+ success: false,
34
+ message: error.message || 'Error fetching entity data',
35
+ });
36
+ }
37
+ }
38
+ }
@@ -1,8 +1,8 @@
1
- import { Entity, PrimaryGeneratedColumn } from 'typeorm';
1
+ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
2
2
  import { BaseEntity } from './base-entity.entity';
3
3
 
4
4
  @Entity({ name: 'cr_app_master' })
5
- export class UserAppMapping extends BaseEntity {
5
+ export class AppMaster extends BaseEntity {
6
6
  constructor() {
7
7
  super();
8
8
  this.entity_type = 'APM';
@@ -10,4 +10,19 @@ export class UserAppMapping extends BaseEntity {
10
10
 
11
11
  @PrimaryGeneratedColumn()
12
12
  id: number;
13
+
14
+ @Column({ name: 'type', type: 'varchar', nullable: true })
15
+ type: string;
16
+
17
+ @Column({ name: 'color', type: 'varchar', nullable: true })
18
+ color: string;
19
+
20
+ @Column({ name: 'route', type: 'varchar', nullable: true })
21
+ route: string;
22
+
23
+ @Column({ name: 'description', type: 'varchar', nullable: true })
24
+ description: string;
25
+
26
+ @Column({ name: 'backgroudColor', type: 'varchar', nullable: true })
27
+ backgroudColor: string;
13
28
  }
@@ -41,6 +41,12 @@ import { FilterModule } from '../filter/filter.module';
41
41
  import { UserAppMappingService } from './service/user-app-mapping.service';
42
42
  import { UserAppMappingRepository } from './repository/user-app-mapping.repository';
43
43
  import { UserAppMapping } from './entity/user-app-mapping.entity';
44
+ import { AppMasterController } from './controller/app-master.controller';
45
+ import { UserRoleMappingRepository } from '../user/repository/user-role-mapping.repository';
46
+ import { UserRoleMapping } from '../user/entity/user-role-mapping.entity';
47
+ import { AppMasterService } from './service/app-master.service';
48
+ import { AppMasterRespository } from './repository/app-master.repository';
49
+ import { AppMaster } from './entity/app-master.entity';
44
50
 
45
51
  @Module({
46
52
  imports: [
@@ -57,6 +63,8 @@ import { UserAppMapping } from './entity/user-app-mapping.entity';
57
63
  SectionMaster,
58
64
  FieldGroup,
59
65
  UserAppMapping,
66
+ UserRoleMapping,
67
+ AppMaster,
60
68
  ]),
61
69
  forwardRef(() => ListMasterModule),
62
70
  forwardRef(() => FilterModule),
@@ -84,6 +92,9 @@ import { UserAppMapping } from './entity/user-app-mapping.entity';
84
92
  { provide: 'ViewMasterService', useClass: ViewMasterService },
85
93
  UserAppMappingService,
86
94
  UserAppMappingRepository,
95
+ UserRoleMappingRepository,
96
+ AppMasterRespository,
97
+ AppMasterService,
87
98
  ],
88
99
  exports: [
89
100
  EntityMasterService,
@@ -100,6 +111,7 @@ import { UserAppMapping } from './entity/user-app-mapping.entity';
100
111
  AttributeMasterService,
101
112
  UserAppMappingService,
102
113
  UserAppMappingRepository,
114
+ AppMasterService,
103
115
  ],
104
116
  controllers: [
105
117
  EntityController,
@@ -107,6 +119,7 @@ import { UserAppMapping } from './entity/user-app-mapping.entity';
107
119
  MediaController,
108
120
  ViewMasterController,
109
121
  MetaController,
122
+ AppMasterController,
110
123
  ],
111
124
  })
112
125
  export class EntityModule {}
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { BaseEntity, Repository } from 'typeorm';
4
+ import { AppMaster } from '../entity/app-master.entity';
5
+
6
+ @Injectable()
7
+ export class AppMasterRespository {
8
+ constructor(
9
+ @InjectRepository(AppMaster)
10
+ private readonly AppMasterRespository: Repository<AppMaster>,
11
+ ) {}
12
+
13
+ async getAppMasterDataByAppCode(
14
+ appCode: string,
15
+ ): Promise<AppMaster[] | null> {
16
+ return await this.AppMasterRespository.find({
17
+ where: { appcode: appCode },
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,34 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { UserRoleMappingRepository } from 'src/module/user/repository/user-role-mapping.repository';
3
+ import { AppMasterRespository } from '../repository/app-master.repository';
4
+
5
+ @Injectable()
6
+ export class AppMasterService {
7
+ constructor(
8
+ private readonly appMasterRepository: AppMasterRespository,
9
+ private readonly userRoleMappingRepository: UserRoleMappingRepository,
10
+ ) {}
11
+
12
+ async getAppMasterDataByAppCode(userId: number) {
13
+ const app_code =
14
+ await this.userRoleMappingRepository.findDistinctAppcodeByUserId(userId);
15
+
16
+ const result: Record<string, any> = {};
17
+
18
+ if (app_code.appcode.length > 0) {
19
+ const resolvedData = await Promise.all(
20
+ app_code.appcode.map(async (element) => {
21
+ const data =
22
+ await this.appMasterRepository.getAppMasterDataByAppCode(element);
23
+ return { [element]: data };
24
+ }),
25
+ );
26
+
27
+ resolvedData.forEach((entry) => {
28
+ Object.assign(result, entry);
29
+ });
30
+ }
31
+
32
+ return result;
33
+ }
34
+ }
@@ -47,4 +47,18 @@ export class UserRoleMappingRepository {
47
47
  async deleteByUserId(userId: number) {
48
48
  await this.userRoleMappingRepository.delete({ user_id: userId });
49
49
  }
50
+
51
+ async findDistinctAppcodeByUserId(
52
+ userId: number,
53
+ ): Promise<{ appcode: string[] }> {
54
+ const result = await this.userRoleMappingRepository
55
+ .createQueryBuilder('urm')
56
+ .select('DISTINCT urm.appcode', 'appcode')
57
+ .where('urm.user_id = :userId', { userId })
58
+ .getRawMany();
59
+
60
+ const appcodeArray = result.map((row) => row.appcode);
61
+
62
+ return { appcode: appcodeArray };
63
+ }
50
64
  }