ztechno_core 0.0.130 → 0.0.131
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.
|
@@ -14,6 +14,8 @@ export declare class InvoicesOrm extends ZOrm {
|
|
|
14
14
|
findAll(): Promise<ZInvoice[]>;
|
|
15
15
|
findLastByYear(year: number): Promise<ZInvoice | undefined>;
|
|
16
16
|
updateStatus(id: number, status: ZInvoiceStatus, amount_paid?: number, paid_at?: string | null): Promise<void>;
|
|
17
|
+
/** Transitions status only if the current DB status matches `fromStatus`. Safe against concurrent updates. */
|
|
18
|
+
updateStatusConditional(id: number, status: ZInvoiceStatus, fromStatus: ZInvoiceStatus): Promise<void>;
|
|
17
19
|
updatePaymentRef(
|
|
18
20
|
id: number,
|
|
19
21
|
payload: {
|
|
@@ -89,6 +89,17 @@ class InvoicesOrm extends orm_1.ZOrm {
|
|
|
89
89
|
{ id, status, amount_paid: amount_paid ?? null, paid_at: paid_at ?? null },
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
|
+
/** Transitions status only if the current DB status matches `fromStatus`. Safe against concurrent updates. */
|
|
93
|
+
async updateStatusConditional(id, status, fromStatus) {
|
|
94
|
+
await this.sqlService.query(
|
|
95
|
+
/*SQL*/ `
|
|
96
|
+
UPDATE \`${this.alias}\`
|
|
97
|
+
SET status=:status, updated_at=NOW()
|
|
98
|
+
WHERE id=:id AND status=:fromStatus
|
|
99
|
+
`,
|
|
100
|
+
{ id, status, fromStatus },
|
|
101
|
+
);
|
|
102
|
+
}
|
|
92
103
|
async updatePaymentRef(id, payload) {
|
|
93
104
|
await this.sqlService.query(
|
|
94
105
|
/*SQL*/ `
|
|
@@ -1010,6 +1010,9 @@ class InvoiceService {
|
|
|
1010
1010
|
],
|
|
1011
1011
|
});
|
|
1012
1012
|
await this.invoicesOrm.incrementTimesSent(invoiceId);
|
|
1013
|
+
if (!isReceipt) {
|
|
1014
|
+
await this.invoicesOrm.updateStatusConditional(invoiceId, 'pending', 'draft');
|
|
1015
|
+
}
|
|
1013
1016
|
return {
|
|
1014
1017
|
invoice_number: invoice.invoice_number,
|
|
1015
1018
|
recipient: to,
|