@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.
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
@@ -1,7 +1,7 @@
1
- import { SQL, SQLAge, SQLConcat, SQLFilterDefinitions, SQLScalar, baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, createSQLFilterNamespace, createSQLRelationFilterCompiler } from "@stamhoofd/sql";
2
- import { Formatter } from "@stamhoofd/utility";
3
- import { organizationFilterCompilers } from "./organizations";
4
- import { registrationFilterCompilers } from "./registrations";
1
+ import { SQL, SQLAge, SQLConcat, SQLFilterDefinitions, SQLScalar, SQLValueType, baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, createSQLFilterNamespace, createSQLRelationFilterCompiler } from '@stamhoofd/sql';
2
+ import { Formatter } from '@stamhoofd/utility';
3
+ import { organizationFilterCompilers } from './organizations';
4
+ import { registrationFilterCompilers } from './registrations';
5
5
 
6
6
  /**
7
7
  * Defines how to filter members in the database from StamhoofdFilter objects
@@ -17,78 +17,78 @@ export const memberFilterCompilers: SQLFilterDefinitions = {
17
17
  SQL.column('firstName'),
18
18
  new SQLScalar(' '),
19
19
  SQL.column('lastName'),
20
- )
20
+ ),
21
21
  ),
22
22
  age: createSQLExpressionFilterCompiler(
23
- new SQLAge(SQL.column('birthDay')),
24
- {nullable: true}
23
+ new SQLAge(SQL.column('birthDay')),
24
+ { nullable: true },
25
25
  ),
26
26
  gender: createSQLExpressionFilterCompiler(
27
27
  SQL.jsonValue(SQL.column('details'), '$.value.gender'),
28
- {isJSONValue: true}
28
+ { isJSONValue: true, type: SQLValueType.JSONString },
29
29
  ),
30
30
  birthDay: createSQLColumnFilterCompiler('birthDay', {
31
31
  normalizeValue: (d) => {
32
32
  if (typeof d === 'number') {
33
- const date = new Date(d)
33
+ const date = new Date(d);
34
34
  return Formatter.dateIso(date);
35
35
  }
36
36
  return d;
37
- }
37
+ },
38
38
  }),
39
39
  organizationName: createSQLExpressionFilterCompiler(
40
- SQL.column('organizations', 'name')
40
+ SQL.column('organizations', 'name'),
41
41
  ),
42
42
 
43
43
  email: createSQLExpressionFilterCompiler(
44
44
  SQL.jsonValue(SQL.column('details'), '$.value.email'),
45
- {isJSONValue: true}
45
+ { isJSONValue: true, type: SQLValueType.JSONString },
46
46
  ),
47
47
 
48
48
  parentEmail: createSQLExpressionFilterCompiler(
49
49
  SQL.jsonValue(SQL.column('details'), '$.value.parents[*].email'),
50
- {isJSONValue: true, isJSONObject: true}
50
+ { isJSONValue: true, isJSONObject: true, type: SQLValueType.JSONString },
51
51
  ),
52
52
 
53
53
  unverifiedEmail: createSQLExpressionFilterCompiler(
54
54
  SQL.jsonValue(SQL.column('details'), '$.value.unverifiedEmails'),
55
- {isJSONValue: true, isJSONObject: true}
55
+ { isJSONValue: true, isJSONObject: true, type: SQLValueType.JSONString },
56
56
  ),
57
57
 
58
58
  phone: createSQLExpressionFilterCompiler(
59
59
  SQL.jsonValue(SQL.column('details'), '$.value.phone'),
60
- {isJSONValue: true}
60
+ { isJSONValue: true },
61
61
  ),
62
62
 
63
63
  parentPhone: createSQLExpressionFilterCompiler(
64
64
  SQL.jsonValue(SQL.column('details'), '$.value.parents[*].phone'),
65
- {isJSONValue: true, isJSONObject: true}
65
+ { isJSONValue: true, isJSONObject: true },
66
66
  ),
67
67
 
68
68
  unverifiedPhone: createSQLExpressionFilterCompiler(
69
69
  SQL.jsonValue(SQL.column('details'), '$.value.unverifiedPhones'),
70
- {isJSONValue: true, isJSONObject: true}
70
+ { isJSONValue: true, isJSONObject: true },
71
71
  ),
72
72
 
73
73
  registrations: createSQLRelationFilterCompiler(
74
74
  SQL.select()
75
75
  .from(
76
- SQL.table('registrations')
76
+ SQL.table('registrations'),
77
77
  ).join(
78
78
  SQL.join(
79
- SQL.table('groups')
79
+ SQL.table('groups'),
80
80
  ).where(
81
81
  SQL.column('groups', 'id'),
82
- SQL.column('registrations', 'groupId')
83
- )
82
+ SQL.column('registrations', 'groupId'),
83
+ ),
84
84
  )
85
85
  .join(
86
86
  SQL.join(
87
- SQL.table('organizations')
87
+ SQL.table('organizations'),
88
88
  ).where(
89
89
  SQL.column('organizations', 'id'),
90
- SQL.column('registrations', 'organizationId')
91
- )
90
+ SQL.column('registrations', 'organizationId'),
91
+ ),
92
92
  )
93
93
  .where(
94
94
  SQL.column('memberId'),
@@ -101,102 +101,102 @@ export const memberFilterCompilers: SQLFilterDefinitions = {
101
101
  null,
102
102
  ).where(
103
103
  SQL.column('groups', 'deletedAt'),
104
- null
104
+ null,
105
105
  ),
106
106
  {
107
107
  ...registrationFilterCompilers,
108
- "organization": createSQLFilterNamespace(organizationFilterCompilers)
109
- }
108
+ organization: createSQLFilterNamespace(organizationFilterCompilers),
109
+ },
110
110
  ),
111
111
 
112
112
  responsibilities: createSQLRelationFilterCompiler(
113
113
  SQL.select()
114
- .from(
115
- SQL.table('member_responsibility_records')
116
- )
117
- .join(
118
- SQL.leftJoin(
119
- SQL.table('groups')
120
- ).where(
121
- SQL.column('groups', 'id'),
122
- SQL.column('member_responsibility_records', 'groupId')
114
+ .from(
115
+ SQL.table('member_responsibility_records'),
123
116
  )
124
- )
125
- .where(
126
- SQL.column('memberId'),
127
- SQL.column('members', 'id'),
128
- ),
117
+ .join(
118
+ SQL.leftJoin(
119
+ SQL.table('groups'),
120
+ ).where(
121
+ SQL.column('groups', 'id'),
122
+ SQL.column('member_responsibility_records', 'groupId'),
123
+ ),
124
+ )
125
+ .where(
126
+ SQL.column('memberId'),
127
+ SQL.column('members', 'id'),
128
+ ),
129
129
  {
130
130
  ...baseSQLFilterCompilers,
131
131
  // Alias for responsibilityId
132
- "id": createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'responsibilityId')),
133
- "responsibilityId": createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'responsibilityId')),
134
- "organizationId": createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'organizationId')),
135
- "startDate": createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'startDate')),
136
- "endDate": createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'endDate')),
137
- "group": createSQLFilterNamespace({
132
+ id: createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'responsibilityId')),
133
+ responsibilityId: createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'responsibilityId')),
134
+ organizationId: createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'organizationId')),
135
+ startDate: createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'startDate')),
136
+ endDate: createSQLColumnFilterCompiler(SQL.column('member_responsibility_records', 'endDate')),
137
+ group: createSQLFilterNamespace({
138
138
  ...baseSQLFilterCompilers,
139
139
  id: createSQLColumnFilterCompiler(SQL.column('groups', 'id')),
140
140
  defaultAgeGroupId: createSQLColumnFilterCompiler(SQL.column('groups', 'defaultAgeGroupId')),
141
- })
142
- }
141
+ }),
142
+ },
143
143
  ),
144
144
 
145
145
  platformMemberships: createSQLRelationFilterCompiler(
146
146
  SQL.select()
147
- .from(
148
- SQL.table('member_platform_memberships')
149
- )
150
- .where(
151
- SQL.column('memberId'),
152
- SQL.column('members', 'id'),
153
- )
154
- .where(
155
- SQL.column('deletedAt'),
156
- null,
157
- ),
147
+ .from(
148
+ SQL.table('member_platform_memberships'),
149
+ )
150
+ .where(
151
+ SQL.column('memberId'),
152
+ SQL.column('members', 'id'),
153
+ )
154
+ .where(
155
+ SQL.column('deletedAt'),
156
+ null,
157
+ ),
158
158
  {
159
159
  ...baseSQLFilterCompilers,
160
- "id": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'id')),
161
- "membershipTypeId": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'membershipTypeId')),
162
- "organizationId": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'organizationId')),
163
- "periodId": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'periodId')),
164
- "price": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'price')),
165
- "invoiceId": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'invoiceId')),
166
- "startDate": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'startDate')),
167
- "endDate": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'endDate')),
168
- "expireDate": createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'expireDate')),
169
- }
160
+ id: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'id')),
161
+ membershipTypeId: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'membershipTypeId')),
162
+ organizationId: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'organizationId')),
163
+ periodId: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'periodId')),
164
+ price: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'price')),
165
+ invoiceId: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'invoiceId')),
166
+ startDate: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'startDate')),
167
+ endDate: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'endDate')),
168
+ expireDate: createSQLColumnFilterCompiler(SQL.column('member_platform_memberships', 'expireDate')),
169
+ },
170
170
  ),
171
171
 
172
172
  organizations: createSQLRelationFilterCompiler(
173
173
  SQL.select()
174
- .from(
175
- SQL.table('registrations')
176
- ).join(
177
- SQL.join(
178
- SQL.table('groups')
174
+ .from(
175
+ SQL.table('registrations'),
176
+ ).join(
177
+ SQL.join(
178
+ SQL.table('groups'),
179
+ ).where(
180
+ SQL.column('groups', 'id'),
181
+ SQL.column('registrations', 'groupId'),
182
+ ),
183
+ ).join(
184
+ SQL.join(
185
+ SQL.table('organizations'),
186
+ ).where(
187
+ SQL.column('organizations', 'id'),
188
+ SQL.column('registrations', 'organizationId'),
189
+ ),
179
190
  ).where(
180
- SQL.column('groups', 'id'),
181
- SQL.column('registrations', 'groupId')
182
- )
183
- ).join(
184
- SQL.join(
185
- SQL.table('organizations')
191
+ SQL.column('memberId'),
192
+ SQL.column('members', 'id'),
193
+ ).whereNot(
194
+ SQL.column('registeredAt'),
195
+ null,
186
196
  ).where(
187
- SQL.column('organizations', 'id'),
188
- SQL.column('registrations', 'organizationId')
189
- )
190
- ).where(
191
- SQL.column('memberId'),
192
- SQL.column('members', 'id'),
193
- ).whereNot(
194
- SQL.column('registeredAt'),
195
- null,
196
- ).where(
197
- SQL.column('groups', 'deletedAt'),
198
- null
199
- ),
200
- organizationFilterCompilers
197
+ SQL.column('groups', 'deletedAt'),
198
+ null,
199
+ ),
200
+ organizationFilterCompilers,
201
201
  ),
202
- }
202
+ };
@@ -1,102 +1,166 @@
1
- import { SQL, SQLConcat, SQLFilterDefinitions, SQLNow, SQLNull, SQLScalar, SQLWhereEqual, SQLWhereOr, SQLWhereSign, baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, createSQLRelationFilterCompiler } from "@stamhoofd/sql";
1
+ import {
2
+ SQL,
3
+ SQLConcat,
4
+ SQLExpressionOptions,
5
+ SQLFilterDefinitions,
6
+ SQLNow,
7
+ SQLNull,
8
+ SQLQuery,
9
+ SQLScalar,
10
+ SQLValueType,
11
+ SQLWhereEqual,
12
+ SQLWhereOr,
13
+ SQLWhereSign,
14
+ baseSQLFilterCompilers,
15
+ createSQLColumnFilterCompiler,
16
+ createSQLExpressionFilterCompiler,
17
+ createSQLFilterNamespace,
18
+ createSQLRelationFilterCompiler,
19
+ } from '@stamhoofd/sql';
20
+ import { SetupStepType } from '@stamhoofd/structures';
2
21
 
3
22
  export const organizationFilterCompilers: SQLFilterDefinitions = {
4
23
  ...baseSQLFilterCompilers,
5
- id: createSQLExpressionFilterCompiler(
6
- SQL.column('organizations', 'id')
7
- ),
8
- uri: createSQLExpressionFilterCompiler(
9
- SQL.column('organizations', 'uri')
10
- ),
24
+ id: createSQLExpressionFilterCompiler(SQL.column('organizations', 'id')),
25
+ uri: createSQLExpressionFilterCompiler(SQL.column('organizations', 'uri')),
11
26
  name: createSQLExpressionFilterCompiler(
12
- SQL.column('organizations', 'name')
27
+ SQL.column('organizations', 'name'),
13
28
  ),
14
29
  active: createSQLExpressionFilterCompiler(
15
- SQL.column('organizations', 'active')
30
+ SQL.column('organizations', 'active'),
16
31
  ),
17
32
  city: createSQLExpressionFilterCompiler(
18
33
  SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.city'),
19
- {isJSONValue: true}
34
+ { isJSONValue: true, type: SQLValueType.JSONString },
20
35
  ),
21
36
  country: createSQLExpressionFilterCompiler(
22
- SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.country'),
23
- {isJSONValue: true}
37
+ SQL.jsonValue(
38
+ SQL.column('organizations', 'address'),
39
+ '$.value.country',
40
+ ),
41
+ { isJSONValue: true, type: SQLValueType.JSONString },
24
42
  ),
25
43
  umbrellaOrganization: createSQLExpressionFilterCompiler(
26
- SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.umbrellaOrganization'),
27
- {isJSONValue: true}
44
+ SQL.jsonValue(
45
+ SQL.column('organizations', 'meta'),
46
+ '$.value.umbrellaOrganization',
47
+ ),
48
+ { isJSONValue: true },
28
49
  ),
29
50
  type: createSQLExpressionFilterCompiler(
30
51
  SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.type'),
31
- {isJSONValue: true}
52
+ { isJSONValue: true },
32
53
  ),
33
54
  tags: createSQLExpressionFilterCompiler(
34
55
  SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.tags'),
35
- {isJSONValue: true, isJSONObject: true}
56
+ { isJSONValue: true, isJSONObject: true },
36
57
  ),
37
- packages: createSQLRelationFilterCompiler(
38
- SQL.select().from(
39
- SQL.table('stamhoofd_packages')
40
- ).where(
41
- SQL.column('organizationId'),
42
- SQL.column('organizations', 'id'),
43
- )
44
- .where(
45
- SQL.column('validAt'),
46
- SQLWhereSign.NotEqual,
47
- new SQLNull()
48
- ).where(
49
- new SQLWhereOr([
50
- new SQLWhereEqual(
51
- SQL.column('validUntil'),
52
- SQLWhereSign.Equal,
53
- new SQLNull()
54
- ),
55
- new SQLWhereEqual(
56
- SQL.column('validUntil'),
57
- SQLWhereSign.Greater,
58
- new SQLNow()
59
- )
60
- ])
61
- ).where(
62
- new SQLWhereOr([
63
- new SQLWhereEqual(
64
- SQL.column('removeAt'),
65
- SQLWhereSign.Equal,
66
- new SQLNull()
58
+ setupSteps: createSQLRelationFilterCompiler(
59
+ SQL.select()
60
+ .from(SQL.table('organization_registration_periods'))
61
+ .where(
62
+ SQL.column(
63
+ 'organization_registration_periods',
64
+ 'organizationId',
67
65
  ),
68
- new SQLWhereEqual(
69
- SQL.column('removeAt'),
70
- SQLWhereSign.Greater,
71
- new SQLNow()
72
- )
73
- ])
74
- ),
66
+ SQL.column('organizations', 'id'),
67
+ ),
68
+ {
69
+ ...baseSQLFilterCompilers,
70
+ periodId: createSQLColumnFilterCompiler(
71
+ SQL.column('organization_registration_periods', 'periodId'),
72
+ ),
73
+ ...Object.fromEntries(
74
+ Object.values(SetupStepType)
75
+ .map((setupStep) => {
76
+ return [
77
+ setupStep,
78
+ createSQLFilterNamespace({
79
+ reviewedAt: createSQLExpressionFilterCompiler(
80
+ SQL.jsonValue(
81
+ SQL.column(
82
+ 'organization_registration_periods',
83
+ 'setupSteps',
84
+ ),
85
+ `$.value.steps.${setupStep}.review.date`,
86
+ ),
87
+ { isJSONValue: true, isJSONObject: false },
88
+ ),
89
+ complete: createSQLExpressionFilterCompiler(
90
+ {
91
+ getSQL: (
92
+ _options?: SQLExpressionOptions,
93
+ ): SQLQuery =>
94
+ `case when CAST(JSON_UNQUOTE(JSON_EXTRACT(\`organization_registration_periods\`.\`setupSteps\`, "$.value.steps.${setupStep}.finishedSteps")) AS unsigned) >= CAST(JSON_UNQUOTE(JSON_EXTRACT(\`organization_registration_periods\`.\`setupSteps\`, "$.value.steps.${setupStep}.totalSteps")) AS unsigned) then 1 else 0 end`,
95
+ },
96
+ { isJSONValue: false, isJSONObject: false },
97
+ ),
98
+ }),
99
+ ];
100
+ }),
101
+ ),
102
+ },
103
+ ),
104
+ packages: createSQLRelationFilterCompiler(
105
+ SQL.select()
106
+ .from(SQL.table('stamhoofd_packages'))
107
+ .where(
108
+ SQL.column('organizationId'),
109
+ SQL.column('organizations', 'id'),
110
+ )
111
+ .where(SQL.column('validAt'), SQLWhereSign.NotEqual, new SQLNull())
112
+ .where(
113
+ new SQLWhereOr([
114
+ new SQLWhereEqual(
115
+ SQL.column('validUntil'),
116
+ SQLWhereSign.Equal,
117
+ new SQLNull(),
118
+ ),
119
+ new SQLWhereEqual(
120
+ SQL.column('validUntil'),
121
+ SQLWhereSign.Greater,
122
+ new SQLNow(),
123
+ ),
124
+ ]),
125
+ )
126
+ .where(
127
+ new SQLWhereOr([
128
+ new SQLWhereEqual(
129
+ SQL.column('removeAt'),
130
+ SQLWhereSign.Equal,
131
+ new SQLNull(),
132
+ ),
133
+ new SQLWhereEqual(
134
+ SQL.column('removeAt'),
135
+ SQLWhereSign.Greater,
136
+ new SQLNow(),
137
+ ),
138
+ ]),
139
+ ),
75
140
 
76
141
  // const pack1 = await STPackage.where({ organizationId, validAt: { sign: "!=", value: null }, removeAt: { sign: ">", value: new Date() }})
77
142
  // const pack2 = await STPackage.where({ organizationId, validAt: { sign: "!=", value: null }, removeAt: null })
78
143
  {
79
144
  ...baseSQLFilterCompilers,
80
- "type": createSQLExpressionFilterCompiler(
145
+ type: createSQLExpressionFilterCompiler(
81
146
  SQL.jsonValue(SQL.column('meta'), '$.value.type'),
82
- {isJSONValue: true}
83
- )
84
- }
147
+ { isJSONValue: true },
148
+ ),
149
+ },
85
150
  ),
86
151
  members: createSQLRelationFilterCompiler(
87
- SQL.select().from(
88
- SQL.table('members')
89
- ).join(
90
- SQL.join(
91
- SQL.table('registrations')
92
- ).where(
93
- SQL.column('members', 'id'),
94
- SQL.column('registrations', 'memberId')
152
+ SQL.select()
153
+ .from(SQL.table('members'))
154
+ .join(
155
+ SQL.join(SQL.table('registrations')).where(
156
+ SQL.column('members', 'id'),
157
+ SQL.column('registrations', 'memberId'),
158
+ ),
95
159
  )
96
- ).where(
97
- SQL.column('registrations', 'organizationId'),
98
- SQL.column('organizations', 'id'),
99
- ),
160
+ .where(
161
+ SQL.column('registrations', 'organizationId'),
162
+ SQL.column('organizations', 'id'),
163
+ ),
100
164
 
101
165
  {
102
166
  ...baseSQLFilterCompilers,
@@ -105,11 +169,11 @@ export const organizationFilterCompilers: SQLFilterDefinitions = {
105
169
  SQL.column('firstName'),
106
170
  new SQLScalar(' '),
107
171
  SQL.column('lastName'),
108
- )
172
+ ),
109
173
  ),
110
- "firstName": createSQLColumnFilterCompiler('firstName'),
111
- "lastName": createSQLColumnFilterCompiler('lastName'),
112
- "email": createSQLColumnFilterCompiler('email')
113
- }
174
+ firstName: createSQLColumnFilterCompiler('firstName'),
175
+ lastName: createSQLColumnFilterCompiler('lastName'),
176
+ email: createSQLColumnFilterCompiler('email'),
177
+ },
114
178
  ),
115
- }
179
+ };
@@ -1,5 +1,5 @@
1
- import { SQL, SQLCast, SQLConcat, SQLFilterDefinitions, SQLJsonUnquote, SQLScalar, baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, createSQLFilterNamespace, createSQLRelationFilterCompiler } from "@stamhoofd/sql";
2
- import { balanceItemPaymentsCompilers } from "./balance-item-payments";
1
+ import { SQL, SQLCast, SQLConcat, SQLFilterDefinitions, SQLJsonUnquote, SQLScalar, SQLValueType, baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, createSQLFilterNamespace, createSQLRelationFilterCompiler } from '@stamhoofd/sql';
2
+ import { balanceItemPaymentsCompilers } from './balance-item-payments';
3
3
 
4
4
  /**
5
5
  * Defines how to filter members in the database from StamhoofdFilter objects
@@ -12,22 +12,22 @@ export const paymentFilterCompilers: SQLFilterDefinitions = {
12
12
  organizationId: createSQLColumnFilterCompiler('organizationId'),
13
13
  createdAt: createSQLColumnFilterCompiler('createdAt'),
14
14
  updatedAt: createSQLColumnFilterCompiler('updatedAt'),
15
- paidAt: createSQLColumnFilterCompiler('paidAt', {nullable: true}),
15
+ paidAt: createSQLColumnFilterCompiler('paidAt', { nullable: true }),
16
16
  price: createSQLColumnFilterCompiler('price'),
17
- provider: createSQLColumnFilterCompiler('provider', {nullable: true}),
17
+ provider: createSQLColumnFilterCompiler('provider', { nullable: true }),
18
18
  customer: createSQLFilterNamespace({
19
19
  ...baseSQLFilterCompilers,
20
20
  email: createSQLExpressionFilterCompiler(
21
21
  SQL.jsonValue(SQL.column('customer'), '$.value.email'),
22
- {isJSONValue: true}
22
+ { isJSONValue: true },
23
23
  ),
24
24
  firstName: createSQLExpressionFilterCompiler(
25
25
  SQL.jsonValue(SQL.column('customer'), '$.value.firstName'),
26
- {isJSONValue: true}
26
+ { isJSONValue: true, type: SQLValueType.JSONString },
27
27
  ),
28
28
  lastName: createSQLExpressionFilterCompiler(
29
29
  SQL.jsonValue(SQL.column('customer'), '$.value.lastName'),
30
- {isJSONValue: true}
30
+ { isJSONValue: true, type: SQLValueType.JSONString },
31
31
  ),
32
32
  name: createSQLExpressionFilterCompiler(
33
33
  new SQLCast(
@@ -36,43 +36,43 @@ export const paymentFilterCompilers: SQLFilterDefinitions = {
36
36
  new SQLScalar(' '),
37
37
  new SQLJsonUnquote(SQL.jsonValue(SQL.column('customer'), '$.value.lastName')),
38
38
  ),
39
- 'CHAR'
40
- )
39
+ 'CHAR',
40
+ ),
41
41
  ),
42
42
  company: createSQLFilterNamespace({
43
43
  name: createSQLExpressionFilterCompiler(
44
44
  SQL.jsonValue(SQL.column('customer'), '$.value.company.name'),
45
- {isJSONValue: true}
45
+ { isJSONValue: true, type: SQLValueType.JSONString },
46
46
  ),
47
47
  VATNumber: createSQLExpressionFilterCompiler(
48
48
  SQL.jsonValue(SQL.column('customer'), '$.value.company.VATNumber'),
49
- {isJSONValue: true}
49
+ { isJSONValue: true, type: SQLValueType.JSONString },
50
50
  ),
51
51
  companyNumber: createSQLExpressionFilterCompiler(
52
52
  SQL.jsonValue(SQL.column('customer'), '$.value.company.companyNumber'),
53
- {isJSONValue: true}
53
+ { isJSONValue: true, type: SQLValueType.JSONString },
54
54
  ),
55
55
  administrationEmail: createSQLExpressionFilterCompiler(
56
56
  SQL.jsonValue(SQL.column('customer'), '$.value.company.administrationEmail'),
57
- {isJSONValue: true}
57
+ { isJSONValue: true, type: SQLValueType.JSONString },
58
58
  ),
59
- })
59
+ }),
60
60
  }),
61
61
  balanceItemPayments: createSQLRelationFilterCompiler(
62
62
  SQL.select()
63
- .from(
64
- SQL.table('balance_item_payments')
65
- ).join(
66
- SQL.join(
67
- SQL.table('balance_items')
63
+ .from(
64
+ SQL.table('balance_item_payments'),
65
+ ).join(
66
+ SQL.join(
67
+ SQL.table('balance_items'),
68
+ ).where(
69
+ SQL.column('balance_items', 'id'),
70
+ SQL.column('balance_item_payments', 'balanceItemId'),
71
+ ),
68
72
  ).where(
69
- SQL.column('balance_items', 'id'),
70
- SQL.column('balance_item_payments', 'balanceItemId')
71
- )
72
- ).where(
73
- SQL.column('paymentId'),
74
- SQL.column('payments', 'id')
75
- ),
76
- balanceItemPaymentsCompilers
73
+ SQL.column('paymentId'),
74
+ SQL.column('payments', 'id'),
75
+ ),
76
+ balanceItemPaymentsCompilers,
77
77
  ),
78
- }
78
+ };