rez_core 2.1.147 → 2.1.148

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.147",
3
+ "version": "2.1.148",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -24,8 +24,8 @@ export class ActionEntity extends BaseEntity {
24
24
  @Column({ type: 'varchar', nullable: true })
25
25
  reason_code: string;
26
26
 
27
- @Column({ type: 'varchar', nullable: true })
28
- default_reason_code: string;
27
+ @Column({ type: 'int', nullable: true })
28
+ default_reason_code: number;
29
29
 
30
30
  @Column({ default: 0, type: 'boolean' })
31
31
  default_value: boolean;
@@ -22,6 +22,9 @@ export class ActionCategoryService extends EntityServiceImpl {
22
22
  [entity_type, organization_id],
23
23
  );
24
24
 
25
- return result;
25
+ return result.map((row: any) => ({
26
+ label: row.name,
27
+ value: row.id,
28
+ }));
26
29
  }
27
30
  }
@@ -37,8 +37,6 @@ export class ActionService extends EntityServiceImpl {
37
37
  manager?: EntityManager | null,
38
38
  appcode?: string,
39
39
  ): Promise<any> {
40
- console.log('entityData', entityData);
41
-
42
40
  let actionData = entityData as any;
43
41
 
44
42
  let action = await super.createEntity(
@@ -196,7 +194,7 @@ export class ActionService extends EntityServiceImpl {
196
194
  }
197
195
  const result = await this.dataSource.query(
198
196
  `
199
- SELECT name, value
197
+ SELECT name, id
200
198
  FROM cr_list_master_items
201
199
  WHERE listtype = ? AND organization_id = ?
202
200
  `,
@@ -205,8 +203,8 @@ export class ActionService extends EntityServiceImpl {
205
203
 
206
204
  // Format as array of key-value pairs
207
205
  return result.map((row: any) => ({
208
- label: row.value,
209
- value: row.name,
206
+ label: row.name,
207
+ value: row.id,
210
208
  }));
211
209
  }
212
210
 
@@ -228,88 +226,93 @@ export class ActionService extends EntityServiceImpl {
228
226
  const actionIds = stageActions.map((sa) => sa.action_id);
229
227
  const mappingIds = stageActions.map((sa) => sa.id);
230
228
 
229
+ // Step 2: Get template codes with mapping IDs
231
230
  const templateMappings = await this.dataSource.query(
232
231
  `
233
- SELECT template_code
232
+ SELECT stg_act_mapping_id, template_code
234
233
  FROM cr_wf_action_template_mapping
235
- WHERE stg_act_mapping_id IN (?)
234
+ WHERE stg_act_mapping_id IN (${mappingIds.map(() => '?').join(',')})
236
235
  `,
237
- [mappingIds],
236
+ mappingIds,
238
237
  );
239
238
 
240
239
  const templateCodes = templateMappings.map((tm) => tm.template_code);
241
240
 
242
241
  // Step 3: Fetch template names from cr_wf_comm_template
243
- let templateNameMap: Record<number, string> = {};
242
+ const templateCodeToName: Record<string, string> = {};
244
243
 
245
244
  if (templateCodes.length > 0) {
246
- const templates = await this.dataSource.query(
247
- `
248
- SELECT code, name
249
- FROM cr_wf_comm_template
250
- WHERE code IN (?)
251
- AND organization_id = ?
252
- `,
253
- [templateCodes, organization_id],
254
- );
255
-
256
- // Map template_code to name
257
- const codeToNameMap = templates.reduce((acc, curr) => {
258
- acc[curr.code] = curr.name;
259
- return acc;
260
- }, {});
261
-
262
- // Group template names by mapping_id
263
- templateMappings.forEach((tm) => {
264
- const mappingId = tm.stg_act_mapping_id;
265
- const name = codeToNameMap[tm.template_code];
266
- if (name) {
267
- if (!templateNameMap[mappingId]) {
268
- templateNameMap[mappingId] = name;
269
- } else {
270
- templateNameMap[mappingId] += `, ${name}`;
271
- }
272
- }
245
+ const templates = await this.dataSource
246
+ .createQueryBuilder()
247
+ .select(['t.code AS code', 't.name AS name'])
248
+ .from('cr_wf_comm_template', 't')
249
+ .where('t.code IN (:...codes)', { codes: templateCodes })
250
+ .andWhere('t.organization_id = :orgId', { orgId: organization_id })
251
+ .getRawMany();
252
+
253
+ templates.forEach((tpl) => {
254
+ templateCodeToName[tpl.code] = tpl.name;
273
255
  });
274
256
  }
275
257
 
276
- // Step 2: Fetch action details based on those action_ids
277
- // Step 4: Fetch action details
278
- const result = await this.dataSource.query(
279
- `
280
- SELECT
281
- a.id,
282
- a.name AS action_name,
283
- ac.name AS action_category,
284
- ar.name AS action_requirement
285
- FROM cr_wf_action a
286
- LEFT JOIN cr_wf_action_category ac
287
- ON ac.id = a.action_cat_id
288
- LEFT JOIN cr_list_master_items ar
289
- ON ar.id = a.action_requirement
290
- AND ar.listtype = 'ACRQ'
291
- AND ar.organization_id = ?
292
- WHERE a.organization_id = ?
293
- AND a.id IN (?)
294
- `,
295
- [organization_id, organization_id, actionIds],
296
- );
258
+ // Step 4: Build map of mapping_id template names
259
+ const mappingIdToTemplates: Record<number, string[]> = {};
297
260
 
298
- // Step 5: Attach templates (comma-separated) to each result row
299
- const enrichedResult = result.map((row) => {
300
- // Find all mapping_ids where action_id == current row.id
301
- const relatedMappingIds = stageActions
302
- .filter((sa) => sa.action_id === row.id)
303
- .map((sa) => sa.id);
261
+ for (const tm of templateMappings) {
262
+ const mappingId = tm.stg_act_mapping_id;
263
+ const name = templateCodeToName[tm.template_code];
264
+ if (name) {
265
+ if (!mappingIdToTemplates[mappingId]) {
266
+ mappingIdToTemplates[mappingId] = [];
267
+ }
268
+ mappingIdToTemplates[mappingId].push(name);
269
+ }
270
+ }
271
+
272
+ // Step 5: Build action_id → template names using mappingIdToTemplates + stageActions
273
+ const actionIdToTemplates: Record<number, string[]> = {};
274
+
275
+ for (const sa of stageActions) {
276
+ const mappingId = sa.id;
277
+ const templates = mappingIdToTemplates[mappingId];
278
+ if (templates?.length) {
279
+ if (!actionIdToTemplates[sa.action_id]) {
280
+ actionIdToTemplates[sa.action_id] = [];
281
+ }
282
+ actionIdToTemplates[sa.action_id].push(...templates);
283
+ }
284
+ }
304
285
 
305
- // Collect all template names across those mapping ids
306
- const allNames = relatedMappingIds
307
- .map((mid) => templateNameMap[mid])
308
- .filter(Boolean);
286
+ // Step 6: Fetch action details
287
+ const actionResults = await this.dataSource
288
+ .createQueryBuilder()
289
+ .select([
290
+ 'a.id AS id',
291
+ 'a.name AS action_name',
292
+ 'ac.name AS action_category',
293
+ 'ar.name AS action_requirement',
294
+ ])
295
+ .from('cr_wf_action', 'a')
296
+ .leftJoin('cr_wf_action_category', 'ac', 'ac.id = a.action_cat_id')
297
+ .leftJoin(
298
+ 'cr_list_master_items',
299
+ 'ar',
300
+ `ar.id = a.action_requirement AND ar.listtype = 'ACRQ' AND ar.organization_id = :orgId`,
301
+ { orgId: organization_id },
302
+ )
303
+ .where('a.organization_id = :orgId', { orgId: organization_id })
304
+ .andWhere('a.id IN (:...actionIds)', { actionIds })
305
+ .getRawMany();
306
+
307
+ // Step 7: Enrich result with template field
308
+ const enrichedResult = actionResults.map((row) => {
309
+ const actionId = Number(row.id); // Ensure numeric ID match
310
+ const templates = actionIdToTemplates[actionId] || [];
311
+ const uniqueTemplates = [...new Set(templates)]; // remove duplicates
309
312
 
310
313
  return {
311
314
  ...row,
312
- template: allNames.length ? allNames.join(', ') : '',
315
+ template: uniqueTemplates.join(', '),
313
316
  };
314
317
  });
315
318