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

@ -318,6 +318,7 @@ function newEventSlot(options: { start?: DateTime, end?: DateTime } = {}) {
start, start,
end, end,
new Set(newEventLocationIds.value), new Set(newEventLocationIds.value),
false,
new Set(), new Set(),
0, 0,
); );

View file

@ -81,6 +81,7 @@ export const apiScheduleEventSlotSchema = z.object({
start: z.string(), start: z.string(),
end: z.string(), end: z.string(),
locationIds: z.array(idSchema), locationIds: z.array(idSchema),
cancelled: z.optional(z.boolean()),
assigned: z.optional(z.array(z.number())), assigned: z.optional(z.array(z.number())),
interested: z.optional(z.number()), interested: z.optional(z.number()),
}); });

View file

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

View file

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