rez_core 2.0.49 → 2.0.51

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 (39) hide show
  1. package/dist/app.module.js +4 -0
  2. package/dist/app.module.js.map +1 -1
  3. package/dist/module/lead/controller/lead.controller.d.ts +20 -0
  4. package/dist/module/lead/controller/lead.controller.js +58 -0
  5. package/dist/module/lead/controller/lead.controller.js.map +1 -0
  6. package/dist/module/lead/lead.module.d.ts +2 -0
  7. package/dist/module/lead/lead.module.js +31 -0
  8. package/dist/module/lead/lead.module.js.map +1 -0
  9. package/dist/module/lead/repository/lead.repository.d.ts +13 -0
  10. package/dist/module/lead/repository/lead.repository.js +52 -0
  11. package/dist/module/lead/repository/lead.repository.js.map +1 -0
  12. package/dist/module/lead/service/lead.service.d.ts +20 -0
  13. package/dist/module/lead/service/lead.service.js +55 -0
  14. package/dist/module/lead/service/lead.service.js.map +1 -0
  15. package/dist/module/user/controller/login.controller.js +2 -2
  16. package/dist/module/user/controller/login.controller.js.map +1 -1
  17. package/dist/module/user/entity/user.entity.d.ts +1 -0
  18. package/dist/module/user/entity/user.entity.js +4 -0
  19. package/dist/module/user/entity/user.entity.js.map +1 -1
  20. package/dist/module/user/service/login.service.d.ts +3 -1
  21. package/dist/module/user/service/login.service.js +8 -8
  22. package/dist/module/user/service/login.service.js.map +1 -1
  23. package/dist/module/user/service/user-session.service.js +1 -4
  24. package/dist/module/user/service/user-session.service.js.map +1 -1
  25. package/dist/module/user/service/user.service.d.ts +1 -0
  26. package/dist/module/user/service/user.service.js +8 -0
  27. package/dist/module/user/service/user.service.js.map +1 -1
  28. package/dist/tsconfig.build.tsbuildinfo +1 -1
  29. package/package.json +1 -1
  30. package/src/app.module.ts +4 -0
  31. package/src/module/lead/controller/lead.controller.ts +30 -0
  32. package/src/module/lead/lead.module.ts +18 -0
  33. package/src/module/lead/repository/lead.repository.ts +37 -0
  34. package/src/module/lead/service/lead.service.ts +54 -0
  35. package/src/module/user/controller/login.controller.ts +2 -3
  36. package/src/module/user/entity/user.entity.ts +3 -0
  37. package/src/module/user/service/login.service.ts +40 -29
  38. package/src/module/user/service/user-session.service.ts +6 -4
  39. package/src/module/user/service/user.service.ts +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.0.49",
3
+ "version": "2.0.51",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
package/src/app.module.ts CHANGED
@@ -10,6 +10,8 @@ import Properties from './resources/properties.module';
10
10
  import { LayoutModule } from './module/layout/layout.module';
11
11
  import { ListMasterModule } from './module/listmaster/listmaster.module';
12
12
  import { ThirdPartyModule } from './module/third-party-module/third-party.module';
13
+ import { FilterModule } from './module/filter/filter.module';
14
+ import { LeadModule } from './module/lead/lead.module';
13
15
 
14
16
  @Module({
15
17
  imports: [
@@ -24,6 +26,8 @@ import { ThirdPartyModule } from './module/third-party-module/third-party.module
24
26
  LayoutModule,
25
27
  ListMasterModule,
26
28
  ThirdPartyModule,
29
+ FilterModule,
30
+ LeadModule,
27
31
  ],
28
32
  })
29
33
  export class AppModule {}
