@stamhoofd/backend 2.91.0 → 2.93.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 (36) hide show
  1. package/package.json +10 -10
  2. package/src/audit-logs/EmailLogger.ts +6 -6
  3. package/src/crons/amazon-ses.ts +100 -4
  4. package/src/crons/balance-emails.ts +1 -1
  5. package/src/crons/endFunctionsOfUsersWithoutRegistration.ts +6 -0
  6. package/src/email-recipient-loaders/receivable-balances.ts +3 -1
  7. package/src/endpoints/global/email/CreateEmailEndpoint.ts +37 -7
  8. package/src/endpoints/global/email/GetAdminEmailsEndpoint.ts +205 -0
  9. package/src/endpoints/global/email/GetEmailEndpoint.ts +5 -1
  10. package/src/endpoints/global/email/PatchEmailEndpoint.test.ts +404 -8
  11. package/src/endpoints/global/email/PatchEmailEndpoint.ts +81 -26
  12. package/src/endpoints/global/email-recipients/GetEmailRecipientsCountEndpoint.ts +47 -0
  13. package/src/endpoints/global/email-recipients/GetEmailRecipientsEndpoint.test.ts +225 -0
  14. package/src/endpoints/global/email-recipients/GetEmailRecipientsEndpoint.ts +164 -0
  15. package/src/endpoints/global/email-recipients/helpers/validateEmailRecipientFilter.ts +64 -0
  16. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +5 -1
  17. package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +19 -1
  18. package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +10 -1
  19. package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +8 -1
  20. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +2 -67
  21. package/src/helpers/AdminPermissionChecker.ts +81 -5
  22. package/src/helpers/EmailResumer.ts +2 -2
  23. package/src/seeds/1752848560-groups-registration-periods.ts +768 -0
  24. package/src/seeds/1755532883-update-email-sender-ids.ts +47 -0
  25. package/src/seeds/1755790070-fill-email-recipient-errors.ts +96 -0
  26. package/src/seeds/1755876819-remove-duplicate-members.ts +145 -0
  27. package/src/seeds/1756115432-remove-old-drafts.ts +16 -0
  28. package/src/seeds/1756115433-fill-email-recipient-organization-id.ts +30 -0
  29. package/src/services/uitpas/UitpasService.ts +71 -2
  30. package/src/services/uitpas/checkUitpasNumbers.ts +1 -0
  31. package/src/sql-filters/email-recipients.ts +59 -0
  32. package/src/sql-filters/emails.ts +95 -0
  33. package/src/sql-filters/members.ts +42 -1
  34. package/src/sql-filters/registration-periods.ts +5 -0
  35. package/src/sql-sorters/email-recipients.ts +69 -0
  36. package/src/sql-sorters/emails.ts +47 -0
@@ -0,0 +1,69 @@
1
+ import { EmailRecipient } from '@stamhoofd/models';
2
+ import { SQL, SQLOrderBy, SQLOrderByDirection, SQLSortDefinitions } from '@stamhoofd/sql';
3
+ import { Formatter } from '@stamhoofd/utility';
4
+
5
+ export const emailRecipientSorters: SQLSortDefinitions<EmailRecipient> = {
6
+ // WARNING! TEST NEW SORTERS THOROUGHLY!
7
+ // Try to avoid creating sorters on fields that er not 1:1 with the database, that often causes pagination issues if not thought through
8
+ // An example: sorting on 'name' is not a good idea, because it is a concatenation of two fields.
9
+ // You might be tempted to use ORDER BY firstName, lastName, but that will not work as expected and it needs to be ORDER BY CONCAT(firstName, ' ', lastName)
10
+ // Why? Because ORDER BY firstName, lastName produces a different order dan ORDER BY CONCAT(firstName, ' ', lastName) if there are multiple people with spaces in the first name
11
+ // And that again causes issues with pagination because the next query will append a filter of name > 'John Doe' - causing duplicate and/or skipped results
12
+ // What if you need mapping? simply map the sorters in the frontend: name -> firstname, lastname, age -> birthDay, etc.
13
+
14
+ id: {
15
+ getValue(a) {
16
+ return a.id;
17
+ },
18
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
19
+ return new SQLOrderBy({
20
+ column: SQL.column('id'),
21
+ direction,
22
+ });
23
+ },
24
+ },
25
+ sentAt: {
26
+ getValue(a) {
27
+ return a.sentAt ? Formatter.dateTimeIso(a.sentAt, 'UTC') : null;
28
+ },
29
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
30
+ return new SQLOrderBy({
31
+ column: SQL.column('sentAt'),
32
+ direction,
33
+ });
34
+ },
35
+ },
36
+ email: {
37
+ getValue(a) {
38
+ return a.email;
39
+ },
40
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
41
+ return new SQLOrderBy({
42
+ column: SQL.column('email'),
43
+ direction,
44
+ });
45
+ },
46
+ },
47
+ firstName: {
48
+ getValue(a) {
49
+ return a.firstName;
50
+ },
51
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
52
+ return new SQLOrderBy({
53
+ column: SQL.column('firstName'),
54
+ direction,
55
+ });
56
+ },
57
+ },
58
+ lastName: {
59
+ getValue(a) {
60
+ return a.lastName;
61
+ },
62
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
63
+ return new SQLOrderBy({
64
+ column: SQL.column('lastName'),
65
+ direction,
66
+ });
67
+ },
68
+ },
69
+ };
@@ -0,0 +1,47 @@
1
+ import { Email } from '@stamhoofd/models';
2
+ import { SQL, SQLOrderBy, SQLOrderByDirection, SQLSortDefinitions } from '@stamhoofd/sql';
3
+ import { Formatter } from '@stamhoofd/utility';
4
+
5
+ export const emailSorters: SQLSortDefinitions<Email> = {
6
+ // WARNING! TEST NEW SORTERS THOROUGHLY!
7
+ // Try to avoid creating sorters on fields that er not 1:1 with the database, that often causes pagination issues if not thought through
8
+ // An example: sorting on 'name' is not a good idea, because it is a concatenation of two fields.
9
+ // You might be tempted to use ORDER BY firstName, lastName, but that will not work as expected and it needs to be ORDER BY CONCAT(firstName, ' ', lastName)
10
+ // Why? Because ORDER BY firstName, lastName produces a different order dan ORDER BY CONCAT(firstName, ' ', lastName) if there are multiple people with spaces in the first name
11
+ // And that again causes issues with pagination because the next query will append a filter of name > 'John Doe' - causing duplicate and/or skipped results
12
+ // What if you need mapping? simply map the sorters in the frontend: name -> firstname, lastname, age -> birthDay, etc.
13
+
14
+ id: {
15
+ getValue(a) {
16
+ return a.id;
17
+ },
18
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
19
+ return new SQLOrderBy({
20
+ column: SQL.column('id'),
21
+ direction,
22
+ });
23
+ },
24
+ },
25
+ createdAt: {
26
+ getValue(a) {
27
+ return Formatter.dateTimeIso(a.createdAt, 'UTC');
28
+ },
29
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
30
+ return new SQLOrderBy({
31
+ column: SQL.column('createdAt'),
32
+ direction,
33
+ });
34
+ },
35
+ },
36
+ sentAt: {
37
+ getValue(a) {
38
+ return a.sentAt ? Formatter.dateTimeIso(a.sentAt, 'UTC') : null;
39
+ },
40
+ toSQL: (direction: SQLOrderByDirection): SQLOrderBy => {
41
+ return new SQLOrderBy({
42
+ column: SQL.column('sentAt'),
43
+ direction,
44
+ });
45
+ },
46
+ },
47
+ };