@attraccess/plugin-reservations 0.1.0 → 0.2.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.
- package/LICENSE.md +32 -0
- package/dist/index.js +1134 -860
- package/frontend/{__federation_expose_Plugin-DAM66N0j.js → __federation_expose_Plugin-BDJ5Eff3.js} +1056 -860
- package/frontend/__federation_fn_import-BHGw2mzr.js +1 -0
- package/frontend/{_virtual___federation_fn_import-BXODRNto.js → _virtual___federation_fn_import-D2E5es2p.js} +2 -4
- package/frontend/remoteEntry.js +3 -71
- package/frontend/style.css +13 -3
- package/package.json +26 -13
- package/dist/migrations.js +0 -161
- package/frontend/__federation_fn_import-DAGm_xmC.js +0 -2
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(plugin_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(plugin_exports);
|
|
36
36
|
|
|
37
37
|
// backend/api/settings.controller.ts
|
|
38
|
-
var
|
|
38
|
+
var import_plugins_backend_sdk9 = require("@attraccess/plugins-backend-sdk");
|
|
39
39
|
var import_common12 = require("@nestjs/common");
|
|
40
40
|
var import_swagger4 = require("@nestjs/swagger");
|
|
41
41
|
|
|
@@ -47,6 +47,7 @@ var PLUGIN_CONTEXT = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
|
|
|
47
47
|
var RESERVATION_NOTIFIER = /* @__PURE__ */ Symbol.for("attraccess.reservations.notifier");
|
|
48
48
|
var RESERVATION_CLOCK = /* @__PURE__ */ Symbol.for("attraccess.reservations.clock");
|
|
49
49
|
var READER_HORIZON_MS = 24 * 60 * 6e4;
|
|
50
|
+
var CAPACITY_REDUCED_REASON = "machine capacity reduced";
|
|
50
51
|
|
|
51
52
|
// backend/reservations/actor.ts
|
|
52
53
|
function subjectOfPrincipal(principal) {
|
|
@@ -165,6 +166,7 @@ var BOOKING_CONFLICT_CODES = [
|
|
|
165
166
|
"OUTSIDE_BOOKABLE_HOURS",
|
|
166
167
|
"USER_BOOKING_LIMIT",
|
|
167
168
|
"OVERLAP",
|
|
169
|
+
"OWN_OVERLAP",
|
|
168
170
|
"MAINTENANCE"
|
|
169
171
|
];
|
|
170
172
|
var STATE_CONFLICT_CODES = [
|
|
@@ -194,327 +196,10 @@ var ReservationError = class extends import_common2.HttpException {
|
|
|
194
196
|
};
|
|
195
197
|
|
|
196
198
|
// backend/reservations/directory.service.ts
|
|
197
|
-
var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
|
|
198
199
|
var import_common3 = require("@nestjs/common");
|
|
199
|
-
var DirectoryService = class {
|
|
200
|
-
constructor(context) {
|
|
201
|
-
__publicField(this, "context", context);
|
|
202
|
-
}
|
|
203
|
-
async getResource(resourceId) {
|
|
204
|
-
const row = await this.context.getRepository(import_plugins_backend_sdk.Resource).findOne({ where: { id: resourceId }, select: { id: true, name: true } });
|
|
205
|
-
return row ? { id: row.id, name: row.name } : null;
|
|
206
|
-
}
|
|
207
|
-
async getResourceNames(resourceIds) {
|
|
208
|
-
const ids = [...new Set(resourceIds)];
|
|
209
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
210
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk.Resource).createQueryBuilder("resource").select(["resource.id", "resource.name"]).where("resource.id IN (:...ids)", { ids }).getMany();
|
|
211
|
-
return new Map(rows.map((row) => [row.id, row.name]));
|
|
212
|
-
}
|
|
213
|
-
async getUserNames(userIds) {
|
|
214
|
-
const ids = [...new Set(userIds)];
|
|
215
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
216
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk.User).createQueryBuilder("user").select(["user.id", "user.username"]).where("user.id IN (:...ids)", { ids }).getMany();
|
|
217
|
-
return new Map(rows.map((row) => [row.id, row.username]));
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
DirectoryService = __decorateClass([
|
|
221
|
-
(0, import_common3.Injectable)(),
|
|
222
|
-
__decorateParam(0, (0, import_common3.Inject)(PLUGIN_CONTEXT))
|
|
223
|
-
], DirectoryService);
|
|
224
|
-
|
|
225
|
-
// backend/settings/settings-admin.service.ts
|
|
226
|
-
var import_common9 = require("@nestjs/common");
|
|
227
|
-
|
|
228
|
-
// backend/reservations/reservation.service.ts
|
|
229
|
-
var import_common8 = require("@nestjs/common");
|
|
230
|
-
|
|
231
|
-
// backend/entities/reservation.entity.ts
|
|
232
|
-
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
233
|
-
var RESERVATION_STATUSES = [
|
|
234
|
-
"pending",
|
|
235
|
-
"confirmed",
|
|
236
|
-
"rejected",
|
|
237
|
-
"cancelled",
|
|
238
|
-
"expired",
|
|
239
|
-
"no_show",
|
|
240
|
-
"completed"
|
|
241
|
-
];
|
|
242
|
-
var REMINDER_FLAGS = [
|
|
243
|
-
"confirmationSentAt",
|
|
244
|
-
"stillNeededSentAt",
|
|
245
|
-
"reminder24hSentAt",
|
|
246
|
-
"handoverSentAt",
|
|
247
|
-
"overrunSentAt",
|
|
248
|
-
"noShowNotifiedAt",
|
|
249
|
-
"expiredNotifiedAt"
|
|
250
|
-
];
|
|
251
|
-
var ReservationEntity = class {
|
|
252
|
-
constructor() {
|
|
253
|
-
__publicField(this, "id");
|
|
254
|
-
__publicField(this, "resourceId");
|
|
255
|
-
__publicField(this, "userId");
|
|
256
|
-
__publicField(this, "startTime");
|
|
257
|
-
__publicField(this, "endTime");
|
|
258
|
-
__publicField(this, "bufferBeforeMinutes");
|
|
259
|
-
__publicField(this, "bufferAfterMinutes");
|
|
260
|
-
__publicField(this, "status");
|
|
261
|
-
__publicField(this, "note");
|
|
262
|
-
__publicField(this, "createdAt");
|
|
263
|
-
__publicField(this, "endedEarlyAt");
|
|
264
|
-
__publicField(this, "cancelledBy");
|
|
265
|
-
__publicField(this, "cancelReason");
|
|
266
|
-
__publicField(this, "decidedBy");
|
|
267
|
-
__publicField(this, "decisionReason");
|
|
268
|
-
__publicField(this, "decidedAt");
|
|
269
|
-
__publicField(this, "checkedInAt");
|
|
270
|
-
__publicField(this, "checkedInUsageId");
|
|
271
|
-
__publicField(this, "keptAt");
|
|
272
|
-
__publicField(this, "confirmationSentAt");
|
|
273
|
-
__publicField(this, "stillNeededSentAt");
|
|
274
|
-
__publicField(this, "reminder24hSentAt");
|
|
275
|
-
__publicField(this, "handoverSentAt");
|
|
276
|
-
__publicField(this, "overrunSentAt");
|
|
277
|
-
__publicField(this, "noShowNotifiedAt");
|
|
278
|
-
__publicField(this, "expiredNotifiedAt");
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
__decorateClass([
|
|
282
|
-
(0, import_plugins_backend_sdk2.PrimaryGeneratedColumn)({ type: "integer" })
|
|
283
|
-
], ReservationEntity.prototype, "id", 2);
|
|
284
|
-
__decorateClass([
|
|
285
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer" })
|
|
286
|
-
], ReservationEntity.prototype, "resourceId", 2);
|
|
287
|
-
__decorateClass([
|
|
288
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer" })
|
|
289
|
-
], ReservationEntity.prototype, "userId", 2);
|
|
290
|
-
__decorateClass([
|
|
291
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime" })
|
|
292
|
-
], ReservationEntity.prototype, "startTime", 2);
|
|
293
|
-
__decorateClass([
|
|
294
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime" })
|
|
295
|
-
], ReservationEntity.prototype, "endTime", 2);
|
|
296
|
-
__decorateClass([
|
|
297
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", default: 0 })
|
|
298
|
-
], ReservationEntity.prototype, "bufferBeforeMinutes", 2);
|
|
299
|
-
__decorateClass([
|
|
300
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", default: 0 })
|
|
301
|
-
], ReservationEntity.prototype, "bufferAfterMinutes", 2);
|
|
302
|
-
__decorateClass([
|
|
303
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar" })
|
|
304
|
-
], ReservationEntity.prototype, "status", 2);
|
|
305
|
-
__decorateClass([
|
|
306
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", nullable: true })
|
|
307
|
-
], ReservationEntity.prototype, "note", 2);
|
|
308
|
-
__decorateClass([
|
|
309
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime" })
|
|
310
|
-
], ReservationEntity.prototype, "createdAt", 2);
|
|
311
|
-
__decorateClass([
|
|
312
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
313
|
-
], ReservationEntity.prototype, "endedEarlyAt", 2);
|
|
314
|
-
__decorateClass([
|
|
315
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", nullable: true })
|
|
316
|
-
], ReservationEntity.prototype, "cancelledBy", 2);
|
|
317
|
-
__decorateClass([
|
|
318
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", nullable: true })
|
|
319
|
-
], ReservationEntity.prototype, "cancelReason", 2);
|
|
320
|
-
__decorateClass([
|
|
321
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", nullable: true })
|
|
322
|
-
], ReservationEntity.prototype, "decidedBy", 2);
|
|
323
|
-
__decorateClass([
|
|
324
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "varchar", nullable: true })
|
|
325
|
-
], ReservationEntity.prototype, "decisionReason", 2);
|
|
326
|
-
__decorateClass([
|
|
327
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
328
|
-
], ReservationEntity.prototype, "decidedAt", 2);
|
|
329
|
-
__decorateClass([
|
|
330
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
331
|
-
], ReservationEntity.prototype, "checkedInAt", 2);
|
|
332
|
-
__decorateClass([
|
|
333
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "integer", nullable: true })
|
|
334
|
-
], ReservationEntity.prototype, "checkedInUsageId", 2);
|
|
335
|
-
__decorateClass([
|
|
336
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
337
|
-
], ReservationEntity.prototype, "keptAt", 2);
|
|
338
|
-
__decorateClass([
|
|
339
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
340
|
-
], ReservationEntity.prototype, "confirmationSentAt", 2);
|
|
341
|
-
__decorateClass([
|
|
342
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
343
|
-
], ReservationEntity.prototype, "stillNeededSentAt", 2);
|
|
344
|
-
__decorateClass([
|
|
345
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
346
|
-
], ReservationEntity.prototype, "reminder24hSentAt", 2);
|
|
347
|
-
__decorateClass([
|
|
348
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
349
|
-
], ReservationEntity.prototype, "handoverSentAt", 2);
|
|
350
|
-
__decorateClass([
|
|
351
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
352
|
-
], ReservationEntity.prototype, "overrunSentAt", 2);
|
|
353
|
-
__decorateClass([
|
|
354
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
355
|
-
], ReservationEntity.prototype, "noShowNotifiedAt", 2);
|
|
356
|
-
__decorateClass([
|
|
357
|
-
(0, import_plugins_backend_sdk2.Column)({ type: "datetime", nullable: true })
|
|
358
|
-
], ReservationEntity.prototype, "expiredNotifiedAt", 2);
|
|
359
|
-
ReservationEntity = __decorateClass([
|
|
360
|
-
(0, import_plugins_backend_sdk2.Entity)({ name: "reservations_reservation" }),
|
|
361
|
-
(0, import_plugins_backend_sdk2.Index)("IDX_reservations_reservation_slot", ["resourceId", "status", "startTime", "endTime"]),
|
|
362
|
-
(0, import_plugins_backend_sdk2.Index)("IDX_reservations_reservation_user", ["userId", "status"])
|
|
363
|
-
], ReservationEntity);
|
|
364
200
|
|
|
365
|
-
// backend/
|
|
366
|
-
var
|
|
367
|
-
var import_common4 = require("@nestjs/common");
|
|
368
|
-
var import_typeorm = require("typeorm");
|
|
369
|
-
var ACTIVE_INTRODUCTION_EXISTS_SQL = `EXISTS (
|
|
370
|
-
SELECT 1 FROM "resource_introduction" "rin"
|
|
371
|
-
WHERE "rin"."resourceGroupId" = vg.id AND "rin"."receiverUserId" = :userId
|
|
372
|
-
AND (
|
|
373
|
-
SELECT "h"."action" FROM "resource_introduction_history_item" "h"
|
|
374
|
-
WHERE "h"."introductionId" = "rin"."id"
|
|
375
|
-
ORDER BY "h"."createdAt" DESC, "h"."id" DESC
|
|
376
|
-
LIMIT 1
|
|
377
|
-
) = 'grant'
|
|
378
|
-
)`;
|
|
379
|
-
var VisibilityService = class {
|
|
380
|
-
constructor(context, access) {
|
|
381
|
-
__publicField(this, "context", context);
|
|
382
|
-
__publicField(this, "access", access);
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* The subset of `resourceIds` (existing resources) the user may see. A request actor's scope applies to the
|
|
386
|
-
* `resources.update` shortcut, as core applies an API token's scope to its group visibility.
|
|
387
|
-
*/
|
|
388
|
-
async filterVisible(subject, resourceIds) {
|
|
389
|
-
const userId = subjectUserId(subject);
|
|
390
|
-
const ids = [...new Set(resourceIds)];
|
|
391
|
-
if (ids.length === 0) return [];
|
|
392
|
-
const base = this.context.getRepository(import_plugins_backend_sdk3.Resource).createQueryBuilder("resource").select("resource.id", "id").where("resource.id IN (:...ids)", { ids });
|
|
393
|
-
if (!await this.access.hasUpdatePermission(subject)) {
|
|
394
|
-
const visibleGroups = this.context.getRepository(import_plugins_backend_sdk3.ResourceGroup).createQueryBuilder("vg").select("vg.id").where("vg.isHidden = :notHidden", { notHidden: false }).orWhere(
|
|
395
|
-
`EXISTS (SELECT 1 FROM "resource_introducer" "ri" WHERE "ri"."resourceGroupId" = vg.id AND "ri"."userId" = :userId)`
|
|
396
|
-
).orWhere(ACTIVE_INTRODUCTION_EXISTS_SQL);
|
|
397
|
-
base.leftJoin("resource.groups", "rg").andWhere(new import_typeorm.Brackets((qb) => qb.where("rg.id IS NULL").orWhere(`rg.id IN (${visibleGroups.getQuery()})`))).setParameters({ ...visibleGroups.getParameters(), notHidden: false, userId });
|
|
398
|
-
}
|
|
399
|
-
const rows = await base.distinct(true).getRawMany();
|
|
400
|
-
return rows.map((row) => Number(row.id));
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Whether the account exists, is not soft-deleted and not disabled. Deleting or disabling a user keeps
|
|
404
|
-
* their role rows, so anything acting on their behalf without a session (iCal feeds) must check this.
|
|
405
|
-
*/
|
|
406
|
-
async isActiveAccount(userId) {
|
|
407
|
-
const user = await this.context.getRepository(import_plugins_backend_sdk3.User).findOne({ where: { id: userId }, select: { id: true, isDisabled: true } });
|
|
408
|
-
return user !== null && !user.isDisabled;
|
|
409
|
-
}
|
|
410
|
-
/** The subset of `resourceIds` whose sessions always need a supervisor (`supervision_required`). */
|
|
411
|
-
async resourceIdsRequiringSupervision(resourceIds) {
|
|
412
|
-
const ids = [...new Set(resourceIds)];
|
|
413
|
-
if (ids.length === 0) return [];
|
|
414
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk3.Resource).createQueryBuilder("resource").select("resource.id", "id").where("resource.id IN (:...ids)", { ids }).andWhere("resource.supervisionMode = :mode", { mode: import_plugins_backend_sdk3.SupervisionMode.SUPERVISION_REQUIRED }).getRawMany();
|
|
415
|
-
return rows.map((row) => Number(row.id));
|
|
416
|
-
}
|
|
417
|
-
/** Ids of all resources in the given groups. */
|
|
418
|
-
async resourceIdsOfGroups(groupIds) {
|
|
419
|
-
if (groupIds.length === 0) return [];
|
|
420
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk3.Resource).createQueryBuilder("resource").select("resource.id", "id").innerJoin("resource.groups", "g").where("g.id IN (:...groupIds)", { groupIds }).distinct(true).getRawMany();
|
|
421
|
-
return rows.map((row) => Number(row.id));
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
VisibilityService = __decorateClass([
|
|
425
|
-
(0, import_common4.Injectable)(),
|
|
426
|
-
__decorateParam(0, (0, import_common4.Inject)(PLUGIN_CONTEXT)),
|
|
427
|
-
__decorateParam(1, (0, import_common4.Inject)(AccessService))
|
|
428
|
-
], VisibilityService);
|
|
429
|
-
|
|
430
|
-
// backend/settings/resource-settings.service.ts
|
|
431
|
-
var import_common5 = require("@nestjs/common");
|
|
432
|
-
|
|
433
|
-
// backend/entities/resource-settings.entity.ts
|
|
434
|
-
var import_plugins_backend_sdk4 = require("@attraccess/plugins-backend-sdk");
|
|
435
|
-
var ResourceSettingsEntity = class {
|
|
436
|
-
constructor() {
|
|
437
|
-
__publicField(this, "resourceId");
|
|
438
|
-
__publicField(this, "enabled");
|
|
439
|
-
__publicField(this, "approvalRequired");
|
|
440
|
-
__publicField(this, "timeStepMinutes");
|
|
441
|
-
__publicField(this, "minDurationMinutes");
|
|
442
|
-
__publicField(this, "maxDurationMinutes");
|
|
443
|
-
__publicField(this, "maxAdvanceDays");
|
|
444
|
-
__publicField(this, "minLeadMinutes");
|
|
445
|
-
__publicField(this, "bufferBeforeMinutes");
|
|
446
|
-
__publicField(this, "bufferAfterMinutes");
|
|
447
|
-
__publicField(this, "maxActiveBookingsPerUser");
|
|
448
|
-
__publicField(this, "whoCanBook");
|
|
449
|
-
__publicField(this, "confirmWindowMinutes");
|
|
450
|
-
__publicField(this, "checkInEnabled");
|
|
451
|
-
__publicField(this, "checkInGraceMinutes");
|
|
452
|
-
__publicField(this, "earlyCheckInMinutes");
|
|
453
|
-
__publicField(this, "handoverReminderMinutes");
|
|
454
|
-
__publicField(this, "bookableHours");
|
|
455
|
-
__publicField(this, "updatedAt");
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
__decorateClass([
|
|
459
|
-
(0, import_plugins_backend_sdk4.PrimaryColumn)({ type: "integer" })
|
|
460
|
-
], ResourceSettingsEntity.prototype, "resourceId", 2);
|
|
461
|
-
__decorateClass([
|
|
462
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "boolean", default: false })
|
|
463
|
-
], ResourceSettingsEntity.prototype, "enabled", 2);
|
|
464
|
-
__decorateClass([
|
|
465
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "boolean", default: false })
|
|
466
|
-
], ResourceSettingsEntity.prototype, "approvalRequired", 2);
|
|
467
|
-
__decorateClass([
|
|
468
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 15 })
|
|
469
|
-
], ResourceSettingsEntity.prototype, "timeStepMinutes", 2);
|
|
470
|
-
__decorateClass([
|
|
471
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 15 })
|
|
472
|
-
], ResourceSettingsEntity.prototype, "minDurationMinutes", 2);
|
|
473
|
-
__decorateClass([
|
|
474
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 240 })
|
|
475
|
-
], ResourceSettingsEntity.prototype, "maxDurationMinutes", 2);
|
|
476
|
-
__decorateClass([
|
|
477
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 30 })
|
|
478
|
-
], ResourceSettingsEntity.prototype, "maxAdvanceDays", 2);
|
|
479
|
-
__decorateClass([
|
|
480
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 0 })
|
|
481
|
-
], ResourceSettingsEntity.prototype, "minLeadMinutes", 2);
|
|
482
|
-
__decorateClass([
|
|
483
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 0 })
|
|
484
|
-
], ResourceSettingsEntity.prototype, "bufferBeforeMinutes", 2);
|
|
485
|
-
__decorateClass([
|
|
486
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 0 })
|
|
487
|
-
], ResourceSettingsEntity.prototype, "bufferAfterMinutes", 2);
|
|
488
|
-
__decorateClass([
|
|
489
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 3 })
|
|
490
|
-
], ResourceSettingsEntity.prototype, "maxActiveBookingsPerUser", 2);
|
|
491
|
-
__decorateClass([
|
|
492
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "varchar", default: "can-start" })
|
|
493
|
-
], ResourceSettingsEntity.prototype, "whoCanBook", 2);
|
|
494
|
-
__decorateClass([
|
|
495
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 60 })
|
|
496
|
-
], ResourceSettingsEntity.prototype, "confirmWindowMinutes", 2);
|
|
497
|
-
__decorateClass([
|
|
498
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "boolean", default: true })
|
|
499
|
-
], ResourceSettingsEntity.prototype, "checkInEnabled", 2);
|
|
500
|
-
__decorateClass([
|
|
501
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 15 })
|
|
502
|
-
], ResourceSettingsEntity.prototype, "checkInGraceMinutes", 2);
|
|
503
|
-
__decorateClass([
|
|
504
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 15 })
|
|
505
|
-
], ResourceSettingsEntity.prototype, "earlyCheckInMinutes", 2);
|
|
506
|
-
__decorateClass([
|
|
507
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "integer", default: 15 })
|
|
508
|
-
], ResourceSettingsEntity.prototype, "handoverReminderMinutes", 2);
|
|
509
|
-
__decorateClass([
|
|
510
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "text", default: "{}" })
|
|
511
|
-
], ResourceSettingsEntity.prototype, "bookableHours", 2);
|
|
512
|
-
__decorateClass([
|
|
513
|
-
(0, import_plugins_backend_sdk4.Column)({ type: "datetime" })
|
|
514
|
-
], ResourceSettingsEntity.prototype, "updatedAt", 2);
|
|
515
|
-
ResourceSettingsEntity = __decorateClass([
|
|
516
|
-
(0, import_plugins_backend_sdk4.Entity)({ name: "reservations_resource_settings" })
|
|
517
|
-
], ResourceSettingsEntity);
|
|
201
|
+
// backend/reservations/capacity.ts
|
|
202
|
+
var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
|
|
518
203
|
|
|
519
204
|
// backend/time/zone.ts
|
|
520
205
|
var formatters = /* @__PURE__ */ new Map();
|
|
@@ -706,6 +391,386 @@ function isWithinBookableHours(hours, timeZone, start, end) {
|
|
|
706
391
|
);
|
|
707
392
|
}
|
|
708
393
|
|
|
394
|
+
// backend/reservations/rules.ts
|
|
395
|
+
var MINUTE_MS = 6e4;
|
|
396
|
+
var PAST_TOLERANCE_MS = MINUTE_MS;
|
|
397
|
+
function blockedSpan(booking) {
|
|
398
|
+
return {
|
|
399
|
+
start: new Date(booking.startTime.getTime() - booking.bufferBeforeMinutes * MINUTE_MS),
|
|
400
|
+
end: new Date(booking.endTime.getTime() + booking.bufferAfterMinutes * MINUTE_MS)
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function spansOverlap(a, b) {
|
|
404
|
+
return a.start.getTime() < b.end.getTime() && b.start.getTime() < a.end.getTime();
|
|
405
|
+
}
|
|
406
|
+
function checkBookingRules(args) {
|
|
407
|
+
const { settings, timeZone, start, end, now } = args;
|
|
408
|
+
if (Number.isNaN(start.getTime()) || Number.isNaN(end.getTime()) || end.getTime() <= start.getTime()) {
|
|
409
|
+
return new ReservationError("INVALID_RANGE", "The end must be after the start");
|
|
410
|
+
}
|
|
411
|
+
if (start.getTime() < now.getTime() - PAST_TOLERANCE_MS) {
|
|
412
|
+
return new ReservationError("IN_THE_PAST", "The booking starts in the past");
|
|
413
|
+
}
|
|
414
|
+
const step2 = settings.timeStepMinutes;
|
|
415
|
+
const durationMinutes = (end.getTime() - start.getTime()) / MINUTE_MS;
|
|
416
|
+
const onGrid = isWholeMinute(start) && isWholeMinute(end) && localMinutesOfDay(start, timeZone) % step2 === 0 && durationMinutes % step2 === 0;
|
|
417
|
+
if (!onGrid) {
|
|
418
|
+
return new ReservationError("OFF_TIME_STEP", `Start and duration must be a multiple of ${step2} minutes`);
|
|
419
|
+
}
|
|
420
|
+
if (durationMinutes < settings.minDurationMinutes) {
|
|
421
|
+
return new ReservationError("DURATION_TOO_SHORT", `The minimum duration is ${settings.minDurationMinutes} minutes`);
|
|
422
|
+
}
|
|
423
|
+
if (durationMinutes > settings.maxDurationMinutes) {
|
|
424
|
+
return new ReservationError("DURATION_TOO_LONG", `The maximum duration is ${settings.maxDurationMinutes} minutes`);
|
|
425
|
+
}
|
|
426
|
+
if (start.getTime() > now.getTime() + settings.maxAdvanceDays * 864e5) {
|
|
427
|
+
return new ReservationError(
|
|
428
|
+
"BEYOND_MAX_ADVANCE",
|
|
429
|
+
`Bookings can be made at most ${settings.maxAdvanceDays} days ahead`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
if (settings.minLeadMinutes > 0 && start.getTime() < now.getTime() + settings.minLeadMinutes * MINUTE_MS) {
|
|
433
|
+
return new ReservationError(
|
|
434
|
+
"LEAD_TIME_TOO_SHORT",
|
|
435
|
+
`Bookings must be made at least ${settings.minLeadMinutes} minutes before they start`
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
const span = blockedSpan({
|
|
439
|
+
startTime: start,
|
|
440
|
+
endTime: end,
|
|
441
|
+
bufferBeforeMinutes: settings.bufferBeforeMinutes,
|
|
442
|
+
bufferAfterMinutes: settings.bufferAfterMinutes
|
|
443
|
+
});
|
|
444
|
+
if (!isWithinBookableHours(settings.bookableHours, timeZone, span.start, span.end)) {
|
|
445
|
+
return new ReservationError("OUTSIDE_BOOKABLE_HOURS", "The booking is outside the bookable hours");
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// backend/reservations/capacity.ts
|
|
451
|
+
function sessionLimitOf(resource) {
|
|
452
|
+
return resource?.type === import_plugins_backend_sdk.ResourceType.Machine ? Math.max(1, resource.maxParallelSessions ?? 1) : 1;
|
|
453
|
+
}
|
|
454
|
+
function peakConcurrency(spans, window) {
|
|
455
|
+
const from = window.start.getTime();
|
|
456
|
+
const to = window.end.getTime();
|
|
457
|
+
const events = [];
|
|
458
|
+
for (const span of spans) {
|
|
459
|
+
const start = Math.max(span.start.getTime(), from);
|
|
460
|
+
const end = Math.min(span.end.getTime(), to);
|
|
461
|
+
if (start >= end) continue;
|
|
462
|
+
events.push([start, 1], [end, -1]);
|
|
463
|
+
}
|
|
464
|
+
events.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
465
|
+
let open = 0;
|
|
466
|
+
let peak = 0;
|
|
467
|
+
for (const [, delta] of events) {
|
|
468
|
+
open += delta;
|
|
469
|
+
peak = Math.max(peak, open);
|
|
470
|
+
}
|
|
471
|
+
return peak;
|
|
472
|
+
}
|
|
473
|
+
function exceedsCapacity(occupying, candidate, limit) {
|
|
474
|
+
return peakConcurrency(occupying, candidate) + 1 > limit;
|
|
475
|
+
}
|
|
476
|
+
function heldBookings(args) {
|
|
477
|
+
const at = args.at.getTime();
|
|
478
|
+
const seen = /* @__PURE__ */ new Set();
|
|
479
|
+
return args.confirmed.filter(
|
|
480
|
+
(b) => b.userId !== args.starterId && b.startTime.getTime() <= at && at < b.endTime.getTime() && !args.inSession.has(b.userId) && !args.overridden?.has(b.id)
|
|
481
|
+
).sort((a, b) => a.endTime.getTime() - b.endTime.getTime() || a.startTime.getTime() - b.startTime.getTime()).filter((b) => !seen.has(b.userId) && !!seen.add(b.userId));
|
|
482
|
+
}
|
|
483
|
+
function selectExcessBookings(occupying, limit, now) {
|
|
484
|
+
const nowMs = now.getTime();
|
|
485
|
+
const remaining = new Set(
|
|
486
|
+
occupying.map((booking) => ({ booking, ...spanMs(booking) })).filter((span) => span.end > nowMs)
|
|
487
|
+
);
|
|
488
|
+
const instants = [...new Set([...remaining].map((span) => Math.max(span.start, nowMs)))].sort((a, b) => a - b);
|
|
489
|
+
const cancelled = [];
|
|
490
|
+
for (const t of instants) {
|
|
491
|
+
for (let victim = excessAt(remaining, t, limit, nowMs); victim; victim = excessAt(remaining, t, limit, nowMs)) {
|
|
492
|
+
remaining.delete(victim);
|
|
493
|
+
cancelled.push(victim.booking);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return cancelled;
|
|
497
|
+
}
|
|
498
|
+
function spanMs(booking) {
|
|
499
|
+
const span = blockedSpan(booking);
|
|
500
|
+
return { start: span.start.getTime(), end: span.end.getTime() };
|
|
501
|
+
}
|
|
502
|
+
function excessAt(spans, t, limit, nowMs) {
|
|
503
|
+
const covering = [...spans].filter((span) => span.start <= t && t < span.end);
|
|
504
|
+
if (covering.length <= limit) return void 0;
|
|
505
|
+
return covering.filter(({ booking }) => booking.startTime.getTime() > nowMs && !booking.checkedInAt).sort((a, b) => b.booking.createdAt.getTime() - a.booking.createdAt.getTime() || b.booking.id - a.booking.id)[0];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// backend/reservations/directory.service.ts
|
|
509
|
+
var DirectoryService = class {
|
|
510
|
+
constructor(context) {
|
|
511
|
+
__publicField(this, "context", context);
|
|
512
|
+
}
|
|
513
|
+
async getResource(resourceId) {
|
|
514
|
+
const row = await this.context.hostData.resources.get(resourceId);
|
|
515
|
+
return row ? { id: row.id, name: row.name } : null;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Effective session limit (core's rule): 1 for doors, unknown resources and machines without parallel sessions.
|
|
519
|
+
* With `scope` it is read inside that transaction.
|
|
520
|
+
*/
|
|
521
|
+
async getSessionLimit(resourceId, scope) {
|
|
522
|
+
return await this.findSessionLimit(resourceId, scope) ?? 1;
|
|
523
|
+
}
|
|
524
|
+
/** Effective session limit, or null when the resource does not exist (anymore: deleted resources are not found). */
|
|
525
|
+
async findSessionLimit(resourceId, scope) {
|
|
526
|
+
const row = await this.context.hostData.resources.get(resourceId, scope);
|
|
527
|
+
return row ? sessionLimitOf(row) : null;
|
|
528
|
+
}
|
|
529
|
+
/** Running sessions on the resource, earliest first. */
|
|
530
|
+
getActiveSessions(resourceId) {
|
|
531
|
+
return this.context.resourceAccess.getActiveSessions(resourceId);
|
|
532
|
+
}
|
|
533
|
+
getResourceNames(resourceIds) {
|
|
534
|
+
return this.context.hostData.resources.getNames(resourceIds);
|
|
535
|
+
}
|
|
536
|
+
getUserNames(userIds) {
|
|
537
|
+
return this.context.hostData.users.getUsernames(userIds);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
DirectoryService = __decorateClass([
|
|
541
|
+
(0, import_common3.Injectable)(),
|
|
542
|
+
__decorateParam(0, (0, import_common3.Inject)(PLUGIN_CONTEXT))
|
|
543
|
+
], DirectoryService);
|
|
544
|
+
|
|
545
|
+
// backend/settings/settings-admin.service.ts
|
|
546
|
+
var import_common9 = require("@nestjs/common");
|
|
547
|
+
|
|
548
|
+
// backend/reservations/reservation.service.ts
|
|
549
|
+
var import_common8 = require("@nestjs/common");
|
|
550
|
+
|
|
551
|
+
// backend/ical/visibility.service.ts
|
|
552
|
+
var import_common4 = require("@nestjs/common");
|
|
553
|
+
var VisibilityService = class {
|
|
554
|
+
constructor(context, access) {
|
|
555
|
+
__publicField(this, "context", context);
|
|
556
|
+
__publicField(this, "access", access);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* The subset of `resourceIds` (existing resources) the user may see. A request actor's scope applies to the
|
|
560
|
+
* `resources.update` shortcut, as core applies an API token's scope to its group visibility.
|
|
561
|
+
*/
|
|
562
|
+
async filterVisible(subject, resourceIds) {
|
|
563
|
+
const ids = [...new Set(resourceIds)];
|
|
564
|
+
if (ids.length === 0) return [];
|
|
565
|
+
return this.context.hostData.resources.filterVisible(subjectUserId(subject), ids, {
|
|
566
|
+
seeAll: await this.access.hasUpdatePermission(subject)
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Whether the account exists, is not soft-deleted and not disabled. Deleting or disabling a user keeps
|
|
571
|
+
* their role rows, so anything acting on their behalf without a session (iCal feeds) must check this.
|
|
572
|
+
*/
|
|
573
|
+
isActiveAccount(userId) {
|
|
574
|
+
return this.context.hostData.users.isActive(userId);
|
|
575
|
+
}
|
|
576
|
+
/** The subset of `resourceIds` whose sessions always need a supervisor (`supervision_required`). */
|
|
577
|
+
resourceIdsRequiringSupervision(resourceIds) {
|
|
578
|
+
const ids = [...new Set(resourceIds)];
|
|
579
|
+
return ids.length === 0 ? Promise.resolve([]) : this.context.hostData.resources.filterRequiringSupervision(ids);
|
|
580
|
+
}
|
|
581
|
+
/** Ids of all resources in the given groups. */
|
|
582
|
+
resourceIdsOfGroups(groupIds) {
|
|
583
|
+
return this.context.hostData.resources.listIdsInGroups(groupIds);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
VisibilityService = __decorateClass([
|
|
587
|
+
(0, import_common4.Injectable)(),
|
|
588
|
+
__decorateParam(0, (0, import_common4.Inject)(PLUGIN_CONTEXT)),
|
|
589
|
+
__decorateParam(1, (0, import_common4.Inject)(AccessService))
|
|
590
|
+
], VisibilityService);
|
|
591
|
+
|
|
592
|
+
// backend/settings/resource-settings.service.ts
|
|
593
|
+
var import_common5 = require("@nestjs/common");
|
|
594
|
+
|
|
595
|
+
// backend/storage/index.ts
|
|
596
|
+
var import_plugins_backend_sdk7 = require("@attraccess/plugins-backend-sdk");
|
|
597
|
+
|
|
598
|
+
// backend/storage/global-settings-table.ts
|
|
599
|
+
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
600
|
+
var globalSettingsTable = (0, import_plugins_backend_sdk2.table)(
|
|
601
|
+
{ key: import_plugins_backend_sdk2.f.string(), value: import_plugins_backend_sdk2.f.text() },
|
|
602
|
+
{ primaryKey: ["key"], physicalName: "reservations_global_settings" }
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
// backend/storage/ical-feed-table.ts
|
|
606
|
+
var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
|
|
607
|
+
var icalFeedTable = (0, import_plugins_backend_sdk3.table)(
|
|
608
|
+
{
|
|
609
|
+
id: import_plugins_backend_sdk3.f.id(),
|
|
610
|
+
userId: import_plugins_backend_sdk3.f.integer(),
|
|
611
|
+
name: import_plugins_backend_sdk3.f.string(),
|
|
612
|
+
/** sha256 hex of the secret token; the token itself is never stored. */
|
|
613
|
+
tokenHash: import_plugins_backend_sdk3.f.string(),
|
|
614
|
+
/** First characters of the token, to recognise a feed in the UI. */
|
|
615
|
+
tokenPrefix: import_plugins_backend_sdk3.f.string().optional(),
|
|
616
|
+
/** JSON text, shape defined by the iCal service. */
|
|
617
|
+
selection: import_plugins_backend_sdk3.f.text(),
|
|
618
|
+
createdAt: import_plugins_backend_sdk3.f.timestamp(),
|
|
619
|
+
revokedAt: import_plugins_backend_sdk3.f.timestamp().optional(),
|
|
620
|
+
lastUsedAt: import_plugins_backend_sdk3.f.timestamp().optional()
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
physicalName: "reservations_ical_feed",
|
|
624
|
+
indexes: [
|
|
625
|
+
{ name: "IDX_reservations_ical_feed_user", fields: ["userId"] },
|
|
626
|
+
{ name: "UQ_reservations_ical_feed_token", fields: ["tokenHash"], unique: true }
|
|
627
|
+
]
|
|
628
|
+
}
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
// backend/storage/notice-table.ts
|
|
632
|
+
var import_plugins_backend_sdk4 = require("@attraccess/plugins-backend-sdk");
|
|
633
|
+
var noticeTable = (0, import_plugins_backend_sdk4.table)(
|
|
634
|
+
{
|
|
635
|
+
id: import_plugins_backend_sdk4.f.id(),
|
|
636
|
+
reservationId: import_plugins_backend_sdk4.f.integer(),
|
|
637
|
+
/** e.g. `maintenance`, `health_unhealthy`, `health_recovered`. */
|
|
638
|
+
kind: import_plugins_backend_sdk4.f.string(),
|
|
639
|
+
/** Disambiguator inside the kind, e.g. the maintenance id or health identifier; '' when unused. */
|
|
640
|
+
refKey: import_plugins_backend_sdk4.f.string().withDefault(""),
|
|
641
|
+
sentAt: import_plugins_backend_sdk4.f.timestamp()
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
physicalName: "reservations_notice",
|
|
645
|
+
indexes: [{ name: "UQ_reservations_notice", fields: ["reservationId", "kind", "refKey"], unique: true }]
|
|
646
|
+
}
|
|
647
|
+
);
|
|
648
|
+
|
|
649
|
+
// backend/storage/reservation-table.ts
|
|
650
|
+
var import_plugins_backend_sdk5 = require("@attraccess/plugins-backend-sdk");
|
|
651
|
+
var RESERVATION_STATUSES = [
|
|
652
|
+
"pending",
|
|
653
|
+
"confirmed",
|
|
654
|
+
"rejected",
|
|
655
|
+
"cancelled",
|
|
656
|
+
"expired",
|
|
657
|
+
"no_show",
|
|
658
|
+
"completed"
|
|
659
|
+
];
|
|
660
|
+
var REMINDER_FLAGS = [
|
|
661
|
+
"confirmationSentAt",
|
|
662
|
+
"stillNeededSentAt",
|
|
663
|
+
"reminder24hSentAt",
|
|
664
|
+
"handoverSentAt",
|
|
665
|
+
"overrunSentAt",
|
|
666
|
+
"noShowNotifiedAt",
|
|
667
|
+
"expiredNotifiedAt"
|
|
668
|
+
];
|
|
669
|
+
var reservationTable = (0, import_plugins_backend_sdk5.table)(
|
|
670
|
+
{
|
|
671
|
+
id: import_plugins_backend_sdk5.f.id(),
|
|
672
|
+
resourceId: import_plugins_backend_sdk5.f.integer(),
|
|
673
|
+
userId: import_plugins_backend_sdk5.f.integer(),
|
|
674
|
+
startTime: import_plugins_backend_sdk5.f.timestamp(),
|
|
675
|
+
endTime: import_plugins_backend_sdk5.f.timestamp(),
|
|
676
|
+
/** Snapshot of the resource's buffers when the booking was made. */
|
|
677
|
+
bufferBeforeMinutes: import_plugins_backend_sdk5.f.integer().withDefault(0),
|
|
678
|
+
bufferAfterMinutes: import_plugins_backend_sdk5.f.integer().withDefault(0),
|
|
679
|
+
status: import_plugins_backend_sdk5.f.string(),
|
|
680
|
+
/** Free text up to MAX_TEXT_LENGTH (500) characters, like both reasons; the legacy columns are unbounded. */
|
|
681
|
+
note: import_plugins_backend_sdk5.f.text().optional(),
|
|
682
|
+
createdAt: import_plugins_backend_sdk5.f.timestamp(),
|
|
683
|
+
endedEarlyAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
684
|
+
cancelledBy: import_plugins_backend_sdk5.f.integer().optional(),
|
|
685
|
+
cancelReason: import_plugins_backend_sdk5.f.text().optional(),
|
|
686
|
+
decidedBy: import_plugins_backend_sdk5.f.integer().optional(),
|
|
687
|
+
decisionReason: import_plugins_backend_sdk5.f.text().optional(),
|
|
688
|
+
decidedAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
689
|
+
checkedInAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
690
|
+
checkedInUsageId: import_plugins_backend_sdk5.f.integer().optional(),
|
|
691
|
+
/** The holder answered "still needed" / chose to keep the booking. */
|
|
692
|
+
keptAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
693
|
+
confirmationSentAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
694
|
+
stillNeededSentAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
695
|
+
reminder24hSentAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
696
|
+
handoverSentAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
697
|
+
overrunSentAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
698
|
+
noShowNotifiedAt: import_plugins_backend_sdk5.f.timestamp().optional(),
|
|
699
|
+
expiredNotifiedAt: import_plugins_backend_sdk5.f.timestamp().optional()
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
physicalName: "reservations_reservation",
|
|
703
|
+
// The per-resource indexes serve the slot queries; the status indexes the scheduler's cross-resource scans.
|
|
704
|
+
indexes: [
|
|
705
|
+
{ name: "IDX_reservations_reservation_slot", fields: ["resourceId", "status", "startTime", "endTime"] },
|
|
706
|
+
{ name: "IDX_reservations_reservation_user", fields: ["userId", "status"] },
|
|
707
|
+
{ name: "IDX_reservations_reservation_status_start", fields: ["status", "startTime"] },
|
|
708
|
+
{ name: "IDX_reservations_reservation_status_end", fields: ["status", "endTime"] }
|
|
709
|
+
]
|
|
710
|
+
}
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
// backend/storage/resource-settings-table.ts
|
|
714
|
+
var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
|
|
715
|
+
var resourceSettingsTable = (0, import_plugins_backend_sdk6.table)(
|
|
716
|
+
{
|
|
717
|
+
resourceId: import_plugins_backend_sdk6.f.integer(),
|
|
718
|
+
enabled: import_plugins_backend_sdk6.f.boolean().withDefault(false),
|
|
719
|
+
approvalRequired: import_plugins_backend_sdk6.f.boolean().withDefault(false),
|
|
720
|
+
timeStepMinutes: import_plugins_backend_sdk6.f.integer().withDefault(15),
|
|
721
|
+
minDurationMinutes: import_plugins_backend_sdk6.f.integer().withDefault(15),
|
|
722
|
+
maxDurationMinutes: import_plugins_backend_sdk6.f.integer().withDefault(240),
|
|
723
|
+
maxAdvanceDays: import_plugins_backend_sdk6.f.integer().withDefault(30),
|
|
724
|
+
minLeadMinutes: import_plugins_backend_sdk6.f.integer().withDefault(0),
|
|
725
|
+
bufferBeforeMinutes: import_plugins_backend_sdk6.f.integer().withDefault(0),
|
|
726
|
+
bufferAfterMinutes: import_plugins_backend_sdk6.f.integer().withDefault(0),
|
|
727
|
+
maxActiveBookingsPerUser: import_plugins_backend_sdk6.f.integer().withDefault(3),
|
|
728
|
+
whoCanBook: import_plugins_backend_sdk6.f.string().withDefault("can-start"),
|
|
729
|
+
confirmWindowMinutes: import_plugins_backend_sdk6.f.integer().withDefault(60),
|
|
730
|
+
checkInEnabled: import_plugins_backend_sdk6.f.boolean().withDefault(true),
|
|
731
|
+
checkInGraceMinutes: import_plugins_backend_sdk6.f.integer().withDefault(15),
|
|
732
|
+
earlyCheckInMinutes: import_plugins_backend_sdk6.f.integer().withDefault(15),
|
|
733
|
+
handoverReminderMinutes: import_plugins_backend_sdk6.f.integer().withDefault(15),
|
|
734
|
+
/** JSON text, see BookableHours. '{}' = bookable 24/7. */
|
|
735
|
+
bookableHours: import_plugins_backend_sdk6.f.text().withDefault("{}"),
|
|
736
|
+
updatedAt: import_plugins_backend_sdk6.f.timestamp()
|
|
737
|
+
},
|
|
738
|
+
{ primaryKey: ["resourceId"], physicalName: "reservations_resource_settings" }
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
// backend/storage/index.ts
|
|
742
|
+
var RESERVATIONS_LEGACY_MIGRATIONS = [
|
|
743
|
+
"CreateReservations1790000000000",
|
|
744
|
+
"AddReservationStatusIndexes1790000000001"
|
|
745
|
+
];
|
|
746
|
+
var tables = {
|
|
747
|
+
reservations: reservationTable,
|
|
748
|
+
resourceSettings: resourceSettingsTable,
|
|
749
|
+
globalSettings: globalSettingsTable,
|
|
750
|
+
icalFeeds: icalFeedTable,
|
|
751
|
+
notices: noticeTable
|
|
752
|
+
};
|
|
753
|
+
var reservationsStorage = (0, import_plugins_backend_sdk7.definePluginStorage)({
|
|
754
|
+
tables,
|
|
755
|
+
migrations: [
|
|
756
|
+
{
|
|
757
|
+
version: 1,
|
|
758
|
+
name: "baseline",
|
|
759
|
+
steps: Object.entries(tables).map(([name, definition]) => import_plugins_backend_sdk7.step.createTable(name, definition))
|
|
760
|
+
}
|
|
761
|
+
],
|
|
762
|
+
adoption: { legacyMigrations: RESERVATIONS_LEGACY_MIGRATIONS }
|
|
763
|
+
});
|
|
764
|
+
var opened = /* @__PURE__ */ new WeakMap();
|
|
765
|
+
function tablesOf(context) {
|
|
766
|
+
let tables2 = opened.get(context);
|
|
767
|
+
if (!tables2) {
|
|
768
|
+
tables2 = context.storage.open(reservationsStorage);
|
|
769
|
+
opened.set(context, tables2);
|
|
770
|
+
}
|
|
771
|
+
return tables2;
|
|
772
|
+
}
|
|
773
|
+
|
|
709
774
|
// backend/settings/settings.model.ts
|
|
710
775
|
var WHO_CAN_BOOK = ["can-start", "managers-only", "any-user"];
|
|
711
776
|
var DEFAULT_SETTINGS = {
|
|
@@ -755,12 +820,12 @@ function validateSettings(values) {
|
|
|
755
820
|
if (errors.some((error) => error.field === "timeStepMinutes") === false && 1440 % values.timeStepMinutes !== 0) {
|
|
756
821
|
errors.push({ field: "timeStepMinutes", message: "must divide 1440 so the grid repeats every day" });
|
|
757
822
|
}
|
|
758
|
-
const
|
|
823
|
+
const step2 = values.timeStepMinutes;
|
|
759
824
|
if (!errors.length) {
|
|
760
|
-
if (values.minDurationMinutes %
|
|
825
|
+
if (values.minDurationMinutes % step2 !== 0) {
|
|
761
826
|
errors.push({ field: "minDurationMinutes", message: "must be a multiple of the time step" });
|
|
762
827
|
}
|
|
763
|
-
if (values.maxDurationMinutes %
|
|
828
|
+
if (values.maxDurationMinutes % step2 !== 0) {
|
|
764
829
|
errors.push({ field: "maxDurationMinutes", message: "must be a multiple of the time step" });
|
|
765
830
|
}
|
|
766
831
|
if (values.maxDurationMinutes < values.minDurationMinutes) {
|
|
@@ -798,8 +863,8 @@ function settingsValues(settings) {
|
|
|
798
863
|
}
|
|
799
864
|
|
|
800
865
|
// backend/settings/resource-settings.service.ts
|
|
801
|
-
function
|
|
802
|
-
let bookableHours
|
|
866
|
+
function fromRow(row) {
|
|
867
|
+
let bookableHours;
|
|
803
868
|
try {
|
|
804
869
|
bookableHours = normalizeBookableHours(JSON.parse(row.bookableHours || "{}"));
|
|
805
870
|
} catch {
|
|
@@ -834,6 +899,9 @@ var ResourceSettingsService = class {
|
|
|
834
899
|
__publicField(this, "warmed", null);
|
|
835
900
|
__publicField(this, "warm", false);
|
|
836
901
|
}
|
|
902
|
+
get rows() {
|
|
903
|
+
return tablesOf(this.context).resourceSettings;
|
|
904
|
+
}
|
|
837
905
|
async onModuleInit() {
|
|
838
906
|
await this.warmUp().catch((error) => this.logger.error(`settings cache warm-up failed: ${String(error)}`));
|
|
839
907
|
}
|
|
@@ -858,9 +926,9 @@ var ResourceSettingsService = class {
|
|
|
858
926
|
return this.warmUp();
|
|
859
927
|
}
|
|
860
928
|
async loadAll() {
|
|
861
|
-
const rows = await this.
|
|
929
|
+
const rows = await this.rows.find();
|
|
862
930
|
this.cache.clear();
|
|
863
|
-
for (const row of rows) this.cache.set(row.resourceId,
|
|
931
|
+
for (const row of rows) this.cache.set(row.resourceId, fromRow(row));
|
|
864
932
|
}
|
|
865
933
|
/**
|
|
866
934
|
* Synchronous, database-free accessor for the pre-start hook. Resources without a row (and every
|
|
@@ -875,8 +943,8 @@ var ResourceSettingsService = class {
|
|
|
875
943
|
}
|
|
876
944
|
/** Authoritative read from the database (defaults when no row exists). */
|
|
877
945
|
async get(resourceId) {
|
|
878
|
-
const row = await this.
|
|
879
|
-
return row ?
|
|
946
|
+
const row = await this.rows.get(resourceId);
|
|
947
|
+
return row ? fromRow(row) : defaultSettings(resourceId);
|
|
880
948
|
}
|
|
881
949
|
/** Validates, persists and refreshes the cache. Throws a 400 `INVALID_SETTINGS` on invalid input. */
|
|
882
950
|
async update(resourceId, patch) {
|
|
@@ -887,13 +955,10 @@ var ResourceSettingsService = class {
|
|
|
887
955
|
throw new ReservationError("INVALID_SETTINGS", "Invalid reservation settings", { errors });
|
|
888
956
|
}
|
|
889
957
|
const merged = finalizeSettings(requested);
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
resourceId
|
|
893
|
-
|
|
894
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
895
|
-
});
|
|
896
|
-
await this.context.runSerialized((manager) => manager.getRepository(ResourceSettingsEntity).save(entity));
|
|
958
|
+
await this.rows.upsert(
|
|
959
|
+
{ ...merged, resourceId, bookableHours: JSON.stringify(merged.bookableHours), updatedAt: /* @__PURE__ */ new Date() },
|
|
960
|
+
{ conflictOn: ["resourceId"] }
|
|
961
|
+
);
|
|
897
962
|
const after = { resourceId, ...merged };
|
|
898
963
|
this.cache.set(resourceId, after);
|
|
899
964
|
return { before, after };
|
|
@@ -910,26 +975,6 @@ ResourceSettingsService = __decorateClass([
|
|
|
910
975
|
|
|
911
976
|
// backend/settings/global-settings.service.ts
|
|
912
977
|
var import_common6 = require("@nestjs/common");
|
|
913
|
-
|
|
914
|
-
// backend/entities/global-settings.entity.ts
|
|
915
|
-
var import_plugins_backend_sdk5 = require("@attraccess/plugins-backend-sdk");
|
|
916
|
-
var GlobalSettingsEntity = class {
|
|
917
|
-
constructor() {
|
|
918
|
-
__publicField(this, "key");
|
|
919
|
-
__publicField(this, "value");
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
__decorateClass([
|
|
923
|
-
(0, import_plugins_backend_sdk5.PrimaryColumn)({ type: "varchar" })
|
|
924
|
-
], GlobalSettingsEntity.prototype, "key", 2);
|
|
925
|
-
__decorateClass([
|
|
926
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "text" })
|
|
927
|
-
], GlobalSettingsEntity.prototype, "value", 2);
|
|
928
|
-
GlobalSettingsEntity = __decorateClass([
|
|
929
|
-
(0, import_plugins_backend_sdk5.Entity)({ name: "reservations_global_settings" })
|
|
930
|
-
], GlobalSettingsEntity);
|
|
931
|
-
|
|
932
|
-
// backend/settings/global-settings.service.ts
|
|
933
978
|
var TIMEZONE_KEY = "timezone";
|
|
934
979
|
var GlobalSettingsService = class {
|
|
935
980
|
constructor(context) {
|
|
@@ -939,7 +984,7 @@ var GlobalSettingsService = class {
|
|
|
939
984
|
/** The configured IANA timezone, or the server's when unset or no longer valid. Cached. */
|
|
940
985
|
async getTimezone() {
|
|
941
986
|
if (this.cachedTimezone) return this.cachedTimezone;
|
|
942
|
-
const row = await this.context
|
|
987
|
+
const row = await tablesOf(this.context).globalSettings.get(TIMEZONE_KEY);
|
|
943
988
|
this.cachedTimezone = row && isValidTimeZone(row.value) ? row.value : serverTimeZone();
|
|
944
989
|
return this.cachedTimezone;
|
|
945
990
|
}
|
|
@@ -951,10 +996,7 @@ var GlobalSettingsService = class {
|
|
|
951
996
|
throw new ReservationError("INVALID_TIMEZONE", `"${String(timezone)}" is not a valid IANA timezone`);
|
|
952
997
|
}
|
|
953
998
|
const before = await this.getTimezone();
|
|
954
|
-
|
|
955
|
-
entity.key = TIMEZONE_KEY;
|
|
956
|
-
entity.value = timezone;
|
|
957
|
-
await this.context.runSerialized((manager) => manager.getRepository(GlobalSettingsEntity).save(entity));
|
|
999
|
+
await tablesOf(this.context).globalSettings.upsert({ key: TIMEZONE_KEY, value: timezone }, { conflictOn: ["key"] });
|
|
958
1000
|
this.cachedTimezone = timezone;
|
|
959
1001
|
return { timezone, before };
|
|
960
1002
|
}
|
|
@@ -1067,182 +1109,177 @@ var KeyedMutex = class {
|
|
|
1067
1109
|
};
|
|
1068
1110
|
|
|
1069
1111
|
// backend/reservations/reservation.store.ts
|
|
1112
|
+
var import_plugins_backend_sdk8 = require("@attraccess/plugins-backend-sdk");
|
|
1070
1113
|
var import_common7 = require("@nestjs/common");
|
|
1071
|
-
|
|
1072
|
-
// backend/entities/notice.entity.ts
|
|
1073
|
-
var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
|
|
1074
|
-
var NoticeEntity = class {
|
|
1075
|
-
constructor() {
|
|
1076
|
-
__publicField(this, "id");
|
|
1077
|
-
__publicField(this, "reservationId");
|
|
1078
|
-
__publicField(this, "kind");
|
|
1079
|
-
__publicField(this, "refKey");
|
|
1080
|
-
__publicField(this, "sentAt");
|
|
1081
|
-
}
|
|
1082
|
-
};
|
|
1083
|
-
__decorateClass([
|
|
1084
|
-
(0, import_plugins_backend_sdk6.PrimaryGeneratedColumn)({ type: "integer" })
|
|
1085
|
-
], NoticeEntity.prototype, "id", 2);
|
|
1086
|
-
__decorateClass([
|
|
1087
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "integer" })
|
|
1088
|
-
], NoticeEntity.prototype, "reservationId", 2);
|
|
1089
|
-
__decorateClass([
|
|
1090
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar" })
|
|
1091
|
-
], NoticeEntity.prototype, "kind", 2);
|
|
1092
|
-
__decorateClass([
|
|
1093
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "varchar", default: "" })
|
|
1094
|
-
], NoticeEntity.prototype, "refKey", 2);
|
|
1095
|
-
__decorateClass([
|
|
1096
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "datetime" })
|
|
1097
|
-
], NoticeEntity.prototype, "sentAt", 2);
|
|
1098
|
-
NoticeEntity = __decorateClass([
|
|
1099
|
-
(0, import_plugins_backend_sdk6.Entity)({ name: "reservations_notice" }),
|
|
1100
|
-
(0, import_plugins_backend_sdk6.Index)("UQ_reservations_notice", ["reservationId", "kind", "refKey"], { unique: true })
|
|
1101
|
-
], NoticeEntity);
|
|
1102
|
-
|
|
1103
|
-
// backend/reservations/reservation.store.ts
|
|
1104
1114
|
var MAX_BUFFER_MINUTES = 1440;
|
|
1115
|
+
var LIVE = ["pending", "confirmed"];
|
|
1105
1116
|
var ReservationStore = class {
|
|
1106
1117
|
constructor(context) {
|
|
1107
1118
|
__publicField(this, "context", context);
|
|
1108
1119
|
}
|
|
1109
|
-
get
|
|
1110
|
-
return this.context
|
|
1120
|
+
get tables() {
|
|
1121
|
+
return tablesOf(this.context);
|
|
1122
|
+
}
|
|
1123
|
+
get reservations() {
|
|
1124
|
+
return this.tables.reservations;
|
|
1125
|
+
}
|
|
1126
|
+
find(where, options = {}) {
|
|
1127
|
+
return this.reservations.find(
|
|
1128
|
+
{ where, orderBy: [{ field: "startTime", direction: options.desc ? "desc" : "asc" }], limit: options.limit },
|
|
1129
|
+
{ scope: options.scope }
|
|
1130
|
+
);
|
|
1111
1131
|
}
|
|
1112
|
-
findById(id) {
|
|
1113
|
-
return this.
|
|
1132
|
+
async findById(id) {
|
|
1133
|
+
return await this.reservations.get(id);
|
|
1114
1134
|
}
|
|
1115
1135
|
/** Confirmed bookings of the resource that end after `from` and start before `to` (hook hot path). */
|
|
1116
1136
|
findConfirmedOverlapping(resourceId, from, to) {
|
|
1117
|
-
return this.
|
|
1137
|
+
return this.find({ resourceId, status: "confirmed", endTime: { gt: from }, startTime: { lt: to } });
|
|
1118
1138
|
}
|
|
1119
1139
|
/** Confirmed bookings running at `now` ([start, end)). */
|
|
1120
1140
|
findActiveForResource(resourceId, now) {
|
|
1121
|
-
return this.
|
|
1141
|
+
return this.find({ resourceId, status: "confirmed", startTime: { lte: now }, endTime: { gt: now } });
|
|
1122
1142
|
}
|
|
1123
1143
|
/** Confirmed bookings starting in (from, to] across all resources (reminders, handover, overrun). */
|
|
1124
1144
|
findUpcomingConfirmed(from, to) {
|
|
1125
|
-
return this.
|
|
1145
|
+
return this.find({ status: "confirmed", startTime: { gt: from, lte: to } });
|
|
1126
1146
|
}
|
|
1127
1147
|
/**
|
|
1128
1148
|
* Confirmed bookings that started and have no check-in yet (no-show step). Ended ones are included on
|
|
1129
1149
|
* purpose: a grace period reaching the end must still end in no_show, not in completed.
|
|
1130
1150
|
*/
|
|
1131
1151
|
findNoShowCandidates(now) {
|
|
1132
|
-
return this.
|
|
1152
|
+
return this.find({ status: "confirmed", startTime: { lte: now }, checkedInAt: null });
|
|
1133
1153
|
}
|
|
1134
1154
|
/** Confirmed bookings whose end has passed (to be marked completed). */
|
|
1135
1155
|
findConfirmedEnded(now) {
|
|
1136
|
-
return this.
|
|
1156
|
+
return this.find({ status: "confirmed", endTime: { lte: now } });
|
|
1137
1157
|
}
|
|
1138
1158
|
/** Pending bookings whose start has passed (to be expired). */
|
|
1139
1159
|
findPendingStarted(now) {
|
|
1140
|
-
return this.
|
|
1160
|
+
return this.find({ status: "pending", startTime: { lte: now } });
|
|
1141
1161
|
}
|
|
1142
1162
|
/** The holder's confirmed, not yet checked-in booking whose check-in window contains `now`. */
|
|
1143
|
-
findCheckInCandidate(userId, resourceId, now, earlyCheckInMinutes) {
|
|
1163
|
+
async findCheckInCandidate(userId, resourceId, now, earlyCheckInMinutes) {
|
|
1144
1164
|
const windowStart = new Date(now.getTime() + earlyCheckInMinutes * 6e4);
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1165
|
+
const [first] = await this.find(
|
|
1166
|
+
{
|
|
1167
|
+
resourceId,
|
|
1168
|
+
userId,
|
|
1169
|
+
status: "confirmed",
|
|
1170
|
+
checkedInAt: null,
|
|
1171
|
+
startTime: { lte: windowStart },
|
|
1172
|
+
endTime: { gt: now }
|
|
1173
|
+
},
|
|
1174
|
+
{ limit: 1 }
|
|
1175
|
+
);
|
|
1176
|
+
return first ?? null;
|
|
1150
1177
|
}
|
|
1151
1178
|
/** The holder's confirmed, not yet checked-in bookings overlapping [from, to) (a session that ran in them). */
|
|
1152
1179
|
findUncheckedOverlapping(userId, resourceId, from, to) {
|
|
1153
|
-
return this.
|
|
1180
|
+
return this.find({
|
|
1154
1181
|
resourceId,
|
|
1155
1182
|
userId,
|
|
1156
|
-
status: "confirmed"
|
|
1157
|
-
|
|
1183
|
+
status: "confirmed",
|
|
1184
|
+
checkedInAt: null,
|
|
1185
|
+
startTime: { lt: to },
|
|
1186
|
+
endTime: { gt: from }
|
|
1187
|
+
});
|
|
1158
1188
|
}
|
|
1159
1189
|
/** Pending + confirmed bookings of the resource overlapping [from, to) (maintenance/health notices). */
|
|
1160
1190
|
findLiveOverlapping(resourceId, from, to) {
|
|
1161
|
-
|
|
1162
|
-
resourceId,
|
|
1163
|
-
statuses: ["pending", "confirmed"]
|
|
1164
|
-
}).andWhere("r.endTime > :from", { from });
|
|
1165
|
-
if (to) query.andWhere("r.startTime < :to", { to });
|
|
1166
|
-
return query.orderBy("r.startTime", "ASC").getMany();
|
|
1167
|
-
}
|
|
1168
|
-
/** Candidates for buffer-aware overlap checks (pending + confirmed), exact filtering is done by the caller. */
|
|
1169
|
-
findOverlapCandidates(manager, resourceId, from, to) {
|
|
1170
|
-
return manager.getRepository(ReservationEntity).createQueryBuilder("r").where("r.resourceId = :resourceId AND r.status IN (:...statuses)", {
|
|
1191
|
+
return this.find({
|
|
1171
1192
|
resourceId,
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1193
|
+
status: { in: LIVE },
|
|
1194
|
+
endTime: { gt: from },
|
|
1195
|
+
...to ? { startTime: { lt: to } } : {}
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Candidates for buffer-aware overlap checks (pending + confirmed), exact filtering is done by the caller. Read
|
|
1200
|
+
* through the scope of the booking transaction.
|
|
1201
|
+
*/
|
|
1202
|
+
findOverlapCandidates(scope, resourceId, from, to) {
|
|
1203
|
+
return this.find(
|
|
1204
|
+
{
|
|
1205
|
+
resourceId,
|
|
1206
|
+
status: { in: LIVE },
|
|
1207
|
+
startTime: { lt: new Date(to.getTime() + MAX_BUFFER_MINUTES * 6e4) },
|
|
1208
|
+
endTime: { gt: new Date(from.getTime() - MAX_BUFFER_MINUTES * 6e4) }
|
|
1209
|
+
},
|
|
1210
|
+
{ scope }
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
/** Confirmed bookings running at `now` ([start, end)), read through the host's start transaction (capacity hook). */
|
|
1214
|
+
findRunningConfirmed(scope, resourceId, now) {
|
|
1215
|
+
return this.find({ resourceId, status: "confirmed", startTime: { lte: now }, endTime: { gt: now } }, { scope });
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Pending + confirmed bookings of the resource whose buffer-aware span can still matter at or after `now`
|
|
1219
|
+
* (the capacity reconciliation after a lowered limit).
|
|
1220
|
+
*/
|
|
1221
|
+
findOccupyingFrom(resourceId, now) {
|
|
1222
|
+
return this.findLiveOverlapping(resourceId, new Date(now.getTime() - MAX_BUFFER_MINUTES * 6e4), null);
|
|
1223
|
+
}
|
|
1224
|
+
countLiveForUser(scope, userId, resourceId, now) {
|
|
1225
|
+
return this.reservations.count({ userId, resourceId, status: { in: LIVE }, endTime: { gt: now } }, { scope });
|
|
1184
1226
|
}
|
|
1185
1227
|
/** Number of pending/confirmed bookings of the resource starting after `now` (a COUNT, no rows loaded). */
|
|
1186
1228
|
countFutureLive(resourceId, now) {
|
|
1187
|
-
return this.
|
|
1188
|
-
resourceId,
|
|
1189
|
-
statuses: ["pending", "confirmed"],
|
|
1190
|
-
now
|
|
1191
|
-
}).getCount();
|
|
1229
|
+
return this.reservations.count({ resourceId, status: { in: LIVE }, startTime: { gt: now } });
|
|
1192
1230
|
}
|
|
1193
1231
|
/**
|
|
1194
1232
|
* Applies `changes` to every pending/confirmed booking of the resource starting after `now`, in one
|
|
1195
|
-
*
|
|
1233
|
+
* transaction (select + one update with the same predicate), and returns the changed rows.
|
|
1196
1234
|
*/
|
|
1197
1235
|
cancelFutureLive(resourceId, now, changes) {
|
|
1198
|
-
const where =
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
const repo = manager.getRepository(ReservationEntity);
|
|
1202
|
-
const rows = await repo.createQueryBuilder("r").where("r.resourceId = :resourceId AND r.status IN (:...statuses) AND r.startTime > :now", parameters).getMany();
|
|
1236
|
+
const where = { resourceId, status: { in: LIVE }, startTime: { gt: now } };
|
|
1237
|
+
return this.context.persistence.transaction(async (scope) => {
|
|
1238
|
+
const rows = await this.find(where, { scope });
|
|
1203
1239
|
if (rows.length === 0) return [];
|
|
1204
|
-
await
|
|
1240
|
+
await this.reservations.update(where, changes, { scope });
|
|
1205
1241
|
return rows.map((row) => Object.assign(row, changes));
|
|
1206
1242
|
});
|
|
1207
1243
|
}
|
|
1208
1244
|
/** Bookings an iCal feed shows (pending, confirmed, ended) in [from, to), optionally only one holder's. */
|
|
1209
1245
|
findForCalendar(resourceIds, from, to, userId) {
|
|
1210
1246
|
if (resourceIds.length === 0) return Promise.resolve([]);
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1247
|
+
return this.find(
|
|
1248
|
+
{
|
|
1249
|
+
resourceId: { in: resourceIds },
|
|
1250
|
+
status: { in: ["pending", "confirmed", "completed"] },
|
|
1251
|
+
endTime: { gt: from },
|
|
1252
|
+
startTime: { lt: to },
|
|
1253
|
+
...userId !== void 0 ? { userId } : {}
|
|
1254
|
+
},
|
|
1255
|
+
{ limit: 5e3 }
|
|
1256
|
+
);
|
|
1217
1257
|
}
|
|
1218
1258
|
/** Occupying bookings (pending + confirmed) overlapping [from, to) for availability views. */
|
|
1219
1259
|
findOccupying(resourceId, from, to) {
|
|
1220
1260
|
return this.findLiveOverlapping(resourceId, from, to);
|
|
1221
1261
|
}
|
|
1222
1262
|
listForUser(userId, scope, now, status) {
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1225
|
-
query.andWhere("r.status IN (:...live) AND r.endTime > :now", { live: ["pending", "confirmed"], now });
|
|
1226
|
-
query.orderBy("r.startTime", "ASC");
|
|
1227
|
-
} else {
|
|
1228
|
-
query.andWhere("(r.status NOT IN (:...live) OR r.endTime <= :now)", { live: ["pending", "confirmed"], now });
|
|
1229
|
-
query.orderBy("r.startTime", "DESC");
|
|
1230
|
-
}
|
|
1231
|
-
if (status) query.andWhere("r.status = :status", { status });
|
|
1232
|
-
return query.take(200).getMany();
|
|
1263
|
+
const mine = scope === "upcoming" ? [{ userId, status: { in: LIVE }, endTime: { gt: now } }] : [{ userId }, { or: [{ status: { notIn: LIVE } }, { endTime: { lte: now } }] }];
|
|
1264
|
+
return this.find({ and: [...mine, ...status ? [{ status }] : []] }, { limit: 200, desc: scope === "past" });
|
|
1233
1265
|
}
|
|
1234
1266
|
async listManaged(filter) {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1267
|
+
if (filter.resourceIds && filter.resourceIds.length === 0) return { items: [], total: 0 };
|
|
1268
|
+
const where = {
|
|
1269
|
+
...filter.resourceIds ? { resourceId: { in: filter.resourceIds } } : {},
|
|
1270
|
+
...filter.status ? { status: filter.status } : {},
|
|
1271
|
+
...filter.from ? { endTime: { gt: filter.from } } : {},
|
|
1272
|
+
...filter.to ? { startTime: { lt: filter.to } } : {}
|
|
1273
|
+
};
|
|
1274
|
+
const [items, total] = await Promise.all([
|
|
1275
|
+
this.reservations.find({
|
|
1276
|
+
where,
|
|
1277
|
+
orderBy: [{ field: "startTime", direction: "desc" }],
|
|
1278
|
+
limit: filter.take,
|
|
1279
|
+
offset: filter.skip
|
|
1280
|
+
}),
|
|
1281
|
+
this.reservations.count(where)
|
|
1282
|
+
]);
|
|
1246
1283
|
return { items, total };
|
|
1247
1284
|
}
|
|
1248
1285
|
/**
|
|
@@ -1251,47 +1288,47 @@ var ReservationStore = class {
|
|
|
1251
1288
|
* was saved after the scheduler loaded the row).
|
|
1252
1289
|
*/
|
|
1253
1290
|
async transition(id, from, changes, options = {}) {
|
|
1254
|
-
const
|
|
1255
|
-
|
|
1256
|
-
|
|
1291
|
+
const affected = await this.reservations.update(
|
|
1292
|
+
{ id, status: { in: from }, ...options.notCheckedIn ? { checkedInAt: null } : {} },
|
|
1293
|
+
changes
|
|
1257
1294
|
);
|
|
1258
|
-
return
|
|
1295
|
+
return affected === 1;
|
|
1259
1296
|
}
|
|
1260
1297
|
/**
|
|
1261
|
-
* Claims a one-shot notification flag: `
|
|
1262
|
-
* Only the caller that gets `true` may send. Combine with the send inside the same transaction
|
|
1263
|
-
* the send can roll the claim back.
|
|
1298
|
+
* Claims a one-shot notification flag: sets `flag = at` where `id = ? AND flag IS NULL` (compare-and-set).
|
|
1299
|
+
* Only the caller that gets `true` may send. Combine with the send inside the same transaction (pass its
|
|
1300
|
+
* `scope`) when the send can roll the claim back.
|
|
1264
1301
|
*/
|
|
1265
|
-
async claimFlag(id, flag, at,
|
|
1302
|
+
async claimFlag(id, flag, at, scope) {
|
|
1266
1303
|
if (!REMINDER_FLAGS.includes(flag)) throw new Error(`Unknown reminder flag ${String(flag)}`);
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
|
|
1304
|
+
const affected = await this.reservations.update(
|
|
1305
|
+
{ id, [flag]: null },
|
|
1306
|
+
{ [flag]: at },
|
|
1307
|
+
{ scope }
|
|
1308
|
+
);
|
|
1309
|
+
return affected === 1;
|
|
1270
1310
|
}
|
|
1271
1311
|
/**
|
|
1272
1312
|
* Exactly-once notice claim for (reservation, kind, refKey): true when this call inserted the row,
|
|
1273
1313
|
* false when it already existed.
|
|
1274
1314
|
*/
|
|
1275
|
-
async claimNotice(reservationId, kind, refKey, at,
|
|
1276
|
-
const insert = (m) => m.getRepository(NoticeEntity).insert({ reservationId, kind, refKey, sentAt: at });
|
|
1315
|
+
async claimNotice(reservationId, kind, refKey, at, scope) {
|
|
1277
1316
|
try {
|
|
1278
|
-
await (
|
|
1317
|
+
await this.tables.notices.insert({ reservationId, kind, refKey, sentAt: at }, { scope });
|
|
1279
1318
|
return true;
|
|
1280
1319
|
} catch (error) {
|
|
1281
|
-
if (
|
|
1320
|
+
if (error instanceof import_plugins_backend_sdk8.PluginStorageUniqueViolation) return false;
|
|
1282
1321
|
throw error;
|
|
1283
1322
|
}
|
|
1284
1323
|
}
|
|
1285
1324
|
/** Notices of the given kind already claimed for these reservations. */
|
|
1286
1325
|
async findNotices(reservationIds, kind) {
|
|
1287
1326
|
if (reservationIds.length === 0) return [];
|
|
1288
|
-
return this.
|
|
1327
|
+
return this.tables.notices.find({ where: { kind, reservationId: { in: reservationIds } } });
|
|
1289
1328
|
}
|
|
1290
1329
|
/** Release a notice claim (when the send failed and should be retried next tick). */
|
|
1291
1330
|
async releaseNotice(reservationId, kind, refKey) {
|
|
1292
|
-
await this.
|
|
1293
|
-
(manager) => manager.getRepository(NoticeEntity).createQueryBuilder().delete().where("reservationId = :reservationId AND kind = :kind AND refKey = :refKey", { reservationId, kind, refKey }).execute()
|
|
1294
|
-
);
|
|
1331
|
+
await this.tables.notices.delete({ reservationId, kind, refKey });
|
|
1295
1332
|
}
|
|
1296
1333
|
};
|
|
1297
1334
|
ReservationStore = __decorateClass([
|
|
@@ -1299,62 +1336,6 @@ ReservationStore = __decorateClass([
|
|
|
1299
1336
|
__decorateParam(0, (0, import_common7.Inject)(PLUGIN_CONTEXT))
|
|
1300
1337
|
], ReservationStore);
|
|
1301
1338
|
|
|
1302
|
-
// backend/reservations/rules.ts
|
|
1303
|
-
var MINUTE_MS = 6e4;
|
|
1304
|
-
var PAST_TOLERANCE_MS = MINUTE_MS;
|
|
1305
|
-
function blockedSpan(booking) {
|
|
1306
|
-
return {
|
|
1307
|
-
start: new Date(booking.startTime.getTime() - booking.bufferBeforeMinutes * MINUTE_MS),
|
|
1308
|
-
end: new Date(booking.endTime.getTime() + booking.bufferAfterMinutes * MINUTE_MS)
|
|
1309
|
-
};
|
|
1310
|
-
}
|
|
1311
|
-
function spansOverlap(a, b) {
|
|
1312
|
-
return a.start.getTime() < b.end.getTime() && b.start.getTime() < a.end.getTime();
|
|
1313
|
-
}
|
|
1314
|
-
function checkBookingRules(args) {
|
|
1315
|
-
const { settings, timeZone, start, end, now } = args;
|
|
1316
|
-
if (Number.isNaN(start.getTime()) || Number.isNaN(end.getTime()) || end.getTime() <= start.getTime()) {
|
|
1317
|
-
return new ReservationError("INVALID_RANGE", "The end must be after the start");
|
|
1318
|
-
}
|
|
1319
|
-
if (start.getTime() < now.getTime() - PAST_TOLERANCE_MS) {
|
|
1320
|
-
return new ReservationError("IN_THE_PAST", "The booking starts in the past");
|
|
1321
|
-
}
|
|
1322
|
-
const step = settings.timeStepMinutes;
|
|
1323
|
-
const durationMinutes = (end.getTime() - start.getTime()) / MINUTE_MS;
|
|
1324
|
-
const onGrid = isWholeMinute(start) && isWholeMinute(end) && localMinutesOfDay(start, timeZone) % step === 0 && durationMinutes % step === 0;
|
|
1325
|
-
if (!onGrid) {
|
|
1326
|
-
return new ReservationError("OFF_TIME_STEP", `Start and duration must be a multiple of ${step} minutes`);
|
|
1327
|
-
}
|
|
1328
|
-
if (durationMinutes < settings.minDurationMinutes) {
|
|
1329
|
-
return new ReservationError("DURATION_TOO_SHORT", `The minimum duration is ${settings.minDurationMinutes} minutes`);
|
|
1330
|
-
}
|
|
1331
|
-
if (durationMinutes > settings.maxDurationMinutes) {
|
|
1332
|
-
return new ReservationError("DURATION_TOO_LONG", `The maximum duration is ${settings.maxDurationMinutes} minutes`);
|
|
1333
|
-
}
|
|
1334
|
-
if (start.getTime() > now.getTime() + settings.maxAdvanceDays * 864e5) {
|
|
1335
|
-
return new ReservationError(
|
|
1336
|
-
"BEYOND_MAX_ADVANCE",
|
|
1337
|
-
`Bookings can be made at most ${settings.maxAdvanceDays} days ahead`
|
|
1338
|
-
);
|
|
1339
|
-
}
|
|
1340
|
-
if (settings.minLeadMinutes > 0 && start.getTime() < now.getTime() + settings.minLeadMinutes * MINUTE_MS) {
|
|
1341
|
-
return new ReservationError(
|
|
1342
|
-
"LEAD_TIME_TOO_SHORT",
|
|
1343
|
-
`Bookings must be made at least ${settings.minLeadMinutes} minutes before they start`
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
const span = blockedSpan({
|
|
1347
|
-
startTime: start,
|
|
1348
|
-
endTime: end,
|
|
1349
|
-
bufferBeforeMinutes: settings.bufferBeforeMinutes,
|
|
1350
|
-
bufferAfterMinutes: settings.bufferAfterMinutes
|
|
1351
|
-
});
|
|
1352
|
-
if (!isWithinBookableHours(settings.bookableHours, timeZone, span.start, span.end)) {
|
|
1353
|
-
return new ReservationError("OUTSIDE_BOOKABLE_HOURS", "The booking is outside the bookable hours");
|
|
1354
|
-
}
|
|
1355
|
-
return null;
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
1339
|
// backend/reservations/reservation.service.ts
|
|
1359
1340
|
var MAX_TEXT_LENGTH = 500;
|
|
1360
1341
|
var DISABLED_REASON = "reservations disabled";
|
|
@@ -1455,8 +1436,7 @@ var ReservationService = class {
|
|
|
1455
1436
|
}
|
|
1456
1437
|
// ---------------------------------------------------------------- create
|
|
1457
1438
|
/**
|
|
1458
|
-
* Creates a booking. Creation is serialised per resource (in-process mutex + host
|
|
1459
|
-
* transaction), so of N concurrent overlapping requests exactly one succeeds. Throws a typed
|
|
1439
|
+
* Creates a booking. Creation is serialised per resource (in-process mutex + one host transaction scope), so of N concurrent overlapping requests exactly one succeeds. Throws a typed
|
|
1460
1440
|
* `ReservationError` (409 with `{ code, message }`) for every violated rule.
|
|
1461
1441
|
*/
|
|
1462
1442
|
async create(actor, input) {
|
|
@@ -1490,9 +1470,9 @@ var ReservationService = class {
|
|
|
1490
1470
|
if (maintenance.length > 0) {
|
|
1491
1471
|
throw new ReservationError("MAINTENANCE", "The resource is in maintenance during this time");
|
|
1492
1472
|
}
|
|
1493
|
-
return this.context.
|
|
1473
|
+
return this.context.persistence.transaction(async (scope) => {
|
|
1494
1474
|
if (settings.maxActiveBookingsPerUser > 0) {
|
|
1495
|
-
const live = await this.store.countLiveForUser(
|
|
1475
|
+
const live = await this.store.countLiveForUser(scope, actor.userId, input.resourceId, now);
|
|
1496
1476
|
if (live >= settings.maxActiveBookingsPerUser) {
|
|
1497
1477
|
throw new ReservationError(
|
|
1498
1478
|
"USER_BOOKING_LIMIT",
|
|
@@ -1500,23 +1480,33 @@ var ReservationService = class {
|
|
|
1500
1480
|
);
|
|
1501
1481
|
}
|
|
1502
1482
|
}
|
|
1503
|
-
const candidates = await this.store.findOverlapCandidates(
|
|
1504
|
-
|
|
1505
|
-
|
|
1483
|
+
const candidates = await this.store.findOverlapCandidates(scope, input.resourceId, span.start, span.end);
|
|
1484
|
+
const overlapping = candidates.filter((other) => spansOverlap(span, blockedSpan(other)));
|
|
1485
|
+
const limit = await this.directory.getSessionLimit(input.resourceId, scope);
|
|
1486
|
+
if (limit <= 1) {
|
|
1487
|
+
if (overlapping.length > 0) throw new ReservationError("OVERLAP", "The time is already reserved");
|
|
1488
|
+
} else {
|
|
1489
|
+
if (overlapping.some((other) => other.userId === actor.userId)) {
|
|
1490
|
+
throw new ReservationError("OWN_OVERLAP", "You already have a booking for this resource at that time");
|
|
1491
|
+
}
|
|
1492
|
+
if (exceedsCapacity(overlapping.map(blockedSpan), span, limit)) {
|
|
1493
|
+
throw new ReservationError("OVERLAP", "All slots are booked at that time");
|
|
1494
|
+
}
|
|
1506
1495
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1496
|
+
return await tablesOf(this.context).reservations.insert(
|
|
1497
|
+
{
|
|
1498
|
+
resourceId: input.resourceId,
|
|
1499
|
+
userId: actor.userId,
|
|
1500
|
+
startTime: input.startTime,
|
|
1501
|
+
endTime: input.endTime,
|
|
1502
|
+
bufferBeforeMinutes: settings.bufferBeforeMinutes,
|
|
1503
|
+
bufferAfterMinutes: settings.bufferAfterMinutes,
|
|
1504
|
+
status: settings.approvalRequired ? "pending" : "confirmed",
|
|
1505
|
+
note: cleanText(input.note),
|
|
1506
|
+
createdAt: now
|
|
1507
|
+
},
|
|
1508
|
+
{ scope }
|
|
1509
|
+
);
|
|
1520
1510
|
});
|
|
1521
1511
|
});
|
|
1522
1512
|
await this.audit.record(
|
|
@@ -1705,6 +1695,54 @@ var ReservationService = class {
|
|
|
1705
1695
|
if (cancelled.length > 0) this.invalidateViews(resourceId);
|
|
1706
1696
|
return cancelled.length;
|
|
1707
1697
|
}
|
|
1698
|
+
// ------------------------------------------------ lowered session limit
|
|
1699
|
+
/**
|
|
1700
|
+
* Cancels the bookings a lowered session limit left without a slot: the newest-created not-yet-started ones first,
|
|
1701
|
+
* until every instant fits (see `selectExcessBookings`). Running bookings are never touched. Takes the resource lock;
|
|
1702
|
+
* idempotent, so it also serves the start-up and scheduler reconciliation. A higher limit cancels nothing, and so
|
|
1703
|
+
* does a resource that no longer exists (deleted: its bookings are not over capacity).
|
|
1704
|
+
* `actorUserId` null = no user (system): the audit then attributes each cancellation to its holder.
|
|
1705
|
+
*/
|
|
1706
|
+
async cancelExcessBookings(resourceId, actorUserId) {
|
|
1707
|
+
return this.mutex.run(resourceId, async () => {
|
|
1708
|
+
const now = this.clock();
|
|
1709
|
+
const limit = await this.directory.findSessionLimit(resourceId);
|
|
1710
|
+
if (limit === null) return 0;
|
|
1711
|
+
const occupying = await this.store.findOccupyingFrom(resourceId, now);
|
|
1712
|
+
if (occupying.length <= limit) return 0;
|
|
1713
|
+
const cancelled = [];
|
|
1714
|
+
for (const booking of selectExcessBookings(occupying, limit, now)) {
|
|
1715
|
+
if (await this.cancelForCapacity(booking, actorUserId)) cancelled.push(booking);
|
|
1716
|
+
}
|
|
1717
|
+
this.notifyEach(
|
|
1718
|
+
"onRemoved",
|
|
1719
|
+
cancelled,
|
|
1720
|
+
(booking) => this.notifier.onRemoved(booking, { byUserId: null, reason: CAPACITY_REDUCED_REASON })
|
|
1721
|
+
);
|
|
1722
|
+
if (cancelled.length > 0) this.invalidateViews(resourceId);
|
|
1723
|
+
return cancelled.length;
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
/** Cancels one booking that lost its slot and audits it; false when it changed meanwhile. */
|
|
1727
|
+
async cancelForCapacity(booking, actorUserId) {
|
|
1728
|
+
const patch = { status: "cancelled", cancelledBy: actorUserId, cancelReason: CAPACITY_REDUCED_REASON };
|
|
1729
|
+
if (!await this.store.transition(booking.id, [booking.status], patch, { notCheckedIn: true })) return false;
|
|
1730
|
+
Object.assign(booking, patch);
|
|
1731
|
+
await this.audit.record(
|
|
1732
|
+
"cancelled",
|
|
1733
|
+
// The user who lowered the limit; without one, the holder (system principal).
|
|
1734
|
+
ReservationAudit.systemPrincipal(actorUserId ?? booking.userId),
|
|
1735
|
+
{ type: "reservation", id: booking.id },
|
|
1736
|
+
{
|
|
1737
|
+
resourceId: booking.resourceId,
|
|
1738
|
+
holderUserId: booking.userId,
|
|
1739
|
+
byManager: actorUserId !== null && actorUserId !== booking.userId,
|
|
1740
|
+
reason: CAPACITY_REDUCED_REASON,
|
|
1741
|
+
bulk: true
|
|
1742
|
+
}
|
|
1743
|
+
);
|
|
1744
|
+
return true;
|
|
1745
|
+
}
|
|
1708
1746
|
// ------------------------------------------- scheduler / hook transitions
|
|
1709
1747
|
async system(id, from, changes, action, options = {}) {
|
|
1710
1748
|
const changed = await this.store.transition(id, from, changes, options);
|
|
@@ -1741,10 +1779,11 @@ var ReservationService = class {
|
|
|
1741
1779
|
}
|
|
1742
1780
|
/** Holder started a session inside the check-in window. True when this call recorded the check-in. */
|
|
1743
1781
|
async markCheckedIn(id, usageId, at) {
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1782
|
+
const affected = await tablesOf(this.context).reservations.update(
|
|
1783
|
+
{ id, status: "confirmed", checkedInAt: null },
|
|
1784
|
+
{ checkedInAt: at, checkedInUsageId: usageId }
|
|
1746
1785
|
);
|
|
1747
|
-
const checkedIn =
|
|
1786
|
+
const checkedIn = affected === 1;
|
|
1748
1787
|
if (checkedIn) {
|
|
1749
1788
|
const booking = await this.store.findById(id);
|
|
1750
1789
|
if (booking) this.invalidateViews(booking.resourceId);
|
|
@@ -2242,6 +2281,7 @@ var AvailabilityDto = class {
|
|
|
2242
2281
|
__publicField(this, "isManager");
|
|
2243
2282
|
__publicField(this, "canBook");
|
|
2244
2283
|
__publicField(this, "rules");
|
|
2284
|
+
__publicField(this, "slots");
|
|
2245
2285
|
__publicField(this, "reservations");
|
|
2246
2286
|
__publicField(this, "maintenance");
|
|
2247
2287
|
}
|
|
@@ -2270,6 +2310,12 @@ __decorateClass([
|
|
|
2270
2310
|
__decorateClass([
|
|
2271
2311
|
(0, import_swagger.ApiProperty)({ type: () => PublicBookingRulesDto })
|
|
2272
2312
|
], AvailabilityDto.prototype, "rules", 2);
|
|
2313
|
+
__decorateClass([
|
|
2314
|
+
(0, import_swagger.ApiProperty)({
|
|
2315
|
+
type: Number,
|
|
2316
|
+
description: "Effective session limit N of the resource: how many bookings may overlap (each takes one slot). 1 for doors, machines without parallel sessions and while reservations are disabled"
|
|
2317
|
+
})
|
|
2318
|
+
], AvailabilityDto.prototype, "slots", 2);
|
|
2273
2319
|
__decorateClass([
|
|
2274
2320
|
(0, import_swagger.ApiProperty)({
|
|
2275
2321
|
type: () => [ReservationDto],
|
|
@@ -2618,7 +2664,7 @@ __decorateClass([
|
|
|
2618
2664
|
], ReservationSettingsController.prototype, "getGlobal", 1);
|
|
2619
2665
|
__decorateClass([
|
|
2620
2666
|
(0, import_common12.Put)("settings/global"),
|
|
2621
|
-
(0,
|
|
2667
|
+
(0, import_plugins_backend_sdk9.Auth)("system.settings.manage"),
|
|
2622
2668
|
(0, import_swagger4.ApiOperation)({ summary: "Update plugin-wide settings (requires system.settings.manage)" }),
|
|
2623
2669
|
(0, import_swagger4.ApiBody)({ type: UpdateGlobalSettingsBody }),
|
|
2624
2670
|
(0, import_swagger4.ApiOkResponse)({ type: GlobalSettingsDto }),
|
|
@@ -2628,7 +2674,7 @@ __decorateClass([
|
|
|
2628
2674
|
], ReservationSettingsController.prototype, "updateGlobal", 1);
|
|
2629
2675
|
ReservationSettingsController = __decorateClass([
|
|
2630
2676
|
(0, import_swagger4.ApiTags)("Reservations"),
|
|
2631
|
-
(0,
|
|
2677
|
+
(0, import_plugins_backend_sdk9.Auth)(),
|
|
2632
2678
|
(0, import_common12.Controller)("reservations"),
|
|
2633
2679
|
__decorateParam(0, (0, import_common12.Inject)(SettingsAdminService)),
|
|
2634
2680
|
__decorateParam(1, (0, import_common12.Inject)(AccessService)),
|
|
@@ -2636,7 +2682,7 @@ ReservationSettingsController = __decorateClass([
|
|
|
2636
2682
|
], ReservationSettingsController);
|
|
2637
2683
|
|
|
2638
2684
|
// backend/events/event-handlers.service.ts
|
|
2639
|
-
var
|
|
2685
|
+
var import_plugins_backend_sdk10 = require("@attraccess/plugins-backend-sdk");
|
|
2640
2686
|
var import_common16 = require("@nestjs/common");
|
|
2641
2687
|
|
|
2642
2688
|
// backend/hooks/pending-decisions.ts
|
|
@@ -2688,7 +2734,6 @@ PendingDecisionStore = __decorateClass([
|
|
|
2688
2734
|
], PendingDecisionStore);
|
|
2689
2735
|
|
|
2690
2736
|
// backend/notifications/host-info.service.ts
|
|
2691
|
-
var import_plugins_backend_sdk8 = require("@attraccess/plugins-backend-sdk");
|
|
2692
2737
|
var import_common14 = require("@nestjs/common");
|
|
2693
2738
|
var MANAGER_PERMISSIONS = ["resources.update"];
|
|
2694
2739
|
function normalizeLanguage(locale, fallback) {
|
|
@@ -2702,9 +2747,7 @@ var HostInfoService = class {
|
|
|
2702
2747
|
__publicField(this, "context", context);
|
|
2703
2748
|
}
|
|
2704
2749
|
async setting(key) {
|
|
2705
|
-
|
|
2706
|
-
const value = row?.value?.trim();
|
|
2707
|
-
return value ? value : null;
|
|
2750
|
+
return this.context.hostData.settings.getApp(key);
|
|
2708
2751
|
}
|
|
2709
2752
|
/**
|
|
2710
2753
|
* The application's public URL, the same setting core uses for links in emails (`app/backend_url`),
|
|
@@ -2724,17 +2767,17 @@ var HostInfoService = class {
|
|
|
2724
2767
|
const ids = [...new Set(userIds)];
|
|
2725
2768
|
const result = /* @__PURE__ */ new Map();
|
|
2726
2769
|
if (ids.length === 0) return result;
|
|
2727
|
-
const [fallback,
|
|
2770
|
+
const [fallback, locales] = await Promise.all([
|
|
2728
2771
|
this.getDefaultLanguage(),
|
|
2729
|
-
this.context.
|
|
2772
|
+
this.context.hostData.users.getLocales(ids)
|
|
2730
2773
|
]);
|
|
2731
|
-
for (const
|
|
2774
|
+
for (const [id, locale] of locales) result.set(id, normalizeLanguage(locale, fallback));
|
|
2732
2775
|
for (const id of ids) if (!result.has(id)) result.set(id, fallback);
|
|
2733
2776
|
return result;
|
|
2734
2777
|
}
|
|
2735
2778
|
/** Health entries of the resource that are currently unhealthy (a resource may carry several). */
|
|
2736
2779
|
countUnhealthyEntries(resourceId) {
|
|
2737
|
-
return this.context.
|
|
2780
|
+
return this.context.hostData.resources.countUnhealthyEntries(resourceId);
|
|
2738
2781
|
}
|
|
2739
2782
|
/**
|
|
2740
2783
|
* Users managing the resource: everyone holding `resources.update` (role join, one query; the global
|
|
@@ -2745,10 +2788,10 @@ var HostInfoService = class {
|
|
|
2745
2788
|
*/
|
|
2746
2789
|
async managerIdsOf(resourceId) {
|
|
2747
2790
|
const [introducers, permitted] = await Promise.all([
|
|
2748
|
-
this.context.
|
|
2749
|
-
this.context.
|
|
2791
|
+
this.context.hostData.resources.listIntroducerUserIds(resourceId),
|
|
2792
|
+
this.context.hostData.users.listIdsWithAnyPermission(MANAGER_PERMISSIONS)
|
|
2750
2793
|
]);
|
|
2751
|
-
return [
|
|
2794
|
+
return [.../* @__PURE__ */ new Set([...introducers, ...permitted])];
|
|
2752
2795
|
}
|
|
2753
2796
|
};
|
|
2754
2797
|
HostInfoService = __decorateClass([
|
|
@@ -2957,13 +3000,17 @@ function endedEarlyByManager(m, r) {
|
|
|
2957
3000
|
severity: "warning"
|
|
2958
3001
|
};
|
|
2959
3002
|
}
|
|
2960
|
-
function removed(m, r) {
|
|
3003
|
+
function removed(m, r, capacityReduced = false) {
|
|
2961
3004
|
const { lang, resourceName } = m;
|
|
2962
3005
|
return {
|
|
2963
|
-
email: { template: "removed", variables: bookingVariables(m, r) },
|
|
3006
|
+
email: { template: "removed", variables: { ...bookingVariables(m, r), removal: { capacity: capacityReduced } } },
|
|
2964
3007
|
title: pick(lang, `Booking removed: ${resourceName}`, `Reservierung entfernt: ${resourceName}`),
|
|
2965
3008
|
lines: [
|
|
2966
|
-
pick(
|
|
3009
|
+
capacityReduced ? pick(
|
|
3010
|
+
lang,
|
|
3011
|
+
`${resourceName} now allows fewer parallel bookings, so your booking (${when(m, r)}) no longer fit and was cancelled.`,
|
|
3012
|
+
`F\xFCr ${resourceName} sind jetzt weniger parallele Buchungen m\xF6glich, daher passte deine Reservierung (${when(m, r)}) nicht mehr und wurde storniert.`
|
|
3013
|
+
) : pick(
|
|
2967
3014
|
lang,
|
|
2968
3015
|
`Reservations were switched off for ${resourceName}, so your booking (${when(m, r)}) was cancelled.`,
|
|
2969
3016
|
`Reservierungen wurden f\xFCr ${resourceName} deaktiviert, daher wurde deine Reservierung (${when(m, r)}) storniert.`
|
|
@@ -3332,13 +3379,14 @@ var ReservationNotifications = class {
|
|
|
3332
3379
|
);
|
|
3333
3380
|
}
|
|
3334
3381
|
async onRemoved(r, context) {
|
|
3335
|
-
|
|
3382
|
+
const capacityReduced = context.reason === CAPACITY_REDUCED_REASON;
|
|
3383
|
+
if (!capacityReduced && context.byUserId === r.userId) return;
|
|
3336
3384
|
await this.send(
|
|
3337
3385
|
"bookings",
|
|
3338
3386
|
r.resourceId,
|
|
3339
3387
|
[r.userId],
|
|
3340
3388
|
`reservations:removed:${r.id}`,
|
|
3341
|
-
(m) => removed(m, r)
|
|
3389
|
+
(m) => removed(m, r, capacityReduced)
|
|
3342
3390
|
);
|
|
3343
3391
|
}
|
|
3344
3392
|
// ------------------------------------- scheduler / event notifications
|
|
@@ -3467,7 +3515,7 @@ ReservationNotifications = __decorateClass([
|
|
|
3467
3515
|
var HOUR_MS = 36e5;
|
|
3468
3516
|
var DAY_MS2 = 24 * HOUR_MS;
|
|
3469
3517
|
var ReservationEventHandlers = class {
|
|
3470
|
-
constructor(context, store, reservations, settings, access, notifications, hostInfo, decisions, clock) {
|
|
3518
|
+
constructor(context, store, reservations, settings, access, notifications, hostInfo, decisions, clock, directory) {
|
|
3471
3519
|
__publicField(this, "context", context);
|
|
3472
3520
|
__publicField(this, "store", store);
|
|
3473
3521
|
__publicField(this, "reservations", reservations);
|
|
@@ -3477,6 +3525,7 @@ var ReservationEventHandlers = class {
|
|
|
3477
3525
|
__publicField(this, "hostInfo", hostInfo);
|
|
3478
3526
|
__publicField(this, "decisions", decisions);
|
|
3479
3527
|
__publicField(this, "clock", clock);
|
|
3528
|
+
__publicField(this, "directory", directory);
|
|
3480
3529
|
__publicField(this, "logger", new import_common16.Logger("ReservationsEvents"));
|
|
3481
3530
|
__publicField(this, "subscriptions", []);
|
|
3482
3531
|
}
|
|
@@ -3497,11 +3546,12 @@ var ReservationEventHandlers = class {
|
|
|
3497
3546
|
}
|
|
3498
3547
|
});
|
|
3499
3548
|
this.subscriptions = [
|
|
3500
|
-
on(
|
|
3501
|
-
on(
|
|
3502
|
-
on(
|
|
3503
|
-
on(
|
|
3504
|
-
on(
|
|
3549
|
+
on(import_plugins_backend_sdk10.SystemEvent.RESOURCE_USAGE_SESSION_STARTED, (p) => this.onSessionStart(p)),
|
|
3550
|
+
on(import_plugins_backend_sdk10.SystemEvent.RESOURCE_USAGE_SESSION_TAKEN_OVER, (p) => this.onSessionStart(p)),
|
|
3551
|
+
on(import_plugins_backend_sdk10.SystemEvent.RESOURCE_USAGE_SESSION_ENDED, (p) => this.onSessionEnded(p)),
|
|
3552
|
+
on(import_plugins_backend_sdk10.SystemEvent.MAINTENANCE_CHANGED, (p) => this.onMaintenance(p)),
|
|
3553
|
+
on(import_plugins_backend_sdk10.SystemEvent.RESOURCE_HEALTH_CHANGED, (p) => this.onHealth(p)),
|
|
3554
|
+
on(import_plugins_backend_sdk10.SystemEvent.RESOURCE_SESSION_LIMIT_CHANGED, (p) => this.onSessionLimitChanged(p))
|
|
3505
3555
|
];
|
|
3506
3556
|
}
|
|
3507
3557
|
unsubscribe() {
|
|
@@ -3525,7 +3575,7 @@ var ReservationEventHandlers = class {
|
|
|
3525
3575
|
settings.earlyCheckInMinutes
|
|
3526
3576
|
);
|
|
3527
3577
|
if (candidate) await this.reservations.markCheckedIn(candidate.id, usageId, startTime);
|
|
3528
|
-
const active =
|
|
3578
|
+
const active = await this.overriddenBooking(resourceId, userId, startTime);
|
|
3529
3579
|
if (!active) return;
|
|
3530
3580
|
if (!await this.access.isManager(userId, resourceId)) return;
|
|
3531
3581
|
if (!await this.store.claimNotice(active.id, "override_start", String(usageId), this.clock())) return;
|
|
@@ -3537,6 +3587,24 @@ var ReservationEventHandlers = class {
|
|
|
3537
3587
|
);
|
|
3538
3588
|
await this.notifications.notifyOverrideStart(active, userId);
|
|
3539
3589
|
}
|
|
3590
|
+
/**
|
|
3591
|
+
* The booking a start of `userId` overrode, if any. On a single-slot machine every running booking of someone else.
|
|
3592
|
+
* On a shared machine anyone may start while a slot is free, so only a start that took a held slot overrode one:
|
|
3593
|
+
* the other sessions plus the slots held at the start fill the machine. It names the first held booking, the one the
|
|
3594
|
+
* gate's override question asks about first.
|
|
3595
|
+
*/
|
|
3596
|
+
async overriddenBooking(resourceId, userId, startTime) {
|
|
3597
|
+
const running = await this.store.findActiveForResource(resourceId, startTime);
|
|
3598
|
+
const active = running.find((r) => r.userId !== userId);
|
|
3599
|
+
if (!active) return void 0;
|
|
3600
|
+
const limit = await this.directory.getSessionLimit(resourceId);
|
|
3601
|
+
if (limit <= 1) return active;
|
|
3602
|
+
if (running.some((r) => r.userId === userId)) return void 0;
|
|
3603
|
+
const sessions = (await this.directory.getActiveSessions(resourceId)).filter((s) => s.userId !== userId);
|
|
3604
|
+
const inSession = new Set(sessions.map((session) => session.userId));
|
|
3605
|
+
const held = heldBookings({ confirmed: running, starterId: userId, inSession, at: startTime });
|
|
3606
|
+
return sessions.length + held.length >= limit ? held[0] : void 0;
|
|
3607
|
+
}
|
|
3540
3608
|
/**
|
|
3541
3609
|
* A session ended. If it ran inside the holder's own booking without a check-in (it started before the
|
|
3542
3610
|
* early check-in window and ended before the no-show deadline), it counts as the check-in. When the holder
|
|
@@ -3560,6 +3628,15 @@ var ReservationEventHandlers = class {
|
|
|
3560
3628
|
const own = (await this.store.findActiveForResource(event.resourceId, now)).find((r) => r.userId === event.userId);
|
|
3561
3629
|
if (own) this.decisions.record(event.userId, event.resourceId, own.id, now.getTime());
|
|
3562
3630
|
}
|
|
3631
|
+
// ------------------------------------------------------------ session limit
|
|
3632
|
+
/**
|
|
3633
|
+
* The machine lost slots: cancel the newest not-yet-started bookings that no longer fit (see
|
|
3634
|
+
* `ReservationService.cancelExcessBookings`). A higher limit cancels nothing.
|
|
3635
|
+
*/
|
|
3636
|
+
async onSessionLimitChanged(event) {
|
|
3637
|
+
if (event.newLimit >= event.previousLimit) return;
|
|
3638
|
+
await this.reservations.cancelExcessBookings(event.resourceId, event.actorUserId);
|
|
3639
|
+
}
|
|
3563
3640
|
// ------------------------------------------------------------- maintenance
|
|
3564
3641
|
/**
|
|
3565
3642
|
* Notifies each holder of bookings overlapping the maintenance window once per maintenance: every affected booking
|
|
@@ -3641,7 +3718,8 @@ ReservationEventHandlers = __decorateClass([
|
|
|
3641
3718
|
__decorateParam(5, (0, import_common16.Inject)(ReservationNotifications)),
|
|
3642
3719
|
__decorateParam(6, (0, import_common16.Inject)(HostInfoService)),
|
|
3643
3720
|
__decorateParam(7, (0, import_common16.Inject)(PendingDecisionStore)),
|
|
3644
|
-
__decorateParam(8, (0, import_common16.Inject)(RESERVATION_CLOCK))
|
|
3721
|
+
__decorateParam(8, (0, import_common16.Inject)(RESERVATION_CLOCK)),
|
|
3722
|
+
__decorateParam(9, (0, import_common16.Inject)(DirectoryService))
|
|
3645
3723
|
], ReservationEventHandlers);
|
|
3646
3724
|
|
|
3647
3725
|
// backend/hooks/pending-decision.service.ts
|
|
@@ -3819,6 +3897,7 @@ var ReservationQueryService = class {
|
|
|
3819
3897
|
isManager: false,
|
|
3820
3898
|
canBook: canBook2,
|
|
3821
3899
|
rules,
|
|
3900
|
+
slots: 1,
|
|
3822
3901
|
reservations: [],
|
|
3823
3902
|
maintenance: []
|
|
3824
3903
|
};
|
|
@@ -3830,7 +3909,8 @@ var ReservationQueryService = class {
|
|
|
3830
3909
|
end: new Date(to.getTime() + settings.bufferAfterMinutes * MINUTE_MS2)
|
|
3831
3910
|
};
|
|
3832
3911
|
const margin = MAX_BUFFER_MINUTES * MINUTE_MS2;
|
|
3833
|
-
const [candidates, windows] = await Promise.all([
|
|
3912
|
+
const [slots, candidates, windows] = await Promise.all([
|
|
3913
|
+
this.directory.getSessionLimit(resourceId),
|
|
3834
3914
|
this.store.findOccupying(
|
|
3835
3915
|
resourceId,
|
|
3836
3916
|
new Date(span.start.getTime() - margin),
|
|
@@ -3846,6 +3926,7 @@ var ReservationQueryService = class {
|
|
|
3846
3926
|
isManager,
|
|
3847
3927
|
canBook,
|
|
3848
3928
|
rules,
|
|
3929
|
+
slots,
|
|
3849
3930
|
reservations: await this.present(actor, rows, /* @__PURE__ */ new Map([[resourceId, isManager]])),
|
|
3850
3931
|
maintenance: windows.map((window) => ({
|
|
3851
3932
|
startTime: window.startTime.toISOString(),
|
|
@@ -3860,8 +3941,7 @@ var ReservationQueryService = class {
|
|
|
3860
3941
|
async canBook(actor, resourceId, settings, isManager) {
|
|
3861
3942
|
const result = await this.access.canBook(actor, resourceId, settings, isManager);
|
|
3862
3943
|
if (!result.allowed || settings.maxActiveBookingsPerUser === 0) return result;
|
|
3863
|
-
const
|
|
3864
|
-
const live = await this.store.countLiveForUser(manager, actor.userId, resourceId, this.clock());
|
|
3944
|
+
const live = await this.store.countLiveForUser(void 0, actor.userId, resourceId, this.clock());
|
|
3865
3945
|
return live >= settings.maxActiveBookingsPerUser ? { allowed: false, reason: "USER_BOOKING_LIMIT" } : result;
|
|
3866
3946
|
}
|
|
3867
3947
|
};
|
|
@@ -3916,9 +3996,9 @@ PendingDecisionService = __decorateClass([
|
|
|
3916
3996
|
var import_common19 = require("@nestjs/common");
|
|
3917
3997
|
|
|
3918
3998
|
// backend/reader-ui/texts.ts
|
|
3919
|
-
var
|
|
3999
|
+
var import_plugins_backend_sdk11 = require("@attraccess/plugins-backend-sdk");
|
|
3920
4000
|
var READER_NAME_MAX = 16;
|
|
3921
|
-
var ROW_MAX =
|
|
4001
|
+
var ROW_MAX = import_plugins_backend_sdk11.READER_UI_LIMITS.maxListRowChars;
|
|
3922
4002
|
function fit(text, max) {
|
|
3923
4003
|
return text.length <= max ? text : text.slice(0, max).trimEnd();
|
|
3924
4004
|
}
|
|
@@ -3987,6 +4067,8 @@ var readerTexts = {
|
|
|
3987
4067
|
return long.length <= ROW_MAX ? long : fit(pick(c.lang, `Res., check-in ${at}`, `Res., Check-in ${at}`), ROW_MAX);
|
|
3988
4068
|
},
|
|
3989
4069
|
rowReservedUntil: (end, c) => fit(pick(c.lang, `Reserved until ${readerTime(end, c)}`, `Reserviert bis ${readerTime(end, c)}`), ROW_MAX),
|
|
4070
|
+
/** Shared machine, bookings run but slots remain: "2/3 reserved" (≤ 24 characters). */
|
|
4071
|
+
rowSlotsReserved: (reserved, slots, c) => fit(pick(c.lang, `${reserved}/${slots} reserved`, `${reserved}/${slots} reserviert`), ROW_MAX),
|
|
3990
4072
|
rowOwnUntil: (end, c) => {
|
|
3991
4073
|
const until = readerTime(end, c);
|
|
3992
4074
|
const long = pick(c.lang, `Your booking until ${until}`, `Deine Buchung bis ${until}`);
|
|
@@ -4009,6 +4091,7 @@ var readerTexts = {
|
|
|
4009
4091
|
) : [pick(c.lang, `then reserved until ${readerTime(end, c)}`, `dann reserviert bis ${readerTime(end, c)}`)]
|
|
4010
4092
|
],
|
|
4011
4093
|
reserved: (start, end, c, holder) => holder ? named(pick(c.lang, `Reserved by ${holder}`, `Reserviert von ${holder}`), range(start, end, c)) : [pick(c.lang, `Reserved ${range(start, end, c)}`, `Reserviert ${range(start, end, c)}`)],
|
|
4094
|
+
slotsReserved: (reserved, slots, c) => pick(c.lang, `${reserved} of ${slots} slots reserved`, `${reserved} von ${slots} Pl\xE4tzen reserviert`),
|
|
4012
4095
|
own: (start, end, c) => pick(c.lang, `Your booking ${range(start, end, c)}`, `Deine Buchung ${range(start, end, c)}`),
|
|
4013
4096
|
/** Its own line under the booking, so the parenthesis never starts a wrapped line by itself. */
|
|
4014
4097
|
checkInLine: (deadline, c) => pick(c.lang, `(check in by ${readerTime(deadline, c)})`, `(Check-in bis ${readerTime(deadline, c)})`),
|
|
@@ -4068,6 +4151,11 @@ async function startBlockedQuery(ctx) {
|
|
|
4068
4151
|
const deadline = hookDeadline();
|
|
4069
4152
|
return (await resolveHookServices(deadline)).preStart.evaluateStartBlocked(ctx, deadline);
|
|
4070
4153
|
}
|
|
4154
|
+
var startCapacityHook = async (ctx) => {
|
|
4155
|
+
const deadline = hookDeadline();
|
|
4156
|
+
const { startCapacity } = await resolveHookServices(deadline);
|
|
4157
|
+
return startCapacity ? startCapacity.evaluate(ctx, deadline) : { heldSlots: 0 };
|
|
4158
|
+
};
|
|
4071
4159
|
var readerUiProvider = {
|
|
4072
4160
|
async getSlotContributions(ctx) {
|
|
4073
4161
|
const deadline = hookDeadline();
|
|
@@ -4085,6 +4173,14 @@ var MINUTE_MS3 = 6e4;
|
|
|
4085
4173
|
var MAX_HOLDER_NAME_CHARS = 40;
|
|
4086
4174
|
var reservationStepKey = (id) => `reservation-${id}`;
|
|
4087
4175
|
var overrideStepKey = (id) => `override-${id}`;
|
|
4176
|
+
function overriddenBookingIds(stepKeys) {
|
|
4177
|
+
return new Set(
|
|
4178
|
+
stepKeys.flatMap((key) => {
|
|
4179
|
+
const match = /^override-(\d+)$/.exec(key);
|
|
4180
|
+
return match ? [Number(match[1])] : [];
|
|
4181
|
+
})
|
|
4182
|
+
);
|
|
4183
|
+
}
|
|
4088
4184
|
var PreStartService = class {
|
|
4089
4185
|
constructor(settings, globalSettings, store, access, directory, visibility, clock) {
|
|
4090
4186
|
__publicField(this, "settings", settings);
|
|
@@ -4107,10 +4203,11 @@ var PreStartService = class {
|
|
|
4107
4203
|
if (!settings.enabled) return ALLOW;
|
|
4108
4204
|
const now = ctx.now ?? this.clock();
|
|
4109
4205
|
const horizon = new Date(now.getTime() + settings.confirmWindowMinutes * MINUTE_MS3 + 1);
|
|
4110
|
-
const
|
|
4111
|
-
|
|
4112
|
-
);
|
|
4206
|
+
const confirmed2 = await this.store.findConfirmedOverlapping(ctx.resourceId, now, horizon);
|
|
4207
|
+
const others = confirmed2.filter((reservation) => reservation.userId !== ctx.userId);
|
|
4113
4208
|
if (others.length === 0) return ALLOW;
|
|
4209
|
+
const limit = await this.directory.getSessionLimit(ctx.resourceId);
|
|
4210
|
+
if (limit > 1) return this.evaluateShared(ctx, confirmed2, limit, now);
|
|
4114
4211
|
const nowMs = now.getTime();
|
|
4115
4212
|
const active = others.filter((r) => r.startTime.getTime() <= nowMs);
|
|
4116
4213
|
if (active.length > 0) {
|
|
@@ -4121,6 +4218,37 @@ var PreStartService = class {
|
|
|
4121
4218
|
(r) => r.startTime.getTime() > nowMs && !ctx.confirmedStepKeys.includes(reservationStepKey(r.id))
|
|
4122
4219
|
);
|
|
4123
4220
|
if (!upcoming) return ALLOW;
|
|
4221
|
+
return this.askReservedSoon(ctx, upcoming, now);
|
|
4222
|
+
}
|
|
4223
|
+
/**
|
|
4224
|
+
* The gate on a machine with several slots. Running bookings block only when the slots they hold fill the
|
|
4225
|
+
* machine for this starter (the starter's own running booking is their slot); an upcoming booking is asked about
|
|
4226
|
+
* only when starting now would leave it without a slot at its start.
|
|
4227
|
+
*/
|
|
4228
|
+
async evaluateShared(ctx, confirmed2, limit, now) {
|
|
4229
|
+
const nowMs = now.getTime();
|
|
4230
|
+
const sessions = await this.directory.getActiveSessions(ctx.resourceId);
|
|
4231
|
+
const inSession = new Set(sessions.map((session) => session.userId));
|
|
4232
|
+
const running = confirmed2.filter((r) => r.startTime.getTime() <= nowMs);
|
|
4233
|
+
const overridden = overriddenBookingIds(ctx.confirmedStepKeys);
|
|
4234
|
+
if (!running.some((r) => r.userId === ctx.userId)) {
|
|
4235
|
+
const held = heldBookings({ confirmed: running, starterId: ctx.userId, inSession, at: now, overridden });
|
|
4236
|
+
if (held.length > 0 && limit - sessions.length - held.length <= 0) {
|
|
4237
|
+
const verdict = await this.whenActive(ctx, held, now);
|
|
4238
|
+
if (verdict) return verdict;
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
for (const booking of confirmed2) {
|
|
4242
|
+
if (booking.userId === ctx.userId || booking.startTime.getTime() <= nowMs) continue;
|
|
4243
|
+
if (ctx.confirmedStepKeys.includes(reservationStepKey(booking.id))) continue;
|
|
4244
|
+
const heldThen = heldBookings({ confirmed: confirmed2, starterId: ctx.userId, inSession, at: booking.startTime, overridden });
|
|
4245
|
+
if (sessions.length + 1 + heldThen.length > limit) return this.askReservedSoon(ctx, booking, now);
|
|
4246
|
+
}
|
|
4247
|
+
return ALLOW;
|
|
4248
|
+
}
|
|
4249
|
+
/** The "Reserved soon ... Start anyway?" question for an upcoming booking of someone else. */
|
|
4250
|
+
async askReservedSoon(ctx, upcoming, now) {
|
|
4251
|
+
const nowMs = now.getTime();
|
|
4124
4252
|
const { language: lang } = ctx;
|
|
4125
4253
|
const minutes = Math.max(1, Math.ceil((upcoming.startTime.getTime() - nowMs) / MINUTE_MS3));
|
|
4126
4254
|
const from = await this.timeText(ctx, upcoming.startTime, now);
|
|
@@ -4160,8 +4288,22 @@ var PreStartService = class {
|
|
|
4160
4288
|
}
|
|
4161
4289
|
if (!this.settings.getCachedSettings(ctx.resourceId).enabled) return null;
|
|
4162
4290
|
const now = ctx.now ?? this.clock();
|
|
4163
|
-
const
|
|
4291
|
+
const running = await this.store.findActiveForResource(ctx.resourceId, now);
|
|
4292
|
+
let active = running.find((r) => r.userId !== ctx.userId);
|
|
4164
4293
|
if (!active) return null;
|
|
4294
|
+
const limit = await this.directory.getSessionLimit(ctx.resourceId);
|
|
4295
|
+
if (limit > 1) {
|
|
4296
|
+
if (running.some((r) => r.userId === ctx.userId)) return null;
|
|
4297
|
+
const sessions = await this.directory.getActiveSessions(ctx.resourceId);
|
|
4298
|
+
const held = heldBookings({
|
|
4299
|
+
confirmed: running,
|
|
4300
|
+
starterId: ctx.userId,
|
|
4301
|
+
inSession: new Set(sessions.map((session) => session.userId)),
|
|
4302
|
+
at: now
|
|
4303
|
+
});
|
|
4304
|
+
if (held.length === 0 || limit - sessions.length - held.length > 0) return null;
|
|
4305
|
+
active = held[0];
|
|
4306
|
+
}
|
|
4165
4307
|
const viewer = subjectOfPrincipal(ctx.principal);
|
|
4166
4308
|
if (await this.access.isManager(viewer, ctx.resourceId)) return null;
|
|
4167
4309
|
if ((await this.visibility.filterVisible(viewer, [ctx.resourceId])).length === 0) return null;
|
|
@@ -4170,6 +4312,17 @@ var PreStartService = class {
|
|
|
4170
4312
|
const until = formatTime(active.endTime, { lang: ctx.language, timeZone });
|
|
4171
4313
|
return { reason: reservedReason(ctx.language, until, holder), until: active.endTime };
|
|
4172
4314
|
}
|
|
4315
|
+
/**
|
|
4316
|
+
* The `RESERVED` refusal for a start that finds every free slot held for `booking`'s holder: same text and
|
|
4317
|
+
* holder-name rule as the gate's block, used by the host's atomic start check.
|
|
4318
|
+
*/
|
|
4319
|
+
async reservedBlockReason(ctx, booking, now) {
|
|
4320
|
+
const starter = subjectOfPrincipal(ctx.principal);
|
|
4321
|
+
const until = await this.timeText(ctx, booking.endTime, now);
|
|
4322
|
+
const found = await this.holderNameFor(starter, booking);
|
|
4323
|
+
const holder = found && ctx.origin === "reader" ? readerName(found) : found;
|
|
4324
|
+
return reservedReason(ctx.language, until, holder);
|
|
4325
|
+
}
|
|
4173
4326
|
/**
|
|
4174
4327
|
* The booking holder's name for a viewer who may see who uses the machine (core's usage attribution rule, the
|
|
4175
4328
|
* same one that decides who sees the current user of a running session); null for everyone else.
|
|
@@ -4252,13 +4405,13 @@ function reservedReason(lang, until, holder) {
|
|
|
4252
4405
|
}
|
|
4253
4406
|
|
|
4254
4407
|
// backend/hooks/publisher.ts
|
|
4255
|
-
var
|
|
4408
|
+
var import_common23 = require("@nestjs/common");
|
|
4256
4409
|
|
|
4257
4410
|
// backend/reader-ui/reader-ui.service.ts
|
|
4258
|
-
var
|
|
4411
|
+
var import_plugins_backend_sdk12 = require("@attraccess/plugins-backend-sdk");
|
|
4259
4412
|
var import_common20 = require("@nestjs/common");
|
|
4260
4413
|
var MINUTE_MS4 = 6e4;
|
|
4261
|
-
var SLOT =
|
|
4414
|
+
var SLOT = import_plugins_backend_sdk12.READER_UI_SLOTS;
|
|
4262
4415
|
var ReaderUiService = class {
|
|
4263
4416
|
constructor(settings, globalSettings, store, access, directory, clock) {
|
|
4264
4417
|
__publicField(this, "settings", settings);
|
|
@@ -4298,14 +4451,17 @@ var ReaderUiService = class {
|
|
|
4298
4451
|
const early = settings.earlyCheckInMinutes * MINUTE_MS4;
|
|
4299
4452
|
const running = bookings.find((r) => r.startTime.getTime() <= nowMs);
|
|
4300
4453
|
const upcoming = bookings.filter((r) => r.startTime.getTime() > nowMs);
|
|
4301
|
-
const
|
|
4302
|
-
const
|
|
4303
|
-
|
|
4454
|
+
const limit = await this.directory.getSessionLimit(ctx.resourceId);
|
|
4455
|
+
const shared = limit > 1 ? await this.sharedSlots(ctx, bookings, limit, now) : null;
|
|
4456
|
+
const own = userId === void 0 ? void 0 : this.ownBooking(userId, running, upcoming, nowMs, early, shared);
|
|
4457
|
+
const subject = this.subjectOf(own, running, upcoming, shared);
|
|
4458
|
+
if (!subject && !(shared && shared.reserved > 0)) return [];
|
|
4304
4459
|
const nameOf = this.nameResolver(ctx);
|
|
4305
|
-
const holder = own ? void 0 : await nameOf(subject);
|
|
4306
|
-
const state = this.describe(subject,
|
|
4460
|
+
const holder = !subject || own ? void 0 : await nameOf(subject);
|
|
4461
|
+
const state = subject ? this.describe(subject, subject.startTime.getTime() <= nowMs, settings, clock, holder, own !== void 0) : this.reservedCount(shared?.reserved ?? 0, limit, bookings, nowMs, clock);
|
|
4307
4462
|
const boundaries = [state.boundary, nextLocalMidnight(now, clock.timeZone).getTime()];
|
|
4308
4463
|
if (upcoming[0]) boundaries.push(upcoming[0].startTime.getTime());
|
|
4464
|
+
if (shared) boundaries.push(...bookings.flatMap((r) => [r.startTime.getTime(), r.endTime.getTime()]));
|
|
4309
4465
|
const contributions = [];
|
|
4310
4466
|
const add = (slotId, key, tree, text, tone) => contributions.push({ slotId, key, tree, fallback: { text, tone } });
|
|
4311
4467
|
add(
|
|
@@ -4315,17 +4471,10 @@ var ReaderUiService = class {
|
|
|
4315
4471
|
state.row,
|
|
4316
4472
|
state.tone
|
|
4317
4473
|
);
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
if (next) sessionBooking = next;
|
|
4323
|
-
else {
|
|
4324
|
-
const opens = upcoming.find((r) => r.userId !== userId);
|
|
4325
|
-
if (opens) boundaries.push(opens.startTime.getTime() - window);
|
|
4326
|
-
}
|
|
4327
|
-
}
|
|
4328
|
-
if (subject !== sessionBooking) {
|
|
4474
|
+
const countdown = this.sessionCountdown(ctx, settings, upcoming, shared, nowMs);
|
|
4475
|
+
const sessionBooking = countdown.next;
|
|
4476
|
+
if (countdown.opensAt !== void 0) boundaries.push(countdown.opensAt);
|
|
4477
|
+
if (subject !== sessionBooking || !subject) {
|
|
4329
4478
|
const lines = state.body.map((text) => ({ t: "text", text, style: "body" }));
|
|
4330
4479
|
add(
|
|
4331
4480
|
SLOT.RESOURCE_DETAILS_BODY,
|
|
@@ -4337,21 +4486,8 @@ var ReaderUiService = class {
|
|
|
4337
4486
|
if (sessionBooking) {
|
|
4338
4487
|
const next = sessionBooking;
|
|
4339
4488
|
const sessionHolder = next === subject ? holder : await nameOf(next);
|
|
4340
|
-
const
|
|
4341
|
-
|
|
4342
|
-
add(
|
|
4343
|
-
SLOT.RESOURCE_DETAILS_SESSION,
|
|
4344
|
-
"reserved-soon",
|
|
4345
|
-
{
|
|
4346
|
-
t: "row",
|
|
4347
|
-
c: [
|
|
4348
|
-
lines.length === 1 ? lines[0] : { t: "col", gap: 0, fill: true, c: lines },
|
|
4349
|
-
{ t: "countdown", to: next.startTime, tone: "warning" }
|
|
4350
|
-
]
|
|
4351
|
-
},
|
|
4352
|
-
texts.join(" "),
|
|
4353
|
-
"warning"
|
|
4354
|
-
);
|
|
4489
|
+
const { tree, text } = this.sessionTree(next, clock, sessionHolder);
|
|
4490
|
+
add(SLOT.RESOURCE_DETAILS_SESSION, "reserved-soon", tree, text, "warning");
|
|
4355
4491
|
boundaries.push(next.startTime.getTime());
|
|
4356
4492
|
}
|
|
4357
4493
|
if (userId !== void 0 && upcoming.length > 0 && !own) {
|
|
@@ -4360,11 +4496,93 @@ var ReaderUiService = class {
|
|
|
4360
4496
|
const expiresAt = new Date(Math.min(...boundaries.filter((at) => at > nowMs)));
|
|
4361
4497
|
return contributions.map((c) => ({ ...c, expiresAt }));
|
|
4362
4498
|
}
|
|
4363
|
-
/**
|
|
4364
|
-
|
|
4499
|
+
/**
|
|
4500
|
+
* The slot picture of a shared machine: sessions and the bookings that hold slots for the viewer's disadvantage.
|
|
4501
|
+
* `ownRunning`: the viewer's own running booking (their slot); `blocker`: the running booking to name when no free
|
|
4502
|
+
* slot is left for the viewer (a signed-out reader counts as nobody); `reserved`: running bookings (one per person);
|
|
4503
|
+
* `nextLacking`: the next booking of someone else that would find no slot at its start if the viewer started now;
|
|
4504
|
+
* `lacksSlotWith`: whether a booking would lack its slot with the viewer's session running (as in the gate: sessions,
|
|
4505
|
+
* one more slot for a viewer not in session yet, and the slots held at the booking's start).
|
|
4506
|
+
*/
|
|
4507
|
+
async sharedSlots(ctx, bookings, limit, now) {
|
|
4508
|
+
const nowMs = now.getTime();
|
|
4509
|
+
const sessions = await this.directory.getActiveSessions(ctx.resourceId);
|
|
4510
|
+
const inSession = new Set(sessions.map((session) => session.userId));
|
|
4511
|
+
const running = bookings.filter((r) => r.startTime.getTime() <= nowMs);
|
|
4512
|
+
const viewerId = ctx.userId ?? -1;
|
|
4513
|
+
const held = heldBookings({ confirmed: running, starterId: viewerId, inSession, at: now });
|
|
4514
|
+
const ownRunning = running.find((r) => r.userId === viewerId);
|
|
4515
|
+
const free = limit - sessions.length - held.length;
|
|
4516
|
+
const lacksSlotWith = (booking, viewer) => sessions.length + (viewer === void 0 || inSession.has(viewer) ? 0 : 1) + heldBookings({ confirmed: bookings, starterId: viewer ?? -1, inSession, at: booking.startTime }).length > limit;
|
|
4517
|
+
return {
|
|
4518
|
+
ownRunning,
|
|
4519
|
+
blocker: !ownRunning && held.length > 0 && free <= 0 ? held[0] : void 0,
|
|
4520
|
+
reserved: new Set(running.map((r) => r.userId)).size,
|
|
4521
|
+
nextLacking: bookings.find(
|
|
4522
|
+
(r) => r.startTime.getTime() > nowMs && r.userId !== ctx.userId && lacksSlotWith(r, ctx.userId)
|
|
4523
|
+
),
|
|
4524
|
+
lacksSlotWith
|
|
4525
|
+
};
|
|
4526
|
+
}
|
|
4527
|
+
/** Bookings run but slots remain: a short success text with the count (Latin-1, within the row limit). */
|
|
4528
|
+
reservedCount(reserved, limit, bookings, nowMs, clock) {
|
|
4529
|
+
const ends = bookings.filter((r) => r.startTime.getTime() <= nowMs).map((r) => r.endTime.getTime());
|
|
4530
|
+
return {
|
|
4531
|
+
row: readerTexts.rowSlotsReserved(reserved, limit, clock),
|
|
4532
|
+
body: [readerTexts.slotsReserved(reserved, limit, clock)],
|
|
4533
|
+
tone: "success",
|
|
4534
|
+
boundary: Math.min(...ends)
|
|
4535
|
+
};
|
|
4536
|
+
}
|
|
4537
|
+
/**
|
|
4538
|
+
* The booking the details are about. On a shared machine a running booking only shows as a warning when it holds
|
|
4539
|
+
* the last free slot, and an upcoming booking only if it would lack its slot (the gate would ask about it); with
|
|
4540
|
+
* none of these a short count replaces it (no subject).
|
|
4541
|
+
*/
|
|
4542
|
+
subjectOf(own, running, upcoming, shared) {
|
|
4543
|
+
if (!shared) return own ?? running ?? upcoming[0];
|
|
4544
|
+
return own ?? shared.blocker ?? shared.nextLacking;
|
|
4545
|
+
}
|
|
4546
|
+
/**
|
|
4547
|
+
* Session area: another user's booking that starts within the confirm window (on a shared machine only one the
|
|
4548
|
+
* viewer's session would leave without a slot), or when the window opens for the next one.
|
|
4549
|
+
*/
|
|
4550
|
+
sessionCountdown(ctx, settings, upcoming, shared, nowMs) {
|
|
4551
|
+
const userId = ctx.userId;
|
|
4552
|
+
if (ctx.sessionActive !== true || userId === void 0 || settings.confirmWindowMinutes <= 0) return {};
|
|
4553
|
+
const window = settings.confirmWindowMinutes * MINUTE_MS4;
|
|
4554
|
+
const needsSlot = (r) => r.userId !== userId && (!shared || shared.lacksSlotWith(r, userId));
|
|
4555
|
+
const next = upcoming.find((r) => needsSlot(r) && r.startTime.getTime() - nowMs <= window);
|
|
4556
|
+
if (next) return { next };
|
|
4557
|
+
const opens = upcoming.find(needsSlot);
|
|
4558
|
+
return opens ? { opensAt: opens.startTime.getTime() - window } : {};
|
|
4559
|
+
}
|
|
4560
|
+
/** The session-area row: the booking's range and a countdown to its start. */
|
|
4561
|
+
sessionTree(next, clock, holder) {
|
|
4562
|
+
const texts = readerTexts.sessionReserved(next.startTime, next.endTime, clock, holder);
|
|
4563
|
+
const lines = texts.map((text) => ({ t: "text", text, style: "small", fill: true }));
|
|
4564
|
+
return {
|
|
4565
|
+
tree: {
|
|
4566
|
+
t: "row",
|
|
4567
|
+
c: [
|
|
4568
|
+
lines.length === 1 ? lines[0] : { t: "col", gap: 0, fill: true, c: lines },
|
|
4569
|
+
{ t: "countdown", to: next.startTime, tone: "warning" }
|
|
4570
|
+
]
|
|
4571
|
+
},
|
|
4572
|
+
text: texts.join(" ")
|
|
4573
|
+
};
|
|
4574
|
+
}
|
|
4575
|
+
/**
|
|
4576
|
+
* Your own booking while it runs or within the early check-in window before it starts. On a shared machine your
|
|
4577
|
+
* running booking is found among all running ones, and a booking that leaves you no free slot wins over your
|
|
4578
|
+
* upcoming one (you could not start yet).
|
|
4579
|
+
*/
|
|
4580
|
+
ownBooking(userId, running, upcoming, nowMs, early, shared) {
|
|
4581
|
+
const soon = () => upcoming.find((r) => r.userId === userId && r.startTime.getTime() - nowMs <= early);
|
|
4582
|
+
if (shared) return shared.ownRunning ?? (shared.blocker ? void 0 : soon());
|
|
4365
4583
|
if (running?.userId === userId) return running;
|
|
4366
4584
|
if (running) return void 0;
|
|
4367
|
-
return
|
|
4585
|
+
return soon();
|
|
4368
4586
|
}
|
|
4369
4587
|
/**
|
|
4370
4588
|
* Resolves holder names for this viewer: undefined for a signed-out reader (no lookup at all), for the
|
|
@@ -4433,8 +4651,47 @@ ReaderUiService = __decorateClass([
|
|
|
4433
4651
|
__decorateParam(5, (0, import_common20.Inject)(RESERVATION_CLOCK))
|
|
4434
4652
|
], ReaderUiService);
|
|
4435
4653
|
|
|
4436
|
-
// backend/hooks/
|
|
4654
|
+
// backend/hooks/start-capacity.service.ts
|
|
4437
4655
|
var import_common21 = require("@nestjs/common");
|
|
4656
|
+
var StartCapacityService = class {
|
|
4657
|
+
constructor(context, settings, store, preStart) {
|
|
4658
|
+
__publicField(this, "context", context);
|
|
4659
|
+
__publicField(this, "settings", settings);
|
|
4660
|
+
__publicField(this, "store", store);
|
|
4661
|
+
__publicField(this, "preStart", preStart);
|
|
4662
|
+
}
|
|
4663
|
+
async evaluate(ctx, deadline = hookDeadline()) {
|
|
4664
|
+
if (!this.settings.isWarm) {
|
|
4665
|
+
await waitUntil(this.settings.whenReady(), deadline, "Reservation settings are not loaded yet");
|
|
4666
|
+
}
|
|
4667
|
+
if (!this.settings.getCachedSettings(ctx.resourceId).enabled) return { heldSlots: 0 };
|
|
4668
|
+
const running = await this.store.findRunningConfirmed(ctx.scope, ctx.resourceId, ctx.now);
|
|
4669
|
+
if (running.length === 0 || running.some((r) => r.userId === ctx.userId)) return { heldSlots: 0 };
|
|
4670
|
+
const held = heldBookings({
|
|
4671
|
+
confirmed: running,
|
|
4672
|
+
starterId: ctx.userId,
|
|
4673
|
+
// A holder in session (or starting) is counted through `occupiedSlots`, never twice.
|
|
4674
|
+
inSession: new Set(ctx.usersInSession),
|
|
4675
|
+
at: ctx.now,
|
|
4676
|
+
overridden: overriddenBookingIds(ctx.confirmedStepKeys)
|
|
4677
|
+
});
|
|
4678
|
+
if (held.length === 0 || ctx.occupiedSlots + held.length < ctx.sessionLimit) return { heldSlots: held.length };
|
|
4679
|
+
return {
|
|
4680
|
+
heldSlots: held.length,
|
|
4681
|
+
reason: await this.preStart.reservedBlockReason(ctx, held[0], ctx.now)
|
|
4682
|
+
};
|
|
4683
|
+
}
|
|
4684
|
+
};
|
|
4685
|
+
StartCapacityService = __decorateClass([
|
|
4686
|
+
(0, import_common21.Injectable)(),
|
|
4687
|
+
__decorateParam(0, (0, import_common21.Inject)(PLUGIN_CONTEXT)),
|
|
4688
|
+
__decorateParam(1, (0, import_common21.Inject)(ResourceSettingsService)),
|
|
4689
|
+
__decorateParam(2, (0, import_common21.Inject)(ReservationStore)),
|
|
4690
|
+
__decorateParam(3, (0, import_common21.Inject)(PreStartService))
|
|
4691
|
+
], StartCapacityService);
|
|
4692
|
+
|
|
4693
|
+
// backend/hooks/session-end.service.ts
|
|
4694
|
+
var import_common22 = require("@nestjs/common");
|
|
4438
4695
|
var NONE = Object.freeze({ decision: "none" });
|
|
4439
4696
|
var SessionEndService = class {
|
|
4440
4697
|
constructor(settings, globalSettings, store, reservations, decisions, clock) {
|
|
@@ -4444,7 +4701,7 @@ var SessionEndService = class {
|
|
|
4444
4701
|
__publicField(this, "reservations", reservations);
|
|
4445
4702
|
__publicField(this, "decisions", decisions);
|
|
4446
4703
|
__publicField(this, "clock", clock);
|
|
4447
|
-
__publicField(this, "logger", new
|
|
4704
|
+
__publicField(this, "logger", new import_common22.Logger("ReservationsSessionEnd"));
|
|
4448
4705
|
}
|
|
4449
4706
|
/** `deadline` (epoch ms) bounds the wait for the settings cache; past it this throws (host policy applies). */
|
|
4450
4707
|
async evaluate(ctx, deadline = hookDeadline()) {
|
|
@@ -4495,39 +4752,46 @@ var SessionEndService = class {
|
|
|
4495
4752
|
}
|
|
4496
4753
|
};
|
|
4497
4754
|
SessionEndService = __decorateClass([
|
|
4498
|
-
(0,
|
|
4499
|
-
__decorateParam(0, (0,
|
|
4500
|
-
__decorateParam(1, (0,
|
|
4501
|
-
__decorateParam(2, (0,
|
|
4502
|
-
__decorateParam(3, (0,
|
|
4503
|
-
__decorateParam(4, (0,
|
|
4504
|
-
__decorateParam(5, (0,
|
|
4755
|
+
(0, import_common22.Injectable)(),
|
|
4756
|
+
__decorateParam(0, (0, import_common22.Inject)(ResourceSettingsService)),
|
|
4757
|
+
__decorateParam(1, (0, import_common22.Inject)(GlobalSettingsService)),
|
|
4758
|
+
__decorateParam(2, (0, import_common22.Inject)(ReservationStore)),
|
|
4759
|
+
__decorateParam(3, (0, import_common22.Inject)(ReservationService)),
|
|
4760
|
+
__decorateParam(4, (0, import_common22.Inject)(PendingDecisionStore)),
|
|
4761
|
+
__decorateParam(5, (0, import_common22.Inject)(RESERVATION_CLOCK))
|
|
4505
4762
|
], SessionEndService);
|
|
4506
4763
|
|
|
4507
4764
|
// backend/hooks/publisher.ts
|
|
4508
4765
|
var HookServicePublisher = class {
|
|
4509
|
-
constructor(preStart, sessionEnd, readerUi) {
|
|
4766
|
+
constructor(preStart, startCapacity, sessionEnd, readerUi) {
|
|
4510
4767
|
__publicField(this, "preStart", preStart);
|
|
4768
|
+
__publicField(this, "startCapacity", startCapacity);
|
|
4511
4769
|
__publicField(this, "sessionEnd", sessionEnd);
|
|
4512
4770
|
__publicField(this, "readerUi", readerUi);
|
|
4513
4771
|
}
|
|
4514
4772
|
onModuleInit() {
|
|
4515
|
-
publishHookServices({
|
|
4773
|
+
publishHookServices({
|
|
4774
|
+
preStart: this.preStart,
|
|
4775
|
+
startCapacity: this.startCapacity,
|
|
4776
|
+
sessionEnd: this.sessionEnd,
|
|
4777
|
+
readerUi: this.readerUi
|
|
4778
|
+
});
|
|
4516
4779
|
}
|
|
4517
4780
|
onModuleDestroy() {
|
|
4518
4781
|
publishHookServices(null);
|
|
4519
4782
|
}
|
|
4520
4783
|
};
|
|
4521
4784
|
HookServicePublisher = __decorateClass([
|
|
4522
|
-
(0,
|
|
4523
|
-
__decorateParam(0, (0,
|
|
4524
|
-
__decorateParam(1, (0,
|
|
4525
|
-
__decorateParam(2, (0,
|
|
4785
|
+
(0, import_common23.Injectable)(),
|
|
4786
|
+
__decorateParam(0, (0, import_common23.Inject)(PreStartService)),
|
|
4787
|
+
__decorateParam(1, (0, import_common23.Inject)(StartCapacityService)),
|
|
4788
|
+
__decorateParam(2, (0, import_common23.Inject)(SessionEndService)),
|
|
4789
|
+
__decorateParam(3, (0, import_common23.Inject)(ReaderUiService))
|
|
4526
4790
|
], HookServicePublisher);
|
|
4527
4791
|
|
|
4528
4792
|
// backend/ical/ical.controller.ts
|
|
4529
4793
|
var import_plugins_backend_sdk13 = require("@attraccess/plugins-backend-sdk");
|
|
4530
|
-
var
|
|
4794
|
+
var import_common25 = require("@nestjs/common");
|
|
4531
4795
|
var import_swagger6 = require("@nestjs/swagger");
|
|
4532
4796
|
|
|
4533
4797
|
// backend/ical/ical.dto.ts
|
|
@@ -4658,56 +4922,9 @@ __decorateClass([
|
|
|
4658
4922
|
], IcalFeedSecretDto.prototype, "token", 2);
|
|
4659
4923
|
|
|
4660
4924
|
// backend/ical/ical.service.ts
|
|
4661
|
-
var
|
|
4925
|
+
var import_common24 = require("@nestjs/common");
|
|
4662
4926
|
var import_node_crypto2 = require("node:crypto");
|
|
4663
4927
|
|
|
4664
|
-
// backend/entities/ical-feed.entity.ts
|
|
4665
|
-
var import_plugins_backend_sdk12 = require("@attraccess/plugins-backend-sdk");
|
|
4666
|
-
var IcalFeedEntity = class {
|
|
4667
|
-
constructor() {
|
|
4668
|
-
__publicField(this, "id");
|
|
4669
|
-
__publicField(this, "userId");
|
|
4670
|
-
__publicField(this, "name");
|
|
4671
|
-
__publicField(this, "tokenHash");
|
|
4672
|
-
__publicField(this, "tokenPrefix");
|
|
4673
|
-
__publicField(this, "selection");
|
|
4674
|
-
__publicField(this, "createdAt");
|
|
4675
|
-
__publicField(this, "revokedAt");
|
|
4676
|
-
__publicField(this, "lastUsedAt");
|
|
4677
|
-
}
|
|
4678
|
-
};
|
|
4679
|
-
__decorateClass([
|
|
4680
|
-
(0, import_plugins_backend_sdk12.PrimaryGeneratedColumn)({ type: "integer" })
|
|
4681
|
-
], IcalFeedEntity.prototype, "id", 2);
|
|
4682
|
-
__decorateClass([
|
|
4683
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "integer" })
|
|
4684
|
-
], IcalFeedEntity.prototype, "userId", 2);
|
|
4685
|
-
__decorateClass([
|
|
4686
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "varchar" })
|
|
4687
|
-
], IcalFeedEntity.prototype, "name", 2);
|
|
4688
|
-
__decorateClass([
|
|
4689
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "varchar", unique: true })
|
|
4690
|
-
], IcalFeedEntity.prototype, "tokenHash", 2);
|
|
4691
|
-
__decorateClass([
|
|
4692
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "varchar", nullable: true })
|
|
4693
|
-
], IcalFeedEntity.prototype, "tokenPrefix", 2);
|
|
4694
|
-
__decorateClass([
|
|
4695
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "text" })
|
|
4696
|
-
], IcalFeedEntity.prototype, "selection", 2);
|
|
4697
|
-
__decorateClass([
|
|
4698
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "datetime" })
|
|
4699
|
-
], IcalFeedEntity.prototype, "createdAt", 2);
|
|
4700
|
-
__decorateClass([
|
|
4701
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "datetime", nullable: true })
|
|
4702
|
-
], IcalFeedEntity.prototype, "revokedAt", 2);
|
|
4703
|
-
__decorateClass([
|
|
4704
|
-
(0, import_plugins_backend_sdk12.Column)({ type: "datetime", nullable: true })
|
|
4705
|
-
], IcalFeedEntity.prototype, "lastUsedAt", 2);
|
|
4706
|
-
IcalFeedEntity = __decorateClass([
|
|
4707
|
-
(0, import_plugins_backend_sdk12.Entity)({ name: "reservations_ical_feed" }),
|
|
4708
|
-
(0, import_plugins_backend_sdk12.Index)("IDX_reservations_ical_feed_user", ["userId"])
|
|
4709
|
-
], IcalFeedEntity);
|
|
4710
|
-
|
|
4711
4928
|
// backend/ical/ical-format.ts
|
|
4712
4929
|
var CRLF = "\r\n";
|
|
4713
4930
|
var MAX_OCTETS = 75;
|
|
@@ -4816,12 +5033,13 @@ var IcalService = class {
|
|
|
4816
5033
|
__publicField(this, "audit");
|
|
4817
5034
|
this.audit = new ReservationAudit(context.audit);
|
|
4818
5035
|
}
|
|
4819
|
-
get
|
|
4820
|
-
return this.context.
|
|
5036
|
+
get feeds() {
|
|
5037
|
+
return tablesOf(this.context).icalFeeds;
|
|
4821
5038
|
}
|
|
4822
|
-
/**
|
|
4823
|
-
|
|
4824
|
-
|
|
5039
|
+
/** Applies a patch to a feed and returns the stored row. The host serializes writes. */
|
|
5040
|
+
async patch(feed, changes) {
|
|
5041
|
+
await this.feeds.update({ id: feed.id }, changes);
|
|
5042
|
+
return { ...feed, ...changes };
|
|
4825
5043
|
}
|
|
4826
5044
|
toDto(feed) {
|
|
4827
5045
|
return {
|
|
@@ -4838,55 +5056,58 @@ var IcalService = class {
|
|
|
4838
5056
|
return { feed: this.toDto(feed), url: `${base}/api/reservations/ical/${token}.ics`, token };
|
|
4839
5057
|
}
|
|
4840
5058
|
async load(userId, id) {
|
|
4841
|
-
const feed = await this.
|
|
5059
|
+
const feed = await this.feeds.findOne({ where: { id, userId } });
|
|
4842
5060
|
if (!feed || feed.revokedAt) throw new ReservationError("FEED_NOT_FOUND", "Feed not found");
|
|
4843
5061
|
return feed;
|
|
4844
5062
|
}
|
|
4845
5063
|
async list(userId) {
|
|
4846
|
-
const feeds = await this.
|
|
5064
|
+
const feeds = await this.feeds.find({
|
|
5065
|
+
where: { userId, revokedAt: null },
|
|
5066
|
+
orderBy: [{ field: "createdAt", direction: "asc" }]
|
|
5067
|
+
});
|
|
4847
5068
|
return feeds.map((feed) => this.toDto(feed));
|
|
4848
5069
|
}
|
|
4849
5070
|
async create(actor, input) {
|
|
4850
5071
|
const selection = assertSelection(input.selection);
|
|
4851
|
-
const count = await this.
|
|
5072
|
+
const count = await this.feeds.count({ userId: actor.userId, revokedAt: null });
|
|
4852
5073
|
if (count >= MAX_FEEDS_PER_USER) {
|
|
4853
5074
|
throw new ReservationError("FEED_LIMIT", `You can have at most ${MAX_FEEDS_PER_USER} calendar feeds`);
|
|
4854
5075
|
}
|
|
4855
5076
|
const token = (0, import_node_crypto2.randomBytes)(32).toString("base64url");
|
|
4856
|
-
const feed = await this.
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
})
|
|
4867
|
-
);
|
|
5077
|
+
const feed = await this.feeds.insert({
|
|
5078
|
+
userId: actor.userId,
|
|
5079
|
+
name: input.name.trim(),
|
|
5080
|
+
tokenHash: hashToken(token),
|
|
5081
|
+
tokenPrefix: token.slice(0, TOKEN_PREFIX_LENGTH),
|
|
5082
|
+
selection: JSON.stringify(selection),
|
|
5083
|
+
createdAt: this.clock(),
|
|
5084
|
+
revokedAt: null,
|
|
5085
|
+
lastUsedAt: null
|
|
5086
|
+
});
|
|
4868
5087
|
await this.audit.record("feed_created", actor, { type: "feed", id: feed.id }, { feedName: feed.name });
|
|
4869
5088
|
return this.secretResult(feed, token);
|
|
4870
5089
|
}
|
|
4871
5090
|
async update(actor, id, input) {
|
|
4872
5091
|
const feed = await this.load(actor.userId, id);
|
|
4873
|
-
|
|
4874
|
-
if (input.
|
|
4875
|
-
|
|
5092
|
+
const changes = {};
|
|
5093
|
+
if (input.name !== void 0) changes.name = input.name.trim();
|
|
5094
|
+
if (input.selection !== void 0) changes.selection = JSON.stringify(assertSelection(input.selection));
|
|
5095
|
+
return this.toDto(await this.patch(feed, changes));
|
|
4876
5096
|
}
|
|
4877
5097
|
/** New token; the old one stops working immediately (its hash is overwritten). */
|
|
4878
5098
|
async regenerate(actor, id) {
|
|
4879
5099
|
const feed = await this.load(actor.userId, id);
|
|
4880
5100
|
const token = (0, import_node_crypto2.randomBytes)(32).toString("base64url");
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
5101
|
+
const updated = await this.patch(feed, {
|
|
5102
|
+
tokenHash: hashToken(token),
|
|
5103
|
+
tokenPrefix: token.slice(0, TOKEN_PREFIX_LENGTH),
|
|
5104
|
+
lastUsedAt: null
|
|
5105
|
+
});
|
|
5106
|
+
return this.secretResult(updated, token);
|
|
4885
5107
|
}
|
|
4886
5108
|
async revoke(actor, id) {
|
|
4887
5109
|
const feed = await this.load(actor.userId, id);
|
|
4888
|
-
feed
|
|
4889
|
-
await this.save(feed);
|
|
5110
|
+
await this.patch(feed, { revokedAt: this.clock() });
|
|
4890
5111
|
await this.audit.record("feed_revoked", actor, { type: "feed", id: feed.id }, { feedName: feed.name });
|
|
4891
5112
|
}
|
|
4892
5113
|
// ------------------------------------------------------------- rendering
|
|
@@ -4896,12 +5117,12 @@ var IcalService = class {
|
|
|
4896
5117
|
*/
|
|
4897
5118
|
async renderForToken(token) {
|
|
4898
5119
|
if (!FEED_TOKEN_PATTERN.test(token)) return null;
|
|
4899
|
-
const feed = await this.
|
|
5120
|
+
const feed = await this.feeds.findOne({ where: { tokenHash: hashToken(token) } });
|
|
4900
5121
|
if (!feed || feed.revokedAt) return null;
|
|
4901
5122
|
if (!await this.visibility.isActiveAccount(feed.userId)) return null;
|
|
4902
5123
|
const now = this.clock();
|
|
4903
5124
|
if (!feed.lastUsedAt || now.getTime() - feed.lastUsedAt.getTime() > 6e4) {
|
|
4904
|
-
await this.
|
|
5125
|
+
await this.feeds.update({ id: feed.id }, { lastUsedAt: now }).catch(() => void 0);
|
|
4905
5126
|
}
|
|
4906
5127
|
return this.render(feed, now);
|
|
4907
5128
|
}
|
|
@@ -5006,16 +5227,16 @@ var IcalService = class {
|
|
|
5006
5227
|
}
|
|
5007
5228
|
};
|
|
5008
5229
|
IcalService = __decorateClass([
|
|
5009
|
-
(0,
|
|
5010
|
-
__decorateParam(0, (0,
|
|
5011
|
-
__decorateParam(1, (0,
|
|
5012
|
-
__decorateParam(2, (0,
|
|
5013
|
-
__decorateParam(3, (0,
|
|
5014
|
-
__decorateParam(4, (0,
|
|
5015
|
-
__decorateParam(5, (0,
|
|
5016
|
-
__decorateParam(6, (0,
|
|
5017
|
-
__decorateParam(7, (0,
|
|
5018
|
-
__decorateParam(8, (0,
|
|
5230
|
+
(0, import_common24.Injectable)(),
|
|
5231
|
+
__decorateParam(0, (0, import_common24.Inject)(PLUGIN_CONTEXT)),
|
|
5232
|
+
__decorateParam(1, (0, import_common24.Inject)(ReservationStore)),
|
|
5233
|
+
__decorateParam(2, (0, import_common24.Inject)(ResourceSettingsService)),
|
|
5234
|
+
__decorateParam(3, (0, import_common24.Inject)(GlobalSettingsService)),
|
|
5235
|
+
__decorateParam(4, (0, import_common24.Inject)(AccessService)),
|
|
5236
|
+
__decorateParam(5, (0, import_common24.Inject)(DirectoryService)),
|
|
5237
|
+
__decorateParam(6, (0, import_common24.Inject)(VisibilityService)),
|
|
5238
|
+
__decorateParam(7, (0, import_common24.Inject)(HostInfoService)),
|
|
5239
|
+
__decorateParam(8, (0, import_common24.Inject)(RESERVATION_CLOCK))
|
|
5019
5240
|
], IcalService);
|
|
5020
5241
|
|
|
5021
5242
|
// backend/ical/rate-limiter.ts
|
|
@@ -5085,14 +5306,14 @@ var IcalFeedsController = class {
|
|
|
5085
5306
|
}
|
|
5086
5307
|
};
|
|
5087
5308
|
__decorateClass([
|
|
5088
|
-
(0,
|
|
5309
|
+
(0, import_common25.Get)(),
|
|
5089
5310
|
(0, import_swagger6.ApiOperation)({ summary: "My calendar feeds (without their secret URLs)" }),
|
|
5090
5311
|
(0, import_swagger6.ApiOkResponse)({ type: [IcalFeedDto] }),
|
|
5091
|
-
__decorateParam(0, (0,
|
|
5312
|
+
__decorateParam(0, (0, import_common25.Req)())
|
|
5092
5313
|
], IcalFeedsController.prototype, "list", 1);
|
|
5093
5314
|
__decorateClass([
|
|
5094
|
-
(0,
|
|
5095
|
-
(0,
|
|
5315
|
+
(0, import_common25.Post)(),
|
|
5316
|
+
(0, import_common25.UseGuards)(import_plugins_backend_sdk13.SessionOnlyGuard),
|
|
5096
5317
|
(0, import_swagger6.ApiForbiddenResponse)({ description: "Session authentication required (API tokens cannot issue feed URLs)" }),
|
|
5097
5318
|
(0, import_swagger6.ApiOperation)({
|
|
5098
5319
|
summary: "Create a calendar feed",
|
|
@@ -5101,24 +5322,24 @@ __decorateClass([
|
|
|
5101
5322
|
(0, import_swagger6.ApiBody)({ type: CreateIcalFeedBody }),
|
|
5102
5323
|
(0, import_swagger6.ApiCreatedResponse)({ type: IcalFeedSecretDto }),
|
|
5103
5324
|
ApiReservationErrors({ badRequest: true, conflict: ["FEED_LIMIT"] }),
|
|
5104
|
-
__decorateParam(0, (0,
|
|
5105
|
-
__decorateParam(1, (0,
|
|
5325
|
+
__decorateParam(0, (0, import_common25.Body)(validated(CreateIcalFeedBody))),
|
|
5326
|
+
__decorateParam(1, (0, import_common25.Req)())
|
|
5106
5327
|
], IcalFeedsController.prototype, "create", 1);
|
|
5107
5328
|
__decorateClass([
|
|
5108
|
-
(0,
|
|
5329
|
+
(0, import_common25.Patch)(":id"),
|
|
5109
5330
|
(0, import_swagger6.ApiOperation)({ summary: "Rename a feed or change what it shows (the URL stays)" }),
|
|
5110
5331
|
(0, import_swagger6.ApiParam)(FEED_ID),
|
|
5111
5332
|
(0, import_swagger6.ApiBody)({ type: UpdateIcalFeedBody }),
|
|
5112
5333
|
(0, import_swagger6.ApiOkResponse)({ type: IcalFeedDto }),
|
|
5113
5334
|
ApiReservationErrors({ badRequest: true, notFound: true }),
|
|
5114
|
-
__decorateParam(0, (0,
|
|
5115
|
-
__decorateParam(1, (0,
|
|
5116
|
-
__decorateParam(2, (0,
|
|
5335
|
+
__decorateParam(0, (0, import_common25.Param)("id", import_common25.ParseIntPipe)),
|
|
5336
|
+
__decorateParam(1, (0, import_common25.Body)(validated(UpdateIcalFeedBody))),
|
|
5337
|
+
__decorateParam(2, (0, import_common25.Req)())
|
|
5117
5338
|
], IcalFeedsController.prototype, "update", 1);
|
|
5118
5339
|
__decorateClass([
|
|
5119
|
-
(0,
|
|
5120
|
-
(0,
|
|
5121
|
-
(0,
|
|
5340
|
+
(0, import_common25.Post)(":id/regenerate"),
|
|
5341
|
+
(0, import_common25.HttpCode)(200),
|
|
5342
|
+
(0, import_common25.UseGuards)(import_plugins_backend_sdk13.SessionOnlyGuard),
|
|
5122
5343
|
(0, import_swagger6.ApiForbiddenResponse)({ description: "Session authentication required (API tokens cannot issue feed URLs)" }),
|
|
5123
5344
|
(0, import_swagger6.ApiOperation)({
|
|
5124
5345
|
summary: "Issue a new secret URL; the old one answers 404 immediately",
|
|
@@ -5127,23 +5348,23 @@ __decorateClass([
|
|
|
5127
5348
|
(0, import_swagger6.ApiParam)(FEED_ID),
|
|
5128
5349
|
(0, import_swagger6.ApiOkResponse)({ type: IcalFeedSecretDto }),
|
|
5129
5350
|
ApiReservationErrors({ notFound: true }),
|
|
5130
|
-
__decorateParam(0, (0,
|
|
5131
|
-
__decorateParam(1, (0,
|
|
5351
|
+
__decorateParam(0, (0, import_common25.Param)("id", import_common25.ParseIntPipe)),
|
|
5352
|
+
__decorateParam(1, (0, import_common25.Req)())
|
|
5132
5353
|
], IcalFeedsController.prototype, "regenerate", 1);
|
|
5133
5354
|
__decorateClass([
|
|
5134
|
-
(0,
|
|
5135
|
-
(0,
|
|
5355
|
+
(0, import_common25.Delete)(":id"),
|
|
5356
|
+
(0, import_common25.HttpCode)(204),
|
|
5136
5357
|
(0, import_swagger6.ApiOperation)({ summary: "Revoke a feed (its URL answers 404 from now on)" }),
|
|
5137
5358
|
(0, import_swagger6.ApiParam)(FEED_ID),
|
|
5138
5359
|
ApiReservationErrors({ notFound: true }),
|
|
5139
|
-
__decorateParam(0, (0,
|
|
5140
|
-
__decorateParam(1, (0,
|
|
5360
|
+
__decorateParam(0, (0, import_common25.Param)("id", import_common25.ParseIntPipe)),
|
|
5361
|
+
__decorateParam(1, (0, import_common25.Req)())
|
|
5141
5362
|
], IcalFeedsController.prototype, "revoke", 1);
|
|
5142
5363
|
IcalFeedsController = __decorateClass([
|
|
5143
5364
|
(0, import_swagger6.ApiTags)("Reservations"),
|
|
5144
5365
|
(0, import_plugins_backend_sdk13.Auth)(),
|
|
5145
|
-
(0,
|
|
5146
|
-
__decorateParam(0, (0,
|
|
5366
|
+
(0, import_common25.Controller)("reservations/ical/feeds"),
|
|
5367
|
+
__decorateParam(0, (0, import_common25.Inject)(IcalService))
|
|
5147
5368
|
], IcalFeedsController);
|
|
5148
5369
|
var ICAL_RATE_LIMIT = { perFeedPerMinute: 60, perIpPerMinute: 240 };
|
|
5149
5370
|
var IcalPublicController = class {
|
|
@@ -5154,40 +5375,40 @@ var IcalPublicController = class {
|
|
|
5154
5375
|
__publicField(this, "perIp", new RateLimiter(ICAL_RATE_LIMIT.perIpPerMinute, 6e4));
|
|
5155
5376
|
}
|
|
5156
5377
|
async feed(file, request, response) {
|
|
5157
|
-
if (!file.endsWith(".ics")) throw new
|
|
5378
|
+
if (!file.endsWith(".ics")) throw new import_common25.NotFoundException();
|
|
5158
5379
|
const token = file.slice(0, -4);
|
|
5159
|
-
if (!FEED_TOKEN_PATTERN.test(token)) throw new
|
|
5380
|
+
if (!FEED_TOKEN_PATTERN.test(token)) throw new import_common25.NotFoundException();
|
|
5160
5381
|
const now = this.clock().getTime();
|
|
5161
5382
|
const ip = (request.ip ?? "unknown").slice(0, 64);
|
|
5162
5383
|
let wait = this.perIp.hit(ip, now);
|
|
5163
5384
|
if (wait === 0) wait = this.perFeed.hit(`${ip}|${hashToken(token)}`, now);
|
|
5164
5385
|
if (wait > 0) {
|
|
5165
5386
|
response.setHeader("Retry-After", String(wait));
|
|
5166
|
-
throw new
|
|
5387
|
+
throw new import_common25.HttpException("Too many requests", import_common25.HttpStatus.TOO_MANY_REQUESTS);
|
|
5167
5388
|
}
|
|
5168
5389
|
const calendar = await this.ical.renderForToken(token);
|
|
5169
|
-
if (calendar === null) throw new
|
|
5390
|
+
if (calendar === null) throw new import_common25.NotFoundException();
|
|
5170
5391
|
return calendar;
|
|
5171
5392
|
}
|
|
5172
5393
|
};
|
|
5173
5394
|
__decorateClass([
|
|
5174
|
-
(0,
|
|
5175
|
-
(0,
|
|
5176
|
-
(0,
|
|
5395
|
+
(0, import_common25.Get)(":file"),
|
|
5396
|
+
(0, import_common25.Header)("Cache-Control", "private, max-age=60"),
|
|
5397
|
+
(0, import_common25.Header)("Content-Type", "text/calendar; charset=utf-8"),
|
|
5177
5398
|
(0, import_swagger6.ApiOperation)({ summary: "iCalendar feed (the token in the URL is the credential; no session)" }),
|
|
5178
5399
|
(0, import_swagger6.ApiParam)({ name: "file", type: String, description: "`<token>.ics`" }),
|
|
5179
5400
|
(0, import_swagger6.ApiProduces)("text/calendar"),
|
|
5180
5401
|
(0, import_swagger6.ApiOkResponse)({ description: "RFC 5545 calendar", schema: { type: "string" } }),
|
|
5181
5402
|
ApiReservationErrors({ notFound: true }),
|
|
5182
|
-
__decorateParam(0, (0,
|
|
5183
|
-
__decorateParam(1, (0,
|
|
5184
|
-
__decorateParam(2, (0,
|
|
5403
|
+
__decorateParam(0, (0, import_common25.Param)("file")),
|
|
5404
|
+
__decorateParam(1, (0, import_common25.Req)()),
|
|
5405
|
+
__decorateParam(2, (0, import_common25.Res)({ passthrough: true }))
|
|
5185
5406
|
], IcalPublicController.prototype, "feed", 1);
|
|
5186
5407
|
IcalPublicController = __decorateClass([
|
|
5187
5408
|
(0, import_swagger6.ApiTags)("Reservations"),
|
|
5188
|
-
(0,
|
|
5189
|
-
__decorateParam(0, (0,
|
|
5190
|
-
__decorateParam(1, (0,
|
|
5409
|
+
(0, import_common25.Controller)("reservations/ical"),
|
|
5410
|
+
__decorateParam(0, (0, import_common25.Inject)(IcalService)),
|
|
5411
|
+
__decorateParam(1, (0, import_common25.Inject)(RESERVATION_CLOCK))
|
|
5191
5412
|
], IcalPublicController);
|
|
5192
5413
|
|
|
5193
5414
|
// backend/notifications/email/template-specs.ts
|
|
@@ -5298,15 +5519,22 @@ var TEMPLATE_SPECS = [
|
|
|
5298
5519
|
{
|
|
5299
5520
|
id: "removed",
|
|
5300
5521
|
label: {
|
|
5301
|
-
en: "Booking removed (reservations switched off)",
|
|
5302
|
-
de: "Reservierung entfernt (Reservierungen deaktiviert)"
|
|
5522
|
+
en: "Booking removed (reservations switched off or fewer parallel bookings allowed)",
|
|
5523
|
+
de: "Reservierung entfernt (Reservierungen deaktiviert oder weniger parallele Buchungen m\xF6glich)"
|
|
5303
5524
|
},
|
|
5304
5525
|
subject: { en: "Booking removed: {resource}", de: "Reservierung entfernt: {resource}" },
|
|
5305
5526
|
paragraphs: [
|
|
5306
5527
|
[
|
|
5307
5528
|
"body",
|
|
5308
5529
|
"Reservations were switched off for <strong>{resource}</strong>, so your booking ({when}) was cancelled.",
|
|
5309
|
-
"Reservierungen wurden f\xFCr <strong>{resource}</strong> deaktiviert, daher wurde deine Reservierung ({when}) storniert."
|
|
5530
|
+
"Reservierungen wurden f\xFCr <strong>{resource}</strong> deaktiviert, daher wurde deine Reservierung ({when}) storniert.",
|
|
5531
|
+
"unless:removal.capacity"
|
|
5532
|
+
],
|
|
5533
|
+
[
|
|
5534
|
+
"body_capacity",
|
|
5535
|
+
"<strong>{resource}</strong> now allows fewer parallel bookings, so your booking ({when}) no longer fit and was cancelled.",
|
|
5536
|
+
"F\xFCr <strong>{resource}</strong> sind jetzt weniger parallele Buchungen m\xF6glich, daher passte deine Reservierung ({when}) nicht mehr und wurde storniert.",
|
|
5537
|
+
"if:removal.capacity"
|
|
5310
5538
|
]
|
|
5311
5539
|
]
|
|
5312
5540
|
},
|
|
@@ -5596,7 +5824,7 @@ function toTemplate(spec) {
|
|
|
5596
5824
|
var EMAIL_TEMPLATES = TEMPLATE_SPECS.map(toTemplate);
|
|
5597
5825
|
|
|
5598
5826
|
// backend/scheduler/scheduler.service.ts
|
|
5599
|
-
var
|
|
5827
|
+
var import_common26 = require("@nestjs/common");
|
|
5600
5828
|
var TICK_INTERVAL_MS = 6e4;
|
|
5601
5829
|
var MINUTE_MS5 = 6e4;
|
|
5602
5830
|
var HOUR_MS2 = 60 * MINUTE_MS5;
|
|
@@ -5604,16 +5832,18 @@ var STILL_NEEDED_LEAD_MS = 48 * HOUR_MS2;
|
|
|
5604
5832
|
var REMINDER_LEAD_MS = 24 * HOUR_MS2;
|
|
5605
5833
|
var OVERRUN_CHECK_WINDOW_MS = 5 * TICK_INTERVAL_MS;
|
|
5606
5834
|
var NO_SHOW_NOTICE_WINDOW_MS = 5 * TICK_INTERVAL_MS;
|
|
5835
|
+
var CAPACITY_RECONCILE_MS = HOUR_MS2;
|
|
5607
5836
|
var confirmedAt = (r) => (r.decidedAt ?? r.createdAt).getTime();
|
|
5608
5837
|
var ReservationScheduler = class {
|
|
5609
|
-
constructor(context, store, reservations, settings, notifications, clock) {
|
|
5838
|
+
constructor(context, store, reservations, settings, notifications, clock, directory) {
|
|
5610
5839
|
__publicField(this, "context", context);
|
|
5611
5840
|
__publicField(this, "store", store);
|
|
5612
5841
|
__publicField(this, "reservations", reservations);
|
|
5613
5842
|
__publicField(this, "settings", settings);
|
|
5614
5843
|
__publicField(this, "notifications", notifications);
|
|
5615
5844
|
__publicField(this, "clock", clock);
|
|
5616
|
-
__publicField(this, "
|
|
5845
|
+
__publicField(this, "directory", directory);
|
|
5846
|
+
__publicField(this, "logger", new import_common26.Logger("ReservationsScheduler"));
|
|
5617
5847
|
__publicField(this, "timer", null);
|
|
5618
5848
|
__publicField(this, "running", false);
|
|
5619
5849
|
__publicField(this, "inflight", null);
|
|
@@ -5621,6 +5851,8 @@ var ReservationScheduler = class {
|
|
|
5621
5851
|
__publicField(this, "startsAnnouncedUntil", null);
|
|
5622
5852
|
/** Bookings that start up to here (now + the reader horizon) were already announced to the readers. */
|
|
5623
5853
|
__publicField(this, "readerHorizonAnnouncedUntil", null);
|
|
5854
|
+
/** When every resource was last checked against its current session limit (see `reconcileCapacity`). */
|
|
5855
|
+
__publicField(this, "capacityReconciledAt", null);
|
|
5624
5856
|
}
|
|
5625
5857
|
async onModuleInit() {
|
|
5626
5858
|
await this.settings.whenReady().catch(() => void 0);
|
|
@@ -5652,6 +5884,7 @@ var ReservationScheduler = class {
|
|
|
5652
5884
|
}
|
|
5653
5885
|
async runSteps(now) {
|
|
5654
5886
|
const steps = [
|
|
5887
|
+
["reconcile capacity", (at) => this.reconcileCapacity(at)],
|
|
5655
5888
|
["expire pending", (at) => this.expirePending(at)],
|
|
5656
5889
|
["no-show", (at) => this.markNoShows(at)],
|
|
5657
5890
|
["announce starts", (at) => this.announceStarts(at)],
|
|
@@ -5662,14 +5895,33 @@ var ReservationScheduler = class {
|
|
|
5662
5895
|
["handover", (at) => this.handover(at)],
|
|
5663
5896
|
["overrun", (at) => this.overrun(at)]
|
|
5664
5897
|
];
|
|
5665
|
-
for (const [name,
|
|
5898
|
+
for (const [name, step2] of steps) {
|
|
5666
5899
|
try {
|
|
5667
|
-
await
|
|
5900
|
+
await step2(now);
|
|
5668
5901
|
} catch (error) {
|
|
5669
5902
|
this.logger.error(`scheduler step "${name}" failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
5670
5903
|
}
|
|
5671
5904
|
}
|
|
5672
5905
|
}
|
|
5906
|
+
/**
|
|
5907
|
+
* Safety net for limit changes the plugin missed (it was disabled or the server was down): checks every enabled
|
|
5908
|
+
* resource against its current session limit with the same algorithm as the limit-changed event. Right after
|
|
5909
|
+
* start-up and then once per hour; idempotent.
|
|
5910
|
+
*/
|
|
5911
|
+
async reconcileCapacity(now) {
|
|
5912
|
+
if (this.capacityReconciledAt && now.getTime() - this.capacityReconciledAt.getTime() < CAPACITY_RECONCILE_MS)
|
|
5913
|
+
return;
|
|
5914
|
+
this.capacityReconciledAt = now;
|
|
5915
|
+
for (const resourceId of this.settings.getEnabledResourceIds()) {
|
|
5916
|
+
try {
|
|
5917
|
+
await this.reservations.cancelExcessBookings(resourceId, null);
|
|
5918
|
+
} catch (error) {
|
|
5919
|
+
this.logger.error(
|
|
5920
|
+
`capacity reconciliation of resource ${resourceId} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
5921
|
+
);
|
|
5922
|
+
}
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5673
5925
|
isEnabled(r) {
|
|
5674
5926
|
return this.settings.getCachedSettings(r.resourceId).enabled;
|
|
5675
5927
|
}
|
|
@@ -5776,6 +6028,21 @@ var ReservationScheduler = class {
|
|
|
5776
6028
|
if (await this.store.claimFlag(r.id, "reminder24hSentAt", now)) await this.notifications.notifyReminder24h(r);
|
|
5777
6029
|
});
|
|
5778
6030
|
}
|
|
6031
|
+
/** Slots held at the booking's start by other people's confirmed bookings (holders in session count as sessions). */
|
|
6032
|
+
async heldAtStart(r, sessions) {
|
|
6033
|
+
const confirmed2 = await this.store.findConfirmedOverlapping(
|
|
6034
|
+
r.resourceId,
|
|
6035
|
+
r.startTime,
|
|
6036
|
+
new Date(r.startTime.getTime() + 1)
|
|
6037
|
+
);
|
|
6038
|
+
const inSession = new Set(sessions.map((session) => session.userId));
|
|
6039
|
+
return heldBookings({ confirmed: confirmed2, starterId: r.userId, inSession, at: r.startTime }).length;
|
|
6040
|
+
}
|
|
6041
|
+
/** Shared machine: the holder is in session, or a slot was free for them at the start besides the lingering ones. */
|
|
6042
|
+
async holderHadSlot(r, sessions, lingering, limit) {
|
|
6043
|
+
if (sessions.some((session) => session.userId === r.userId)) return true;
|
|
6044
|
+
return limit - lingering - await this.heldAtStart(r, sessions) > 0;
|
|
6045
|
+
}
|
|
5779
6046
|
/** Users with a running session on the resource, other than the holder, shortly before a booking starts. */
|
|
5780
6047
|
async handover(now) {
|
|
5781
6048
|
const widest = Math.max(
|
|
@@ -5788,10 +6055,11 @@ var ReservationScheduler = class {
|
|
|
5788
6055
|
const settings = this.settings.getCachedSettings(r.resourceId);
|
|
5789
6056
|
const minutes = settings.handoverReminderMinutes;
|
|
5790
6057
|
if (!settings.enabled || minutes <= 0 || r.startTime.getTime() - now.getTime() > minutes * MINUTE_MS5) return;
|
|
5791
|
-
const
|
|
5792
|
-
|
|
5793
|
-
);
|
|
6058
|
+
const sessions = await this.context.resourceAccess.getActiveSessions(r.resourceId);
|
|
6059
|
+
const others = sessions.filter((session) => session.userId !== r.userId);
|
|
5794
6060
|
if (others.length === 0) return;
|
|
6061
|
+
const limit = await this.directory.getSessionLimit(r.resourceId);
|
|
6062
|
+
if (limit > 1 && others.length + await this.heldAtStart(r, sessions) < limit) return;
|
|
5795
6063
|
if (await this.store.claimFlag(r.id, "handoverSentAt", now)) {
|
|
5796
6064
|
await this.notifications.notifyHandover(r, [...new Set(others.map((session) => session.userId))]);
|
|
5797
6065
|
}
|
|
@@ -5807,10 +6075,13 @@ var ReservationScheduler = class {
|
|
|
5807
6075
|
const recent = await this.store.findUpcomingConfirmed(new Date(now.getTime() - OVERRUN_CHECK_WINDOW_MS), now);
|
|
5808
6076
|
await this.each(recent, async (r) => {
|
|
5809
6077
|
if (!this.isEnabled(r) || r.overrunSentAt || r.endTime.getTime() <= now.getTime()) return;
|
|
5810
|
-
const
|
|
6078
|
+
const sessions = await this.context.resourceAccess.getActiveSessions(r.resourceId);
|
|
6079
|
+
const lingering = sessions.filter(
|
|
5811
6080
|
(session) => session.userId !== r.userId && session.startTime.getTime() < r.startTime.getTime()
|
|
5812
6081
|
);
|
|
5813
6082
|
if (lingering.length === 0) return;
|
|
6083
|
+
const limit = await this.directory.getSessionLimit(r.resourceId);
|
|
6084
|
+
if (limit > 1 && await this.holderHadSlot(r, sessions, lingering.length, limit)) return;
|
|
5814
6085
|
if (await this.store.claimFlag(r.id, "overrunSentAt", now)) {
|
|
5815
6086
|
await this.notifications.notifyOverrun(r, [...new Set(lingering.map((session) => session.userId))]);
|
|
5816
6087
|
}
|
|
@@ -5818,18 +6089,19 @@ var ReservationScheduler = class {
|
|
|
5818
6089
|
}
|
|
5819
6090
|
};
|
|
5820
6091
|
ReservationScheduler = __decorateClass([
|
|
5821
|
-
(0,
|
|
5822
|
-
__decorateParam(0, (0,
|
|
5823
|
-
__decorateParam(1, (0,
|
|
5824
|
-
__decorateParam(2, (0,
|
|
5825
|
-
__decorateParam(3, (0,
|
|
5826
|
-
__decorateParam(4, (0,
|
|
5827
|
-
__decorateParam(5, (0,
|
|
6092
|
+
(0, import_common26.Injectable)(),
|
|
6093
|
+
__decorateParam(0, (0, import_common26.Inject)(PLUGIN_CONTEXT)),
|
|
6094
|
+
__decorateParam(1, (0, import_common26.Inject)(ReservationStore)),
|
|
6095
|
+
__decorateParam(2, (0, import_common26.Inject)(ReservationService)),
|
|
6096
|
+
__decorateParam(3, (0, import_common26.Inject)(ResourceSettingsService)),
|
|
6097
|
+
__decorateParam(4, (0, import_common26.Inject)(ReservationNotifications)),
|
|
6098
|
+
__decorateParam(5, (0, import_common26.Inject)(RESERVATION_CLOCK)),
|
|
6099
|
+
__decorateParam(6, (0, import_common26.Inject)(DirectoryService))
|
|
5828
6100
|
], ReservationScheduler);
|
|
5829
6101
|
|
|
5830
6102
|
// backend/api/reservations.controller.ts
|
|
5831
6103
|
var import_plugins_backend_sdk14 = require("@attraccess/plugins-backend-sdk");
|
|
5832
|
-
var
|
|
6104
|
+
var import_common27 = require("@nestjs/common");
|
|
5833
6105
|
var import_swagger7 = require("@nestjs/swagger");
|
|
5834
6106
|
var RESERVATION_ID = { name: "id", type: Number, description: "Reservation id" };
|
|
5835
6107
|
var STATUS_QUERY = {
|
|
@@ -5918,19 +6190,19 @@ var ReservationsController = class {
|
|
|
5918
6190
|
}
|
|
5919
6191
|
};
|
|
5920
6192
|
__decorateClass([
|
|
5921
|
-
(0,
|
|
6193
|
+
(0, import_common27.Get)("resources/:resourceId/pending-decision"),
|
|
5922
6194
|
(0, import_swagger7.ApiOperation)({
|
|
5923
6195
|
summary: 'The caller\u2019s running booking that still awaits a "keep or free the rest?" answer on this resource',
|
|
5924
6196
|
description: "Set when the holder stopped a session inside their own running booking (kept for 15 minutes in memory). The body is the booking, or the JSON value null when nothing is pending. Cleared by keep, end-early, expiry and the holder\u2019s next session start."
|
|
5925
6197
|
}),
|
|
5926
6198
|
(0, import_swagger7.ApiParam)({ name: "resourceId", type: Number }),
|
|
5927
6199
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto, description: "The booking, or null" }),
|
|
5928
|
-
__decorateParam(0, (0,
|
|
5929
|
-
__decorateParam(1, (0,
|
|
5930
|
-
__decorateParam(2, (0,
|
|
6200
|
+
__decorateParam(0, (0, import_common27.Param)("resourceId", import_common27.ParseIntPipe)),
|
|
6201
|
+
__decorateParam(1, (0, import_common27.Req)()),
|
|
6202
|
+
__decorateParam(2, (0, import_common27.Res)())
|
|
5931
6203
|
], ReservationsController.prototype, "pendingDecision", 1);
|
|
5932
6204
|
__decorateClass([
|
|
5933
|
-
(0,
|
|
6205
|
+
(0, import_common27.Get)("resources/:resourceId/availability"),
|
|
5934
6206
|
(0, import_swagger7.ApiOperation)({
|
|
5935
6207
|
summary: "Bookings, booking rules and the caller\u2019s booking permission of a resource for a time range",
|
|
5936
6208
|
description: "Lists pending and confirmed bookings and maintenance that can collide with a booking inside [from, to), i.e. the range widened by the resource\u2019s buffers. Other users\u2019 bookings carry a holder id only for managers of the resource; the holder name is shown to the holder, managers and everyone who may see who uses the resource (core\u2019s activity-visibility rule). Resources the caller cannot see answer 404."
|
|
@@ -5940,33 +6212,33 @@ __decorateClass([
|
|
|
5940
6212
|
(0, import_swagger7.ApiQuery)({ name: "to", type: String, description: "ISO 8601 end of the range, at most 62 days after from" }),
|
|
5941
6213
|
(0, import_swagger7.ApiOkResponse)({ type: AvailabilityDto }),
|
|
5942
6214
|
ApiReservationErrors({ badRequest: true, notFound: true }),
|
|
5943
|
-
__decorateParam(0, (0,
|
|
5944
|
-
__decorateParam(1, (0,
|
|
5945
|
-
__decorateParam(2, (0,
|
|
5946
|
-
__decorateParam(3, (0,
|
|
6215
|
+
__decorateParam(0, (0, import_common27.Param)("resourceId", import_common27.ParseIntPipe)),
|
|
6216
|
+
__decorateParam(1, (0, import_common27.Query)("from")),
|
|
6217
|
+
__decorateParam(2, (0, import_common27.Query)("to")),
|
|
6218
|
+
__decorateParam(3, (0, import_common27.Req)())
|
|
5947
6219
|
], ReservationsController.prototype, "availability", 1);
|
|
5948
6220
|
__decorateClass([
|
|
5949
|
-
(0,
|
|
6221
|
+
(0, import_common27.Get)("mine"),
|
|
5950
6222
|
(0, import_swagger7.ApiOperation)({ summary: "List the caller\u2019s own bookings" }),
|
|
5951
6223
|
(0, import_swagger7.ApiQuery)({ name: "scope", required: false, enum: ["upcoming", "past"], description: "Default: upcoming" }),
|
|
5952
6224
|
(0, import_swagger7.ApiQuery)(STATUS_QUERY),
|
|
5953
6225
|
(0, import_swagger7.ApiOkResponse)({ type: [ReservationDto] }),
|
|
5954
6226
|
ApiReservationErrors({ badRequest: true }),
|
|
5955
|
-
__decorateParam(0, (0,
|
|
5956
|
-
__decorateParam(1, (0,
|
|
5957
|
-
__decorateParam(2, (0,
|
|
6227
|
+
__decorateParam(0, (0, import_common27.Req)()),
|
|
6228
|
+
__decorateParam(1, (0, import_common27.Query)("scope")),
|
|
6229
|
+
__decorateParam(2, (0, import_common27.Query)("status"))
|
|
5958
6230
|
], ReservationsController.prototype, "listMine", 1);
|
|
5959
6231
|
__decorateClass([
|
|
5960
|
-
(0,
|
|
6232
|
+
(0, import_common27.Get)("manage/access"),
|
|
5961
6233
|
(0, import_swagger7.ApiOperation)({
|
|
5962
6234
|
summary: "Whether the caller manages any resource (shows the manager pages)",
|
|
5963
6235
|
description: "True for resources.update holders and for maintainers/introducers of at least one resource."
|
|
5964
6236
|
}),
|
|
5965
6237
|
(0, import_swagger7.ApiOkResponse)({ type: ManagerAccessDto }),
|
|
5966
|
-
__decorateParam(0, (0,
|
|
6238
|
+
__decorateParam(0, (0, import_common27.Req)())
|
|
5967
6239
|
], ReservationsController.prototype, "managerAccess", 1);
|
|
5968
6240
|
__decorateClass([
|
|
5969
|
-
(0,
|
|
6241
|
+
(0, import_common27.Get)("manage"),
|
|
5970
6242
|
(0, import_swagger7.ApiOperation)({
|
|
5971
6243
|
summary: "List bookings of the resources the caller manages",
|
|
5972
6244
|
description: "resources.update sees all resources; maintainers and introducers see the resources they manage. 25 per page."
|
|
@@ -5978,15 +6250,15 @@ __decorateClass([
|
|
|
5978
6250
|
(0, import_swagger7.ApiQuery)({ name: "page", required: false, type: Number, description: "1-based, default 1" }),
|
|
5979
6251
|
(0, import_swagger7.ApiOkResponse)({ type: ManagedReservationListDto }),
|
|
5980
6252
|
ApiReservationErrors({ badRequest: true, forbidden: true }),
|
|
5981
|
-
__decorateParam(0, (0,
|
|
5982
|
-
__decorateParam(1, (0,
|
|
5983
|
-
__decorateParam(2, (0,
|
|
5984
|
-
__decorateParam(3, (0,
|
|
5985
|
-
__decorateParam(4, (0,
|
|
5986
|
-
__decorateParam(5, (0,
|
|
6253
|
+
__decorateParam(0, (0, import_common27.Req)()),
|
|
6254
|
+
__decorateParam(1, (0, import_common27.Query)("resourceId")),
|
|
6255
|
+
__decorateParam(2, (0, import_common27.Query)("status")),
|
|
6256
|
+
__decorateParam(3, (0, import_common27.Query)("from")),
|
|
6257
|
+
__decorateParam(4, (0, import_common27.Query)("to")),
|
|
6258
|
+
__decorateParam(5, (0, import_common27.Query)("page"))
|
|
5987
6259
|
], ReservationsController.prototype, "listManaged", 1);
|
|
5988
6260
|
__decorateClass([
|
|
5989
|
-
(0,
|
|
6261
|
+
(0, import_common27.Post)(),
|
|
5990
6262
|
(0, import_swagger7.ApiOperation)({
|
|
5991
6263
|
summary: "Book a resource",
|
|
5992
6264
|
description: "Creates a confirmed booking, or a pending one when the resource requires approval. Violated rules answer 409 with a typed code."
|
|
@@ -5994,88 +6266,88 @@ __decorateClass([
|
|
|
5994
6266
|
(0, import_swagger7.ApiBody)({ type: CreateReservationBody }),
|
|
5995
6267
|
(0, import_swagger7.ApiCreatedResponse)({ type: ReservationDto }),
|
|
5996
6268
|
ApiReservationErrors({ badRequest: true, notFound: true, conflict: BOOKING_CONFLICT_CODES }),
|
|
5997
|
-
__decorateParam(0, (0,
|
|
5998
|
-
__decorateParam(1, (0,
|
|
6269
|
+
__decorateParam(0, (0, import_common27.Body)(validated(CreateReservationBody))),
|
|
6270
|
+
__decorateParam(1, (0, import_common27.Req)())
|
|
5999
6271
|
], ReservationsController.prototype, "create", 1);
|
|
6000
6272
|
__decorateClass([
|
|
6001
|
-
(0,
|
|
6273
|
+
(0, import_common27.Get)(":id"),
|
|
6002
6274
|
(0, import_swagger7.ApiOperation)({ summary: "Get a booking (holder or manager of its resource)" }),
|
|
6003
6275
|
(0, import_swagger7.ApiParam)(RESERVATION_ID),
|
|
6004
6276
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto }),
|
|
6005
6277
|
ApiReservationErrors({ notFound: true }),
|
|
6006
|
-
__decorateParam(0, (0,
|
|
6007
|
-
__decorateParam(1, (0,
|
|
6278
|
+
__decorateParam(0, (0, import_common27.Param)("id", import_common27.ParseIntPipe)),
|
|
6279
|
+
__decorateParam(1, (0, import_common27.Req)())
|
|
6008
6280
|
], ReservationsController.prototype, "get", 1);
|
|
6009
6281
|
__decorateClass([
|
|
6010
|
-
(0,
|
|
6011
|
-
(0,
|
|
6282
|
+
(0, import_common27.Post)(":id/cancel"),
|
|
6283
|
+
(0, import_common27.HttpCode)(200),
|
|
6012
6284
|
(0, import_swagger7.ApiOperation)({ summary: "Cancel a pending or upcoming booking (holder, or a manager with a reason)" }),
|
|
6013
6285
|
(0, import_swagger7.ApiParam)(RESERVATION_ID),
|
|
6014
6286
|
(0, import_swagger7.ApiBody)({ type: ReasonBody, required: false }),
|
|
6015
6287
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto }),
|
|
6016
6288
|
ApiReservationErrors({ notFound: true, conflict: ["NOT_CANCELLABLE", "ALREADY_STARTED"] }),
|
|
6017
|
-
__decorateParam(0, (0,
|
|
6018
|
-
__decorateParam(1, (0,
|
|
6019
|
-
__decorateParam(2, (0,
|
|
6289
|
+
__decorateParam(0, (0, import_common27.Param)("id", import_common27.ParseIntPipe)),
|
|
6290
|
+
__decorateParam(1, (0, import_common27.Body)(validated(ReasonBody))),
|
|
6291
|
+
__decorateParam(2, (0, import_common27.Req)())
|
|
6020
6292
|
], ReservationsController.prototype, "cancel", 1);
|
|
6021
6293
|
__decorateClass([
|
|
6022
|
-
(0,
|
|
6023
|
-
(0,
|
|
6294
|
+
(0, import_common27.Post)(":id/end-early"),
|
|
6295
|
+
(0, import_common27.HttpCode)(200),
|
|
6024
6296
|
(0, import_swagger7.ApiOperation)({ summary: "End a running booking now and free the rest (holder or manager)" }),
|
|
6025
6297
|
(0, import_swagger7.ApiParam)(RESERVATION_ID),
|
|
6026
6298
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto }),
|
|
6027
6299
|
ApiReservationErrors({ notFound: true, conflict: ["NOT_ACTIVE"] }),
|
|
6028
|
-
__decorateParam(0, (0,
|
|
6029
|
-
__decorateParam(1, (0,
|
|
6300
|
+
__decorateParam(0, (0, import_common27.Param)("id", import_common27.ParseIntPipe)),
|
|
6301
|
+
__decorateParam(1, (0, import_common27.Req)())
|
|
6030
6302
|
], ReservationsController.prototype, "endEarly", 1);
|
|
6031
6303
|
__decorateClass([
|
|
6032
|
-
(0,
|
|
6033
|
-
(0,
|
|
6304
|
+
(0, import_common27.Post)(":id/keep"),
|
|
6305
|
+
(0, import_common27.HttpCode)(200),
|
|
6034
6306
|
(0, import_swagger7.ApiOperation)({ summary: 'Keep the booking ("still needed" / keep the rest after stopping); holder only' }),
|
|
6035
6307
|
(0, import_swagger7.ApiParam)(RESERVATION_ID),
|
|
6036
6308
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto }),
|
|
6037
6309
|
ApiReservationErrors({ notFound: true, conflict: ["ALREADY_FINISHED"] }),
|
|
6038
|
-
__decorateParam(0, (0,
|
|
6039
|
-
__decorateParam(1, (0,
|
|
6310
|
+
__decorateParam(0, (0, import_common27.Param)("id", import_common27.ParseIntPipe)),
|
|
6311
|
+
__decorateParam(1, (0, import_common27.Req)())
|
|
6040
6312
|
], ReservationsController.prototype, "keep", 1);
|
|
6041
6313
|
__decorateClass([
|
|
6042
|
-
(0,
|
|
6043
|
-
(0,
|
|
6314
|
+
(0, import_common27.Post)(":id/approve"),
|
|
6315
|
+
(0, import_common27.HttpCode)(200),
|
|
6044
6316
|
(0, import_swagger7.ApiOperation)({ summary: "Approve a pending booking (manager)" }),
|
|
6045
6317
|
(0, import_swagger7.ApiParam)(RESERVATION_ID),
|
|
6046
6318
|
(0, import_swagger7.ApiBody)({ type: ReasonBody, required: false }),
|
|
6047
6319
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto }),
|
|
6048
6320
|
ApiReservationErrors({ notFound: true, forbidden: true, conflict: STATE_CONFLICT_CODES }),
|
|
6049
|
-
__decorateParam(0, (0,
|
|
6050
|
-
__decorateParam(1, (0,
|
|
6051
|
-
__decorateParam(2, (0,
|
|
6321
|
+
__decorateParam(0, (0, import_common27.Param)("id", import_common27.ParseIntPipe)),
|
|
6322
|
+
__decorateParam(1, (0, import_common27.Body)(validated(ReasonBody))),
|
|
6323
|
+
__decorateParam(2, (0, import_common27.Req)())
|
|
6052
6324
|
], ReservationsController.prototype, "approve", 1);
|
|
6053
6325
|
__decorateClass([
|
|
6054
|
-
(0,
|
|
6055
|
-
(0,
|
|
6326
|
+
(0, import_common27.Post)(":id/reject"),
|
|
6327
|
+
(0, import_common27.HttpCode)(200),
|
|
6056
6328
|
(0, import_swagger7.ApiOperation)({ summary: "Reject a pending booking (manager)" }),
|
|
6057
6329
|
(0, import_swagger7.ApiParam)(RESERVATION_ID),
|
|
6058
6330
|
(0, import_swagger7.ApiBody)({ type: ReasonBody, required: false }),
|
|
6059
6331
|
(0, import_swagger7.ApiOkResponse)({ type: ReservationDto }),
|
|
6060
6332
|
ApiReservationErrors({ notFound: true, forbidden: true, conflict: STATE_CONFLICT_CODES }),
|
|
6061
|
-
__decorateParam(0, (0,
|
|
6062
|
-
__decorateParam(1, (0,
|
|
6063
|
-
__decorateParam(2, (0,
|
|
6333
|
+
__decorateParam(0, (0, import_common27.Param)("id", import_common27.ParseIntPipe)),
|
|
6334
|
+
__decorateParam(1, (0, import_common27.Body)(validated(ReasonBody))),
|
|
6335
|
+
__decorateParam(2, (0, import_common27.Req)())
|
|
6064
6336
|
], ReservationsController.prototype, "reject", 1);
|
|
6065
6337
|
ReservationsController = __decorateClass([
|
|
6066
6338
|
(0, import_swagger7.ApiTags)("Reservations"),
|
|
6067
6339
|
(0, import_plugins_backend_sdk14.Auth)(),
|
|
6068
|
-
(0,
|
|
6069
|
-
__decorateParam(0, (0,
|
|
6070
|
-
__decorateParam(1, (0,
|
|
6071
|
-
__decorateParam(2, (0,
|
|
6340
|
+
(0, import_common27.Controller)("reservations"),
|
|
6341
|
+
__decorateParam(0, (0, import_common27.Inject)(ReservationService)),
|
|
6342
|
+
__decorateParam(1, (0, import_common27.Inject)(ReservationQueryService)),
|
|
6343
|
+
__decorateParam(2, (0, import_common27.Inject)(PendingDecisionService))
|
|
6072
6344
|
], ReservationsController);
|
|
6073
6345
|
|
|
6074
6346
|
// backend/plugin.ts
|
|
6075
6347
|
var ReservationsPluginModule = class {
|
|
6076
6348
|
};
|
|
6077
6349
|
var plugin = {
|
|
6078
|
-
|
|
6350
|
+
storage: reservationsStorage,
|
|
6079
6351
|
auditDomains: [RESERVATIONS_AUDIT_DOMAIN],
|
|
6080
6352
|
notificationCategories: [...NOTIFICATION_CATEGORIES],
|
|
6081
6353
|
emailTemplates: EMAIL_TEMPLATES,
|
|
@@ -6083,6 +6355,7 @@ var plugin = {
|
|
|
6083
6355
|
preStartHook,
|
|
6084
6356
|
sessionEndHook,
|
|
6085
6357
|
startBlockedQuery,
|
|
6358
|
+
startCapacityHook,
|
|
6086
6359
|
readerUi: readerUiProvider,
|
|
6087
6360
|
register(context) {
|
|
6088
6361
|
return {
|
|
@@ -6107,6 +6380,7 @@ var plugin = {
|
|
|
6107
6380
|
PendingDecisionStore,
|
|
6108
6381
|
PendingDecisionService,
|
|
6109
6382
|
PreStartService,
|
|
6383
|
+
StartCapacityService,
|
|
6110
6384
|
SessionEndService,
|
|
6111
6385
|
ReaderUiService,
|
|
6112
6386
|
HookServicePublisher,
|