rez_core 1.0.80 → 1.0.83
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/meta/service/entity-list.service.js +1 -1
- package/dist/module/meta/service/entity-list.service.js.map +1 -1
- package/dist/module/meta/service/entity-validation.service.js +10 -5
- package/dist/module/meta/service/entity-validation.service.js.map +1 -1
- package/dist/module/user/repository/role.repository.d.ts +4 -1
- package/dist/module/user/repository/role.repository.js +8 -3
- package/dist/module/user/repository/role.repository.js.map +1 -1
- package/dist/module/user/repository/user.repository.d.ts +1 -1
- package/dist/module/user/repository/user.repository.js +10 -10
- package/dist/module/user/repository/user.repository.js.map +1 -1
- package/dist/module/user/service/role.service.js +2 -2
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/service/user.service.js +16 -8
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/service/entity-list.service.ts +1 -1
- package/src/module/meta/service/entity-validation.service.ts +16 -5
- package/src/module/user/repository/role.repository.ts +15 -5
- package/src/module/user/repository/user.repository.ts +12 -11
- package/src/module/user/service/role.service.ts +2 -2
- package/src/module/user/service/user.service.ts +42 -14
package/package.json
CHANGED
|
@@ -56,13 +56,23 @@ export class EntityValidationService {
|
|
|
56
56
|
const value = entityData[attr.attribute_key];
|
|
57
57
|
|
|
58
58
|
if (this.hasValidValue(value)) {
|
|
59
|
-
|
|
59
|
+
let qb = this.dataSource
|
|
60
60
|
.createQueryBuilder()
|
|
61
|
-
.select(
|
|
61
|
+
.select('*')
|
|
62
62
|
.from(db_table_name, db_table_name)
|
|
63
|
-
.where(`${db_table_name}.${attr.attribute_key} = :value`, { value })
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
.where(`${db_table_name}.${attr.attribute_key} = :value`, { value });
|
|
64
|
+
|
|
65
|
+
// Add AND condition for organization_id if present
|
|
66
|
+
const orgId = entityData.organization_id;
|
|
67
|
+
|
|
68
|
+
if (orgId !== undefined && orgId !== null) {
|
|
69
|
+
qb = qb.andWhere(`${db_table_name}.organization_id = :organization_id`, {
|
|
70
|
+
organization_id: orgId,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const existing = await qb.limit(1).getRawOne();
|
|
66
76
|
|
|
67
77
|
if (existing) {
|
|
68
78
|
errors.push({
|
|
@@ -76,6 +86,7 @@ export class EntityValidationService {
|
|
|
76
86
|
return errors;
|
|
77
87
|
}
|
|
78
88
|
|
|
89
|
+
|
|
79
90
|
/**
|
|
80
91
|
* Validates both required and unique fields for a given entity type.
|
|
81
92
|
*/
|
|
@@ -17,16 +17,26 @@ export class RoleRepository {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
public async isRoleNameExists(
|
|
20
|
+
public async isRoleNameExists(
|
|
21
|
+
name: string,
|
|
22
|
+
options?: { excludeRoleId?: number; organization_id?: number }
|
|
23
|
+
): Promise<boolean> {
|
|
21
24
|
const query = this.roleRepo
|
|
22
25
|
.createQueryBuilder('role')
|
|
23
26
|
.where('role.name = :name', { name });
|
|
24
|
-
|
|
25
|
-
if (excludeRoleId) {
|
|
26
|
-
query.andWhere('role.id != :excludeRoleId', { excludeRoleId });
|
|
27
|
+
|
|
28
|
+
if (options?.excludeRoleId) {
|
|
29
|
+
query.andWhere('role.id != :excludeRoleId', { excludeRoleId: options.excludeRoleId });
|
|
27
30
|
}
|
|
28
|
-
|
|
31
|
+
|
|
32
|
+
if (options?.organization_id !== undefined) {
|
|
33
|
+
query.andWhere('role.organization_id = :organization_id', {
|
|
34
|
+
organization_id: options.organization_id,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
const existingRole = await query.getOne();
|
|
30
39
|
return !!existingRole;
|
|
31
40
|
}
|
|
41
|
+
|
|
32
42
|
}
|
|
@@ -9,22 +9,23 @@ export class UserRepository {
|
|
|
9
9
|
@InjectRepository(UserData) private userRepository: Repository<UserData>,
|
|
10
10
|
) {}
|
|
11
11
|
|
|
12
|
-
async findByEmailId(email: string): Promise<UserData | null> {
|
|
13
|
-
if (email) {
|
|
14
|
-
return this.userRepository.findOne({ where: { email_id: email } });
|
|
15
|
-
}
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
async findById(userId: number): Promise<UserData | null> {
|
|
20
13
|
return this.userRepository.findOne({ where: { id: userId } });
|
|
21
14
|
}
|
|
15
|
+
async findByEmailId(email: string): Promise<UserData | null> {
|
|
16
|
+
if (!email) return null;
|
|
17
|
+
|
|
18
|
+
const where: any = { email_id: email };
|
|
19
|
+
|
|
20
|
+
return this.userRepository.findOne({ where });
|
|
21
|
+
}
|
|
22
22
|
|
|
23
23
|
async findByMobile(mobile: string): Promise<UserData | null> {
|
|
24
|
-
if (mobile)
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
24
|
+
if (!mobile) return null;
|
|
25
|
+
|
|
26
|
+
const where: any = { mobile: mobile };
|
|
27
|
+
|
|
28
|
+
return this.userRepository.findOne({ where });
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
async saveUser(user: UserData): Promise<UserData> {
|
|
@@ -27,7 +27,7 @@ export class RoleService extends EntityServiceImpl {
|
|
|
27
27
|
): Promise<BaseEntity> {
|
|
28
28
|
let role = entityData as Role;
|
|
29
29
|
|
|
30
|
-
if (await this.roleRepository.isRoleNameExists(role.name)) {
|
|
30
|
+
if (await this.roleRepository.isRoleNameExists(role.name,{organization_id:entityData.organization_id})) {
|
|
31
31
|
throw new BadRequestException('Role name already exists.');
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -98,7 +98,7 @@ export class RoleService extends EntityServiceImpl {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
if (
|
|
101
|
-
await this.roleRepository.isRoleNameExists(entityData.name, entityData.id)
|
|
101
|
+
await this.roleRepository.isRoleNameExists(entityData.name, {excludeRoleId:entityData.id})
|
|
102
102
|
) {
|
|
103
103
|
throw new BadRequestException('Role name already exists.');
|
|
104
104
|
}
|
|
@@ -38,13 +38,15 @@ export class UserService extends EntityServiceImpl {
|
|
|
38
38
|
): Promise<BaseEntity> {
|
|
39
39
|
let userData = entityData as CreateUserDto;
|
|
40
40
|
let existingUser = await this.userRepository.findByEmailId(
|
|
41
|
-
userData.email_id
|
|
41
|
+
userData.email_id
|
|
42
42
|
);
|
|
43
43
|
if (existingUser) {
|
|
44
44
|
throw new BadRequestException('User already exists');
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
existingUser = await this.userRepository.findByMobile(
|
|
47
|
+
existingUser = await this.userRepository.findByMobile(
|
|
48
|
+
userData.mobile
|
|
49
|
+
);
|
|
48
50
|
if (existingUser) {
|
|
49
51
|
throw new BadRequestException('User already exists');
|
|
50
52
|
}
|
|
@@ -113,37 +115,63 @@ export class UserService extends EntityServiceImpl {
|
|
|
113
115
|
entityData: BaseEntity,
|
|
114
116
|
loggedInUserData: UserData,
|
|
115
117
|
): Promise<BaseEntity> {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
const userDto = entityData as UpdateUserDto;
|
|
119
|
+
|
|
120
|
+
// Fetch the current user data from DB to get the existing encrypted password
|
|
121
|
+
const existingUser = await this.userRepository.findById(entityData.id);
|
|
122
|
+
|
|
123
|
+
if (!existingUser) {
|
|
124
|
+
throw new BadRequestException('User not found');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// If password is being updated, check if it's the same as existing one
|
|
118
128
|
if (userDto.password) {
|
|
119
|
-
const
|
|
129
|
+
const decryptedPassword = EncryptUtilService.decryptGCM(
|
|
130
|
+
existingUser.password,
|
|
131
|
+
this.masterKey,
|
|
132
|
+
this.masterIv,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (decryptedPassword === userDto.password) {
|
|
136
|
+
throw new BadRequestException(
|
|
137
|
+
'New password cannot be the same as the current password',
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Encrypt new password
|
|
142
|
+
const encryptedPassword = EncryptUtilService.encryptGCM(
|
|
120
143
|
userDto.password,
|
|
121
144
|
this.masterKey,
|
|
122
145
|
this.masterIv,
|
|
123
146
|
);
|
|
124
|
-
userDto.password =
|
|
147
|
+
userDto.password = encryptedPassword;
|
|
125
148
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
149
|
+
|
|
150
|
+
const userData = plainToInstance(UserData, userDto);
|
|
151
|
+
|
|
152
|
+
const savedData = await super.updateEntity(userData, loggedInUserData);
|
|
153
|
+
|
|
154
|
+
// Update roles if provided
|
|
129
155
|
if (userDto.roles) {
|
|
130
|
-
|
|
131
|
-
for (const role
|
|
132
|
-
|
|
156
|
+
await this.userRoleMappingService.deleteByUserId(savedData.id); // prevent duplicates
|
|
157
|
+
for (const role of userDto.roles) {
|
|
158
|
+
const userRoleMapping = new UserRoleMapping(
|
|
133
159
|
savedData.id,
|
|
134
|
-
Number(
|
|
160
|
+
Number(role),
|
|
135
161
|
);
|
|
136
162
|
await this.userRoleMappingService.assignUserRole(userRoleMapping);
|
|
137
163
|
}
|
|
138
164
|
}
|
|
165
|
+
|
|
139
166
|
return savedData;
|
|
140
167
|
}
|
|
168
|
+
|
|
141
169
|
|
|
142
170
|
async findByEmailId(email_id: string): Promise<UserData | null> {
|
|
143
171
|
return await this.userRepository.findByEmailId(email_id);
|
|
144
172
|
}
|
|
145
173
|
|
|
146
|
-
async findByMobile(mobile: string) {
|
|
174
|
+
async findByMobile(mobile: string): Promise<UserData | null> {
|
|
147
175
|
return await this.userRepository.findByMobile(mobile);
|
|
148
176
|
}
|
|
149
177
|
}
|