@stamhoofd/models 2.140.0 → 2.142.0
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/migrations/1785854600-settlements-table.sql +27 -0
- package/dist/migrations/1785854601-payment-settlements-table.sql +15 -0
- package/dist/migrations/1785854602-settlement-charges-table.sql +31 -0
- package/dist/migrations/1786443124-application-fees-table.sql +33 -0
- package/dist/migrations/1786443125-settlement-charges-drop-balance-item-id.sql +4 -0
- package/dist/migrations/1786443126-settlements-pending-fees.sql +2 -0
- package/dist/migrations/1786443128-settlement-charges-drop-orphaned.sql +1 -0
- package/dist/migrations/1786443129-settlement-charges-drop-organization-id-fk.sql +2 -0
- package/dist/migrations/1786443130-settlement-charges-organization-id-required.sql +1 -0
- package/dist/migrations/1786443131-settlement-charges-organization-id-fk.sql +1 -0
- package/dist/migrations/1786513670-payment-settlements-external-id-nullable.sql +1 -0
- package/dist/migrations/1786516131-payment-settlements-truncate.sql +3 -0
- package/dist/migrations/1786516132-payment-settlements-organization-id.sql +1 -0
- package/dist/migrations/1786516133-payment-settlements-organization-id-fk.sql +1 -0
- package/dist/migrations/1786534200-application-fees-drop-paying-organization-fk.sql +3 -0
- package/dist/migrations/1786534201-application-fees-drop-settlement-charge-fk.sql +1 -0
- package/dist/migrations/1786534202-application-fees-paying-organization-nullable.sql +1 -0
- package/dist/migrations/1786534203-application-fees-settlement-charge-nullable.sql +1 -0
- package/dist/migrations/1786534204-application-fees-paying-organization-fk.sql +1 -0
- package/dist/migrations/1786534205-application-fees-settlement-charge-fk.sql +3 -0
- package/dist/migrations/1786534206-settlements-uncollectible-fees.sql +1 -0
- package/dist/models/ApplicationFee.d.ts +67 -0
- package/dist/models/ApplicationFee.d.ts.map +1 -0
- package/dist/models/ApplicationFee.js +131 -0
- package/dist/models/ApplicationFee.js.map +1 -0
- package/dist/models/Payment.d.ts +15 -3
- package/dist/models/Payment.d.ts.map +1 -1
- package/dist/models/Payment.js +46 -4
- package/dist/models/Payment.js.map +1 -1
- package/dist/models/PaymentSettlement.d.ts +32 -0
- package/dist/models/PaymentSettlement.d.ts.map +1 -0
- package/dist/models/PaymentSettlement.js +82 -0
- package/dist/models/PaymentSettlement.js.map +1 -0
- package/dist/models/Settlement.d.ts +60 -0
- package/dist/models/Settlement.d.ts.map +1 -0
- package/dist/models/Settlement.js +136 -0
- package/dist/models/Settlement.js.map +1 -0
- package/dist/models/SettlementCharge.d.ts +51 -0
- package/dist/models/SettlementCharge.d.ts.map +1 -0
- package/dist/models/SettlementCharge.js +115 -0
- package/dist/models/SettlementCharge.js.map +1 -0
- package/dist/models/StripeAccount.d.ts +1 -1
- package/dist/models/StripeAccount.d.ts.map +1 -1
- package/dist/models/StripeAccount.js.map +1 -1
- package/dist/models/User.d.ts.map +1 -1
- package/dist/models/User.js +14 -0
- package/dist/models/User.js.map +1 -1
- package/package.json +3 -3
- package/src/migrations/1785854600-settlements-table.sql +27 -0
- package/src/migrations/1785854601-payment-settlements-table.sql +15 -0
- package/src/migrations/1785854602-settlement-charges-table.sql +31 -0
- package/src/migrations/1786443124-application-fees-table.sql +33 -0
- package/src/migrations/1786443125-settlement-charges-drop-balance-item-id.sql +4 -0
- package/src/migrations/1786443126-settlements-pending-fees.sql +2 -0
- package/src/migrations/1786443128-settlement-charges-drop-orphaned.sql +1 -0
- package/src/migrations/1786443129-settlement-charges-drop-organization-id-fk.sql +2 -0
- package/src/migrations/1786443130-settlement-charges-organization-id-required.sql +1 -0
- package/src/migrations/1786443131-settlement-charges-organization-id-fk.sql +1 -0
- package/src/migrations/1786513670-payment-settlements-external-id-nullable.sql +1 -0
- package/src/migrations/1786516131-payment-settlements-truncate.sql +3 -0
- package/src/migrations/1786516132-payment-settlements-organization-id.sql +1 -0
- package/src/migrations/1786516133-payment-settlements-organization-id-fk.sql +1 -0
- package/src/migrations/1786534200-application-fees-drop-paying-organization-fk.sql +3 -0
- package/src/migrations/1786534201-application-fees-drop-settlement-charge-fk.sql +1 -0
- package/src/migrations/1786534202-application-fees-paying-organization-nullable.sql +1 -0
- package/src/migrations/1786534203-application-fees-settlement-charge-nullable.sql +1 -0
- package/src/migrations/1786534204-application-fees-paying-organization-fk.sql +1 -0
- package/src/migrations/1786534205-application-fees-settlement-charge-fk.sql +3 -0
- package/src/migrations/1786534206-settlements-uncollectible-fees.sql +1 -0
- package/src/models/ApplicationFee.ts +117 -0
- package/src/models/Payment.ts +55 -5
- package/src/models/PaymentSettlement.ts +72 -0
- package/src/models/Settlement.ts +118 -0
- package/src/models/SettlementCharge.ts +101 -0
- package/src/models/StripeAccount.ts +1 -1
- package/src/models/User.ts +26 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { column } from '@simonbackx/simple-database';
|
|
2
|
+
import { QueryableModel } from '@stamhoofd/sql';
|
|
3
|
+
import type { SettlementChargeType } from '@stamhoofd/structures/settlements/SettlementChargeType.js';
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Every charge in a settlement that is not a payment: application fee deductions on the payer's
|
|
8
|
+
* payout, provider fees, VAT, transfers, reserves and disputes.
|
|
9
|
+
*/
|
|
10
|
+
export class SettlementCharge extends QueryableModel {
|
|
11
|
+
static table = 'settlement_charges';
|
|
12
|
+
|
|
13
|
+
@column({
|
|
14
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
15
|
+
return value ?? uuidv4();
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
id!: string;
|
|
19
|
+
|
|
20
|
+
@column({ type: 'string' })
|
|
21
|
+
type: SettlementChargeType;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Globally unique, deterministic id so every sync can upsert. Fee rows use `<feeId>:<type>`,
|
|
25
|
+
* other rows the provider's transaction id (txn_…, txn_…:fee:<i>, fr_…).
|
|
26
|
+
*/
|
|
27
|
+
@column({ type: 'string' })
|
|
28
|
+
externalId: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Signed effect on the `settlementId` payout.
|
|
32
|
+
*/
|
|
33
|
+
@column({ type: 'integer' })
|
|
34
|
+
amount = 0;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The payout containing this charge. NULL until that payout is synced.
|
|
38
|
+
*/
|
|
39
|
+
@column({ type: 'string', nullable: true })
|
|
40
|
+
settlementId: string | null = null;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Stripe fee_… id: links the deduction rows on the organization payout to the application_fees
|
|
44
|
+
* rows of the same application fee.
|
|
45
|
+
*/
|
|
46
|
+
@column({ type: 'string', nullable: true })
|
|
47
|
+
applicationFeeId: string | null = null;
|
|
48
|
+
|
|
49
|
+
@column({ type: 'string', nullable: true })
|
|
50
|
+
paymentId: string | null = null;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The organization that was charged. Always the organization of the payout it is deducted
|
|
54
|
+
* from, and of the payment it relates to: a charge never crosses organizations.
|
|
55
|
+
*/
|
|
56
|
+
@column({ type: 'string' })
|
|
57
|
+
organizationId: string;
|
|
58
|
+
|
|
59
|
+
@column({ type: 'string', nullable: true })
|
|
60
|
+
stripeAccountId: string | null = null;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Which invoice bills this fee to the charged party: Mollie's real invoice id (inv_…), the
|
|
64
|
+
* derived `stripe-YYYY-MM` for Stripe provider fees, or the Stamhoofd invoice number for
|
|
65
|
+
* application fee deductions.
|
|
66
|
+
*/
|
|
67
|
+
@column({ type: 'string', nullable: true })
|
|
68
|
+
providerInvoiceId: string | null = null;
|
|
69
|
+
|
|
70
|
+
@column({ type: 'string' })
|
|
71
|
+
description = '';
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* When the provider created the charge. For application fees this drives the monthly
|
|
75
|
+
* invoice grouping.
|
|
76
|
+
*/
|
|
77
|
+
@column({ type: 'datetime' })
|
|
78
|
+
occurredAt: Date;
|
|
79
|
+
|
|
80
|
+
@column({
|
|
81
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
82
|
+
if (old !== undefined) {
|
|
83
|
+
return old;
|
|
84
|
+
}
|
|
85
|
+
const date = new Date();
|
|
86
|
+
date.setMilliseconds(0);
|
|
87
|
+
return date;
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
createdAt: Date;
|
|
91
|
+
|
|
92
|
+
@column({
|
|
93
|
+
type: 'datetime', beforeSave() {
|
|
94
|
+
const date = new Date();
|
|
95
|
+
date.setMilliseconds(0);
|
|
96
|
+
return date;
|
|
97
|
+
},
|
|
98
|
+
skipUpdate: true,
|
|
99
|
+
})
|
|
100
|
+
updatedAt: Date;
|
|
101
|
+
}
|
|
@@ -27,7 +27,7 @@ export class StripeAccount extends QueryableModel {
|
|
|
27
27
|
meta = StripeMetaData.create({});
|
|
28
28
|
|
|
29
29
|
@column({ type: 'string' })
|
|
30
|
-
status: 'active' | 'deleted' = 'active';
|
|
30
|
+
status: 'active' | 'deleted' | 'inaccessible' = 'active';
|
|
31
31
|
|
|
32
32
|
@column({
|
|
33
33
|
type: 'datetime', beforeSave(old?: any) {
|
package/src/models/User.ts
CHANGED
|
@@ -191,6 +191,32 @@ export class User extends QueryableModel {
|
|
|
191
191
|
// Hide api accounts
|
|
192
192
|
global = global.filter(a => !a.isApiUser);
|
|
193
193
|
|
|
194
|
+
{
|
|
195
|
+
// Also load global admins with explicit permissions set
|
|
196
|
+
const q = User.select()
|
|
197
|
+
.where('organizationId', null)
|
|
198
|
+
.where('permissions', '!=', null)
|
|
199
|
+
.where(
|
|
200
|
+
SQL.jsonOverlaps(
|
|
201
|
+
SQL.jsonKeys(SQL.jsonExtract(SQL.column('permissions'), '$.value.organizationPermissions')),
|
|
202
|
+
SQL.cast(SQL.scalar(JSON.stringify(Array.isArray(organizationId) ? organizationId : [organizationId])), 'JSON'),
|
|
203
|
+
),
|
|
204
|
+
'=',
|
|
205
|
+
1,
|
|
206
|
+
)
|
|
207
|
+
;
|
|
208
|
+
|
|
209
|
+
if (options?.verified !== undefined) {
|
|
210
|
+
q.where('verified', options.verified);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let xtra = await q.fetch();
|
|
214
|
+
// Hide api accounts
|
|
215
|
+
xtra = xtra.filter(a => !a.isApiUser);
|
|
216
|
+
|
|
217
|
+
global.push(...xtra);
|
|
218
|
+
}
|
|
219
|
+
|
|
194
220
|
return global;
|
|
195
221
|
}
|
|
196
222
|
|