@stamhoofd/models 2.39.0 → 2.40.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/AddressFactory.d.ts +3 -4
- package/dist/src/factories/AddressFactory.d.ts.map +1 -1
- package/dist/src/factories/AddressFactory.js +13 -13
- package/dist/src/factories/EmergencyContactFactory.d.ts +3 -4
- package/dist/src/factories/EmergencyContactFactory.d.ts.map +1 -1
- package/dist/src/factories/EmergencyContactFactory.js +27 -27
- package/dist/src/factories/EmergencyContactFactory.js.map +1 -1
- package/dist/src/factories/GroupFactory.d.ts +4 -4
- package/dist/src/factories/GroupFactory.d.ts.map +1 -1
- package/dist/src/factories/GroupFactory.js +8 -8
- package/dist/src/factories/GroupFactory.js.map +1 -1
- package/dist/src/factories/MemberFactory.d.ts +4 -4
- package/dist/src/factories/MemberFactory.d.ts.map +1 -1
- package/dist/src/factories/MemberFactory.js +17 -17
- package/dist/src/factories/MemberFactory.js.map +1 -1
- package/dist/src/factories/OrganizationFactory.d.ts +4 -4
- package/dist/src/factories/OrganizationFactory.js +8 -8
- package/dist/src/factories/OrganizationFactory.js.map +1 -1
- package/dist/src/factories/ParentFactory.d.ts +1 -1
- package/dist/src/factories/ParentFactory.js +19 -19
- package/dist/src/factories/ParentFactory.js.map +1 -1
- package/dist/src/factories/RecordFactory.d.ts +2 -3
- package/dist/src/factories/RecordFactory.d.ts.map +1 -1
- package/dist/src/factories/RecordFactory.js +1 -1
- package/dist/src/factories/RecordFactory.js.map +1 -1
- package/dist/src/factories/RegisterCodeFactory.d.ts +2 -2
- package/dist/src/factories/RegisterCodeFactory.d.ts.map +1 -1
- package/dist/src/factories/RegisterCodeFactory.js +2 -2
- package/dist/src/factories/RegistrationFactory.d.ts +3 -3
- package/dist/src/factories/RegistrationFactory.d.ts.map +1 -1
- package/dist/src/factories/RegistrationFactory.js.map +1 -1
- package/dist/src/factories/RegistrationPeriodFactory.d.ts +2 -2
- package/dist/src/factories/RegistrationPeriodFactory.js.map +1 -1
- package/dist/src/factories/UserFactory.d.ts +3 -3
- package/dist/src/factories/UserFactory.d.ts.map +1 -1
- package/dist/src/factories/UserFactory.js +3 -3
- package/dist/src/factories/UserFactory.js.map +1 -1
- package/dist/src/factories/WebshopFactory.d.ts +4 -4
- package/dist/src/factories/WebshopFactory.d.ts.map +1 -1
- package/dist/src/factories/WebshopFactory.js +1 -1
- package/dist/src/factories/WebshopFactory.js.map +1 -1
- package/dist/src/helpers/DNSValidator.d.ts +1 -1
- package/dist/src/helpers/DNSValidator.d.ts.map +1 -1
- package/dist/src/helpers/DNSValidator.js +33 -33
- package/dist/src/helpers/DNSValidator.js.map +1 -1
- package/dist/src/helpers/EmailBuilder.d.ts +10 -10
- package/dist/src/helpers/EmailBuilder.d.ts.map +1 -1
- package/dist/src/helpers/EmailBuilder.js +34 -34
- package/dist/src/helpers/EmailBuilder.js.map +1 -1
- package/dist/src/helpers/GroupBuilder.d.ts.map +1 -1
- package/dist/src/helpers/GroupBuilder.js +57 -57
- package/dist/src/helpers/GroupBuilder.js.map +1 -1
- package/dist/src/helpers/Handlebars.d.ts.map +1 -1
- package/dist/src/helpers/Handlebars.js +29 -29
- package/dist/src/helpers/Handlebars.js.map +1 -1
- package/dist/src/helpers/MemberMerger.d.ts +1 -1
- package/dist/src/helpers/MemberMerger.d.ts.map +1 -1
- package/dist/src/helpers/MemberMerger.js +33 -33
- package/dist/src/helpers/MemberMerger.js.map +1 -1
- package/dist/src/helpers/MemberMerger.test.js +194 -194
- package/dist/src/helpers/MemberMerger.test.js.map +1 -1
- package/dist/src/helpers/RateLimiter.d.ts.map +1 -1
- package/dist/src/helpers/RateLimiter.js +2 -2
- package/dist/src/helpers/RateLimiter.js.map +1 -1
- package/dist/src/helpers/SetupStepsUpdater.d.ts +22 -0
- package/dist/src/helpers/SetupStepsUpdater.d.ts.map +1 -0
- package/dist/src/helpers/SetupStepsUpdater.js +255 -0
- package/dist/src/helpers/SetupStepsUpdater.js.map +1 -0
- package/dist/src/helpers/WebshopCounter.d.ts +1 -1
- package/dist/src/helpers/WebshopCounter.d.ts.map +1 -1
- package/dist/src/helpers/WebshopCounter.js +1 -1
- package/dist/src/helpers/WebshopCounter.js.map +1 -1
- package/dist/src/helpers/WebshopCounter.test.js +6 -6
- package/dist/src/helpers/WebshopCounter.test.js.map +1 -1
- package/dist/src/index.d.ts +20 -19
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/migrations/1605262045-import-postcodes.js +12 -12
- package/dist/src/migrations/1605262046-import-postcodes-nl.js +10 -10
- package/dist/src/models/BalanceItem.d.ts.map +1 -1
- package/dist/src/models/BalanceItem.js +37 -37
- package/dist/src/models/BalanceItem.js.map +1 -1
- package/dist/src/models/BalanceItemPayment.d.ts.map +1 -1
- package/dist/src/models/BalanceItemPayment.js +13 -13
- package/dist/src/models/BalanceItemPayment.js.map +1 -1
- package/dist/src/models/BuckarooPayment.d.ts +1 -1
- package/dist/src/models/BuckarooPayment.d.ts.map +1 -1
- package/dist/src/models/BuckarooPayment.js +5 -5
- package/dist/src/models/BuckarooPayment.js.map +1 -1
- package/dist/src/models/CachedOutstandingBalance.d.ts.map +1 -1
- package/dist/src/models/CachedOutstandingBalance.js +37 -37
- package/dist/src/models/CachedOutstandingBalance.js.map +1 -1
- package/dist/src/models/Document.d.ts +4 -4
- package/dist/src/models/Document.d.ts.map +1 -1
- package/dist/src/models/Document.js +27 -27
- package/dist/src/models/Document.js.map +1 -1
- package/dist/src/models/DocumentTemplate.d.ts +4 -4
- package/dist/src/models/DocumentTemplate.d.ts.map +1 -1
- package/dist/src/models/DocumentTemplate.js +72 -72
- package/dist/src/models/DocumentTemplate.js.map +1 -1
- package/dist/src/models/Email.d.ts.map +1 -1
- package/dist/src/models/Email.js +63 -64
- package/dist/src/models/Email.js.map +1 -1
- package/dist/src/models/EmailRecipient.d.ts.map +1 -1
- package/dist/src/models/EmailRecipient.js +20 -20
- package/dist/src/models/EmailRecipient.js.map +1 -1
- package/dist/src/models/EmailTemplate.d.ts +3 -3
- package/dist/src/models/EmailTemplate.d.ts.map +1 -1
- package/dist/src/models/EmailTemplate.js +16 -16
- package/dist/src/models/EmailTemplate.js.map +1 -1
- package/dist/src/models/EmailVerificationCode.d.ts +2 -2
- package/dist/src/models/EmailVerificationCode.d.ts.map +1 -1
- package/dist/src/models/EmailVerificationCode.js +57 -55
- package/dist/src/models/EmailVerificationCode.js.map +1 -1
- package/dist/src/models/Event.d.ts +2 -2
- package/dist/src/models/Event.d.ts.map +1 -1
- package/dist/src/models/Event.js +15 -15
- package/dist/src/models/Event.js.map +1 -1
- package/dist/src/models/Group.d.ts +3 -1
- package/dist/src/models/Group.d.ts.map +1 -1
- package/dist/src/models/Group.js +46 -35
- package/dist/src/models/Group.js.map +1 -1
- package/dist/src/models/Image.d.ts +1 -1
- package/dist/src/models/Image.d.ts.map +1 -1
- package/dist/src/models/Image.js +26 -26
- package/dist/src/models/Image.js.map +1 -1
- package/dist/src/models/Member.d.ts +8 -8
- package/dist/src/models/Member.d.ts.map +1 -1
- package/dist/src/models/Member.js +60 -60
- package/dist/src/models/Member.js.map +1 -1
- package/dist/src/models/MemberPlatformMembership.d.ts +3 -3
- package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -1
- package/dist/src/models/MemberPlatformMembership.js +26 -26
- package/dist/src/models/MemberPlatformMembership.js.map +1 -1
- package/dist/src/models/MemberResponsibilityRecord.d.ts.map +1 -1
- package/dist/src/models/MemberResponsibilityRecord.js +13 -13
- package/dist/src/models/MemberResponsibilityRecord.js.map +1 -1
- package/dist/src/models/MergedMember.d.ts +3 -3
- package/dist/src/models/MergedMember.d.ts.map +1 -1
- package/dist/src/models/MergedMember.js +19 -19
- package/dist/src/models/MergedMember.js.map +1 -1
- package/dist/src/models/MolliePayment.d.ts +1 -1
- package/dist/src/models/MolliePayment.d.ts.map +1 -1
- package/dist/src/models/MolliePayment.js +5 -5
- package/dist/src/models/MolliePayment.js.map +1 -1
- package/dist/src/models/MollieToken.d.ts.map +1 -1
- package/dist/src/models/MollieToken.js +60 -60
- package/dist/src/models/MollieToken.js.map +1 -1
- package/dist/src/models/OneTimeToken.d.ts +2 -2
- package/dist/src/models/OneTimeToken.d.ts.map +1 -1
- package/dist/src/models/OneTimeToken.js +13 -13
- package/dist/src/models/OneTimeToken.js.map +1 -1
- package/dist/src/models/Order.d.ts +1 -1
- package/dist/src/models/Order.d.ts.map +1 -1
- package/dist/src/models/Order.js +70 -70
- package/dist/src/models/Order.js.map +1 -1
- package/dist/src/models/Organization.d.ts +5 -5
- package/dist/src/models/Organization.d.ts.map +1 -1
- package/dist/src/models/Organization.js +127 -127
- package/dist/src/models/Organization.js.map +1 -1
- package/dist/src/models/OrganizationRegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/OrganizationRegistrationPeriod.js +15 -15
- package/dist/src/models/OrganizationRegistrationPeriod.js.map +1 -1
- package/dist/src/models/PasswordToken.d.ts +3 -3
- package/dist/src/models/PasswordToken.d.ts.map +1 -1
- package/dist/src/models/PasswordToken.js +17 -17
- package/dist/src/models/PasswordToken.js.map +1 -1
- package/dist/src/models/PayconiqPayment.d.ts +1 -1
- package/dist/src/models/PayconiqPayment.d.ts.map +1 -1
- package/dist/src/models/PayconiqPayment.js +49 -49
- package/dist/src/models/PayconiqPayment.js.map +1 -1
- package/dist/src/models/Payment.d.ts +3 -3
- package/dist/src/models/Payment.d.ts.map +1 -1
- package/dist/src/models/Payment.js +36 -36
- package/dist/src/models/Payment.js.map +1 -1
- package/dist/src/models/Platform.d.ts +2 -2
- package/dist/src/models/Platform.d.ts.map +1 -1
- package/dist/src/models/Platform.js +8 -8
- package/dist/src/models/Platform.js.map +1 -1
- package/dist/src/models/RegisterCode.d.ts +1 -1
- package/dist/src/models/RegisterCode.d.ts.map +1 -1
- package/dist/src/models/RegisterCode.js +11 -11
- package/dist/src/models/RegisterCode.js.map +1 -1
- package/dist/src/models/Registration.d.ts +1 -1
- package/dist/src/models/Registration.d.ts.map +1 -1
- package/dist/src/models/Registration.js +88 -88
- package/dist/src/models/Registration.js.map +1 -1
- package/dist/src/models/RegistrationPeriod.d.ts.map +1 -1
- package/dist/src/models/RegistrationPeriod.js +12 -12
- package/dist/src/models/RegistrationPeriod.js.map +1 -1
- package/dist/src/models/STCredit.d.ts +1 -1
- package/dist/src/models/STCredit.d.ts.map +1 -1
- package/dist/src/models/STCredit.js +12 -12
- package/dist/src/models/STCredit.js.map +1 -1
- package/dist/src/models/STInvoice.d.ts +1 -1
- package/dist/src/models/STInvoice.d.ts.map +1 -1
- package/dist/src/models/STInvoice.js +16 -16
- package/dist/src/models/STInvoice.js.map +1 -1
- package/dist/src/models/STPackage.d.ts +1 -1
- package/dist/src/models/STPackage.d.ts.map +1 -1
- package/dist/src/models/STPackage.js +39 -39
- package/dist/src/models/STPackage.js.map +1 -1
- package/dist/src/models/STPendingInvoice.d.ts +1 -1
- package/dist/src/models/STPendingInvoice.d.ts.map +1 -1
- package/dist/src/models/STPendingInvoice.js +11 -11
- package/dist/src/models/STPendingInvoice.js.map +1 -1
- package/dist/src/models/StripeAccount.d.ts.map +1 -1
- package/dist/src/models/StripeAccount.js +13 -13
- package/dist/src/models/StripeAccount.js.map +1 -1
- package/dist/src/models/StripeCheckoutSession.d.ts +1 -1
- package/dist/src/models/StripeCheckoutSession.d.ts.map +1 -1
- package/dist/src/models/StripeCheckoutSession.js +7 -7
- package/dist/src/models/StripeCheckoutSession.js.map +1 -1
- package/dist/src/models/StripePaymentIntent.d.ts +1 -1
- package/dist/src/models/StripePaymentIntent.d.ts.map +1 -1
- package/dist/src/models/StripePaymentIntent.js +7 -7
- package/dist/src/models/StripePaymentIntent.js.map +1 -1
- package/dist/src/models/Ticket.d.ts +2 -2
- package/dist/src/models/Ticket.d.ts.map +1 -1
- package/dist/src/models/Ticket.js +23 -23
- package/dist/src/models/Ticket.js.map +1 -1
- package/dist/src/models/Token.d.ts +3 -3
- package/dist/src/models/Token.d.ts.map +1 -1
- package/dist/src/models/Token.js +27 -27
- package/dist/src/models/Token.js.map +1 -1
- package/dist/src/models/Token.test.js +11 -11
- package/dist/src/models/UsedRegisterCode.d.ts +1 -1
- package/dist/src/models/UsedRegisterCode.d.ts.map +1 -1
- package/dist/src/models/UsedRegisterCode.js +10 -10
- package/dist/src/models/UsedRegisterCode.js.map +1 -1
- package/dist/src/models/User.d.ts +4 -4
- package/dist/src/models/User.d.ts.map +1 -1
- package/dist/src/models/User.js +53 -51
- package/dist/src/models/User.js.map +1 -1
- package/dist/src/models/UserPermissions.d.ts +3 -3
- package/dist/src/models/UserPermissions.d.ts.map +1 -1
- package/dist/src/models/UserPermissions.js +12 -12
- package/dist/src/models/UserPermissions.js.map +1 -1
- package/dist/src/models/Webshop.d.ts +1 -1
- package/dist/src/models/Webshop.d.ts.map +1 -1
- package/dist/src/models/Webshop.js +23 -23
- package/dist/src/models/Webshop.js.map +1 -1
- package/dist/src/models/WebshopDiscountCode.d.ts +1 -1
- package/dist/src/models/WebshopDiscountCode.d.ts.map +1 -1
- package/dist/src/models/WebshopDiscountCode.js +16 -16
- package/dist/src/models/WebshopDiscountCode.js.map +1 -1
- package/dist/src/models/addresses/City.d.ts.map +1 -1
- package/dist/src/models/addresses/City.js +9 -9
- package/dist/src/models/addresses/City.js.map +1 -1
- package/dist/src/models/addresses/PostalCode.d.ts.map +1 -1
- package/dist/src/models/addresses/PostalCode.js +11 -11
- package/dist/src/models/addresses/PostalCode.js.map +1 -1
- package/dist/src/models/addresses/PostalCode.test.js +22 -22
- package/dist/src/models/addresses/PostalCode.test.js.map +1 -1
- package/dist/src/models/addresses/Province.d.ts.map +1 -1
- package/dist/src/models/addresses/Province.js +5 -5
- package/dist/src/models/addresses/Province.js.map +1 -1
- package/dist/src/models/addresses/Street.d.ts.map +1 -1
- package/dist/src/models/addresses/Street.js +6 -6
- package/dist/src/models/addresses/Street.js.map +1 -1
- package/dist/src/models/index.d.ts +46 -46
- package/dist/src/models/index.d.ts.map +1 -1
- package/dist/src/models/index.js +0 -1
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/structures/OrganizationServerMetaData.d.ts.map +1 -1
- package/dist/src/structures/OrganizationServerMetaData.js +4 -4
- package/dist/src/structures/OrganizationServerMetaData.js.map +1 -1
- package/dist/tests/jest.global.setup.d.ts.map +1 -1
- package/dist/tests/jest.global.setup.js +15 -13
- package/dist/tests/jest.global.setup.js.map +1 -1
- package/dist/tests/jest.setup.js +3 -1
- package/dist/tests/jest.setup.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +3 -3
- package/src/factories/AddressFactory.ts +17 -17
- package/src/factories/EmergencyContactFactory.ts +30 -31
- package/src/factories/GroupFactory.ts +30 -30
- package/src/factories/MemberFactory.ts +41 -38
- package/src/factories/OrganizationFactory.ts +15 -15
- package/src/factories/ParentFactory.ts +24 -24
- package/src/factories/RecordFactory.ts +5 -4
- package/src/factories/RegisterCodeFactory.ts +7 -7
- package/src/factories/RegistrationFactory.ts +16 -16
- package/src/factories/RegistrationPeriodFactory.ts +5 -5
- package/src/factories/UserFactory.ts +20 -19
- package/src/factories/WebshopFactory.ts +14 -14
- package/src/helpers/DNSValidator.ts +89 -84
- package/src/helpers/EmailBuilder.ts +141 -135
- package/src/helpers/GroupBuilder.ts +181 -181
- package/src/helpers/Handlebars.ts +57 -54
- package/src/helpers/MemberMerger.test.ts +702 -702
- package/src/helpers/MemberMerger.ts +83 -77
- package/src/helpers/RateLimiter.ts +25 -27
- package/src/helpers/SetupStepsUpdater.ts +402 -0
- package/src/helpers/WebshopCounter.test.ts +12 -12
- package/src/helpers/WebshopCounter.ts +20 -19
- package/src/index.ts +20 -19
- package/src/migrations/1605262045-import-postcodes.ts +59 -63
- package/src/migrations/1605262046-import-postcodes-nl.ts +41 -43
- package/src/models/BalanceItem.ts +173 -172
- package/src/models/BalanceItemPayment.ts +32 -33
- package/src/models/BuckarooPayment.ts +7 -7
- package/src/models/CachedOutstandingBalance.ts +98 -99
- package/src/models/Document.ts +90 -87
- package/src/models/DocumentTemplate.ts +207 -198
- package/src/models/Email.ts +198 -200
- package/src/models/EmailRecipient.ts +38 -39
- package/src/models/EmailTemplate.ts +36 -37
- package/src/models/EmailVerificationCode.ts +146 -142
- package/src/models/Event.ts +53 -53
- package/src/models/Group.ts +136 -123
- package/src/models/Image.ts +48 -48
- package/src/models/Member.ts +277 -275
- package/src/models/MemberPlatformMembership.ts +71 -71
- package/src/models/MemberResponsibilityRecord.ts +32 -32
- package/src/models/MergedMember.ts +77 -77
- package/src/models/MolliePayment.ts +7 -7
- package/src/models/MollieToken.ts +131 -126
- package/src/models/OneTimeToken.ts +40 -39
- package/src/models/Order.ts +379 -372
- package/src/models/Organization.ts +332 -325
- package/src/models/OrganizationRegistrationPeriod.ts +50 -50
- package/src/models/PasswordToken.ts +42 -42
- package/src/models/PayconiqPayment.ts +80 -76
- package/src/models/Payment.ts +86 -86
- package/src/models/Platform.ts +21 -22
- package/src/models/RegisterCode.ts +26 -26
- package/src/models/Registration.ts +167 -168
- package/src/models/RegistrationPeriod.ts +29 -29
- package/src/models/STCredit.ts +24 -25
- package/src/models/STInvoice.ts +34 -34
- package/src/models/STPackage.ts +143 -136
- package/src/models/STPendingInvoice.ts +26 -26
- package/src/models/StripeAccount.ts +27 -27
- package/src/models/StripeCheckoutSession.ts +10 -10
- package/src/models/StripePaymentIntent.ts +10 -10
- package/src/models/Ticket.ts +51 -52
- package/src/models/Token.test.ts +13 -13
- package/src/models/Token.ts +64 -63
- package/src/models/UsedRegisterCode.ts +20 -21
- package/src/models/User.ts +148 -144
- package/src/models/UserPermissions.ts +25 -28
- package/src/models/Webshop.ts +53 -53
- package/src/models/WebshopDiscountCode.ts +33 -33
- package/src/models/addresses/City.ts +12 -12
- package/src/models/addresses/PostalCode.test.ts +68 -69
- package/src/models/addresses/PostalCode.ts +57 -57
- package/src/models/addresses/Province.ts +8 -8
- package/src/models/addresses/Street.ts +10 -12
- package/src/models/index.ts +54 -55
- package/src/structures/OrganizationServerMetaData.ts +36 -36
package/src/models/STPackage.ts
CHANGED
|
@@ -1,91 +1,92 @@
|
|
|
1
|
-
import { column, Model } from
|
|
2
|
-
import { SimpleError } from
|
|
1
|
+
import { column, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { SimpleError } from '@simonbackx/simple-errors';
|
|
3
3
|
import { EmailTemplateType, Recipient, Replacement, STPackageMeta, STPackageStatus, STPackageType } from '@stamhoofd/structures';
|
|
4
|
-
import { Formatter } from
|
|
5
|
-
import { v4 as uuidv4 } from
|
|
4
|
+
import { Formatter } from '@stamhoofd/utility';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
6
|
|
|
7
|
-
import { sendEmailTemplate } from
|
|
8
|
-
import { GroupBuilder } from
|
|
9
|
-
import { Organization } from
|
|
7
|
+
import { sendEmailTemplate } from '../helpers/EmailBuilder';
|
|
8
|
+
import { GroupBuilder } from '../helpers/GroupBuilder';
|
|
9
|
+
import { Organization } from './';
|
|
10
10
|
|
|
11
11
|
export class STPackage extends Model {
|
|
12
|
-
static table =
|
|
12
|
+
static table = 'stamhoofd_packages';
|
|
13
13
|
|
|
14
14
|
// Columns
|
|
15
15
|
@column({
|
|
16
|
-
primary: true, type:
|
|
16
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
17
17
|
return value ?? uuidv4();
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
19
|
})
|
|
20
20
|
id!: string;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* We keep packages of deleted organizations for statistics, so this doesn't have a foreign key
|
|
24
24
|
*/
|
|
25
|
-
@column({ type:
|
|
26
|
-
organizationId: string
|
|
25
|
+
@column({ type: 'string' })
|
|
26
|
+
organizationId: string;
|
|
27
27
|
|
|
28
|
-
@column({ type:
|
|
29
|
-
meta: STPackageMeta
|
|
28
|
+
@column({ type: 'json', decoder: STPackageMeta })
|
|
29
|
+
meta: STPackageMeta;
|
|
30
30
|
|
|
31
31
|
@column({
|
|
32
|
-
type:
|
|
32
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
33
33
|
if (old !== undefined) {
|
|
34
34
|
return old;
|
|
35
35
|
}
|
|
36
|
-
const date = new Date()
|
|
37
|
-
date.setMilliseconds(0)
|
|
38
|
-
return date
|
|
39
|
-
}
|
|
36
|
+
const date = new Date();
|
|
37
|
+
date.setMilliseconds(0);
|
|
38
|
+
return date;
|
|
39
|
+
},
|
|
40
40
|
})
|
|
41
|
-
createdAt: Date
|
|
41
|
+
createdAt: Date;
|
|
42
42
|
|
|
43
43
|
@column({
|
|
44
|
-
type:
|
|
45
|
-
const date = new Date()
|
|
46
|
-
date.setMilliseconds(0)
|
|
47
|
-
return date
|
|
44
|
+
type: 'datetime', beforeSave() {
|
|
45
|
+
const date = new Date();
|
|
46
|
+
date.setMilliseconds(0);
|
|
47
|
+
return date;
|
|
48
48
|
},
|
|
49
|
-
skipUpdate: true
|
|
49
|
+
skipUpdate: true,
|
|
50
50
|
})
|
|
51
|
-
updatedAt: Date
|
|
51
|
+
updatedAt: Date;
|
|
52
52
|
|
|
53
|
-
@column({ type:
|
|
54
|
-
validAt: Date | null = null
|
|
53
|
+
@column({ type: 'datetime', nullable: true })
|
|
54
|
+
validAt: Date | null = null;
|
|
55
55
|
|
|
56
|
-
@column({ type:
|
|
57
|
-
validUntil: Date | null = null
|
|
56
|
+
@column({ type: 'datetime', nullable: true })
|
|
57
|
+
validUntil: Date | null = null;
|
|
58
58
|
|
|
59
|
-
@column({ type:
|
|
60
|
-
removeAt: Date | null = null
|
|
59
|
+
@column({ type: 'datetime', nullable: true })
|
|
60
|
+
removeAt: Date | null = null;
|
|
61
61
|
|
|
62
|
-
@column({ type:
|
|
63
|
-
emailCount = 0
|
|
62
|
+
@column({ type: 'integer' })
|
|
63
|
+
emailCount = 0;
|
|
64
64
|
|
|
65
|
-
@column({ type:
|
|
66
|
-
lastEmailAt: Date | null = null
|
|
65
|
+
@column({ type: 'datetime', nullable: true })
|
|
66
|
+
lastEmailAt: Date | null = null;
|
|
67
67
|
|
|
68
68
|
static async getForOrganization(organizationId: string) {
|
|
69
|
-
const pack1 = await STPackage.where({ organizationId, validAt: { sign:
|
|
70
|
-
const pack2 = await STPackage.where({ organizationId, validAt: { sign:
|
|
69
|
+
const pack1 = await STPackage.where({ organizationId, validAt: { sign: '!=', value: null }, removeAt: { sign: '>', value: new Date() } });
|
|
70
|
+
const pack2 = await STPackage.where({ organizationId, validAt: { sign: '!=', value: null }, removeAt: null });
|
|
71
71
|
|
|
72
|
-
return [...pack1, ...pack2]
|
|
72
|
+
return [...pack1, ...pack2];
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
static async getForOrganizationIncludingExpired(organizationId: string) {
|
|
76
|
-
return await STPackage.where({ organizationId, validAt: { sign:
|
|
76
|
+
return await STPackage.where({ organizationId, validAt: { sign: '!=', value: null } }, { sort: [{ column: 'validAt', direction: 'DESC' }] });
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
static async getOrganizationPackagesMap(organizationId: string): Promise<Map<STPackageType, STPackageStatus>> {
|
|
80
|
-
const packages = await this.getForOrganizationIncludingExpired(organizationId)
|
|
80
|
+
const packages = await this.getForOrganizationIncludingExpired(organizationId);
|
|
81
81
|
|
|
82
|
-
const map = new Map<STPackageType, STPackageStatus>()
|
|
82
|
+
const map = new Map<STPackageType, STPackageStatus>();
|
|
83
83
|
for (const pack of packages) {
|
|
84
|
-
const exist = map.get(pack.meta.type)
|
|
84
|
+
const exist = map.get(pack.meta.type);
|
|
85
85
|
if (exist) {
|
|
86
|
-
exist.merge(pack.createStatus())
|
|
87
|
-
}
|
|
88
|
-
|
|
86
|
+
exist.merge(pack.createStatus());
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
map.set(pack.meta.type, pack.createStatus());
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -93,52 +94,53 @@ export class STPackage extends Model {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
static async updateOrganizationPackages(organizationId: string) {
|
|
96
|
-
console.log(
|
|
97
|
-
const map = await this.getOrganizationPackagesMap(organizationId)
|
|
97
|
+
console.log('Updating packages for organization ' + organizationId);
|
|
98
|
+
const map = await this.getOrganizationPackagesMap(organizationId);
|
|
98
99
|
|
|
99
|
-
const organization = await Organization.getByID(organizationId)
|
|
100
|
+
const organization = await Organization.getByID(organizationId);
|
|
100
101
|
if (organization) {
|
|
101
|
-
const didUseMembers = organization.meta.packages.useMembers && organization.meta.packages.useActivities
|
|
102
|
-
organization.meta.packages.packages = map
|
|
103
|
-
await organization.save()
|
|
102
|
+
const didUseMembers = organization.meta.packages.useMembers && organization.meta.packages.useActivities;
|
|
103
|
+
organization.meta.packages.packages = map;
|
|
104
|
+
await organization.save();
|
|
104
105
|
|
|
105
106
|
if (!didUseMembers && organization.meta.packages.useMembers && organization.meta.packages.useActivities) {
|
|
106
|
-
console.log(
|
|
107
|
-
const builder = new GroupBuilder(organization)
|
|
108
|
-
await builder.build()
|
|
107
|
+
console.log('Building groups and categories for ' + organization.id);
|
|
108
|
+
const builder = new GroupBuilder(organization);
|
|
109
|
+
await builder.build();
|
|
109
110
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.error("Couldn't find organization when updating packages " + organizationId);
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
async activate() {
|
|
116
118
|
if (this.validAt !== null) {
|
|
117
|
-
return
|
|
119
|
+
return;
|
|
118
120
|
}
|
|
119
|
-
this.validAt = new Date()
|
|
120
|
-
await this.save()
|
|
121
|
+
this.validAt = new Date();
|
|
122
|
+
await this.save();
|
|
121
123
|
|
|
122
124
|
if (this.meta.didRenewId) {
|
|
123
|
-
const pack = await STPackage.getByID(this.meta.didRenewId)
|
|
125
|
+
const pack = await STPackage.getByID(this.meta.didRenewId);
|
|
124
126
|
if (pack && pack.organizationId === this.organizationId) {
|
|
125
|
-
await pack.didRenew(this)
|
|
127
|
+
await pack.didRenew(this);
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
async didRenew(renewed: STPackage) {
|
|
131
|
-
this.removeAt = renewed.meta.startDate ?? renewed.validAt ?? new Date()
|
|
132
|
-
this.meta.allowRenew = false
|
|
133
|
-
await this.save()
|
|
133
|
+
this.removeAt = renewed.meta.startDate ?? renewed.validAt ?? new Date();
|
|
134
|
+
this.meta.allowRenew = false;
|
|
135
|
+
await this.save();
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
async deactivate() {
|
|
137
139
|
if (this.removeAt !== null && this.removeAt <= new Date()) {
|
|
138
|
-
return
|
|
140
|
+
return;
|
|
139
141
|
}
|
|
140
|
-
this.removeAt = new Date()
|
|
141
|
-
await this.save()
|
|
142
|
+
this.removeAt = new Date();
|
|
143
|
+
await this.save();
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
/**
|
|
@@ -147,43 +149,43 @@ export class STPackage extends Model {
|
|
|
147
149
|
createRenewed(): STPackage {
|
|
148
150
|
if (!this.meta.allowRenew) {
|
|
149
151
|
throw new SimpleError({
|
|
150
|
-
code:
|
|
151
|
-
message:
|
|
152
|
-
human:
|
|
153
|
-
})
|
|
152
|
+
code: 'not_allowed',
|
|
153
|
+
message: 'Not allowed',
|
|
154
|
+
human: 'Je kan dit pakket niet verlengen',
|
|
155
|
+
});
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
const pack = new STPackage()
|
|
157
|
-
pack.id = uuidv4()
|
|
158
|
-
pack.meta = this.meta
|
|
158
|
+
const pack = new STPackage();
|
|
159
|
+
pack.id = uuidv4();
|
|
160
|
+
pack.meta = this.meta;
|
|
159
161
|
|
|
160
162
|
// Not yet valid / active (ignored until valid)
|
|
161
|
-
pack.validAt = null
|
|
162
|
-
pack.organizationId = this.organizationId
|
|
163
|
-
|
|
164
|
-
pack.meta.startDate = new Date(Math.max(new Date().getTime(), this.validUntil?.getTime() ?? 0))
|
|
165
|
-
pack.meta.paidAmount = 0
|
|
166
|
-
pack.meta.paidPrice = 0
|
|
167
|
-
pack.meta.firstFailedPayment = null
|
|
168
|
-
pack.meta.didRenewId = this.id
|
|
169
|
-
|
|
163
|
+
pack.validAt = null;
|
|
164
|
+
pack.organizationId = this.organizationId;
|
|
165
|
+
|
|
166
|
+
pack.meta.startDate = new Date(Math.max(new Date().getTime(), this.validUntil?.getTime() ?? 0));
|
|
167
|
+
pack.meta.paidAmount = 0;
|
|
168
|
+
pack.meta.paidPrice = 0;
|
|
169
|
+
pack.meta.firstFailedPayment = null;
|
|
170
|
+
pack.meta.didRenewId = this.id;
|
|
171
|
+
|
|
170
172
|
// Duration for renewals is always a year ATM
|
|
171
|
-
pack.validUntil = new Date(pack.meta.startDate)
|
|
172
|
-
pack.validUntil.setFullYear(pack.validUntil.getFullYear() + 1)
|
|
173
|
+
pack.validUntil = new Date(pack.meta.startDate);
|
|
174
|
+
pack.validUntil.setFullYear(pack.validUntil.getFullYear() + 1);
|
|
173
175
|
|
|
174
176
|
// Remove (= not renewable) if not renewed after 3 months
|
|
175
|
-
pack.removeAt = new Date(pack.validUntil)
|
|
176
|
-
pack.removeAt.setMonth(pack.removeAt.getMonth() + 3)
|
|
177
|
+
pack.removeAt = new Date(pack.validUntil);
|
|
178
|
+
pack.removeAt.setMonth(pack.removeAt.getMonth() + 3);
|
|
177
179
|
|
|
178
180
|
// Custom renewals for single webshop:
|
|
179
181
|
if (this.meta.type === STPackageType.SingleWebshop) {
|
|
180
182
|
// Disable functions after two months
|
|
181
|
-
pack.validUntil = new Date(pack.meta.startDate)
|
|
182
|
-
pack.validUntil.setMonth(pack.validUntil.getMonth() + 2)
|
|
183
|
-
pack.removeAt = new Date(pack.validUntil)
|
|
183
|
+
pack.validUntil = new Date(pack.meta.startDate);
|
|
184
|
+
pack.validUntil.setMonth(pack.validUntil.getMonth() + 2);
|
|
185
|
+
pack.removeAt = new Date(pack.validUntil);
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
return pack
|
|
188
|
+
return pack;
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
createStatus(): STPackageStatus {
|
|
@@ -193,19 +195,19 @@ export class STPackage extends Model {
|
|
|
193
195
|
startDate: this.meta.startDate,
|
|
194
196
|
validUntil: this.validUntil,
|
|
195
197
|
removeAt: this.removeAt,
|
|
196
|
-
firstFailedPayment: this.meta.firstFailedPayment
|
|
197
|
-
})
|
|
198
|
+
firstFailedPayment: this.meta.firstFailedPayment,
|
|
199
|
+
});
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
async sendExpiryEmail() {
|
|
201
203
|
if (this.validAt === null) {
|
|
202
204
|
// never activated
|
|
203
|
-
return
|
|
205
|
+
return;
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
if (this.removeAt && this.removeAt <= new Date()) {
|
|
207
|
-
this.emailCount += 1
|
|
208
|
-
await this.save()
|
|
209
|
+
this.emailCount += 1;
|
|
210
|
+
await this.save();
|
|
209
211
|
return;
|
|
210
212
|
}
|
|
211
213
|
|
|
@@ -215,91 +217,96 @@ export class STPackage extends Model {
|
|
|
215
217
|
if (this.meta.type === STPackageType.Members) {
|
|
216
218
|
type = EmailTemplateType.MembersExpirationReminder;
|
|
217
219
|
allowDays = 32;
|
|
218
|
-
}
|
|
220
|
+
}
|
|
221
|
+
else if (this.meta.type === STPackageType.Webshops) {
|
|
219
222
|
type = EmailTemplateType.WebshopsExpirationReminder;
|
|
220
223
|
allowDays = 32;
|
|
221
|
-
}
|
|
224
|
+
}
|
|
225
|
+
else if (this.meta.type === STPackageType.SingleWebshop) {
|
|
222
226
|
type = EmailTemplateType.SingleWebshopExpirationReminder;
|
|
223
227
|
allowDays = 7;
|
|
224
|
-
}
|
|
228
|
+
}
|
|
229
|
+
else if (this.meta.type === STPackageType.TrialMembers) {
|
|
225
230
|
type = EmailTemplateType.TrialMembersExpirationReminder;
|
|
226
231
|
allowDays = 3;
|
|
227
|
-
}
|
|
232
|
+
}
|
|
233
|
+
else if (this.meta.type === STPackageType.TrialWebshops) {
|
|
228
234
|
type = EmailTemplateType.TrialWebshopsExpirationReminder;
|
|
229
235
|
allowDays = 3;
|
|
230
236
|
}
|
|
231
237
|
|
|
232
|
-
const allowFrom = new Date(Date.now() + 1000 * 60 * 60 * 24 * allowDays)
|
|
238
|
+
const allowFrom = new Date(Date.now() + 1000 * 60 * 60 * 24 * allowDays);
|
|
233
239
|
if (type && (this.validUntil === null || this.validUntil < new Date() || this.validUntil > allowFrom)) {
|
|
234
|
-
console.log('Skip sending expiration email for '+this.id)
|
|
240
|
+
console.log('Skip sending expiration email for ' + this.id);
|
|
235
241
|
return;
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
if (type) {
|
|
239
|
-
console.log('Sending expiration email for '+this.id, type)
|
|
240
|
-
if (STAMHOOFD.environment ===
|
|
245
|
+
console.log('Sending expiration email for ' + this.id, type);
|
|
246
|
+
if (STAMHOOFD.environment === 'production') {
|
|
241
247
|
await this.sendEmailTemplate({
|
|
242
|
-
type
|
|
243
|
-
})
|
|
248
|
+
type,
|
|
249
|
+
});
|
|
244
250
|
}
|
|
245
|
-
this.lastEmailAt = new Date()
|
|
246
|
-
} else {
|
|
247
|
-
console.log('Skip sending expiration email for '+this.id+' (no type)')
|
|
251
|
+
this.lastEmailAt = new Date();
|
|
248
252
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
else {
|
|
254
|
+
console.log('Skip sending expiration email for ' + this.id + ' (no type)');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.emailCount += 1;
|
|
258
|
+
await this.save();
|
|
252
259
|
}
|
|
253
260
|
|
|
254
261
|
async sendEmailTemplate(data: {
|
|
255
|
-
type: EmailTemplateType
|
|
256
|
-
replyTo?: string
|
|
262
|
+
type: EmailTemplateType;
|
|
263
|
+
replyTo?: string;
|
|
257
264
|
}) {
|
|
258
|
-
const organization = await Organization.getByID(this.organizationId)
|
|
265
|
+
const organization = await Organization.getByID(this.organizationId);
|
|
259
266
|
|
|
260
267
|
if (!organization) {
|
|
261
|
-
console.error(
|
|
262
|
-
return
|
|
268
|
+
console.error('Could not find package organization ' + this.id);
|
|
269
|
+
return;
|
|
263
270
|
}
|
|
264
271
|
|
|
265
|
-
const admins = await organization.getFullAdmins()
|
|
272
|
+
const admins = await organization.getFullAdmins();
|
|
266
273
|
|
|
267
|
-
const recipients = admins.map(admin =>
|
|
274
|
+
const recipients = admins.map(admin =>
|
|
268
275
|
Recipient.create({
|
|
269
276
|
firstName: admin.firstName,
|
|
270
277
|
lastName: admin.lastName,
|
|
271
278
|
email: admin.email,
|
|
272
279
|
replacements: [
|
|
273
280
|
Replacement.create({
|
|
274
|
-
token:
|
|
275
|
-
value: organization.name
|
|
281
|
+
token: 'organizationName',
|
|
282
|
+
value: organization.name,
|
|
276
283
|
}),
|
|
277
284
|
Replacement.create({
|
|
278
|
-
token:
|
|
279
|
-
value: this.meta.name ??
|
|
285
|
+
token: 'packageName',
|
|
286
|
+
value: this.meta.name ?? '',
|
|
280
287
|
}),
|
|
281
288
|
Replacement.create({
|
|
282
|
-
token:
|
|
283
|
-
value: this.validUntil ? Formatter.dateTime(this.validUntil) :
|
|
289
|
+
token: 'validUntil',
|
|
290
|
+
value: this.validUntil ? Formatter.dateTime(this.validUntil) : 'nooit',
|
|
284
291
|
}),
|
|
285
292
|
Replacement.create({
|
|
286
|
-
token:
|
|
287
|
-
value: this.validUntil ? Formatter.date(this.validUntil) :
|
|
293
|
+
token: 'validUntilDate',
|
|
294
|
+
value: this.validUntil ? Formatter.date(this.validUntil) : 'nooit',
|
|
288
295
|
}),
|
|
289
296
|
Replacement.create({
|
|
290
|
-
token:
|
|
291
|
-
value:
|
|
297
|
+
token: 'renewUrl',
|
|
298
|
+
value: 'https://' + (STAMHOOFD.domains.dashboard ?? 'stamhoofd.app') + '/' + organization.i18n.locale + '/settings/packages',
|
|
292
299
|
}),
|
|
293
|
-
]
|
|
294
|
-
})
|
|
300
|
+
],
|
|
301
|
+
}),
|
|
295
302
|
);
|
|
296
|
-
|
|
303
|
+
|
|
297
304
|
// Create e-mail builder
|
|
298
305
|
await sendEmailTemplate(null, {
|
|
299
306
|
template: {
|
|
300
|
-
type: data.type
|
|
307
|
+
type: data.type,
|
|
301
308
|
},
|
|
302
|
-
recipients
|
|
303
|
-
})
|
|
309
|
+
recipients,
|
|
310
|
+
});
|
|
304
311
|
}
|
|
305
312
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { column, ManyToOneRelation, Model } from
|
|
1
|
+
import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
2
|
import { STInvoiceMeta } from '@stamhoofd/structures';
|
|
3
|
-
import { v4 as uuidv4 } from
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
|
|
5
5
|
import { Organization } from './';
|
|
6
6
|
|
|
@@ -8,56 +8,56 @@ import { Organization } from './';
|
|
|
8
8
|
* Things that should get paid, but are not yet invoiced yet because:
|
|
9
9
|
* - total price is too low
|
|
10
10
|
* - auto renewals waiting for payment
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* When they are about to get paid, we create a new invoice model
|
|
13
13
|
* and if that model is marked as paid, it will remove the corresponding
|
|
14
14
|
* items in this pending invoice.
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* So please make sure you don't edit existing items, unless you change the id
|
|
17
17
|
*/
|
|
18
18
|
export class STPendingInvoice extends Model {
|
|
19
|
-
static table =
|
|
19
|
+
static table = 'stamhoofd_pending_invoices';
|
|
20
20
|
|
|
21
21
|
// Columns
|
|
22
22
|
@column({
|
|
23
|
-
primary: true, type:
|
|
23
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
24
24
|
return value ?? uuidv4();
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
26
|
})
|
|
27
27
|
id!: string;
|
|
28
28
|
|
|
29
|
-
@column({ foreignKey: STPendingInvoice.organization, type:
|
|
29
|
+
@column({ foreignKey: STPendingInvoice.organization, type: 'string', nullable: true })
|
|
30
30
|
organizationId: string | null;
|
|
31
|
-
|
|
32
|
-
@column({ type:
|
|
33
|
-
meta: STInvoiceMeta
|
|
31
|
+
|
|
32
|
+
@column({ type: 'json', decoder: STInvoiceMeta })
|
|
33
|
+
meta: STInvoiceMeta;
|
|
34
34
|
|
|
35
35
|
/// We can only have one invoice at a time for the pending invoice items
|
|
36
36
|
/// So until this invoice is marked as 'failed', we don't create new invoices for this pending invoice
|
|
37
|
-
@column({ type:
|
|
38
|
-
invoiceId: string | null = null
|
|
37
|
+
@column({ type: 'string', nullable: true })
|
|
38
|
+
invoiceId: string | null = null;
|
|
39
39
|
|
|
40
40
|
@column({
|
|
41
|
-
type:
|
|
41
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
42
42
|
if (old !== undefined) {
|
|
43
43
|
return old;
|
|
44
44
|
}
|
|
45
|
-
const date = new Date()
|
|
46
|
-
date.setMilliseconds(0)
|
|
47
|
-
return date
|
|
48
|
-
}
|
|
45
|
+
const date = new Date();
|
|
46
|
+
date.setMilliseconds(0);
|
|
47
|
+
return date;
|
|
48
|
+
},
|
|
49
49
|
})
|
|
50
|
-
createdAt: Date
|
|
50
|
+
createdAt: Date;
|
|
51
51
|
|
|
52
52
|
@column({
|
|
53
|
-
type:
|
|
54
|
-
const date = new Date()
|
|
55
|
-
date.setMilliseconds(0)
|
|
56
|
-
return date
|
|
53
|
+
type: 'datetime', beforeSave() {
|
|
54
|
+
const date = new Date();
|
|
55
|
+
date.setMilliseconds(0);
|
|
56
|
+
return date;
|
|
57
57
|
},
|
|
58
|
-
skipUpdate: true
|
|
58
|
+
skipUpdate: true,
|
|
59
59
|
})
|
|
60
|
-
updatedAt: Date
|
|
60
|
+
updatedAt: Date;
|
|
61
61
|
|
|
62
|
-
static organization = new ManyToOneRelation(Organization,
|
|
62
|
+
static organization = new ManyToOneRelation(Organization, 'organization');
|
|
63
63
|
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
2
|
import { column, Model } from '@simonbackx/simple-database';
|
|
3
3
|
import { Requirements, StripeBusinessProfile, StripeCompany, StripeMetaAccountSettings, StripeMetaData } from '@stamhoofd/structures';
|
|
4
|
-
import { v4 as uuidv4 } from
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Keeps track of how much a member/user owes or needs to be reimbursed.
|
|
8
8
|
*/
|
|
9
9
|
export class StripeAccount extends Model {
|
|
10
|
-
static table =
|
|
10
|
+
static table = 'stripe_accounts';
|
|
11
11
|
|
|
12
12
|
@column({
|
|
13
|
-
primary: true, type:
|
|
13
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
14
14
|
return value ?? uuidv4();
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
16
|
})
|
|
17
17
|
id!: string;
|
|
18
18
|
|
|
19
|
-
@column({ type:
|
|
20
|
-
organizationId: string
|
|
19
|
+
@column({ type: 'string' })
|
|
20
|
+
organizationId: string;
|
|
21
21
|
|
|
22
|
-
@column({ type:
|
|
23
|
-
accountId: string
|
|
22
|
+
@column({ type: 'string' })
|
|
23
|
+
accountId: string;
|
|
24
24
|
|
|
25
|
-
@column({ type:
|
|
26
|
-
meta = StripeMetaData.create({})
|
|
25
|
+
@column({ type: 'json', decoder: StripeMetaData })
|
|
26
|
+
meta = StripeMetaData.create({});
|
|
27
27
|
|
|
28
|
-
@column({ type:
|
|
29
|
-
status: 'active' | 'deleted' = 'active'
|
|
28
|
+
@column({ type: 'string' })
|
|
29
|
+
status: 'active' | 'deleted' = 'active';
|
|
30
30
|
|
|
31
31
|
@column({
|
|
32
|
-
type:
|
|
32
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
33
33
|
if (old !== undefined) {
|
|
34
34
|
return old;
|
|
35
35
|
}
|
|
36
|
-
const date = new Date()
|
|
37
|
-
date.setMilliseconds(0)
|
|
38
|
-
return date
|
|
39
|
-
}
|
|
36
|
+
const date = new Date();
|
|
37
|
+
date.setMilliseconds(0);
|
|
38
|
+
return date;
|
|
39
|
+
},
|
|
40
40
|
})
|
|
41
|
-
createdAt: Date
|
|
41
|
+
createdAt: Date;
|
|
42
42
|
|
|
43
43
|
@column({
|
|
44
|
-
type:
|
|
45
|
-
const date = new Date()
|
|
46
|
-
date.setMilliseconds(0)
|
|
47
|
-
return date
|
|
44
|
+
type: 'datetime', beforeSave() {
|
|
45
|
+
const date = new Date();
|
|
46
|
+
date.setMilliseconds(0);
|
|
47
|
+
return date;
|
|
48
48
|
},
|
|
49
|
-
skipUpdate: true
|
|
49
|
+
skipUpdate: true,
|
|
50
50
|
})
|
|
51
|
-
updatedAt: Date
|
|
51
|
+
updatedAt: Date;
|
|
52
52
|
|
|
53
53
|
setMetaFromStripeAccount(account: any) {
|
|
54
54
|
this.meta = StripeMetaData.create({
|
|
55
55
|
type: account.type ?? 'express',
|
|
56
56
|
blob: account,
|
|
57
|
-
business_profile: StripeBusinessProfile.create(!account.business_profile?.name ? {...account.business_profile, name: ''} : account.business_profile),
|
|
57
|
+
business_profile: StripeBusinessProfile.create(!account.business_profile?.name ? { ...account.business_profile, name: '' } : account.business_profile),
|
|
58
58
|
business_type: account.business_type ?? this.meta.business_type ?? null,
|
|
59
59
|
company: account.company ? StripeCompany.create(account.company) : (this.meta.company ?? null),
|
|
60
60
|
charges_enabled: account.charges_enabled,
|
|
@@ -64,8 +64,8 @@ export class StripeAccount extends Model {
|
|
|
64
64
|
requirements: Requirements.create(account.requirements),
|
|
65
65
|
future_requirements: Requirements.create(account.future_requirements),
|
|
66
66
|
settings: StripeMetaAccountSettings.create(account.settings),
|
|
67
|
-
bank_account_last4: account.external_accounts?.data[0]?.last4 ?? this.meta.bank_account_last4 ??
|
|
68
|
-
bank_account_bank_name: account.external_accounts?.data[0]?.bank_name ?? this.meta.bank_account_bank_name ??
|
|
67
|
+
bank_account_last4: account.external_accounts?.data[0]?.last4 ?? this.meta.bank_account_last4 ?? '',
|
|
68
|
+
bank_account_bank_name: account.external_accounts?.data[0]?.bank_name ?? this.meta.bank_account_bank_name ?? '',
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
}
|