@stamhoofd/models 2.63.0 → 2.64.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/src/migrations/1605262045-import-postcodes.d.ts +1 -1
- package/dist/src/migrations/1605262045-import-postcodes.js +1 -4
- package/dist/src/migrations/1734429094-registration-trial-until.sql +3 -0
- package/dist/src/migrations/1734429095-membership-trial-until.sql +2 -0
- package/dist/src/migrations/1734535120-registration-period-previous-period-id.sql +3 -0
- package/dist/src/migrations/1734535121-platform-previous-period-id.sql +3 -0
- package/dist/src/migrations/1734626607-cached-balance-amount-open.sql +2 -0
- package/dist/src/migrations/1734698906-cached-balance-amount-paid.sql +2 -0
- package/dist/src/models/BalanceItem.d.ts +2 -2
- package/dist/src/models/BalanceItem.d.ts.map +1 -1
- package/dist/src/models/BalanceItem.js +13 -11
- package/dist/src/models/BalanceItem.js.map +1 -1
- package/dist/src/models/BalanceItemPayment.d.ts +5 -0
- package/dist/src/models/BalanceItemPayment.d.ts.map +1 -1
- package/dist/src/models/BalanceItemPayment.js +15 -0
- package/dist/src/models/BalanceItemPayment.js.map +1 -1
- package/dist/src/models/CachedBalance.d.ts +6 -2
- package/dist/src/models/CachedBalance.d.ts.map +1 -1
- package/dist/src/models/CachedBalance.js +64 -20
- package/dist/src/models/CachedBalance.js.map +1 -1
- package/dist/src/models/DocumentTemplate.d.ts.map +1 -1
- package/dist/src/models/DocumentTemplate.js +36 -9
- package/dist/src/models/DocumentTemplate.js.map +1 -1
- package/dist/src/models/Member.d.ts +3 -7
- package/dist/src/models/Member.d.ts.map +1 -1
- package/dist/src/models/Member.js +2 -41
- package/dist/src/models/Member.js.map +1 -1
- package/dist/src/models/MemberPlatformMembership.d.ts +10 -1
- package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -1
- package/dist/src/models/MemberPlatformMembership.js +79 -5
- package/dist/src/models/MemberPlatformMembership.js.map +1 -1
- package/dist/src/models/MergedMember.d.ts +1 -1
- package/dist/src/models/MergedMember.js +1 -1
- package/dist/src/models/Platform.d.ts +2 -0
- package/dist/src/models/Platform.d.ts.map +1 -1
- package/dist/src/models/Platform.js +9 -1
- package/dist/src/models/Platform.js.map +1 -1
- package/dist/src/models/Registration.d.ts +17 -5
- package/dist/src/models/Registration.d.ts.map +1 -1
- package/dist/src/models/Registration.js +23 -34
- package/dist/src/models/Registration.js.map +1 -1
- package/dist/src/models/RegistrationPeriod.d.ts +7 -0
- package/dist/src/models/RegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/RegistrationPeriod.js +36 -0
- package/dist/src/models/RegistrationPeriod.js.map +1 -1
- package/package.json +2 -2
- package/src/migrations/1605262045-import-postcodes.ts +2 -4
- package/src/migrations/1734429094-registration-trial-until.sql +3 -0
- package/src/migrations/1734429095-membership-trial-until.sql +2 -0
- package/src/migrations/1734535120-registration-period-previous-period-id.sql +3 -0
- package/src/migrations/1734535121-platform-previous-period-id.sql +3 -0
- package/src/migrations/1734626607-cached-balance-amount-open.sql +2 -0
- package/src/migrations/1734698906-cached-balance-amount-paid.sql +2 -0
- package/src/models/BalanceItem.ts +18 -17
- package/src/models/BalanceItemPayment.ts +20 -1
- package/src/models/CachedBalance.ts +88 -23
- package/src/models/DocumentTemplate.ts +39 -9
- package/src/models/Member.ts +2 -48
- package/src/models/MemberPlatformMembership.ts +92 -5
- package/src/models/MergedMember.ts +1 -1
- package/src/models/Platform.ts +9 -1
- package/src/models/Registration.ts +21 -40
- package/src/models/RegistrationPeriod.ts +47 -2
|
@@ -53,6 +53,10 @@ export class Registration extends Model {
|
|
|
53
53
|
@column({ type: 'integer' })
|
|
54
54
|
cycle: number = 0;
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated
|
|
58
|
+
* Moved to cached balances
|
|
59
|
+
*/
|
|
56
60
|
@column({ type: 'integer', nullable: true })
|
|
57
61
|
price: number | null = null;
|
|
58
62
|
|
|
@@ -78,12 +82,27 @@ export class Registration extends Model {
|
|
|
78
82
|
})
|
|
79
83
|
updatedAt: Date;
|
|
80
84
|
|
|
85
|
+
/**
|
|
86
|
+
* The date when the registration was confirmed
|
|
87
|
+
*/
|
|
81
88
|
@column({ type: 'datetime', nullable: true })
|
|
82
89
|
registeredAt: Date | null = null;
|
|
83
90
|
|
|
84
91
|
@column({ type: 'datetime', nullable: true })
|
|
85
92
|
reservedUntil: Date | null = null;
|
|
86
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Start date of the registration. Defaults to the start date of the related group
|
|
96
|
+
*/
|
|
97
|
+
@column({ type: 'datetime', nullable: true })
|
|
98
|
+
startDate: Date | null = null;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* If this registration is under a trial, this is the end date of the trial
|
|
102
|
+
*/
|
|
103
|
+
@column({ type: 'datetime', nullable: true })
|
|
104
|
+
trialUntil: Date | null = null;
|
|
105
|
+
|
|
87
106
|
/**
|
|
88
107
|
* @deprecated - replaced by group type
|
|
89
108
|
*/
|
|
@@ -101,7 +120,8 @@ export class Registration extends Model {
|
|
|
101
120
|
deactivatedAt: Date | null = null;
|
|
102
121
|
|
|
103
122
|
/**
|
|
104
|
-
*
|
|
123
|
+
* @deprecated
|
|
124
|
+
* Moved to cached balances
|
|
105
125
|
*/
|
|
106
126
|
@column({ type: 'integer' })
|
|
107
127
|
pricePaid = 0;
|
|
@@ -122,45 +142,6 @@ export class Registration extends Model {
|
|
|
122
142
|
});
|
|
123
143
|
}
|
|
124
144
|
|
|
125
|
-
/**
|
|
126
|
-
* Update the outstanding balance of multiple members in one go (or all members)
|
|
127
|
-
*/
|
|
128
|
-
static async updateOutstandingBalance(registrationIds: string[] | 'all', organizationId?: string) {
|
|
129
|
-
if (registrationIds !== 'all' && registrationIds.length === 0) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const params: any[] = [];
|
|
134
|
-
let firstWhere = '';
|
|
135
|
-
let secondWhere = '';
|
|
136
|
-
|
|
137
|
-
if (registrationIds !== 'all') {
|
|
138
|
-
firstWhere = ` AND registrationId IN (?)`;
|
|
139
|
-
params.push(registrationIds);
|
|
140
|
-
|
|
141
|
-
secondWhere = `WHERE registrations.id IN (?)`;
|
|
142
|
-
params.push(registrationIds);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const query = `UPDATE
|
|
146
|
-
registrations
|
|
147
|
-
LEFT JOIN (
|
|
148
|
-
SELECT
|
|
149
|
-
registrationId,
|
|
150
|
-
sum(unitPrice * amount) AS price,
|
|
151
|
-
sum(pricePaid) AS pricePaid
|
|
152
|
-
FROM
|
|
153
|
-
balance_items
|
|
154
|
-
WHERE status != 'Hidden'${firstWhere}
|
|
155
|
-
GROUP BY
|
|
156
|
-
registrationId
|
|
157
|
-
) i ON i.registrationId = registrations.id
|
|
158
|
-
SET registrations.price = coalesce(i.price, 0), registrations.pricePaid = coalesce(i.pricePaid, 0)
|
|
159
|
-
${secondWhere}`;
|
|
160
|
-
|
|
161
|
-
await Database.update(query, params);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
145
|
/**
|
|
165
146
|
* Get the number of active members that are currently registered
|
|
166
147
|
* This is used for billing
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { column, Model } from '@simonbackx/simple-database';
|
|
2
|
-
import { SQL, SQLWhereSign } from '@stamhoofd/sql';
|
|
1
|
+
import { column, Model, SQLResultNamespacedRow } from '@simonbackx/simple-database';
|
|
2
|
+
import { SQL, SQLSelect, SQLWhereSign } from '@stamhoofd/sql';
|
|
3
3
|
import { RegistrationPeriodBase, RegistrationPeriodSettings, RegistrationPeriod as RegistrationPeriodStruct } from '@stamhoofd/structures';
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
5
|
|
|
@@ -13,6 +13,9 @@ export class RegistrationPeriod extends Model {
|
|
|
13
13
|
})
|
|
14
14
|
id!: string;
|
|
15
15
|
|
|
16
|
+
@column({ type: 'string', nullable: true })
|
|
17
|
+
previousPeriodId: string | null = null;
|
|
18
|
+
|
|
16
19
|
@column({ type: 'string', nullable: true })
|
|
17
20
|
organizationId: string | null = null;
|
|
18
21
|
|
|
@@ -70,4 +73,46 @@ export class RegistrationPeriod extends Model {
|
|
|
70
73
|
|
|
71
74
|
return RegistrationPeriod.fromRow(result[this.table]) ?? null;
|
|
72
75
|
}
|
|
76
|
+
|
|
77
|
+
async setPreviousPeriodId() {
|
|
78
|
+
const allPeriods = await RegistrationPeriod.where({ organizationId: this.organizationId });
|
|
79
|
+
|
|
80
|
+
// Include self if not yet in database
|
|
81
|
+
if (!this.existsInDatabase) {
|
|
82
|
+
allPeriods.push(this);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Sort by start date
|
|
86
|
+
allPeriods.sort((a, b) => a.startDate.getTime() - b.startDate.getTime());
|
|
87
|
+
|
|
88
|
+
// Take the one before this.periodId
|
|
89
|
+
let previousPeriod: RegistrationPeriod | null = null;
|
|
90
|
+
|
|
91
|
+
for (const period of allPeriods) {
|
|
92
|
+
if (period.id === this.id) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
previousPeriod = period;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.previousPeriodId = previousPeriod?.id ?? null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Experimental: needs to move to library
|
|
103
|
+
*/
|
|
104
|
+
static select() {
|
|
105
|
+
const transformer = (row: SQLResultNamespacedRow): RegistrationPeriod => {
|
|
106
|
+
const d = (this as typeof RegistrationPeriod & typeof Model).fromRow(row[this.table] as any) as RegistrationPeriod | undefined;
|
|
107
|
+
|
|
108
|
+
if (!d) {
|
|
109
|
+
throw new Error('MemberPlatformMembership not found');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return d;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const select = new SQLSelect(transformer, SQL.wildcard());
|
|
116
|
+
return select.from(SQL.table(this.table));
|
|
117
|
+
}
|
|
73
118
|
}
|