@stamhoofd/backend 2.99.1 → 2.100.1

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 (25) hide show
  1. package/package.json +10 -10
  2. package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +1 -1
  3. package/src/endpoints/global/events/PatchEventNotificationsEndpoint.test.ts +7 -1
  4. package/src/endpoints/global/events/PatchEventNotificationsEndpoint.ts +2 -2
  5. package/src/endpoints/global/events/PatchEventsEndpoint.test.ts +267 -0
  6. package/src/endpoints/global/events/PatchEventsEndpoint.ts +4 -4
  7. package/src/endpoints/global/members/GetMembersEndpoint.ts +1 -1
  8. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +1 -1
  9. package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +5 -2
  10. package/src/endpoints/global/platform/PatchPlatformEnpoint.test.ts +63 -0
  11. package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +1 -1
  12. package/src/endpoints/global/registration/GetRegistrationsEndpoint.ts +1 -1
  13. package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +4 -3
  14. package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +2 -2
  15. package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +10 -3
  16. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +67 -2
  17. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +41 -29
  18. package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.test.ts +32 -8
  19. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.test.ts +206 -0
  20. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +35 -1
  21. package/src/helpers/AuthenticatedStructures.ts +1 -1
  22. package/src/helpers/FlagMomentCleanup.ts +105 -52
  23. package/src/helpers/PeriodHelper.ts +85 -2
  24. package/src/sql-filters/registration-periods.ts +1 -1
  25. package/tests/jest.setup.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stamhoofd/backend",
3
- "version": "2.99.1",
3
+ "version": "2.100.1",
4
4
  "main": "./dist/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -45,14 +45,14 @@
45
45
  "@simonbackx/simple-encoding": "2.22.0",
46
46
  "@simonbackx/simple-endpoints": "1.20.1",
47
47
  "@simonbackx/simple-logging": "^1.0.1",
48
- "@stamhoofd/backend-i18n": "2.99.1",
49
- "@stamhoofd/backend-middleware": "2.99.1",
50
- "@stamhoofd/email": "2.99.1",
51
- "@stamhoofd/models": "2.99.1",
52
- "@stamhoofd/queues": "2.99.1",
53
- "@stamhoofd/sql": "2.99.1",
54
- "@stamhoofd/structures": "2.99.1",
55
- "@stamhoofd/utility": "2.99.1",
48
+ "@stamhoofd/backend-i18n": "2.100.1",
49
+ "@stamhoofd/backend-middleware": "2.100.1",
50
+ "@stamhoofd/email": "2.100.1",
51
+ "@stamhoofd/models": "2.100.1",
52
+ "@stamhoofd/queues": "2.100.1",
53
+ "@stamhoofd/sql": "2.100.1",
54
+ "@stamhoofd/structures": "2.100.1",
55
+ "@stamhoofd/utility": "2.100.1",
56
56
  "archiver": "^7.0.1",
57
57
  "axios": "^1.8.2",
58
58
  "cookie": "^0.7.0",
@@ -70,5 +70,5 @@
70
70
  "publishConfig": {
71
71
  "access": "public"
72
72
  },
73
- "gitHead": "92d884776091f7182f8699725b7a7b5b8dcf41e7"
73
+ "gitHead": "989981a387ceddd505dc757d2e0a3dacd492b733"
74
74
  }
@@ -126,7 +126,7 @@ export class PatchOrganizationsEndpoint extends Endpoint<Params, Query, Body, Re
126
126
  organization.meta = put.meta;
127
127
  organization.address = put.address;
128
128
 
129
- const periodId = (await Platform.getShared()).periodId;
129
+ const periodId = (await Platform.getShared()).periodIdIfPlatform;
130
130
  organization.periodId = periodId;
131
131
 
