@stamhoofd/models 2.1.3 → 2.3.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.
Files changed (39) hide show
  1. package/dist/src/migrations/1720080975-convert-charset.sql +85 -0
  2. package/dist/src/migrations/1720080976-responsibilities.sql +14 -0
  3. package/dist/src/migrations/1720088136-member-membership-types.sql +23 -0
  4. package/dist/src/migrations/1720088137-member-membership-types-expire-date.sql +2 -0
  5. package/dist/src/migrations/1720444931-organization-active.sql +2 -0
  6. package/dist/src/models/Member.d.ts +1 -0
  7. package/dist/src/models/Member.d.ts.map +1 -1
  8. package/dist/src/models/Member.js +71 -0
  9. package/dist/src/models/Member.js.map +1 -1
  10. package/dist/src/models/MemberPlatformMembership.d.ts +19 -0
  11. package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -0
  12. package/dist/src/models/MemberPlatformMembership.js +123 -0
  13. package/dist/src/models/MemberPlatformMembership.js.map +1 -0
  14. package/dist/src/models/Organization.d.ts +2 -1
  15. package/dist/src/models/Organization.d.ts.map +1 -1
  16. package/dist/src/models/Organization.js +4 -0
  17. package/dist/src/models/Organization.js.map +1 -1
  18. package/dist/src/models/Registration.d.ts.map +1 -1
  19. package/dist/src/models/Registration.js +4 -0
  20. package/dist/src/models/Registration.js.map +1 -1
  21. package/dist/src/models/STInvoice.d.ts.map +1 -1
  22. package/dist/src/models/STInvoice.js +1 -0
  23. package/dist/src/models/STInvoice.js.map +1 -1
  24. package/dist/src/models/index.d.ts +1 -0
  25. package/dist/src/models/index.d.ts.map +1 -1
  26. package/dist/src/models/index.js +1 -0
  27. package/dist/src/models/index.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/migrations/1720080975-convert-charset.sql +85 -0
  30. package/src/migrations/1720080976-responsibilities.sql +14 -0
  31. package/src/migrations/1720088136-member-membership-types.sql +23 -0
  32. package/src/migrations/1720088137-member-membership-types-expire-date.sql +2 -0
  33. package/src/migrations/1720444931-organization-active.sql +2 -0
  34. package/src/models/Member.ts +86 -2
  35. package/src/models/MemberPlatformMembership.ts +122 -0
  36. package/src/models/Organization.ts +4 -2
  37. package/src/models/Registration.ts +6 -0
  38. package/src/models/STInvoice.ts +2 -0
  39. package/src/models/index.ts +1 -0
@@ -0,0 +1,122 @@
1
+
2
+ import { column, Model } from "@simonbackx/simple-database";
3
+ import { v4 as uuidv4 } from "uuid";
4
+ import { Platform } from "./Platform";
5
+ import { PlatformMembershipTypeBehaviour } from "@stamhoofd/structures";
6
+ import { SimpleError } from "@simonbackx/simple-errors";
7
+ import { Formatter } from "@stamhoofd/utility";
8
+
9
+ export class MemberPlatformMembership extends Model {
10
+ static table = "member_platform_memberships";
11
+
12
+ // Columns
13
+ @column({
14
+ primary: true, type: "string", beforeSave(value) {
15
+ return value ?? uuidv4();
16
+ }
17
+ })
18
+ id!: string;
19
+
20
+ @column({ type: "string" })
21
+ memberId: string;
22
+
23
+ @column({ type: "string" })
24
+ membershipTypeId: string;
25
+
26
+ @column({ type: "string" })
27
+ organizationId: string;
28
+
29
+ @column({ type: "string" })
30
+ periodId: string;
31
+
32
+ @column({ type: "date" })
33
+ startDate: Date;
34
+
35
+ @column({ type: "date" })
36
+ endDate: Date;
37
+
38
+ @column({ type: "date", nullable: true})
39
+ expireDate: Date | null = null;
40
+
41
+ @column({ type: "string", nullable: true })
42
+ invoiceItemDetailId: string | null = null;
43
+
44
+ @column({ type: "string", nullable: true })
45
+ invoiceId: string | null = null;
46
+
47
+ @column({ type: "integer" })
48
+ price = 0;
49
+
50
+ @column({
51
+ type: "datetime", beforeSave(old?: any) {
52
+ if (old !== undefined) {
53
+ return old;
54
+ }
55
+ const date = new Date()
56
+ date.setMilliseconds(0)
57
+ return date
58
+ }
59
+ })
60
+ createdAt: Date
61
+
62
+ @column({
63
+ type: "datetime", beforeSave() {
64
+ const date = new Date()
65
+ date.setMilliseconds(0)
66
+ return date
67
+ },
68
+ skipUpdate: true
69
+ })
70
+ updatedAt: Date
71
+
72
+
73
+ async calculatePrice() {
74
+ if (this.invoiceId || this.invoiceItemDetailId) {
75
+ return;
76
+ }
77
+
78
+ const platform = await Platform.getShared();
79
+ const membershipType = platform.config.membershipTypes.find(m => m.id == this.membershipTypeId);
80
+
81
+ if (!membershipType) {
82
+ throw new SimpleError({
83
+ code: 'invalid_membership_type',
84
+ message: 'Uknown membership type',
85
+ human: 'Deze aansluiting is niet (meer) beschikbaar'
86
+ })
87
+ }
88
+
89
+ const periodConfig = membershipType.periods.get(this.periodId)
90
+
91
+ if (!periodConfig) {
92
+ throw new SimpleError({
93
+ code: 'period_unavailable',
94
+ message: 'Membership not available for this period',
95
+ human: 'Deze aansluiting is nog niet beschikbaar voor dit werkjaar'
96
+ })
97
+ }
98
+
99
+ const priceConfig = periodConfig.getPriceForDate(membershipType.behaviour === PlatformMembershipTypeBehaviour.Days ? this.startDate : (this.createdAt ?? new Date()));
100
+
101
+
102
+ if (membershipType.behaviour === PlatformMembershipTypeBehaviour.Days) {
103
+ // Make sure time is equal between start and end date
104
+ let startBrussels = Formatter.luxon(this.startDate);
105
+ let endBrussels = Formatter.luxon(this.endDate);
106
+ startBrussels = startBrussels.set({hour: 0, minute: 0, second: 0, millisecond: 0});
107
+ endBrussels = endBrussels.set({hour: 23, minute: 59, second: 59, millisecond: 0});
108
+ this.startDate = startBrussels.toJSDate();
109
+ this.endDate = endBrussels.toJSDate();
110
+
111
+ this.expireDate = null
112
+
113
+ const days = Math.round((this.endDate.getTime() - this.startDate.getTime()) / (1000 * 60 * 60 * 24));
114
+ this.price = priceConfig.pricePerDay * days + priceConfig.price;
115
+ } else {
116
+ this.price = priceConfig.price;
117
+ this.startDate = periodConfig.startDate;
118
+ this.endDate = periodConfig.endDate;
119
+ this.expireDate = periodConfig.expireDate;
120
+ }
121
+ }
122
+ }
@@ -3,8 +3,7 @@ import { DecodedRequest } from '@simonbackx/simple-endpoints';
3
3
  import { SimpleError } from '@simonbackx/simple-errors';
