rez_core 2.0.2 → 2.0.4
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/entity/app-master.entity.d.ts +5 -0
- package/dist/module/meta/entity/app-master.entity.js +30 -0
- package/dist/module/meta/entity/app-master.entity.js.map +1 -0
- package/dist/module/meta/entity/user-app-mapping.entity.d.ts +7 -0
- package/dist/module/meta/entity/user-app-mapping.entity.js +41 -0
- package/dist/module/meta/entity/user-app-mapping.entity.js.map +1 -0
- package/dist/module/meta/entity.module.js +9 -1
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/meta/repository/user-app-mapping.repository.d.ts +8 -0
- package/dist/module/meta/repository/user-app-mapping.repository.js +43 -0
- package/dist/module/meta/repository/user-app-mapping.repository.js.map +1 -0
- package/dist/module/meta/service/entity-list.service.js +1 -4
- package/dist/module/meta/service/entity-list.service.js.map +1 -1
- package/dist/module/meta/service/entity-service-impl.service.js +2 -2
- package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
- package/dist/module/meta/service/user-app-mapping.service.d.ts +7 -0
- package/dist/module/meta/service/user-app-mapping.service.js +31 -0
- package/dist/module/meta/service/user-app-mapping.service.js.map +1 -0
- package/dist/module/user/entity/user-role-mapping.entity.js +1 -1
- package/dist/module/user/entity/user-role-mapping.entity.js.map +1 -1
- package/dist/module/user/service/login.service.d.ts +3 -1
- package/dist/module/user/service/login.service.js +11 -4
- 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 +2 -2
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/module/user/service/user.service.d.ts +5 -1
- package/dist/module/user/service/user.service.js +21 -2
- 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/entity/app-master.entity.ts +13 -0
- package/src/module/meta/entity/user-app-mapping.entity.ts +21 -0
- package/src/module/meta/entity.module.ts +10 -1
- package/src/module/meta/repository/user-app-mapping.repository.ts +29 -0
- package/src/module/meta/service/entity-list.service.ts +4 -4
- package/src/module/meta/service/entity-service-impl.service.ts +3 -3
- package/src/module/meta/service/user-app-mapping.service.ts +17 -0
- package/src/module/user/entity/user-role-mapping.entity.ts +2 -2
- package/src/module/user/service/login.service.ts +23 -3
- package/src/module/user/service/user-session.service.ts +2 -2
- package/src/module/user/service/user.service.ts +73 -6
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
+
import { BaseEntity } from './base-entity.entity';
|
|
3
|
+
|
|
4
|
+
@Entity({ name: 'cr_app_master' })
|
|
5
|
+
export class UserAppMapping extends BaseEntity {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.entity_type = 'APM';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@PrimaryGeneratedColumn()
|
|
12
|
+
id: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
@Entity({ name: 'cr_user_app_mapping' })
|
|
4
|
+
export class UserAppMapping {
|
|
5
|
+
constructor(user_id: number) {
|
|
6
|
+
this.user_id = user_id;
|
|
7
|
+
this.entity_type = 'UAP';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@PrimaryGeneratedColumn()
|
|
11
|
+
id: number;
|
|
12
|
+
|
|
13
|
+
@Column({ type: 'bigint', nullable: true })
|
|
14
|
+
user_id: number;
|
|
15
|
+
|
|
16
|
+
@Column({ type: 'varchar', nullable: true })
|
|
17
|
+
appcode: string;
|
|
18
|
+
|
|
19
|
+
@Column({ type: 'varchar' })
|
|
20
|
+
entity_type: string;
|
|
21
|
+
}
|
|
@@ -38,6 +38,9 @@ import { MetaController } from './controller/meta.controller';
|
|
|
38
38
|
import { EntityValidationService } from './service/entity-validation.service';
|
|
39
39
|
import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
40
40
|
import { FilterModule } from '../filter/filter.module';
|
|
41
|
+
import { UserAppMappingService } from './service/user-app-mapping.service';
|
|
42
|
+
import { UserAppMappingRepository } from './repository/user-app-mapping.repository';
|
|
43
|
+
import { UserAppMapping } from './entity/user-app-mapping.entity';
|
|
41
44
|
|
|
42
45
|
@Module({
|
|
43
46
|
imports: [
|
|
@@ -53,10 +56,12 @@ import { FilterModule } from '../filter/filter.module';
|
|
|
53
56
|
SchoolAddressEntity,
|
|
54
57
|
SectionMaster,
|
|
55
58
|
FieldGroup,
|
|
59
|
+
UserAppMapping,
|
|
56
60
|
]),
|
|
57
61
|
forwardRef(() => ListMasterModule),
|
|
58
62
|
forwardRef(() => FilterModule),
|
|
59
|
-
UtilsModule
|
|
63
|
+
UtilsModule,
|
|
64
|
+
],
|
|
60
65
|
providers: [
|
|
61
66
|
EntityMasterService,
|
|
62
67
|
EntityServiceImpl,
|
|
@@ -77,6 +82,8 @@ import { FilterModule } from '../filter/filter.module';
|
|
|
77
82
|
ViewMaterRespository,
|
|
78
83
|
EntityValidationService,
|
|
79
84
|
{ provide: 'ViewMasterService', useClass: ViewMasterService },
|
|
85
|
+
UserAppMappingService,
|
|
86
|
+
UserAppMappingRepository,
|
|
80
87
|
],
|
|
81
88
|
exports: [
|
|
82
89
|
EntityMasterService,
|
|
@@ -91,6 +98,8 @@ import { FilterModule } from '../filter/filter.module';
|
|
|
91
98
|
FieldGroupService,
|
|
92
99
|
'ViewMasterService',
|
|
93
100
|
AttributeMasterService,
|
|
101
|
+
UserAppMappingService,
|
|
102
|
+
UserAppMappingRepository,
|
|
94
103
|
],
|
|
95
104
|
controllers: [
|
|
96
105
|
EntityController,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
import { UserAppMapping } from '../entity/user-app-mapping.entity';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class UserAppMappingRepository {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(UserAppMapping)
|
|
10
|
+
private readonly userAppMappingRepository: Repository<UserAppMapping>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async save(userId: number, appCode: string): Promise<UserAppMapping | null> {
|
|
14
|
+
const mapping = this.userAppMappingRepository.create({
|
|
15
|
+
user_id: userId,
|
|
16
|
+
appcode: appCode,
|
|
17
|
+
});
|
|
18
|
+
return await this.userAppMappingRepository.save(mapping);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async findByUserIdAndAppCode(
|
|
22
|
+
userId: number,
|
|
23
|
+
appCode: string,
|
|
24
|
+
): Promise<UserAppMapping | null> {
|
|
25
|
+
return await this.userAppMappingRepository.findOne({
|
|
26
|
+
where: { user_id: userId, appcode: appCode },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -71,9 +71,9 @@ export class EntityListService {
|
|
|
71
71
|
appcode?: string,
|
|
72
72
|
) {
|
|
73
73
|
// Add appcode to filters if provided
|
|
74
|
-
if (appcode) {
|
|
75
|
-
|
|
76
|
-
}
|
|
74
|
+
// if (appcode) {
|
|
75
|
+
// filters = { ...filters, appcode };
|
|
76
|
+
// }
|
|
77
77
|
|
|
78
78
|
let query = this.getQuery(entityTable.data_source, null);
|
|
79
79
|
let whereClause = await this.getWhereClause(entityTable, filters);
|
|
@@ -95,7 +95,7 @@ export class EntityListService {
|
|
|
95
95
|
appcode?: string,
|
|
96
96
|
) {
|
|
97
97
|
let query = this.getQuery(entityTable.data_source, entityTable.tab_column);
|
|
98
|
-
let whereClause = await this.getWhereClause(entityTable, filters
|
|
98
|
+
let whereClause = await this.getWhereClause(entityTable, filters);
|
|
99
99
|
if (whereClause.query) {
|
|
100
100
|
query += whereClause.query;
|
|
101
101
|
}
|
|
@@ -35,7 +35,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
35
35
|
loggedInUser: UserData | null,
|
|
36
36
|
manager?: EntityManager | null,
|
|
37
37
|
appcode?: string,
|
|
38
|
-
){
|
|
38
|
+
) {
|
|
39
39
|
if (!entityData.entity_type) {
|
|
40
40
|
throw new BadRequestException(`EntityType is missing`);
|
|
41
41
|
}
|
|
@@ -49,10 +49,10 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
49
49
|
entityMaster,
|
|
50
50
|
);
|
|
51
51
|
if (validationErrors.length > 0) {
|
|
52
|
-
|
|
52
|
+
throw new BadRequestException({
|
|
53
53
|
success: false,
|
|
54
54
|
errors: validationErrors,
|
|
55
|
-
};
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const repo = manager
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { UserAppMappingRepository } from '../repository/user-app-mapping.repository';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class UserAppMappingService {
|
|
6
|
+
constructor(
|
|
7
|
+
private readonly userAppMappingRepository: UserAppMappingRepository,
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
async assignUserAppMapping(userId: number, appCode: string) {
|
|
11
|
+
return await this.userAppMappingRepository.save(userId, appCode);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getUserAppMappings(userId: number , appCode: string) {
|
|
15
|
+
return await this.userAppMappingRepository.findByUserIdAndAppCode(userId, appCode);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -12,7 +12,7 @@ export class UserRoleMapping {
|
|
|
12
12
|
@PrimaryGeneratedColumn()
|
|
13
13
|
id: number;
|
|
14
14
|
|
|
15
|
-
@Column({type: 'varchar'})
|
|
15
|
+
@Column({ type: 'varchar' })
|
|
16
16
|
entity_type: string;
|
|
17
17
|
|
|
18
18
|
@Column({ type: 'bigint', nullable: true })
|
|
@@ -24,6 +24,6 @@ export class UserRoleMapping {
|
|
|
24
24
|
@Column({ type: 'int', nullable: true })
|
|
25
25
|
is_default: number;
|
|
26
26
|
|
|
27
|
-
@Column({type: 'varchar'})
|
|
27
|
+
@Column({ type: 'varchar', nullable: true })
|
|
28
28
|
appcode: string;
|
|
29
29
|
}
|
|
@@ -4,6 +4,7 @@ import { UserData } from '../entity/user.entity';
|
|
|
4
4
|
import { UserSessionService } from './user-session.service';
|
|
5
5
|
import { UserService } from './user.service';
|
|
6
6
|
import { ConfigService } from '@nestjs/config';
|
|
7
|
+
import { UserAppMappingService } from 'src/module/meta/service/user-app-mapping.service';
|
|
7
8
|
|
|
8
9
|
@Injectable()
|
|
9
10
|
export class LoginService {
|
|
@@ -11,13 +12,20 @@ export class LoginService {
|
|
|
11
12
|
@Inject('UserService') private readonly userService: UserService,
|
|
12
13
|
private userSessionService: UserSessionService,
|
|
13
14
|
private configService: ConfigService,
|
|
15
|
+
private readonly userAppMappingService: UserAppMappingService,
|
|
14
16
|
) {}
|
|
15
17
|
|
|
16
18
|
masterKey: string = this.configService.get('MASTER_KEY') || '';
|
|
17
19
|
masterIv: string = this.configService.get('MASTER_IV') || '';
|
|
18
20
|
|
|
19
|
-
async login(
|
|
20
|
-
|
|
21
|
+
async login(
|
|
22
|
+
email: string,
|
|
23
|
+
password: string,
|
|
24
|
+
appcode: string,
|
|
25
|
+
organization_id,
|
|
26
|
+
) {
|
|
27
|
+
const user = await this.userService.findByEmailId(email, organization_id);
|
|
28
|
+
|
|
21
29
|
if (!user) {
|
|
22
30
|
return {
|
|
23
31
|
success: false,
|
|
@@ -26,6 +34,18 @@ export class LoginService {
|
|
|
26
34
|
};
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
const userAppMapping = await this.userAppMappingService.getUserAppMappings(
|
|
38
|
+
user.id,
|
|
39
|
+
appcode,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!userAppMapping) {
|
|
43
|
+
// If user is not mapped to the app, throw an error
|
|
44
|
+
throw new BadRequestException(
|
|
45
|
+
`User with email ${email} is not mapped to the app ${appcode}.`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
if (user.status !== 'ACTIVE') {
|
|
30
50
|
return {
|
|
31
51
|
success: false,
|
|
@@ -48,7 +68,7 @@ export class LoginService {
|
|
|
48
68
|
};
|
|
49
69
|
}
|
|
50
70
|
|
|
51
|
-
const token = await this.userSessionService.createSession(user);
|
|
71
|
+
const token = await this.userSessionService.createSession(user, appcode);
|
|
52
72
|
|
|
53
73
|
if (user.is_firstlogin === 1) {
|
|
54
74
|
user.invitation_status = 'ACCEPTED';
|
|
@@ -13,7 +13,7 @@ export class UserSessionService {
|
|
|
13
13
|
private readonly clockIDGenService: ClockIDGenService,
|
|
14
14
|
private configService: ConfigService,
|
|
15
15
|
) {}
|
|
16
|
-
async createSession(user) {
|
|
16
|
+
async createSession(user, appcode?: string) {
|
|
17
17
|
const sessionToken = this.clockIDGenService.idGenerator('SES');
|
|
18
18
|
|
|
19
19
|
const userSession: any = new UserSession();
|
|
@@ -28,7 +28,7 @@ export class UserSessionService {
|
|
|
28
28
|
|
|
29
29
|
await this.userSessionRepository.saveSession(userSession);
|
|
30
30
|
|
|
31
|
-
const payload = { userId: user.id, sessionToken, appcode:
|
|
31
|
+
const payload = { userId: user.id, sessionToken, appcode: appcode };
|
|
32
32
|
const accessToken = this.jwtAuthService.generateJwt(payload);
|
|
33
33
|
|
|
34
34
|
userSession.access_token = accessToken;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RoleService } from './role.service';
|
|
2
|
+
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
|
2
3
|
import { EntityServiceImpl } from '../../meta/service/entity-service-impl.service';
|
|
3
4
|
import { UserData } from '../entity/user.entity';
|
|
4
5
|
import { BaseEntity } from '../../meta/entity/base-entity.entity';
|
|
@@ -16,6 +17,8 @@ import { plainToInstance } from 'class-transformer';
|
|
|
16
17
|
import { EntityManager } from 'typeorm';
|
|
17
18
|
import { UpdateUserDto } from '../dto/update-user.dto';
|
|
18
19
|
import { ConfigService } from '@nestjs/config';
|
|
20
|
+
import { UserAppMappingService } from 'src/module/meta/service/user-app-mapping.service';
|
|
21
|
+
import { Role } from '../entity/role.entity';
|
|
19
22
|
|
|
20
23
|
@Injectable()
|
|
21
24
|
export class UserService extends EntityServiceImpl {
|
|
@@ -24,6 +27,8 @@ export class UserService extends EntityServiceImpl {
|
|
|
24
27
|
private userRoleMappingService: UserRoleMappingService,
|
|
25
28
|
private readonly clockIDGenService: ClockIDGenService,
|
|
26
29
|
private configService: ConfigService,
|
|
30
|
+
private readonly userAppMappingService: UserAppMappingService,
|
|
31
|
+
@Inject('RoleService') private readonly roleService: RoleService,
|
|
27
32
|
) {
|
|
28
33
|
super();
|
|
29
34
|
}
|
|
@@ -38,7 +43,7 @@ export class UserService extends EntityServiceImpl {
|
|
|
38
43
|
appcode?: string,
|
|
39
44
|
): Promise<BaseEntity> {
|
|
40
45
|
let userData = entityData as CreateUserDto;
|
|
41
|
-
if(appcode){
|
|
46
|
+
if (appcode) {
|
|
42
47
|
userData.appcode = appcode;
|
|
43
48
|
}
|
|
44
49
|
let existingUser = await this.userRepository.findByEmailId(
|
|
@@ -75,9 +80,12 @@ export class UserService extends EntityServiceImpl {
|
|
|
75
80
|
}
|
|
76
81
|
userData.password = password;
|
|
77
82
|
userData.is_firstlogin = 1;
|
|
83
|
+
userData.roles = [];
|
|
78
84
|
userData.invitation_status = 'SENT';
|
|
79
85
|
userData.status = STATUS_ACTIVE;
|
|
80
86
|
const savedData = await super.createEntity(userData, loggedInUser);
|
|
87
|
+
userData.roles.push('1');
|
|
88
|
+
userData.roles.push('2');
|
|
81
89
|
if (userData.roles) {
|
|
82
90
|
let roles = userData.roles;
|
|
83
91
|
await this.userRoleMappingService.deleteByUserId(userData.id);
|
|
@@ -86,10 +94,53 @@ export class UserService extends EntityServiceImpl {
|
|
|
86
94
|
savedData.id,
|
|
87
95
|
Number(roles[role]),
|
|
88
96
|
);
|
|
97
|
+
|
|
89
98
|
await this.userRoleMappingService.assignUserRole(userRoleMapping);
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
101
|
|
|
102
|
+
//Assign user app mapping as per user
|
|
103
|
+
|
|
104
|
+
const appcodedata = ['CRM', 'ERP'];
|
|
105
|
+
|
|
106
|
+
if (savedData.id) {
|
|
107
|
+
for (const app of appcodedata) {
|
|
108
|
+
await this.userAppMappingService.assignUserAppMapping(
|
|
109
|
+
savedData.id,
|
|
110
|
+
app,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// let role = new Role();
|
|
116
|
+
// role.organization_id = savedData.organization_id;
|
|
117
|
+
// role.enterprise_id = savedData.enterprise_id;
|
|
118
|
+
// role.is_system = 1;
|
|
119
|
+
// role.status = 'ACTIVE';
|
|
120
|
+
// role.name = 'School Admin';
|
|
121
|
+
|
|
122
|
+
// let defaultadminERP: string | undefined = 'ADMIN';
|
|
123
|
+
// let defaultadminCRM: string | undefined = 'ADMIN_CRM';
|
|
124
|
+
|
|
125
|
+
// if (defaultadminERP && defaultadminCRM) {
|
|
126
|
+
// let defaultAdminRoleERP = await this.roleService.findByCode(
|
|
127
|
+
// ENTITYTYPE_ROLE,
|
|
128
|
+
// defaultadminERP,
|
|
129
|
+
// );
|
|
130
|
+
// let defaultAdminRoleCRM = await this.roleService.findByCode(
|
|
131
|
+
// ENTITYTYPE_ROLE,
|
|
132
|
+
// defaultadminCRM,
|
|
133
|
+
// );
|
|
134
|
+
// if (defaultAdminRoleERP) {
|
|
135
|
+
// role.copy_from_role_id = defaultAdminRoleERP.id;
|
|
136
|
+
// let savedRoleERP = await this.roleService.createEntity(role, null);
|
|
137
|
+
// }
|
|
138
|
+
// if (defaultAdminRoleCRM) {
|
|
139
|
+
// role.copy_from_role_id = defaultAdminRoleCRM.id;
|
|
140
|
+
// let savedRoleCRM = await this.roleService.createEntity(role, null);
|
|
141
|
+
// }
|
|
142
|
+
// }
|
|
143
|
+
|
|
93
144
|
return savedData;
|
|
94
145
|
}
|
|
95
146
|
|
|
@@ -169,11 +220,27 @@ export class UserService extends EntityServiceImpl {
|
|
|
169
220
|
return savedData;
|
|
170
221
|
}
|
|
171
222
|
|
|
172
|
-
async findByEmailId(
|
|
173
|
-
|
|
223
|
+
async findByEmailId(
|
|
224
|
+
email_id: string,
|
|
225
|
+
organization_id?: number,
|
|
226
|
+
appCode?: string,
|
|
227
|
+
): Promise<UserData | null> {
|
|
228
|
+
return await this.userRepository.findByEmailId(
|
|
229
|
+
email_id,
|
|
230
|
+
organization_id,
|
|
231
|
+
appCode,
|
|
232
|
+
);
|
|
174
233
|
}
|
|
175
234
|
|
|
176
|
-
async findByMobile(
|
|
177
|
-
|
|
235
|
+
async findByMobile(
|
|
236
|
+
mobile: string,
|
|
237
|
+
organization_id?: number,
|
|
238
|
+
appCode?: string,
|
|
239
|
+
): Promise<UserData | null> {
|
|
240
|
+
return await this.userRepository.findByMobile(
|
|
241
|
+
mobile,
|
|
242
|
+
organization_id,
|
|
243
|
+
appCode,
|
|
244
|
+
);
|
|
178
245
|
}
|
|
179
246
|
}
|