rez_core 2.1.33 → 2.1.35
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/main.js +0 -13
- package/dist/main.js.map +1 -1
- package/dist/module/enterprise/enterprise.module.js +11 -2
- package/dist/module/enterprise/enterprise.module.js.map +1 -1
- package/dist/module/enterprise/repository/organization.repository.d.ts +7 -0
- package/dist/module/enterprise/repository/organization.repository.js +36 -0
- package/dist/module/enterprise/repository/organization.repository.js.map +1 -0
- package/dist/module/enterprise/service/school.service.d.ts +3 -0
- package/dist/module/enterprise/service/school.service.js +18 -0
- package/dist/module/enterprise/service/school.service.js.map +1 -0
- package/dist/module/filter/service/filter.service.js +1 -3
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/meta/service/entity-service-impl.service.js +5 -3
- package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
- package/dist/module/user/service/login.service.d.ts +5 -3
- package/dist/module/user/service/login.service.js +14 -9
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/module/user/user.module.js +3 -1
- 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/enterprise.module.ts +12 -3
- package/src/module/enterprise/repository/organization.repository.ts +18 -0
- package/src/module/enterprise/service/school.service.ts +5 -0
- package/src/module/filter/service/filter.service.ts +3 -4
- package/src/module/meta/service/entity-service-impl.service.ts +5 -3
- package/src/module/user/service/login.service.ts +44 -32
- package/src/module/user/user.module.ts +4 -2
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
1
|
+
import { forwardRef, Module } from '@nestjs/common';
|
|
2
2
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
3
|
import { OrganizationService } from './service/organization.service';
|
|
4
4
|
import { OrganizationData } from './entity/organization.entity';
|
|
@@ -12,6 +12,9 @@ import { BrandRepository } from './repository/brand.repository';
|
|
|
12
12
|
import { SchoolRepository } from './repository/school.repository';
|
|
13
13
|
import { UtilsModule } from 'src/utils/utils.module';
|
|
14
14
|
import { BrandService } from './service/brand.service';
|
|
15
|
+
import { OrganizationRepository } from './repository/organization.repository';
|
|
16
|
+
import { SchoolService } from './service/school.service';
|
|
17
|
+
import { EntityModule } from '../meta/entity.module';
|
|
15
18
|
|
|
16
19
|
@Module({
|
|
17
20
|
imports: [
|
|
@@ -21,8 +24,9 @@ import { BrandService } from './service/brand.service';
|
|
|
21
24
|
BrandData,
|
|
22
25
|
SchoolData,
|
|
23
26
|
]),
|
|
24
|
-
UserModule,
|
|
27
|
+
forwardRef(() => UserModule),
|
|
25
28
|
UtilsModule,
|
|
29
|
+
EntityModule,
|
|
26
30
|
],
|
|
27
31
|
controllers: [OrganizationController],
|
|
28
32
|
providers: [
|
|
@@ -30,11 +34,16 @@ import { BrandService } from './service/brand.service';
|
|
|
30
34
|
OrganizationAppMappingService,
|
|
31
35
|
BrandRepository,
|
|
32
36
|
SchoolRepository,
|
|
37
|
+
OrganizationRepository,
|
|
33
38
|
{
|
|
34
39
|
provide: 'BrandService',
|
|
35
40
|
useClass: BrandService,
|
|
36
41
|
},
|
|
42
|
+
{
|
|
43
|
+
provide: 'SchoolService',
|
|
44
|
+
useClass: SchoolService,
|
|
45
|
+
},
|
|
37
46
|
],
|
|
38
|
-
exports: [OrganizationService],
|
|
47
|
+
exports: [OrganizationService, OrganizationRepository],
|
|
39
48
|
})
|
|
40
49
|
export class EnterpriseModule {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { OrganizationData } from '../entity/organization.entity';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class OrganizationRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(OrganizationData)
|
|
10
|
+
private readonly organizationRepository: Repository<OrganizationData>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findOrganizationById(id: number): Promise<OrganizationData | null> {
|
|
14
|
+
return await this.organizationRepository.findOne({
|
|
15
|
+
where: { id },
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -298,10 +298,9 @@ export class FilterService {
|
|
|
298
298
|
},
|
|
299
299
|
);
|
|
300
300
|
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
qb.addOrderBy('e.created_date', 'DESC');
|
|
305
304
|
|
|
306
305
|
// Pagination
|
|
307
306
|
const page = dto.page && dto.page > 0 ? dto.page : 1;
|
|
@@ -49,11 +49,13 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
49
49
|
entityMaster,
|
|
50
50
|
loggedInUser,
|
|
51
51
|
);
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
console.log('Validation Errors:', validationErrors); // Debug log
|
|
53
|
+
if (validationErrors && validationErrors.length > 0) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
54
56
|
message: 'Validation failed',
|
|
55
57
|
errors: validationErrors,
|
|
56
|
-
}
|
|
58
|
+
};
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
const repo = manager
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
|
2
|
+
import { OrganizationRepository } from 'src/module/enterprise/repository/organization.repository';
|
|
2
3
|
import { EncryptUtilService } from '../../../utils/service/encryptUtil.service';
|
|
4
|
+
import { Role } from '../entity/role.entity';
|
|
5
|
+
import { UserRoleMapping } from '../entity/user-role-mapping.entity';
|
|
3
6
|
import { UserData } from '../entity/user.entity';
|
|
4
7
|
import { UserSessionService } from './user-session.service';
|
|
5
8
|
import { UserService } from './user.service';
|
|
6
9
|
import { ConfigService } from '@nestjs/config';
|
|
7
10
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
8
|
-
import { UserRoleMapping } from '../entity/user-role-mapping.entity';
|
|
9
11
|
import { DataSource, Repository } from 'typeorm';
|
|
10
|
-
import { Role } from '../entity/role.entity';
|
|
11
12
|
|
|
12
13
|
@Injectable()
|
|
13
14
|
export class LoginService {
|
|
@@ -20,6 +21,7 @@ export class LoginService {
|
|
|
20
21
|
@InjectRepository(Role)
|
|
21
22
|
private readonly roleRepo: Repository<Role>,
|
|
22
23
|
private readonly dataSource: DataSource,
|
|
24
|
+
private readonly organizationRepository: OrganizationRepository,
|
|
23
25
|
) {}
|
|
24
26
|
|
|
25
27
|
masterKey: string = this.configService.get('MASTER_KEY') || '';
|
|
@@ -27,7 +29,7 @@ export class LoginService {
|
|
|
27
29
|
|
|
28
30
|
async login(email: string, password: string) {
|
|
29
31
|
const user = await this.userService.findByEmailId(email);
|
|
30
|
-
|
|
32
|
+
|
|
31
33
|
if (!user) {
|
|
32
34
|
return {
|
|
33
35
|
success: false,
|
|
@@ -35,21 +37,24 @@ export class LoginService {
|
|
|
35
37
|
type: 'email',
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
const userOrgData = await this.organizationRepository.findOrganizationById(
|
|
41
|
+
user.organization_id,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (user.status !== 'ACTIVE' || userOrgData?.status !== 'ACTIVE') {
|
|
40
45
|
return {
|
|
41
46
|
success: false,
|
|
42
47
|
message: 'Your account is inactive.',
|
|
43
48
|
type: 'email',
|
|
44
49
|
};
|
|
45
50
|
}
|
|
46
|
-
|
|
51
|
+
|
|
47
52
|
const encryptedPassword = EncryptUtilService.encryptGCM(
|
|
48
53
|
password,
|
|
49
54
|
this.masterKey,
|
|
50
55
|
this.masterIv,
|
|
51
56
|
);
|
|
52
|
-
|
|
57
|
+
|
|
53
58
|
if (encryptedPassword !== user.password) {
|
|
54
59
|
return {
|
|
55
60
|
success: false,
|
|
@@ -57,38 +62,44 @@ export class LoginService {
|
|
|
57
62
|
type: 'password',
|
|
58
63
|
};
|
|
59
64
|
}
|
|
60
|
-
|
|
65
|
+
|
|
61
66
|
let appcode = user.last_app_access || 'ADM';
|
|
62
|
-
|
|
67
|
+
|
|
63
68
|
if (!user.last_app_access) {
|
|
64
69
|
await this.userService.setDefaultLastAccess(user.id, appcode);
|
|
65
70
|
}
|
|
66
|
-
|
|
71
|
+
|
|
67
72
|
const roleMappings = await this.userRoleMappingRepository.find({
|
|
68
73
|
where: { user_id: user.id, appcode },
|
|
69
74
|
});
|
|
70
|
-
|
|
75
|
+
|
|
71
76
|
if (!roleMappings.length) {
|
|
72
|
-
throw new BadRequestException(
|
|
77
|
+
throw new BadRequestException(
|
|
78
|
+
'User does not have any access mapped for this app.',
|
|
79
|
+
);
|
|
73
80
|
}
|
|
74
|
-
|
|
81
|
+
|
|
75
82
|
const defaultAccess = await this.getDefaultAccess(user, roleMappings);
|
|
76
|
-
|
|
83
|
+
|
|
77
84
|
await this.userService.setLastLevelTypeAndId(
|
|
78
85
|
user.id,
|
|
79
86
|
defaultAccess.level_type,
|
|
80
87
|
defaultAccess.level_id,
|
|
81
88
|
);
|
|
82
|
-
|
|
83
|
-
const token = await this.userSessionService.createSession(
|
|
84
|
-
|
|
89
|
+
|
|
90
|
+
const token = await this.userSessionService.createSession(
|
|
91
|
+
user,
|
|
92
|
+
appcode,
|
|
93
|
+
defaultAccess,
|
|
94
|
+
);
|
|
95
|
+
|
|
85
96
|
if (user.is_firstlogin === 1) {
|
|
86
97
|
user.invitation_status = 'ACCEPTED';
|
|
87
98
|
user.is_firstlogin = 0;
|
|
88
99
|
const { password, ...userWithoutPassword } = user;
|
|
89
100
|
await this.userService.updateEntity(userWithoutPassword, user);
|
|
90
101
|
}
|
|
91
|
-
|
|
102
|
+
|
|
92
103
|
return {
|
|
93
104
|
success: true,
|
|
94
105
|
accessToken: token,
|
|
@@ -97,35 +108,37 @@ export class LoginService {
|
|
|
97
108
|
level_id: defaultAccess.level_id,
|
|
98
109
|
};
|
|
99
110
|
}
|
|
100
|
-
|
|
111
|
+
|
|
101
112
|
private async getDefaultAccess(
|
|
102
113
|
user: any,
|
|
103
114
|
roleMappings: any[],
|
|
104
115
|
): Promise<{ level_type: string; level_id: string }> {
|
|
105
|
-
const orgAccess = roleMappings.find(r => r.level_type === 'ORG');
|
|
106
|
-
const brnAccesses = roleMappings.filter(r => r.level_type === 'BRN');
|
|
107
|
-
const schAccesses = roleMappings.filter(r => r.level_type === 'SCH');
|
|
108
|
-
|
|
116
|
+
const orgAccess = roleMappings.find((r) => r.level_type === 'ORG');
|
|
117
|
+
const brnAccesses = roleMappings.filter((r) => r.level_type === 'BRN');
|
|
118
|
+
const schAccesses = roleMappings.filter((r) => r.level_type === 'SCH');
|
|
119
|
+
|
|
109
120
|
const validURM = roleMappings.find(
|
|
110
|
-
r =>
|
|
121
|
+
(r) =>
|
|
122
|
+
r.level_type === user.last_level_type &&
|
|
123
|
+
r.level_id === user.last_level_id,
|
|
111
124
|
);
|
|
112
|
-
|
|
125
|
+
|
|
113
126
|
if (user.last_level_type && user.last_level_id && validURM) {
|
|
114
127
|
return { level_type: user.last_level_type, level_id: user.last_level_id };
|
|
115
128
|
}
|
|
116
|
-
|
|
129
|
+
|
|
117
130
|
if (orgAccess) {
|
|
118
131
|
return { level_type: 'ORG', level_id: orgAccess.level_id };
|
|
119
132
|
}
|
|
120
|
-
|
|
133
|
+
|
|
121
134
|
if (brnAccesses.length) {
|
|
122
135
|
const brandId = brnAccesses[0].level_id;
|
|
123
|
-
|
|
136
|
+
|
|
124
137
|
const rows = await this.dataSource.query(
|
|
125
138
|
`SELECT id FROM cr_school WHERE brand_id = ? ORDER BY id ASC LIMIT 1`,
|
|
126
139
|
[brandId],
|
|
127
140
|
);
|
|
128
|
-
|
|
141
|
+
|
|
129
142
|
if (rows.length) {
|
|
130
143
|
return { level_type: 'SCH', level_id: rows[0].id };
|
|
131
144
|
} else {
|
|
@@ -134,16 +147,15 @@ export class LoginService {
|
|
|
134
147
|
);
|
|
135
148
|
}
|
|
136
149
|
}
|
|
137
|
-
|
|
150
|
+
|
|
138
151
|
if (schAccesses.length) {
|
|
139
152
|
return { level_type: 'SCH', level_id: schAccesses[0].level_id };
|
|
140
153
|
}
|
|
141
|
-
|
|
154
|
+
|
|
142
155
|
throw new BadRequestException(
|
|
143
156
|
'User does not have ORG, BRN, or SCH access for this app.',
|
|
144
157
|
);
|
|
145
158
|
}
|
|
146
|
-
|
|
147
159
|
|
|
148
160
|
async loginWithGoogle(email: string, name) {
|
|
149
161
|
let user = await this.userService.findByEmailId(email);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
1
|
+
import { forwardRef, Module } from '@nestjs/common';
|
|
2
2
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
3
|
import { UserData } from './entity/user.entity';
|
|
4
4
|
import { UserService } from './service/user.service';
|
|
@@ -20,6 +20,7 @@ import { UserRoleMappingRepository } from './repository/user-role-mapping.reposi
|
|
|
20
20
|
import { UserRoleMappingService } from './service/user-role-mapping.service';
|
|
21
21
|
import { RoleRepository } from './repository/role.repository';
|
|
22
22
|
import { ModuleAccess } from '../module/entity/module-access.entity';
|
|
23
|
+
import { EnterpriseModule } from '../enterprise/enterprise.module';
|
|
23
24
|
|
|
24
25
|
@Module({
|
|
25
26
|
imports: [
|
|
@@ -30,9 +31,10 @@ import { ModuleAccess } from '../module/entity/module-access.entity';
|
|
|
30
31
|
UserRoleMapping,
|
|
31
32
|
ModuleAccess,
|
|
32
33
|
]),
|
|
34
|
+
forwardRef(() => AuthModule),
|
|
33
35
|
EntityModule,
|
|
34
36
|
UtilsModule,
|
|
35
|
-
|
|
37
|
+
forwardRef(() => EnterpriseModule),
|
|
36
38
|
],
|
|
37
39
|
providers: [
|
|
38
40
|
{ provide: 'UserService', useClass: UserService },
|