@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/Group.ts
CHANGED
|
@@ -1,130 +1,131 @@
|
|
|
1
1
|
import { column, Database, ManyToOneRelation, Model, OneToManyRelation } from '@simonbackx/simple-database';
|
|
2
|
-
import { GroupCategory, GroupPrivateSettings, GroupSettings, GroupStatus, Group as GroupStruct, GroupType, StockReservation } from '@stamhoofd/structures';
|
|
3
|
-
import { v4 as uuidv4 } from
|
|
2
|
+
import { GroupCategory, GroupPrivateSettings, GroupSettings, GroupStatus, Group as GroupStruct, GroupType, minimumRegistrationCount, StockReservation } from '@stamhoofd/structures';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
|
|
5
|
+
import { ArrayDecoder } from '@simonbackx/simple-encoding';
|
|
6
|
+
import { QueueHandler } from '@stamhoofd/queues';
|
|
5
7
|
import { Formatter } from '@stamhoofd/utility';
|
|
8
|
+
import { SetupStepUpdater } from '../helpers/SetupStepsUpdater';
|
|
6
9
|
import { Member, MemberWithRegistrations, OrganizationRegistrationPeriod, Payment, Registration, User } from './';
|
|
7
|
-
import { QueueHandler } from '@stamhoofd/queues';
|
|
8
|
-
import { ArrayDecoder } from '@simonbackx/simple-encoding';
|
|
9
10
|
|
|
10
11
|
if (Member === undefined) {
|
|
11
|
-
throw new Error(
|
|
12
|
+
throw new Error('Import Member is undefined');
|
|
12
13
|
}
|
|
13
14
|
if (User === undefined) {
|
|
14
|
-
throw new Error(
|
|
15
|
+
throw new Error('Import User is undefined');
|
|
15
16
|
}
|
|
16
17
|
if (Payment === undefined) {
|
|
17
|
-
throw new Error(
|
|
18
|
+
throw new Error('Import Payment is undefined');
|
|
18
19
|
}
|
|
19
20
|
if (Registration === undefined) {
|
|
20
|
-
throw new Error(
|
|
21
|
+
throw new Error('Import Registration is undefined');
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export class Group extends Model {
|
|
24
|
-
static table =
|
|
25
|
+
static table = 'groups';
|
|
25
26
|
|
|
26
27
|
@column({
|
|
27
|
-
primary: true, type:
|
|
28
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
28
29
|
return value ?? uuidv4();
|
|
29
|
-
}
|
|
30
|
+
},
|
|
30
31
|
})
|
|
31
32
|
id!: string;
|
|
32
33
|
|
|
33
|
-
@column({ type:
|
|
34
|
+
@column({ type: 'string' })
|
|
34
35
|
type = GroupType.Membership;
|
|
35
36
|
|
|
36
|
-
@column({ type:
|
|
37
|
+
@column({ type: 'json', decoder: GroupSettings })
|
|
37
38
|
settings: GroupSettings;
|
|
38
39
|
|
|
39
|
-
@column({
|
|
40
|
-
type:
|
|
40
|
+
@column({
|
|
41
|
+
type: 'json', decoder: GroupPrivateSettings,
|
|
41
42
|
})
|
|
42
|
-
privateSettings = GroupPrivateSettings.create({})
|
|
43
|
+
privateSettings = GroupPrivateSettings.create({});
|
|
43
44
|
|
|
44
|
-
@column({ type:
|
|
45
|
+
@column({ type: 'string' })
|
|
45
46
|
organizationId: string;
|
|
46
47
|
|
|
47
|
-
@column({ type:
|
|
48
|
-
waitingListId: string | null = null
|
|
48
|
+
@column({ type: 'string', nullable: true })
|
|
49
|
+
waitingListId: string | null = null;
|
|
49
50
|
|
|
50
|
-
@column({ type:
|
|
51
|
+
@column({ type: 'string' })
|
|
51
52
|
periodId: string;
|
|
52
53
|
|
|
53
|
-
@column({ type:
|
|
54
|
-
defaultAgeGroupId: string | null = null
|
|
54
|
+
@column({ type: 'string', nullable: true })
|
|
55
|
+
defaultAgeGroupId: string | null = null;
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* Every time a new registration period starts, this number increases. This is used to mark all older registrations as 'out of date' automatically
|
|
58
59
|
*/
|
|
59
|
-
@column({ type:
|
|
60
|
+
@column({ type: 'integer' })
|
|
60
61
|
cycle = 0;
|
|
61
62
|
|
|
62
63
|
@column({
|
|
63
|
-
type:
|
|
64
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
64
65
|
if (old !== undefined) {
|
|
65
66
|
return old;
|
|
66
67
|
}
|
|
67
|
-
const date = new Date()
|
|
68
|
-
date.setMilliseconds(0)
|
|
69
|
-
return date
|
|
70
|
-
}
|
|
68
|
+
const date = new Date();
|
|
69
|
+
date.setMilliseconds(0);
|
|
70
|
+
return date;
|
|
71
|
+
},
|
|
71
72
|
})
|
|
72
|
-
createdAt: Date
|
|
73
|
+
createdAt: Date;
|
|
73
74
|
|
|
74
75
|
@column({
|
|
75
|
-
type:
|
|
76
|
-
const date = new Date()
|
|
77
|
-
date.setMilliseconds(0)
|
|
78
|
-
return date
|
|
76
|
+
type: 'datetime', beforeSave() {
|
|
77
|
+
const date = new Date();
|
|
78
|
+
date.setMilliseconds(0);
|
|
79
|
+
return date;
|
|
79
80
|
},
|
|
80
|
-
skipUpdate: true
|
|
81
|
+
skipUpdate: true,
|
|
81
82
|
})
|
|
82
|
-
updatedAt: Date
|
|
83
|
+
updatedAt: Date;
|
|
83
84
|
|
|
84
85
|
@column({
|
|
85
|
-
type:
|
|
86
|
-
nullable: true
|
|
86
|
+
type: 'datetime',
|
|
87
|
+
nullable: true,
|
|
87
88
|
})
|
|
88
|
-
deletedAt: Date | null = null
|
|
89
|
+
deletedAt: Date | null = null;
|
|
89
90
|
|
|
90
|
-
@column({ type:
|
|
91
|
+
@column({ type: 'string' })
|
|
91
92
|
status = GroupStatus.Open;
|
|
92
93
|
|
|
93
94
|
/**
|
|
94
95
|
* Editing this field is only allowed when running inside the QueueHandler
|
|
95
96
|
*/
|
|
96
|
-
@column({ type:
|
|
97
|
-
stockReservations: StockReservation[] = []
|
|
97
|
+
@column({ type: 'json', decoder: new ArrayDecoder(StockReservation) })
|
|
98
|
+
stockReservations: StockReservation[] = [];
|
|
98
99
|
|
|
99
|
-
static async getAll(organizationId: string, periodId: string|null, active = true) {
|
|
100
|
-
const w: any = periodId ? {periodId} : {}
|
|
100
|
+
static async getAll(organizationId: string, periodId: string | null, active = true) {
|
|
101
|
+
const w: any = periodId ? { periodId } : {};
|
|
101
102
|
if (active) {
|
|
102
103
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
103
|
-
return await Group.where({ organizationId, deletedAt: null, ...w })
|
|
104
|
+
return await Group.where({ organizationId, deletedAt: null, ...w });
|
|
104
105
|
}
|
|
105
106
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
106
|
-
return await Group.where({ organizationId, ...w })
|
|
107
|
+
return await Group.where({ organizationId, ...w });
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
111
|
* Returns all parent and grandparents of this group
|
|
111
112
|
*/
|
|
112
113
|
getParentCategories(all: GroupCategory[], recursive = true): GroupCategory[] {
|
|
113
|
-
const map = new Map<string, GroupCategory>()
|
|
114
|
-
|
|
115
|
-
const parents = all.filter(g => g.groupIds.includes(this.id))
|
|
114
|
+
const map = new Map<string, GroupCategory>();
|
|
115
|
+
|
|
116
|
+
const parents = all.filter(g => g.groupIds.includes(this.id));
|
|
116
117
|
for (const parent of parents) {
|
|
117
|
-
map.set(parent.id, parent)
|
|
118
|
+
map.set(parent.id, parent);
|
|
118
119
|
|
|
119
120
|
if (recursive) {
|
|
120
|
-
const hisParents = parent.getParentCategories(all)
|
|
121
|
+
const hisParents = parent.getParentCategories(all);
|
|
121
122
|
for (const pp of hisParents) {
|
|
122
|
-
map.set(pp.id, pp)
|
|
123
|
+
map.set(pp.id, pp);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
return [...map.values()]
|
|
128
|
+
return [...map.values()];
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
/**
|
|
@@ -132,177 +133,189 @@ export class Group extends Model {
|
|
|
132
133
|
*/
|
|
133
134
|
async getMembersWithRegistration(waitingList = false, cycleOffset = 0): Promise<MemberWithRegistrations[]> {
|
|
134
135
|
let query = `SELECT ${Member.getDefaultSelect()}, ${Registration.getDefaultSelect()}, ${User.getDefaultSelect()} from \`${Member.table}\`\n`;
|
|
135
|
-
|
|
136
|
-
query += `JOIN \`${Registration.table}\` ON \`${Registration.table}\`.\`${Member.registrations.foreignKey}\` = \`${Member.table}\`.\`${Member.primary.name}\` AND (\`${Registration.table}\`.\`registeredAt\` is not null OR \`${Registration.table}\`.\`waitingList\` = 1)\n
|
|
136
|
+
|
|
137
|
+
query += `JOIN \`${Registration.table}\` ON \`${Registration.table}\`.\`${Member.registrations.foreignKey}\` = \`${Member.table}\`.\`${Member.primary.name}\` AND (\`${Registration.table}\`.\`registeredAt\` is not null OR \`${Registration.table}\`.\`waitingList\` = 1)\n`;
|
|
137
138
|
|
|
138
139
|
if (waitingList) {
|
|
139
|
-
query += `JOIN \`${Registration.table}\` as reg_filter ON reg_filter.\`${Member.registrations.foreignKey}\` = \`${Member.table}\`.\`${Member.primary.name}\` AND reg_filter.\`waitingList\` = 1\n
|
|
140
|
-
}
|
|
141
|
-
|
|
140
|
+
query += `JOIN \`${Registration.table}\` as reg_filter ON reg_filter.\`${Member.registrations.foreignKey}\` = \`${Member.table}\`.\`${Member.primary.name}\` AND reg_filter.\`waitingList\` = 1\n`;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
query += `JOIN \`${Registration.table}\` as reg_filter ON reg_filter.\`${Member.registrations.foreignKey}\` = \`${Member.table}\`.\`${Member.primary.name}\` AND reg_filter.\`waitingList\` = 0 AND reg_filter.\`registeredAt\` is not null\n`;
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
query += Member.users.joinQuery(Member.table, User.table)+
|
|
146
|
+
query += Member.users.joinQuery(Member.table, User.table) + '\n';
|
|
145
147
|
|
|
146
148
|
// We do an extra join because we also need to get the other registrations of each member (only one regitration has to match the query)
|
|
147
|
-
query += `where reg_filter.\`groupId\` = ? AND reg_filter.\`cycle\` =
|
|
149
|
+
query += `where reg_filter.\`groupId\` = ? AND reg_filter.\`cycle\` = ?`;
|
|
148
150
|
|
|
149
|
-
const [results] = await Database.select(query, [this.id, this.cycle - cycleOffset])
|
|
150
|
-
const members: MemberWithRegistrations[] = []
|
|
151
|
+
const [results] = await Database.select(query, [this.id, this.cycle - cycleOffset]);
|
|
152
|
+
const members: MemberWithRegistrations[] = [];
|
|
151
153
|
|
|
152
|
-
const groupIds = results.map(r => r[Registration.table]?.groupId).filter(id => id) as string[]
|
|
153
|
-
const groups = await Group.getByIDs(...Formatter.uniqueArray(groupIds))
|
|
154
|
+
const groupIds = results.map(r => r[Registration.table]?.groupId).filter(id => id) as string[];
|
|
155
|
+
const groups = await Group.getByIDs(...Formatter.uniqueArray(groupIds));
|
|
154
156
|
|
|
155
157
|
for (const row of results) {
|
|
156
|
-
const foundMember = Member.fromRow(row[Member.table])
|
|
158
|
+
const foundMember = Member.fromRow(row[Member.table]);
|
|
157
159
|
if (!foundMember) {
|
|
158
|
-
throw new Error(
|
|
160
|
+
throw new Error('Expected member in every row');
|
|
159
161
|
}
|
|
160
|
-
const _f = foundMember.setManyRelation(Member.registrations as unknown as OneToManyRelation<
|
|
162
|
+
const _f = foundMember.setManyRelation(Member.registrations as unknown as OneToManyRelation<'registrations', Member, Registration & { group: Group }>, []).setManyRelation(Member.users, []);
|
|
161
163
|
|
|
162
164
|
// Seach if we already got this member?
|
|
163
|
-
const existingMember = members.find(m => m.id == _f.id)
|
|
165
|
+
const existingMember = members.find(m => m.id == _f.id);
|
|
164
166
|
|
|
165
|
-
const member: MemberWithRegistrations = (existingMember ?? _f)
|
|
167
|
+
const member: MemberWithRegistrations = (existingMember ?? _f);
|
|
166
168
|
if (!existingMember) {
|
|
167
|
-
members.push(member)
|
|
169
|
+
members.push(member);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
// Check if we have a registration with a payment
|
|
171
|
-
const registration = Registration.fromRow(row[Registration.table])
|
|
173
|
+
const registration = Registration.fromRow(row[Registration.table]);
|
|
172
174
|
if (registration) {
|
|
173
175
|
// Check if we already have this registration
|
|
174
176
|
if (!member.registrations.find(r => r.id == registration.id)) {
|
|
175
|
-
const group = groups.find(g => g.id == registration.groupId)
|
|
177
|
+
const group = groups.find(g => g.id == registration.groupId);
|
|
176
178
|
if (!group) {
|
|
177
|
-
throw new Error(
|
|
179
|
+
throw new Error('Expected group');
|
|
178
180
|
}
|
|
179
|
-
member.registrations.push(registration.setRelation(Registration.group, group))
|
|
181
|
+
member.registrations.push(registration.setRelation(Registration.group, group));
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
// Check if we have a user
|
|
184
|
-
const user = User.fromRow(row[User.table])
|
|
186
|
+
const user = User.fromRow(row[User.table]);
|
|
185
187
|
if (user) {
|
|
186
188
|
// Check if we already have this registration
|
|
187
189
|
if (!member.users.find(r => r.id == user.id)) {
|
|
188
|
-
member.users.push(user)
|
|
190
|
+
member.users.push(user);
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
return members
|
|
194
|
-
|
|
195
|
+
return members;
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
/**
|
|
198
199
|
* @deprecated
|
|
199
200
|
*/
|
|
200
201
|
getStructure() {
|
|
201
|
-
return GroupStruct.create({ ...this, privateSettings: null })
|
|
202
|
+
return GroupStruct.create({ ...this, privateSettings: null });
|
|
202
203
|
}
|
|
203
204
|
|
|
204
205
|
/**
|
|
205
206
|
* @deprecated
|
|
206
207
|
*/
|
|
207
208
|
getPrivateStructure() {
|
|
208
|
-
return GroupStruct.create(this)
|
|
209
|
+
return GroupStruct.create(this);
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
private static async getCount(where: string, params: any[]) {
|
|
212
|
-
const query = `select count(*) as c from \`${Registration.table}\` where ${where}
|
|
213
|
-
|
|
214
|
-
const [results] = await Database.select(query, params)
|
|
213
|
+
const query = `select count(*) as c from \`${Registration.table}\` where ${where}`;
|
|
214
|
+
|
|
215
|
+
const [results] = await Database.select(query, params);
|
|
215
216
|
const count = results[0]['']['c'];
|
|
216
217
|
if (Number.isInteger(count)) {
|
|
217
|
-
return count as number
|
|
218
|
+
return count as number;
|
|
218
219
|
}
|
|
219
|
-
return null
|
|
220
|
+
return null;
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
async updateOccupancy() {
|
|
223
|
-
this.settings.registeredMembers
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
async updateOccupancy(options?: { isNew?: boolean }) {
|
|
224
|
+
const registeredMembersBefore = this.settings.registeredMembers ?? 0;
|
|
225
|
+
|
|
226
|
+
const registeredMembersAfter = await Group.getCount(
|
|
227
|
+
'groupId = ? and registeredAt is not null AND deactivatedAt is null',
|
|
228
|
+
[this.id],
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
this.settings.registeredMembers = registeredMembersAfter;
|
|
227
232
|
|
|
228
233
|
this.settings.reservedMembers = await Group.getCount(
|
|
229
|
-
|
|
230
|
-
[this.id, new Date()]
|
|
231
|
-
)
|
|
234
|
+
'groupId = ? and registeredAt is null AND (canRegister = 1 OR reservedUntil >= ?)',
|
|
235
|
+
[this.id, new Date()],
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
if (this.defaultAgeGroupId) {
|
|
239
|
+
const hasSufficientMembersBefore = registeredMembersBefore >= minimumRegistrationCount;
|
|
240
|
+
const hasSufficientMembersAfter = (registeredMembersAfter ?? 0) >= minimumRegistrationCount;
|
|
241
|
+
|
|
242
|
+
if (options?.isNew || hasSufficientMembersAfter !== hasSufficientMembersBefore) {
|
|
243
|
+
SetupStepUpdater.updateForOrganizationId(this.organizationId)
|
|
244
|
+
.catch(console.error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
static async deleteUnreachable(organizationId: string, period: OrganizationRegistrationPeriod, allGroups: Group[]) {
|
|
235
|
-
const reachable = new Map<string, boolean>()
|
|
250
|
+
const reachable = new Map<string, boolean>();
|
|
236
251
|
|
|
237
|
-
const visited = new Map<string, boolean>()
|
|
238
|
-
const queue = [period.settings.rootCategoryId]
|
|
239
|
-
visited.set(period.settings.rootCategoryId, true)
|
|
252
|
+
const visited = new Map<string, boolean>();
|
|
253
|
+
const queue = [period.settings.rootCategoryId];
|
|
254
|
+
visited.set(period.settings.rootCategoryId, true);
|
|
240
255
|
|
|
241
256
|
while (queue.length > 0) {
|
|
242
|
-
const id = queue.shift()
|
|
257
|
+
const id = queue.shift();
|
|
243
258
|
if (!id) {
|
|
244
|
-
break
|
|
259
|
+
break;
|
|
245
260
|
}
|
|
246
261
|
|
|
247
|
-
const category = period.settings.categories.find(c => c.id === id)
|
|
262
|
+
const category = period.settings.categories.find(c => c.id === id);
|
|
248
263
|
if (!category) {
|
|
249
|
-
continue
|
|
264
|
+
continue;
|
|
250
265
|
}
|
|
251
266
|
|
|
252
267
|
for (const i of category.categoryIds) {
|
|
253
268
|
if (!visited.get(i)) {
|
|
254
|
-
queue.push(i)
|
|
255
|
-
visited.set(i, true)
|
|
269
|
+
queue.push(i);
|
|
270
|
+
visited.set(i, true);
|
|
256
271
|
}
|
|
257
272
|
}
|
|
258
273
|
|
|
259
274
|
for (const g of category.groupIds) {
|
|
260
|
-
reachable.set(g, true)
|
|
275
|
+
reachable.set(g, true);
|
|
261
276
|
}
|
|
262
277
|
}
|
|
263
278
|
|
|
264
279
|
for (const group of allGroups) {
|
|
265
280
|
if (group.periodId !== period.periodId) {
|
|
266
|
-
continue
|
|
281
|
+
continue;
|
|
267
282
|
}
|
|
268
283
|
|
|
269
284
|
if (group.type !== GroupType.Membership) {
|
|
270
|
-
continue
|
|
285
|
+
continue;
|
|
271
286
|
}
|
|
272
287
|
|
|
273
288
|
if (!reachable.get(group.id) && group.deletedAt === null) {
|
|
274
|
-
console.log(
|
|
275
|
-
group.deletedAt = new Date()
|
|
276
|
-
await group.save()
|
|
289
|
+
console.log('Deleting unreachable group ' + group.id + ' from organization ' + organizationId + ' org period ' + period.id);
|
|
290
|
+
group.deletedAt = new Date();
|
|
291
|
+
await group.save();
|
|
277
292
|
|
|
278
|
-
Member.updateMembershipsForGroupId(group.id)
|
|
293
|
+
Member.updateMembershipsForGroupId(group.id);
|
|
279
294
|
}
|
|
280
295
|
}
|
|
281
296
|
}
|
|
282
297
|
|
|
283
298
|
static async applyStockReservations(groupId: string, addStockReservations: StockReservation[], free = false) {
|
|
284
|
-
await QueueHandler.schedule('group-stock-update-'+groupId, async () => {
|
|
285
|
-
const updatedGroup = await Group.getByID(groupId)
|
|
299
|
+
await QueueHandler.schedule('group-stock-update-' + groupId, async () => {
|
|
300
|
+
const updatedGroup = await Group.getByID(groupId);
|
|
286
301
|
if (!updatedGroup) {
|
|
287
|
-
throw new Error(
|
|
302
|
+
throw new Error('Expected group');
|
|
288
303
|
}
|
|
289
304
|
|
|
290
305
|
if (!free) {
|
|
291
|
-
updatedGroup.stockReservations = StockReservation.added(updatedGroup.stockReservations, addStockReservations)
|
|
292
|
-
} else {
|
|
293
|
-
updatedGroup.stockReservations = StockReservation.removed(updatedGroup.stockReservations, addStockReservations)
|
|
306
|
+
updatedGroup.stockReservations = StockReservation.added(updatedGroup.stockReservations, addStockReservations);
|
|
294
307
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
308
|
+
else {
|
|
309
|
+
updatedGroup.stockReservations = StockReservation.removed(updatedGroup.stockReservations, addStockReservations);
|
|
310
|
+
}
|
|
311
|
+
await updatedGroup.save();
|
|
312
|
+
});
|
|
298
313
|
}
|
|
299
314
|
|
|
300
315
|
static async freeStockReservations(groupId: string, reservations: StockReservation[]) {
|
|
301
|
-
return await this.applyStockReservations(groupId, reservations, true)
|
|
316
|
+
return await this.applyStockReservations(groupId, reservations, true);
|
|
302
317
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
318
|
}
|
|
306
319
|
|
|
307
|
-
Registration.group = new ManyToOneRelation(Group,
|
|
308
|
-
Registration.group.foreignKey =
|
|
320
|
+
Registration.group = new ManyToOneRelation(Group, 'group');
|
|
321
|
+
Registration.group.foreignKey = 'groupId';
|
package/src/models/Image.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
import { column, Model } from "@simonbackx/simple-database";
|
|
1
|
+
import { column, Model } from '@simonbackx/simple-database';
|
|
3
2
|
import { ArrayDecoder } from '@simonbackx/simple-encoding';
|
|
4
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
5
4
|
import { File, Resolution, ResolutionRequest } from '@stamhoofd/structures';
|
|
6
5
|
import AWS from 'aws-sdk';
|
|
7
|
-
import sharp from
|
|
8
|
-
import { v4 as uuidv4 } from
|
|
6
|
+
import sharp from 'sharp';
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
8
|
|
|
10
9
|
export class Image extends Model {
|
|
11
|
-
static table =
|
|
10
|
+
static table = 'images';
|
|
12
11
|
|
|
13
|
-
@column({ primary: true, type:
|
|
12
|
+
@column({ primary: true, type: 'string', beforeSave(value) {
|
|
14
13
|
return value ?? uuidv4();
|
|
15
14
|
} })
|
|
16
15
|
id!: string;
|
|
17
16
|
|
|
18
|
-
@column({ type:
|
|
19
|
-
source: File
|
|
17
|
+
@column({ type: 'json', decoder: File })
|
|
18
|
+
source: File;
|
|
20
19
|
|
|
21
|
-
@column({ type:
|
|
22
|
-
resolutions: Resolution[] = []
|
|
20
|
+
@column({ type: 'json', decoder: new ArrayDecoder(Resolution) })
|
|
21
|
+
resolutions: Resolution[] = [];
|
|
23
22
|
|
|
24
|
-
@column({ type:
|
|
25
|
-
createdAt: Date = new Date()
|
|
23
|
+
@column({ type: 'datetime' })
|
|
24
|
+
createdAt: Date = new Date();
|
|
26
25
|
|
|
27
26
|
static async create(fileContent: string | Buffer, type: string | undefined, resolutions: ResolutionRequest[]): Promise<Image> {
|
|
28
27
|
if (!STAMHOOFD.SPACES_BUCKET || !STAMHOOFD.SPACES_ENDPOINT || !STAMHOOFD.SPACES_KEY || !STAMHOOFD.SPACES_SECRET) {
|
|
29
28
|
throw new SimpleError({
|
|
30
|
-
code:
|
|
31
|
-
message:
|
|
32
|
-
statusCode: 503
|
|
33
|
-
})
|
|
29
|
+
code: 'not_available',
|
|
30
|
+
message: 'Uploading is not available',
|
|
31
|
+
statusCode: 503,
|
|
32
|
+
});
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
let fileType = 'png';
|
|
37
|
-
if (type ==
|
|
38
|
-
fileType =
|
|
36
|
+
if (type == 'image/jpeg' || type == 'image/jpg') {
|
|
37
|
+
fileType = 'jpg';
|
|
39
38
|
}
|
|
40
|
-
if (type ===
|
|
41
|
-
fileType =
|
|
39
|
+
if (type === 'image/svg+xml' || type === 'image/svg') {
|
|
40
|
+
fileType = 'svg';
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
console.log('creating image', fileType, type, resolutions)
|
|
43
|
+
console.log('creating image', fileType, type, resolutions);
|
|
45
44
|
|
|
46
|
-
const supportsTransparency = fileType ==
|
|
47
|
-
const promises: Promise<{data: Buffer;info: sharp.OutputInfo}>[] = [];
|
|
45
|
+
const supportsTransparency = fileType == 'png' || fileType == 'svg';
|
|
46
|
+
const promises: Promise<{ data: Buffer;info: sharp.OutputInfo }>[] = [];
|
|
48
47
|
|
|
49
48
|
if (resolutions.length) {
|
|
50
|
-
let sharpStream = sharp(fileContent, fileType === 'svg' ? {density: 600} : {}).rotate();
|
|
49
|
+
let sharpStream = sharp(fileContent, fileType === 'svg' ? { density: 600 } : {}).rotate();
|
|
51
50
|
if (!supportsTransparency) {
|
|
52
|
-
sharpStream = sharpStream.flatten({background: {r: 255, g: 255, b: 255}});
|
|
51
|
+
sharpStream = sharpStream.flatten({ background: { r: 255, g: 255, b: 255 } });
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
for(const r of resolutions) {
|
|
54
|
+
for (const r of resolutions) {
|
|
56
55
|
const size = {
|
|
57
56
|
width: r.width ?? undefined,
|
|
58
57
|
height: r.height ?? undefined,
|
|
59
58
|
fit: r.fit,
|
|
60
|
-
withoutEnlargement: type !==
|
|
61
|
-
}
|
|
59
|
+
withoutEnlargement: type !== 'image/svg+xml',
|
|
60
|
+
};
|
|
62
61
|
|
|
63
62
|
let t = sharpStream.resize(size);
|
|
64
63
|
|
|
65
64
|
// Generate the image data
|
|
66
65
|
if (!supportsTransparency) {
|
|
67
66
|
t = t.jpeg({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
67
|
+
quality: 80,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
71
|
t = t.png();
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -80,37 +80,37 @@ export class Image extends Model {
|
|
|
80
80
|
const s3 = new AWS.S3({
|
|
81
81
|
endpoint: STAMHOOFD.SPACES_ENDPOINT,
|
|
82
82
|
accessKeyId: STAMHOOFD.SPACES_KEY,
|
|
83
|
-
secretAccessKey: STAMHOOFD.SPACES_SECRET
|
|
83
|
+
secretAccessKey: STAMHOOFD.SPACES_SECRET,
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
let prefix = (STAMHOOFD.SPACES_PREFIX ??
|
|
86
|
+
let prefix = (STAMHOOFD.SPACES_PREFIX ?? '');
|
|
87
87
|
if (prefix.length > 0) {
|
|
88
|
-
prefix +=
|
|
88
|
+
prefix += '/';
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
const uploadPromises: Promise<any>[] = []
|
|
92
|
-
const image = new Image()
|
|
91
|
+
const uploadPromises: Promise<any>[] = [];
|
|
92
|
+
const image = new Image();
|
|
93
93
|
image.id = uuidv4();
|
|
94
94
|
|
|
95
95
|
for (const f of files) {
|
|
96
96
|
const fileId = uuidv4();
|
|
97
97
|
|
|
98
|
-
const key = prefix+(STAMHOOFD.environment ??
|
|
98
|
+
const key = prefix + (STAMHOOFD.environment ?? 'development') + '/' + image.id + '/' + fileId + (!supportsTransparency ? '.jpg' : '.png');
|
|
99
99
|
const params = {
|
|
100
100
|
Bucket: STAMHOOFD.SPACES_BUCKET,
|
|
101
101
|
Key: key,
|
|
102
102
|
Body: f.data,
|
|
103
103
|
ContentType: !supportsTransparency ? 'image/jpeg' : 'image/png',
|
|
104
|
-
ACL:
|
|
104
|
+
ACL: 'public-read',
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
uploadPromises.push(s3.putObject(params).promise());
|
|
108
108
|
|
|
109
109
|
const _file = new File({
|
|
110
110
|
id: fileId,
|
|
111
|
-
server:
|
|
111
|
+
server: 'https://' + STAMHOOFD.SPACES_BUCKET + '.' + STAMHOOFD.SPACES_ENDPOINT,
|
|
112
112
|
path: key,
|
|
113
|
-
size: f.info.size
|
|
113
|
+
size: f.info.size,
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
const _image = new Resolution({
|
|
@@ -118,32 +118,32 @@ export class Image extends Model {
|
|
|
118
118
|
width: f.info.width,
|
|
119
119
|
height: f.info.height,
|
|
120
120
|
});
|
|
121
|
-
image.resolutions.push(_image)
|
|
121
|
+
image.resolutions.push(_image);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// Also include the source, in private mode
|
|
125
125
|
const fileId = uuidv4();
|
|
126
|
-
const uploadExt = fileType
|
|
127
|
-
const key = prefix+(STAMHOOFD.environment ??
|
|
126
|
+
const uploadExt = fileType;
|
|
127
|
+
const key = prefix + (STAMHOOFD.environment ?? 'development') + '/' + image.id + '/' + fileId + '.' + uploadExt;
|
|
128
128
|
const params = {
|
|
129
129
|
Bucket: STAMHOOFD.SPACES_BUCKET,
|
|
130
130
|
Key: key,
|
|
131
131
|
Body: fileContent,
|
|
132
|
-
ContentType: type ??
|
|
133
|
-
ACL:
|
|
132
|
+
ContentType: type ?? 'image/jpeg',
|
|
133
|
+
ACL: 'private',
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
image.source = new File({
|
|
137
137
|
id: fileId,
|
|
138
|
-
server:
|
|
138
|
+
server: 'https://' + STAMHOOFD.SPACES_BUCKET + '.' + STAMHOOFD.SPACES_ENDPOINT,
|
|
139
139
|
path: key,
|
|
140
|
-
size: fileContent.length
|
|
140
|
+
size: fileContent.length,
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
uploadPromises.push(s3.putObject(params).promise());
|
|
144
144
|
|
|
145
145
|
await Promise.all(uploadPromises);
|
|
146
146
|
await image.save();
|
|
147
|
-
return image
|
|
147
|
+
return image;
|
|
148
148
|
}
|
|
149
149
|
}
|