rez_core 2.0.46 → 2.0.47
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/brand.entity.d.ts +1 -0
- package/dist/module/enterprise/entity/brand.entity.js +7 -0
- package/dist/module/enterprise/entity/brand.entity.js.map +1 -1
- package/dist/module/enterprise/entity/organization.entity.d.ts +1 -0
- package/dist/module/enterprise/entity/organization.entity.js +4 -0
- package/dist/module/enterprise/entity/organization.entity.js.map +1 -1
- package/dist/module/enterprise/entity/school.entity.d.ts +1 -0
- package/dist/module/enterprise/entity/school.entity.js +4 -0
- package/dist/module/enterprise/entity/school.entity.js.map +1 -1
- package/dist/module/enterprise/repository/school.repository.js +5 -0
- package/dist/module/enterprise/repository/school.repository.js.map +1 -1
- package/dist/module/user/controller/login.controller.js +1 -1
- package/dist/module/user/controller/login.controller.js.map +1 -1
- package/dist/module/user/service/login.service.d.ts +6 -3
- package/dist/module/user/service/login.service.js +32 -10
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/module/user/service/user-session.service.d.ts +1 -1
- package/dist/module/user/service/user-session.service.js +8 -2
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/enterprise/entity/brand.entity.ts +5 -2
- package/src/module/enterprise/entity/organization.entity.ts +3 -0
- package/src/module/enterprise/entity/school.entity.ts +3 -0
- package/src/module/enterprise/repository/school.repository.ts +5 -0
- package/src/module/user/controller/login.controller.ts +1 -1
- package/src/module/user/service/login.service.ts +48 -29
- package/src/module/user/service/user-session.service.ts +19 -8
package/package.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
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_brand' })
|
|
5
|
-
export class BrandData extends BaseEntity {
|
|
5
|
+
export class BrandData extends BaseEntity {
|
|
6
|
+
@Column({ name: 'type', nullable: true })
|
|
7
|
+
type: string;
|
|
8
|
+
}
|
|
@@ -73,6 +73,7 @@ export class SchoolRepository {
|
|
|
73
73
|
org_id,
|
|
74
74
|
org_name,
|
|
75
75
|
org_address,
|
|
76
|
+
type: 'Organization',
|
|
76
77
|
brands: {},
|
|
77
78
|
};
|
|
78
79
|
}
|
|
@@ -80,6 +81,7 @@ export class SchoolRepository {
|
|
|
80
81
|
result[org_id].brands[brand_id] = {
|
|
81
82
|
brand_id,
|
|
82
83
|
brand_name,
|
|
84
|
+
type: 'Brand',
|
|
83
85
|
schools: [],
|
|
84
86
|
};
|
|
85
87
|
}
|
|
@@ -87,6 +89,7 @@ export class SchoolRepository {
|
|
|
87
89
|
school_id,
|
|
88
90
|
school_name,
|
|
89
91
|
school_location,
|
|
92
|
+
type: 'School',
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
95
|
|
|
@@ -148,6 +151,7 @@ export class SchoolRepository {
|
|
|
148
151
|
result[brand_id] = {
|
|
149
152
|
brand_id,
|
|
150
153
|
brand_name,
|
|
154
|
+
type: 'Brand',
|
|
151
155
|
schools: [],
|
|
152
156
|
};
|
|
153
157
|
}
|
|
@@ -161,6 +165,7 @@ export class SchoolRepository {
|
|
|
161
165
|
school_id,
|
|
162
166
|
school_name,
|
|
163
167
|
school_location,
|
|
168
|
+
type: 'School',
|
|
164
169
|
});
|
|
165
170
|
}
|
|
166
171
|
}
|
|
@@ -30,7 +30,7 @@ export class LoginController {
|
|
|
30
30
|
@Req() request: Request & { user: any },
|
|
31
31
|
@Res() response: Response,
|
|
32
32
|
) {
|
|
33
|
-
let requestUser: any = request.user;
|
|
33
|
+
let requestUser: any = request.user.userData;
|
|
34
34
|
response
|
|
35
35
|
.status(HttpStatus.OK)
|
|
36
36
|
.json(await this.loginService.logout(requestUser.sessionToken));
|
|
@@ -5,6 +5,11 @@ import { UserSessionService } from './user-session.service';
|
|
|
5
5
|
import { UserService } from './user.service';
|
|
6
6
|
import { ConfigService } from '@nestjs/config';
|
|
7
7
|
import { UserAppMappingService } from 'src/module/meta/service/user-app-mapping.service';
|
|
8
|
+
import { UserRoleMappingRepository } from '../repository/user-role-mapping.repository';
|
|
9
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
10
|
+
import { UserRoleMapping } from '../entity/user-role-mapping.entity';
|
|
11
|
+
import { Repository } from 'typeorm';
|
|
12
|
+
import { Role } from '../entity/role.entity';
|
|
8
13
|
|
|
9
14
|
@Injectable()
|
|
10
15
|
export class LoginService {
|
|
@@ -12,7 +17,10 @@ export class LoginService {
|
|
|
12
17
|
@Inject('UserService') private readonly userService: UserService,
|
|
13
18
|
private userSessionService: UserSessionService,
|
|
14
19
|
private configService: ConfigService,
|
|
15
|
-
|
|
20
|
+
@InjectRepository(UserRoleMapping)
|
|
21
|
+
private readonly userRoleMappingRepository: Repository<UserRoleMapping>,
|
|
22
|
+
@InjectRepository(Role)
|
|
23
|
+
private readonly roleRepo: Repository<Role>,
|
|
16
24
|
) {}
|
|
17
25
|
|
|
18
26
|
masterKey: string = this.configService.get('MASTER_KEY') || '';
|
|
@@ -20,27 +28,15 @@ export class LoginService {
|
|
|
20
28
|
|
|
21
29
|
async login(email: string, password: string, appcode: string) {
|
|
22
30
|
const user = await this.userService.findByEmailId(email);
|
|
23
|
-
|
|
31
|
+
|
|
24
32
|
if (!user) {
|
|
25
33
|
return {
|
|
26
34
|
success: false,
|
|
27
|
-
message: 'Your Email ID not registered.',
|
|
35
|
+
message: 'Your Email ID is not registered.',
|
|
28
36
|
type: 'email',
|
|
29
37
|
};
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
const userAppMapping = await this.userAppMappingService.getUserAppMappings(
|
|
33
|
-
user.id,
|
|
34
|
-
appcode,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (!userAppMapping) {
|
|
38
|
-
// If user is not mapped to the app, throw an error
|
|
39
|
-
throw new BadRequestException(
|
|
40
|
-
`User with email ${email} is not mapped to the app ${appcode}.`,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
39
|
+
|
|
44
40
|
if (user.status !== 'ACTIVE') {
|
|
45
41
|
return {
|
|
46
42
|
success: false,
|
|
@@ -48,13 +44,9 @@ export class LoginService {
|
|
|
48
44
|
type: 'email',
|
|
49
45
|
};
|
|
50
46
|
}
|
|
51
|
-
|
|
52
|
-
const encryptedPassword = EncryptUtilService.encryptGCM(
|
|
53
|
-
|
|
54
|
-
this.masterKey,
|
|
55
|
-
this.masterIv,
|
|
56
|
-
);
|
|
57
|
-
|
|
47
|
+
|
|
48
|
+
const encryptedPassword = EncryptUtilService.encryptGCM(password, this.masterKey, this.masterIv);
|
|
49
|
+
|
|
58
50
|
if (encryptedPassword !== user.password) {
|
|
59
51
|
return {
|
|
60
52
|
success: false,
|
|
@@ -62,23 +54,50 @@ export class LoginService {
|
|
|
62
54
|
type: 'password',
|
|
63
55
|
};
|
|
64
56
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
|
|
58
|
+
// ✅ Get user-role mappings for this app
|
|
59
|
+
const roleMappings = await this.userRoleMappingRepository.find({
|
|
60
|
+
where: {
|
|
61
|
+
user_id: user.id,
|
|
62
|
+
appcode: appcode,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!roleMappings.length) {
|
|
67
|
+
throw new BadRequestException('User does not have any access mapped for this app.');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ✅ Pick default access based on priority
|
|
71
|
+
const priority = { org: 1, sch: 2, brn: 3 };
|
|
72
|
+
const defaultAccess = roleMappings.sort(
|
|
73
|
+
(a, b) => priority[a.level_type] - priority[b.level_type],
|
|
74
|
+
)[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
|
+
|
|
68
88
|
if (user.is_firstlogin === 1) {
|
|
69
89
|
user.invitation_status = 'ACCEPTED';
|
|
70
90
|
user.is_firstlogin = 0;
|
|
71
|
-
|
|
72
91
|
const { password, ...userWithoutPassword } = user;
|
|
73
|
-
|
|
74
92
|
await this.userService.updateEntity(userWithoutPassword, user);
|
|
75
93
|
}
|
|
76
|
-
|
|
94
|
+
|
|
77
95
|
return {
|
|
78
96
|
success: true,
|
|
79
97
|
accessToken: token,
|
|
80
98
|
};
|
|
81
99
|
}
|
|
100
|
+
|
|
82
101
|
|
|
83
102
|
async loginWithGoogle(email: string, name) {
|
|
84
103
|
let user = await this.userService.findByEmailId(email);
|
|
@@ -13,36 +13,47 @@ export class UserSessionService {
|
|
|
13
13
|
private readonly clockIDGenService: ClockIDGenService,
|
|
14
14
|
private configService: ConfigService,
|
|
15
15
|
) {}
|
|
16
|
-
async createSession(user, appcode?: string) {
|
|
16
|
+
async createSession(user, appcode?: string, accessInfo?: any) {
|
|
17
17
|
const sessionToken = this.clockIDGenService.idGenerator('SES');
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
const userSession: any = new UserSession();
|
|
20
20
|
userSession.user_id = user.id;
|
|
21
21
|
userSession.session_key = sessionToken;
|
|
22
22
|
userSession.is_session_loggedout = 0;
|
|
23
23
|
userSession.login_time = new Date();
|
|
24
|
+
|
|
24
25
|
const expiryTokenInHours = this.configService.get('TOKEN_EXPIRY') || 1;
|
|
25
26
|
userSession.expiry_date = new Date(
|
|
26
27
|
Date.now() + expiryTokenInHours * 60 * 60 * 1000,
|
|
27
28
|
);
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
await this.userSessionRepository.saveSession(userSession);
|
|
30
|
-
|
|
31
|
-
const payload = {
|
|
31
|
+
|
|
32
|
+
const payload: any = {
|
|
32
33
|
userId: user.id,
|
|
33
34
|
sessionToken,
|
|
34
|
-
appcode
|
|
35
|
+
appcode,
|
|
35
36
|
email_id: user.email_id,
|
|
36
37
|
organization_id: user.organization_id,
|
|
37
38
|
enterprise_id: user.enterprise_id,
|
|
38
39
|
};
|
|
40
|
+
|
|
41
|
+
// ✅ Add role access details
|
|
42
|
+
if (accessInfo) {
|
|
43
|
+
payload.level_type = accessInfo.level_type;
|
|
44
|
+
payload.level_id = accessInfo.level_id;
|
|
45
|
+
payload.role_id = accessInfo.role_id;
|
|
46
|
+
payload.role_code = accessInfo.role_code;
|
|
47
|
+
}
|
|
48
|
+
|
|
39
49
|
const accessToken = this.jwtAuthService.generateJwt(payload);
|
|
40
|
-
|
|
50
|
+
|
|
41
51
|
userSession.access_token = accessToken;
|
|
42
52
|
await this.userSessionRepository.saveSession(userSession);
|
|
43
|
-
|
|
53
|
+
|
|
44
54
|
return accessToken;
|
|
45
55
|
}
|
|
56
|
+
|
|
46
57
|
|
|
47
58
|
async findBySessionKey(sessionKey: string): Promise<UserSession | null> {
|
|
48
59
|
return await this.userSessionRepository.findBySessionKey(sessionKey);
|