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 +55 -54
- package/dist/index.mjs +55 -54
- package/package.json +1 -1
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
|
|
2346
|
-
JOIN core_approval_step
|
|
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
|
|
2350
|
-
AND s.is_active
|
|
2351
|
-
AND (
|
|
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
|
-
|
|
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
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
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
|
-
|
|
2752
|
+
UNION
|
|
2750
2753
|
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
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
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
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
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
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
|
|
2285
|
-
JOIN core_approval_step
|
|
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
|
|
2289
|
-
AND s.is_active
|
|
2290
|
-
AND (
|
|
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
|
-
|
|
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
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
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
|
-
|
|
2691
|
+
UNION
|
|
2689
2692
|
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
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
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
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
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
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
|
}
|