Add cancelled field to event slots

Make it possible to represent one slot out of a multi-slot event being
cancelled by adding a field for it in the slot, in addition to the
existing field on the event itself.
This commit is contained in:
Hornwitser 2025-09-06 15:54:58 +02:00
parent d006be251c
commit 9a46ea5af0
4 changed files with 15 additions and 2 deletions

View file

@ -28,8 +28,8 @@ function fixtureClientSchedule(multiSlot = false) {
),
];
const eventSlots = idMap([
new ClientScheduleEventSlot(1, false, false, 1, now, now.plus({ hours: 1 }), new Set([left.id]), new Set(), 0),
new ClientScheduleEventSlot(2, false, false, multiSlot ? 1 : 2, now, now.plus({ hours: 2 }), new Set([right.id]), new Set(), 0),
new ClientScheduleEventSlot(1, false, false, 1, now, now.plus({ hours: 1 }), new Set([left.id]), false, new Set(), 0),
new ClientScheduleEventSlot(2, false, false, multiSlot ? 1 : 2, now, now.plus({ hours: 2 }), new Set([right.id]), false, new Set(), 0),
]);
const red = new ClientScheduleRole(1, now, false, "Red", "Is a color.");
@ -277,6 +277,7 @@ describe("class ClientSchedule", () => {
now,
now.plus({ hours: 3 }),
new Set(),
false,
new Set(),
0,
);

View file

@ -295,6 +295,7 @@ export class ClientScheduleEventSlot {
serverStart: DateTime;
serverEnd: DateTime;
serverLocationIds: Set<Id>;
serverCancelled: boolean;
serverAssigned: Set<Id>;
serverInterested: number;
@ -306,6 +307,7 @@ export class ClientScheduleEventSlot {
public start: DateTime,
public end: DateTime,
public locationIds: Set<Id>,
public cancelled: boolean,
public assigned: Set<Id>,
public interested: number,
) {
@ -314,6 +316,7 @@ export class ClientScheduleEventSlot {
this.serverStart = start;
this.serverEnd = end;
this.serverLocationIds = new Set(locationIds);
this.serverCancelled = cancelled;
this.serverAssigned = new Set(assigned);
this.serverInterested = interested;
}
@ -327,6 +330,7 @@ export class ClientScheduleEventSlot {
|| this.start.toMillis() !== this.serverStart.toMillis()
|| this.end.toMillis() !== this.serverEnd.toMillis()
|| !setEquals(this.locationIds, this.serverLocationIds)
|| this.cancelled !== this.serverCancelled
|| !setEquals(this.assigned, this.serverAssigned)
|| this.interested !== this.serverInterested
);
@ -349,6 +353,7 @@ export class ClientScheduleEventSlot {
this.start = this.serverStart;
this.end = this.serverEnd;
this.locationIds = new Set(this.serverLocationIds);
this.cancelled = this.serverCancelled;
this.assigned = new Set(this.serverAssigned);
this.interested = this.serverInterested;
}
@ -360,6 +365,7 @@ export class ClientScheduleEventSlot {
start: DateTime,
end: DateTime,
locationIds: Set<Id>,
cancelled: boolean,
assigned: Set<Id>,
interested: number,
) {
@ -371,6 +377,7 @@ export class ClientScheduleEventSlot {
start,
end,
locationIds,
cancelled,
assigned,
interested,
);
@ -391,6 +398,7 @@ export class ClientScheduleEventSlot {
DateTime.fromISO(api.start, opts),
DateTime.fromISO(api.end, opts),
new Set(api.locationIds),
api.cancelled ?? false,
new Set(api.assigned),
api.interested ?? 0,
);
@ -408,6 +416,7 @@ export class ClientScheduleEventSlot {
this.serverStart = DateTime.fromISO(api.start, opts);
this.serverEnd = DateTime.fromISO(api.end, opts);
this.serverLocationIds = new Set(api.locationIds);
this.serverCancelled = api.cancelled ?? false;
this.serverAssigned = new Set(api.assigned);
this.serverInterested = api.interested ?? 0;
if (!wasModified || !this.isModified()) {
@ -424,6 +433,7 @@ export class ClientScheduleEventSlot {
start: toIso(this.start),
end: toIso(this.end),
locationIds: [...this.locationIds],
cancelled: this.cancelled || undefined,
assigned: this.assigned.size ? [...this.assigned] : undefined,
interested: this.interested || undefined,
}