av6-core 1.8.4 → 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
@@ -2739,59 +2739,57 @@ var ApprovalService = class {
2739
2739
  }
2740
2740
  }
2741
2741
  async assertPermission(step, approverId, instanceId, ccId, tx) {
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}
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}
2751
2751
 
2752
- UNION
2752
+ UNION
2753
2753
 
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
- `);
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
+ `;
2767
2767
  if (Number(result[0].count) === 0) {
2768
2768
  throw new this.deps.helpers.ErrorHandler(403, "You are not allowed to act on this approval step");
2769
2769
  }
2770
- const existingActsQuery = `
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 = ?
2775
- AND a.level = ?
2776
- AND a.acted_by = ?
2777
- AND a.is_active = true
2778
- AND ai.is_active = true
2779
- `;
2780
- 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
+ `;
2781
2780
  if (Number(actionsResult[0].count) > 0) {
2782
2781
  throw new this.deps.helpers.ErrorHandler(409, "You have already submitted a decision for this level");
2783
2782
  }
2784
- const prevApproversQuery = `
2785
- SELECT COUNT(*) AS count
2786
- FROM core_approval_action a
2787
- JOIN core_approval_instance ai ON ai.id = a.instance_id
2788
- WHERE ai.id = ?
2789
- AND a.level < ?
2790
- AND a.is_active = true
2791
- AND ai.is_active = true
2792
- AND a.acted_by IS NOT NULL
2793
- `;
2794
- 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
+ `;
2795
2793
  if (Number(prevActionsResult[0].count) !== step.level - 1) {
2796
2794
  throw new this.deps.helpers.ErrorHandler(403, "You must wait for previous approvers to act first");
2797
2795
  }
package/dist/index.mjs CHANGED
@@ -2678,59 +2678,57 @@ var ApprovalService = class {
2678
2678
  }
2679
2679
  }
2680
2680
  async assertPermission(step, approverId, instanceId, ccId, tx) {
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}
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}
2690
2690
 
2691
- UNION
2691
+ UNION
2692
2692
 
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
- `);
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
+ `;
2706
2706
  if (Number(result[0].count) === 0) {
2707
2707
  throw new this.deps.helpers.ErrorHandler(403, "You are not allowed to act on this approval step");
2708
2708
  }
2709
- const existingActsQuery = `
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 = ?
2714
- AND a.level = ?
2715
- AND a.acted_by = ?
2716
- AND a.is_active = true
2717
- AND ai.is_active = true
2718
- `;
2719
- 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
+ `;
2720
2719
  if (Number(actionsResult[0].count) > 0) {
2721
2720
  throw new this.deps.helpers.ErrorHandler(409, "You have already submitted a decision for this level");
2722
2721
  }
2723
- const prevApproversQuery = `
2724
- SELECT COUNT(*) AS count
2725
- FROM core_approval_action a
2726
- JOIN core_approval_instance ai ON ai.id = a.instance_id
2727
- WHERE ai.id = ?
2728
- AND a.level < ?
2729
- AND a.is_active = true
2730
- AND ai.is_active = true
2731
- AND a.acted_by IS NOT NULL
2732
- `;
2733
- 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
+ `;
2734
2732
  if (Number(prevActionsResult[0].count) !== step.level - 1) {
2735
2733
  throw new this.deps.helpers.ErrorHandler(403, "You must wait for previous approvers to act first");
2736
2734
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",