av6-core 1.8.3 → 1.8.5

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/index.js CHANGED
@@ -2334,7 +2334,7 @@ var import_client = require("@prisma/client");
2334
2334
  var approvalRepository = (helpers) => {
2335
2335
  return {
2336
2336
  async findMatchingFlow(tx, type, service, ccId, netTotal, level = 1) {
2337
- const result = await tx.$queryRaw(`
2337
+ const result = await tx.$queryRaw`
2338
2338
  SELECT af.id AS flowId,
2339
2339
  s.id AS stepId,
2340
2340
  s.level,
@@ -2342,18 +2342,21 @@ var approvalRepository = (helpers) => {
2342
2342
  s.max_amount AS maxAmount,
2343
2343
  s.step_type AS stepType,
2344
2344
  af.service
2345
- FROM core_approval_flow AS af
2346
- JOIN core_approval_step AS s ON s.flow_id = af.id AND s.level = ${level}
2345
+ FROM core_approval_flow AS af
2346
+ JOIN core_approval_step AS s
2347
+ ON s.flow_id = af.id AND s.level = ${level}
2347
2348
  WHERE af.subject_type = ${type}
2348
2349
  AND af.service = ${service}
2349
- AND af.is_active = TRUE
2350
- AND s.is_active = TRUE
2351
- AND ( (s.step_type = 'MIN_MAX'
2350
+ AND af.is_active = TRUE
2351
+ AND s.is_active = TRUE
2352
+ AND (
2353
+ (s.step_type = 'MIN_MAX'
2352
2354
  AND s.min_amount <= ${netTotal}
2353
2355
  AND s.max_amount >= ${netTotal})
2354
- OR (s.step_type = 'NORMAL') )
2355
- LIMIT 1; -- we expect exactly one matching step
2356
- `);
2356
+ OR (s.step_type = 'NORMAL')
2357
+ )
2358
+ LIMIT 1;
2359
+ `;
2357
2360
  if (result.length === 0) {
2358
2361
  throw new helpers.ErrorHandler(400, "No matching flow found.");
2359
2362
  }
@@ -2736,59 +2739,57 @@ var ApprovalService = class {
2736
2739
  }
2737
2740
  }
2738
2741
  async assertPermission(step, approverId, instanceId, ccId, tx) {
2739
- const result = await tx.$queryRaw(`
2740
- SELECT COUNT(*) AS count
2741
- FROM (
2742
- SELECT am.staff_id AS staff_id
2743
- FROM core_approver_mapping am
2744
- WHERE am.step_id = ${step.id}
2745
- AND am.is_active = TRUE
2746
- AND am.cc_id = ${ccId}
2747
- AND am.staff_id = ${approverId}
2742
+ const result = await tx.$queryRaw`
2743
+ SELECT COUNT(*) AS count
2744
+ FROM (
2745
+ SELECT am.staff_id AS staff_id
2746
+ FROM core_approver_mapping am
2747
+ WHERE am.step_id = ${step.id}
2748
+ AND am.is_active = TRUE
2749
+ AND am.cc_id = ${ccId}
2750
+ AND am.staff_id = ${approverId}
2748
2751
 
2749
- UNION
2752
+ UNION
2750
2753
 
2751
- SELECT scc.staff_id AS staff_id
2752
- FROM core_approver_mapping am
2753
- LEFT JOIN staff_roles sr
2754
- ON sr.role_id = am.role_id
2755
- LEFT JOIN staff_collection_center scc
2756
- ON scc.collection_center_id = am.cc_id
2757
- AND scc.staff_id = sr.staff_id
2758
- WHERE am.step_id = ${step.id}
2759
- AND am.is_active = TRUE
2760
- AND am.cc_id = ${ccId}
2761
- AND scc.staff_id = ${approverId}
2762
- ) AS staff_union;
2763
- `);
2754
+ SELECT scc.staff_id AS staff_id
2755
+ FROM core_approver_mapping am
2756
+ LEFT JOIN staff_roles sr
2757
+ ON sr.role_id = am.role_id
2758
+ LEFT JOIN staff_collection_center scc
2759
+ ON scc.collection_center_id = am.cc_id
2760
+ AND scc.staff_id = sr.staff_id
2761
+ WHERE am.step_id = ${step.id}
2762
+ AND am.is_active = TRUE
2763
+ AND am.cc_id = ${ccId}
2764
+ AND scc.staff_id = ${approverId}
2765
+ ) AS staff_union;
2766
+ `;
2764
2767
  if (Number(result[0].count) === 0) {
2765
2768
  throw new this.deps.helpers.ErrorHandler(403, "You are not allowed to act on this approval step");
2766
2769
  }
2767
- const existingActsQuery = `
2768
- SELECT COUNT(*) AS count
2769
- FROM core_approval_action a
2770
- JOIN core_approval_instance ai ON ai.id = a.instance_id
2771
- WHERE ai.id = ?
2772
- AND a.level = ?
2773
- AND a.acted_by = ?
2774
- AND a.is_active = true
2775
- AND ai.is_active = true
2776
- `;
2777
- const actionsResult = await tx.$queryRawUnsafe(existingActsQuery, instanceId, step.level, approverId);
2770
+ const actionsResult = await tx.$queryRaw`
2771
+ SELECT COUNT(*) AS count
2772
+ FROM core_approval_action a
2773
+ JOIN core_approval_instance ai ON ai.id = a.instance_id
2774
+ WHERE ai.id = ${instanceId}
2775
+ AND a.level = ${step.level}
2776
+ AND a.acted_by = ${approverId}
2777
+ AND a.is_active = true
2778
+ AND ai.is_active = true
2779
+ `;
2778
2780
  if (Number(actionsResult[0].count) > 0) {
2779
2781
  throw new this.deps.helpers.ErrorHandler(409, "You have already submitted a decision for this level");
2780
2782
  }
2781
- const prevApproversQuery = `
2782
- SELECT COUNT(*) AS count
2783
- FROM core_approval_action a
2784
- JOIN core_approval_instance ai ON ai.id = a.instance_id
2785
- WHERE ai.id = ?
2786
- AND a.level < ?
2787
- AND a.is_active = true
2788
- AND ai.is_active = true
2789
- AND a.acted_by IS NOT NULL
2790
- `;
2791
- const prevActionsResult = await tx.$queryRawUnsafe(prevApproversQuery, instanceId, step.level);
2783
+ const prevActionsResult = await tx.$queryRaw`
2784
+ SELECT COUNT(*) AS count
2785
+ FROM core_approval_action a
2786
+ JOIN core_approval_instance ai ON ai.id = a.instance_id
2787
+ WHERE ai.id = ${instanceId}
2788
+ AND a.level < ${step.level}
2789
+ AND a.is_active = true
2790
+ AND ai.is_active = true
2791
+ AND a.acted_by IS NOT NULL
2792
+ `;
2792
2793
  if (Number(prevActionsResult[0].count) !== step.level - 1) {
2793
2794
  throw new this.deps.helpers.ErrorHandler(403, "You must wait for previous approvers to act first");
2794
2795
  }
package/dist/index.mjs CHANGED
@@ -2273,7 +2273,7 @@ import { Prisma } from "@prisma/client";
2273
2273
  var approvalRepository = (helpers) => {
2274
2274
  return {
2275
2275
  async findMatchingFlow(tx, type, service, ccId, netTotal, level = 1) {
2276
- const result = await tx.$queryRaw(`
2276
+ const result = await tx.$queryRaw`
2277
2277
  SELECT af.id AS flowId,
2278
2278
  s.id AS stepId,
2279
2279
  s.level,
@@ -2281,18 +2281,21 @@ var approvalRepository = (helpers) => {
2281
2281
  s.max_amount AS maxAmount,
2282
2282
  s.step_type AS stepType,
2283
2283
  af.service
2284
- FROM core_approval_flow AS af
2285
- JOIN core_approval_step AS s ON s.flow_id = af.id AND s.level = ${level}
2284
+ FROM core_approval_flow AS af
2285
+ JOIN core_approval_step AS s
2286
+ ON s.flow_id = af.id AND s.level = ${level}
2286
2287
  WHERE af.subject_type = ${type}
2287
2288
  AND af.service = ${service}
2288
- AND af.is_active = TRUE
2289
- AND s.is_active = TRUE
2290
- AND ( (s.step_type = 'MIN_MAX'
2289
+ AND af.is_active = TRUE
2290
+ AND s.is_active = TRUE
2291
+ AND (
2292
+ (s.step_type = 'MIN_MAX'
2291
2293
  AND s.min_amount <= ${netTotal}
2292
2294
  AND s.max_amount >= ${netTotal})
2293
- OR (s.step_type = 'NORMAL') )
2294
- LIMIT 1; -- we expect exactly one matching step
2295
- `);
2295
+ OR (s.step_type = 'NORMAL')
2296
+ )
2297
+ LIMIT 1;
2298
+ `;
2296
2299
  if (result.length === 0) {
2297
2300
  throw new helpers.ErrorHandler(400, "No matching flow found.");
2298
2301
  }
@@ -2675,59 +2678,57 @@ var ApprovalService = class {
2675
2678
  }
2676
2679
  }
2677
2680
  async assertPermission(step, approverId, instanceId, ccId, tx) {
2678
- const result = await tx.$queryRaw(`
2679
- SELECT COUNT(*) AS count
2680
- FROM (
2681
- SELECT am.staff_id AS staff_id
2682
- FROM core_approver_mapping am
2683
- WHERE am.step_id = ${step.id}
2684
- AND am.is_active = TRUE
2685
- AND am.cc_id = ${ccId}
2686
- AND am.staff_id = ${approverId}
2681
+ const result = await tx.$queryRaw`
2682
+ SELECT COUNT(*) AS count
2683
+ FROM (
2684
+ SELECT am.staff_id AS staff_id
2685
+ FROM core_approver_mapping am
2686
+ WHERE am.step_id = ${step.id}
2687
+ AND am.is_active = TRUE
2688
+ AND am.cc_id = ${ccId}
2689
+ AND am.staff_id = ${approverId}
2687
2690
 
2688
- UNION
2691
+ UNION
2689
2692
 
2690
- SELECT scc.staff_id AS staff_id
2691
- FROM core_approver_mapping am
2692
- LEFT JOIN staff_roles sr
2693
- ON sr.role_id = am.role_id
2694
- LEFT JOIN staff_collection_center scc
2695
- ON scc.collection_center_id = am.cc_id
2696
- AND scc.staff_id = sr.staff_id
2697
- WHERE am.step_id = ${step.id}
2698
- AND am.is_active = TRUE
2699
- AND am.cc_id = ${ccId}
2700
- AND scc.staff_id = ${approverId}
2701
- ) AS staff_union;
2702
- `);
2693
+ SELECT scc.staff_id AS staff_id
2694
+ FROM core_approver_mapping am
2695
+ LEFT JOIN staff_roles sr
2696
+ ON sr.role_id = am.role_id
2697
+ LEFT JOIN staff_collection_center scc
2698
+ ON scc.collection_center_id = am.cc_id
2699
+ AND scc.staff_id = sr.staff_id
2700
+ WHERE am.step_id = ${step.id}
2701
+ AND am.is_active = TRUE
2702
+ AND am.cc_id = ${ccId}
2703
+ AND scc.staff_id = ${approverId}
2704
+ ) AS staff_union;
2705
+ `;
2703
2706
  if (Number(result[0].count) === 0) {
2704
2707
  throw new this.deps.helpers.ErrorHandler(403, "You are not allowed to act on this approval step");
2705
2708
  }
2706
- const existingActsQuery = `
2707
- SELECT COUNT(*) AS count
2708
- FROM core_approval_action a
2709
- JOIN core_approval_instance ai ON ai.id = a.instance_id
2710
- WHERE ai.id = ?
2711
- AND a.level = ?
2712
- AND a.acted_by = ?
2713
- AND a.is_active = true
2714
- AND ai.is_active = true
2715
- `;
2716
- const actionsResult = await tx.$queryRawUnsafe(existingActsQuery, instanceId, step.level, approverId);
2709
+ const actionsResult = await tx.$queryRaw`
2710
+ SELECT COUNT(*) AS count
2711
+ FROM core_approval_action a
2712
+ JOIN core_approval_instance ai ON ai.id = a.instance_id
2713
+ WHERE ai.id = ${instanceId}
2714
+ AND a.level = ${step.level}
2715
+ AND a.acted_by = ${approverId}
2716
+ AND a.is_active = true
2717
+ AND ai.is_active = true
2718
+ `;
2717
2719
  if (Number(actionsResult[0].count) > 0) {
2718
2720
  throw new this.deps.helpers.ErrorHandler(409, "You have already submitted a decision for this level");
2719
2721
  }
2720
- const prevApproversQuery = `
2721
- SELECT COUNT(*) AS count
2722
- FROM core_approval_action a
2723
- JOIN core_approval_instance ai ON ai.id = a.instance_id
2724
- WHERE ai.id = ?
2725
- AND a.level < ?
2726
- AND a.is_active = true
2727
- AND ai.is_active = true
2728
- AND a.acted_by IS NOT NULL
2729
- `;
2730
- const prevActionsResult = await tx.$queryRawUnsafe(prevApproversQuery, instanceId, step.level);
2722
+ const prevActionsResult = await tx.$queryRaw`
2723
+ SELECT COUNT(*) AS count
2724
+ FROM core_approval_action a
2725
+ JOIN core_approval_instance ai ON ai.id = a.instance_id
2726
+ WHERE ai.id = ${instanceId}
2727
+ AND a.level < ${step.level}
2728
+ AND a.is_active = true
2729
+ AND ai.is_active = true
2730
+ AND a.acted_by IS NOT NULL
2731
+ `;
2731
2732
  if (Number(prevActionsResult[0].count) !== step.level - 1) {
2732
2733
  throw new this.deps.helpers.ErrorHandler(403, "You must wait for previous approvers to act first");
2733
2734
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",