@stamhoofd/backend 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.
Files changed (198) hide show
  1. package/eslint.config.mjs +5 -0
  2. package/index.ts +81 -74
  3. package/jest.config.cjs +10 -0
  4. package/migrations.ts +16 -14
  5. package/package.json +11 -11
  6. package/src/crons/clear-excel-cache.test.ts +48 -50
  7. package/src/crons/clear-excel-cache.ts +18 -18
  8. package/src/crons/setup-steps.ts +2 -2
  9. package/src/crons.ts +325 -306
  10. package/src/decoders/StringArrayDecoder.ts +7 -7
  11. package/src/decoders/StringNullableDecoder.ts +1 -2
  12. package/src/email-recipient-loaders/members.ts +22 -22
  13. package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +8 -9
  14. package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +39 -40
  15. package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +8 -8
  16. package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +44 -45
  17. package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +58 -57
  18. package/src/endpoints/auth/CreateAdminEndpoint.ts +48 -45
  19. package/src/endpoints/auth/CreateTokenEndpoint.test.ts +31 -31
  20. package/src/endpoints/auth/CreateTokenEndpoint.ts +146 -147
  21. package/src/endpoints/auth/DeleteTokenEndpoint.ts +7 -7
  22. package/src/endpoints/auth/DeleteUserEndpoint.ts +15 -15
  23. package/src/endpoints/auth/ForgotPasswordEndpoint.ts +17 -18
  24. package/src/endpoints/auth/GetOtherUserEndpoint.ts +9 -10
  25. package/src/endpoints/auth/GetUserEndpoint.test.ts +32 -35
  26. package/src/endpoints/auth/GetUserEndpoint.ts +5 -6
  27. package/src/endpoints/auth/PatchApiUserEndpoint.ts +35 -33
  28. package/src/endpoints/auth/PatchUserEndpoint.ts +55 -52
  29. package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +9 -9
  30. package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +8 -8
  31. package/src/endpoints/auth/SignupEndpoint.ts +37 -36
  32. package/src/endpoints/auth/VerifyEmailEndpoint.ts +29 -28
  33. package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +33 -33
  34. package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +7 -7
  35. package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +37 -37
  36. package/src/endpoints/global/email/CreateEmailEndpoint.ts +30 -30
  37. package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +13 -13
  38. package/src/endpoints/global/email/GetEmailEndpoint.ts +13 -13
  39. package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +16 -16
  40. package/src/endpoints/global/email/PatchEmailEndpoint.ts +25 -25
  41. package/src/endpoints/global/events/GetEventsEndpoint.ts +43 -44
  42. package/src/endpoints/global/events/PatchEventsEndpoint.ts +127 -172
  43. package/src/endpoints/global/files/ExportToExcelEndpoint.ts +49 -50
  44. package/src/endpoints/global/files/GetFileCache.ts +13 -13
  45. package/src/endpoints/global/files/UploadFile.ts +51 -54
  46. package/src/endpoints/global/files/UploadImage.ts +53 -53
  47. package/src/endpoints/global/groups/GetGroupsEndpoint.ts +25 -25
  48. package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +24 -23
  49. package/src/endpoints/global/members/GetMembersCountEndpoint.ts +8 -8
  50. package/src/endpoints/global/members/GetMembersEndpoint.ts +105 -102
  51. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +240 -239
  52. package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +12 -14
  53. package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +32 -33
  54. package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +48 -57
  55. package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +21 -22
  56. package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +28 -28
  57. package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +18 -18
  58. package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +20 -20
  59. package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +17 -17
  60. package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +81 -75
  61. package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +14 -14
  62. package/src/endpoints/global/platform/GetPlatformEnpoint.ts +11 -11
  63. package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +71 -68
  64. package/src/endpoints/global/registration/GetPaymentRegistrations.ts +27 -27
  65. package/src/endpoints/global/registration/GetUserBillingStatusEndpoint.ts +30 -30
  66. package/src/endpoints/global/registration/GetUserDetailedBillingStatusEndpoint.ts +34 -34
  67. package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +26 -26
  68. package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +12 -12
  69. package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +90 -90
  70. package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +118 -121
  71. package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +362 -350
  72. package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +8 -9
  73. package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +21 -21
  74. package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +65 -65
  75. package/src/endpoints/organization/dashboard/billing/GetOrganizationBillingStatusEndpoint.ts +9 -9
  76. package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedBillingStatusEndpoint.ts +14 -14
  77. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +17 -17
  78. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +21 -21
  79. package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +15 -15
  80. package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +52 -52
  81. package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplateEndpoint.ts +37 -37
  82. package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +14 -14
  83. package/src/endpoints/organization/dashboard/email/EmailEndpoint.ts +113 -112
  84. package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +29 -29
  85. package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +48 -47
  86. package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +22 -21
  87. package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +13 -14
  88. package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +12 -13
  89. package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +24 -24
  90. package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +10 -12
  91. package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +14 -14
  92. package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +13 -13
  93. package/src/endpoints/organization/dashboard/organization/GetOrganizationSSOEndpoint.ts +12 -12
  94. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +120 -124
  95. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +172 -173
  96. package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +88 -89
  97. package/src/endpoints/organization/dashboard/organization/SetOrganizationSSOEndpoint.ts +12 -12
  98. package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +17 -17
  99. package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +8 -8
  100. package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +66 -67
  101. package/src/endpoints/organization/dashboard/payments/PatchBalanceItemsEndpoint.ts +47 -47
  102. package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +93 -91
  103. package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +16 -17
  104. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +170 -167
  105. package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +25 -24
  106. package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +22 -23
  107. package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +22 -22
  108. package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +17 -18
  109. package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +8 -9
  110. package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +17 -18
  111. package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +14 -15
  112. package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +19 -19
  113. package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +19 -19
  114. package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +14 -14
  115. package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +12 -12
  116. package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +103 -100
  117. package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +11 -12
  118. package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +15 -15
  119. package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +14 -14
  120. package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +14 -14
  121. package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +23 -23
  122. package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +54 -52
  123. package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +84 -81
  124. package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +120 -111
  125. package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +24 -24
  126. package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +18 -18
  127. package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +141 -130
  128. package/src/endpoints/organization/shared/GetDocumentHtml.ts +25 -25
  129. package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +18 -18
  130. package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +36 -37
  131. package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +9 -9
  132. package/src/endpoints/organization/shared/auth/OpenIDConnectCallbackEndpoint.ts +11 -11
  133. package/src/endpoints/organization/shared/auth/OpenIDConnectStartEndpoint.ts +28 -27
  134. package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +20 -20
  135. package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +22 -22
  136. package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +14 -14
  137. package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +57 -56
  138. package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +65 -66
  139. package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +18 -17
  140. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +124 -128
  141. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +154 -145
  142. package/src/excel-loaders/members.ts +102 -103
  143. package/src/excel-loaders/payments.ts +155 -156
  144. package/src/helpers/AddressValidator.test.ts +32 -32
  145. package/src/helpers/AddressValidator.ts +128 -122
  146. package/src/helpers/AdminPermissionChecker.ts +339 -236
  147. package/src/helpers/AuthenticatedStructures.ts +233 -134
  148. package/src/helpers/BuckarooHelper.ts +134 -134
  149. package/src/helpers/CheckSettlements.ts +94 -88
  150. package/src/helpers/Context.ts +87 -86
  151. package/src/helpers/CookieHelper.ts +23 -22
  152. package/src/helpers/EmailResumer.ts +10 -10
  153. package/src/helpers/FileCache.ts +62 -62
  154. package/src/helpers/ForwardHandler.test.ts +122 -124
  155. package/src/helpers/ForwardHandler.ts +76 -70
  156. package/src/helpers/MemberUserSyncer.ts +101 -96
  157. package/src/helpers/MembershipCharger.ts +69 -69
  158. package/src/helpers/MembershipHelper.ts +11 -12
  159. package/src/helpers/OpenIDConnectHelper.ts +85 -82
  160. package/src/helpers/PeriodHelper.ts +65 -70
  161. package/src/helpers/StripeHelper.ts +146 -137
  162. package/src/helpers/StripePayoutChecker.ts +51 -52
  163. package/src/helpers/ViesHelper.ts +46 -44
  164. package/src/helpers/fetchToAsyncIterator.ts +14 -14
  165. package/src/helpers/xlsxAddressTransformerColumnFactory.ts +50 -52
  166. package/src/middleware/ContextMiddleware.ts +5 -5
  167. package/src/migrations/1646578856-validate-addresses.ts +6 -9
  168. package/src/seeds/0000000000-example.ts +3 -5
  169. package/src/seeds/1715028563-user-permissions.ts +16 -18
  170. package/src/seeds/1722256498-group-update-occupancy.ts +12 -12
  171. package/src/seeds/1722344162-sync-member-users.ts +14 -15
  172. package/src/seeds/1722344162-update-membership.ts +6 -6
  173. package/src/seeds/1726055544-balance-item-paid.ts +4 -4
  174. package/src/seeds/1726055545-balance-item-pending.ts +4 -4
  175. package/src/seeds/1726494419-update-cached-outstanding-balance.ts +16 -16
  176. package/src/seeds/1726494420-update-cached-outstanding-balance-from-items.ts +12 -12
  177. package/src/seeds/1726572303-schedule-stock-updates.ts +12 -12
  178. package/src/seeds/1726847064-setup-steps.ts +16 -0
  179. package/src/sql-filters/balance-item-payments.ts +7 -7
  180. package/src/sql-filters/events.ts +14 -14
  181. package/src/sql-filters/members.ts +96 -96
  182. package/src/sql-filters/organizations.ts +139 -75
  183. package/src/sql-filters/payments.ts +28 -28
  184. package/src/sql-filters/registrations.ts +14 -14
  185. package/src/sql-sorters/events.ts +25 -25
  186. package/src/sql-sorters/members.ts +26 -26
  187. package/src/sql-sorters/organizations.ts +36 -36
  188. package/src/sql-sorters/payments.ts +26 -26
  189. package/tests/e2e/stock.test.ts +616 -621
  190. package/tests/e2e/tickets.test.ts +255 -260
  191. package/tests/helpers/StripeMocker.ts +177 -179
  192. package/tests/helpers/TestServer.ts +9 -9
  193. package/tests/jest.global.setup.ts +14 -13
  194. package/tests/jest.setup.ts +33 -32
  195. package/.eslintrc.js +0 -61
  196. package/jest.config.js +0 -11
  197. package/src/helpers/SetupStepsUpdater.ts +0 -359
  198. 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,11 +0,0 @@
1
-
2
- module.exports = {
3
- roots: ["<rootDir>/dist"],
4
- testEnvironment: "node",
5
- setupFilesAfterEnv: [
6
- "jest-extended/all",
7
- "./dist/tests/jest.setup.js",
8
- ],
9
- globalSetup: "./dist/tests/jest.global.setup.js"
10
- //verbose: true,
11
- };
@@ -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
- })