@stamhoofd/backend 2.83.1 → 2.83.3
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/backend",
|
|
3
|
-
"version": "2.83.
|
|
3
|
+
"version": "2.83.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"@simonbackx/simple-encoding": "2.22.0",
|
|
39
39
|
"@simonbackx/simple-endpoints": "1.19.1",
|
|
40
40
|
"@simonbackx/simple-logging": "^1.0.1",
|
|
41
|
-
"@stamhoofd/backend-i18n": "2.83.
|
|
42
|
-
"@stamhoofd/backend-middleware": "2.83.
|
|
43
|
-
"@stamhoofd/email": "2.83.
|
|
44
|
-
"@stamhoofd/models": "2.83.
|
|
45
|
-
"@stamhoofd/queues": "2.83.
|
|
46
|
-
"@stamhoofd/sql": "2.83.
|
|
47
|
-
"@stamhoofd/structures": "2.83.
|
|
48
|
-
"@stamhoofd/utility": "2.83.
|
|
41
|
+
"@stamhoofd/backend-i18n": "2.83.3",
|
|
42
|
+
"@stamhoofd/backend-middleware": "2.83.3",
|
|
43
|
+
"@stamhoofd/email": "2.83.3",
|
|
44
|
+
"@stamhoofd/models": "2.83.3",
|
|
45
|
+
"@stamhoofd/queues": "2.83.3",
|
|
46
|
+
"@stamhoofd/sql": "2.83.3",
|
|
47
|
+
"@stamhoofd/structures": "2.83.3",
|
|
48
|
+
"@stamhoofd/utility": "2.83.3",
|
|
49
49
|
"archiver": "^7.0.1",
|
|
50
50
|
"aws-sdk": "^2.885.0",
|
|
51
51
|
"axios": "1.6.8",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "1d81ad636d7a240301dc6dcd2725549d4846fe1c"
|
|
69
69
|
}
|
|
@@ -257,12 +257,12 @@ export class RegisterMembersEndpoint extends Endpoint<Params, Query, Body, Respo
|
|
|
257
257
|
const existingRegistrations = await Registration.where({ memberId: member.id, groupId: item.groupId, cycle: group.cycle, periodId: group.periodId, registeredAt: { sign: '!=', value: null } });
|
|
258
258
|
|
|
259
259
|
for (const existingRegistration of existingRegistrations) {
|
|
260
|
-
if (item.replaceRegistrations.some(r => r.id === existingRegistration.id)) {
|
|
260
|
+
if (item.replaceRegistrations.some(r => r.registration.id === existingRegistration.id)) {
|
|
261
261
|
// Safe
|
|
262
262
|
continue;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
if (checkout.cart.deleteRegistrations.some(r => r.id === existingRegistration.id)) {
|
|
265
|
+
if (checkout.cart.deleteRegistrations.some(r => r.registration.id === existingRegistration.id)) {
|
|
266
266
|
// Safe
|
|
267
267
|
continue;
|
|
268
268
|
}
|
|
@@ -279,7 +279,7 @@ export class RegisterMembersEndpoint extends Endpoint<Params, Query, Body, Respo
|
|
|
279
279
|
|
|
280
280
|
if (item.replaceRegistrations.length === 1) {
|
|
281
281
|
// Try to reuse this specific one
|
|
282
|
-
reuseRegistration = (await Registration.getByID(item.replaceRegistrations[0].id)) ?? null;
|
|
282
|
+
reuseRegistration = (await Registration.getByID(item.replaceRegistrations[0].registration.id)) ?? null;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
let startDate = item.calculatedStartDate;
|
|
@@ -327,7 +327,7 @@ export class RegisterMembersEndpoint extends Endpoint<Params, Query, Body, Respo
|
|
|
327
327
|
if (whoWillPayNow === 'nobody' && item.replaceRegistrations.length > 0) {
|
|
328
328
|
// If the replace registration was paid by an organization
|
|
329
329
|
// Make sure this updated registration will also be paid by the organization, not the member
|
|
330
|
-
const paidAsOrganization = item.replaceRegistrations[0].payingOrganizationId;
|
|
330
|
+
const paidAsOrganization = item.replaceRegistrations[0].registration.payingOrganizationId;
|
|
331
331
|
if (paidAsOrganization) {
|
|
332
332
|
registration.payingOrganizationId = paidAsOrganization;
|
|
333
333
|
}
|
|
@@ -389,7 +389,7 @@ export class RegisterMembersEndpoint extends Endpoint<Params, Query, Body, Respo
|
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
const existingRegistration = await Registration.getByID(registrationStruct.id);
|
|
392
|
+
const existingRegistration = await Registration.getByID(registrationStruct.registration.id);
|
|
393
393
|
if (!existingRegistration || existingRegistration.organizationId !== organization.id) {
|
|
394
394
|
throw new SimpleError({
|
|
395
395
|
code: 'invalid_data',
|
|
@@ -214,7 +214,6 @@ export class PlatformMembershipService {
|
|
|
214
214
|
membershipTypeId: { sign: 'IN', value: types },
|
|
215
215
|
deletedAt: null,
|
|
216
216
|
});
|
|
217
|
-
const activeMembershipsUndeletable = activeMemberships.filter(m => !m.canDelete() || !m.generated);
|
|
218
217
|
|
|
219
218
|
if (defaultMemberships.length === 0) {
|
|
220
219
|
// Stop all active memberships that were added automatically
|
|
@@ -233,23 +232,6 @@ export class PlatformMembershipService {
|
|
|
233
232
|
continue;
|
|
234
233
|
}
|
|
235
234
|
|
|
236
|
-
if (activeMembershipsUndeletable.length) {
|
|
237
|
-
// Skip automatic additions
|
|
238
|
-
for (const m of activeMembershipsUndeletable) {
|
|
239
|
-
try {
|
|
240
|
-
await m.calculatePrice(me);
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
// Ignore error: membership might not be available anymore
|
|
244
|
-
if (!silent) {
|
|
245
|
-
console.error('Failed to calculate price for undeletable membership', m.id, e);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
await m.save();
|
|
249
|
-
}
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
235
|
// Add the cheapest available membership
|
|
254
236
|
const organizations = await Organization.getByIDs(...Formatter.uniqueArray(defaultMemberships.map(m => m.registration.organizationId)));
|
|
255
237
|
|
|
@@ -286,28 +268,58 @@ export class PlatformMembershipService {
|
|
|
286
268
|
})[0];
|
|
287
269
|
|
|
288
270
|
if (!cheapestMembership) {
|
|
271
|
+
// Technically not possible, but for type checking
|
|
289
272
|
console.error('No membership found');
|
|
290
273
|
continue;
|
|
291
274
|
}
|
|
292
275
|
|
|
293
276
|
// Check if already have the same membership
|
|
294
277
|
// if that is the case, we'll keep that one and update the price + dates if the organization matches the cheapest/earliest membership
|
|
295
|
-
let didFind =
|
|
278
|
+
let didFind: MemberPlatformMembership | null = null;
|
|
296
279
|
for (const m of activeMemberships) {
|
|
297
280
|
if (m.membershipTypeId === cheapestMembership.membership.id && m.organizationId === cheapestMembership.registration.organizationId) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
281
|
+
if (!m.locked) {
|
|
282
|
+
// Update the price and dates of this active membership (could have changed)
|
|
283
|
+
try {
|
|
284
|
+
await m.calculatePrice(me, cheapestMembership.registration);
|
|
285
|
+
}
|
|
286
|
+
catch (e) {
|
|
287
|
+
// Ignore error: membership might not be available anymore
|
|
288
|
+
if (!silent) {
|
|
289
|
+
console.error('Failed to calculate price for active membership', m.id, e);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
await m.save();
|
|
301
293
|
}
|
|
302
|
-
|
|
303
|
-
|
|
294
|
+
didFind = m;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Delete all other generated memberships that are not the cheapest one
|
|
300
|
+
for (const m of activeMemberships) {
|
|
301
|
+
if (m.id !== didFind?.id) {
|
|
302
|
+
if (!m.locked && (m.generated || m.membershipTypeId === cheapestMembership.membership.id)) {
|
|
304
303
|
if (!silent) {
|
|
305
|
-
console.
|
|
304
|
+
console.log('Removing membership because cheaper membership found or duplicate, for: ' + me.id + ' - membership ' + m.id);
|
|
305
|
+
}
|
|
306
|
+
await m.doDelete();
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
// Update price
|
|
310
|
+
if (!m.locked) {
|
|
311
|
+
try {
|
|
312
|
+
await m.calculatePrice(me);
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
// Ignore error: membership might not be available anymore
|
|
316
|
+
if (!silent) {
|
|
317
|
+
console.error('Failed to calculate price for undeletable membership', m.id, e);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
await m.save();
|
|
306
321
|
}
|
|
307
322
|
}
|
|
308
|
-
await m.save();
|
|
309
|
-
didFind = true;
|
|
310
|
-
break;
|
|
311
323
|
}
|
|
312
324
|
}
|
|
313
325
|
|
|
@@ -315,6 +327,8 @@ export class PlatformMembershipService {
|
|
|
315
327
|
continue;
|
|
316
328
|
}
|
|
317
329
|
|
|
330
|
+
// Otherwise make sure we create a new membership
|
|
331
|
+
|
|
318
332
|
const periodConfig = cheapestMembership.membership.periods.get(period.id);
|
|
319
333
|
if (!periodConfig) {
|
|
320
334
|
console.error('Missing membership prices for membership type ' + cheapestMembership.membership.id + ' and period ' + period.id);
|
|
@@ -351,16 +365,6 @@ export class PlatformMembershipService {
|
|
|
351
365
|
|
|
352
366
|
await membership.calculatePrice(me, cheapestMembership.registration);
|
|
353
367
|
await membership.save();
|
|
354
|
-
|
|
355
|
-
// This reasoning allows us to replace an existing membership with a cheaper one (not date based ones, but type based ones)
|
|
356
|
-
for (const toDelete of activeMemberships) {
|
|
357
|
-
if (toDelete.canDelete() && toDelete.generated) {
|
|
358
|
-
if (!silent) {
|
|
359
|
-
console.log('Removing membership because cheaper membership found for: ' + me.id + ' - membership ' + toDelete.id);
|
|
360
|
-
}
|
|
361
|
-
await toDelete.doDelete();
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
368
|
}
|
|
365
369
|
});
|
|
366
370
|
});
|