rez_core 5.0.7 → 5.0.9

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": "5.0.7",
3
+ "version": "5.0.9",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -279,129 +279,115 @@ export class TaskService extends EntityServiceImpl {
279
279
  const { mapped_entity_type, mapped_entity_id, status, mandatory, overdue } =
280
280
  data;
281
281
 
282
- // Build dynamic WHERE clauses
283
- const whereClauses = [`t.mapped_entity_type = ?`, `t.mapped_entity_id = ?`];
284
- const params: any[] = [mapped_entity_type, mapped_entity_id];
282
+ const whereClauses: string[] = [];
283
+ const params: any[] = [];
284
+ let idx = 1;
285
285
 
286
+ // Required conditions
287
+ whereClauses.push(`t.mapped_entity_type = $${idx++}`);
288
+ params.push(mapped_entity_type);
289
+
290
+ whereClauses.push(`t.mapped_entity_id = $${idx++}`);
291
+ params.push(Number(mapped_entity_id));
292
+
293
+ // Optional filters
286
294
  if (status) {
287
- whereClauses.push(`t.status = ?`);
288
- params.push(status);
295
+ whereClauses.push(`t.status = $${idx++}`);
296
+ params.push(Number(status));
289
297
  }
290
- if (mandatory) {
291
- whereClauses.push(`t.is_mandatory = ?`);
292
- params.push(mandatory ? 1 : 0);
298
+
299
+ if (mandatory !== undefined) {
300
+ whereClauses.push(`t.is_mandatory = $${idx++}`);
301
+ params.push(mandatory ? true : false);
293
302
  }
303
+
294
304
  if (overdue) {
295
- whereClauses.push(
296
- `(t.due_date < CURDATE() OR (t.due_date = CURDATE() AND t.due_time < CURTIME()))`,
297
- );
298
- // exclude tasks that are already completed
299
- whereClauses.push(`t.is_done = ?`);
300
- params.push(0); // Only include tasks that are not done
305
+ // Use PostgreSQL CURRENT_DATE + CURRENT_TIME
306
+ whereClauses.push(`
307
+ (
308
+ t.due_date < CURRENT_DATE
309
+ OR (t.due_date = CURRENT_DATE AND t.due_time < CURRENT_TIME)
310
+ )
311
+ `);
312
+
313
+ // Only if not done
314
+ whereClauses.push(`t.is_done = $${idx++}`);
315
+ params.push(false);
301
316
  }
302
317
 
303
318
  const sql = `
304
- SELECT
305
- t.*,
306
- sg.name AS stage_group_name,
307
- s.name AS stage_name,
308
- a.name AS action_name
309
- FROM frm_wf_task_data t
310
- LEFT JOIN frm_wf_stage s ON t.stage_id = s.id
311
- LEFT JOIN frm_wf_stage_group sg ON s.stage_group_id = sg.id
312
- LEFT JOIN frm_wf_action a ON t.action_id = a.id
313
- WHERE ${whereClauses.join(' AND ')}
314
- ORDER BY t.created_date DESC
315
- `;
319
+ SELECT
320
+ t.*,
321
+ sg.name AS stage_group_name,
322
+ s.name AS stage_name,
323
+ a.name AS action_name
324
+ FROM frm_wf_task_data t
325
+ LEFT JOIN frm_wf_stage s ON t.stage_id = s.id
326
+ LEFT JOIN frm_wf_stage_group sg ON s.stage_group_id = sg.id
327
+ LEFT JOIN frm_wf_action a ON t.action_id = a.id
328
+ WHERE ${whereClauses.join(" AND ")}
329
+ ORDER BY t.created_date DESC
330
+ `;
316
331
 
317
332
  const taskData = await this.dataSource.query(sql, params);
318
333
 
319
- if (taskData) {
320
- let user: any = null;
321
- for (const param of taskData as any) {
334
+ // ------------------------------------------------------
335
+ // Resolve user profile
336
+ // ------------------------------------------------------
337
+ if (taskData?.length) {
338
+ for (const task of taskData) {
322
339
  try {
323
- const baseUrl = this.configService.get<string>('REDIRECT_BE_URL');
340
+ const baseUrl = this.configService.get<string>("REDIRECT_BE_URL");
324
341
 
325
- // Prepare the query string
326
342
  const queryParams = new URLSearchParams({
327
343
  loggedInUser: JSON.stringify(loggedInUser),
328
344
  }).toString();
329
345
 
330
- // Make the GET request with query parameters
331
346
  const response = await axios.get(
332
- `${baseUrl}/users/profile-image-url/${param?.task_owner}?entity_type=USR&${queryParams}`,
333
- {
334
- headers: {
335
- 'Content-Type': 'application/json',
336
- },
337
- },
347
+ `${baseUrl}/users/profile-image-url/${task?.task_owner}?entity_type=USR&${queryParams}`,
348
+ { headers: { "Content-Type": "application/json" } },
338
349
  );
339
350
 
340
- user = response.data;
341
- param.created_by_name = user.name;
342
- param.task_owner_name = user.name;
343
- param.task_owner_profile = user.profile_image;
344
- } catch (error) {
345
- console.error('⚠️ Internal Entity API call failed:', error.message);
351
+ task.created_by_name = response.data.name;
352
+ task.task_owner_name = response.data.name;
353
+ task.task_owner_profile = response.data.profile_image;
354
+ } catch (err) {
355
+ console.error("⚠ Error fetching profile:", err.message);
346
356
  }
347
357
  }
348
358
  }
349
359
 
350
- if (taskData.length === 0) {
351
- return [];
352
- }
360
+ if (!taskData.length) return [];
353
361
 
354
- // Fetch all TKST statuses in a single query
355
- const taskStatusQuery = `
356
- SELECT id, name
357
- FROM frm_list_master_items
358
- WHERE organization_id = $1
359
- AND listtype = 'TKST'
360
- `;
361
- const taskAllStatus = await this.dataSource.query(taskStatusQuery, [
362
+ // ------------------------------------------------------
363
+ // Load All TKST Statuses
364
+ // ------------------------------------------------------
365
+ const statusSql = `
366
+ SELECT id, name
367
+ FROM frm_list_master_items
368
+ WHERE organization_id = $1
369
+ AND listtype = 'TKST'
370
+ `;
371
+
372
+ const allStatuses = await this.dataSource.query(statusSql, [
362
373
  loggedInUser.organization_id,
363
374
  ]);
364
375
 
365
- // Build a hash map { id → name }
366
376
  const statusMap = new Map(
367
- taskAllStatus.map((row) => [String(row.id), row.name]),
377
+ allStatuses.map((row) => [String(row.id), row.name]),
368
378
  );
369
379
 
370
- // Assign task_status using the map
371
-
372
- const mediaCache = new Map<number, any>();
373
-
374
- for (const task of taskData) {
375
- // Map status name
376
- task.task_status = task.status
377
- ? statusMap.get(String(task.status)) || null
378
- : null;
379
-
380
- // Fix action_name for generic tasks
381
- task.action_name =
382
- task.action_id === '0' || task.action_id === 0
383
- ? 'Generic'
384
- : task.action_name;
385
-
386
- // Profile media (with caching like notes)
387
- // if (task.task_owner_profile) {
388
- // if (!mediaCache.has(task.task_owner_profile)) {
389
- // const url = await this.mediaDataService.getMediaDownloadUrl(
390
- // Number(task.task_owner_profile),
391
- // loggedInUser,
392
- // );
393
- // mediaCache.set(task.task_owner_profile, url);
394
- // }
395
- // task.task_owner_profile = mediaCache.get(task.task_owner_profile);
396
- // } else {
397
- // task.task_owner_profile = null;
398
- // }
399
- }
400
-
401
- // Normalize is_mandatory to '0'/'1' as string
380
+ // ------------------------------------------------------
381
+ // Normalize & decorate tasks
382
+ // ------------------------------------------------------
402
383
  return taskData.map((task) => ({
403
384
  ...task,
404
- is_mandatory: task.is_mandatory ? '1' : '0',
385
+ task_status: statusMap.get(String(task.status)) || null,
386
+ action_name:
387
+ task.action_id === 0 || task.action_id === "0"
388
+ ? "Generic"
389
+ : task.action_name,
390
+ is_mandatory: task.is_mandatory ? "1" : "0",
405
391
  }));
406
392
  }
407
393