@stamhoofd/backend 2.89.1 → 2.90.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 (66) hide show
  1. package/package.json +12 -11
  2. package/src/boot.ts +2 -0
  3. package/src/crons/balance-emails.ts +1 -6
  4. package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +1 -1
  5. package/src/endpoints/admin/organizations/SearchUitpasOrganizersEndpoint.ts +42 -0
  6. package/src/endpoints/global/audit-logs/GetAuditLogsEndpoint.ts +4 -4
  7. package/src/endpoints/global/events/GetEventNotificationsEndpoint.ts +3 -3
  8. package/src/endpoints/global/events/GetEventsEndpoint.ts +2 -2
  9. package/src/endpoints/global/events/PatchEventsEndpoint.ts +23 -2
  10. package/src/endpoints/global/groups/GetGroupsEndpoint.ts +6 -6
  11. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.test.ts +8 -6
  12. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +2 -2
  13. package/src/endpoints/global/platform/GetPlatformEndpoint.ts +1 -0
  14. package/src/endpoints/global/registration/PatchUserMembersEndpoint.test.ts +10 -8
  15. package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +11 -0
  16. package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +2 -2
  17. package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +3 -6
  18. package/src/endpoints/organization/dashboard/organization/GetUitpasClientIdEndpoint.ts +38 -0
  19. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +31 -1
  20. package/src/endpoints/organization/dashboard/organization/SetUitpasClientCredentialsEndpoint.ts +108 -0
  21. package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +1 -1
  22. package/src/endpoints/organization/dashboard/receivable-balances/GetReceivableBalancesEndpoint.ts +1 -2
  23. package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +1 -1
  24. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +9 -1
  25. package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +3 -2
  26. package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +1 -1
  27. package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +2 -9
  28. package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +1 -7
  29. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +68 -1
  30. package/src/endpoints/organization/webshops/RetrieveUitpasSocialTariffPriceEndpoint.ts +27 -20
  31. package/src/helpers/AdminPermissionChecker.ts +129 -22
  32. package/src/helpers/AuthenticatedStructures.ts +13 -10
  33. package/src/helpers/Context.ts +1 -1
  34. package/src/helpers/UitpasTokenRepository.ts +125 -35
  35. package/src/helpers/ViesHelper.ts +2 -1
  36. package/src/seeds/0000000002-clear-stamhoofd-email-templates.ts +13 -0
  37. package/src/seeds/0000000003-default-email-templates.ts +20 -0
  38. package/src/seeds/data/default-email-templates.sql +55 -0
  39. package/src/services/RegistrationService.ts +6 -4
  40. package/src/services/uitpas/UitpasService.test.ts +23 -0
  41. package/src/services/uitpas/UitpasService.ts +222 -0
  42. package/src/services/uitpas/checkPermissionsFor.ts +111 -0
  43. package/src/services/uitpas/checkUitpasNumbers.ts +180 -0
  44. package/src/services/uitpas/getSocialTariffForEvent.ts +90 -0
  45. package/src/services/uitpas/getSocialTariffForUitpasNumbers.ts +181 -0
  46. package/src/services/uitpas/searchUitpasOrganizers.ts +93 -0
  47. package/src/sql-filters/audit-logs.ts +26 -6
  48. package/src/sql-filters/balance-item-payments.ts +23 -8
  49. package/src/sql-filters/base-registration-filter-compilers.ts +74 -23
  50. package/src/sql-filters/documents.ts +46 -13
  51. package/src/sql-filters/event-notifications.ts +48 -12
  52. package/src/sql-filters/events.ts +62 -26
  53. package/src/sql-filters/groups.ts +12 -12
  54. package/src/sql-filters/members.ts +325 -137
  55. package/src/sql-filters/orders.ts +96 -48
  56. package/src/sql-filters/organization-registration-periods.ts +16 -4
  57. package/src/sql-filters/organizations.ts +105 -99
  58. package/src/sql-filters/payments.ts +97 -47
  59. package/src/sql-filters/receivable-balances.ts +56 -19
  60. package/src/sql-filters/registration-periods.ts +16 -4
  61. package/src/sql-filters/registrations.ts +2 -2
  62. package/src/sql-filters/shared/EmailRelationFilterCompilers.ts +14 -8
  63. package/src/sql-filters/tickets.ts +26 -6
  64. package/tests/e2e/charge-members.test.ts +1 -0
  65. package/src/helpers/UitpasNumberValidator.test.ts +0 -23
  66. package/src/helpers/UitpasNumberValidator.ts +0 -185
