@stamhoofd/backend 2.119.0 → 2.120.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 (348) hide show
  1. package/package.json +32 -22
  2. package/src/audit-logs/ModelLogger.ts +4 -2
  3. package/src/boot.ts +32 -14
  4. package/src/crons/balance-emails.ts +4 -2
  5. package/src/crons/clearExcelCache.test.ts +8 -8
  6. package/src/crons/update-cached-balances.ts +40 -14
  7. package/src/debug.ts +3 -2
  8. package/src/decoders/StringArrayDecoder.ts +1 -1
  9. package/src/decoders/StringNullableDecoder.ts +1 -1
  10. package/src/email-recipient-loaders/documents.ts +2 -1
  11. package/src/email-recipient-loaders/members.ts +2 -1
  12. package/src/email-recipient-loaders/orders.ts +2 -1
  13. package/src/email-recipient-loaders/payments.ts +6 -3
  14. package/src/email-recipient-loaders/receivable-balances.ts +2 -1
  15. package/src/email-recipient-loaders/registrations.ts +2 -1
  16. package/src/email-replacements/getEmailReplacementsForPayment.ts +2 -1
  17. package/src/endpoints/admin/members/ChargeMembersEndpoint.ts +3 -2
  18. package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +2 -1
  19. package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +2 -1
  20. package/src/endpoints/admin/organizations/ChargeOrganizationsEndpoint.ts +3 -2
  21. package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +3 -2
  22. package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +6 -4
  23. package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +4 -2
  24. package/src/endpoints/admin/registrations/ChargeRegistrationsEndpoint.ts +3 -2
  25. package/src/endpoints/auth/CreateAdminEndpoint.ts +5 -3
  26. package/src/endpoints/auth/CreateTokenEndpoint.ts +4 -2
  27. package/src/endpoints/auth/DeleteTokenEndpoint.ts +2 -1
  28. package/src/endpoints/auth/DeleteUserEndpoint.ts +2 -1
  29. package/src/endpoints/auth/ForgotPasswordEndpoint.ts +3 -2
  30. package/src/endpoints/auth/GetOtherUserEndpoint.ts +3 -2
  31. package/src/endpoints/auth/GetUserEndpoint.ts +3 -2
  32. package/src/endpoints/auth/OpenIDConnectAuthTokenEndpoint.ts +2 -1
  33. package/src/endpoints/auth/OpenIDConnectCallbackEndpoint.ts +4 -2
  34. package/src/endpoints/auth/OpenIDConnectStartEndpoint.ts +3 -2
  35. package/src/endpoints/auth/PatchUserEndpoint.ts +6 -3
  36. package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +3 -2
  37. package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +3 -2
  38. package/src/endpoints/auth/SignupEndpoint.ts +3 -2
  39. package/src/endpoints/auth/VerifyEmailEndpoint.ts +3 -2
  40. package/src/endpoints/frontend/FrontendEnvironmentEndpoint.ts +3 -2
  41. package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +8 -5
  42. package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +5 -3
  43. package/src/endpoints/global/audit-logs/GetAuditLogsEndpoint.ts +7 -4
  44. package/src/endpoints/global/billing/ActivatePackagesEndpoint.ts +6 -4
  45. package/src/endpoints/global/billing/DeactivatePackageEndpoint.ts +2 -1
  46. package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +4 -2
  47. package/src/endpoints/global/email/CreateEmailEndpoint.ts +5 -3
  48. package/src/endpoints/global/email/GetAdminEmailsEndpoint.test.ts +2 -1
  49. package/src/endpoints/global/email/GetAdminEmailsEndpoint.ts +22 -19
  50. package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +4 -2
  51. package/src/endpoints/global/email/GetEmailEndpoint.ts +3 -2
  52. package/src/endpoints/global/email/GetUserEmailsEndpoint.test.ts +2 -1
  53. package/src/endpoints/global/email/GetUserEmailsEndpoint.ts +7 -4
  54. package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +4 -2
  55. package/src/endpoints/global/email/PatchEmailEndpoint.test.ts +11 -11
  56. package/src/endpoints/global/email/PatchEmailEndpoint.ts +6 -3
  57. package/src/endpoints/global/email-recipients/GetEmailRecipientsCountEndpoint.ts +3 -2
  58. package/src/endpoints/global/email-recipients/GetEmailRecipientsEndpoint.test.ts +2 -1
  59. package/src/endpoints/global/email-recipients/GetEmailRecipientsEndpoint.ts +7 -4
  60. package/src/endpoints/global/email-recipients/RetryEmailRecipientEndpoint.ts +4 -2
  61. package/src/endpoints/global/email-recipients/helpers/validateEmailRecipientFilter.ts +2 -1
  62. package/src/endpoints/global/events/GetEventNotificationsCountEndpoint.ts +3 -2
  63. package/src/endpoints/global/events/GetEventNotificationsEndpoint.ts +8 -5
  64. package/src/endpoints/global/events/GetEventsEndpoint.ts +7 -4
  65. package/src/endpoints/global/events/PatchEventNotificationsEndpoint.test.ts +4 -2
  66. package/src/endpoints/global/events/PatchEventNotificationsEndpoint.ts +4 -2
  67. package/src/endpoints/global/events/PatchEventsEndpoint.test.ts +4 -2
  68. package/src/endpoints/global/events/PatchEventsEndpoint.ts +4 -2
  69. package/src/endpoints/global/files/ExportToExcelEndpoint.ts +7 -4
  70. package/src/endpoints/global/files/GetFileCache.ts +5 -3
  71. package/src/endpoints/global/files/UploadFile.ts +9 -3
  72. package/src/endpoints/global/files/UploadImage.ts +4 -2
  73. package/src/endpoints/global/groups/GetGroupsEndpoint.test.ts +4 -2
  74. package/src/endpoints/global/groups/GetGroupsEndpoint.ts +7 -4
  75. package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +5 -3
  76. package/src/endpoints/global/members/GetMembersCountEndpoint.ts +3 -2
  77. package/src/endpoints/global/members/GetMembersEndpoint.test.ts +4 -2
  78. package/src/endpoints/global/members/GetMembersEndpoint.ts +8 -6
  79. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.test.ts +257 -6
  80. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +114 -59
  81. package/src/endpoints/global/members/helpers/validateGroupFilter.ts +2 -1
  82. package/src/endpoints/global/members/shouldCheckIfMemberIsDuplicate.ts +3 -2
  83. package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +2 -1
  84. package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +3 -2
  85. package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +3 -2
  86. package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +5 -3
  87. package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +5 -3
  88. package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +8 -5
  89. package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +4 -2
  90. package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +2 -1
  91. package/src/endpoints/global/platform/GetPlatformEndpoint.ts +3 -2
  92. package/src/endpoints/global/platform/PatchPlatformEnpoint.test.ts +3 -2
  93. package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +6 -3
  94. package/src/endpoints/global/platform-memberships/GetPlatformMembershipsCountEndpoint.ts +47 -0
  95. package/src/endpoints/global/platform-memberships/GetPlatformMembershipsEndpoint.ts +206 -0
  96. package/src/endpoints/global/registration/GetRegistrationsCountEndpoint.ts +3 -2
  97. package/src/endpoints/global/registration/GetRegistrationsEndpoint.test.ts +2 -1
  98. package/src/endpoints/global/registration/GetRegistrationsEndpoint.ts +8 -5
  99. package/src/endpoints/global/registration/GetUserDetailedPayableBalanceEndpoint.ts +4 -2
  100. package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +4 -2
  101. package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +3 -2
  102. package/src/endpoints/global/registration/GetUserPayableBalanceEndpoint.ts +2 -1
  103. package/src/endpoints/global/registration/PatchUserMembersEndpoint.test.ts +5 -3
  104. package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +9 -5
  105. package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +50 -49
  106. package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +7 -4
  107. package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +7 -4
  108. package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +4 -2
  109. package/src/endpoints/global/sso/GetSSOEndpoint.ts +4 -2
  110. package/src/endpoints/global/sso/SetSSOEndpoint.ts +3 -2
  111. package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +4 -2
  112. package/src/endpoints/global/webshops/GetWebshopsCountEndpoint.ts +43 -0
  113. package/src/endpoints/global/webshops/GetWebshopsEndpoint.test.ts +808 -0
  114. package/src/endpoints/global/webshops/GetWebshopsEndpoint.ts +221 -0
  115. package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemEndpoint.ts +3 -2
  116. package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemsCountEndpoint.ts +3 -2
  117. package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemsEndpoint.ts +5 -3
  118. package/src/endpoints/organization/dashboard/balance-items/PatchBalanceItemsEndpoint.ts +4 -2
  119. package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedPayableBalanceEndpoint.ts +4 -2
  120. package/src/endpoints/organization/dashboard/billing/GetOrganizationPayableBalanceEndpoint.ts +4 -2
  121. package/src/endpoints/organization/dashboard/billing/GetPackagesEndpoint.ts +2 -1
  122. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +2 -1
  123. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesCountEndpoint.ts +3 -2
  124. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +7 -4
  125. package/src/endpoints/organization/dashboard/documents/GetDocumentsCountEndpoint.ts +3 -2
  126. package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +7 -4
  127. package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +4 -2
  128. package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplatesEndpoint.test.ts +4 -2
  129. package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplatesEndpoint.ts +4 -2
  130. package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +2 -1
  131. package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.test.ts +36 -1
  132. package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +13 -4
  133. package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.test.ts +4 -2
  134. package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +4 -2
  135. package/src/endpoints/organization/dashboard/invoices/GetInvoicesCountEndpoint.ts +3 -2
  136. package/src/endpoints/organization/dashboard/invoices/GetInvoicesEndpoint.ts +5 -3
  137. package/src/endpoints/organization/dashboard/invoices/PatchInvoicesEndpoint.ts +5 -3
  138. package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +4 -2
  139. package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +6 -3
  140. package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +4 -2
  141. package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +2 -1
  142. package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +2 -1
  143. package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +4 -2
  144. package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +3 -2
  145. package/src/endpoints/organization/dashboard/organization/GetUitpasClientIdEndpoint.ts +2 -1
  146. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +5 -3
  147. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +6 -3
  148. package/src/endpoints/organization/dashboard/organization/SearchUitpasOrganizersEndpoint.ts +5 -3
  149. package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +8 -6
  150. package/src/endpoints/organization/dashboard/organization/SetUitpasClientCredentialsEndpoint.ts +3 -2
  151. package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +2 -1
  152. package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +3 -2
  153. package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +6 -4
  154. package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +5 -3
  155. package/src/endpoints/organization/dashboard/receivable-balances/GetReceivableBalanceEndpoint.ts +2 -1
  156. package/src/endpoints/organization/dashboard/receivable-balances/GetReceivableBalancesCountEndpoint.ts +3 -2
  157. package/src/endpoints/organization/dashboard/receivable-balances/GetReceivableBalancesEndpoint.ts +5 -3
  158. package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.test.ts +2 -1
  159. package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +7 -4
  160. package/src/endpoints/organization/dashboard/registration-periods/MoveRegistrationPeriods.test.ts +4 -2
  161. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.test.ts +4 -2
  162. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +6 -3
  163. package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +6 -3
  164. package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +3 -2
  165. package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +2 -1
  166. package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +4 -2
  167. package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +2 -1
  168. package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +4 -2
  169. package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +2 -1
  170. package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +3 -2
  171. package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +2 -1
  172. package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +3 -2
  173. package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +2 -1
  174. package/src/endpoints/organization/dashboard/users/PatchApiUserEndpoint.ts +4 -2
  175. package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +3 -2
  176. package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +2 -1
  177. package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +4 -2
  178. package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersCountEndpoint.ts +3 -2
  179. package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +7 -4
  180. package/src/endpoints/organization/dashboard/webshops/{GetWebshopTicketsCountEndpoint → GetWebshopTicketsCountEndpoint.ts} +7 -7
  181. package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +9 -6
  182. package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +4 -2
  183. package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +4 -2
  184. package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +4 -3
  185. package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +4 -2
  186. package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +4 -2
  187. package/src/endpoints/organization/dashboard/webshops/SearchUitpasEventsEndpoint.ts +5 -3
  188. package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +2 -1
  189. package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +5 -3
  190. package/src/endpoints/organization/shared/GetDocumentHtml.ts +2 -1
  191. package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +3 -2
  192. package/src/endpoints/organization/shared/GetUitpasNumberDetailsEndpoint.ts +3 -2
  193. package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +3 -2
  194. package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +3 -2
  195. package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +3 -2
  196. package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +3 -2
  197. package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +4 -2
  198. package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +3 -2
  199. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +7 -3
  200. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +3 -2
  201. package/src/endpoints/organization/webshops/RetrieveUitpasSocialTariffPriceEndpoint.ts +3 -2
  202. package/src/endpoints/system/HealthEndpoint.test.ts +44 -0
  203. package/src/endpoints/system/HealthEndpoint.ts +14 -6
  204. package/src/excel-loaders/balance-items.ts +4 -2
  205. package/src/excel-loaders/event-notifications.ts +4 -2
  206. package/src/excel-loaders/index.ts +1 -0
  207. package/src/excel-loaders/members.ts +4 -2
  208. package/src/excel-loaders/organizations.ts +3 -2
  209. package/src/excel-loaders/payments.ts +4 -2
  210. package/src/excel-loaders/platform-memberships.ts +202 -0
  211. package/src/excel-loaders/receivable-balances.ts +4 -2
  212. package/src/excel-loaders/registrations.ts +4 -2
  213. package/src/helpers/AddressValidator.test.ts +2 -1
  214. package/src/helpers/AddressValidator.ts +7 -4
  215. package/src/helpers/AdminPermissionChecker.ts +190 -92
  216. package/src/helpers/AuthenticatedStructures.ts +4 -2
  217. package/src/helpers/BuckarooHelper.ts +2 -1
  218. package/src/helpers/Context.ts +4 -2
  219. package/src/helpers/CookieHelper.ts +2 -2
  220. package/src/helpers/FileCache.ts +2 -2
  221. package/src/helpers/ForwardHandler.ts +2 -1
  222. package/src/helpers/GlobalHelper.ts +2 -0
  223. package/src/helpers/GroupBuilder.ts +2 -1
  224. package/src/helpers/GroupedThrottledQueue.test.ts +19 -19
  225. package/src/helpers/LimitedFilteredRequestHelper.ts +1 -1
  226. package/src/helpers/MemberCharger.ts +2 -1
  227. package/src/helpers/MemberUserSyncer.ts +6 -3
  228. package/src/helpers/OrganizationCharger.ts +2 -1
  229. package/src/helpers/PeriodHelper.ts +2 -1
  230. package/src/helpers/SQLTranslatedString.ts +3 -2
  231. package/src/helpers/ServiceFeeHelper.ts +1 -1
  232. package/src/helpers/SetupStepUpdater.ts +5 -4
  233. package/src/helpers/StripeHelper.ts +3 -2
  234. package/src/helpers/TagHelper.test.ts +5 -5
  235. package/src/helpers/TagHelper.ts +2 -1
  236. package/src/helpers/TemporaryMemberAccess.ts +2 -1
  237. package/src/helpers/ThrottledQueue.test.ts +20 -20
  238. package/src/helpers/ViesHelper.ts +4 -3
  239. package/src/helpers/XlsxTransformerColumnHelper.ts +4 -2
  240. package/src/helpers/email-html-helpers.ts +3 -2
  241. package/src/helpers/fetchToAsyncIterator.ts +1 -1
  242. package/src/helpers/outstandingBalanceJoin.ts +2 -1
  243. package/src/helpers/updateMemberDetailsUitpasNumber.ts +4 -3
  244. package/src/middleware/ContextMiddleware.ts +1 -1
  245. package/src/migrate.ts +21 -4
  246. package/src/seeds/0000000003-default-email-templates.ts +1 -1
  247. package/src/seeds/0000000004-single-organization.ts +2 -1
  248. package/src/seeds/1752848561-groups-registration-periods.ts +2 -1
  249. package/src/seeds/1754560914-groups-prices.test.ts +2 -1
  250. package/src/seeds/1754560914-groups-prices.ts +2 -1
  251. package/src/seeds/1755876819-remove-duplicate-members.ts +2 -1
  252. package/src/seeds/1765896674-document-update-year.test.ts +2 -1
  253. package/src/seeds/1773754928-force-save-members.ts +15 -0
  254. package/src/services/AuditLogService.ts +3 -2
  255. package/src/services/BalanceItemPaymentService.ts +2 -2
  256. package/src/services/BalanceItemService.ts +2 -1
  257. package/src/services/BootChecksService.test.ts +33 -0
  258. package/src/services/BootChecksService.ts +21 -0
  259. package/src/services/DatabaseCollationService.test.ts +18 -0
  260. package/src/services/DatabaseCollationService.ts +81 -0
  261. package/src/services/DocumentService.ts +1 -1
  262. package/src/services/EventNotificationService.ts +2 -1
  263. package/src/services/FileSignService.ts +1 -1
  264. package/src/services/MemberNumberService.ts +3 -1
  265. package/src/services/MemberRecordStore.ts +28 -19
  266. package/src/services/PaymentReallocationService.test.ts +2 -1
  267. package/src/services/PaymentReallocationService.ts +2 -1
  268. package/src/services/PaymentService.ts +5 -3
  269. package/src/services/RegistrationService.ts +65 -3
  270. package/src/services/SSOService.ts +8 -4
  271. package/src/services/STPackageService.ts +5 -3
  272. package/src/services/StartupHealthService.ts +15 -0
  273. package/src/services/uitpas/UitpasService.ts +6 -3
  274. package/src/sql-filters/audit-logs.ts +2 -1
  275. package/src/sql-filters/balance-item-payments.ts +2 -1
  276. package/src/sql-filters/balance-items.ts +2 -1
  277. package/src/sql-filters/base-registration-filter-compilers.ts +4 -2
  278. package/src/sql-filters/document-templates.ts +2 -1
  279. package/src/sql-filters/documents.ts +2 -1
  280. package/src/sql-filters/email-recipients.ts +2 -1
  281. package/src/sql-filters/emails.ts +2 -1
  282. package/src/sql-filters/event-notifications.ts +2 -1
  283. package/src/sql-filters/events.ts +2 -1
  284. package/src/sql-filters/groups.ts +2 -1
  285. package/src/sql-filters/invoiced-balance-items.ts +2 -1
  286. package/src/sql-filters/invoices.ts +2 -1
  287. package/src/sql-filters/member-responsibility-records.ts +2 -1
  288. package/src/sql-filters/members.ts +2 -1
  289. package/src/sql-filters/orders.ts +2 -1
  290. package/src/sql-filters/organization-registration-periods.ts +2 -1
  291. package/src/sql-filters/organizations.ts +2 -1
  292. package/src/sql-filters/payments.ts +2 -1
  293. package/src/sql-filters/platform-memberships.ts +67 -0
  294. package/src/sql-filters/receivable-balances.ts +2 -1
  295. package/src/sql-filters/registration-periods.ts +2 -1
  296. package/src/sql-filters/registrations.ts +2 -1
  297. package/src/sql-filters/tickets.ts +2 -1
  298. package/src/sql-filters/users.ts +2 -1
  299. package/src/sql-filters/webshops.ts +38 -0
  300. package/src/sql-sorters/audit-logs.ts +3 -2
  301. package/src/sql-sorters/balance-items.ts +3 -2
  302. package/src/sql-sorters/document-templates.ts +3 -2
  303. package/src/sql-sorters/documents.ts +3 -2
  304. package/src/sql-sorters/email-recipients.ts +3 -2
  305. package/src/sql-sorters/emails.ts +3 -2
  306. package/src/sql-sorters/event-notifications.ts +3 -2
  307. package/src/sql-sorters/events.ts +3 -2
  308. package/src/sql-sorters/groups.ts +3 -2
  309. package/src/sql-sorters/invoices.ts +3 -2
  310. package/src/sql-sorters/members.ts +3 -2
  311. package/src/sql-sorters/orders.ts +3 -2
  312. package/src/sql-sorters/organization-registration-periods.ts +3 -2
  313. package/src/sql-sorters/organizations.ts +3 -2
  314. package/src/sql-sorters/payments.ts +3 -2
  315. package/src/sql-sorters/platform-memberships.ts +40 -0
  316. package/src/sql-sorters/receivable-balances.ts +3 -2
  317. package/src/sql-sorters/registration-periods.ts +3 -2
  318. package/src/sql-sorters/registrations.ts +3 -2
  319. package/src/sql-sorters/tickets.ts +3 -2
  320. package/src/sql-sorters/webshops.ts +40 -0
  321. package/tests/actions/patchOrganizationMember.ts +5 -4
  322. package/tests/actions/patchPaymentStatus.ts +2 -2
  323. package/tests/actions/patchUserMember.ts +6 -4
  324. package/tests/e2e/api-rate-limits.test.ts +4 -5
  325. package/tests/e2e/bundle-discounts.test.ts +3 -2
  326. package/tests/e2e/charge-members.test.ts +7 -5
  327. package/tests/e2e/documents.test.ts +3 -2
  328. package/tests/e2e/private-files.test.ts +11 -13
  329. package/tests/e2e/register.test.ts +6 -5
  330. package/tests/e2e/stock.test.ts +6 -8
  331. package/tests/e2e/tickets.test.ts +4 -2
  332. package/tests/helpers/StripeMocker.ts +3 -3
  333. package/tests/init/initAdmin.ts +4 -2
  334. package/tests/init/initBundleDiscount.ts +3 -2
  335. package/tests/init/initPayconiq.ts +1 -1
  336. package/tests/init/initPermissionRole.ts +4 -2
  337. package/tests/init/initPlatformRecordCategory.ts +1 -1
  338. package/tests/init/initStripe.ts +1 -1
  339. package/tests/vitest.global.setup.ts +26 -0
  340. package/tests/{jest.setup.ts → vitest.setup.ts} +4 -3
  341. package/tsconfig.build.json +17 -0
  342. package/tsconfig.json +10 -41
  343. package/tsconfig.test.json +17 -0
  344. package/vitest.config.js +13 -0
  345. package/eslint.config.mjs +0 -5
  346. package/jest.config.cjs +0 -27
  347. package/tests/jest.global.setup.ts +0 -33
  348. package/tests/toMatchMap.ts +0 -68
