rez_core 2.1.30 → 2.1.32
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/filter/service/filter.service.js +9 -18
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/user/service/login.service.d.ts +6 -4
- package/dist/module/user/service/login.service.js +36 -27
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/module/filter/service/filter.service.ts +27 -26
- package/src/module/user/service/login.service.ts +59 -43
package/package.json
CHANGED
|
@@ -25,7 +25,6 @@ export class FilterService {
|
|
|
25
25
|
column: string | undefined,
|
|
26
26
|
whereClauses: { query: string; params: Record<string, any> }[],
|
|
27
27
|
) {
|
|
28
|
-
console.log('GTETABCOUNTS', tableName, column, whereClauses);
|
|
29
28
|
if (!column) return [];
|
|
30
29
|
|
|
31
30
|
let whereSQL = '';
|
|
@@ -96,8 +95,6 @@ export class FilterService {
|
|
|
96
95
|
'LIST',
|
|
97
96
|
);
|
|
98
97
|
|
|
99
|
-
console.log(getTableMeta, 'GETTABLEMETA');
|
|
100
|
-
|
|
101
98
|
if (!getTableMeta) {
|
|
102
99
|
throw new BadRequestException(
|
|
103
100
|
`Table meta not found for entity_type: ${entity_type}`,
|
|
@@ -110,7 +107,6 @@ export class FilterService {
|
|
|
110
107
|
true,
|
|
111
108
|
);
|
|
112
109
|
|
|
113
|
-
console.log(getTableColumnMeta, 'GETTABLECOLUMNMETA');
|
|
114
110
|
// const attributeMeta =
|
|
115
111
|
// await this.attributeMasterService.findAttributesByMappedEntityType(
|
|
116
112
|
// entity_type,
|
|
@@ -123,7 +119,6 @@ export class FilterService {
|
|
|
123
119
|
{} as Record<string, any>,
|
|
124
120
|
);
|
|
125
121
|
|
|
126
|
-
console.log(attributeMetaMap, 'ATTRIBUTEMETAMAP');
|
|
127
122
|
// Get and parse filters
|
|
128
123
|
const savedFilters = await this.getSavedFilters(savedFilterCode);
|
|
129
124
|
const baseFilters = [
|
|
@@ -133,7 +128,7 @@ export class FilterService {
|
|
|
133
128
|
];
|
|
134
129
|
|
|
135
130
|
const baseWhere = this.buildWhereClauses(baseFilters, attributeMetaMap);
|
|
136
|
-
|
|
131
|
+
|
|
137
132
|
if (level_type && level_id) {
|
|
138
133
|
baseWhere.push({
|
|
139
134
|
query: 'e.level_type = :level_type AND e.level_id = :level_id',
|
|
@@ -144,9 +139,7 @@ export class FilterService {
|
|
|
144
139
|
});
|
|
145
140
|
}
|
|
146
141
|
|
|
147
|
-
console.log('OUSTSIDE SKIP');
|
|
148
142
|
if (this.skipLevelFilterEntities.includes(entity_type)) {
|
|
149
|
-
console.log('INSIDE SKIP');
|
|
150
143
|
baseWhere.push({
|
|
151
144
|
query: 'e.appcode = :appcode',
|
|
152
145
|
params: { appcode },
|
|
@@ -160,15 +153,12 @@ export class FilterService {
|
|
|
160
153
|
[user_id, entity_type],
|
|
161
154
|
);
|
|
162
155
|
|
|
163
|
-
console.log('LAYOUTPREFERNECE', layoutPreference);
|
|
164
|
-
|
|
165
156
|
// Extract layout preference
|
|
166
157
|
const layout = layoutPreference?.[0]?.layout_json?.quick_tab || {};
|
|
167
158
|
let showList = layout?.show_list?.map((val) => val.toLowerCase()) || [];
|
|
168
159
|
|
|
169
160
|
let allTabs;
|
|
170
161
|
if (layout.attribute) {
|
|
171
|
-
console.log('IN LAYOUT');
|
|
172
162
|
allTabs = await this.gettab_value_counts(
|
|
173
163
|
getTableMeta.data_source,
|
|
174
164
|
layout.attribute,
|
|
@@ -220,8 +210,6 @@ export class FilterService {
|
|
|
220
210
|
filteredTabs = allTabs;
|
|
221
211
|
}
|
|
222
212
|
|
|
223
|
-
console.log(allTabs, 'ALLTABSE');
|
|
224
|
-
|
|
225
213
|
const dataWhere = [...baseWhere];
|
|
226
214
|
|
|
227
215
|
if (tabs?.columnName && tabs?.value) {
|
|
@@ -255,6 +243,7 @@ export class FilterService {
|
|
|
255
243
|
},
|
|
256
244
|
tabAttrMeta,
|
|
257
245
|
);
|
|
246
|
+
|
|
258
247
|
if (tabCondition) {
|
|
259
248
|
dataWhere.push(tabCondition);
|
|
260
249
|
}
|
|
@@ -272,21 +261,33 @@ export class FilterService {
|
|
|
272
261
|
qb.andWhere(clause.query, clause.params);
|
|
273
262
|
});
|
|
274
263
|
|
|
275
|
-
if (Array.isArray(sortby)) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
264
|
+
// if (Array.isArray(sortby)) {
|
|
265
|
+
// // Optional sorting
|
|
266
|
+
// sortby.forEach(({ sortColum, sortType }) => {
|
|
267
|
+
// qb.addOrderBy(
|
|
268
|
+
// `e.${sortColum}`,
|
|
269
|
+
// sortType.toUpperCase() === 'DSC' ? 'DESC' : 'ASC',
|
|
270
|
+
// );
|
|
271
|
+
// });
|
|
272
|
+
// }
|
|
273
|
+
|
|
274
|
+
if (layoutPreference && layoutPreference[0]?.layout_json?.sorting) {
|
|
275
|
+
if (Array.isArray(layoutPreference[0]?.layout_json?.sorting?.tabs)) {
|
|
276
|
+
let preferenceTabArray =
|
|
277
|
+
layoutPreference[0]?.layout_json?.sorting?.tabs;
|
|
278
|
+
let tabFilter = preferenceTabArray.find(
|
|
279
|
+
(tabData) => tabData.tab_name === tabs?.value,
|
|
281
280
|
);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
281
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
282
|
+
tabFilter?.sortby.forEach(({ column, order }) => {
|
|
283
|
+
qb.addOrderBy(
|
|
284
|
+
`e.${column}`,
|
|
285
|
+
order?.toUpperCase() === 'DSC' ? 'DESC' : 'ASC',
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
} else if (
|
|
289
|
+
Array.isArray(layoutPreference[0]?.layout_json?.sorting?.sortby)
|
|
290
|
+
) {
|
|
290
291
|
// Optional sorting
|
|
291
292
|
layoutPreference[0]?.layout_json?.sorting?.sortby?.forEach(
|
|
292
293
|
({ column, order }) => {
|
|
@@ -4,11 +4,9 @@ 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';
|
|
8
|
-
import { UserRoleMappingRepository } from '../repository/user-role-mapping.repository';
|
|
9
7
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
10
8
|
import { UserRoleMapping } from '../entity/user-role-mapping.entity';
|
|
11
|
-
import { Repository } from 'typeorm';
|
|
9
|
+
import { DataSource, Repository } from 'typeorm';
|
|
12
10
|
import { Role } from '../entity/role.entity';
|
|
13
11
|
|
|
14
12
|
@Injectable()
|
|
@@ -21,6 +19,7 @@ export class LoginService {
|
|
|
21
19
|
private readonly userRoleMappingRepository: Repository<UserRoleMapping>,
|
|
22
20
|
@InjectRepository(Role)
|
|
23
21
|
private readonly roleRepo: Repository<Role>,
|
|
22
|
+
private readonly dataSource: DataSource,
|
|
24
23
|
) {}
|
|
25
24
|
|
|
26
25
|
masterKey: string = this.configService.get('MASTER_KEY') || '';
|
|
@@ -59,58 +58,29 @@ export class LoginService {
|
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
let
|
|
63
|
-
let appcode = user.last_app_access;
|
|
61
|
+
let appcode = user.last_app_access || 'ADM';
|
|
64
62
|
|
|
65
|
-
if (!
|
|
66
|
-
appcode = 'ADM';
|
|
63
|
+
if (!user.last_app_access) {
|
|
67
64
|
await this.userService.setDefaultLastAccess(user.id, appcode);
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
// ✅ Always fetch role mappings for the user + app
|
|
71
67
|
const roleMappings = await this.userRoleMappingRepository.find({
|
|
72
|
-
where: {
|
|
73
|
-
user_id: user.id,
|
|
74
|
-
appcode,
|
|
75
|
-
},
|
|
68
|
+
where: { user_id: user.id, appcode },
|
|
76
69
|
});
|
|
77
70
|
|
|
78
71
|
if (!roleMappings.length) {
|
|
79
|
-
throw new BadRequestException(
|
|
80
|
-
'User does not have any access mapped for this app.',
|
|
81
|
-
);
|
|
72
|
+
throw new BadRequestException('User does not have any access mapped for this app.');
|
|
82
73
|
}
|
|
83
74
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
const defaultAccess = await this.getDefaultAccess(user, roleMappings);
|
|
76
|
+
|
|
77
|
+
await this.userService.setLastLevelTypeAndId(
|
|
78
|
+
user.id,
|
|
79
|
+
defaultAccess.level_type,
|
|
80
|
+
defaultAccess.level_id,
|
|
89
81
|
);
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
defaultAccess = {
|
|
93
|
-
level_type: user.last_level_type,
|
|
94
|
-
level_id: user.last_level_id,
|
|
95
|
-
};
|
|
96
|
-
} else {
|
|
97
|
-
// ❌ Fallback: Pick default based on priority
|
|
98
|
-
const priority = { org: 1, sch: 2, brn: 3 };
|
|
99
|
-
defaultAccess = roleMappings.sort(
|
|
100
|
-
(a, b) => priority[a.level_type] - priority[b.level_type],
|
|
101
|
-
)[0];
|
|
102
|
-
|
|
103
|
-
await this.userService.setLastLevelTypeAndId(
|
|
104
|
-
user.id,
|
|
105
|
-
defaultAccess.level_type,
|
|
106
|
-
defaultAccess.level_id,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const token = await this.userSessionService.createSession(user, appcode, {
|
|
111
|
-
level_type: defaultAccess.level_type,
|
|
112
|
-
level_id: defaultAccess.level_id,
|
|
113
|
-
});
|
|
83
|
+
const token = await this.userSessionService.createSession(user, appcode, defaultAccess);
|
|
114
84
|
|
|
115
85
|
if (user.is_firstlogin === 1) {
|
|
116
86
|
user.invitation_status = 'ACCEPTED';
|
|
@@ -128,6 +98,52 @@ export class LoginService {
|
|
|
128
98
|
};
|
|
129
99
|
}
|
|
130
100
|
|
|
101
|
+
private async getDefaultAccess(
|
|
102
|
+
user: any,
|
|
103
|
+
roleMappings: any[],
|
|
104
|
+
): 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
|
+
|
|
109
|
+
const validURM = roleMappings.find(
|
|
110
|
+
r => r.level_type === user.last_level_type && r.level_id === user.last_level_id,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (user.last_level_type && user.last_level_id && validURM) {
|
|
114
|
+
return { level_type: user.last_level_type, level_id: user.last_level_id };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (orgAccess) {
|
|
118
|
+
return { level_type: 'ORG', level_id: orgAccess.level_id };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (brnAccesses.length) {
|
|
122
|
+
const brandId = brnAccesses[0].level_id;
|
|
123
|
+
|
|
124
|
+
const rows = await this.dataSource.query(
|
|
125
|
+
`SELECT id FROM cr_school WHERE brand_id = ? ORDER BY id ASC LIMIT 1`,
|
|
126
|
+
[brandId],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (rows.length) {
|
|
130
|
+
return { level_type: 'SCH', level_id: rows[0].id };
|
|
131
|
+
} else {
|
|
132
|
+
throw new BadRequestException(
|
|
133
|
+
'User has BRN access but no schools found under that brand.',
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (schAccesses.length) {
|
|
139
|
+
return { level_type: 'SCH', level_id: schAccesses[0].level_id };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
throw new BadRequestException(
|
|
143
|
+
'User does not have ORG, BRN, or SCH access for this app.',
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
|
|
132
148
|
async loginWithGoogle(email: string, name) {
|
|
133
149
|
let user = await this.userService.findByEmailId(email);
|