@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/User.ts
CHANGED
|
@@ -1,84 +1,83 @@
|
|
|
1
|
+
import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { EmailInterfaceRecipient } from '@stamhoofd/email';
|
|
3
|
+
import { LoginProviderType, NewUser, Permissions, Recipient, Replacement, UserMeta, UserPermissions, User as UserStruct } from '@stamhoofd/structures';
|
|
4
|
+
import argon2 from 'argon2';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
1
6
|
|
|
2
|
-
import {
|
|
3
|
-
import { EmailInterfaceRecipient } from "@stamhoofd/email";
|
|
4
|
-
import { LoginProviderType, NewUser, Permissions, Recipient, Replacement, UserMeta, UserPermissions, User as UserStruct } from "@stamhoofd/structures";
|
|
5
|
-
import argon2 from "argon2";
|
|
6
|
-
import { v4 as uuidv4 } from "uuid";
|
|
7
|
-
|
|
8
|
-
import { Organization } from "./";
|
|
7
|
+
import { Organization } from './';
|
|
9
8
|
|
|
10
9
|
export class User extends Model {
|
|
11
|
-
static table =
|
|
10
|
+
static table = 'users';
|
|
12
11
|
|
|
13
12
|
// Columns
|
|
14
13
|
@column({
|
|
15
|
-
primary: true, type:
|
|
14
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
16
15
|
return value ?? uuidv4();
|
|
17
|
-
}
|
|
16
|
+
},
|
|
18
17
|
})
|
|
19
18
|
id!: string;
|
|
20
19
|
|
|
21
|
-
@column({ foreignKey: User.organization, type:
|
|
22
|
-
organizationId: string|null;
|
|
20
|
+
@column({ foreignKey: User.organization, type: 'string', nullable: true })
|
|
21
|
+
organizationId: string | null;
|
|
23
22
|
|
|
24
|
-
@column({ type:
|
|
25
|
-
memberId: string|null = null
|
|
23
|
+
@column({ type: 'string', nullable: true })
|
|
24
|
+
memberId: string | null = null;
|
|
26
25
|
|
|
27
|
-
@column({ type:
|
|
26
|
+
@column({ type: 'string', nullable: true })
|
|
28
27
|
firstName: string | null = null;
|
|
29
28
|
|
|
30
|
-
@column({ type:
|
|
29
|
+
@column({ type: 'string', nullable: true })
|
|
31
30
|
lastName: string | null = null;
|
|
32
31
|
|
|
33
|
-
@column({ type:
|
|
32
|
+
@column({ type: 'string' })
|
|
34
33
|
email: string;
|
|
35
34
|
|
|
36
|
-
@column({ type:
|
|
35
|
+
@column({ type: 'string', nullable: true })
|
|
37
36
|
password: string | null = null;
|
|
38
37
|
|
|
39
|
-
@column({ type:
|
|
40
|
-
verified = false
|
|
38
|
+
@column({ type: 'boolean' })
|
|
39
|
+
verified = false;
|
|
41
40
|
|
|
42
|
-
@column({ type:
|
|
43
|
-
permissions: UserPermissions | null = null
|
|
41
|
+
@column({ type: 'json', decoder: UserPermissions, nullable: true })
|
|
42
|
+
permissions: UserPermissions | null = null;
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* @deprecated
|
|
47
46
|
* use permissions
|
|
48
47
|
*/
|
|
49
|
-
@column({ type:
|
|
50
|
-
organizationPermissions: Permissions | null = null
|
|
48
|
+
@column({ type: 'json', decoder: Permissions, nullable: true })
|
|
49
|
+
organizationPermissions: Permissions | null = null;
|
|
51
50
|
|
|
52
|
-
@column({ type:
|
|
53
|
-
meta: UserMeta | null = null
|
|
51
|
+
@column({ type: 'json', decoder: UserMeta, nullable: true })
|
|
52
|
+
meta: UserMeta | null = null;
|
|
54
53
|
|
|
55
54
|
@column({
|
|
56
|
-
type:
|
|
55
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
57
56
|
if (old !== undefined) {
|
|
58
57
|
return old;
|
|
59
58
|
}
|
|
60
|
-
const date = new Date()
|
|
61
|
-
date.setMilliseconds(0)
|
|
62
|
-
return date
|
|
63
|
-
}
|
|
59
|
+
const date = new Date();
|
|
60
|
+
date.setMilliseconds(0);
|
|
61
|
+
return date;
|
|
62
|
+
},
|
|
64
63
|
})
|
|
65
|
-
createdAt: Date
|
|
64
|
+
createdAt: Date;
|
|
66
65
|
|
|
67
66
|
@column({
|
|
68
|
-
type:
|
|
69
|
-
const date = new Date()
|
|
70
|
-
date.setMilliseconds(0)
|
|
71
|
-
return date
|
|
67
|
+
type: 'datetime', beforeSave() {
|
|
68
|
+
const date = new Date();
|
|
69
|
+
date.setMilliseconds(0);
|
|
70
|
+
return date;
|
|
72
71
|
},
|
|
73
|
-
skipUpdate: true
|
|
72
|
+
skipUpdate: true,
|
|
74
73
|
})
|
|
75
|
-
updatedAt: Date
|
|
74
|
+
updatedAt: Date;
|
|
76
75
|
|
|
77
|
-
static organization = new ManyToOneRelation(Organization,
|
|
76
|
+
static organization = new ManyToOneRelation(Organization, 'organization');
|
|
78
77
|
|
|
79
78
|
get name() {
|
|
80
79
|
if (this.firstName && this.lastName) {
|
|
81
|
-
return this.firstName +
|
|
80
|
+
return this.firstName + ' ' + this.lastName;
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
if (this.firstName) {
|
|
@@ -101,52 +100,53 @@ export class User extends Model {
|
|
|
101
100
|
...replacements,
|
|
102
101
|
Replacement.create({
|
|
103
102
|
token: 'firstName',
|
|
104
|
-
value: this.firstName ?? ''
|
|
103
|
+
value: this.firstName ?? '',
|
|
105
104
|
}),
|
|
106
105
|
Replacement.create({
|
|
107
106
|
token: 'lastName',
|
|
108
|
-
value: this.lastName ?? ''
|
|
107
|
+
value: this.lastName ?? '',
|
|
109
108
|
}),
|
|
110
109
|
Replacement.create({
|
|
111
110
|
token: 'email',
|
|
112
|
-
value: this.email
|
|
113
|
-
})
|
|
114
|
-
]
|
|
115
|
-
})
|
|
111
|
+
value: this.email,
|
|
112
|
+
}),
|
|
113
|
+
],
|
|
114
|
+
});
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
static async getAdmins(organizationIds: string[], options?: {verified?: boolean}) {
|
|
117
|
+
static async getAdmins(organizationIds: string[], options?: { verified?: boolean }) {
|
|
119
118
|
if (organizationIds.length == 0) {
|
|
120
|
-
return []
|
|
119
|
+
return [];
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
if (STAMHOOFD.userMode === 'platform') {
|
|
124
123
|
// Custom implementation
|
|
125
|
-
let global = (await User.where({ organizationId: null, permissions: { sign:
|
|
126
|
-
global = global.filter(u => organizationIds.find(organizationId => u.permissions?.organizationPermissions.has(organizationId)))
|
|
124
|
+
let global = (await User.where({ organizationId: null, permissions: { sign: '!=', value: null } }));
|
|
125
|
+
global = global.filter(u => organizationIds.find(organizationId => u.permissions?.organizationPermissions.has(organizationId)));
|
|
127
126
|
|
|
128
127
|
// Hide api accounts
|
|
129
|
-
global = global.filter(a => !a.isApiUser)
|
|
128
|
+
global = global.filter(a => !a.isApiUser);
|
|
130
129
|
|
|
131
|
-
return global
|
|
130
|
+
return global;
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
const query: any = {
|
|
135
|
-
permissions: { sign:
|
|
136
|
-
organizationId: {sign: 'IN', value: organizationIds},
|
|
134
|
+
permissions: { sign: '!=', value: null },
|
|
135
|
+
organizationId: { sign: 'IN', value: organizationIds },
|
|
137
136
|
};
|
|
138
137
|
|
|
139
138
|
if (options?.verified !== undefined) {
|
|
140
|
-
query.verified = options.verified
|
|
139
|
+
query.verified = options.verified;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
return (
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
144
144
|
await User.where(query)
|
|
145
|
-
).filter(a => !a.isApiUser)
|
|
145
|
+
).filter(a => !a.isApiUser);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
static async getApiUsers(organizationIds: string[]) {
|
|
149
|
-
return organizationIds.length > 0 ? (await User.where({ permissions: { sign:
|
|
149
|
+
return organizationIds.length > 0 ? (await User.where({ permissions: { sign: '!=', value: null }, organizationId: { sign: 'IN', value: organizationIds } })).filter(a => a.isApiUser) : [];
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
async merge(other: User) {
|
|
@@ -154,7 +154,8 @@ export class User extends Model {
|
|
|
154
154
|
// We are going to merge accounts!
|
|
155
155
|
if (this.organizationPermissions && other.organizationPermissions) {
|
|
156
156
|
this.organizationPermissions.add(other.organizationPermissions);
|
|
157
|
-
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
158
159
|
if (!this.organizationPermissions && other.organizationPermissions) {
|
|
159
160
|
this.organizationPermissions = other.organizationPermissions;
|
|
160
161
|
}
|
|
@@ -170,74 +171,75 @@ export class User extends Model {
|
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
const Member = (await import(
|
|
174
|
+
const Member = (await import('./Member')).Member;
|
|
174
175
|
|
|
175
176
|
// Delete placeholder account, but migrate members first
|
|
176
|
-
const members = await Member.getMembersWithRegistrationForUser(other)
|
|
177
|
+
const members = await Member.getMembersWithRegistrationForUser(other);
|
|
177
178
|
|
|
178
179
|
if (members.length > 0) {
|
|
179
|
-
console.log(
|
|
180
|
-
await Member.users.reverse(
|
|
180
|
+
console.log('Moving members from user ' + other.id + ' to ' + this.id);
|
|
181
|
+
await Member.users.reverse('members').link(this, members);
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
// Update balance items
|
|
184
|
-
const query =
|
|
185
|
-
await Database.update(query, [this.id, other.id])
|
|
185
|
+
const query = 'UPDATE balance_items SET userId = ? WHERE userId = ?';
|
|
186
|
+
await Database.update(query, [this.id, other.id]);
|
|
186
187
|
|
|
187
188
|
// Update payments
|
|
188
|
-
const query2 =
|
|
189
|
-
await Database.update(query2, [this.id, other.id])
|
|
189
|
+
const query2 = 'UPDATE payments SET userId = ? WHERE userId = ?';
|
|
190
|
+
await Database.update(query2, [this.id, other.id]);
|
|
190
191
|
|
|
191
192
|
// Update orders
|
|
192
|
-
const query3 =
|
|
193
|
-
await Database.update(query3, [this.id, other.id])
|
|
193
|
+
const query3 = 'UPDATE webshop_orders SET userId = ? WHERE userId = ?';
|
|
194
|
+
await Database.update(query3, [this.id, other.id]);
|
|
194
195
|
|
|
195
|
-
await other.delete()
|
|
196
|
+
await other.delete();
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
static async login(organizationId: string|null, email: string, password: string): Promise<User | undefined> {
|
|
199
|
-
const user = await User.getForAuthentication(organizationId, email)
|
|
199
|
+
static async login(organizationId: string | null, email: string, password: string): Promise<User | undefined> {
|
|
200
|
+
const user = await User.getForAuthentication(organizationId, email);
|
|
200
201
|
if (!user || !user.hasKeys() || user.isApiUser) {
|
|
201
|
-
return undefined
|
|
202
|
+
return undefined;
|
|
202
203
|
}
|
|
203
204
|
|
|
204
205
|
if (STAMHOOFD.environment === 'development') {
|
|
205
206
|
if (password === 'stamhoofd') {
|
|
206
|
-
return user
|
|
207
|
+
return user;
|
|
207
208
|
}
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
if (!user.password) {
|
|
211
|
-
console.log('Tried to login to a user without password', email)
|
|
212
|
-
return
|
|
212
|
+
console.log('Tried to login to a user without password', email);
|
|
213
|
+
return;
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
try {
|
|
216
217
|
if (await argon2.verify(user.password, password)) {
|
|
217
|
-
return user
|
|
218
|
+
return user;
|
|
218
219
|
}
|
|
219
|
-
}
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
220
222
|
// internal failure
|
|
221
|
-
console.error(e)
|
|
223
|
+
console.error(e);
|
|
222
224
|
}
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
/// Delete users when we delete a member
|
|
226
228
|
static async deleteForDeletedMember(memberId: string) {
|
|
227
229
|
const [rows] = await Database.delete(`DELETE ${this.table} FROM ${this.table} JOIN _members_users a ON a.usersId = ${this.table}.id LEFT JOIN _members_users b ON b.usersId = ${this.table}.id AND b.membersId != a.membersId WHERE a.membersId = ? and b.membersId is null and users.permissions is null`, [memberId]);
|
|
228
|
-
return rows
|
|
230
|
+
return rows;
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
hasPasswordBasedAccount() {
|
|
232
234
|
if (this.password) {
|
|
233
235
|
return true;
|
|
234
236
|
}
|
|
235
|
-
|
|
236
|
-
return false
|
|
237
|
+
|
|
238
|
+
return false;
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
get isApiUser() {
|
|
240
|
-
return !this.email.includes('@') && this.email.endsWith('.api') && this.verified
|
|
242
|
+
return !this.email.includes('@') && this.email.endsWith('.api') && this.verified;
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
hasAccount() {
|
|
@@ -250,7 +252,7 @@ export class User extends Model {
|
|
|
250
252
|
if (this.isApiUser) {
|
|
251
253
|
return true;
|
|
252
254
|
}
|
|
253
|
-
return false
|
|
255
|
+
return false;
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
protected hasKeys() {
|
|
@@ -262,51 +264,51 @@ export class User extends Model {
|
|
|
262
264
|
return false;
|
|
263
265
|
}
|
|
264
266
|
|
|
265
|
-
static async getForRegister(organizationId: string|null, email: string): Promise<User | undefined> {
|
|
266
|
-
return await this.getForAuthentication(organizationId, email, {allowWithoutAccount: true})
|
|
267
|
+
static async getForRegister(organizationId: string | null, email: string): Promise<User | undefined> {
|
|
268
|
+
return await this.getForAuthentication(organizationId, email, { allowWithoutAccount: true });
|
|
267
269
|
}
|
|
268
270
|
|
|
269
271
|
static async getOrganizationLevelUser(organizationId: string, email: string): Promise<User | undefined> {
|
|
270
272
|
const users = await User.where({
|
|
271
273
|
email,
|
|
272
|
-
organizationId: organizationId
|
|
274
|
+
organizationId: organizationId,
|
|
273
275
|
}, {
|
|
274
|
-
limit: 1
|
|
275
|
-
})
|
|
276
|
+
limit: 1,
|
|
277
|
+
});
|
|
276
278
|
|
|
277
279
|
if (users.length == 0) {
|
|
278
280
|
return undefined;
|
|
279
281
|
}
|
|
280
|
-
const user = users[0]
|
|
282
|
+
const user = users[0];
|
|
281
283
|
|
|
282
284
|
if (!user) {
|
|
283
|
-
return undefined
|
|
285
|
+
return undefined;
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
return user;
|
|
287
289
|
}
|
|
288
290
|
|
|
289
|
-
static async getForAuthentication(organizationId: string|null, email: string, {allowWithoutAccount = false}: {allowWithoutAccount?: boolean} = {}): Promise<User | undefined> {
|
|
291
|
+
static async getForAuthentication(organizationId: string | null, email: string, { allowWithoutAccount = false }: { allowWithoutAccount?: boolean } = {}): Promise<User | undefined> {
|
|
290
292
|
const users = await User.where({
|
|
291
293
|
email,
|
|
292
|
-
organizationId: STAMHOOFD.userMode === 'platform' ? null : organizationId
|
|
294
|
+
organizationId: STAMHOOFD.userMode === 'platform' ? null : organizationId,
|
|
293
295
|
}, {
|
|
294
|
-
limit: 1
|
|
295
|
-
})
|
|
296
|
+
limit: 1,
|
|
297
|
+
});
|
|
296
298
|
|
|
297
299
|
if (users.length == 0) {
|
|
298
300
|
if (organizationId && STAMHOOFD.userMode === 'organization') {
|
|
299
|
-
return this.getForAuthentication(null, email, {allowWithoutAccount})
|
|
301
|
+
return this.getForAuthentication(null, email, { allowWithoutAccount });
|
|
300
302
|
}
|
|
301
303
|
return undefined;
|
|
302
304
|
}
|
|
303
|
-
const user = users[0]
|
|
305
|
+
const user = users[0];
|
|
304
306
|
|
|
305
307
|
if (!user || (!user.hasKeys() && !allowWithoutAccount)) {
|
|
306
308
|
if (organizationId && STAMHOOFD.userMode === 'organization') {
|
|
307
|
-
return this.getForAuthentication(null, email, {allowWithoutAccount})
|
|
309
|
+
return this.getForAuthentication(null, email, { allowWithoutAccount });
|
|
308
310
|
}
|
|
309
|
-
return undefined
|
|
311
|
+
return undefined;
|
|
310
312
|
}
|
|
311
313
|
|
|
312
314
|
// Read member + address from first row
|
|
@@ -314,37 +316,38 @@ export class User extends Model {
|
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
static async hash(password: string) {
|
|
317
|
-
const hash = await argon2.hash(password, { type: argon2.argon2id })
|
|
318
|
-
return hash
|
|
319
|
+
const hash = await argon2.hash(password, { type: argon2.argon2id });
|
|
320
|
+
return hash;
|
|
319
321
|
}
|
|
320
322
|
|
|
321
323
|
static async createInvited(
|
|
322
|
-
organization: Organization|null,
|
|
323
|
-
data: {firstName: string|null
|
|
324
|
+
organization: Organization | null,
|
|
325
|
+
data: { firstName: string | null; lastName: string | null; email: string; allowPlatform?: boolean },
|
|
324
326
|
): Promise<User | undefined> {
|
|
325
327
|
const {
|
|
326
328
|
email,
|
|
327
329
|
firstName,
|
|
328
|
-
lastName
|
|
330
|
+
lastName,
|
|
329
331
|
} = data;
|
|
330
332
|
|
|
331
333
|
if (!organization && STAMHOOFD.userMode !== 'platform' && !data.allowPlatform) {
|
|
332
|
-
throw new Error(
|
|
334
|
+
throw new Error('Missing organization');
|
|
333
335
|
}
|
|
334
336
|
|
|
335
337
|
const user = new User();
|
|
336
|
-
user.organizationId = STAMHOOFD.userMode === 'platform' ? null : (organization?.id ?? null)
|
|
337
|
-
user.id = uuidv4()
|
|
338
|
+
user.organizationId = STAMHOOFD.userMode === 'platform' ? null : (organization?.id ?? null);
|
|
339
|
+
user.id = uuidv4();
|
|
338
340
|
user.email = email;
|
|
339
341
|
user.verified = false;
|
|
340
|
-
user.firstName = firstName
|
|
341
|
-
user.lastName = lastName
|
|
342
|
+
user.firstName = firstName;
|
|
343
|
+
user.lastName = lastName;
|
|
342
344
|
|
|
343
345
|
try {
|
|
344
346
|
await user.save();
|
|
345
|
-
}
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
346
349
|
// Duplicate key probably
|
|
347
|
-
if (e.code && e.code ==
|
|
350
|
+
if (e.code && e.code == 'ER_DUP_ENTRY') {
|
|
348
351
|
return;
|
|
349
352
|
}
|
|
350
353
|
throw e;
|
|
@@ -354,44 +357,45 @@ export class User extends Model {
|
|
|
354
357
|
}
|
|
355
358
|
|
|
356
359
|
static async register(
|
|
357
|
-
organization: Organization|null,
|
|
358
|
-
data: NewUser
|
|
360
|
+
organization: Organization | null,
|
|
361
|
+
data: NewUser,
|
|
359
362
|
): Promise<User | undefined> {
|
|
360
363
|
const {
|
|
361
364
|
email,
|
|
362
365
|
password,
|
|
363
366
|
id,
|
|
364
367
|
firstName,
|
|
365
|
-
lastName
|
|
368
|
+
lastName,
|
|
366
369
|
} = data;
|
|
367
370
|
|
|
368
371
|
if (!password) {
|
|
369
|
-
throw new Error(
|
|
372
|
+
throw new Error('A password is required for new users');
|
|
370
373
|
}
|
|
371
374
|
|
|
372
375
|
if (!organization && STAMHOOFD.userMode !== 'platform') {
|
|
373
|
-
throw new Error(
|
|
376
|
+
throw new Error('Missing organization');
|
|
374
377
|
}
|
|
375
378
|
|
|
376
|
-
if (await User.getForAuthentication(organization?.id ?? null, email, {allowWithoutAccount: true})) {
|
|
379
|
+
if (await User.getForAuthentication(organization?.id ?? null, email, { allowWithoutAccount: true })) {
|
|
377
380
|
// Already exists
|
|
378
381
|
return;
|
|
379
382
|
}
|
|
380
383
|
|
|
381
384
|
const user = new User();
|
|
382
|
-
user.organizationId = STAMHOOFD.userMode === 'platform' ? null : (organization?.id ?? null)
|
|
383
|
-
user.id = id ?? uuidv4()
|
|
385
|
+
user.organizationId = STAMHOOFD.userMode === 'platform' ? null : (organization?.id ?? null);
|
|
386
|
+
user.id = id ?? uuidv4();
|
|
384
387
|
user.email = email;
|
|
385
|
-
user.password = await this.hash(password)
|
|
388
|
+
user.password = await this.hash(password);
|
|
386
389
|
user.verified = false;
|
|
387
|
-
user.firstName = firstName
|
|
388
|
-
user.lastName = lastName
|
|
390
|
+
user.firstName = firstName;
|
|
391
|
+
user.lastName = lastName;
|
|
389
392
|
|
|
390
393
|
try {
|
|
391
394
|
await user.save();
|
|
392
|
-
}
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
393
397
|
// Duplicate key probably
|
|
394
|
-
if (e.code && e.code ==
|
|
398
|
+
if (e.code && e.code == 'ER_DUP_ENTRY') {
|
|
395
399
|
return;
|
|
396
400
|
}
|
|
397
401
|
throw e;
|
|
@@ -402,44 +406,45 @@ export class User extends Model {
|
|
|
402
406
|
|
|
403
407
|
linkLoginProvider(type: LoginProviderType, sub: string) {
|
|
404
408
|
if (!this.meta) {
|
|
405
|
-
this.meta = UserMeta.create({})
|
|
409
|
+
this.meta = UserMeta.create({});
|
|
406
410
|
}
|
|
407
|
-
this.meta.loginProviderIds.set(type, sub)
|
|
411
|
+
this.meta.loginProviderIds.set(type, sub);
|
|
408
412
|
}
|
|
409
413
|
|
|
410
414
|
static async registerSSO(
|
|
411
|
-
organization: Organization|null,
|
|
412
|
-
data: {email
|
|
415
|
+
organization: Organization | null,
|
|
416
|
+
data: { email; id; firstName; lastName; type: LoginProviderType; sub: string },
|
|
413
417
|
): Promise<User | undefined> {
|
|
414
418
|
const {
|
|
415
419
|
email,
|
|
416
420
|
id,
|
|
417
421
|
firstName,
|
|
418
|
-
lastName
|
|
422
|
+
lastName,
|
|
419
423
|
} = data;
|
|
420
424
|
|
|
421
425
|
if (STAMHOOFD.userMode === 'platform') {
|
|
422
|
-
throw new Error('SSO is disabled on platforms for now')
|
|
426
|
+
throw new Error('SSO is disabled on platforms for now');
|
|
423
427
|
}
|
|
424
428
|
|
|
425
429
|
if (!organization) {
|
|
426
|
-
throw new Error(
|
|
430
|
+
throw new Error('Missing organization');
|
|
427
431
|
}
|
|
428
432
|
|
|
429
433
|
const user = new User();
|
|
430
|
-
user.organizationId = organization.id
|
|
431
|
-
user.id = id ?? uuidv4()
|
|
434
|
+
user.organizationId = organization.id;
|
|
435
|
+
user.id = id ?? uuidv4();
|
|
432
436
|
user.email = email;
|
|
433
437
|
user.verified = false;
|
|
434
|
-
user.firstName = firstName
|
|
435
|
-
user.lastName = lastName
|
|
436
|
-
user.linkLoginProvider(data.type, data.sub)
|
|
438
|
+
user.firstName = firstName;
|
|
439
|
+
user.lastName = lastName;
|
|
440
|
+
user.linkLoginProvider(data.type, data.sub);
|
|
437
441
|
|
|
438
442
|
try {
|
|
439
443
|
await user.save();
|
|
440
|
-
}
|
|
444
|
+
}
|
|
445
|
+
catch (e) {
|
|
441
446
|
// Duplicate key probably
|
|
442
|
-
if (e.code && e.code ==
|
|
447
|
+
if (e.code && e.code == 'ER_DUP_ENTRY') {
|
|
443
448
|
return;
|
|
444
449
|
}
|
|
445
450
|
throw e;
|
|
@@ -449,7 +454,7 @@ export class User extends Model {
|
|
|
449
454
|
}
|
|
450
455
|
|
|
451
456
|
async changePassword(password: string) {
|
|
452
|
-
this.password = await User.hash(password)
|
|
457
|
+
this.password = await User.hash(password);
|
|
453
458
|
}
|
|
454
459
|
|
|
455
460
|
getStructure() {
|
|
@@ -462,17 +467,16 @@ export class User extends Model {
|
|
|
462
467
|
permissions: this.permissions,
|
|
463
468
|
hasAccount: this.hasAccount(),
|
|
464
469
|
memberId: this.memberId,
|
|
465
|
-
organizationId: this.organizationId
|
|
470
|
+
organizationId: this.organizationId,
|
|
466
471
|
});
|
|
467
472
|
}
|
|
468
473
|
|
|
469
474
|
getEmailTo(): EmailInterfaceRecipient[] {
|
|
470
475
|
return [
|
|
471
|
-
|
|
476
|
+
{
|
|
472
477
|
email: this.email,
|
|
473
|
-
name: this.name
|
|
474
|
-
}
|
|
475
|
-
]
|
|
478
|
+
name: this.name,
|
|
479
|
+
},
|
|
480
|
+
];
|
|
476
481
|
}
|
|
477
|
-
|
|
478
482
|
}
|
|
@@ -1,54 +1,51 @@
|
|
|
1
|
+
import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
|
|
2
|
+
import { Permissions } from '@stamhoofd/structures';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
1
4
|
|
|
2
|
-
import {
|
|
3
|
-
import { Permissions } from "@stamhoofd/structures";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
|
|
6
|
-
import { Organization, User } from "./";
|
|
5
|
+
import { Organization, User } from './';
|
|
7
6
|
|
|
8
7
|
export class UserPermissions extends Model {
|
|
9
|
-
static table =
|
|
8
|
+
static table = 'user_permissions';
|
|
10
9
|
|
|
11
10
|
// Columns
|
|
12
11
|
@column({
|
|
13
|
-
primary: true, type:
|
|
12
|
+
primary: true, type: 'string', beforeSave(value) {
|
|
14
13
|
return value ?? uuidv4();
|
|
15
|
-
}
|
|
14
|
+
},
|
|
16
15
|
})
|
|
17
16
|
id!: string;
|
|
18
17
|
|
|
19
|
-
@column({ foreignKey: UserPermissions.organization, type:
|
|
18
|
+
@column({ foreignKey: UserPermissions.organization, type: 'string' })
|
|
20
19
|
organizationId: string;
|
|
21
20
|
|
|
22
|
-
@column({ foreignKey: UserPermissions.user, type:
|
|
21
|
+
@column({ foreignKey: UserPermissions.user, type: 'string' })
|
|
23
22
|
userId: string;
|
|
24
23
|
|
|
25
|
-
@column({ type:
|
|
26
|
-
permissions: Permissions | null = null
|
|
24
|
+
@column({ type: 'json', decoder: Permissions, nullable: true })
|
|
25
|
+
permissions: Permissions | null = null;
|
|
27
26
|
|
|
28
27
|
@column({
|
|
29
|
-
type:
|
|
28
|
+
type: 'datetime', beforeSave(old?: any) {
|
|
30
29
|
if (old !== undefined) {
|
|
31
30
|
return old;
|
|
32
31
|
}
|
|
33
|
-
const date = new Date()
|
|
34
|
-
date.setMilliseconds(0)
|
|
35
|
-
return date
|
|
36
|
-
}
|
|
32
|
+
const date = new Date();
|
|
33
|
+
date.setMilliseconds(0);
|
|
34
|
+
return date;
|
|
35
|
+
},
|
|
37
36
|
})
|
|
38
|
-
createdAt: Date
|
|
37
|
+
createdAt: Date;
|
|
39
38
|
|
|
40
39
|
@column({
|
|
41
|
-
type:
|
|
42
|
-
const date = new Date()
|
|
43
|
-
date.setMilliseconds(0)
|
|
44
|
-
return date
|
|
40
|
+
type: 'datetime', beforeSave() {
|
|
41
|
+
const date = new Date();
|
|
42
|
+
date.setMilliseconds(0);
|
|
43
|
+
return date;
|
|
45
44
|
},
|
|
46
|
-
skipUpdate: true
|
|
45
|
+
skipUpdate: true,
|
|
47
46
|
})
|
|
48
|
-
updatedAt: Date
|
|
49
|
-
|
|
50
|
-
static organization = new ManyToOneRelation(Organization, "organization");
|
|
51
|
-
static user = new ManyToOneRelation(User, "user");
|
|
47
|
+
updatedAt: Date;
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
static organization = new ManyToOneRelation(Organization, 'organization');
|
|
50
|
+
static user = new ManyToOneRelation(User, 'user');
|
|
54
51
|
}
|