@@ -1,61 +1,109 @@
1
- import { baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, SQL, SQLCast, SQLConcat, SQLFilterDefinitions, SQLJsonUnquote, SQLScalar, SQLValueType } from '@stamhoofd/sql';
1
+ import { baseSQLFilterCompilers, createColumnFilter, SQL, SQLCast, SQLConcat, SQLJsonUnquote, SQLFilterDefinitions, SQLValueType, SQLScalar } from '@stamhoofd/sql';
2
2
 
3
3
  export const orderFilterCompilers: SQLFilterDefinitions = {
4
4
  ...baseSQLFilterCompilers,
5
5
  // only backend (not useful to filter on these in the frontend)
6
- organizationId: createSQLColumnFilterCompiler('organizationId'),
7
- updatedAt: createSQLColumnFilterCompiler('updatedAt'),
6
+ organizationId: createColumnFilter({
7
+ expression: SQL.column('organizationId'),
8
+ type: SQLValueType.String,
9
+ nullable: false,
10
+ }),
11
+ updatedAt: createColumnFilter({
12
+ expression: SQL.column('updatedAt'),
13
+ type: SQLValueType.Datetime,
14
+ nullable: false,
15
+ }),
8
16
 
9
17
  // frontend and backend
10
- webshopId: createSQLColumnFilterCompiler('webshopId'),
11
- id: createSQLColumnFilterCompiler('id'),
12
- timeSlotEndTime: createSQLExpressionFilterCompiler(
13
- SQL.jsonValue(SQL.column('data'), '$.value.timeSlot.endTime'),
14
- // todo: type?
15
- { isJSONValue: true, type: SQLValueType.JSONString },
16
- ),
17
- timeSlotStartTime: createSQLExpressionFilterCompiler(
18
- SQL.jsonValue(SQL.column('data'), '$.value.timeSlot.startTime'),
19
- // todo: type?
20
- { isJSONValue: true, type: SQLValueType.JSONString },
21
- ),
22
- createdAt: createSQLColumnFilterCompiler('createdAt'),
23
- number: createSQLColumnFilterCompiler('number'),
24
- status: createSQLColumnFilterCompiler('status'),
25
- paymentMethod: createSQLExpressionFilterCompiler(
26
- SQL.jsonValue(SQL.column('data'), '$.value.paymentMethod'),
27
- { isJSONValue: true, type: SQLValueType.JSONString },
28
- ),
29
- checkoutMethod: createSQLExpressionFilterCompiler(
30
- SQL.jsonValue(SQL.column('data'), '$.value.checkoutMethod.type'),
31
- { isJSONValue: true, type: SQLValueType.JSONString },
32
- ),
33
- timeSlotDate: createSQLExpressionFilterCompiler(
34
- SQL.jsonValue(SQL.column('data'), '$.value.timeSlot.date'),
35
- // todo: type?
36
- { isJSONValue: true, type: SQLValueType.JSONString },
37
- ),
38
- validAt: createSQLColumnFilterCompiler('validAt'),
39
- name: createSQLExpressionFilterCompiler(
40
- new SQLCast(
18
+ webshopId: createColumnFilter({
19
+ expression: SQL.column('webshopId'),
20
+ type: SQLValueType.String,
21
+ nullable: false,
22
+ }),
23
+ id: createColumnFilter({
24
+ expression: SQL.column('id'),
25
+ type: SQLValueType.String,
26
+ nullable: false,
27
+ }),
28
+ timeSlotEndTime: createColumnFilter({
29
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.timeSlot.endTime'),
30
+ type: SQLValueType.JSONString,
31
+ nullable: true,
32
+ }),
33
+ timeSlotStartTime: createColumnFilter({
34
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.timeSlot.startTime'),
35
+ type: SQLValueType.JSONString,
36
+ nullable: true,
37
+ }),
38
+ createdAt: createColumnFilter({
39
+ expression: SQL.column('createdAt'),
40
+ type: SQLValueType.Datetime,
41
+ nullable: false,
42
+ }),
43
+ number: createColumnFilter({
44
+ expression: SQL.column('number'),
45
+ type: SQLValueType.Number,
46
+ nullable: true,
47
+ }),
48
+ status: createColumnFilter({
49
+ expression: SQL.column('status'),
50
+ type: SQLValueType.String,
51
+ nullable: false,
52
+ }),
53
+ paymentMethod: createColumnFilter({
54
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.paymentMethod'),
55
+ type: SQLValueType.JSONString,
56
+ nullable: false,
57
+ }),
58
+ checkoutMethod: createColumnFilter({
59
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.checkoutMethod.type'),
60
+ type: SQLValueType.JSONString,
61
+ nullable: true,
62
+ }),
63
+ timeSlotDate: createColumnFilter({
64
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.timeSlot.date'),
65
+ type: SQLValueType.JSONString,
66
+ nullable: true,
67
+ }),
68
+ validAt: createColumnFilter({
69
+ expression: SQL.column('validAt'),
70
+ type: SQLValueType.Datetime,
71
+ nullable: true,
72
+ }),
73
+ name: createColumnFilter({
74
+ expression: new SQLCast(
41
75
  new SQLConcat(
42
76
  new SQLJsonUnquote(SQL.jsonValue(SQL.column('data'), '$.value.customer.firstName')),
43
77
  new SQLScalar(' '),
44
78
  new SQLJsonUnquote(SQL.jsonValue(SQL.column('data'), '$.value.customer.lastName')),
45
79
  ),
46
80
  'CHAR'),
47
- ),
48
- email: createSQLExpressionFilterCompiler(
49
- SQL.jsonValue(SQL.column('data'), '$.value.customer.email'),
50
- // todo: type?
51
- { isJSONValue: true, type: SQLValueType.JSONString },
52
- ),
53
- phone: createSQLExpressionFilterCompiler(
54
- SQL.jsonValue(SQL.column('data'), '$.value.customer.phone'),
55
- // todo: type?
56
- { isJSONValue: true, type: SQLValueType.JSONString },
57
- ),
58
- totalPrice: createSQLColumnFilterCompiler('totalPrice'),
59
- amount: createSQLColumnFilterCompiler('amount'),
60
- timeSlotTime: createSQLColumnFilterCompiler('timeSlotTime'),
81
+ type: SQLValueType.String,
82
+ nullable: false,
83
+ }),
84
+ email: createColumnFilter({
85
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.customer.email'),
86
+ type: SQLValueType.JSONString,
87
+ nullable: false,
88
+ }),
89
+ phone: createColumnFilter({
90
+ expression: SQL.jsonValue(SQL.column('data'), '$.value.customer.phone'),
91
+ type: SQLValueType.JSONString,
92
+ nullable: false,
93
+ }),
94
+ totalPrice: createColumnFilter({
95
+ expression: SQL.column('totalPrice'),
96
+ type: SQLValueType.Number,
97
+ nullable: false,
98
+ }),
99
+ amount: createColumnFilter({
100
+ expression: SQL.column('amount'),
101
+ type: SQLValueType.Number,
102
+ nullable: false,
103
+ }),
104
+ timeSlotTime: createColumnFilter({
105
+ expression: SQL.column('timeSlotTime'),
106
+ type: SQLValueType.Datetime,
107
+ nullable: true,
108
+ }),
61
109
  };
@@ -1,8 +1,20 @@
1
- import { SQLFilterDefinitions, baseSQLFilterCompilers, createSQLColumnFilterCompiler } from '@stamhoofd/sql';
1
+ import { baseSQLFilterCompilers, createColumnFilter, SQL, SQLFilterDefinitions, SQLValueType } from '@stamhoofd/sql';
2
2
 
3
3
  export const organizationRegistrationPeriodFilterCompilers: SQLFilterDefinitions = {
4
4
  ...baseSQLFilterCompilers,
5
- id: createSQLColumnFilterCompiler('id'),
6
- organizationId: createSQLColumnFilterCompiler('organizationId'),
7
- periodId: createSQLColumnFilterCompiler('periodId'),
5
+ id: createColumnFilter({
6
+ expression: SQL.column('id'),
7
+ type: SQLValueType.String,
8
+ nullable: false,
9
+ }),
10
+ organizationId: createColumnFilter({
11
+ expression: SQL.column('organizationId'),
12
+ type: SQLValueType.String,
13
+ nullable: false,
14
+ }),
15
+ periodId: createColumnFilter({
16
+ expression: SQL.column('periodId'),
17
+ type: SQLValueType.String,
18
+ nullable: false,
19
+ }),
8
20
  };
@@ -1,112 +1,107 @@
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';
1
+ import { baseSQLFilterCompilers, createColumnFilter, createExistsFilter, SQL, SQLConcat, SQLFilterDefinitions, SQLValueType, SQLNow, SQLNull, SQLScalar, SQLWhereEqual, SQLWhereOr, SQLWhereSign } from '@stamhoofd/sql';
20
2
  import { SetupStepType } from '@stamhoofd/structures';
21
3
 
22
4
  export const organizationFilterCompilers: SQLFilterDefinitions = {
23
5
  ...baseSQLFilterCompilers,
24
- id: createSQLExpressionFilterCompiler(SQL.column('organizations', 'id')),
25
- uriPadded: createSQLExpressionFilterCompiler(SQL.lpad(SQL.column('organizations', 'uri'), 10, '0')),
26
- uri: createSQLExpressionFilterCompiler(SQL.column('organizations', 'uri')),
27
- name: createSQLExpressionFilterCompiler(
28
- SQL.column('organizations', 'name'),
29
- ),
30
- active: createSQLExpressionFilterCompiler(
31
- SQL.column('organizations', 'active'),
32
- ),
33
- city: createSQLExpressionFilterCompiler(
34
- SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.city'),
35
- { isJSONValue: true, type: SQLValueType.JSONString },
36
- ),
37
- postalCode: createSQLExpressionFilterCompiler(
38
- SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.postalCode'),
39
- { isJSONValue: true, type: SQLValueType.JSONString },
40
- ),
41
- country: createSQLExpressionFilterCompiler(
42
- SQL.jsonValue(
43
- SQL.column('organizations', 'address'),
44
- '$.value.country',
45
- ),
46
- { isJSONValue: true, type: SQLValueType.JSONString },
47
- ),
48
- umbrellaOrganization: createSQLExpressionFilterCompiler(
49
- SQL.jsonValue(
50
- SQL.column('organizations', 'meta'),
51
- '$.value.umbrellaOrganization',
52
- ),
53
- { isJSONValue: true },
54
- ),
55
- type: createSQLExpressionFilterCompiler(
56
- SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.type'),
57
- { isJSONValue: true },
58
- ),
59
- tags: createSQLExpressionFilterCompiler(
60
- SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.tags'),
61
- { isJSONValue: true, isJSONObject: true },
62
- ),
63
- setupSteps: createSQLRelationFilterCompiler(
6
+ id: createColumnFilter({
7
+ expression: SQL.column('organizations', 'id'),
8
+ type: SQLValueType.String,
9
+ nullable: false,
10
+ }),
11
+ uriPadded: createColumnFilter({
12
+ expression: SQL.lpad(SQL.column('organizations', 'uri'), 10, '0'),
13
+ type: SQLValueType.String,
14
+ nullable: false,
15
+ }),
16
+ uri: createColumnFilter({
17
+ expression: SQL.column('organizations', 'uri'),
18
+ type: SQLValueType.String,
19
+ nullable: false,
20
+ }),
21
+ name: createColumnFilter({
22
+ expression: SQL.column('organizations', 'name'),
23
+ type: SQLValueType.String,
24
+ nullable: false,
25
+ }),
26
+ active: createColumnFilter({
27
+ expression: SQL.column('organizations', 'active'),
28
+ type: SQLValueType.Boolean,
29
+ nullable: false,
30
+ }),
31
+ city: createColumnFilter({
32
+ expression: SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.city'),
33
+ type: SQLValueType.JSONString,
34
+ nullable: false,
35
+ }),
36
+ postalCode: createColumnFilter({
37
+ expression: SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.postalCode'),
38
+ type: SQLValueType.JSONString,
39
+ nullable: false,
40
+ }),
41
+ country: createColumnFilter({
42
+ expression: SQL.jsonValue(SQL.column('organizations', 'address'), '$.value.country'),
43
+ type: SQLValueType.JSONString,
44
+ nullable: false,
45
+ }),
46
+ umbrellaOrganization: createColumnFilter({
47
+ expression: SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.umbrellaOrganization'),
48
+ type: SQLValueType.JSONString,
49
+ nullable: true,
50
+ }),
51
+ type: createColumnFilter({
52
+ expression: SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.type'),
53
+ type: SQLValueType.JSONString,
54
+ nullable: false,
55
+ }),
56
+ tags: createColumnFilter({
57
+ expression: SQL.jsonValue(SQL.column('organizations', 'meta'), '$.value.tags'),
58
+ type: SQLValueType.JSONArray,
59
+ nullable: false,
60
+ }),
61
+ setupSteps: createExistsFilter(
64
62
  SQL.select()
65
63
  .from(SQL.table('organization_registration_periods'))
66
64
  .where(
67
- SQL.column(
68
- 'organization_registration_periods',
69
- 'organizationId',
70
- ),
65
+ SQL.column('organization_registration_periods', 'organizationId'),
71
66
  SQL.column('organizations', 'id'),
72
67
  ),
73
68
  {
74
69
  ...baseSQLFilterCompilers,
75
- periodId: createSQLColumnFilterCompiler(
76
- SQL.column('organization_registration_periods', 'periodId'),
77
- ),
70
+ periodId: createColumnFilter({
71
+ expression: SQL.column('organization_registration_periods', 'periodId'),
72
+ type: SQLValueType.String,
73
+ nullable: false,
74
+ }),
78
75
  ...Object.fromEntries(
79
76
  Object.values(SetupStepType)
80
77
  .map((setupStep) => {
81
78
  return [
82
79
  setupStep,
83
- createSQLFilterNamespace({
84
- reviewedAt: createSQLExpressionFilterCompiler(
85
- SQL.jsonValue(
86
- SQL.column(
87
- 'organization_registration_periods',
88
- 'setupSteps',
89
- ),
80
+ {
81
+ ...baseSQLFilterCompilers,
82
+ reviewedAt: createColumnFilter({
83
+ expression: SQL.jsonValue(
84
+ SQL.column('organization_registration_periods', 'setupSteps'),
90
85
  `$.value.steps.${setupStep}.review.date`,
91
86
  ),
92
- { isJSONValue: true, isJSONObject: false },
93
- ),
94
- complete: createSQLExpressionFilterCompiler(
95
- {
96
- getSQL: (
97
- _options?: SQLExpressionOptions,
98
- ): SQLQuery =>
87
+ type: SQLValueType.JSONString,
88
+ nullable: true,
89
+ }),
90
+ complete: createColumnFilter({
91
+ expression: {
92
+ getSQL: () =>
99
93
  `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`,
100
94
  },
101
- { isJSONValue: false, isJSONObject: false },
102
- ),
103
- }),
95
+ type: SQLValueType.Boolean,
96
+ nullable: false,
97
+ }),
98
+ },
104
99
  ];
105
100
  }),
106
101
  ),
107
102
  },
108
103
  ),
109
- packages: createSQLRelationFilterCompiler(
104
+ packages: createExistsFilter(
110
105
  SQL.select()
111
106
  .from(SQL.table('stamhoofd_packages'))
112
107
  .where(
@@ -142,18 +137,16 @@ export const organizationFilterCompilers: SQLFilterDefinitions = {
142
137
  ),
143
138
  ]),
144
139
  ),
145
-
146
- // const pack1 = await STPackage.where({ organizationId, validAt: { sign: "!=", value: null }, removeAt: { sign: ">", value: new Date() }})
147
- // const pack2 = await STPackage.where({ organizationId, validAt: { sign: "!=", value: null }, removeAt: null })
148
140
  {
149
141
  ...baseSQLFilterCompilers,
150
- type: createSQLExpressionFilterCompiler(
151
- SQL.jsonValue(SQL.column('meta'), '$.value.type'),
152
- { isJSONValue: true },
153
- ),
142
+ type: createColumnFilter({
143
+ expression: SQL.jsonValue(SQL.column('meta'), '$.value.type'),
144
+ type: SQLValueType.JSONString,
145
+ nullable: false,
146
+ }),
154
147
  },
155
148
  ),
156
- members: createSQLRelationFilterCompiler(
149
+ members: createExistsFilter(
157
150
  SQL.select()
158
151
  .from(SQL.table('members'))
159
152
  .join(
@@ -166,19 +159,32 @@ export const organizationFilterCompilers: SQLFilterDefinitions = {
166
159
  SQL.column('registrations', 'organizationId'),
167
160
  SQL.column('organizations', 'id'),
168
161
  ),
169
-
170
162
  {
171
163
  ...baseSQLFilterCompilers,
172
- name: createSQLExpressionFilterCompiler(
173
- new SQLConcat(
164
+ name: createColumnFilter({
165
+ expression: new SQLConcat(
174
166
  SQL.column('firstName'),
175
167
  new SQLScalar(' '),
176
168
  SQL.column('lastName'),
177
169
  ),
178
- ),
179
- firstName: createSQLColumnFilterCompiler('firstName'),
180
- lastName: createSQLColumnFilterCompiler('lastName'),
181
- email: createSQLColumnFilterCompiler('email'),
170
+ type: SQLValueType.String,
171
+ nullable: false,
172
+ }),
173
+ firstName: createColumnFilter({
174
+ expression: SQL.column('firstName'),
175
+ type: SQLValueType.String,
176
+ nullable: false,
177
+ }),
178
+ lastName: createColumnFilter({
179
+ expression: SQL.column('lastName'),
180
+ type: SQLValueType.String,
181
+ nullable: false,
182
+ }),
183
+ email: createColumnFilter({
184
+ expression: SQL.jsonValue(SQL.column('details'), '$.value.email'),
185
+ type: SQLValueType.JSONString,
186
+ nullable: true,
187
+ }),
182
188
  },
183
189
  ),
184
190
  };
@@ -1,37 +1,80 @@
1
- import { SQL, SQLCast, SQLConcat, SQLFilterDefinitions, SQLJsonUnquote, SQLScalar, SQLValueType, baseSQLFilterCompilers, createSQLColumnFilterCompiler, createSQLExpressionFilterCompiler, createSQLFilterNamespace, createSQLRelationFilterCompiler } from '@stamhoofd/sql';
1
+ import { baseSQLFilterCompilers, createColumnFilter, createExistsFilter, SQL, SQLCast, SQLConcat, SQLJsonUnquote, SQLFilterDefinitions, SQLValueType, SQLScalar } from '@stamhoofd/sql';
2
2
  import { balanceItemPaymentsCompilers } from './balance-item-payments';
3
3
 
4
4
  /**
5
- * Defines how to filter members in the database from StamhoofdFilter objects
5
+ * Defines how to filter payments in the database from StamhoofdFilter objects
6
6
  */
7
7
  export const paymentFilterCompilers: SQLFilterDefinitions = {
8
8
  ...baseSQLFilterCompilers,
9
- id: createSQLColumnFilterCompiler('id'),
10
- method: createSQLColumnFilterCompiler('method'),
11
- status: createSQLColumnFilterCompiler('status'),
12
- organizationId: createSQLColumnFilterCompiler('organizationId'),
13
- createdAt: createSQLColumnFilterCompiler('createdAt'),
14
- updatedAt: createSQLColumnFilterCompiler('updatedAt'),
15
- paidAt: createSQLColumnFilterCompiler('paidAt', { nullable: true }),
16
- price: createSQLColumnFilterCompiler('price'),
17
- provider: createSQLColumnFilterCompiler('provider', { nullable: true }),
18
- transferDescription: createSQLColumnFilterCompiler('transferDescription', { nullable: true }),
19
- customer: createSQLFilterNamespace({
9
+ id: createColumnFilter({
10
+ expression: SQL.column('id'),
11
+ type: SQLValueType.String,
12
+ nullable: false,
13
+ }),
14
+ method: createColumnFilter({
15
+ expression: SQL.column('method'),
16
+ type: SQLValueType.String,
17
+ nullable: false,
18
+ }),
19
+ status: createColumnFilter({
20
+ expression: SQL.column('status'),
21
+ type: SQLValueType.String,
22
+ nullable: false,
23
+ }),
24
+ organizationId: createColumnFilter({
25
+ expression: SQL.column('organizationId'),
26
+ type: SQLValueType.String,
27
+ nullable: true,
28
+ }),
29
+ createdAt: createColumnFilter({
30
+ expression: SQL.column('createdAt'),
31
+ type: SQLValueType.Datetime,
32
+ nullable: false,
33
+ }),
34
+ updatedAt: createColumnFilter({
35
+ expression: SQL.column('updatedAt'),
36
+ type: SQLValueType.Datetime,
37
+ nullable: false,
38
+ }),
39
+ paidAt: createColumnFilter({
40
+ expression: SQL.column('paidAt'),
41
+ type: SQLValueType.Datetime,
42
+ nullable: true,
43
+ }),
44
+ price: createColumnFilter({
45
+ expression: SQL.column('price'),
46
+ type: SQLValueType.Number,
47
+ nullable: false,
48
+ }),
49
+ provider: createColumnFilter({
50
+ expression: SQL.column('provider'),
51
+ type: SQLValueType.String,
52
+ nullable: true,
53
+ }),
54
+ transferDescription: createColumnFilter({
55
+ expression: SQL.column('transferDescription'),
56
+ type: SQLValueType.String,
57
+ nullable: true,
58
+ }),
59
+ customer: {
20
60
  ...baseSQLFilterCompilers,
21
- email: createSQLExpressionFilterCompiler(
22
- SQL.jsonValue(SQL.column('customer'), '$.value.email'),
23
- { isJSONValue: true },
24
- ),
25
- firstName: createSQLExpressionFilterCompiler(
26
- SQL.jsonValue(SQL.column('customer'), '$.value.firstName'),
27
- { isJSONValue: true, type: SQLValueType.JSONString },
28
- ),
29
- lastName: createSQLExpressionFilterCompiler(
30
- SQL.jsonValue(SQL.column('customer'), '$.value.lastName'),
31
- { isJSONValue: true, type: SQLValueType.JSONString },
32
- ),
33
- name: createSQLExpressionFilterCompiler(
34
- new SQLCast(
61
+ email: createColumnFilter({
62
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.email'),
63
+ type: SQLValueType.JSONString,
64
+ nullable: true,
65
+ }),
66
+ firstName: createColumnFilter({
67
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.firstName'),
68
+ type: SQLValueType.JSONString,
69
+ nullable: true,
70
+ }),
71
+ lastName: createColumnFilter({
72
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.lastName'),
73
+ type: SQLValueType.JSONString,
74
+ nullable: true,
75
+ }),
76
+ name: createColumnFilter({
77
+ expression: new SQLCast(
35
78
  new SQLConcat(
36
79
  new SQLJsonUnquote(SQL.jsonValue(SQL.column('customer'), '$.value.firstName')),
37
80
  new SQLScalar(' '),
@@ -39,27 +82,34 @@ export const paymentFilterCompilers: SQLFilterDefinitions = {
39
82
  ),
40
83
  'CHAR',
41
84
  ),
42
- ),
43
- company: createSQLFilterNamespace({
44
- name: createSQLExpressionFilterCompiler(
45
- SQL.jsonValue(SQL.column('customer'), '$.value.company.name'),
46
- { isJSONValue: true, type: SQLValueType.JSONString },
47
- ),
48
- VATNumber: createSQLExpressionFilterCompiler(
49
- SQL.jsonValue(SQL.column('customer'), '$.value.company.VATNumber'),
50
- { isJSONValue: true, type: SQLValueType.JSONString },
51
- ),
52
- companyNumber: createSQLExpressionFilterCompiler(
53
- SQL.jsonValue(SQL.column('customer'), '$.value.company.companyNumber'),
54
- { isJSONValue: true, type: SQLValueType.JSONString },
55
- ),
56
- administrationEmail: createSQLExpressionFilterCompiler(
57
- SQL.jsonValue(SQL.column('customer'), '$.value.company.administrationEmail'),
58
- { isJSONValue: true, type: SQLValueType.JSONString },
59
- ),
85
+ type: SQLValueType.String,
86
+ nullable: true,
60
87
  }),
61
- }),
62
- balanceItemPayments: createSQLRelationFilterCompiler(
88
+ company: {
89
+ ...baseSQLFilterCompilers,
90
+ name: createColumnFilter({
91
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.company.name'),
92
+ type: SQLValueType.JSONString,
93
+ nullable: true,
94
+ }),
95
+ VATNumber: createColumnFilter({
96
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.company.VATNumber'),
97
+ type: SQLValueType.JSONString,
98
+ nullable: true,
99
+ }),
100
+ companyNumber: createColumnFilter({
101
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.company.companyNumber'),
102
+ type: SQLValueType.JSONString,
103
+ nullable: true,
104
+ }),
105
+ administrationEmail: createColumnFilter({
106
+ expression: SQL.jsonValue(SQL.column('customer'), '$.value.company.administrationEmail'),
107
+ type: SQLValueType.JSONString,
108
+ nullable: true,
109
+ }),
110
+ },
111
+ },
112
+ balanceItemPayments: createExistsFilter(
63
113
  SQL.select()
64
114
  .from(
65
115
  SQL.table('balance_item_payments'),