132
132
  if (put.privateMeta) {
@@ -84,12 +84,18 @@ describe('Endpoint.PatchEventNotificationsEndpoint', () => {
84
84
  });
85
85
 
86
86
  test('A normal user can create new event notifications for an event', async () => {
87
+ const startDate = new Date(2024, 8, 1, 0, 0, 0, 0);
88
+ const endDate = new Date(2025, 7, 31, 0, 0, 0, 0);
89
+ const registrationPeriod = await new RegistrationPeriodFactory({ startDate, endDate }).create();
87
90
  const organization = await new OrganizationFactory({}).create();
91
+ registrationPeriod.organizationId = organization.id;
92
+ await registrationPeriod.save();
93
+
88
94
  const user = await new UserFactory({
89
95
  organization,
90
96
  permissions: minimumUserPermissions,
91
97
  }).create();
92
- const event = await new EventFactory({ organization }).create();
98
+ const event = await new EventFactory({ organization, startDate, endDate }).create();
93
99
  const recordCategories = await new RecordCategoryFactory({
94
100
  records: [
95
101
  {
@@ -1,6 +1,6 @@
1
1
  import { AutoEncoderPatchType, Decoder, PatchableArrayAutoEncoder, PatchableArrayDecoder, patchObject, StringDecoder } from '@simonbackx/simple-encoding';
2
2
  import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
3
- import { Event, EventNotification, RegistrationPeriod, Platform } from '@stamhoofd/models';
3
+ import { Event, EventNotification, Platform, RegistrationPeriod } from '@stamhoofd/models';
4
4
  import { EmailTemplateType, EventNotificationStatus, EventNotification as EventNotificationStruct, PermissionLevel, RecordCategory } from '@stamhoofd/structures';
5
5
 
6
6
  import { isSimpleError, isSimpleErrors, SimpleError } from '@simonbackx/simple-errors';
@@ -81,7 +81,7 @@ export class PatchEventNotificationsEndpoint extends Endpoint<Params, Query, Bod
81
81
  if (index === 0) {
82
82
  notification.startDate = model.startDate;
83
83
  notification.endDate = model.endDate;
84
- const period = await RegistrationPeriod.getByDate(model.startDate);
84
+ const period = await RegistrationPeriod.getByDate(model.startDate, organization?.id ?? null);
85
85
 
86
86
  if (!period) {
87
87
  throw new SimpleError({
@@ -0,0 +1,267 @@
1
+ import { PatchableArray } from '@simonbackx/simple-encoding';
2
+ import { Endpoint, Request } from '@simonbackx/simple-endpoints';
3
+ import { EventFactory, Organization, OrganizationFactory, PlatformEventTypeFactory, RegistrationPeriodFactory, Token, User, UserFactory } from '@stamhoofd/models';
4
+ import { AccessRight, Event, Permissions, PermissionsResourceType, ResourcePermissions } from '@stamhoofd/structures';
5
+ import { STExpect, TestUtils } from '@stamhoofd/test-utils';
6
+ import { testServer } from '../../../../tests/helpers/TestServer';
7
+ import { PatchEventsEndpoint } from './PatchEventsEndpoint';
8
+
9
+ const baseUrl = `/events`;
10
+ const endpoint = new PatchEventsEndpoint();
11
+ type EndpointType = typeof endpoint;
12
+ type Body = EndpointType extends Endpoint<any, any, infer B, any> ? B : never;
13
+
14
+ const minimumUserPermissions = Permissions.create({
15
+ resources: new Map([
16
+ [PermissionsResourceType.Groups, new Map([
17
+ ['', ResourcePermissions.create({
18
+ accessRights: [AccessRight.EventWrite],
19
+ })],
20
+ ])],
21
+ ]),
22
+ });
23
+
24
+ const TestRequest = {
25
+ async patch(options: {
26
+ body?: Body;
27
+ user?: User;
28
+ organization?: Organization;
29
+ }) {
30
+ const request = Request.buildJson('PATCH', baseUrl, options.organization?.getApiHost(), options.body);
31
+ if (options.user) {
32
+ const token = await Token.createToken(options.user);
33
+ request.headers.authorization = 'Bearer ' + token.accessToken;
34
+ }
35
+ return await testServer.test(endpoint, request);
36
+ },
37
+ };
38
+
39
+ describe('Endpoint.PatchEventsEndpoint', () => {
40
+ let admin: User;
41
+
42
+ beforeAll(async () => {
43
+ TestUtils.setEnvironment('userMode', 'platform');
44
+
45
+ admin = await new UserFactory({
46
+ globalPermissions: Permissions.create({
47
+ resources: new Map([
48
+ [PermissionsResourceType.OrganizationTags, new Map([
49
+ ['', ResourcePermissions.create({
50
+ accessRights: [
51
+ AccessRight.EventWrite,
52
+ ],
53
+ })],
54
+ ])],
55
+ ]),
56
+ }),
57
+ }).create();
58
+ });
59
+
60
+ test('A normal user with write access can create an event', async () => {
61
+ const organization = await new OrganizationFactory({}).create();
62
+ const user = await new UserFactory({
63
+ organization,
64
+ permissions: minimumUserPermissions,
65
+ }).create();
66
+
67
+ const body: Body = new PatchableArray();
68
+ const newEvent = Event.create({
69
+ organizationId: organization.id,
70
+ typeId: (await new PlatformEventTypeFactory({}).create()).id,
71
+ name: 'test event',
72
+ startDate: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000),
73
+ endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
74
+ });
75
+ body.addPut(newEvent);
76
+
77
+ const result = await TestRequest.patch({ body, user, organization });
78
+ expect(result.status).toBe(200);
79
+ expect(result.body).toHaveLength(1);
80
+ expect(result.body[0]).toMatchObject({
81
+ organizationId: newEvent.organizationId,
82
+ typeId: newEvent.typeId,
83
+ name: newEvent.name,
84
+ });
85
+ });
86
+
87
+ test('A normal user with write access cannot create a global event', async () => {
88
+ const organization = await new OrganizationFactory({}).create();
89
+ const user = await new UserFactory({
90
+ organization,
91
+ permissions: minimumUserPermissions,
92
+ }).create();
93
+
94
+ const body: Body = new PatchableArray();
95
+ const newEvent = Event.create({
96
+ organizationId: null,
97
+ typeId: (await new PlatformEventTypeFactory({}).create()).id,
98
+ name: 'test event',
99
+ startDate: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000),
100
+ endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
101
+ });
102
+ body.addPut(newEvent);
103
+
104
+ await expect(TestRequest.patch({ body, user, organization })).rejects.toThrow(
105
+ STExpect.simpleError({ code: 'permission_denied' }),
106
+ );
107
+ });
108
+
109
+ test('A normal user with write access cannot make an event global', async () => {
110
+ const organization = await new OrganizationFactory({}).create();
111
+
112
+ const user = await new UserFactory({
113
+ organization,
114
+ permissions: minimumUserPermissions,
115
+ }).create();
116
+
117
+ const startDate = new Date(Date.now() + 5 * 24 * 60 * 60 * 1000);
118
+ const endDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
119
+
120
+ const body: Body = new PatchableArray();
121
+
122
+ const eventToPatch = await new EventFactory({
123
+ organization,
124
+ typeId: (await new PlatformEventTypeFactory({
125
+ maximum: 5,
126
+ }).create()).id,
127
+ name: 'test event',
128
+ startDate,
129
+ endDate,
130
+
131
+ }).create();
132
+
133
+ body.addPatch(Event.patch({
134
+ id: eventToPatch.id,
135
+ organizationId: null,
136
+ }));
137
+
138
+ await expect(TestRequest.patch({ body, user, organization })).rejects.toThrow(
139
+ STExpect.simpleError({ code: 'permission_denied' }),
140
+ );
141
+ });
142
+
143
+ test('An admin can create a global event', async () => {
144
+ const organization = await new OrganizationFactory({}).create();
145
+
146
+ const body: Body = new PatchableArray();
147
+ const newEvent = Event.create({
148
+ organizationId: null,
149
+ typeId: (await new PlatformEventTypeFactory({}).create()).id,
150
+ name: 'test event',
151
+ startDate: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000),
152
+ endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
153
+ });
154
+ body.addPut(newEvent);
155
+
156
+ const result = await TestRequest.patch({ body, user: admin, organization });
157
+ expect(result.status).toBe(200);
158
+ expect(result.body).toHaveLength(1);
159
+ expect(result.body[0]).toMatchObject({
160
+ organizationId: newEvent.organizationId,
161
+ typeId: newEvent.typeId,
162
+ name: newEvent.name,
163
+ });
164
+ });
165
+
166
+ describe('userMode organization', () => {
167
+ beforeEach(async () => {
168
+ TestUtils.setEnvironment('userMode', 'organization');
169
+ });
170
+
171
+ test('A normal user with write access can create an event where the type has a maximum', async () => {
172
+ const organization = await new OrganizationFactory({}).create();
173
+
174
+ const user = await new UserFactory({
175
+ organization,
176
+ permissions: minimumUserPermissions,
177
+ }).create();
178
+
179
+ const startDate = new Date(Date.now() + 5 * 24 * 60 * 60 * 1000);
180
+ const endDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
181
+
182
+ // create registration period
183
+ await new RegistrationPeriodFactory({
184
+ startDate,
185
+ endDate,
186
+ organization,
187
+ }).create();
188
+
189
+ const body: Body = new PatchableArray();
190
+ const newEvent = Event.create({
191
+ organizationId: organization.id,
192
+ typeId: (await new PlatformEventTypeFactory({
193
+ maximum: 5,
194
+ }).create()).id,
195
+ name: 'test event',
196
+ startDate,
197
+ endDate,
198
+ });
199
+ body.addPut(newEvent);
200
+
201
+ const result = await TestRequest.patch({ body, user, organization });
202
+ expect(result.status).toBe(200);
203
+ expect(result.body).toHaveLength(1);
204
+ expect(result.body[0]).toMatchObject({
205
+ organizationId: newEvent.organizationId,
206
+ typeId: newEvent.typeId,
207
+ name: newEvent.name,
208
+ });
209
+ });
210
+
211
+ test('A normal user with write access cannot create a global event', async () => {
212
+ const organization = await new OrganizationFactory({}).create();
213
+ const user = await new UserFactory({
214
+ organization,
215
+ permissions: minimumUserPermissions,
216
+ }).create();
217
+
218
+ const body: Body = new PatchableArray();
219
+ const newEvent = Event.create({
220
+ organizationId: null,
221
+ typeId: (await new PlatformEventTypeFactory({}).create()).id,
222
+ name: 'test event',
223
+ startDate: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000),
224
+ endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
225
+ });
226
+ body.addPut(newEvent);
227
+
228
+ await expect(TestRequest.patch({ body, user, organization })).rejects.toThrow(
229
+ STExpect.simpleError({ code: 'permission_denied' }),
230
+ );
231
+ });
232
+
233
+ test('A normal user with write access cannot make an event global', async () => {
234
+ const organization = await new OrganizationFactory({}).create();
235
+
236
+ const user = await new UserFactory({
237
+ organization,
238
+ permissions: minimumUserPermissions,
239
+ }).create();
240
+
241
+ const startDate = new Date(Date.now() + 5 * 24 * 60 * 60 * 1000);
242
+ const endDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
243
+
244
+ const body: Body = new PatchableArray();
245
+
246
+ const eventToPatch = await new EventFactory({
247
+ organization,
248
+ typeId: (await new PlatformEventTypeFactory({
249
+ maximum: 5,
250
+ }).create()).id,
251
+ name: 'test event',
252
+ startDate,
253
+ endDate,
254
+
255
+ }).create();
256
+
257
+ body.addPatch(Event.patch({
258
+ id: eventToPatch.id,
259
+ organizationId: null,
260
+ }));
261
+
262
+ await expect(TestRequest.patch({ body, user, organization })).rejects.toThrow(
263
+ STExpect.simpleError({ code: 'permission_denied' }),
264
+ );
265
+ });
266
+ });
267
+ });
@@ -33,7 +33,7 @@ export class PatchEventsEndpoint extends Endpoint<Params, Query, Body, ResponseB
33
33
  }
34
34
 
35
35
  async putEventGroup(event: Event, putGroup: GroupStruct) {
36
- const period = await RegistrationPeriod.getByDate(event.startDate);
36
+ const period = await RegistrationPeriod.getByDate(event.startDate, event.organizationId);
37
37
 
38
38
  if (!period) {
39
39
  throw new SimpleError({
@@ -252,7 +252,7 @@ export class PatchEventsEndpoint extends Endpoint<Params, Query, Body, ResponseB
252
252
  patch.group.id = event.groupId;
253
253
  patch.group.type = GroupType.EventRegistration;
254
254
 
255
- const period = await RegistrationPeriod.getByDate(event.startDate);
255
+ const period = await RegistrationPeriod.getByDate(event.startDate, event.organizationId);
256
256
  group = await PatchOrganizationRegistrationPeriodsEndpoint.patchGroup(patch.group, period);
257
257
  }
258
258
  else {
@@ -274,7 +274,7 @@ export class PatchEventsEndpoint extends Endpoint<Params, Query, Body, ResponseB
274
274
  else {
275
275
  if (patch.startDate || patch.endDate) {
276
276
  // Correct period id if needed
277
- const period = await RegistrationPeriod.getByDate(event.startDate);
277
+ const period = await RegistrationPeriod.getByDate(event.startDate, event.organizationId);
278
278
  if (event.groupId) {
279
279
  await AuditLogService.setContext({ source: AuditLogSource.System }, async () => {
280
280
  if (event.groupId) {
@@ -439,7 +439,7 @@ export class PatchEventsEndpoint extends Endpoint<Params, Query, Body, ResponseB
439
439
  }
440
440
 
441
441
  if (type.maximum && (!event.existsInDatabase || ('typeId' in (await event.getChangedDatabaseProperties()).fields))) {
442
- const currentPeriod = await RegistrationPeriod.getByDate(event.startDate);
442
+ const currentPeriod = await RegistrationPeriod.getByDate(event.startDate, event.organizationId);
443
443
  console.log('event.startDate', event.startDate);
444
444
  if (currentPeriod) {
445
445
  const count = await SQL.select().from(
@@ -62,7 +62,7 @@ export class GetMembersEndpoint extends Endpoint<Params, Query, Body, ResponseBo
62
62
  $in: tags,
63
63
  },
64
64
  },
65
- periodId: platform.periodId,
65
+ periodId: platform.periodIdIfPlatform,
66
66
  },
67
67
  },
68
68
  };
@@ -306,7 +306,7 @@ export class PatchOrganizationMembersEndpoint extends Endpoint<Params, Query, Bo
306
306
  }
307
307
  }
308
308
  else {
309
- if (registration.periodId !== platform.periodId) {
309
+ if (registration.periodId !== platform.periodIdIfPlatform) {
310
310
  return false;
311
311
  }
312
312
  }
@@ -1,7 +1,8 @@
1
1
  import { Request } from '@simonbackx/simple-endpoints';
2
- import { Organization, OrganizationFactory } from '@stamhoofd/models';
2
+ import { OrganizationFactory } from '@stamhoofd/models';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
 
5
+ import { Database } from '@simonbackx/simple-database';
5
6
  import { testServer } from '../../../../tests/helpers/TestServer';
6
7
  import { SearchOrganizationEndpoint } from './SearchOrganizationEndpoint';
7
8
 
@@ -10,7 +11,9 @@ describe('Endpoint.SearchOrganization', () => {
10
11
  const endpoint = new SearchOrganizationEndpoint();
11
12
 
12
13
  afterEach(async () => {
13
- await Organization.delete();
14
+ await Database.update('UPDATE registration_periods set organizationId = null, customName = ? where organizationId is not null', ['delete']);
15
+ await Database.delete('DELETE FROM `organizations`');
16
+ await Database.delete('DELETE FROM `registration_periods` where customName = ?', ['delete']);
14
17
  });
15
18
 
16
19
  test('Search for a given organization using exact search', async () => {
@@ -0,0 +1,63 @@
1
+ import { Request } from '@simonbackx/simple-endpoints';
2
+ import { Organization, OrganizationFactory, Platform, RegistrationPeriod, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
3
+ import { PermissionLevel, Permissions, PlatformConfig, Platform as PlatformStruct, Version } from '@stamhoofd/structures';
4
+
5
+ import { AutoEncoderPatchType } from '@simonbackx/simple-encoding';
6
+ import { TestUtils } from '@stamhoofd/test-utils';
7
+ import { testServer } from '../../../../tests/helpers/TestServer';
8
+ import { PatchPlatformEndpoint } from './PatchPlatformEnpoint';
9
+
10
+ describe('Endpoint.PatchPlatform', () => {
11
+ // Test endpoint
12
+ const endpoint = new PatchPlatformEndpoint();
13
+
14
+ beforeEach(async () => {
15
+ TestUtils.setEnvironment('userMode', 'platform');
16
+ });
17
+
18
+ const patchPlatform = async ({ patch, organization, token }: { patch: AutoEncoderPatchType<PlatformStruct>; organization: Organization; token: Token }) => {
19
+ const request = Request.buildJson('PATCH', `/v${Version}/platform`, organization.getApiHost(), patch);
20
+ request.headers.authorization = 'Bearer ' + token.accessToken;
21
+ return await testServer.test(endpoint, request);
22
+ };
23
+
24
+ describe('userMode organization', () => {
25
+ beforeEach(async () => {
26
+ TestUtils.setEnvironment('userMode', 'organization');
27
+ });
28
+
29
+ test('Should return platform with global period', async () => {
30
+ const organization = await new OrganizationFactory({ }).create();
31
+
32
+ const admin = await new UserFactory({
33
+ organization,
34
+ globalPermissions: Permissions.create({ level: PermissionLevel.Full }),
35
+ }).create();
36
+
37
+ admin.organizationId = null;
38
+ await admin.save();
39
+
40
+ const token = await Token.createToken(admin);
41
+
42
+ const patch = PlatformStruct.patch({
43
+ config: PlatformConfig.patch({
44
+ name: 'new name',
45
+ }),
46
+ });
47
+
48
+ // make sure no platform exists
49
+ await Platform.delete().where('id', '1');
50
+
51
+ // create global registration period
52
+ await new RegistrationPeriodFactory({
53
+ }).create();
54
+
55
+ const response = await patchPlatform({ patch, organization, token });
56
+ const periodId = response.body.period.id;
57
+ const period = await RegistrationPeriod.getByID(periodId);
58
+
59
+ expect(period).toBeDefined();
60
+ expect(period?.organizationId).toBeNull();
61
+ });
62
+ });
63
+ });
@@ -7,11 +7,11 @@ import { SimpleError } from '@simonbackx/simple-errors';
7
7
  import { QueueHandler } from '@stamhoofd/queues';
8
8
  import { Context } from '../../../helpers/Context';
9
9
  import { MembershipCharger } from '../../../helpers/MembershipCharger';
10
+ import { MemberUserSyncer } from '../../../helpers/MemberUserSyncer';
10
11
  import { PeriodHelper } from '../../../helpers/PeriodHelper';
11
12
  import { SetupStepUpdater } from '../../../helpers/SetupStepUpdater';
12
13
  import { TagHelper } from '../../../helpers/TagHelper';
13
14
  import { PlatformMembershipService } from '../../../services/PlatformMembershipService';
14
- import { MemberUserSyncer } from '../../../helpers/MemberUserSyncer';
15
15
 
16
16
  type Params = Record<string, never>;
17
17
  type Query = undefined;
@@ -80,7 +80,7 @@ export class GetRegistrationsEndpoint extends Endpoint<Params, Query, Body, Resp
80
80
 
81
81
  // Add organization scope filter
82
82
  scopeFilter = {
83
- periodId: platform.periodId,
83
+ periodId: platform.periodIdIfPlatform,
84
84
  organization: {
85
85
  $elemMatch: {
86
86
  tags: {
@@ -1,6 +1,6 @@
1
1
  import { Request } from '@simonbackx/simple-endpoints';
2
2
  import { EmailMocker } from '@stamhoofd/email';
3
- import { BalanceItem, BalanceItemFactory, Group, GroupFactory, MemberFactory, MemberWithRegistrations, Organization, OrganizationFactory, OrganizationRegistrationPeriodFactory, Registration, RegistrationFactory, RegistrationPeriod, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
3
+ import { BalanceItemFactory, Group, GroupFactory, MemberFactory, MemberWithRegistrations, Organization, OrganizationFactory, OrganizationRegistrationPeriodFactory, Registration, RegistrationFactory, RegistrationPeriod, RegistrationPeriodFactory, Token, UserFactory } from '@stamhoofd/models';
4
4
  import { BalanceItemCartItem, BalanceItemType, Company, GroupOption, GroupOptionMenu, IDRegisterCart, IDRegisterCheckout, IDRegisterItem, OrganizationPackages, PaymentCustomer, PaymentMethod, PermissionLevel, Permissions, ReduceablePrice, RegisterItemOption, STPackageStatus, STPackageType, UserPermissions, Version } from '@stamhoofd/structures';
5
5
  import { STExpect, TestUtils } from '@stamhoofd/test-utils';
6
6
  import { v4 as uuidv4 } from 'uuid';
@@ -59,8 +59,8 @@ describe('Endpoint.RegisterMembers', () => {
59
59
  organization,
60
60
  permissions: permissionLevel !== PermissionLevel.None
61
61
  ? Permissions.create({
62
- level: permissionLevel,
63
- })
62
+ level: permissionLevel,
63
+ })
64
64
  : null,
65
65
  })
66
66
  .create();
@@ -105,6 +105,7 @@ describe('Endpoint.RegisterMembers', () => {
105
105
 
106
106
  test('Should fail if demo limit reached', async () => {
107
107
  TestUtils.setEnvironment('userMode', 'organization');
108
+
108
109
  const { member, group, groupPrice, organization, token, otherMembers } = await initData({ otherMemberAmount: 10 });
109
110
 
110
111
  organization.meta.packages = OrganizationPackages.create({
@@ -116,6 +116,8 @@ export class GetRegistrationPeriodsEndpoint extends Endpoint<Params, Query, Body
116
116
  }
117
117
 
118
118
  async handle(request: DecodedRequest<Params, Query, Body>) {
119
+ await Context.setUserOrganizationScope();
120
+
119
121
  if (request.request.getVersion() < 371) {
120
122
  throw new SimpleError({
121
123
  code: 'client_update_required',
@@ -143,8 +145,6 @@ export class GetRegistrationPeriodsEndpoint extends Endpoint<Params, Query, Body
143
145
  });
144
146
  }
145
147
 
146
- await Context.setUserOrganizationScope();
147
-
148
148
  return new Response(
149
149
  await GetRegistrationPeriodsEndpoint.buildData(request.query),
150
150
  );
@@ -36,7 +36,14 @@ export class PatchRegistrationPeriodsEndpoint extends Endpoint<Params, Query, Bo
36
36
  static async isCurrentRegistrationPeriod(organizationId: string | null, periodId: string) {
37
37
  if (organizationId === null) {
38
38
  const platform = await Platform.getSharedStruct();
39
- return platform.period.id === periodId;
39
+ if (STAMHOOFD.userMode === 'platform') {
40
+ return platform.period.id === periodId;
41
+ }
42
+ throw new SimpleError({
43
+ code: 'only_platform',
44
+ message: 'Period id should only be used if userMode is platform',
45
+ human: $t(`8a50ee7d-f37e-46cc-9ce7-30c7b37cefe8`),
46
+ });
40
47
  }
41
48
 
42
49
  const organization = await Organization.getByID(organizationId);
@@ -73,7 +80,7 @@ export class PatchRegistrationPeriodsEndpoint extends Endpoint<Params, Query, Bo
73
80
  if (put.endDate < put.startDate) {
74
81
  throw new SimpleError({
75
82
  code: 'invalid_field',
76
- message: $t('De einddatum moet na de startdatum liggen.'),
83
+ message: $t('186723cd-2cd4-45fd-aa9c-020c9d92b225'),
77
84
  field: 'endDate',
78
85
  });
79
86
  }
@@ -141,7 +148,7 @@ export class PatchRegistrationPeriodsEndpoint extends Endpoint<Params, Query, Bo
141
148
  if ((patch.startDate || patch.endDate) && model.endDate < model.startDate) {
142
149
  throw new SimpleError({
143
150
  code: 'invalid_field',
144
- message: $t('De einddatum moet na de startdatum liggen.'),
151
+ message: $t('186723cd-2cd4-45fd-aa9c-020c9d92b225'),
145
152
  field: 'endDate',
146
153
  });
147
154
  }