@@ -0,0 +1,221 @@
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request } from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
4
+ import { SimpleError } from '@simonbackx/simple-errors';
5
+ import { Organization, Webshop } from '@stamhoofd/models';
6
+ import { SQL, applySQLSorter, compileToSQLFilter } from '@stamhoofd/sql';
7
+ import type { CountFilteredRequest, StamhoofdFilter } from '@stamhoofd/structures';
8
+ import { LimitedFilteredRequest, PaginatedResponse, PermissionLevel, WebshopWithOrganization, assertSort, getSortFilter } from '@stamhoofd/structures';
9
+
10
+ import type { SQLResultNamespacedRow } from '@simonbackx/simple-database';
11
+ import { Formatter } from '@stamhoofd/utility';
12
+ import { AuthenticatedStructures } from '../../../helpers/AuthenticatedStructures.js';
13
+ import { Context } from '../../../helpers/Context.js';
14
+ import { organizationFilterCompilers } from '../../../sql-filters/organizations.js';
15
+ import { webshopFilterCompilers } from '../../../sql-filters/webshops.js';
16
+ import { webshopSorters } from '../../../sql-sorters/webshops.js';
17
+
18
+ type Params = Record<string, never>;
19
+ type Query = LimitedFilteredRequest;
20
+ type Body = undefined;
21
+ type ResponseBody = PaginatedResponse<WebshopWithOrganization[], LimitedFilteredRequest>;
22
+
23
+ const sorters = webshopSorters;
24
+ const filterCompilers = webshopFilterCompilers;
25
+
26
+ export class GetWebshopsEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
27
+ queryDecoder = LimitedFilteredRequest as Decoder<LimitedFilteredRequest>;
28
+
29
+ protected doesMatch(request: Request): [true, Params] | [false] {
30
+ if (request.method !== 'GET') {
31
+ return [false];
32
+ }
33
+
34
+ const params = Endpoint.parseParameters(request.url, '/webshops', {});
35
+
36
+ if (params) {
37
+ return [true, params as Params];
38
+ }
39
+ return [false];
40
+ }
41
+
42
+ static async buildQuery(q: CountFilteredRequest | LimitedFilteredRequest) {
43
+ const organization = Context.organization;
44
+
45
+ const query = SQL
46
+ .select(
47
+ SQL.wildcard('webshops'),
48
+ )
49
+ .setMaxExecutionTime(15 * 1000)
50
+ .from(
51
+ SQL.table('webshops'),
52
+ );
53
+
54
+ if (organization) {
55
+ // Organization context: scope to this organization's webshops only
56
+ const scopeFilter: StamhoofdFilter = {
57
+ organizationId: {
58
+ $eq: organization.id,
59
+ },
60
+ };
61
+ query.where(await compileToSQLFilter(scopeFilter, filterCompilers));
62
+ }
63
+ else {
64
+ // Platform context: check platform access
65
+ const tags = Context.auth.getPlatformAccessibleOrganizationTags(PermissionLevel.Read);
66
+
67
+ if (tags !== 'all' && tags.length === 0) {
68
+ throw Context.auth.error();
69
+ }
70
+
71
+ if (tags !== 'all') {
72
+ // Join with organizations table to filter by accessible organization tags
73
+ query.join(
74
+ SQL.join(SQL.table('organizations'))
75
+ .where(
76
+ SQL.column('webshops', 'organizationId'),
77
+ SQL.column('organizations', 'id'),
78
+ ),
79
+ );
80
+
81
+ // Apply tag scope filter using the organizations filter compiler
82
+ const tagScopeFilter: StamhoofdFilter = {
83
+ tags: {
84
+ $in: tags,
85
+ },
86
+ };
87
+ query.where(await compileToSQLFilter(tagScopeFilter, organizationFilterCompilers));
88
+ }
89
+ }
90
+
91
+ if (q.filter) {
92
+ query.where(await compileToSQLFilter(q.filter, filterCompilers));
93
+ }
94
+
95
+ if (q.search) {
96
+ const searchFilter: StamhoofdFilter = {
97
+ $or: [
98
+ {
99
+ name: {
100
+ $contains: q.search,
101
+ },
102
+ },
103
+ ],
104
+ };
105
+ query.where(await compileToSQLFilter(searchFilter, filterCompilers));
106
+ }
107
+
108
+ if (q instanceof LimitedFilteredRequest) {
109
+ if (q.pageFilter) {
110
+ query.where(await compileToSQLFilter(q.pageFilter, filterCompilers));
111
+ }
112
+
113
+ q.sort = assertSort(q.sort, [{ key: 'id' }]);
114
+ applySQLSorter(query, q.sort, sorters);
115
+ query.limit(q.limit);
116
+ }
117
+
118
+ return query;
119
+ }
120
+
121
+ static async buildData(requestQuery: LimitedFilteredRequest): Promise<PaginatedResponse<WebshopWithOrganization[], LimitedFilteredRequest>> {
122
+ const query = await GetWebshopsEndpoint.buildQuery(requestQuery);
123
+ let data: SQLResultNamespacedRow[];
124
+
125
+ try {
126
+ data = await query.fetch();
127
+ }
128
+ catch (error) {
129
+ if (error.message.includes('ER_QUERY_TIMEOUT')) {
130
+ throw new SimpleError({
131
+ code: 'timeout',
132
+ message: 'Query took too long',
133
+ human: $t(`%Cv`),
134
+ });
135
+ }
136
+ throw error;
137
+ }
138
+
139
+ const webshops = Webshop.fromRows(data, 'webshops');
140
+
141
+ // Filter out webshops the user cannot access (e.g. specific resource-level permissions)
142
+ const accessibleWebshops: Webshop[] = [];
143
+ for (const webshop of webshops) {
144
+ if (await Context.auth.canAccessWebshop(webshop, PermissionLevel.Read)) {
145
+ accessibleWebshops.push(webshop);
146
+ }
147
+ }
148
+
149
+ // Batch-load organizations for accessible webshops
150
+ const organizationIds = Formatter.uniqueArray(accessibleWebshops.map(w => w.organizationId));
151
+ const organizationModels = organizationIds.length > 0 ? await Organization.getByIDs(...organizationIds) : [];
152
+
153
+ let next: LimitedFilteredRequest | undefined;
154
+
155
+ if (webshops.length >= requestQuery.limit) {
156
+ const lastObject = webshops[webshops.length - 1];
157
+ const nextFilter = getSortFilter(lastObject, sorters, requestQuery.sort);
158
+
159
+ next = new LimitedFilteredRequest({
160
+ filter: requestQuery.filter,
161
+ pageFilter: nextFilter,
162
+ sort: requestQuery.sort,
163
+ limit: requestQuery.limit,
164
+ search: requestQuery.search,
165
+ });
166
+
167
+ if (JSON.stringify(nextFilter) === JSON.stringify(requestQuery.pageFilter)) {
168
+ console.error('Found infinite loading loop for', requestQuery);
169
+ next = undefined;
170
+ }
171
+ }
172
+
173
+ const results: WebshopWithOrganization[] = [];
174
+ for (const webshop of accessibleWebshops) {
175
+ const organizationModel = organizationModels.find(o => o.id === webshop.organizationId);
176
+ if (!organizationModel) {
177
+ // Skip webshops whose organization cannot be found
178
+ console.warn('Organization not found for webshop', webshop.id, webshop.organizationId);
179
+ continue;
180
+ }
181
+
182
+ const webshopStruct = AuthenticatedStructures.webshopPreview(webshop);
183
+ results.push(WebshopWithOrganization.create({
184
+ webshop: webshopStruct,
185
+ organization: organizationModel.getBaseStructure(),
186
+ }));
187
+ }
188
+
189
+ return new PaginatedResponse<WebshopWithOrganization[], LimitedFilteredRequest>({
190
+ results,
191
+ next,
192
+ });
193
+ }
194
+
195
+ async handle(request: DecodedRequest<Params, Query, Body>) {
196
+ await Context.setOptionalOrganizationScope();
197
+ await Context.authenticate();
198
+
199
+ const maxLimit = Context.auth.hasSomePlatformAccess() ? 1000 : 100;
200
+
201
+ if (request.query.limit > maxLimit) {
202
+ throw new SimpleError({
203
+ code: 'invalid_field',
204
+ field: 'limit',
205
+ message: 'Limit can not be more than ' + maxLimit,
206
+ });
207
+ }
208
+
209
+ if (request.query.limit < 1) {
210
+ throw new SimpleError({
211
+ code: 'invalid_field',
212
+ field: 'limit',
213
+ message: 'Limit can not be less than 1',
214
+ });
215
+ }
216
+
217
+ return new Response(
218
+ await GetWebshopsEndpoint.buildData(request.query),
219
+ );
220
+ }
221
+ }
@@ -1,7 +1,8 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { SimpleError } from '@simonbackx/simple-errors';
3
4
  import { BalanceItem } from '@stamhoofd/models';