@@ -0,0 +1,30 @@
1
+ import { Controller, Get, Param, Query } from '@nestjs/common';
2
+ import { LeadService } from '../service/lead.service';
3
+
4
+ @Controller('lead')
5
+ export class LeadController {
6
+ constructor(private readonly leadService: LeadService) {}
7
+
8
+ @Get('organizations')
9
+ async getAllOrganizations() {
10
+ return this.leadService.getAllOrganizations();
11
+ }
12
+
13
+ @Get('brands/:organizationId')
14
+ async getBrandsByOrganization(
15
+ @Param('organizationId') organizationId: number,
16
+ ) {
17
+ return this.leadService.getBrandsByOrganization(organizationId);
18
+ }
19
+
20
+ @Get('schools')
21
+ async getSchoolsByBrandAndOrganization(
22
+ @Query('brandId') brandId: number,
23
+ @Query('organizationId') organizationId: number,
24
+ ) {
25
+ return this.leadService.getSchoolsByBrandAndOrganization(
26
+ brandId,
27
+ organizationId,
28
+ );
29
+ }
30
+ }
@@ -0,0 +1,18 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { LeadController } from './controller/lead.controller';
3
+ import { LeadService } from './service/lead.service';
4
+ import { LeadRepository } from './repository/lead.repository';
5
+ import { TypeOrmModule } from '@nestjs/typeorm';
6
+ import { OrganizationData } from '../enterprise/entity/organization.entity';
7
+ import { BrandData } from '../enterprise/entity/brand.entity';
8
+ import { SchoolData } from '../enterprise/entity/school.entity';
9
+
10
+ @Module({
11
+ imports: [
12
+ TypeOrmModule.forFeature([OrganizationData, BrandData, SchoolData]),
13
+ ],
14
+ providers: [LeadService, LeadRepository],
15
+ controllers: [LeadController],
16
+ exports: [],
17
+ })
18
+ export class LeadModule {}
@@ -0,0 +1,37 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { BrandData } from 'src/module/enterprise/entity/brand.entity';
4
+ import { OrganizationData } from 'src/module/enterprise/entity/organization.entity';
5
+ import { SchoolData } from 'src/module/enterprise/entity/school.entity';
6
+ import { Repository } from 'typeorm';
7
+
8
+ @Injectable()
9
+ export class LeadRepository {
10
+ constructor(
11
+ @InjectRepository(OrganizationData)
12
+ private organizationRepository: Repository<OrganizationData>,
13
+ @InjectRepository(BrandData)
14
+ private brandRepository: Repository<BrandData>,
15
+ @InjectRepository(SchoolData)
16
+ private schoolRepository: Repository<SchoolData>,
17
+ ) {}
18
+
19
+ async getAllOrganizations(): Promise<OrganizationData[]> {
20
+ return this.organizationRepository.find();
21
+ }
22
+
23
+ async getBrandsByOrganization(organization_id: number): Promise<BrandData[]> {
24
+ return this.brandRepository.find({
25
+ where: { organization_id },
26
+ });
27
+ }
28
+
29
+ async getSchoolsByBrandAndOrganization(
30
+ brand_id: number,
31
+ organization_id: number,
32
+ ): Promise<SchoolData[]> {
33
+ return this.schoolRepository.find({
34
+ where: { brand_id, organization_id },
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,54 @@
1
+ import { Injectable, NotFoundException } from '@nestjs/common';
2
+ import { LeadRepository } from '../repository/lead.repository';
3
+
4
+ @Injectable()
5
+ export class LeadService {
6
+ constructor(private readonly leadRepository: LeadRepository) {}
7
+
8
+ async getAllOrganizations() {
9
+ const organizations = await this.leadRepository.getAllOrganizations();
10
+ return organizations.map((org) => ({
11
+ id: org.id,
12
+ name: org.name,
13
+ // Add other organization fields as needed
14
+ }));
15
+ }
16
+
17
+ async getBrandsByOrganization(organizationId: number) {
18
+ const brands =
19
+ await this.leadRepository.getBrandsByOrganization(organizationId);
20
+ if (!brands.length) {
21
+ throw new NotFoundException(
22
+ `No brands found for organization ID ${organizationId}`,
23
+ );
24
+ }
25
+ return brands.map((brand) => ({
26
+ id: brand.id,
27
+ name: brand.name,
28
+ organizationId: brand.organization_id,
29
+ // Add other brand fields as needed
30
+ }));
31
+ }
32
+
33
+ async getSchoolsByBrandAndOrganization(
34
+ brandId: number,
35
+ organizationId: number,
36
+ ) {
37
+ const schools = await this.leadRepository.getSchoolsByBrandAndOrganization(
38
+ brandId,
39
+ organizationId,
40
+ );
41
+ if (!schools.length) {
42
+ throw new NotFoundException(
43
+ `No schools found for brand ID ${brandId} and organization ID ${organizationId}`,
44
+ );
45
+ }
46
+ return schools.map((school) => ({
47
+ id: school.id,
48
+ name: school.name,
49
+ brandId: school.brand_id,
50
+ organizationId: school.organization_id,
51
+ // Add other school fields as needed
52
+ }));
53
+ }
54
+ }
@@ -12,7 +12,6 @@ import { LoginService } from '../service/login.service';
12
12
  import { GoogleAuthGuard } from '../../../module/auth/guards/google-auth.guard';
13
13
  import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
14
14
  import { Request, Response } from 'express';
15
- import { JwtAuthService } from 'src/module/auth/services/jwt.service';
16
15
  import { UserSessionService } from '../service/user-session.service';
17
16
 
18
17
  @Controller('auth')
@@ -24,8 +23,8 @@ export class LoginController {
24
23
 
25
24
  @Post('login')
26
25
  async login(@Body() body, @Res() res: Response) {
27
- const { email_id, password, appcode } = body;
28
- const result = await this.loginService.login(email_id, password, appcode);
26
+ const { email_id, password, appcode, organization_id } = body;
27
+ const result = await this.loginService.login(email_id, password);
29
28
  return res.status(HttpStatus.OK).json(result);
30
29
  }
31
30
 
@@ -41,4 +41,7 @@ export class UserData extends BaseEntity {
41
41
 
42
42
  @Column({ type: 'int', nullable: true })
43
43
  is_factory: number;
44
+
45
+ @Column({ type: 'varchar', nullable: true })
46
+ last_app_access: string;
44
47
  }
@@ -18,17 +18,17 @@ export class LoginService {
18
18
  private userSessionService: UserSessionService,
19
19
  private configService: ConfigService,
20
20
  @InjectRepository(UserRoleMapping)
21
- private readonly userRoleMappingRepository: Repository<UserRoleMapping>,
22
- @InjectRepository(Role)
23
- private readonly roleRepo: Repository<Role>,
21
+ private readonly userRoleMappingRepository: Repository<UserRoleMapping>,
22
+ @InjectRepository(Role)
23
+ private readonly roleRepo: Repository<Role>,
24
24
  ) {}
25
25
 
26
26
  masterKey: string = this.configService.get('MASTER_KEY') || '';
27
27
  masterIv: string = this.configService.get('MASTER_IV') || '';
28
28
 
29
- async login(email: string, password: string, appcode: string) {
29
+ async login(email: string, password: string) {
30
30
  const user = await this.userService.findByEmailId(email);
31
-
31
+
32
32
  if (!user) {
33
33
  return {
34
34
  success: false,
@@ -36,7 +36,7 @@ export class LoginService {
36
36
  type: 'email',
37
37
  };
38
38
  }
39
-
39
+
40
40
  if (user.status !== 'ACTIVE') {
41
41
  return {
42
42
  success: false,
@@ -44,9 +44,13 @@ export class LoginService {
44
44
  type: 'email',
45
45
  };
46
46
  }
47
-
48
- const encryptedPassword = EncryptUtilService.encryptGCM(password, this.masterKey, this.masterIv);
49
-
47
+
48
+ const encryptedPassword = EncryptUtilService.encryptGCM(
49
+ password,
50
+ this.masterKey,
51
+ this.masterIv,
52
+ );
53
+
50
54
  if (encryptedPassword !== user.password) {
51
55
  return {
52
56
  success: false,
@@ -54,50 +58,57 @@ export class LoginService {
54
58
  type: 'password',
55
59
  };
56
60
  }
57
-
61
+
58
62
  // ✅ Get user-role mappings for this app
59
63
  const roleMappings = await this.userRoleMappingRepository.find({
60
64
  where: {
61
65
  user_id: user.id,
62
- appcode: appcode,
63
66
  },
64
67
  });
65
-
68
+
66
69
  if (!roleMappings.length) {
67
- throw new BadRequestException('User does not have any access mapped for this app.');
70
+ throw new BadRequestException(
71
+ 'User does not have any access mapped for this app.',
72
+ );
68
73
  }
69
-
74
+
70
75
  // ✅ Pick default access based on priority
71
76
  const priority = { org: 1, sch: 2, brn: 3 };
72
77
  const defaultAccess = roleMappings.sort(
73
78
  (a, b) => priority[a.level_type] - priority[b.level_type],
74
79
  )[0];
75
-
76
- // ✅ Manually fetch role_code from cr_role table
77
- const role = await this.roleRepo.findOne({
78
- where: { id: defaultAccess.role_id },
79
- });
80
-
81
- const token = await this.userSessionService.createSession(user, appcode, {
82
- level_type: defaultAccess.level_type,
83
- level_id: defaultAccess.level_id,
84
- role_id: defaultAccess.role_id,
85
- role_code: role?.code || null, // fallback if role not found
86
- });
87
-
80
+
81
+ //appcode
82
+
83
+ let appcode = user.last_app_access;
84
+
85
+ if (!appcode) {
86
+ appcode = 'ADM';
87
+ await this.userService.setDefaultLastAccess(user.id, appcode);
88
+ }
89
+
90
+ const token = await this.userSessionService.createSession(
91
+ user,
92
+ user.appcode,
93
+ {
94
+ level_type: defaultAccess.level_type,
95
+ level_id: defaultAccess.level_id,
96
+ },
97
+ );
98
+
88
99
  if (user.is_firstlogin === 1) {
89
100
  user.invitation_status = 'ACCEPTED';
90
101
  user.is_firstlogin = 0;
91
102
  const { password, ...userWithoutPassword } = user;
92
103
  await this.userService.updateEntity(userWithoutPassword, user);
93
104
  }
94
-
105
+
95
106
  return {
96
107
  success: true,
97
108
  accessToken: token,
109
+ appcode,
98
110
  };
99
111
  }
100
-
101
112
 
102
113
  async loginWithGoogle(email: string, name) {
103
114
  let user = await this.userService.findByEmailId(email);
@@ -38,8 +38,6 @@ export class UserSessionService {
38
38
  sessionToken,
39
39
  appcode,
40
40
  email_id: user.email_id,
41
- level_type: user.level_type,
42
- level_id: user.level_id,
43
41
  organization_id: user.organization_id,
44
42
  enterprise_id: user.enterprise_id,
45
43
  };
@@ -48,8 +46,6 @@ export class UserSessionService {
48
46
  if (accessInfo) {
49
47
  payload.level_type = accessInfo.level_type;
50
48
  payload.level_id = accessInfo.level_id;
51
- payload.role_id = accessInfo.role_id;
52
- payload.role_code = accessInfo.role_code;
53
49
  }
54
50
 
55
51
  const accessToken = this.jwtAuthService.generateJwt(payload);
@@ -98,6 +94,12 @@ export class UserSessionService {
98
94
  level_type: currentUserLevelType,
99
95
  appcode: data.appcode,
100
96
  };
97
+
98
+ await this.dataSource.query(
99
+ `UPDATE cr_user SET last_app_access = ? WHERE id = ?`,
100
+ [data.appcode, userId],
101
+ );
102
+
101
103
  // }
102
104
 
103
105
  // Step 2: Level switch logic
@@ -252,4 +252,16 @@ export class UserService extends EntityServiceImpl {
252
252
  appCode,
253
253
  );
254
254
  }
255
+
256
+ async setDefaultLastAccess(userId: number, appcode: string): Promise<void> {
257
+ const user = await this.userRepository.findById(userId);
258
+
259
+ if (!user) {
260
+ throw new BadRequestException('User not found');
261
+ }
262
+
263
+ user.last_app_access = appcode;
264
+
265
+ await this.userRepository.saveUser(user); // This persists the updated field
266
+ }
255
267
  }