@attraccess/plugin-reservations 0.1.0-nightly.1188.1 → 0.2.0-nightly.1197.2
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/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
|
|
|
@@ -196,7 +196,6 @@ var ReservationError = class extends import_common2.HttpException {
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
// backend/reservations/directory.service.ts
|
|
199
|
-
var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
|
|
200
199
|
var import_common3 = require("@nestjs/common");
|
|
201
200
|
|
|
202
201
|
// backend/reservations/capacity.ts
|
|
@@ -412,11 +411,11 @@ function checkBookingRules(args) {
|
|
|
412
411
|
if (start.getTime() < now.getTime() - PAST_TOLERANCE_MS) {
|
|
413
412
|
return new ReservationError("IN_THE_PAST", "The booking starts in the past");
|
|
414
413
|
}
|
|
415
|
-
const
|
|
414
|
+
const step2 = settings.timeStepMinutes;
|
|
416
415
|
const durationMinutes = (end.getTime() - start.getTime()) / MINUTE_MS;
|
|
417
|
-
const onGrid = isWholeMinute(start) && isWholeMinute(end) && localMinutesOfDay(start, timeZone) %
|
|
416
|
+
const onGrid = isWholeMinute(start) && isWholeMinute(end) && localMinutesOfDay(start, timeZone) % step2 === 0 && durationMinutes % step2 === 0;
|
|
418
417
|
if (!onGrid) {
|
|
419
|
-
return new ReservationError("OFF_TIME_STEP", `Start and duration must be a multiple of ${
|
|
418
|
+
return new ReservationError("OFF_TIME_STEP", `Start and duration must be a multiple of ${step2} minutes`);
|
|
420
419
|
}
|
|
421
420
|
if (durationMinutes < settings.minDurationMinutes) {
|
|
422
421
|
return new ReservationError("DURATION_TOO_SHORT", `The minimum duration is ${settings.minDurationMinutes} minutes`);
|
|
@@ -512,36 +511,30 @@ var DirectoryService = class {
|
|
|
512
511
|
__publicField(this, "context", context);
|
|
513
512
|
}
|
|
514
513
|
async getResource(resourceId) {
|
|
515
|
-
const row = await this.context.
|
|
514
|
+
const row = await this.context.hostData.resources.get(resourceId);
|
|
516
515
|
return row ? { id: row.id, name: row.name } : null;
|
|
517
516
|
}
|
|
518
|
-
/**
|
|
519
|
-
|
|
520
|
-
|
|
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;
|
|
521
523
|
}
|
|
522
524
|
/** Effective session limit, or null when the resource does not exist (anymore: deleted resources are not found). */
|
|
523
|
-
async findSessionLimit(resourceId,
|
|
524
|
-
const row = await
|
|
525
|
-
where: { id: resourceId },
|
|
526
|
-
select: { id: true, type: true, maxParallelSessions: true }
|
|
527
|
-
});
|
|
525
|
+
async findSessionLimit(resourceId, scope) {
|
|
526
|
+
const row = await this.context.hostData.resources.get(resourceId, scope);
|
|
528
527
|
return row ? sessionLimitOf(row) : null;
|
|
529
528
|
}
|
|
530
529
|
/** Running sessions on the resource, earliest first. */
|
|
531
530
|
getActiveSessions(resourceId) {
|
|
532
531
|
return this.context.resourceAccess.getActiveSessions(resourceId);
|
|
533
532
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
537
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk2.Resource).createQueryBuilder("resource").select(["resource.id", "resource.name"]).where("resource.id IN (:...ids)", { ids }).getMany();
|
|
538
|
-
return new Map(rows.map((row) => [row.id, row.name]));
|
|
533
|
+
getResourceNames(resourceIds) {
|
|
534
|
+
return this.context.hostData.resources.getNames(resourceIds);
|
|
539
535
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
543
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk2.User).createQueryBuilder("user").select(["user.id", "user.username"]).where("user.id IN (:...ids)", { ids }).getMany();
|
|
544
|
-
return new Map(rows.map((row) => [row.id, row.username]));
|
|
536
|
+
getUserNames(userIds) {
|
|
537
|
+
return this.context.hostData.users.getUsernames(userIds);
|
|
545
538
|
}
|
|
546
539
|
};
|
|
547
540
|
DirectoryService = __decorateClass([
|
|
@@ -555,154 +548,8 @@ var import_common9 = require("@nestjs/common");
|
|
|
555
548
|
// backend/reservations/reservation.service.ts
|
|
556
549
|
var import_common8 = require("@nestjs/common");
|
|
557
550
|
|
|
558
|
-
// backend/entities/reservation.entity.ts
|
|
559
|
-
var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
|
|
560
|
-
var RESERVATION_STATUSES = [
|
|
561
|
-
"pending",
|
|
562
|
-
"confirmed",
|
|
563
|
-
"rejected",
|
|
564
|
-
"cancelled",
|
|
565
|
-
"expired",
|
|
566
|
-
"no_show",
|
|
567
|
-
"completed"
|
|
568
|
-
];
|
|
569
|
-
var REMINDER_FLAGS = [
|
|
570
|
-
"confirmationSentAt",
|
|
571
|
-
"stillNeededSentAt",
|
|
572
|
-
"reminder24hSentAt",
|
|
573
|
-
"handoverSentAt",
|
|
574
|
-
"overrunSentAt",
|
|
575
|
-
"noShowNotifiedAt",
|
|
576
|
-
"expiredNotifiedAt"
|
|
577
|
-
];
|
|
578
|
-
var ReservationEntity = class {
|
|
579
|
-
constructor() {
|
|
580
|
-
__publicField(this, "id");
|
|
581
|
-
__publicField(this, "resourceId");
|
|
582
|
-
__publicField(this, "userId");
|
|
583
|
-
__publicField(this, "startTime");
|
|
584
|
-
__publicField(this, "endTime");
|
|
585
|
-
__publicField(this, "bufferBeforeMinutes");
|
|
586
|
-
__publicField(this, "bufferAfterMinutes");
|
|
587
|
-
__publicField(this, "status");
|
|
588
|
-
__publicField(this, "note");
|
|
589
|
-
__publicField(this, "createdAt");
|
|
590
|
-
__publicField(this, "endedEarlyAt");
|
|
591
|
-
__publicField(this, "cancelledBy");
|
|
592
|
-
__publicField(this, "cancelReason");
|
|
593
|
-
__publicField(this, "decidedBy");
|
|
594
|
-
__publicField(this, "decisionReason");
|
|
595
|
-
__publicField(this, "decidedAt");
|
|
596
|
-
__publicField(this, "checkedInAt");
|
|
597
|
-
__publicField(this, "checkedInUsageId");
|
|
598
|
-
__publicField(this, "keptAt");
|
|
599
|
-
__publicField(this, "confirmationSentAt");
|
|
600
|
-
__publicField(this, "stillNeededSentAt");
|
|
601
|
-
__publicField(this, "reminder24hSentAt");
|
|
602
|
-
__publicField(this, "handoverSentAt");
|
|
603
|
-
__publicField(this, "overrunSentAt");
|
|
604
|
-
__publicField(this, "noShowNotifiedAt");
|
|
605
|
-
__publicField(this, "expiredNotifiedAt");
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
__decorateClass([
|
|
609
|
-
(0, import_plugins_backend_sdk3.PrimaryGeneratedColumn)({ type: "integer" })
|
|
610
|
-
], ReservationEntity.prototype, "id", 2);
|
|
611
|
-
__decorateClass([
|
|
612
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer" })
|
|
613
|
-
], ReservationEntity.prototype, "resourceId", 2);
|
|
614
|
-
__decorateClass([
|
|
615
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer" })
|
|
616
|
-
], ReservationEntity.prototype, "userId", 2);
|
|
617
|
-
__decorateClass([
|
|
618
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime" })
|
|
619
|
-
], ReservationEntity.prototype, "startTime", 2);
|
|
620
|
-
__decorateClass([
|
|
621
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime" })
|
|
622
|
-
], ReservationEntity.prototype, "endTime", 2);
|
|
623
|
-
__decorateClass([
|
|
624
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer", default: 0 })
|
|
625
|
-
], ReservationEntity.prototype, "bufferBeforeMinutes", 2);
|
|
626
|
-
__decorateClass([
|
|
627
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer", default: 0 })
|
|
628
|
-
], ReservationEntity.prototype, "bufferAfterMinutes", 2);
|
|
629
|
-
__decorateClass([
|
|
630
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar" })
|
|
631
|
-
], ReservationEntity.prototype, "status", 2);
|
|
632
|
-
__decorateClass([
|
|
633
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar", nullable: true })
|
|
634
|
-
], ReservationEntity.prototype, "note", 2);
|
|
635
|
-
__decorateClass([
|
|
636
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime" })
|
|
637
|
-
], ReservationEntity.prototype, "createdAt", 2);
|
|
638
|
-
__decorateClass([
|
|
639
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
640
|
-
], ReservationEntity.prototype, "endedEarlyAt", 2);
|
|
641
|
-
__decorateClass([
|
|
642
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer", nullable: true })
|
|
643
|
-
], ReservationEntity.prototype, "cancelledBy", 2);
|
|
644
|
-
__decorateClass([
|
|
645
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar", nullable: true })
|
|
646
|
-
], ReservationEntity.prototype, "cancelReason", 2);
|
|
647
|
-
__decorateClass([
|
|
648
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer", nullable: true })
|
|
649
|
-
], ReservationEntity.prototype, "decidedBy", 2);
|
|
650
|
-
__decorateClass([
|
|
651
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "varchar", nullable: true })
|
|
652
|
-
], ReservationEntity.prototype, "decisionReason", 2);
|
|
653
|
-
__decorateClass([
|
|
654
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
655
|
-
], ReservationEntity.prototype, "decidedAt", 2);
|
|
656
|
-
__decorateClass([
|
|
657
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
658
|
-
], ReservationEntity.prototype, "checkedInAt", 2);
|
|
659
|
-
__decorateClass([
|
|
660
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "integer", nullable: true })
|
|
661
|
-
], ReservationEntity.prototype, "checkedInUsageId", 2);
|
|
662
|
-
__decorateClass([
|
|
663
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
664
|
-
], ReservationEntity.prototype, "keptAt", 2);
|
|
665
|
-
__decorateClass([
|
|
666
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
667
|
-
], ReservationEntity.prototype, "confirmationSentAt", 2);
|
|
668
|
-
__decorateClass([
|
|
669
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
670
|
-
], ReservationEntity.prototype, "stillNeededSentAt", 2);
|
|
671
|
-
__decorateClass([
|
|
672
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
673
|
-
], ReservationEntity.prototype, "reminder24hSentAt", 2);
|
|
674
|
-
__decorateClass([
|
|
675
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
676
|
-
], ReservationEntity.prototype, "handoverSentAt", 2);
|
|
677
|
-
__decorateClass([
|
|
678
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
679
|
-
], ReservationEntity.prototype, "overrunSentAt", 2);
|
|
680
|
-
__decorateClass([
|
|
681
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
682
|
-
], ReservationEntity.prototype, "noShowNotifiedAt", 2);
|
|
683
|
-
__decorateClass([
|
|
684
|
-
(0, import_plugins_backend_sdk3.Column)({ type: "datetime", nullable: true })
|
|
685
|
-
], ReservationEntity.prototype, "expiredNotifiedAt", 2);
|
|
686
|
-
ReservationEntity = __decorateClass([
|
|
687
|
-
(0, import_plugins_backend_sdk3.Entity)({ name: "reservations_reservation" }),
|
|
688
|
-
(0, import_plugins_backend_sdk3.Index)("IDX_reservations_reservation_slot", ["resourceId", "status", "startTime", "endTime"]),
|
|
689
|
-
(0, import_plugins_backend_sdk3.Index)("IDX_reservations_reservation_user", ["userId", "status"])
|
|
690
|
-
], ReservationEntity);
|
|
691
|
-
|
|
692
551
|
// backend/ical/visibility.service.ts
|
|
693
|
-
var import_plugins_backend_sdk4 = require("@attraccess/plugins-backend-sdk");
|
|
694
552
|
var import_common4 = require("@nestjs/common");
|
|
695
|
-
var import_typeorm = require("typeorm");
|
|
696
|
-
var ACTIVE_INTRODUCTION_EXISTS_SQL = `EXISTS (
|
|
697
|
-
SELECT 1 FROM "resource_introduction" "rin"
|
|
698
|
-
WHERE "rin"."resourceGroupId" = vg.id AND "rin"."receiverUserId" = :userId
|
|
699
|
-
AND (
|
|
700
|
-
SELECT "h"."action" FROM "resource_introduction_history_item" "h"
|
|
701
|
-
WHERE "h"."introductionId" = "rin"."id"
|
|
702
|
-
ORDER BY "h"."createdAt" DESC, "h"."id" DESC
|
|
703
|
-
LIMIT 1
|
|
704
|
-
) = 'grant'
|
|
705
|
-
)`;
|
|
706
553
|
var VisibilityService = class {
|
|
707
554
|
constructor(context, access) {
|
|
708
555
|
__publicField(this, "context", context);
|
|
@@ -713,39 +560,27 @@ var VisibilityService = class {
|
|
|
713
560
|
* `resources.update` shortcut, as core applies an API token's scope to its group visibility.
|
|
714
561
|
*/
|
|
715
562
|
async filterVisible(subject, resourceIds) {
|
|
716
|
-
const userId = subjectUserId(subject);
|
|
717
563
|
const ids = [...new Set(resourceIds)];
|
|
718
564
|
if (ids.length === 0) return [];
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
`EXISTS (SELECT 1 FROM "resource_introducer" "ri" WHERE "ri"."resourceGroupId" = vg.id AND "ri"."userId" = :userId)`
|
|
723
|
-
).orWhere(ACTIVE_INTRODUCTION_EXISTS_SQL);
|
|
724
|
-
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 });
|
|
725
|
-
}
|
|
726
|
-
const rows = await base.distinct(true).getRawMany();
|
|
727
|
-
return rows.map((row) => Number(row.id));
|
|
565
|
+
return this.context.hostData.resources.filterVisible(subjectUserId(subject), ids, {
|
|
566
|
+
seeAll: await this.access.hasUpdatePermission(subject)
|
|
567
|
+
});
|
|
728
568
|
}
|
|
729
569
|
/**
|
|
730
570
|
* Whether the account exists, is not soft-deleted and not disabled. Deleting or disabling a user keeps
|
|
731
571
|
* their role rows, so anything acting on their behalf without a session (iCal feeds) must check this.
|
|
732
572
|
*/
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
return user !== null && !user.isDisabled;
|
|
573
|
+
isActiveAccount(userId) {
|
|
574
|
+
return this.context.hostData.users.isActive(userId);
|
|
736
575
|
}
|
|
737
576
|
/** The subset of `resourceIds` whose sessions always need a supervisor (`supervision_required`). */
|
|
738
|
-
|
|
577
|
+
resourceIdsRequiringSupervision(resourceIds) {
|
|
739
578
|
const ids = [...new Set(resourceIds)];
|
|
740
|
-
|
|
741
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk4.Resource).createQueryBuilder("resource").select("resource.id", "id").where("resource.id IN (:...ids)", { ids }).andWhere("resource.supervisionMode = :mode", { mode: import_plugins_backend_sdk4.SupervisionMode.SUPERVISION_REQUIRED }).getRawMany();
|
|
742
|
-
return rows.map((row) => Number(row.id));
|
|
579
|
+
return ids.length === 0 ? Promise.resolve([]) : this.context.hostData.resources.filterRequiringSupervision(ids);
|
|
743
580
|
}
|
|
744
581
|
/** Ids of all resources in the given groups. */
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const rows = await this.context.getRepository(import_plugins_backend_sdk4.Resource).createQueryBuilder("resource").select("resource.id", "id").innerJoin("resource.groups", "g").where("g.id IN (:...groupIds)", { groupIds }).distinct(true).getRawMany();
|
|
748
|
-
return rows.map((row) => Number(row.id));
|
|
582
|
+
resourceIdsOfGroups(groupIds) {
|
|
583
|
+
return this.context.hostData.resources.listIdsInGroups(groupIds);
|
|
749
584
|
}
|
|
750
585
|
};
|
|
751
586
|
VisibilityService = __decorateClass([
|
|
@@ -757,91 +592,184 @@ VisibilityService = __decorateClass([
|
|
|
757
592
|
// backend/settings/resource-settings.service.ts
|
|
758
593
|
var import_common5 = require("@nestjs/common");
|
|
759
594
|
|
|
760
|
-
// backend/
|
|
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
|
|
761
650
|
var import_plugins_backend_sdk5 = require("@attraccess/plugins-backend-sdk");
|
|
762
|
-
var
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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
|
+
]
|
|
783
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
|
|
784
752
|
};
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
],
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
], ResourceSettingsEntity.prototype, "maxAdvanceDays", 2);
|
|
806
|
-
__decorateClass([
|
|
807
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 0 })
|
|
808
|
-
], ResourceSettingsEntity.prototype, "minLeadMinutes", 2);
|
|
809
|
-
__decorateClass([
|
|
810
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 0 })
|
|
811
|
-
], ResourceSettingsEntity.prototype, "bufferBeforeMinutes", 2);
|
|
812
|
-
__decorateClass([
|
|
813
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 0 })
|
|
814
|
-
], ResourceSettingsEntity.prototype, "bufferAfterMinutes", 2);
|
|
815
|
-
__decorateClass([
|
|
816
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 3 })
|
|
817
|
-
], ResourceSettingsEntity.prototype, "maxActiveBookingsPerUser", 2);
|
|
818
|
-
__decorateClass([
|
|
819
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "varchar", default: "can-start" })
|
|
820
|
-
], ResourceSettingsEntity.prototype, "whoCanBook", 2);
|
|
821
|
-
__decorateClass([
|
|
822
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 60 })
|
|
823
|
-
], ResourceSettingsEntity.prototype, "confirmWindowMinutes", 2);
|
|
824
|
-
__decorateClass([
|
|
825
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "boolean", default: true })
|
|
826
|
-
], ResourceSettingsEntity.prototype, "checkInEnabled", 2);
|
|
827
|
-
__decorateClass([
|
|
828
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 15 })
|
|
829
|
-
], ResourceSettingsEntity.prototype, "checkInGraceMinutes", 2);
|
|
830
|
-
__decorateClass([
|
|
831
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 15 })
|
|
832
|
-
], ResourceSettingsEntity.prototype, "earlyCheckInMinutes", 2);
|
|
833
|
-
__decorateClass([
|
|
834
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "integer", default: 15 })
|
|
835
|
-
], ResourceSettingsEntity.prototype, "handoverReminderMinutes", 2);
|
|
836
|
-
__decorateClass([
|
|
837
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "text", default: "{}" })
|
|
838
|
-
], ResourceSettingsEntity.prototype, "bookableHours", 2);
|
|
839
|
-
__decorateClass([
|
|
840
|
-
(0, import_plugins_backend_sdk5.Column)({ type: "datetime" })
|
|
841
|
-
], ResourceSettingsEntity.prototype, "updatedAt", 2);
|
|
842
|
-
ResourceSettingsEntity = __decorateClass([
|
|
843
|
-
(0, import_plugins_backend_sdk5.Entity)({ name: "reservations_resource_settings" })
|
|
844
|
-
], ResourceSettingsEntity);
|
|
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
|
+
}
|
|
845
773
|
|
|
846
774
|
// backend/settings/settings.model.ts
|
|
847
775
|
var WHO_CAN_BOOK = ["can-start", "managers-only", "any-user"];
|
|
@@ -892,12 +820,12 @@ function validateSettings(values) {
|
|
|
892
820
|
if (errors.some((error) => error.field === "timeStepMinutes") === false && 1440 % values.timeStepMinutes !== 0) {
|
|
893
821
|
errors.push({ field: "timeStepMinutes", message: "must divide 1440 so the grid repeats every day" });
|
|
894
822
|
}
|
|
895
|
-
const
|
|
823
|
+
const step2 = values.timeStepMinutes;
|
|
896
824
|
if (!errors.length) {
|
|
897
|
-
if (values.minDurationMinutes %
|
|
825
|
+
if (values.minDurationMinutes % step2 !== 0) {
|
|
898
826
|
errors.push({ field: "minDurationMinutes", message: "must be a multiple of the time step" });
|
|
899
827
|
}
|
|
900
|
-
if (values.maxDurationMinutes %
|
|
828
|
+
if (values.maxDurationMinutes % step2 !== 0) {
|
|
901
829
|
errors.push({ field: "maxDurationMinutes", message: "must be a multiple of the time step" });
|
|
902
830
|
}
|
|
903
831
|
if (values.maxDurationMinutes < values.minDurationMinutes) {
|
|
@@ -935,7 +863,7 @@ function settingsValues(settings) {
|
|
|
935
863
|
}
|
|
936
864
|
|
|
937
865
|
// backend/settings/resource-settings.service.ts
|
|
938
|
-
function
|
|
866
|
+
function fromRow(row) {
|
|
939
867
|
let bookableHours;
|
|
940
868
|
try {
|
|
941
869
|
bookableHours = normalizeBookableHours(JSON.parse(row.bookableHours || "{}"));
|
|
@@ -971,6 +899,9 @@ var ResourceSettingsService = class {
|
|
|
971
899
|
__publicField(this, "warmed", null);
|
|
972
900
|
__publicField(this, "warm", false);
|
|
973
901
|
}
|
|
902
|
+
get rows() {
|
|
903
|
+
return tablesOf(this.context).resourceSettings;
|
|
904
|
+
}
|
|
974
905
|
async onModuleInit() {
|
|
975
906
|
await this.warmUp().catch((error) => this.logger.error(`settings cache warm-up failed: ${String(error)}`));
|
|
976
907
|
}
|
|
@@ -995,9 +926,9 @@ var ResourceSettingsService = class {
|
|
|
995
926
|
return this.warmUp();
|
|
996
927
|
}
|
|
997
928
|
async loadAll() {
|
|
998
|
-
const rows = await this.
|
|
929
|
+
const rows = await this.rows.find();
|
|
999
930
|
this.cache.clear();
|
|
1000
|
-
for (const row of rows) this.cache.set(row.resourceId,
|
|
931
|
+
for (const row of rows) this.cache.set(row.resourceId, fromRow(row));
|
|
1001
932
|
}
|
|
1002
933
|
/**
|
|
1003
934
|
* Synchronous, database-free accessor for the pre-start hook. Resources without a row (and every
|
|
@@ -1012,8 +943,8 @@ var ResourceSettingsService = class {
|
|
|
1012
943
|
}
|
|
1013
944
|
/** Authoritative read from the database (defaults when no row exists). */
|
|
1014
945
|
async get(resourceId) {
|
|
1015
|
-
const row = await this.
|
|
1016
|
-
return row ?
|
|
946
|
+
const row = await this.rows.get(resourceId);
|
|
947
|
+
return row ? fromRow(row) : defaultSettings(resourceId);
|
|
1017
948
|
}
|
|
1018
949
|
/** Validates, persists and refreshes the cache. Throws a 400 `INVALID_SETTINGS` on invalid input. */
|
|
1019
950
|
async update(resourceId, patch) {
|
|
@@ -1024,13 +955,10 @@ var ResourceSettingsService = class {
|
|
|
1024
955
|
throw new ReservationError("INVALID_SETTINGS", "Invalid reservation settings", { errors });
|
|
1025
956
|
}
|
|
1026
957
|
const merged = finalizeSettings(requested);
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
resourceId
|
|
1030
|
-
|
|
1031
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1032
|
-
});
|
|
1033
|
-
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
|
+
);
|
|
1034
962
|
const after = { resourceId, ...merged };
|
|
1035
963
|
this.cache.set(resourceId, after);
|
|
1036
964
|
return { before, after };
|
|
@@ -1047,26 +975,6 @@ ResourceSettingsService = __decorateClass([
|
|
|
1047
975
|
|
|
1048
976
|
// backend/settings/global-settings.service.ts
|
|
1049
977
|
var import_common6 = require("@nestjs/common");
|
|
1050
|
-
|
|
1051
|
-
// backend/entities/global-settings.entity.ts
|
|
1052
|
-
var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
|
|
1053
|
-
var GlobalSettingsEntity = class {
|
|
1054
|
-
constructor() {
|
|
1055
|
-
__publicField(this, "key");
|
|
1056
|
-
__publicField(this, "value");
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
__decorateClass([
|
|
1060
|
-
(0, import_plugins_backend_sdk6.PrimaryColumn)({ type: "varchar" })
|
|
1061
|
-
], GlobalSettingsEntity.prototype, "key", 2);
|
|
1062
|
-
__decorateClass([
|
|
1063
|
-
(0, import_plugins_backend_sdk6.Column)({ type: "text" })
|
|
1064
|
-
], GlobalSettingsEntity.prototype, "value", 2);
|
|
1065
|
-
GlobalSettingsEntity = __decorateClass([
|
|
1066
|
-
(0, import_plugins_backend_sdk6.Entity)({ name: "reservations_global_settings" })
|
|
1067
|
-
], GlobalSettingsEntity);
|
|
1068
|
-
|
|
1069
|
-
// backend/settings/global-settings.service.ts
|
|
1070
978
|
var TIMEZONE_KEY = "timezone";
|
|
1071
979
|
var GlobalSettingsService = class {
|
|
1072
980
|
constructor(context) {
|
|
@@ -1076,7 +984,7 @@ var GlobalSettingsService = class {
|
|
|
1076
984
|
/** The configured IANA timezone, or the server's when unset or no longer valid. Cached. */
|
|
1077
985
|
async getTimezone() {
|
|
1078
986
|
if (this.cachedTimezone) return this.cachedTimezone;
|
|
1079
|
-
const row = await this.context
|
|
987
|
+
const row = await tablesOf(this.context).globalSettings.get(TIMEZONE_KEY);
|
|
1080
988
|
this.cachedTimezone = row && isValidTimeZone(row.value) ? row.value : serverTimeZone();
|
|
1081
989
|
return this.cachedTimezone;
|
|
1082
990
|
}
|
|
@@ -1088,10 +996,7 @@ var GlobalSettingsService = class {
|
|
|
1088
996
|
throw new ReservationError("INVALID_TIMEZONE", `"${String(timezone)}" is not a valid IANA timezone`);
|
|
1089
997
|
}
|
|
1090
998
|
const before = await this.getTimezone();
|
|
1091
|
-
|
|
1092
|
-
entity.key = TIMEZONE_KEY;
|
|
1093
|
-
entity.value = timezone;
|
|
1094
|
-
await this.context.runSerialized((manager) => manager.getRepository(GlobalSettingsEntity).save(entity));
|
|
999
|
+
await tablesOf(this.context).globalSettings.upsert({ key: TIMEZONE_KEY, value: timezone }, { conflictOn: ["key"] });
|
|
1095
1000
|
this.cachedTimezone = timezone;
|
|
1096
1001
|
return { timezone, before };
|
|
1097
1002
|
}
|
|
@@ -1204,117 +1109,110 @@ var KeyedMutex = class {
|
|
|
1204
1109
|
};
|
|
1205
1110
|
|
|
1206
1111
|
// backend/reservations/reservation.store.ts
|
|
1112
|
+
var import_plugins_backend_sdk8 = require("@attraccess/plugins-backend-sdk");
|
|
1207
1113
|
var import_common7 = require("@nestjs/common");
|
|
1208
|
-
|
|
1209
|
-
// backend/entities/notice.entity.ts
|
|
1210
|
-
var import_plugins_backend_sdk7 = require("@attraccess/plugins-backend-sdk");
|
|
1211
|
-
var NoticeEntity = class {
|
|
1212
|
-
constructor() {
|
|
1213
|
-
__publicField(this, "id");
|
|
1214
|
-
__publicField(this, "reservationId");
|
|
1215
|
-
__publicField(this, "kind");
|
|
1216
|
-
__publicField(this, "refKey");
|
|
1217
|
-
__publicField(this, "sentAt");
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
__decorateClass([
|
|
1221
|
-
(0, import_plugins_backend_sdk7.PrimaryGeneratedColumn)({ type: "integer" })
|
|
1222
|
-
], NoticeEntity.prototype, "id", 2);
|
|
1223
|
-
__decorateClass([
|
|
1224
|
-
(0, import_plugins_backend_sdk7.Column)({ type: "integer" })
|
|
1225
|
-
], NoticeEntity.prototype, "reservationId", 2);
|
|
1226
|
-
__decorateClass([
|
|
1227
|
-
(0, import_plugins_backend_sdk7.Column)({ type: "varchar" })
|
|
1228
|
-
], NoticeEntity.prototype, "kind", 2);
|
|
1229
|
-
__decorateClass([
|
|
1230
|
-
(0, import_plugins_backend_sdk7.Column)({ type: "varchar", default: "" })
|
|
1231
|
-
], NoticeEntity.prototype, "refKey", 2);
|
|
1232
|
-
__decorateClass([
|
|
1233
|
-
(0, import_plugins_backend_sdk7.Column)({ type: "datetime" })
|
|
1234
|
-
], NoticeEntity.prototype, "sentAt", 2);
|
|
1235
|
-
NoticeEntity = __decorateClass([
|
|
1236
|
-
(0, import_plugins_backend_sdk7.Entity)({ name: "reservations_notice" }),
|
|
1237
|
-
(0, import_plugins_backend_sdk7.Index)("UQ_reservations_notice", ["reservationId", "kind", "refKey"], { unique: true })
|
|
1238
|
-
], NoticeEntity);
|
|
1239
|
-
|
|
1240
|
-
// backend/reservations/reservation.store.ts
|
|
1241
1114
|
var MAX_BUFFER_MINUTES = 1440;
|
|
1115
|
+
var LIVE = ["pending", "confirmed"];
|
|
1242
1116
|
var ReservationStore = class {
|
|
1243
1117
|
constructor(context) {
|
|
1244
1118
|
__publicField(this, "context", context);
|
|
1245
1119
|
}
|
|
1246
|
-
get
|
|
1247
|
-
return this.context
|
|
1120
|
+
get tables() {
|
|
1121
|
+
return tablesOf(this.context);
|
|
1122
|
+
}
|
|
1123
|
+
get reservations() {
|
|
1124
|
+
return this.tables.reservations;
|
|
1248
1125
|
}
|
|
1249
|
-
|
|
1250
|
-
return this.
|
|
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
|
+
);
|
|
1131
|
+
}
|
|
1132
|
+
async findById(id) {
|
|
1133
|
+
return await this.reservations.get(id);
|
|
1251
1134
|
}
|
|
1252
1135
|
/** Confirmed bookings of the resource that end after `from` and start before `to` (hook hot path). */
|
|
1253
1136
|
findConfirmedOverlapping(resourceId, from, to) {
|
|
1254
|
-
return this.
|
|
1137
|
+
return this.find({ resourceId, status: "confirmed", endTime: { gt: from }, startTime: { lt: to } });
|
|
1255
1138
|
}
|
|
1256
1139
|
/** Confirmed bookings running at `now` ([start, end)). */
|
|
1257
1140
|
findActiveForResource(resourceId, now) {
|
|
1258
|
-
return this.
|
|
1141
|
+
return this.find({ resourceId, status: "confirmed", startTime: { lte: now }, endTime: { gt: now } });
|
|
1259
1142
|
}
|
|
1260
1143
|
/** Confirmed bookings starting in (from, to] across all resources (reminders, handover, overrun). */
|
|
1261
1144
|
findUpcomingConfirmed(from, to) {
|
|
1262
|
-
return this.
|
|
1145
|
+
return this.find({ status: "confirmed", startTime: { gt: from, lte: to } });
|
|
1263
1146
|
}
|
|
1264
1147
|
/**
|
|
1265
1148
|
* Confirmed bookings that started and have no check-in yet (no-show step). Ended ones are included on
|
|
1266
1149
|
* purpose: a grace period reaching the end must still end in no_show, not in completed.
|
|
1267
1150
|
*/
|
|
1268
1151
|
findNoShowCandidates(now) {
|
|
1269
|
-
return this.
|
|
1152
|
+
return this.find({ status: "confirmed", startTime: { lte: now }, checkedInAt: null });
|
|
1270
1153
|
}
|
|
1271
1154
|
/** Confirmed bookings whose end has passed (to be marked completed). */
|
|
1272
1155
|
findConfirmedEnded(now) {
|
|
1273
|
-
return this.
|
|
1156
|
+
return this.find({ status: "confirmed", endTime: { lte: now } });
|
|
1274
1157
|
}
|
|
1275
1158
|
/** Pending bookings whose start has passed (to be expired). */
|
|
1276
1159
|
findPendingStarted(now) {
|
|
1277
|
-
return this.
|
|
1160
|
+
return this.find({ status: "pending", startTime: { lte: now } });
|
|
1278
1161
|
}
|
|
1279
1162
|
/** The holder's confirmed, not yet checked-in booking whose check-in window contains `now`. */
|
|
1280
|
-
findCheckInCandidate(userId, resourceId, now, earlyCheckInMinutes) {
|
|
1163
|
+
async findCheckInCandidate(userId, resourceId, now, earlyCheckInMinutes) {
|
|
1281
1164
|
const windowStart = new Date(now.getTime() + earlyCheckInMinutes * 6e4);
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
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;
|
|
1287
1177
|
}
|
|
1288
1178
|
/** The holder's confirmed, not yet checked-in bookings overlapping [from, to) (a session that ran in them). */
|
|
1289
1179
|
findUncheckedOverlapping(userId, resourceId, from, to) {
|
|
1290
|
-
return this.
|
|
1180
|
+
return this.find({
|
|
1291
1181
|
resourceId,
|
|
1292
1182
|
userId,
|
|
1293
|
-
status: "confirmed"
|
|
1294
|
-
|
|
1183
|
+
status: "confirmed",
|
|
1184
|
+
checkedInAt: null,
|
|
1185
|
+
startTime: { lt: to },
|
|
1186
|
+
endTime: { gt: from }
|
|
1187
|
+
});
|
|
1295
1188
|
}
|
|
1296
1189
|
/** Pending + confirmed bookings of the resource overlapping [from, to) (maintenance/health notices). */
|
|
1297
1190
|
findLiveOverlapping(resourceId, from, to) {
|
|
1298
|
-
|
|
1191
|
+
return this.find({
|
|
1299
1192
|
resourceId,
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
}
|
|
1305
|
-
/** Candidates for buffer-aware overlap checks (pending + confirmed), exact filtering is done by the caller. */
|
|
1306
|
-
findOverlapCandidates(manager, resourceId, from, to) {
|
|
1307
|
-
return manager.getRepository(ReservationEntity).createQueryBuilder("r").where("r.resourceId = :resourceId AND r.status IN (:...statuses)", {
|
|
1308
|
-
resourceId,
|
|
1309
|
-
statuses: ["pending", "confirmed"]
|
|
1310
|
-
}).andWhere("r.startTime < :to AND r.endTime > :from", {
|
|
1311
|
-
from: new Date(from.getTime() - MAX_BUFFER_MINUTES * 6e4),
|
|
1312
|
-
to: new Date(to.getTime() + MAX_BUFFER_MINUTES * 6e4)
|
|
1313
|
-
}).getMany();
|
|
1193
|
+
status: { in: LIVE },
|
|
1194
|
+
endTime: { gt: from },
|
|
1195
|
+
...to ? { startTime: { lt: to } } : {}
|
|
1196
|
+
});
|
|
1314
1197
|
}
|
|
1315
|
-
/**
|
|
1316
|
-
|
|
1317
|
-
|
|
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 });
|
|
1318
1216
|
}
|
|
1319
1217
|
/**
|
|
1320
1218
|
* Pending + confirmed bookings of the resource whose buffer-aware span can still matter at or after `now`
|
|
@@ -1323,74 +1221,65 @@ var ReservationStore = class {
|
|
|
1323
1221
|
findOccupyingFrom(resourceId, now) {
|
|
1324
1222
|
return this.findLiveOverlapping(resourceId, new Date(now.getTime() - MAX_BUFFER_MINUTES * 6e4), null);
|
|
1325
1223
|
}
|
|
1326
|
-
countLiveForUser(
|
|
1327
|
-
return
|
|
1328
|
-
userId,
|
|
1329
|
-
resourceId,
|
|
1330
|
-
statuses: ["pending", "confirmed"]
|
|
1331
|
-
}).andWhere("r.endTime > :now", { now }).getCount();
|
|
1224
|
+
countLiveForUser(scope, userId, resourceId, now) {
|
|
1225
|
+
return this.reservations.count({ userId, resourceId, status: { in: LIVE }, endTime: { gt: now } }, { scope });
|
|
1332
1226
|
}
|
|
1333
1227
|
/** Number of pending/confirmed bookings of the resource starting after `now` (a COUNT, no rows loaded). */
|
|
1334
1228
|
countFutureLive(resourceId, now) {
|
|
1335
|
-
return this.
|
|
1336
|
-
resourceId,
|
|
1337
|
-
statuses: ["pending", "confirmed"],
|
|
1338
|
-
now
|
|
1339
|
-
}).getCount();
|
|
1229
|
+
return this.reservations.count({ resourceId, status: { in: LIVE }, startTime: { gt: now } });
|
|
1340
1230
|
}
|
|
1341
1231
|
/**
|
|
1342
1232
|
* Applies `changes` to every pending/confirmed booking of the resource starting after `now`, in one
|
|
1343
|
-
*
|
|
1233
|
+
* transaction (select + one update with the same predicate), and returns the changed rows.
|
|
1344
1234
|
*/
|
|
1345
1235
|
cancelFutureLive(resourceId, now, changes) {
|
|
1346
|
-
const where =
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
const repo = manager.getRepository(ReservationEntity);
|
|
1350
|
-
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 });
|
|
1351
1239
|
if (rows.length === 0) return [];
|
|
1352
|
-
await
|
|
1240
|
+
await this.reservations.update(where, changes, { scope });
|
|
1353
1241
|
return rows.map((row) => Object.assign(row, changes));
|
|
1354
1242
|
});
|
|
1355
1243
|
}
|
|
1356
1244
|
/** Bookings an iCal feed shows (pending, confirmed, ended) in [from, to), optionally only one holder's. */
|
|
1357
1245
|
findForCalendar(resourceIds, from, to, userId) {
|
|
1358
1246
|
if (resourceIds.length === 0) return Promise.resolve([]);
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
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
|
+
);
|
|
1365
1257
|
}
|
|
1366
1258
|
/** Occupying bookings (pending + confirmed) overlapping [from, to) for availability views. */
|
|
1367
1259
|
findOccupying(resourceId, from, to) {
|
|
1368
1260
|
return this.findLiveOverlapping(resourceId, from, to);
|
|
1369
1261
|
}
|
|
1370
1262
|
listForUser(userId, scope, now, status) {
|
|
1371
|
-
const
|
|
1372
|
-
|
|
1373
|
-
query.andWhere("r.status IN (:...live) AND r.endTime > :now", { live: ["pending", "confirmed"], now });
|
|
1374
|
-
query.orderBy("r.startTime", "ASC");
|
|
1375
|
-
} else {
|
|
1376
|
-
query.andWhere("(r.status NOT IN (:...live) OR r.endTime <= :now)", { live: ["pending", "confirmed"], now });
|
|
1377
|
-
query.orderBy("r.startTime", "DESC");
|
|
1378
|
-
}
|
|
1379
|
-
if (status) query.andWhere("r.status = :status", { status });
|
|
1380
|
-
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" });
|
|
1381
1265
|
}
|
|
1382
1266
|
async listManaged(filter) {
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
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
|
+
]);
|
|
1394
1283
|
return { items, total };
|
|
1395
1284
|
}
|
|
1396
1285
|
/**
|
|
@@ -1399,47 +1288,47 @@ var ReservationStore = class {
|
|
|
1399
1288
|
* was saved after the scheduler loaded the row).
|
|
1400
1289
|
*/
|
|
1401
1290
|
async transition(id, from, changes, options = {}) {
|
|
1402
|
-
const
|
|
1403
|
-
|
|
1404
|
-
|
|
1291
|
+
const affected = await this.reservations.update(
|
|
1292
|
+
{ id, status: { in: from }, ...options.notCheckedIn ? { checkedInAt: null } : {} },
|
|
1293
|
+
changes
|
|
1405
1294
|
);
|
|
1406
|
-
return
|
|
1295
|
+
return affected === 1;
|
|
1407
1296
|
}
|
|
1408
1297
|
/**
|
|
1409
|
-
* Claims a one-shot notification flag: `
|
|
1410
|
-
* Only the caller that gets `true` may send. Combine with the send inside the same transaction
|
|
1411
|
-
* 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.
|
|
1412
1301
|
*/
|
|
1413
|
-
async claimFlag(id, flag, at,
|
|
1302
|
+
async claimFlag(id, flag, at, scope) {
|
|
1414
1303
|
if (!REMINDER_FLAGS.includes(flag)) throw new Error(`Unknown reminder flag ${String(flag)}`);
|
|
1415
|
-
const
|
|
1416
|
-
|
|
1417
|
-
|
|
1304
|
+
const affected = await this.reservations.update(
|
|
1305
|
+
{ id, [flag]: null },
|
|
1306
|
+
{ [flag]: at },
|
|
1307
|
+
{ scope }
|
|
1308
|
+
);
|
|
1309
|
+
return affected === 1;
|
|
1418
1310
|
}
|
|
1419
1311
|
/**
|
|
1420
1312
|
* Exactly-once notice claim for (reservation, kind, refKey): true when this call inserted the row,
|
|
1421
1313
|
* false when it already existed.
|
|
1422
1314
|
*/
|
|
1423
|
-
async claimNotice(reservationId, kind, refKey, at,
|
|
1424
|
-
const insert = (m) => m.getRepository(NoticeEntity).insert({ reservationId, kind, refKey, sentAt: at });
|
|
1315
|
+
async claimNotice(reservationId, kind, refKey, at, scope) {
|
|
1425
1316
|
try {
|
|
1426
|
-
await (
|
|
1317
|
+
await this.tables.notices.insert({ reservationId, kind, refKey, sentAt: at }, { scope });
|
|
1427
1318
|
return true;
|
|
1428
1319
|
} catch (error) {
|
|
1429
|
-
if (
|
|
1320
|
+
if (error instanceof import_plugins_backend_sdk8.PluginStorageUniqueViolation) return false;
|
|
1430
1321
|
throw error;
|
|
1431
1322
|
}
|
|
1432
1323
|
}
|
|
1433
1324
|
/** Notices of the given kind already claimed for these reservations. */
|
|
1434
1325
|
async findNotices(reservationIds, kind) {
|
|
1435
1326
|
if (reservationIds.length === 0) return [];
|
|
1436
|
-
return this.
|
|
1327
|
+
return this.tables.notices.find({ where: { kind, reservationId: { in: reservationIds } } });
|
|
1437
1328
|
}
|
|
1438
1329
|
/** Release a notice claim (when the send failed and should be retried next tick). */
|
|
1439
1330
|
async releaseNotice(reservationId, kind, refKey) {
|
|
1440
|
-
await this.
|
|
1441
|
-
(manager) => manager.getRepository(NoticeEntity).createQueryBuilder().delete().where("reservationId = :reservationId AND kind = :kind AND refKey = :refKey", { reservationId, kind, refKey }).execute()
|
|
1442
|
-
);
|
|
1331
|
+
await this.tables.notices.delete({ reservationId, kind, refKey });
|
|
1443
1332
|
}
|
|
1444
1333
|
};
|
|
1445
1334
|
ReservationStore = __decorateClass([
|
|
@@ -1547,8 +1436,7 @@ var ReservationService = class {
|
|
|
1547
1436
|
}
|
|
1548
1437
|
// ---------------------------------------------------------------- create
|
|
1549
1438
|
/**
|
|
1550
|
-
* Creates a booking. Creation is serialised per resource (in-process mutex + host
|
|
1551
|
-
* 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
|
|
1552
1440
|
* `ReservationError` (409 with `{ code, message }`) for every violated rule.
|
|
1553
1441
|
*/
|
|
1554
1442
|
async create(actor, input) {
|
|
@@ -1582,9 +1470,9 @@ var ReservationService = class {
|
|
|
1582
1470
|
if (maintenance.length > 0) {
|
|
1583
1471
|
throw new ReservationError("MAINTENANCE", "The resource is in maintenance during this time");
|
|
1584
1472
|
}
|
|
1585
|
-
return this.context.
|
|
1473
|
+
return this.context.persistence.transaction(async (scope) => {
|
|
1586
1474
|
if (settings.maxActiveBookingsPerUser > 0) {
|
|
1587
|
-
const live = await this.store.countLiveForUser(
|
|
1475
|
+
const live = await this.store.countLiveForUser(scope, actor.userId, input.resourceId, now);
|
|
1588
1476
|
if (live >= settings.maxActiveBookingsPerUser) {
|
|
1589
1477
|
throw new ReservationError(
|
|
1590
1478
|
"USER_BOOKING_LIMIT",
|
|
@@ -1592,9 +1480,9 @@ var ReservationService = class {
|
|
|
1592
1480
|
);
|
|
1593
1481
|
}
|
|
1594
1482
|
}
|
|
1595
|
-
const candidates = await this.store.findOverlapCandidates(
|
|
1483
|
+
const candidates = await this.store.findOverlapCandidates(scope, input.resourceId, span.start, span.end);
|
|
1596
1484
|
const overlapping = candidates.filter((other) => spansOverlap(span, blockedSpan(other)));
|
|
1597
|
-
const limit = await this.directory.getSessionLimit(input.resourceId,
|
|
1485
|
+
const limit = await this.directory.getSessionLimit(input.resourceId, scope);
|
|
1598
1486
|
if (limit <= 1) {
|
|
1599
1487
|
if (overlapping.length > 0) throw new ReservationError("OVERLAP", "The time is already reserved");
|
|
1600
1488
|
} else {
|
|
@@ -1605,19 +1493,20 @@ var ReservationService = class {
|
|
|
1605
1493
|
throw new ReservationError("OVERLAP", "All slots are booked at that time");
|
|
1606
1494
|
}
|
|
1607
1495
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
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
|
+
);
|
|
1621
1510
|
});
|
|
1622
1511
|
});
|
|
1623
1512
|
await this.audit.record(
|
|
@@ -1890,10 +1779,11 @@ var ReservationService = class {
|
|
|
1890
1779
|
}
|
|
1891
1780
|
/** Holder started a session inside the check-in window. True when this call recorded the check-in. */
|
|
1892
1781
|
async markCheckedIn(id, usageId, at) {
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1782
|
+
const affected = await tablesOf(this.context).reservations.update(
|
|
1783
|
+
{ id, status: "confirmed", checkedInAt: null },
|
|
1784
|
+
{ checkedInAt: at, checkedInUsageId: usageId }
|
|
1895
1785
|
);
|
|
1896
|
-
const checkedIn =
|
|
1786
|
+
const checkedIn = affected === 1;
|
|
1897
1787
|
if (checkedIn) {
|
|
1898
1788
|
const booking = await this.store.findById(id);
|
|
1899
1789
|
if (booking) this.invalidateViews(booking.resourceId);
|
|
@@ -2774,7 +2664,7 @@ __decorateClass([
|
|
|
2774
2664
|
], ReservationSettingsController.prototype, "getGlobal", 1);
|
|
2775
2665
|
__decorateClass([
|
|
2776
2666
|
(0, import_common12.Put)("settings/global"),
|
|
2777
|
-
(0,
|
|
2667
|
+
(0, import_plugins_backend_sdk9.Auth)("system.settings.manage"),
|
|
2778
2668
|
(0, import_swagger4.ApiOperation)({ summary: "Update plugin-wide settings (requires system.settings.manage)" }),
|
|
2779
2669
|
(0, import_swagger4.ApiBody)({ type: UpdateGlobalSettingsBody }),
|
|
2780
2670
|
(0, import_swagger4.ApiOkResponse)({ type: GlobalSettingsDto }),
|
|
@@ -2784,7 +2674,7 @@ __decorateClass([
|
|
|
2784
2674
|
], ReservationSettingsController.prototype, "updateGlobal", 1);
|
|
2785
2675
|
ReservationSettingsController = __decorateClass([
|
|
2786
2676
|
(0, import_swagger4.ApiTags)("Reservations"),
|
|
2787
|
-
(0,
|
|
2677
|
+
(0, import_plugins_backend_sdk9.Auth)(),
|
|
2788
2678
|
(0, import_common12.Controller)("reservations"),
|
|
2789
2679
|
__decorateParam(0, (0, import_common12.Inject)(SettingsAdminService)),
|
|
2790
2680
|
__decorateParam(1, (0, import_common12.Inject)(AccessService)),
|
|
@@ -2844,7 +2734,6 @@ PendingDecisionStore = __decorateClass([
|
|
|
2844
2734
|
], PendingDecisionStore);
|
|
2845
2735
|
|
|
2846
2736
|
// backend/notifications/host-info.service.ts
|
|
2847
|
-
var import_plugins_backend_sdk9 = require("@attraccess/plugins-backend-sdk");
|
|
2848
2737
|
var import_common14 = require("@nestjs/common");
|
|
2849
2738
|
var MANAGER_PERMISSIONS = ["resources.update"];
|
|
2850
2739
|
function normalizeLanguage(locale, fallback) {
|
|
@@ -2858,9 +2747,7 @@ var HostInfoService = class {
|
|
|
2858
2747
|
__publicField(this, "context", context);
|
|
2859
2748
|
}
|
|
2860
2749
|
async setting(key) {
|
|
2861
|
-
|
|
2862
|
-
const value = row?.value?.trim();
|
|
2863
|
-
return value ? value : null;
|
|
2750
|
+
return this.context.hostData.settings.getApp(key);
|
|
2864
2751
|
}
|
|
2865
2752
|
/**
|
|
2866
2753
|
* The application's public URL, the same setting core uses for links in emails (`app/backend_url`),
|
|
@@ -2880,17 +2767,17 @@ var HostInfoService = class {
|
|
|
2880
2767
|
const ids = [...new Set(userIds)];
|
|
2881
2768
|
const result = /* @__PURE__ */ new Map();
|
|
2882
2769
|
if (ids.length === 0) return result;
|
|
2883
|
-
const [fallback,
|
|
2770
|
+
const [fallback, locales] = await Promise.all([
|
|
2884
2771
|
this.getDefaultLanguage(),
|
|
2885
|
-
this.context.
|
|
2772
|
+
this.context.hostData.users.getLocales(ids)
|
|
2886
2773
|
]);
|
|
2887
|
-
for (const
|
|
2774
|
+
for (const [id, locale] of locales) result.set(id, normalizeLanguage(locale, fallback));
|
|
2888
2775
|
for (const id of ids) if (!result.has(id)) result.set(id, fallback);
|
|
2889
2776
|
return result;
|
|
2890
2777
|
}
|
|
2891
2778
|
/** Health entries of the resource that are currently unhealthy (a resource may carry several). */
|
|
2892
2779
|
countUnhealthyEntries(resourceId) {
|
|
2893
|
-
return this.context.
|
|
2780
|
+
return this.context.hostData.resources.countUnhealthyEntries(resourceId);
|
|
2894
2781
|
}
|
|
2895
2782
|
/**
|
|
2896
2783
|
* Users managing the resource: everyone holding `resources.update` (role join, one query; the global
|
|
@@ -2901,10 +2788,10 @@ var HostInfoService = class {
|
|
|
2901
2788
|
*/
|
|
2902
2789
|
async managerIdsOf(resourceId) {
|
|
2903
2790
|
const [introducers, permitted] = await Promise.all([
|
|
2904
|
-
this.context.
|
|
2905
|
-
this.context.
|
|
2791
|
+
this.context.hostData.resources.listIntroducerUserIds(resourceId),
|
|
2792
|
+
this.context.hostData.users.listIdsWithAnyPermission(MANAGER_PERMISSIONS)
|
|
2906
2793
|
]);
|
|
2907
|
-
return [
|
|
2794
|
+
return [.../* @__PURE__ */ new Set([...introducers, ...permitted])];
|
|
2908
2795
|
}
|
|
2909
2796
|
};
|
|
2910
2797
|
HostInfoService = __decorateClass([
|
|
@@ -4054,8 +3941,7 @@ var ReservationQueryService = class {
|
|
|
4054
3941
|
async canBook(actor, resourceId, settings, isManager) {
|
|
4055
3942
|
const result = await this.access.canBook(actor, resourceId, settings, isManager);
|
|
4056
3943
|
if (!result.allowed || settings.maxActiveBookingsPerUser === 0) return result;
|
|
4057
|
-
const
|
|
4058
|
-
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());
|
|
4059
3945
|
return live >= settings.maxActiveBookingsPerUser ? { allowed: false, reason: "USER_BOOKING_LIMIT" } : result;
|
|
4060
3946
|
}
|
|
4061
3947
|
};
|
|
@@ -4768,7 +4654,8 @@ ReaderUiService = __decorateClass([
|
|
|
4768
4654
|
// backend/hooks/start-capacity.service.ts
|
|
4769
4655
|
var import_common21 = require("@nestjs/common");
|
|
4770
4656
|
var StartCapacityService = class {
|
|
4771
|
-
constructor(settings, store, preStart) {
|
|
4657
|
+
constructor(context, settings, store, preStart) {
|
|
4658
|
+
__publicField(this, "context", context);
|
|
4772
4659
|
__publicField(this, "settings", settings);
|
|
4773
4660
|
__publicField(this, "store", store);
|
|
4774
4661
|
__publicField(this, "preStart", preStart);
|
|
@@ -4778,7 +4665,7 @@ var StartCapacityService = class {
|
|
|
4778
4665
|
await waitUntil(this.settings.whenReady(), deadline, "Reservation settings are not loaded yet");
|
|
4779
4666
|
}
|
|
4780
4667
|
if (!this.settings.getCachedSettings(ctx.resourceId).enabled) return { heldSlots: 0 };
|
|
4781
|
-
const running = await this.store.findRunningConfirmed(ctx.
|
|
4668
|
+
const running = await this.store.findRunningConfirmed(ctx.scope, ctx.resourceId, ctx.now);
|
|
4782
4669
|
if (running.length === 0 || running.some((r) => r.userId === ctx.userId)) return { heldSlots: 0 };
|
|
4783
4670
|
const held = heldBookings({
|
|
4784
4671
|
confirmed: running,
|
|
@@ -4797,9 +4684,10 @@ var StartCapacityService = class {
|
|
|
4797
4684
|
};
|
|
4798
4685
|
StartCapacityService = __decorateClass([
|
|
4799
4686
|
(0, import_common21.Injectable)(),
|
|
4800
|
-
__decorateParam(0, (0, import_common21.Inject)(
|
|
4801
|
-
__decorateParam(1, (0, import_common21.Inject)(
|
|
4802
|
-
__decorateParam(2, (0, import_common21.Inject)(
|
|
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))
|
|
4803
4691
|
], StartCapacityService);
|
|
4804
4692
|
|
|
4805
4693
|
// backend/hooks/session-end.service.ts
|
|
@@ -4902,7 +4790,7 @@ HookServicePublisher = __decorateClass([
|
|
|
4902
4790
|
], HookServicePublisher);
|
|
4903
4791
|
|
|
4904
4792
|
// backend/ical/ical.controller.ts
|
|
4905
|
-
var
|
|
4793
|
+
var import_plugins_backend_sdk13 = require("@attraccess/plugins-backend-sdk");
|
|
4906
4794
|
var import_common25 = require("@nestjs/common");
|
|
4907
4795
|
var import_swagger6 = require("@nestjs/swagger");
|
|
4908
4796
|
|
|
@@ -5037,53 +4925,6 @@ __decorateClass([
|
|
|
5037
4925
|
var import_common24 = require("@nestjs/common");
|
|
5038
4926
|
var import_node_crypto2 = require("node:crypto");
|
|
5039
4927
|
|
|
5040
|
-
// backend/entities/ical-feed.entity.ts
|
|
5041
|
-
var import_plugins_backend_sdk13 = require("@attraccess/plugins-backend-sdk");
|
|
5042
|
-
var IcalFeedEntity = class {
|
|
5043
|
-
constructor() {
|
|
5044
|
-
__publicField(this, "id");
|
|
5045
|
-
__publicField(this, "userId");
|
|
5046
|
-
__publicField(this, "name");
|
|
5047
|
-
__publicField(this, "tokenHash");
|
|
5048
|
-
__publicField(this, "tokenPrefix");
|
|
5049
|
-
__publicField(this, "selection");
|
|
5050
|
-
__publicField(this, "createdAt");
|
|
5051
|
-
__publicField(this, "revokedAt");
|
|
5052
|
-
__publicField(this, "lastUsedAt");
|
|
5053
|
-
}
|
|
5054
|
-
};
|
|
5055
|
-
__decorateClass([
|
|
5056
|
-
(0, import_plugins_backend_sdk13.PrimaryGeneratedColumn)({ type: "integer" })
|
|
5057
|
-
], IcalFeedEntity.prototype, "id", 2);
|
|
5058
|
-
__decorateClass([
|
|
5059
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "integer" })
|
|
5060
|
-
], IcalFeedEntity.prototype, "userId", 2);
|
|
5061
|
-
__decorateClass([
|
|
5062
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "varchar" })
|
|
5063
|
-
], IcalFeedEntity.prototype, "name", 2);
|
|
5064
|
-
__decorateClass([
|
|
5065
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "varchar", unique: true })
|
|
5066
|
-
], IcalFeedEntity.prototype, "tokenHash", 2);
|
|
5067
|
-
__decorateClass([
|
|
5068
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "varchar", nullable: true })
|
|
5069
|
-
], IcalFeedEntity.prototype, "tokenPrefix", 2);
|
|
5070
|
-
__decorateClass([
|
|
5071
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "text" })
|
|
5072
|
-
], IcalFeedEntity.prototype, "selection", 2);
|
|
5073
|
-
__decorateClass([
|
|
5074
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "datetime" })
|
|
5075
|
-
], IcalFeedEntity.prototype, "createdAt", 2);
|
|
5076
|
-
__decorateClass([
|
|
5077
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "datetime", nullable: true })
|
|
5078
|
-
], IcalFeedEntity.prototype, "revokedAt", 2);
|
|
5079
|
-
__decorateClass([
|
|
5080
|
-
(0, import_plugins_backend_sdk13.Column)({ type: "datetime", nullable: true })
|
|
5081
|
-
], IcalFeedEntity.prototype, "lastUsedAt", 2);
|
|
5082
|
-
IcalFeedEntity = __decorateClass([
|
|
5083
|
-
(0, import_plugins_backend_sdk13.Entity)({ name: "reservations_ical_feed" }),
|
|
5084
|
-
(0, import_plugins_backend_sdk13.Index)("IDX_reservations_ical_feed_user", ["userId"])
|
|
5085
|
-
], IcalFeedEntity);
|
|
5086
|
-
|
|
5087
4928
|
// backend/ical/ical-format.ts
|
|
5088
4929
|
var CRLF = "\r\n";
|
|
5089
4930
|
var MAX_OCTETS = 75;
|
|
@@ -5192,12 +5033,13 @@ var IcalService = class {
|
|
|
5192
5033
|
__publicField(this, "audit");
|
|
5193
5034
|
this.audit = new ReservationAudit(context.audit);
|
|
5194
5035
|
}
|
|
5195
|
-
get
|
|
5196
|
-
return this.context.
|
|
5036
|
+
get feeds() {
|
|
5037
|
+
return tablesOf(this.context).icalFeeds;
|
|
5197
5038
|
}
|
|
5198
|
-
/**
|
|
5199
|
-
|
|
5200
|
-
|
|
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 };
|
|
5201
5043
|
}
|
|
5202
5044
|
toDto(feed) {
|
|
5203
5045
|
return {
|
|
@@ -5214,55 +5056,58 @@ var IcalService = class {
|
|
|
5214
5056
|
return { feed: this.toDto(feed), url: `${base}/api/reservations/ical/${token}.ics`, token };
|
|
5215
5057
|
}
|
|
5216
5058
|
async load(userId, id) {
|
|
5217
|
-
const feed = await this.
|
|
5059
|
+
const feed = await this.feeds.findOne({ where: { id, userId } });
|
|
5218
5060
|
if (!feed || feed.revokedAt) throw new ReservationError("FEED_NOT_FOUND", "Feed not found");
|
|
5219
5061
|
return feed;
|
|
5220
5062
|
}
|
|
5221
5063
|
async list(userId) {
|
|
5222
|
-
const feeds = await this.
|
|
5064
|
+
const feeds = await this.feeds.find({
|
|
5065
|
+
where: { userId, revokedAt: null },
|
|
5066
|
+
orderBy: [{ field: "createdAt", direction: "asc" }]
|
|
5067
|
+
});
|
|
5223
5068
|
return feeds.map((feed) => this.toDto(feed));
|
|
5224
5069
|
}
|
|
5225
5070
|
async create(actor, input) {
|
|
5226
5071
|
const selection = assertSelection(input.selection);
|
|
5227
|
-
const count = await this.
|
|
5072
|
+
const count = await this.feeds.count({ userId: actor.userId, revokedAt: null });
|
|
5228
5073
|
if (count >= MAX_FEEDS_PER_USER) {
|
|
5229
5074
|
throw new ReservationError("FEED_LIMIT", `You can have at most ${MAX_FEEDS_PER_USER} calendar feeds`);
|
|
5230
5075
|
}
|
|
5231
5076
|
const token = (0, import_node_crypto2.randomBytes)(32).toString("base64url");
|
|
5232
|
-
const feed = await this.
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
})
|
|
5243
|
-
);
|
|
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
|
+
});
|
|
5244
5087
|
await this.audit.record("feed_created", actor, { type: "feed", id: feed.id }, { feedName: feed.name });
|
|
5245
5088
|
return this.secretResult(feed, token);
|
|
5246
5089
|
}
|
|
5247
5090
|
async update(actor, id, input) {
|
|
5248
5091
|
const feed = await this.load(actor.userId, id);
|
|
5249
|
-
|
|
5250
|
-
if (input.
|
|
5251
|
-
|
|
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));
|
|
5252
5096
|
}
|
|
5253
5097
|
/** New token; the old one stops working immediately (its hash is overwritten). */
|
|
5254
5098
|
async regenerate(actor, id) {
|
|
5255
5099
|
const feed = await this.load(actor.userId, id);
|
|
5256
5100
|
const token = (0, import_node_crypto2.randomBytes)(32).toString("base64url");
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
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);
|
|
5261
5107
|
}
|
|
5262
5108
|
async revoke(actor, id) {
|
|
5263
5109
|
const feed = await this.load(actor.userId, id);
|
|
5264
|
-
feed
|
|
5265
|
-
await this.save(feed);
|
|
5110
|
+
await this.patch(feed, { revokedAt: this.clock() });
|
|
5266
5111
|
await this.audit.record("feed_revoked", actor, { type: "feed", id: feed.id }, { feedName: feed.name });
|
|
5267
5112
|
}
|
|
5268
5113
|
// ------------------------------------------------------------- rendering
|
|
@@ -5272,12 +5117,12 @@ var IcalService = class {
|
|
|
5272
5117
|
*/
|
|
5273
5118
|
async renderForToken(token) {
|
|
5274
5119
|
if (!FEED_TOKEN_PATTERN.test(token)) return null;
|
|
5275
|
-
const feed = await this.
|
|
5120
|
+
const feed = await this.feeds.findOne({ where: { tokenHash: hashToken(token) } });
|
|
5276
5121
|
if (!feed || feed.revokedAt) return null;
|
|
5277
5122
|
if (!await this.visibility.isActiveAccount(feed.userId)) return null;
|
|
5278
5123
|
const now = this.clock();
|
|
5279
5124
|
if (!feed.lastUsedAt || now.getTime() - feed.lastUsedAt.getTime() > 6e4) {
|
|
5280
|
-
await this.
|
|
5125
|
+
await this.feeds.update({ id: feed.id }, { lastUsedAt: now }).catch(() => void 0);
|
|
5281
5126
|
}
|
|
5282
5127
|
return this.render(feed, now);
|
|
5283
5128
|
}
|
|
@@ -5468,7 +5313,7 @@ __decorateClass([
|
|
|
5468
5313
|
], IcalFeedsController.prototype, "list", 1);
|
|
5469
5314
|
__decorateClass([
|
|
5470
5315
|
(0, import_common25.Post)(),
|
|
5471
|
-
(0, import_common25.UseGuards)(
|
|
5316
|
+
(0, import_common25.UseGuards)(import_plugins_backend_sdk13.SessionOnlyGuard),
|
|
5472
5317
|
(0, import_swagger6.ApiForbiddenResponse)({ description: "Session authentication required (API tokens cannot issue feed URLs)" }),
|
|
5473
5318
|
(0, import_swagger6.ApiOperation)({
|
|
5474
5319
|
summary: "Create a calendar feed",
|
|
@@ -5494,7 +5339,7 @@ __decorateClass([
|
|
|
5494
5339
|
__decorateClass([
|
|
5495
5340
|
(0, import_common25.Post)(":id/regenerate"),
|
|
5496
5341
|
(0, import_common25.HttpCode)(200),
|
|
5497
|
-
(0, import_common25.UseGuards)(
|
|
5342
|
+
(0, import_common25.UseGuards)(import_plugins_backend_sdk13.SessionOnlyGuard),
|
|
5498
5343
|
(0, import_swagger6.ApiForbiddenResponse)({ description: "Session authentication required (API tokens cannot issue feed URLs)" }),
|
|
5499
5344
|
(0, import_swagger6.ApiOperation)({
|
|
5500
5345
|
summary: "Issue a new secret URL; the old one answers 404 immediately",
|
|
@@ -5517,7 +5362,7 @@ __decorateClass([
|
|
|
5517
5362
|
], IcalFeedsController.prototype, "revoke", 1);
|
|
5518
5363
|
IcalFeedsController = __decorateClass([
|
|
5519
5364
|
(0, import_swagger6.ApiTags)("Reservations"),
|
|
5520
|
-
(0,
|
|
5365
|
+
(0, import_plugins_backend_sdk13.Auth)(),
|
|
5521
5366
|
(0, import_common25.Controller)("reservations/ical/feeds"),
|
|
5522
5367
|
__decorateParam(0, (0, import_common25.Inject)(IcalService))
|
|
5523
5368
|
], IcalFeedsController);
|
|
@@ -6050,9 +5895,9 @@ var ReservationScheduler = class {
|
|
|
6050
5895
|
["handover", (at) => this.handover(at)],
|
|
6051
5896
|
["overrun", (at) => this.overrun(at)]
|
|
6052
5897
|
];
|
|
6053
|
-
for (const [name,
|
|
5898
|
+
for (const [name, step2] of steps) {
|
|
6054
5899
|
try {
|
|
6055
|
-
await
|
|
5900
|
+
await step2(now);
|
|
6056
5901
|
} catch (error) {
|
|
6057
5902
|
this.logger.error(`scheduler step "${name}" failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6058
5903
|
}
|
|
@@ -6255,7 +6100,7 @@ ReservationScheduler = __decorateClass([
|
|
|
6255
6100
|
], ReservationScheduler);
|
|
6256
6101
|
|
|
6257
6102
|
// backend/api/reservations.controller.ts
|
|
6258
|
-
var
|
|
6103
|
+
var import_plugins_backend_sdk14 = require("@attraccess/plugins-backend-sdk");
|
|
6259
6104
|
var import_common27 = require("@nestjs/common");
|
|
6260
6105
|
var import_swagger7 = require("@nestjs/swagger");
|
|
6261
6106
|
var RESERVATION_ID = { name: "id", type: Number, description: "Reservation id" };
|
|
@@ -6491,7 +6336,7 @@ __decorateClass([
|
|
|
6491
6336
|
], ReservationsController.prototype, "reject", 1);
|
|
6492
6337
|
ReservationsController = __decorateClass([
|
|
6493
6338
|
(0, import_swagger7.ApiTags)("Reservations"),
|
|
6494
|
-
(0,
|
|
6339
|
+
(0, import_plugins_backend_sdk14.Auth)(),
|
|
6495
6340
|
(0, import_common27.Controller)("reservations"),
|
|
6496
6341
|
__decorateParam(0, (0, import_common27.Inject)(ReservationService)),
|
|
6497
6342
|
__decorateParam(1, (0, import_common27.Inject)(ReservationQueryService)),
|
|
@@ -6502,7 +6347,7 @@ ReservationsController = __decorateClass([
|
|
|
6502
6347
|
var ReservationsPluginModule = class {
|
|
6503
6348
|
};
|
|
6504
6349
|
var plugin = {
|
|
6505
|
-
|
|
6350
|
+
storage: reservationsStorage,
|
|
6506
6351
|
auditDomains: [RESERVATIONS_AUDIT_DOMAIN],
|
|
6507
6352
|
notificationCategories: [...NOTIFICATION_CATEGORIES],
|
|
6508
6353
|
emailTemplates: EMAIL_TEMPLATES,
|