4
4
  import { I18n } from "@stamhoofd/backend-i18n";
5
5
  import { Email, EmailInterfaceRecipient } from "@stamhoofd/email";
6
- import { OrganizationRegistrationPeriod as OrganizationRegistrationPeriodStruct, Address, Country, DNSRecordStatus, EmailTemplateType, Organization as OrganizationStruct, OrganizationEmail, OrganizationMetaData, OrganizationPrivateMetaData, OrganizationRecordsConfiguration, PaymentMethod, PaymentProvider, PrivatePaymentConfiguration, Recipient, Replacement, STPackageType, TransferSettings } from "@stamhoofd/structures";
7
- import { Formatter } from "@stamhoofd/utility";
6
+ import { Address, Country, DNSRecordStatus, EmailTemplateType, OrganizationEmail, OrganizationMetaData, OrganizationPrivateMetaData, OrganizationRecordsConfiguration, OrganizationRegistrationPeriod as OrganizationRegistrationPeriodStruct, Organization as OrganizationStruct, PaymentMethod, PaymentProvider, PrivatePaymentConfiguration, Recipient, Replacement, STPackageType, TransferSettings } from "@stamhoofd/structures";
8
7
  import { AWSError } from 'aws-sdk';
9
8
  import SES from 'aws-sdk/clients/sesv2';
10
9
  import { PromiseResult } from 'aws-sdk/lib/request';
@@ -95,6 +94,9 @@ export class Organization extends Model {
95
94
  })
96
95
  updatedAt: Date
97
96
 
97
+ @column({type: 'boolean'})
98
+ active = true;
99
+
98
100
  /**
99
101
  * Return default locale confiruation
100
102
  */
@@ -167,8 +167,14 @@ export class Registration extends Model {
167
167
  await this.save();
168
168
  return false;
169
169
  }
170
+
171
+ if (this.waitingList && this.canRegister) {
172
+ this.waitingList = false
173
+ }
174
+
170
175
  this.reservedUntil = null
171
176
  this.registeredAt = new Date()
177
+ this.canRegister = false
172
178
  await this.save();
173
179
 
174
180
  await this.sendEmailTemplate({
@@ -305,6 +305,8 @@ export class STInvoice extends Model {
305
305
  await code.reward()
306
306
  }
307
307
  }
308
+
309
+ // todo: link member_membership items to this newly created invoice
308
310
  }
309
311
 
310
312
  async assignNextNumber() {
@@ -47,3 +47,4 @@ export * from "./MemberResponsibilityRecord"
47
47
 
48
48
  export * from "./OrganizationRegistrationPeriod"
49
49
  export * from "./RegistrationPeriod"
50
+ export * from "./MemberPlatformMembership"