ztechno_core 0.0.107 → 0.0.108
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.
|
@@ -13,6 +13,10 @@ export declare class MollieService {
|
|
|
13
13
|
webhookUrl: string;
|
|
14
14
|
});
|
|
15
15
|
private get client();
|
|
16
|
+
resetDatabase(options?: { dryRun?: boolean }): Promise<{
|
|
17
|
+
dryRun: boolean;
|
|
18
|
+
deleted: Record<string, number>;
|
|
19
|
+
}>;
|
|
16
20
|
recoverFromMollie(options?: { dryRun?: boolean }): Promise<RecoveryStats>;
|
|
17
21
|
createCustomer(payload: {
|
|
18
22
|
name: string;
|
|
@@ -36,6 +36,36 @@ class MollieService {
|
|
|
36
36
|
}
|
|
37
37
|
return (0, api_client_1.createMollieClient)({ apiKey });
|
|
38
38
|
}
|
|
39
|
+
async resetDatabase(options) {
|
|
40
|
+
const customersOrm = new customers_orm_1.CustomersOrm({ sqlService: this.opt.sqlService });
|
|
41
|
+
const subscriptionsOrm = new subscriptions_orm_1.SubscriptionsOrm({ sqlService: this.opt.sqlService });
|
|
42
|
+
const subscriptionItemsOrm = new subscription_items_orm_1.SubscriptionItemsOrm({ sqlService: this.opt.sqlService });
|
|
43
|
+
const invoicesOrm = new invoices_orm_1.InvoicesOrm({ sqlService: this.opt.sqlService });
|
|
44
|
+
const invoiceItemsOrm = new invoice_items_orm_1.InvoiceItemsOrm({ sqlService: this.opt.sqlService });
|
|
45
|
+
const paymentsOrm = new invoice_payments_orm_1.InvoicePaymentsOrm({ sqlService: this.opt.sqlService });
|
|
46
|
+
// Child tables first, then parent tables (respect FK ordering)
|
|
47
|
+
const orms = [invoiceItemsOrm, paymentsOrm, invoicesOrm, subscriptionItemsOrm, subscriptionsOrm, customersOrm];
|
|
48
|
+
if (options?.dryRun) {
|
|
49
|
+
const counts = {};
|
|
50
|
+
for (const orm of orms) {
|
|
51
|
+
const rows = await this.opt.sqlService.exec({
|
|
52
|
+
query: `SELECT COUNT(*) AS cnt FROM \`${orm.alias}\``,
|
|
53
|
+
});
|
|
54
|
+
counts[orm.alias] = rows[0]?.cnt ?? 0;
|
|
55
|
+
}
|
|
56
|
+
return { dryRun: true, deleted: counts };
|
|
57
|
+
}
|
|
58
|
+
return await this.opt.sqlService.transaction(async (trx) => {
|
|
59
|
+
const deleted = {};
|
|
60
|
+
trx.query('SET FOREIGN_KEY_CHECKS = 0');
|
|
61
|
+
for (const orm of orms) {
|
|
62
|
+
const res = await trx.query(`DELETE FROM \`${orm.alias}\``);
|
|
63
|
+
deleted[orm.alias] = res?.affectedRows ?? 0;
|
|
64
|
+
}
|
|
65
|
+
await trx.query('SET FOREIGN_KEY_CHECKS = 1');
|
|
66
|
+
return { dryRun: false, deleted };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
39
69
|
async recoverFromMollie(options) {
|
|
40
70
|
const dryRun = options?.dryRun ?? false;
|
|
41
71
|
const mollie = this.client;
|