@stamhoofd/models 2.6.0 → 2.8.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/factories/RegistrationFactory.d.ts +0 -1
- package/dist/src/factories/RegistrationFactory.d.ts.map +1 -1
- package/dist/src/factories/RegistrationFactory.js +2 -8
- package/dist/src/factories/RegistrationFactory.js.map +1 -1
- package/dist/src/migrations/1722959111-allow-multiple-registrations.sql +2 -0
- package/dist/src/migrations/1722963554-registration-group-price-and-options.sql +3 -0
- package/dist/src/models/BalanceItem.d.ts +4 -0
- package/dist/src/models/BalanceItem.d.ts.map +1 -1
- package/dist/src/models/BalanceItem.js +36 -19
- package/dist/src/models/BalanceItem.js.map +1 -1
- package/dist/src/models/Email.d.ts.map +1 -1
- package/dist/src/models/Email.js +16 -8
- package/dist/src/models/Email.js.map +1 -1
- package/dist/src/models/EmailTemplate.d.ts.map +1 -1
- package/dist/src/models/EmailTemplate.js.map +1 -1
- package/dist/src/models/Event.js +2 -2
- package/dist/src/models/Event.js.map +1 -1
- package/dist/src/models/Member.d.ts +2 -1
- package/dist/src/models/Member.d.ts.map +1 -1
- package/dist/src/models/Member.js +21 -14
- package/dist/src/models/Member.js.map +1 -1
- package/dist/src/models/Registration.d.ts +7 -1
- package/dist/src/models/Registration.d.ts.map +1 -1
- package/dist/src/models/Registration.js +49 -4
- package/dist/src/models/Registration.js.map +1 -1
- package/package.json +2 -2
- package/src/factories/RegistrationFactory.ts +2 -9
- package/src/migrations/1722959111-allow-multiple-registrations.sql +2 -0
- package/src/migrations/1722963554-registration-group-price-and-options.sql +3 -0
- package/src/models/BalanceItem.ts +43 -22
- package/src/models/Email.ts +28 -17
- package/src/models/EmailTemplate.ts +1 -1
- package/src/models/Event.ts +2 -2
- package/src/models/Member.ts +23 -15
- package/src/models/Registration.ts +53 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
2
|
import { Email } from '@stamhoofd/email';
|
|
3
|
-
import { EmailTemplateType, PaymentMethod, PaymentMethodHelper, Recipient, Registration as RegistrationStructure, Replacement, StockReservation } from '@stamhoofd/structures';
|
|
3
|
+
import { EmailTemplateType, GroupPrice, PaymentMethod, PaymentMethodHelper, Recipient, RegisterItemOption, Registration as RegistrationStructure, Replacement, StockReservation } from '@stamhoofd/structures';
|
|
4
4
|
import { Formatter } from '@stamhoofd/utility';
|
|
5
5
|
import { v4 as uuidv4 } from "uuid";
|
|
6
6
|
|
|
@@ -30,6 +30,12 @@ export class Registration extends Model {
|
|
|
30
30
|
|
|
31
31
|
@column({ type: "string", foreignKey: Registration.group})
|
|
32
32
|
groupId: string;
|
|
33
|
+
|
|
34
|
+
@column({ type: "json", decoder: GroupPrice})
|
|
35
|
+
groupPrice: GroupPrice;
|
|
36
|
+
|
|
37
|
+
@column({ type: "json", decoder: new ArrayDecoder(RegisterItemOption) })
|
|
38
|
+
options: RegisterItemOption[] = [];
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
41
|
* @deprecated
|
|
@@ -37,8 +43,11 @@ export class Registration extends Model {
|
|
|
37
43
|
@column({ type: "string", nullable: true })
|
|
38
44
|
paymentId: string | null = null
|
|
39
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated
|
|
48
|
+
*/
|
|
40
49
|
@column({ type: "integer" })
|
|
41
|
-
cycle: number;
|
|
50
|
+
cycle: number = 0;
|
|
42
51
|
|
|
43
52
|
@column({ type: "integer", nullable: true })
|
|
44
53
|
price: number | null = null;
|
|
@@ -173,6 +182,20 @@ export class Registration extends Model {
|
|
|
173
182
|
}
|
|
174
183
|
}
|
|
175
184
|
|
|
185
|
+
async deactivate() {
|
|
186
|
+
if (this.deactivatedAt !== null) {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Clear the registration
|
|
191
|
+
this.deactivatedAt = new Date()
|
|
192
|
+
await this.save()
|
|
193
|
+
this.scheduleStockUpdate()
|
|
194
|
+
|
|
195
|
+
const {Member} = await import('./Member');
|
|
196
|
+
await Member.updateMembershipsForId(this.memberId)
|
|
197
|
+
}
|
|
198
|
+
|
|
176
199
|
async markValid(this: Registration) {
|
|
177
200
|
if (this.registeredAt !== null && this.deactivatedAt === null) {
|
|
178
201
|
await this.save();
|
|
@@ -186,11 +209,13 @@ export class Registration extends Model {
|
|
|
186
209
|
await this.save();
|
|
187
210
|
this.scheduleStockUpdate()
|
|
188
211
|
|
|
212
|
+
const {Member} = await import('./Member');
|
|
213
|
+
await Member.updateMembershipsForId(this.memberId)
|
|
214
|
+
|
|
189
215
|
await this.sendEmailTemplate({
|
|
190
216
|
type: EmailTemplateType.RegistrationConfirmation
|
|
191
217
|
});
|
|
192
218
|
|
|
193
|
-
const {Member} = await import('./Member');
|
|
194
219
|
const member = await Member.getByID(this.memberId);
|
|
195
220
|
if (member) {
|
|
196
221
|
const registrationMemberRelation = new ManyToOneRelation(Member, "member")
|
|
@@ -453,11 +478,33 @@ export class Registration extends Model {
|
|
|
453
478
|
}
|
|
454
479
|
|
|
455
480
|
if (updated.shouldIncludeStock()) {
|
|
456
|
-
const
|
|
481
|
+
const groupStockReservations: StockReservation[] = [
|
|
482
|
+
// Group level stock reservatiosn (stored in the group)
|
|
483
|
+
StockReservation.create({
|
|
484
|
+
objectId: updated.groupPrice.id,
|
|
485
|
+
objectType: 'GroupPrice',
|
|
486
|
+
amount: 1
|
|
487
|
+
}),
|
|
488
|
+
...updated.options.map(o => {
|
|
489
|
+
return StockReservation.create({
|
|
490
|
+
objectId: o.option.id,
|
|
491
|
+
objectType: 'GroupOption',
|
|
492
|
+
amount: o.amount
|
|
493
|
+
})
|
|
494
|
+
})
|
|
495
|
+
]
|
|
457
496
|
|
|
458
|
-
|
|
497
|
+
await Group.applyStockReservations(updated.groupId, groupStockReservations);
|
|
459
498
|
|
|
460
|
-
updated.stockReservations =
|
|
499
|
+
updated.stockReservations = [
|
|
500
|
+
// Global level stock reservations (stored in each group)
|
|
501
|
+
StockReservation.create({
|
|
502
|
+
objectId: updated.groupId,
|
|
503
|
+
objectType: 'Group',
|
|
504
|
+
amount: 1,
|
|
505
|
+
children: groupStockReservations
|
|
506
|
+
})
|
|
507
|
+
];
|
|
461
508
|
await updated.save();
|
|
462
509
|
} else {
|
|
463
510
|
if (updated.stockReservations.length) {
|