@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
|
@@ -1,126 +1,126 @@
|
|
|
1
1
|
import { column, Model } from '@simonbackx/simple-database';
|
|
2
2
|
import { Group as GroupStruct, OrganizationRegistrationPeriodSettings, OrganizationRegistrationPeriod as OrganizationRegistrationPeriodStruct, SetupSteps } from '@stamhoofd/structures';
|
|
3
3
|
import { Formatter } from '@stamhoofd/utility';
|
|
4
|
-
import { v4 as uuidv4 } from
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
5
5
|
import { Group, RegistrationPeriod } from '.';
|
|
6
6
|
|
|
7
7
|
export class OrganizationRegistrationPeriod extends Model {
|
|
8
|
-
static table =
|
|
8
|
+
static table = 'organization_registration_periods';
|
|
9
9
|
|
|
10
10
|
@column({
|
|
11
|
-
primary: true, type:
|
|
11
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
12
12
|
return value ?? uuidv4();
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
14
|
})
|
|
15
15
|
id!: string;
|
|
16
16
|
|
|
17
|
-
@column({ type:
|
|
17
|
+
@column({ type: 'string' })
|
|
18
18
|
organizationId: string;
|
|
19
19
|
|
|
20
|
-
@column({ type:
|
|
21
|
-
periodId: string
|
|
20
|
+
@column({ type: 'string' })
|
|
21
|
+
periodId: string;
|
|
22
22
|
|
|
23
|
-
@column({ type:
|
|
24
|
-
settings = OrganizationRegistrationPeriodSettings.create({})
|
|
23
|
+
@column({ type: 'json', decoder: OrganizationRegistrationPeriodSettings })
|
|
24
|
+
settings = OrganizationRegistrationPeriodSettings.create({});
|
|
25
25
|
|
|
26
26
|
@column({
|
|
27
|
-
type:
|
|
27
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
28
28
|
if (old !== undefined) {
|
|
29
29
|
return old;
|
|
30
30
|
}
|
|
31
|
-
const date = new Date()
|
|
32
|
-
date.setMilliseconds(0)
|
|
33
|
-
return date
|
|
34
|
-
}
|
|
31
|
+
const date = new Date();
|
|
32
|
+
date.setMilliseconds(0);
|
|
33
|
+
return date;
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
|
-
createdAt: Date
|
|
36
|
+
createdAt: Date;
|
|
37
37
|
|
|
38
38
|
@column({
|
|
39
|
-
type:
|
|
40
|
-
const date = new Date()
|
|
41
|
-
date.setMilliseconds(0)
|
|
42
|
-
return date
|
|
39
|
+
type: 'datetime', beforeSave() {
|
|
40
|
+
const date = new Date();
|
|
41
|
+
date.setMilliseconds(0);
|
|
42
|
+
return date;
|
|
43
43
|
},
|
|
44
|
-
skipUpdate: true
|
|
44
|
+
skipUpdate: true,
|
|
45
45
|
})
|
|
46
|
-
updatedAt: Date
|
|
46
|
+
updatedAt: Date;
|
|
47
47
|
|
|
48
|
-
@column({ type:
|
|
49
|
-
setupSteps = SetupSteps.create({})
|
|
48
|
+
@column({ type: 'json', decoder: SetupSteps })
|
|
49
|
+
setupSteps = SetupSteps.create({});
|
|
50
50
|
|
|
51
51
|
getStructure(this: OrganizationRegistrationPeriod, period: RegistrationPeriod, groups: Group[]) {
|
|
52
52
|
return OrganizationRegistrationPeriodStruct.create({
|
|
53
53
|
...this,
|
|
54
54
|
period: period.getStructure(),
|
|
55
|
-
groups: groups.map(g => g.getStructure()).sort(GroupStruct.defaultSort)
|
|
56
|
-
})
|
|
55
|
+
groups: groups.map(g => g.getStructure()).sort(GroupStruct.defaultSort),
|
|
56
|
+
});
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
getPrivateStructure(this: OrganizationRegistrationPeriod, period: RegistrationPeriod, groups: Group[]) {
|
|
60
60
|
return OrganizationRegistrationPeriodStruct.create({
|
|
61
61
|
...this,
|
|
62
62
|
period: period.getStructure(),
|
|
63
|
-
groups: groups.map(g => g.getPrivateStructure()).sort(GroupStruct.defaultSort)
|
|
64
|
-
})
|
|
63
|
+
groups: groups.map(g => g.getPrivateStructure()).sort(GroupStruct.defaultSort),
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async cleanCategories(groups: {id: string}[]) {
|
|
68
|
-
const reachable = new Map<string, boolean>()
|
|
69
|
-
const queue = [this.settings.rootCategoryId]
|
|
70
|
-
reachable.set(this.settings.rootCategoryId, true)
|
|
67
|
+
async cleanCategories(groups: { id: string }[]) {
|
|
68
|
+
const reachable = new Map<string, boolean>();
|
|
69
|
+
const queue = [this.settings.rootCategoryId];
|
|
70
|
+
reachable.set(this.settings.rootCategoryId, true);
|
|
71
71
|
let shouldSave = false;
|
|
72
72
|
|
|
73
|
-
const usedGroupIds = new Set<string>()
|
|
73
|
+
const usedGroupIds = new Set<string>();
|
|
74
74
|
|
|
75
75
|
while (queue.length > 0) {
|
|
76
|
-
const id = queue.shift()
|
|
76
|
+
const id = queue.shift();
|
|
77
77
|
if (!id) {
|
|
78
|
-
break
|
|
78
|
+
break;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const category = this.settings.categories.find(c => c.id === id)
|
|
81
|
+
const category = this.settings.categories.find(c => c.id === id);
|
|
82
82
|
if (!category) {
|
|
83
|
-
continue
|
|
83
|
+
continue;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
for (const i of category.categoryIds) {
|
|
87
87
|
if (!reachable.get(i)) {
|
|
88
|
-
reachable.set(i, true)
|
|
89
|
-
queue.push(i)
|
|
88
|
+
reachable.set(i, true);
|
|
89
|
+
queue.push(i);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// Remove groupIds that no longer exist or are in a different category already
|
|
94
|
-
let filtered = category.groupIds.filter(id => !!groups.find(g => g.id === id) && !usedGroupIds.has(id))
|
|
94
|
+
let filtered = category.groupIds.filter(id => !!groups.find(g => g.id === id) && !usedGroupIds.has(id));
|
|
95
95
|
|
|
96
96
|
// Remove duplicate groups
|
|
97
|
-
filtered = Formatter.uniqueArray(filtered)
|
|
97
|
+
filtered = Formatter.uniqueArray(filtered);
|
|
98
98
|
|
|
99
99
|
if (filtered.length !== category.groupIds.length) {
|
|
100
100
|
shouldSave = true;
|
|
101
|
-
console.log(
|
|
102
|
-
category.groupIds = filtered
|
|
101
|
+
console.log('Deleted ' + (category.groupIds.length - filtered.length) + ' group ids from category ' + category.id + ', in organization period ' + this.id);
|
|
102
|
+
category.groupIds = filtered;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
for (const groupId of category.groupIds) {
|
|
106
|
-
usedGroupIds.add(groupId)
|
|
106
|
+
usedGroupIds.add(groupId);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const reachableCategoryIds = [...reachable.keys()]
|
|
110
|
+
const reachableCategoryIds = [...reachable.keys()];
|
|
111
111
|
|
|
112
112
|
// Delete all categories that are not reachable anymore
|
|
113
113
|
const beforeCount = this.settings.categories.length;
|
|
114
|
-
this.settings.categories = this.settings.categories.filter(c => reachableCategoryIds.includes(c.id))
|
|
114
|
+
this.settings.categories = this.settings.categories.filter(c => reachableCategoryIds.includes(c.id));
|
|
115
115
|
|
|
116
116
|
if (this.settings.categories.length !== beforeCount) {
|
|
117
|
-
console.log(
|
|
118
|
-
await this.save()
|
|
119
|
-
}
|
|
117
|
+
console.log('Deleted ' + (beforeCount - this.settings.categories.length) + ' categories from organizaton period ' + this.id);
|
|
118
|
+
await this.save();
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
120
121
|
if (shouldSave) {
|
|
121
|
-
await this.save()
|
|
122
|
+
await this.save();
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
|
-
|
|
126
126
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { I18n } from '@stamhoofd/backend-i18n';
|
|
3
|
+
import basex from 'base-x';
|
|
4
|
+
import crypto from 'crypto';
|
|
1
5
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import crypto from "crypto";
|
|
6
|
-
|
|
7
|
-
import { Organization, User } from "./";
|
|
8
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
|
9
|
-
const bs58 = basex(ALPHABET)
|
|
6
|
+
import { Organization, User } from './';
|
|
7
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
8
|
+
const bs58 = basex(ALPHABET);
|
|
10
9
|
|
|
11
10
|
export type PasswordTokenWithUser = PasswordToken & { user: User };
|
|
12
11
|
|
|
@@ -23,47 +22,47 @@ async function randomBytes(size: number): Promise<Buffer> {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export class PasswordToken extends Model {
|
|
26
|
-
static table =
|
|
27
|
-
|
|
25
|
+
static table = 'password_tokens';
|
|
26
|
+
|
|
28
27
|
// Columns
|
|
29
|
-
@column({ primary: true, type:
|
|
28
|
+
@column({ primary: true, type: 'string' })
|
|
30
29
|
token: string;
|
|
31
30
|
|
|
32
|
-
@column({ type:
|
|
31
|
+
@column({ type: 'datetime' })
|
|
33
32
|
validUntil: Date;
|
|
34
33
|
|
|
35
34
|
@column({
|
|
36
|
-
type:
|
|
35
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
37
36
|
if (old !== undefined) {
|
|
38
37
|
return old;
|
|
39
38
|
}
|
|
40
|
-
const date = new Date()
|
|
41
|
-
date.setMilliseconds(0)
|
|
42
|
-
return date
|
|
43
|
-
}
|
|
39
|
+
const date = new Date();
|
|
40
|
+
date.setMilliseconds(0);
|
|
41
|
+
return date;
|
|
42
|
+
},
|
|
44
43
|
})
|
|
45
|
-
createdAt: Date
|
|
44
|
+
createdAt: Date;
|
|
46
45
|
|
|
47
|
-
@column({ type:
|
|
46
|
+
@column({ type: 'string', foreignKey: PasswordToken.user })
|
|
48
47
|
userId: string;
|
|
49
48
|
|
|
50
|
-
static user = new ManyToOneRelation(User,
|
|
49
|
+
static user = new ManyToOneRelation(User, 'user');
|
|
51
50
|
|
|
52
51
|
isExpired(): boolean {
|
|
53
|
-
return this.validUntil < new Date()
|
|
52
|
+
return this.validUntil < new Date();
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
|
|
56
55
|
/**
|
|
57
56
|
* Get a token
|
|
58
|
-
* @param token
|
|
57
|
+
* @param token
|
|
59
58
|
* @param ignoreExpireDate: do not return if it is expired
|
|
60
59
|
*/
|
|
61
60
|
static async getToken(token: string, ignoreExpireDate = false): Promise<PasswordTokenWithUser | undefined> {
|
|
62
61
|
const [rows] = await Database.select(
|
|
63
|
-
`SELECT ${this.getDefaultSelect()}, ${User.getDefaultSelect(
|
|
62
|
+
`SELECT ${this.getDefaultSelect()}, ${User.getDefaultSelect('user')} FROM ${
|
|
64
63
|
this.table
|
|
65
|
-
} ${PasswordToken.user.joinQuery(this.table,
|
|
66
|
-
[token]
|
|
64
|
+
} ${PasswordToken.user.joinQuery(this.table, 'user')} WHERE ${this.primary.name} = ? LIMIT 1 `,
|
|
65
|
+
[token],
|
|
67
66
|
);
|
|
68
67
|
|
|
69
68
|
if (rows.length == 0) {
|
|
@@ -78,13 +77,13 @@ export class PasswordToken extends Model {
|
|
|
78
77
|
|
|
79
78
|
if (!ignoreExpireDate && passwordToken.isExpired()) {
|
|
80
79
|
// If the refresh token is invalid, do not return it
|
|
81
|
-
return undefined
|
|
80
|
+
return undefined;
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
const user = User.fromRow(rows[0][
|
|
83
|
+
const user = User.fromRow(rows[0]['user']) || null;
|
|
85
84
|
|
|
86
85
|
if (!user) {
|
|
87
|
-
console.error(
|
|
86
|
+
console.error('Password token without a valid user!');
|
|
88
87
|
return undefined;
|
|
89
88
|
}
|
|
90
89
|
|
|
@@ -98,8 +97,9 @@ export class PasswordToken extends Model {
|
|
|
98
97
|
const token = new PasswordToken().setRelation(PasswordToken.user, user);
|
|
99
98
|
|
|
100
99
|
if (validUntil) {
|
|
101
|
-
token.validUntil = new Date(validUntil)
|
|
102
|
-
}
|
|
100
|
+
token.validUntil = new Date(validUntil);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
103
|
token.validUntil = new Date();
|
|
104
104
|
token.validUntil.setTime(token.validUntil.getTime() + 3 * 3600 * 1000);
|
|
105
105
|
}
|
|
@@ -109,31 +109,31 @@ export class PasswordToken extends Model {
|
|
|
109
109
|
return token;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
static async getPasswordRecoveryUrl(user: User, organization: Organization|null, i18n: I18n, validUntil?: Date) {
|
|
112
|
+
static async getPasswordRecoveryUrl(user: User, organization: Organization | null, i18n: I18n, validUntil?: Date) {
|
|
113
113
|
if (user.organizationId !== null && ((user.organizationId ?? null) !== (organization?.id ?? null))) {
|
|
114
|
-
throw new Error('Unexpected mismatch in organization id for PasswordToken')
|
|
114
|
+
throw new Error('Unexpected mismatch in organization id for PasswordToken');
|
|
115
115
|
}
|
|
116
116
|
// Send an e-mail to say you already have an account + follow password forgot flow
|
|
117
|
-
const token = await PasswordToken.createToken(user, validUntil)
|
|
117
|
+
const token = await PasswordToken.createToken(user, validUntil);
|
|
118
118
|
|
|
119
119
|
let host: string;
|
|
120
|
-
if (user.permissions || !organization || STAMHOOFD.userMode ===
|
|
121
|
-
host =
|
|
122
|
-
return host+
|
|
120
|
+
if (user.permissions || !organization || STAMHOOFD.userMode === 'platform') {
|
|
121
|
+
host = 'https://' + (STAMHOOFD.domains.dashboard) + '/' + i18n.locale;
|
|
122
|
+
return host + '/reset-password' + ((user.organizationId || organization) ? ('/' + encodeURIComponent(user.organizationId ?? organization!.id)) : '') + '?token=' + encodeURIComponent(token.token);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
host =
|
|
126
|
-
return host+
|
|
125
|
+
host = 'https://' + organization.getHost(i18n);
|
|
126
|
+
return host + '/reset-password?token=' + encodeURIComponent(token.token);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
static async getMagicSignInUrl(user: User, organization: Organization) {
|
|
130
130
|
// For now we don't add a token yet for security. We might add some sort of email validation thing later on
|
|
131
|
-
const host =
|
|
132
|
-
return Promise.resolve(host+
|
|
131
|
+
const host = 'https://' + organization.getHost();
|
|
132
|
+
return Promise.resolve(host + '/login' + '?email=' + encodeURIComponent(user.email) + '&hasAccount=' + (user.hasAccount() ? 1 : 0));
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
static async clearFor(userId: string) {
|
|
136
136
|
const query = `DELETE from ${this.table} where userId = ?`;
|
|
137
|
-
await Database.delete(query, [userId])
|
|
137
|
+
await Database.delete(query, [userId]);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -1,127 +1,128 @@
|
|
|
1
|
-
import { column, Model } from
|
|
1
|
+
import { column, Model } from '@simonbackx/simple-database';
|
|
2
2
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
3
3
|
import { PayconiqAccount, PaymentStatus, Version } from '@stamhoofd/structures';
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
|
-
import https from
|
|
6
|
-
import { v4 as uuidv4 } from
|
|
5
|
+
import https from 'https';
|
|
6
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
7
7
|
|
|
8
8
|
import { Organization, Payment } from './';
|
|
9
9
|
|
|
10
10
|
export class PayconiqPayment extends Model {
|
|
11
|
-
static table =
|
|
11
|
+
static table = 'payconiq_payments';
|
|
12
12
|
|
|
13
13
|
@column({
|
|
14
|
-
primary: true, type:
|
|
14
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
15
15
|
return value ?? uuidv4();
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
17
|
})
|
|
18
18
|
id!: string;
|
|
19
19
|
|
|
20
|
-
@column({ type:
|
|
20
|
+
@column({ type: 'string' })
|
|
21
21
|
paymentId: string;
|
|
22
22
|
|
|
23
|
-
@column({ type:
|
|
23
|
+
@column({ type: 'string' })
|
|
24
24
|
payconiqId: string;
|
|
25
25
|
|
|
26
26
|
async getStatus(organization: Organization): Promise<PaymentStatus> {
|
|
27
|
-
const apiKey = organization.privateMeta.payconiqApiKey
|
|
27
|
+
const apiKey = organization.privateMeta.payconiqApiKey;
|
|
28
28
|
if (!apiKey) {
|
|
29
29
|
throw new SimpleError({
|
|
30
|
-
code:
|
|
31
|
-
message:
|
|
32
|
-
})
|
|
30
|
+
code: '',
|
|
31
|
+
message: 'Payconiq API key missing to check the status of the payment',
|
|
32
|
+
});
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const response = await PayconiqPayment.request(
|
|
35
|
+
const response = await PayconiqPayment.request('GET', '/v3/payments/' + this.payconiqId, {}, apiKey, organization.privateMeta.useTestPayments ?? STAMHOOFD.environment !== 'production');
|
|
36
36
|
if (response.status) {
|
|
37
37
|
switch (response.status) {
|
|
38
|
-
case
|
|
39
|
-
case
|
|
38
|
+
case 'AUTHORIZED': return PaymentStatus.Pending;
|
|
39
|
+
case 'PENDING': return PaymentStatus.Created;
|
|
40
40
|
|
|
41
|
-
case
|
|
41
|
+
case 'IDENTIFIED': return PaymentStatus.Pending; // Code has been scanned!
|
|
42
42
|
|
|
43
|
-
case
|
|
44
|
-
case
|
|
45
|
-
case
|
|
46
|
-
case
|
|
43
|
+
case 'AUTHORIZATION_FAILED': return PaymentStatus.Failed;
|
|
44
|
+
case 'EXPIRED': return PaymentStatus.Failed;
|
|
45
|
+
case 'FAILED': return PaymentStatus.Failed;
|
|
46
|
+
case 'CANCELLED': return PaymentStatus.Failed;
|
|
47
47
|
|
|
48
|
-
case
|
|
48
|
+
case 'SUCCEEDED': return PaymentStatus.Succeeded;
|
|
49
49
|
}
|
|
50
|
-
return PaymentStatus.Pending // default to pending
|
|
50
|
+
return PaymentStatus.Pending; // default to pending
|
|
51
51
|
}
|
|
52
52
|
throw new SimpleError({
|
|
53
|
-
code:
|
|
54
|
-
message:
|
|
55
|
-
})
|
|
53
|
+
code: '',
|
|
54
|
+
message: 'Status missing in response',
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async cancel(organization: Organization): Promise<boolean> {
|
|
59
|
-
const apiKey = organization.privateMeta.payconiqApiKey
|
|
59
|
+
const apiKey = organization.privateMeta.payconiqApiKey;
|
|
60
60
|
if (!apiKey) {
|
|
61
61
|
throw new SimpleError({
|
|
62
|
-
code:
|
|
63
|
-
message:
|
|
64
|
-
})
|
|
62
|
+
code: '',
|
|
63
|
+
message: 'Payconiq API key missing to check the status of the payment',
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Throws on failure
|
|
68
68
|
try {
|
|
69
|
-
await PayconiqPayment.request(
|
|
69
|
+
await PayconiqPayment.request('DELETE', '/v3/payments/' + this.payconiqId, {}, apiKey, organization.privateMeta.useTestPayments ?? STAMHOOFD.environment !== 'production');
|
|
70
70
|
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.error('Failed to cancel Payconiq payment', this.id, this.payconiqId, e);
|
|
73
74
|
return false;
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
static async createTest(organization: Organization, payconiqAccount: PayconiqAccount): Promise<undefined|object> {
|
|
78
|
-
const apiKey = payconiqAccount.apiKey
|
|
78
|
+
static async createTest(organization: Organization, payconiqAccount: PayconiqAccount): Promise<undefined | object> {
|
|
79
|
+
const apiKey = payconiqAccount.apiKey;
|
|
79
80
|
if (!apiKey) {
|
|
80
|
-
return
|
|
81
|
+
return;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
try {
|
|
84
|
-
const response = await this.request(
|
|
85
|
-
reference:
|
|
85
|
+
const response = await this.request('POST', '/v3/payments', {
|
|
86
|
+
reference: 'test-' + (new Date().getTime()), // 36 chars, max length is 35...
|
|
86
87
|
amount: 1,
|
|
87
|
-
currency:
|
|
88
|
-
callbackUrl: 'https://'+organization.getApiHost(),
|
|
89
|
-
description:
|
|
88
|
+
currency: 'EUR',
|
|
89
|
+
callbackUrl: 'https://' + organization.getApiHost(),
|
|
90
|
+
description: 'Key validation test',
|
|
90
91
|
|
|
91
|
-
}, apiKey, organization.privateMeta.useTestPayments ?? STAMHOOFD.environment
|
|
92
|
+
}, apiKey, organization.privateMeta.useTestPayments ?? STAMHOOFD.environment !== 'production');
|
|
92
93
|
return response;
|
|
93
|
-
}
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
94
96
|
return;
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
|
|
99
100
|
static async createPayment(payment: Payment, organization: Organization, description: string, returnUrl?: string, callbackUrl?: string) {
|
|
100
|
-
const apiKey = organization.privateMeta.payconiqApiKey
|
|
101
|
+
const apiKey = organization.privateMeta.payconiqApiKey;
|
|
101
102
|
if (!apiKey) {
|
|
102
103
|
throw new SimpleError({
|
|
103
|
-
code:
|
|
104
|
-
message:
|
|
105
|
-
})
|
|
104
|
+
code: '',
|
|
105
|
+
message: 'Betaling via Payconiq is tijdelijk onbeschikbaar',
|
|
106
|
+
});
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
const response = await this.request(
|
|
109
|
-
reference: payment.id.replace(
|
|
109
|
+
const response = await this.request('POST', '/v3/payments', {
|
|
110
|
+
reference: payment.id.replace('-', ''), // 36 chars, max length is 35...
|
|
110
111
|
amount: payment.price,
|
|
111
|
-
currency:
|
|
112
|
-
callbackUrl: callbackUrl ?? 'https://'+organization.getApiHost()+
|
|
112
|
+
currency: 'EUR',
|
|
113
|
+
callbackUrl: callbackUrl ?? 'https://' + organization.getApiHost() + '/v' + Version + '/payments/' + encodeURIComponent(payment.id) + '?exchange=true',
|
|
113
114
|
returnUrl,
|
|
114
|
-
description
|
|
115
|
-
}, apiKey, organization.privateMeta.useTestPayments ?? STAMHOOFD.environment
|
|
115
|
+
description,
|
|
116
|
+
}, apiKey, organization.privateMeta.useTestPayments ?? STAMHOOFD.environment !== 'production');
|
|
116
117
|
|
|
117
|
-
const payconiqPayment = new PayconiqPayment()
|
|
118
|
-
payconiqPayment.paymentId = payment.id
|
|
119
|
-
payconiqPayment.payconiqId = response.paymentId
|
|
118
|
+
const payconiqPayment = new PayconiqPayment();
|
|
119
|
+
payconiqPayment.paymentId = payment.id;
|
|
120
|
+
payconiqPayment.payconiqId = response.paymentId;
|
|
120
121
|
|
|
121
122
|
// Read link (currently we use checkout!)
|
|
122
123
|
let link = response._links.checkout.href as string;
|
|
123
124
|
|
|
124
|
-
if (organization.privateMeta.useTestPayments ?? STAMHOOFD.environment
|
|
125
|
+
if (organization.privateMeta.useTestPayments ?? STAMHOOFD.environment !== 'production') {
|
|
125
126
|
// For checkout only!
|
|
126
127
|
// We get the wrong link in development mode
|
|
127
128
|
link = link.replace('https://payconiq.com/', 'https://ext.payconiq.com/');
|
|
@@ -138,20 +139,20 @@ export class PayconiqPayment extends Model {
|
|
|
138
139
|
private static request(method: string, path: string, data = {}, auth: string | null = null, testMode: boolean): Promise<any> {
|
|
139
140
|
return new Promise((resolve, reject) => {
|
|
140
141
|
const jsonData = JSON.stringify(data);
|
|
141
|
-
const hostname = !testMode ?
|
|
142
|
-
const base =
|
|
142
|
+
const hostname = !testMode ? 'api.payconiq.com' : 'api.ext.payconiq.com';
|
|
143
|
+
const base = 'https://' + hostname;
|
|
143
144
|
|
|
144
145
|
// Log all communication
|
|
145
|
-
console.log(method+
|
|
146
|
+
console.log(method + ' ' + base + path + '\n' + jsonData);
|
|
146
147
|
console.log(jsonData);
|
|
147
148
|
|
|
148
149
|
const headers = {
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
151
|
+
'Content-Length': Buffer.byteLength(jsonData),
|
|
151
152
|
};
|
|
152
153
|
|
|
153
154
|
if (auth) {
|
|
154
|
-
headers[
|
|
155
|
+
headers['Authorization'] = 'Bearer ' + auth;
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
const req = https.request(
|
|
@@ -168,14 +169,14 @@ export class PayconiqPayment extends Model {
|
|
|
168
169
|
|
|
169
170
|
const chunks: any[] = [];
|
|
170
171
|
|
|
171
|
-
response.on(
|
|
172
|
+
response.on('data', (chunk) => {
|
|
172
173
|
chunks.push(chunk);
|
|
173
174
|
});
|
|
174
175
|
|
|
175
|
-
response.on(
|
|
176
|
+
response.on('end', () => {
|
|
176
177
|
try {
|
|
177
178
|
if (!response.statusCode) {
|
|
178
|
-
reject(new Error(
|
|
179
|
+
reject(new Error('Unexpected order of events'));
|
|
179
180
|
return;
|
|
180
181
|
}
|
|
181
182
|
const body = Buffer.concat(chunks).toString();
|
|
@@ -189,20 +190,22 @@ export class PayconiqPayment extends Model {
|
|
|
189
190
|
let json: any;
|
|
190
191
|
try {
|
|
191
192
|
json = JSON.parse(body);
|
|
192
|
-
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
193
195
|
console.error(error);
|
|
194
|
-
|
|
196
|
+
|
|
195
197
|
// invalid json
|
|
196
198
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
197
199
|
if (body.length == 0) {
|
|
198
200
|
console.error(response.statusCode);
|
|
199
|
-
reject(new Error(
|
|
201
|
+
reject(new Error('Status ' + response.statusCode));
|
|
200
202
|
return;
|
|
201
203
|
}
|
|
202
|
-
console.error(response.statusCode +
|
|
204
|
+
console.error(response.statusCode + ' ' + body);
|
|
203
205
|
reject(new Error(body));
|
|
204
206
|
return;
|
|
205
|
-
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
206
209
|
// something wrong: throw parse error
|
|
207
210
|
reject(error);
|
|
208
211
|
return;
|
|
@@ -211,25 +214,26 @@ export class PayconiqPayment extends Model {
|
|
|
211
214
|
|
|
212
215
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
213
216
|
console.error(body);
|
|
214
|
-
reject(new Error(response.statusCode +
|
|
217
|
+
reject(new Error(response.statusCode + ' ' + response.statusMessage));
|
|
215
218
|
return;
|
|
216
219
|
}
|
|
217
220
|
|
|
218
221
|
resolve(json);
|
|
219
|
-
}
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
220
224
|
console.error(error);
|
|
221
225
|
reject(error);
|
|
222
226
|
}
|
|
223
227
|
});
|
|
224
|
-
}
|
|
228
|
+
},
|
|
225
229
|
);
|
|
226
230
|
|
|
227
231
|
// use its "timeout" event to abort the request
|
|
228
|
-
req.on(
|
|
232
|
+
req.on('timeout', () => {
|
|
229
233
|
req.abort();
|
|
230
234
|
});
|
|
231
235
|
|
|
232
|
-
req.on(
|
|
236
|
+
req.on('error', (error) => {
|
|
233
237
|
console.error(error);
|
|
234
238
|
reject(error);
|
|
235
239
|
});
|