rez_core 1.0.95 → 1.0.97
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/auth/auth.module.js +8 -4
- package/dist/module/auth/auth.module.js.map +1 -1
- package/dist/module/master/service/master.service.js +20 -10
- package/dist/module/master/service/master.service.js.map +1 -1
- package/dist/module/meta/entity/entity-table-column.entity.d.ts +2 -0
- package/dist/module/meta/entity/entity-table-column.entity.js +13 -0
- package/dist/module/meta/entity/entity-table-column.entity.js.map +1 -1
- package/dist/module/user/repository/user.repository.d.ts +2 -2
- package/dist/module/user/repository/user.repository.js +9 -3
- package/dist/module/user/repository/user.repository.js.map +1 -1
- package/dist/module/user/service/user-session.service.d.ts +4 -2
- package/dist/module/user/service/user-session.service.js +8 -4
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/module/user/service/user.service.js +3 -3
- 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/auth/auth.module.ts +12 -4
- package/src/module/master/service/master.service.ts +24 -14
- package/src/module/meta/entity/entity-table-column.entity.ts +11 -0
- package/src/module/user/repository/user.repository.ts +17 -3
- package/src/module/user/service/user-session.service.ts +8 -3
- package/src/module/user/service/user.service.ts +15 -17
- package/src/resources/dev.properties.yaml +7 -0
- package/src/resources/uat.properties.yaml +2 -1
package/package.json
CHANGED
|
@@ -18,11 +18,19 @@ import { RolesGuard } from './guards/role.guard';
|
|
|
18
18
|
JwtModule.registerAsync({
|
|
19
19
|
imports: [ConfigModule],
|
|
20
20
|
inject: [ConfigService],
|
|
21
|
-
useFactory: async (configService: ConfigService) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
useFactory: async (configService: ConfigService) => {
|
|
22
|
+
const expiryInHours = parseFloat(
|
|
23
|
+
configService.get('TOKEN_EXPIRY') || '1',
|
|
24
|
+
);
|
|
25
|
+
const expiryInSeconds = expiryInHours * 60 * 60;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
secret: configService.get('SECRET_KEY'),
|
|
29
|
+
signOptions: { expiresIn: expiryInSeconds },
|
|
30
|
+
};
|
|
31
|
+
},
|
|
25
32
|
}),
|
|
33
|
+
|
|
26
34
|
TypeOrmModule.forFeature([UserSession]),
|
|
27
35
|
],
|
|
28
36
|
providers: [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { Brackets, EntityManager } from 'typeorm';
|
|
3
3
|
import { ExcelUtil } from 'src/utils/service/excelUtil.service';
|
|
4
4
|
import { EntityMasterService } from '../../meta/service/entity-master.service';
|
|
5
5
|
import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
|
|
@@ -97,6 +97,10 @@ export class MasterService {
|
|
|
97
97
|
table: 'cr_organization',
|
|
98
98
|
unique_fields: ['code'],
|
|
99
99
|
},
|
|
100
|
+
{
|
|
101
|
+
table: 'eth_academic_year',
|
|
102
|
+
unique_fields: ['code'],
|
|
103
|
+
},
|
|
100
104
|
];
|
|
101
105
|
private readonly dataSequence = [
|
|
102
106
|
{
|
|
@@ -357,29 +361,35 @@ export class MasterService {
|
|
|
357
361
|
const qb = this.entityManager
|
|
358
362
|
.createQueryBuilder()
|
|
359
363
|
.select('*')
|
|
360
|
-
.from(entityMaster.db_table_name, entityMaster.db_table_name)
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
364
|
+
.from(entityMaster.db_table_name, entityMaster.db_table_name)
|
|
365
|
+
.where(
|
|
366
|
+
new Brackets((qbOr) => {
|
|
367
|
+
uniqueFields.forEach((field, index) => {
|
|
368
|
+
const condition = `${entityMaster.db_table_name}.${field} = :val${index}`;
|
|
369
|
+
const param = { [`val${index}`]: row[field] };
|
|
370
|
+
if (index === 0) {
|
|
371
|
+
qbOr.where(condition, param);
|
|
372
|
+
} else {
|
|
373
|
+
qbOr.orWhere(condition, param);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}),
|
|
377
|
+
)
|
|
378
|
+
.andWhere(`${entityMaster.db_table_name}.organization_id = :orgId`, {
|
|
379
|
+
orgId: loggedInUser.organization_id,
|
|
380
|
+
});
|
|
373
381
|
|
|
374
382
|
const existing = await qb.limit(1).getRawOne();
|
|
375
383
|
|
|
376
384
|
row.entity_type = entityType;
|
|
385
|
+
row.organization_id = loggedInUser.organization_id;
|
|
377
386
|
|
|
378
387
|
if (existing) {
|
|
379
388
|
if (duplicateHandling === 'skip_duplicates') {
|
|
380
389
|
continue; // Skip this row
|
|
381
390
|
} else if (duplicateHandling === 'overwrite_items') {
|
|
382
391
|
row.id = existing.id;
|
|
392
|
+
|
|
383
393
|
await entityService.updateEntity(row, loggedInUser);
|
|
384
394
|
}
|
|
385
395
|
} else {
|
|
@@ -39,6 +39,17 @@ export class EntityTableColumn extends BaseEntity {
|
|
|
39
39
|
@Column({ name: 'data_type', nullable: true })
|
|
40
40
|
data_type: string;
|
|
41
41
|
|
|
42
|
+
@Column({
|
|
43
|
+
name: 'data_source_type',
|
|
44
|
+
type: 'varchar',
|
|
45
|
+
nullable: true,
|
|
46
|
+
length: 50,
|
|
47
|
+
})
|
|
48
|
+
data_source_type: string;
|
|
49
|
+
|
|
50
|
+
@Column({ name: 'datasource_list', type: 'varchar', nullable: true })
|
|
51
|
+
datasource_list: string;
|
|
52
|
+
|
|
42
53
|
@Column({ name: 'visible', nullable: true })
|
|
43
54
|
visible: string;
|
|
44
55
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OrganizationData } from './../../enterprise/entity/organization.entity';
|
|
1
2
|
import { Repository } from 'typeorm';
|
|
2
3
|
import { UserData } from '../entity/user.entity';
|
|
3
4
|
import { Injectable } from '@nestjs/common';
|
|
@@ -12,18 +13,31 @@ export class UserRepository {
|
|
|
12
13
|
async findById(userId: number): Promise<UserData | null> {
|
|
13
14
|
return this.userRepository.findOne({ where: { id: userId } });
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
|
|
17
|
+
async findByEmailId(
|
|
18
|
+
email: string,
|
|
19
|
+
organization_id?: number,
|
|
20
|
+
): Promise<UserData | null> {
|
|
16
21
|
if (!email) return null;
|
|
17
22
|
|
|
18
23
|
const where: any = { email_id: email };
|
|
24
|
+
if (organization_id !== undefined) {
|
|
25
|
+
where.organization_id = organization_id;
|
|
26
|
+
}
|
|
19
27
|
|
|
20
28
|
return this.userRepository.findOne({ where });
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
async findByMobile(
|
|
31
|
+
async findByMobile(
|
|
32
|
+
mobile: string,
|
|
33
|
+
organization_id?: number,
|
|
34
|
+
): Promise<UserData | null> {
|
|
24
35
|
if (!mobile) return null;
|
|
25
36
|
|
|
26
|
-
const where: any = { mobile
|
|
37
|
+
const where: any = { mobile };
|
|
38
|
+
if (organization_id !== undefined) {
|
|
39
|
+
where.organization_id = organization_id;
|
|
40
|
+
}
|
|
27
41
|
|
|
28
42
|
return this.userRepository.findOne({ where });
|
|
29
43
|
}
|
|
@@ -2,7 +2,8 @@ import { UserSession } from '../entity/user-session.entity';
|
|
|
2
2
|
import { ClockIDGenService } from '../../../utils/service/clockIDGenUtil.service';
|
|
3
3
|
import { Injectable } from '@nestjs/common';
|
|
4
4
|
import { UserSessionRepository } from '../repository/userSession.repository';
|
|
5
|
-
import { JwtAuthService } from '
|
|
5
|
+
import { JwtAuthService } from 'src/module/auth/services/jwt.service';
|
|
6
|
+
import { ConfigService } from '@nestjs/config';
|
|
6
7
|
|
|
7
8
|
@Injectable()
|
|
8
9
|
export class UserSessionService {
|
|
@@ -10,6 +11,7 @@ export class UserSessionService {
|
|
|
10
11
|
private readonly userSessionRepository: UserSessionRepository,
|
|
11
12
|
private readonly jwtAuthService: JwtAuthService,
|
|
12
13
|
private readonly clockIDGenService: ClockIDGenService,
|
|
14
|
+
private configService: ConfigService,
|
|
13
15
|
) {}
|
|
14
16
|
async createSession(user) {
|
|
15
17
|
const sessionToken = this.clockIDGenService.idGenerator('SES');
|
|
@@ -19,7 +21,10 @@ export class UserSessionService {
|
|
|
19
21
|
userSession.session_key = sessionToken;
|
|
20
22
|
userSession.is_session_loggedout = 0;
|
|
21
23
|
userSession.login_time = new Date();
|
|
22
|
-
|
|
24
|
+
const expiryTokenInHours = this.configService.get('TOKEN_EXPIRY') || 1;
|
|
25
|
+
userSession.expiry_date = new Date(
|
|
26
|
+
Date.now() + expiryTokenInHours * 60 * 60 * 1000,
|
|
27
|
+
);
|
|
23
28
|
|
|
24
29
|
await this.userSessionRepository.saveSession(userSession);
|
|
25
30
|
|
|
@@ -29,7 +34,7 @@ export class UserSessionService {
|
|
|
29
34
|
userSession.access_token = accessToken;
|
|
30
35
|
await this.userSessionRepository.saveSession(userSession);
|
|
31
36
|
|
|
32
|
-
return
|
|
37
|
+
return accessToken;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
async findBySessionKey(sessionKey: string): Promise<UserSession | null> {
|
|
@@ -38,14 +38,16 @@ 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
|
+
loggedInUser?.organization_id,
|
|
42
43
|
);
|
|
43
44
|
if (existingUser) {
|
|
44
45
|
throw new BadRequestException('User already exists');
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
existingUser = await this.userRepository.findByMobile(
|
|
48
|
-
userData.mobile
|
|
49
|
+
userData.mobile,
|
|
50
|
+
loggedInUser?.organization_id,
|
|
49
51
|
);
|
|
50
52
|
if (existingUser) {
|
|
51
53
|
throw new BadRequestException('User already exists');
|
|
@@ -62,7 +64,7 @@ export class UserService extends EntityServiceImpl {
|
|
|
62
64
|
);
|
|
63
65
|
} else {
|
|
64
66
|
password = EncryptUtilService.encryptGCM(
|
|
65
|
-
|
|
67
|
+
'Admin@123',
|
|
66
68
|
this.masterKey,
|
|
67
69
|
this.masterIv,
|
|
68
70
|
);
|
|
@@ -116,14 +118,14 @@ export class UserService extends EntityServiceImpl {
|
|
|
116
118
|
loggedInUserData: UserData,
|
|
117
119
|
): Promise<BaseEntity> {
|
|
118
120
|
const userDto = entityData as UpdateUserDto;
|
|
119
|
-
|
|
121
|
+
|
|
120
122
|
// Fetch the current user data from DB to get the existing encrypted password
|
|
121
123
|
const existingUser = await this.userRepository.findById(entityData.id);
|
|
122
|
-
|
|
124
|
+
|
|
123
125
|
if (!existingUser) {
|
|
124
126
|
throw new BadRequestException('User not found');
|
|
125
127
|
}
|
|
126
|
-
|
|
128
|
+
|
|
127
129
|
// If password is being updated, check if it's the same as existing one
|
|
128
130
|
if (userDto.password) {
|
|
129
131
|
const decryptedPassword = EncryptUtilService.decryptGCM(
|
|
@@ -131,13 +133,13 @@ export class UserService extends EntityServiceImpl {
|
|
|
131
133
|
this.masterKey,
|
|
132
134
|
this.masterIv,
|
|
133
135
|
);
|
|
134
|
-
|
|
136
|
+
|
|
135
137
|
if (decryptedPassword === userDto.password) {
|
|
136
138
|
throw new BadRequestException(
|
|
137
139
|
'New password cannot be the same as the current password',
|
|
138
140
|
);
|
|
139
141
|
}
|
|
140
|
-
|
|
142
|
+
|
|
141
143
|
// Encrypt new password
|
|
142
144
|
const encryptedPassword = EncryptUtilService.encryptGCM(
|
|
143
145
|
userDto.password,
|
|
@@ -146,26 +148,22 @@ export class UserService extends EntityServiceImpl {
|
|
|
146
148
|
);
|
|
147
149
|
userDto.password = encryptedPassword;
|
|
148
150
|
}
|
|
149
|
-
|
|
151
|
+
|
|
150
152
|
const userData = plainToInstance(UserData, userDto);
|
|
151
|
-
|
|
153
|
+
|
|
152
154
|
const savedData = await super.updateEntity(userData, loggedInUserData);
|
|
153
|
-
|
|
155
|
+
|
|
154
156
|
// Update roles if provided
|
|
155
157
|
if (userDto.roles) {
|
|
156
158
|
await this.userRoleMappingService.deleteByUserId(savedData.id); // prevent duplicates
|
|
157
159
|
for (const role of userDto.roles) {
|
|
158
|
-
const userRoleMapping = new UserRoleMapping(
|
|
159
|
-
savedData.id,
|
|
160
|
-
Number(role),
|
|
161
|
-
);
|
|
160
|
+
const userRoleMapping = new UserRoleMapping(savedData.id, Number(role));
|
|
162
161
|
await this.userRoleMappingService.assignUserRole(userRoleMapping);
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
|
-
|
|
164
|
+
|
|
166
165
|
return savedData;
|
|
167
166
|
}
|
|
168
|
-
|
|
169
167
|
|
|
170
168
|
async findByEmailId(email_id: string): Promise<UserData | null> {
|
|
171
169
|
return await this.userRepository.findByEmailId(email_id);
|
|
@@ -14,3 +14,10 @@ OTP_EXPIRY: "10"
|
|
|
14
14
|
OTP_LENGTH: "6"
|
|
15
15
|
VERIFY_OTP: "false"
|
|
16
16
|
DEFAULT_OTP: "123456"
|
|
17
|
+
TOKEN_EXPIRY: 1
|
|
18
|
+
# AWS:
|
|
19
|
+
# S3:
|
|
20
|
+
# AWS_ACCESS_KEY_ID: "AKIAYYKIBDDSQF3KILGE"
|
|
21
|
+
# AWS_SECRET_KEY: "PPDMAeO2mVUY1w2f46n/dlt5l9+7NY7E9twJb9LU"
|
|
22
|
+
# AWS_REGION: "ap-south-1"
|
|
23
|
+
# BUCKET_NAME: "testether"
|