4
- import { BalanceItemWithPayments } from '@stamhoofd/structures';
5
+ import type { BalanceItemWithPayments } from '@stamhoofd/structures';
5
6
 
6
7
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
7
8
  import { Context } from '../../../../helpers/Context.js';
@@ -1,5 +1,6 @@
1
- import { Decoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { CountFilteredRequest, CountResponse } from '@stamhoofd/structures';
4
5
 
5
6
  import { Context } from '../../../../helpers/Context.js';
@@ -1,9 +1,11 @@
1
- import { Decoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { SimpleError } from '@simonbackx/simple-errors';
4
5
  import { BalanceItem } from '@stamhoofd/models';
5
6
  import { applySQLSorter, compileToSQLFilter } from '@stamhoofd/sql';
6
- import { BalanceItem as BalanceItemStruct, CountFilteredRequest, LimitedFilteredRequest, PaginatedResponse, StamhoofdFilter, assertSort, getSortFilter } from '@stamhoofd/structures';
7
+ import type { BalanceItem as BalanceItemStruct, CountFilteredRequest, StamhoofdFilter} from '@stamhoofd/structures';
8
+ import { LimitedFilteredRequest, PaginatedResponse, assertSort, getSortFilter } from '@stamhoofd/structures';
7
9
 
8
10
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
9
11
  import { Context } from '../../../../helpers/Context.js';
@@ -1,5 +1,7 @@
1
- import { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder} from '@simonbackx/simple-encoding';
2
+ import { PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { SimpleError } from '@simonbackx/simple-errors';
4
6
  import { BalanceItem, Member, Order, User } from '@stamhoofd/models';
5
7
  import { QueueHandler } from '@stamhoofd/queues';
@@ -1,5 +1,7 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
- import { DetailedPayableBalanceCollection, PaymentStatus } from '@stamhoofd/structures';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
+ import type { DetailedPayableBalanceCollection} from '@stamhoofd/structures';
4
+ import { PaymentStatus } from '@stamhoofd/structures';
3
5
 
4
6
  import { BalanceItem, Payment } from '@stamhoofd/models';
5
7
  import { SQL } from '@stamhoofd/sql';
@@ -1,5 +1,7 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
- import { PayableBalanceCollection, ReceivableBalanceType } from '@stamhoofd/structures';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
+ import type { PayableBalanceCollection} from '@stamhoofd/structures';
4
+ import { ReceivableBalanceType } from '@stamhoofd/structures';
3
5
 
4
6
  import { Context } from '../../../../helpers/Context.js';
5
7
  import { GetUserPayableBalanceEndpoint } from '../../../global/registration/GetUserPayableBalanceEndpoint.js';
@@ -1,4 +1,5 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { OrganizationPackagesStatus, STPackage as STPackageStruct } from '@stamhoofd/structures';
3
4
  import { Context } from '../../../../helpers/Context.js';
4
5
  import { STPackageService } from '../../../../services/STPackageService.js';
@@ -1,4 +1,5 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { SimpleError } from '@simonbackx/simple-errors';
3
4
  import { DocumentTemplate } from '@stamhoofd/models';
4
5
 
@@ -1,5 +1,6 @@
1
- import { Decoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { CountFilteredRequest, CountResponse } from '@stamhoofd/structures';
4
5
 
5
6
  import { Context } from '../../../../helpers/Context.js';
@@ -1,9 +1,12 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { DocumentTemplate } from '@stamhoofd/models';
3
- import { assertSort, CountFilteredRequest, DocumentTemplatePrivate, LimitedFilteredRequest, PaginatedResponse, SearchFilterFactory, StamhoofdFilter } from '@stamhoofd/structures';
4
+ import type { CountFilteredRequest, DocumentTemplatePrivate, StamhoofdFilter } from '@stamhoofd/structures';
5
+ import { assertSort, LimitedFilteredRequest, PaginatedResponse, SearchFilterFactory } from '@stamhoofd/structures';
4
6
 
5
- import { Decoder } from '@simonbackx/simple-encoding';
6
- import { applySQLSorter, compileToSQLFilter, SQL, SQLFilterDefinitions, SQLSortDefinitions } from '@stamhoofd/sql';
7
+ import type { Decoder } from '@simonbackx/simple-encoding';
8
+ import type { SQLFilterDefinitions, SQLSortDefinitions } from '@stamhoofd/sql';
9
+ import { applySQLSorter, compileToSQLFilter, SQL } from '@stamhoofd/sql';
7
10
  import { Context } from '../../../../helpers/Context.js';
8
11
  import { LimitedFilteredRequestHelper } from '../../../../helpers/LimitedFilteredRequestHelper.js';
9
12
  import { documentTemplateFilterCompilers } from '../../../../sql-filters/document-templates.js';
@@ -1,5 +1,6 @@
1
- import { Decoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { CountFilteredRequest, CountResponse } from '@stamhoofd/structures';
4
5
 
5
6
  import { Context } from '../../../../helpers/Context.js';
@@ -1,9 +1,12 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { Document } from '@stamhoofd/models';
3
- import { assertSort, CountFilteredRequest, Document as DocumentStruct, getSortFilter, LimitedFilteredRequest, PaginatedResponse, SearchFilterFactory, StamhoofdFilter } from '@stamhoofd/structures';
4
+ import type { CountFilteredRequest, Document as DocumentStruct, StamhoofdFilter } from '@stamhoofd/structures';
5
+ import { assertSort, getSortFilter, LimitedFilteredRequest, PaginatedResponse, SearchFilterFactory } from '@stamhoofd/structures';
4
6
 
5
- import { Decoder } from '@simonbackx/simple-encoding';
6
- import { applySQLSorter, compileToSQLFilter, SQL, SQLFilterDefinitions, SQLSortDefinitions } from '@stamhoofd/sql';
7
+ import type { Decoder } from '@simonbackx/simple-encoding';
8
+ import type { SQLFilterDefinitions, SQLSortDefinitions } from '@stamhoofd/sql';
9
+ import { applySQLSorter, compileToSQLFilter, SQL } from '@stamhoofd/sql';
7
10
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
8
11
  import { Context } from '../../../../helpers/Context.js';
9
12
  import { LimitedFilteredRequestHelper } from '../../../../helpers/LimitedFilteredRequestHelper.js';
@@ -1,5 +1,7 @@
1
- import { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder} from '@simonbackx/simple-encoding';
2
+ import { PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { SimpleError } from '@simonbackx/simple-errors';
4
6
  import { Document, DocumentTemplate, Member, Registration } from '@stamhoofd/models';
5
7
  import { DocumentStatus, Document as DocumentStruct, PermissionLevel } from '@stamhoofd/structures';
@@ -1,6 +1,8 @@
1
1
  import { PatchableArray } from '@simonbackx/simple-encoding';
2
- import { Endpoint, Request } from '@simonbackx/simple-endpoints';
3
- import { DocumentTemplate, DocumentTemplateFactory, Organization, OrganizationFactory, RegistrationPeriod, RegistrationPeriodFactory, Token, User, UserFactory } from '@stamhoofd/models';
2
+ import type { Endpoint} from '@simonbackx/simple-endpoints';
3
+ import { Request } from '@simonbackx/simple-endpoints';
4
+ import type { Organization, RegistrationPeriod, User} from '@stamhoofd/models';
5
+ import { DocumentTemplate, DocumentTemplateFactory, OrganizationFactory, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
4
6
  import { SQL } from '@stamhoofd/sql';
5
7
  import { DocumentPrivateSettings, DocumentStatus, DocumentTemplateDefinition, DocumentTemplatePrivate, PermissionLevel, Permissions } from '@stamhoofd/structures';
6
8
  import { STExpect, TestUtils } from '@stamhoofd/test-utils';
@@ -1,5 +1,7 @@
1
- import { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder} from '@simonbackx/simple-encoding';
2
+ import { PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { SimpleError } from '@simonbackx/simple-errors';
4
6
  import { DocumentTemplate } from '@stamhoofd/models';
5
7
  import { DocumentTemplatePrivate, PermissionLevel } from '@stamhoofd/structures';
@@ -1,5 +1,6 @@
1
1
  import { ArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { SimpleError } from '@simonbackx/simple-errors';
4
5
  import { EmailAddress } from '@stamhoofd/email';
5
6
  import { EmailInformation } from '@stamhoofd/structures';
@@ -1,5 +1,6 @@
1
1
  import { Request } from '@simonbackx/simple-endpoints';
2
- import { EmailTemplate, GroupFactory, Organization, OrganizationFactory, Platform, RegistrationPeriod, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
2
+ import type { Organization, RegistrationPeriod} from '@stamhoofd/models';
3
+ import { EmailTemplate, GroupFactory, OrganizationFactory, Platform, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
3
4
  import { EmailTemplateType, PermissionLevel, PermissionRoleDetailed, Permissions, PermissionsResourceType, ResourcePermissions, Version } from '@stamhoofd/structures';
4
5
  import { TestUtils } from '@stamhoofd/test-utils';
5
6
  import { testServer } from '../../../../../tests/helpers/TestServer.js';
@@ -86,4 +87,38 @@ describe('Endpoint.GetEmailTemplatesEndpoint', () => {
86
87
  expect(response.body).toBeDefined();
87
88
  expect(response.body).toHaveLength(1);
88
89
  });
90
+
91
+ test('Saved templates with groupIds should not throw SQL syntax error', async () => {
92
+ const organization = await new OrganizationFactory({ period }).create();
93
+ const group = await new GroupFactory({ organization }).create();
94
+
95
+ const user = await new UserFactory({
96
+ organization,
97
+ permissions: Permissions.create({
98
+ level: PermissionLevel.Full,
99
+ }),
100
+ }).create();
101
+
102
+ const token = await Token.createToken(user);
103
+
104
+ const template = new EmailTemplate();
105
+ template.subject = 'saved template';
106
+ template.type = EmailTemplateType.SavedMembersEmail;
107
+ template.json = {};
108
+ template.html = 'html test';
109
+ template.text = 'text test';
110
+ template.organizationId = organization.id;
111
+ template.groupId = group.id;
112
+ await template.save();
113
+
114
+ const response = await getEmailTemplates({
115
+ token,
116
+ organization,
117
+ types: [EmailTemplateType.SavedMembersEmail],
118
+ groupIds: [group.id],
119
+ });
120
+
121
+ expect(response.body).toBeDefined();
122
+ expect(response.body).toHaveLength(1);
123
+ });
89
124
  });
@@ -1,7 +1,10 @@
1
- import { AutoEncoder, Decoder, EnumDecoder, field, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder} from '@simonbackx/simple-encoding';
2
+ import { AutoEncoder, EnumDecoder, field, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { EmailTemplate } from '@stamhoofd/models';
4
6
  import { EmailTemplate as EmailTemplateStruct, EmailTemplateType } from '@stamhoofd/structures';
7
+ import { Formatter } from '@stamhoofd/utility';
5
8
 
6
9
  import { SimpleError } from '@simonbackx/simple-errors';
7
10
  import { StringArrayDecoder } from '../../../../decoders/StringArrayDecoder.js';
@@ -101,7 +104,7 @@ export class GetEmailTemplatesEndpoint extends Endpoint<Params, Query, Body, Res
101
104
  },
102
105
  }));
103
106
 
104
- if (organization && (request.query.webshopId || request.query.groupIds)) {
107
+ if (organization && defaultTemplateTypes.length > 0 && (request.query.webshopId || request.query.groupIds)) {
105
108
  const orgDefaults = (await EmailTemplate.where({
106
109
  organizationId: organization.id,
107
110
  webshopId: null,
@@ -116,8 +119,14 @@ export class GetEmailTemplatesEndpoint extends Endpoint<Params, Query, Body, Res
116
119
  }
117
120
 
118
121
  const allTemplates: EmailTemplate[] = [];
122
+ const allCandidates = templates.concat(defaultTemplates);
119
123
 
120
- for (const template of templates.concat(defaultTemplates)) {
124
+ const groupIds = Formatter.uniqueArray(allCandidates.map(t => t.groupId).filter((id): id is string => id !== null));
125
+ if (groupIds.length > 0) {
126
+ await Context.auth.getGroups(groupIds);
127
+ }
128
+
129
+ for (const template of allCandidates) {
121
130
  if (await Context.auth.canAccessEmailTemplate(template)) {
122
131
  allTemplates.push(template);
123
132
  }
@@ -1,6 +1,8 @@
1
- import { PatchableArray, PatchableArrayAutoEncoder } from '@simonbackx/simple-encoding';
1
+ import type { PatchableArrayAutoEncoder } from '@simonbackx/simple-encoding';
2
+ import { PatchableArray } from '@simonbackx/simple-encoding';
2
3
  import { Request } from '@simonbackx/simple-endpoints';
3
- import { EmailTemplate, GroupFactory, Organization, OrganizationFactory, Platform, RegistrationPeriod, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
4
+ import type { Organization, RegistrationPeriod} from '@stamhoofd/models';
5
+ import { EmailTemplate, GroupFactory, OrganizationFactory, Platform, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
4
6
  import { EmailTemplate as EmailTemplateStruct, EmailTemplateType, PermissionLevel, PermissionRoleDetailed, Permissions, PermissionsResourceType, ResourcePermissions, Version } from '@stamhoofd/structures';
5
7
  import { TestUtils } from '@stamhoofd/test-utils';
6
8
  import { testServer } from '../../../../../tests/helpers/TestServer.js';
@@ -1,5 +1,7 @@
1
- import { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder} from '@simonbackx/simple-encoding';
2
+ import { PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { EmailTemplate, Group, Webshop } from '@stamhoofd/models';
4
6
  import { EmailTemplate as EmailTemplateStruct, PermissionLevel } from '@stamhoofd/structures';
5
7
 
@@ -1,5 +1,6 @@
1
- import { Decoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { CountFilteredRequest, CountResponse } from '@stamhoofd/structures';
4
5
 
5
6
  import { Context } from '../../../../helpers/Context.js';
@@ -1,9 +1,11 @@
1
- import { Decoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder } from '@simonbackx/simple-encoding';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import { SimpleError } from '@simonbackx/simple-errors';
4
5
  import { Invoice } from '@stamhoofd/models';
5
6
  import { applySQLSorter, compileToSQLFilter } from '@stamhoofd/sql';
6
- import { CountFilteredRequest, InvoiceStruct, LimitedFilteredRequest, PaginatedResponse, StamhoofdFilter, assertSort, getSortFilter } from '@stamhoofd/structures';
7
+ import type { CountFilteredRequest, InvoiceStruct, StamhoofdFilter} from '@stamhoofd/structures';
8
+ import { LimitedFilteredRequest, PaginatedResponse, assertSort, getSortFilter } from '@stamhoofd/structures';
7
9
 
8
10
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
9
11
  import { Context } from '../../../../helpers/Context.js';
@@ -1,10 +1,12 @@
1
- import { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder} from '@simonbackx/simple-encoding';
2
+ import { PatchableArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { Invoice as InvoiceStruct } from '@stamhoofd/structures';
4
6
 
5
7
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
6
8
  import { Context } from '../../../../helpers/Context.js';
7
- import { Invoice } from '@stamhoofd/models';
9
+ import type { Invoice } from '@stamhoofd/models';
8
10
  import { SimpleError } from '@simonbackx/simple-errors';
9
11
  import { ViesHelper } from '../../../../helpers/ViesHelper.js';
10
12
  import { InvoiceService } from '../../../../services/InvoiceService.js';
@@ -1,6 +1,8 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { MollieToken } from '@stamhoofd/models';
3
- import { CheckMollieResponse, Organization as OrganizationStruct, PermissionLevel } from '@stamhoofd/structures';
4
+ import type { Organization as OrganizationStruct} from '@stamhoofd/structures';
5
+ import { CheckMollieResponse, PermissionLevel } from '@stamhoofd/structures';
4
6
 
5
7
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
6
8
  import { Context } from '../../../../helpers/Context.js';
@@ -1,7 +1,10 @@
1
- import { AutoEncoder, Decoder, field, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { Decoder} from '@simonbackx/simple-encoding';
2
+ import { AutoEncoder, field, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
4
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
5
  import { MollieToken } from '@stamhoofd/models';
4
- import { Organization as OrganizationStruct, PermissionLevel } from '@stamhoofd/structures';
6
+ import type { Organization as OrganizationStruct} from '@stamhoofd/structures';
7
+ import { PermissionLevel } from '@stamhoofd/structures';
5
8
 
6
9
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
7
10
  import { checkMollieSettlementsFor } from '../../../../helpers/CheckSettlements.js';
@@ -1,6 +1,8 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { MollieToken } from '@stamhoofd/models';
3
- import { Organization as OrganizationStruct, PermissionLevel } from '@stamhoofd/structures';
4
+ import type { Organization as OrganizationStruct} from '@stamhoofd/structures';
5
+ import { PermissionLevel } from '@stamhoofd/structures';
4
6
 
5
7
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures.js';
6
8
  import { Context } from '../../../../helpers/Context.js';
@@ -1,4 +1,5 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
1
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
2
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
2
3
  import { isSimpleError, isSimpleErrors, SimpleError } from '@simonbackx/simple-errors';
3
4
  import { MollieToken } from '@stamhoofd/models';
4
5
  import { PermissionLevel } from '@stamhoofd/structures';
@@ -1,5 +1,6 @@
1
1
  import { AutoEncoder, field, StringDecoder } from '@simonbackx/simple-encoding';
2
- import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
+ import type { DecodedRequest, Request} from '@simonbackx/simple-endpoints';
3
+ import { Endpoint, Response } from '@simonbackx/simple-endpoints';
3
4
  import jwt from 'jsonwebtoken';
4
5
 
5
6
  import { Context } from '../../../../helpers/Context.js';