@stamhoofd/backend 2.39.1 → 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/eslint.config.mjs +5 -0
- package/index.ts +81 -74
- package/jest.config.cjs +10 -0
- package/migrations.ts +16 -14
- package/package.json +11 -11
- package/src/crons/clear-excel-cache.test.ts +48 -50
- package/src/crons/clear-excel-cache.ts +18 -18
- package/src/crons/setup-steps.ts +2 -2
- package/src/crons.ts +325 -306
- package/src/decoders/StringArrayDecoder.ts +7 -7
- package/src/decoders/StringNullableDecoder.ts +1 -2
- package/src/email-recipient-loaders/members.ts +22 -22
- package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +8 -9
- package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +39 -40
- package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +8 -8
- package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +44 -45
- package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +58 -57
- package/src/endpoints/auth/CreateAdminEndpoint.ts +48 -45
- package/src/endpoints/auth/CreateTokenEndpoint.test.ts +31 -31
- package/src/endpoints/auth/CreateTokenEndpoint.ts +146 -147
- package/src/endpoints/auth/DeleteTokenEndpoint.ts +7 -7
- package/src/endpoints/auth/DeleteUserEndpoint.ts +15 -15
- package/src/endpoints/auth/ForgotPasswordEndpoint.ts +17 -18
- package/src/endpoints/auth/GetOtherUserEndpoint.ts +9 -10
- package/src/endpoints/auth/GetUserEndpoint.test.ts +32 -35
- package/src/endpoints/auth/GetUserEndpoint.ts +5 -6
- package/src/endpoints/auth/PatchApiUserEndpoint.ts +35 -33
- package/src/endpoints/auth/PatchUserEndpoint.ts +55 -52
- package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +9 -9
- package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +8 -8
- package/src/endpoints/auth/SignupEndpoint.ts +37 -36
- package/src/endpoints/auth/VerifyEmailEndpoint.ts +29 -28
- package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +33 -33
- package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +7 -7
- package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +37 -37
- package/src/endpoints/global/email/CreateEmailEndpoint.ts +30 -30
- package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +13 -13
- package/src/endpoints/global/email/GetEmailEndpoint.ts +13 -13
- package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +16 -16
- package/src/endpoints/global/email/PatchEmailEndpoint.ts +25 -25
- package/src/endpoints/global/events/GetEventsEndpoint.ts +43 -44
- package/src/endpoints/global/events/PatchEventsEndpoint.ts +127 -172
- package/src/endpoints/global/files/ExportToExcelEndpoint.ts +49 -50
- package/src/endpoints/global/files/GetFileCache.ts +13 -13
- package/src/endpoints/global/files/UploadFile.ts +51 -54
- package/src/endpoints/global/files/UploadImage.ts +53 -53
- package/src/endpoints/global/groups/GetGroupsEndpoint.ts +25 -25
- package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +24 -23
- package/src/endpoints/global/members/GetMembersCountEndpoint.ts +8 -8
- package/src/endpoints/global/members/GetMembersEndpoint.ts +105 -102
- package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +240 -239
- package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +12 -14
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +32 -33
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +48 -57
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +21 -22
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +28 -28
- package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +18 -18
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +20 -20
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +17 -17
- package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +81 -75
- package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +14 -14
- package/src/endpoints/global/platform/GetPlatformEnpoint.ts +11 -11
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +71 -68
- package/src/endpoints/global/registration/GetPaymentRegistrations.ts +27 -27
- package/src/endpoints/global/registration/GetUserBillingStatusEndpoint.ts +30 -30
- package/src/endpoints/global/registration/GetUserDetailedBillingStatusEndpoint.ts +34 -34
- package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +26 -26
- package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +12 -12
- package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +90 -90
- package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +118 -121
- package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +362 -350
- package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +8 -9
- package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +21 -21
- package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +65 -65
- package/src/endpoints/organization/dashboard/billing/GetOrganizationBillingStatusEndpoint.ts +9 -9
- package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedBillingStatusEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +17 -17
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +21 -21
- package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +52 -52
- package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplateEndpoint.ts +37 -37
- package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/email/EmailEndpoint.ts +113 -112
- package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +29 -29
- package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +48 -47
- package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +22 -21
- package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +13 -14
- package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +12 -13
- package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +10 -12
- package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +14 -14
- package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +13 -13
- package/src/endpoints/organization/dashboard/organization/GetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +120 -124
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +172 -173
- package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +88 -89
- package/src/endpoints/organization/dashboard/organization/SetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +17 -17
- package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +8 -8
- package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +66 -67
- package/src/endpoints/organization/dashboard/payments/PatchBalanceItemsEndpoint.ts +47 -47
- package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +93 -91
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +16 -17
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +170 -167
- package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +25 -24
- package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +22 -23
- package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +22 -22
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +8 -9
- package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +14 -15
- package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +103 -100
- package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +11 -12
- package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +23 -23
- package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +54 -52
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +84 -81
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +120 -111
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +141 -130
- package/src/endpoints/organization/shared/GetDocumentHtml.ts +25 -25
- package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +36 -37
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +9 -9
- package/src/endpoints/organization/shared/auth/OpenIDConnectCallbackEndpoint.ts +11 -11
- package/src/endpoints/organization/shared/auth/OpenIDConnectStartEndpoint.ts +28 -27
- package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +20 -20
- package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +22 -22
- package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +14 -14
- package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +57 -56
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +65 -66
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +18 -17
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +124 -128
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +154 -145
- package/src/excel-loaders/members.ts +102 -103
- package/src/excel-loaders/payments.ts +155 -156
- package/src/helpers/AddressValidator.test.ts +32 -32
- package/src/helpers/AddressValidator.ts +128 -122
- package/src/helpers/AdminPermissionChecker.ts +339 -236
- package/src/helpers/AuthenticatedStructures.ts +233 -134
- package/src/helpers/BuckarooHelper.ts +134 -134
- package/src/helpers/CheckSettlements.ts +94 -88
- package/src/helpers/Context.ts +87 -86
- package/src/helpers/CookieHelper.ts +23 -22
- package/src/helpers/EmailResumer.ts +10 -10
- package/src/helpers/FileCache.ts +62 -62
- package/src/helpers/ForwardHandler.test.ts +122 -124
- package/src/helpers/ForwardHandler.ts +76 -70
- package/src/helpers/MemberUserSyncer.ts +101 -96
- package/src/helpers/MembershipCharger.ts +69 -69
- package/src/helpers/MembershipHelper.ts +11 -12
- package/src/helpers/OpenIDConnectHelper.ts +85 -82
- package/src/helpers/PeriodHelper.ts +65 -70
- package/src/helpers/StripeHelper.ts +146 -137
- package/src/helpers/StripePayoutChecker.ts +51 -52
- package/src/helpers/ViesHelper.ts +46 -44
- package/src/helpers/fetchToAsyncIterator.ts +14 -14
- package/src/helpers/xlsxAddressTransformerColumnFactory.ts +50 -52
- package/src/middleware/ContextMiddleware.ts +5 -5
- package/src/migrations/1646578856-validate-addresses.ts +6 -9
- package/src/seeds/0000000000-example.ts +3 -5
- package/src/seeds/1715028563-user-permissions.ts +16 -18
- package/src/seeds/1722256498-group-update-occupancy.ts +12 -12
- package/src/seeds/1722344162-sync-member-users.ts +14 -15
- package/src/seeds/1722344162-update-membership.ts +6 -6
- package/src/seeds/1726055544-balance-item-paid.ts +4 -4
- package/src/seeds/1726055545-balance-item-pending.ts +4 -4
- package/src/seeds/1726494419-update-cached-outstanding-balance.ts +16 -16
- package/src/seeds/1726494420-update-cached-outstanding-balance-from-items.ts +12 -12
- package/src/seeds/1726572303-schedule-stock-updates.ts +12 -12
- package/src/seeds/1726847064-setup-steps.ts +16 -0
- package/src/sql-filters/balance-item-payments.ts +7 -7
- package/src/sql-filters/events.ts +14 -14
- package/src/sql-filters/members.ts +96 -96
- package/src/sql-filters/organizations.ts +139 -75
- package/src/sql-filters/payments.ts +28 -28
- package/src/sql-filters/registrations.ts +14 -14
- package/src/sql-sorters/events.ts +25 -25
- package/src/sql-sorters/members.ts +26 -26
- package/src/sql-sorters/organizations.ts +36 -36
- package/src/sql-sorters/payments.ts +26 -26
- package/tests/e2e/stock.test.ts +616 -621
- package/tests/e2e/tickets.test.ts +255 -260
- package/tests/helpers/StripeMocker.ts +177 -179
- package/tests/helpers/TestServer.ts +9 -9
- package/tests/jest.global.setup.ts +14 -13
- package/tests/jest.setup.ts +33 -32
- package/.eslintrc.js +0 -61
- package/jest.config.js +0 -11
- package/src/helpers/SetupStepsUpdater.ts +0 -359
- package/src/seeds/1724076679-setup-steps.ts +0 -16
package/.eslintrc.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
ignorePatterns: ["dist/", "node_modules/"],
|
|
4
|
-
parserOptions: {
|
|
5
|
-
"ecmaVersion": 2017
|
|
6
|
-
},
|
|
7
|
-
env: {
|
|
8
|
-
"es6": true,
|
|
9
|
-
"node": true,
|
|
10
|
-
},
|
|
11
|
-
extends: [
|
|
12
|
-
"eslint:recommended",
|
|
13
|
-
],
|
|
14
|
-
plugins: [],
|
|
15
|
-
rules: {
|
|
16
|
-
"no-console": "off",
|
|
17
|
-
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
|
|
18
|
-
"sort-imports": "off",
|
|
19
|
-
"import/order": "off"
|
|
20
|
-
},
|
|
21
|
-
overrides: [
|
|
22
|
-
{
|
|
23
|
-
// Rules for TypeScript and vue
|
|
24
|
-
files: ["*.ts"],
|
|
25
|
-
parser: "@typescript-eslint/parser",
|
|
26
|
-
parserOptions: {
|
|
27
|
-
project: ["./tsconfig.json"]
|
|
28
|
-
},
|
|
29
|
-
plugins: ["@typescript-eslint", "jest"],
|
|
30
|
-
extends: [
|
|
31
|
-
"eslint:recommended",
|
|
32
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
33
|
-
"plugin:@typescript-eslint/recommended",
|
|
34
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
35
|
-
"plugin:jest/recommended",
|
|
36
|
-
],
|
|
37
|
-
rules: {
|
|
38
|
-
"no-console": "off",
|
|
39
|
-
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
|
|
40
|
-
"sort-imports": "off",
|
|
41
|
-
"import/order": "off",
|
|
42
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
43
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
44
|
-
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
|
|
45
|
-
"@typescript-eslint/no-namespace": "off",
|
|
46
|
-
"@typescript-eslint/no-floating-promises": "error",
|
|
47
|
-
"@typescript-eslint/no-misused-promises": "error",
|
|
48
|
-
"@typescript-eslint/prefer-for-of": "warn",
|
|
49
|
-
"@typescript-eslint/no-empty-interface": "off", // It is convenient to have placeholder interfaces
|
|
50
|
-
"@typescript-eslint/no-this-alias": "off", // No idea why we need this. This breaks code that is just fine. Prohibit the use of function() instead of this rule
|
|
51
|
-
"@typescript-eslint/unbound-method": "off", // Methods are automatically bound in vue, it would break removeEventListeners if we bound it every time unless we save every method in variables again...
|
|
52
|
-
"@typescript-eslint/no-unsafe-assignment": "off", // This is impossible to use with dependencies that don't have types yet, such as tiptap
|
|
53
|
-
"@typescript-eslint/no-unsafe-return": "off", // This is impossible to use with dependencies that don't have types yet, such as tiptap
|
|
54
|
-
"@typescript-eslint/no-unsafe-call": "off", // This is impossible to use with dependencies that don't have types yet, such as tiptap
|
|
55
|
-
"@typescript-eslint/no-unsafe-member-access": "off", // This is impossible to use with dependencies that don't have types yet, such as tiptap
|
|
56
|
-
"@typescript-eslint/restrict-plus-operands": "off", // bullshit one
|
|
57
|
-
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
};
|
package/jest.config.js
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Group,
|
|
3
|
-
Member,
|
|
4
|
-
MemberResponsibilityRecord,
|
|
5
|
-
Organization,
|
|
6
|
-
OrganizationRegistrationPeriod,
|
|
7
|
-
Platform
|
|
8
|
-
} from "@stamhoofd/models";
|
|
9
|
-
import { QueueHandler } from "@stamhoofd/queues";
|
|
10
|
-
import { SQL, SQLWhereSign } from "@stamhoofd/sql";
|
|
11
|
-
import {
|
|
12
|
-
GroupType,
|
|
13
|
-
MemberResponsibility,
|
|
14
|
-
Platform as PlatformStruct,
|
|
15
|
-
SetupStepType,
|
|
16
|
-
SetupSteps
|
|
17
|
-
} from "@stamhoofd/structures";
|
|
18
|
-
import { Formatter } from "@stamhoofd/utility";
|
|
19
|
-
|
|
20
|
-
type SetupStepOperation = (setupSteps: SetupSteps, organization: Organization, platform: PlatformStruct) => void | Promise<void>;
|
|
21
|
-
|
|
22
|
-
export class SetupStepUpdater {
|
|
23
|
-
private static readonly STEP_TYPE_OPERATIONS: Record<
|
|
24
|
-
SetupStepType,
|
|
25
|
-
SetupStepOperation
|
|
26
|
-
> = {
|
|
27
|
-
[SetupStepType.Responsibilities]: this.updateStepResponsibilities,
|
|
28
|
-
[SetupStepType.Companies]: this.updateStepCompanies,
|
|
29
|
-
[SetupStepType.Groups]: this.updateStepGroups,
|
|
30
|
-
[SetupStepType.Premises]: this.updateStepPremises,
|
|
31
|
-
[SetupStepType.Emails]: this.updateStepEmails,
|
|
32
|
-
[SetupStepType.Payment]: this.updateStepPayment
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
static async updateSetupStepsForAllOrganizationsInCurrentPeriod({
|
|
36
|
-
batchSize
|
|
37
|
-
}: { batchSize?: number } = {}) {
|
|
38
|
-
const tag = "updateSetupStepsForAllOrganizationsInCurrentPeriod";
|
|
39
|
-
QueueHandler.cancel(tag);
|
|
40
|
-
|
|
41
|
-
await QueueHandler.schedule(tag, async () => {
|
|
42
|
-
const platform = (await Platform.getSharedPrivateStruct()).clone();
|
|
43
|
-
|
|
44
|
-
const periodId = platform.period.id;
|
|
45
|
-
|
|
46
|
-
let lastId = "";
|
|
47
|
-
|
|
48
|
-
while (true) {
|
|
49
|
-
const organizationRegistrationPeriods =
|
|
50
|
-
await OrganizationRegistrationPeriod.where(
|
|
51
|
-
{
|
|
52
|
-
id: { sign: ">", value: lastId },
|
|
53
|
-
periodId: periodId,
|
|
54
|
-
},
|
|
55
|
-
{ limit: batchSize ?? 10, sort: ["id"] }
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
if (organizationRegistrationPeriods.length === 0) {
|
|
59
|
-
lastId = "";
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const organizationPeriodMap = new Map(
|
|
64
|
-
organizationRegistrationPeriods.map((period) => {
|
|
65
|
-
return [period.organizationId, period];
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const organizations = await Organization.getByIDs(
|
|
70
|
-
...organizationPeriodMap.keys()
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
for (const organization of organizations) {
|
|
74
|
-
const organizationId = organization.id;
|
|
75
|
-
const organizationRegistrationPeriod =
|
|
76
|
-
organizationPeriodMap.get(organizationId);
|
|
77
|
-
|
|
78
|
-
if (!organizationRegistrationPeriod) {
|
|
79
|
-
console.error(
|
|
80
|
-
`[FLAG-MOMENT] organizationRegistrationPeriod not found for organization with id ${organizationId}`
|
|
81
|
-
);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
console.log(
|
|
86
|
-
"[FLAG-MOMENT] checking flag moments for " +
|
|
87
|
-
organizationId
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
await SetupStepUpdater.updateFor(
|
|
91
|
-
organizationRegistrationPeriod,
|
|
92
|
-
platform,
|
|
93
|
-
organization
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
lastId =
|
|
98
|
-
organizationRegistrationPeriods[
|
|
99
|
-
organizationRegistrationPeriods.length - 1
|
|
100
|
-
].id;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static async updateForOrganization(
|
|
106
|
-
organization: Organization,
|
|
107
|
-
{
|
|
108
|
-
platform,
|
|
109
|
-
organizationRegistrationPeriod,
|
|
110
|
-
}: {
|
|
111
|
-
platform?: PlatformStruct;
|
|
112
|
-
organizationRegistrationPeriod?: OrganizationRegistrationPeriod;
|
|
113
|
-
} = {}
|
|
114
|
-
) {
|
|
115
|
-
if (!platform) {
|
|
116
|
-
platform = await Platform.getSharedPrivateStruct();
|
|
117
|
-
if (!platform) {
|
|
118
|
-
console.error("No platform not found");
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (!organizationRegistrationPeriod) {
|
|
124
|
-
const periodId = platform.period.id;
|
|
125
|
-
organizationRegistrationPeriod = (
|
|
126
|
-
await OrganizationRegistrationPeriod.where({
|
|
127
|
-
organizationId: organization.id,
|
|
128
|
-
periodId: periodId,
|
|
129
|
-
})
|
|
130
|
-
)[0];
|
|
131
|
-
|
|
132
|
-
if (!organizationRegistrationPeriod) {
|
|
133
|
-
console.error(
|
|
134
|
-
`OrganizationRegistrationPeriod with organizationId ${organization.id} and periodId ${periodId} not found`
|
|
135
|
-
);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
await this.updateFor(
|
|
141
|
-
organizationRegistrationPeriod,
|
|
142
|
-
platform,
|
|
143
|
-
organization
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private static async updateFor(
|
|
148
|
-
organizationRegistrationPeriod: OrganizationRegistrationPeriod,
|
|
149
|
-
platform: PlatformStruct,
|
|
150
|
-
organization: Organization
|
|
151
|
-
) {
|
|
152
|
-
const setupSteps = organizationRegistrationPeriod.setupSteps;
|
|
153
|
-
|
|
154
|
-
for (const stepType of Object.values(SetupStepType)) {
|
|
155
|
-
const operation = this.STEP_TYPE_OPERATIONS[stepType];
|
|
156
|
-
await operation(setupSteps, organization, platform);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
await organizationRegistrationPeriod.save();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private static updateStepPremises(
|
|
163
|
-
setupSteps: SetupSteps,
|
|
164
|
-
organization: Organization,
|
|
165
|
-
platform: PlatformStruct
|
|
166
|
-
) {
|
|
167
|
-
let totalSteps = 0;
|
|
168
|
-
let finishedSteps = 0;
|
|
169
|
-
|
|
170
|
-
const premiseTypes = platform.config.premiseTypes;
|
|
171
|
-
|
|
172
|
-
for (const premiseType of premiseTypes) {
|
|
173
|
-
const { min, max } = premiseType;
|
|
174
|
-
|
|
175
|
-
// only add step if premise type has restrictions
|
|
176
|
-
if (min === null && max === null) {
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
totalSteps++;
|
|
181
|
-
|
|
182
|
-
const premiseTypeId = premiseType.id;
|
|
183
|
-
let totalPremisesOfThisType = 0;
|
|
184
|
-
|
|
185
|
-
for (const premise of organization.privateMeta.premises) {
|
|
186
|
-
if (premise.premiseTypeIds.includes(premiseTypeId)) {
|
|
187
|
-
totalPremisesOfThisType++;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (max !== null && totalPremisesOfThisType > max) {
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (min !== null && totalPremisesOfThisType < min) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
finishedSteps++;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
setupSteps.update(SetupStepType.Premises, {
|
|
203
|
-
totalSteps,
|
|
204
|
-
finishedSteps,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private static updateStepGroups(
|
|
209
|
-
setupSteps: SetupSteps,
|
|
210
|
-
_organization: Organization,
|
|
211
|
-
_platform: PlatformStruct
|
|
212
|
-
) {
|
|
213
|
-
setupSteps.update(SetupStepType.Groups, {
|
|
214
|
-
totalSteps: 0,
|
|
215
|
-
finishedSteps: 0,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private static updateStepCompanies(
|
|
220
|
-
setupSteps: SetupSteps,
|
|
221
|
-
_organization: Organization,
|
|
222
|
-
_platform: PlatformStruct
|
|
223
|
-
) {
|
|
224
|
-
const totalSteps = 1;
|
|
225
|
-
let finishedSteps = 0;
|
|
226
|
-
|
|
227
|
-
if(_organization.meta.companies.length) {
|
|
228
|
-
finishedSteps = 1;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
setupSteps.update(SetupStepType.Companies, {
|
|
232
|
-
totalSteps,
|
|
233
|
-
finishedSteps,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private static async updateStepResponsibilities(
|
|
238
|
-
setupSteps: SetupSteps,
|
|
239
|
-
organization: Organization,
|
|
240
|
-
platform: PlatformStruct
|
|
241
|
-
) {
|
|
242
|
-
const now = new Date();
|
|
243
|
-
const organizationBasedResponsibilitiesWithRestriction = platform.config.responsibilities
|
|
244
|
-
.filter(r => r.organizationBased && (r.minimumMembers || r.maximumMembers));
|
|
245
|
-
|
|
246
|
-
const responsibilityIds = organizationBasedResponsibilitiesWithRestriction.map(r => r.id);
|
|
247
|
-
|
|
248
|
-
const allRecords = responsibilityIds.length === 0 ? [] : await MemberResponsibilityRecord.select()
|
|
249
|
-
.where('responsibilityId', responsibilityIds)
|
|
250
|
-
.where('organizationId', organization.id)
|
|
251
|
-
.where(SQL.where('endDate', SQLWhereSign.Greater, now).or('endDate', null))
|
|
252
|
-
.fetch();
|
|
253
|
-
|
|
254
|
-
// Remove invalid responsibilities: members that are not registered in the current period
|
|
255
|
-
const memberIds = Formatter.uniqueArray(allRecords.map(r => r.memberId));
|
|
256
|
-
const members = await Member.getBlobByIds(...memberIds);
|
|
257
|
-
const validMembers = members.filter(m => m.registrations.some(r => r.organizationId === organization.id && r.periodId === organization.periodId && r.group.type === GroupType.Membership && r.deactivatedAt === null && r.registeredAt !== null));
|
|
258
|
-
|
|
259
|
-
const validMembersIds = validMembers.map(m => m.id);
|
|
260
|
-
|
|
261
|
-
const records = allRecords.filter(r => validMembersIds.includes(r.memberId));
|
|
262
|
-
|
|
263
|
-
let totalSteps = 0;
|
|
264
|
-
let finishedSteps = 0;
|
|
265
|
-
|
|
266
|
-
const groups = await Group.getAll(organization.id, organization.periodId);
|
|
267
|
-
|
|
268
|
-
const flatResponsibilities: {responsibility: MemberResponsibility, group: Group | null}[] = organizationBasedResponsibilitiesWithRestriction
|
|
269
|
-
.flatMap(responsibility => {
|
|
270
|
-
const defaultAgeGroupIds = responsibility.defaultAgeGroupIds;
|
|
271
|
-
if(defaultAgeGroupIds === null) {
|
|
272
|
-
const item: {responsibility: MemberResponsibility, group: Group | null} = {
|
|
273
|
-
responsibility,
|
|
274
|
-
group: null
|
|
275
|
-
}
|
|
276
|
-
return [item];
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return groups
|
|
280
|
-
.filter(g => g.defaultAgeGroupId !== null && defaultAgeGroupIds.includes(g.defaultAgeGroupId))
|
|
281
|
-
.map(group => {
|
|
282
|
-
return {
|
|
283
|
-
responsibility,
|
|
284
|
-
group
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
for(const {responsibility, group} of flatResponsibilities) {
|
|
290
|
-
const { minimumMembers: min, maximumMembers: max } = responsibility;
|
|
291
|
-
|
|
292
|
-
if (min === null) {
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
totalSteps += min;
|
|
297
|
-
|
|
298
|
-
const responsibilityId = responsibility.id;
|
|
299
|
-
let totalRecordsWithThisResponsibility = 0;
|
|
300
|
-
|
|
301
|
-
if(group === null) {
|
|
302
|
-
for (const record of records) {
|
|
303
|
-
if (record.responsibilityId === responsibilityId) {
|
|
304
|
-
totalRecordsWithThisResponsibility++;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
} else {
|
|
308
|
-
for (const record of records) {
|
|
309
|
-
if (record.responsibilityId === responsibilityId && record.groupId === group.id) {
|
|
310
|
-
totalRecordsWithThisResponsibility++;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (max !== null && totalRecordsWithThisResponsibility > max) {
|
|
316
|
-
// Not added
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
finishedSteps += Math.min(min, totalRecordsWithThisResponsibility);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
setupSteps.update(SetupStepType.Responsibilities, {
|
|
324
|
-
totalSteps,
|
|
325
|
-
finishedSteps,
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
private static updateStepEmails(setupSteps: SetupSteps,
|
|
330
|
-
organization: Organization,
|
|
331
|
-
_platform: PlatformStruct) {
|
|
332
|
-
|
|
333
|
-
const totalSteps = 1;
|
|
334
|
-
let finishedSteps = 0;
|
|
335
|
-
|
|
336
|
-
const emails = organization.privateMeta.emails;
|
|
337
|
-
|
|
338
|
-
// organization should have 1 default email
|
|
339
|
-
if(emails.some(e => e.default)) {
|
|
340
|
-
finishedSteps = 1;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
setupSteps.update(SetupStepType.Emails, {
|
|
344
|
-
totalSteps,
|
|
345
|
-
finishedSteps,
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
setupSteps.markReviewed(SetupStepType.Emails, {userId: 'backend', userName: 'backend'});
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
private static updateStepPayment(setupSteps: SetupSteps,
|
|
352
|
-
_organization: Organization,
|
|
353
|
-
_platform: PlatformStruct) {
|
|
354
|
-
setupSteps.update(SetupStepType.Payment, {
|
|
355
|
-
totalSteps: 0,
|
|
356
|
-
finishedSteps: 0,
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Migration } from '@simonbackx/simple-database';
|
|
2
|
-
import { SetupStepUpdater } from '../helpers/SetupStepsUpdater';
|
|
3
|
-
|
|
4
|
-
export default new Migration(async () => {
|
|
5
|
-
if (STAMHOOFD.environment == "test") {
|
|
6
|
-
console.log("skipped in tests")
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if(STAMHOOFD.userMode !== "platform") {
|
|
11
|
-
console.log("skipped seed setup-steps because usermode not platform")
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
await SetupStepUpdater.updateSetupStepsForAllOrganizationsInCurrentPeriod();
|
|
16
|
-
})
|