Create a new mutable ClientEntity type and implement ClientUser on top of it. The mutable concept is intended to replace the immutable concept used by the ClientSchedule entities as updating immutable types in a deep interconnected structure is a lot of hassle for little benefit.
127 lines
3.5 KiB
TypeScript
127 lines
3.5 KiB
TypeScript
import { z } from "zod/v4-mini";
|
|
import { defineEntity, idSchema, type Id } from "~/shared/types/common";
|
|
|
|
export const apiUserTypeSchema = z.union([
|
|
z.literal("anonymous"),
|
|
z.literal("regular"),
|
|
z.literal("crew"),
|
|
z.literal("admin"),
|
|
])
|
|
export type ApiUserType = z.infer<typeof apiUserTypeSchema>;
|
|
|
|
export interface ApiAccount {
|
|
id: Id,
|
|
type: ApiUserType,
|
|
/** Name of the account. Not present on anonymous accounts */
|
|
name?: string,
|
|
interestedEventIds?: number[],
|
|
interestedEventSlotIds?: number[],
|
|
timezone?: string,
|
|
locale?: string,
|
|
}
|
|
|
|
export const apiAccountPatchSchema = z.object({
|
|
name: z.optional(z.string()),
|
|
interestedEventIds: z.optional(z.array(z.number())),
|
|
interestedEventSlotIds: z.optional(z.array(z.number())),
|
|
timezone: z.optional(z.string()),
|
|
locale: z.optional(z.string()),
|
|
});
|
|
export type ApiAccountPatch = z.infer<typeof apiAccountPatchSchema>;
|
|
|
|
export const apiSubscriptionSchema = z.object({
|
|
type: z.literal("push"),
|
|
sessionId: z.number(),
|
|
push: z.object({
|
|
endpoint: z.optional(z.string()),
|
|
expirationTime: z.nullish(z.number()),
|
|
keys: z.record(z.string(), z.string()),
|
|
}),
|
|
});
|
|
export type ApiSubscription = z.infer<typeof apiSubscriptionSchema>;
|
|
|
|
export interface ApiSession {
|
|
id: Id,
|
|
account?: ApiAccount,
|
|
push: boolean,
|
|
}
|
|
|
|
export const apiScheduleLocationSchema = defineEntity({
|
|
name: z.string(),
|
|
description: z.optional(z.string()),
|
|
});
|
|
export type ApiScheduleLocation = z.infer<typeof apiScheduleLocationSchema>;
|
|
|
|
export const apiScheduleEventSlotSchema = z.object({
|
|
id: idSchema,
|
|
start: z.string(),
|
|
end: z.string(),
|
|
locationIds: z.array(idSchema),
|
|
assigned: z.optional(z.array(z.number())),
|
|
interested: z.optional(z.number()),
|
|
});
|
|
export type ApiScheduleEventSlot = z.infer<typeof apiScheduleEventSlotSchema>;
|
|
|
|
export const apiScheduleEventSchema = defineEntity({
|
|
name: z.string(),
|
|
crew: z.optional(z.boolean()),
|
|
host: z.optional(z.string()),
|
|
cancelled: z.optional(z.boolean()),
|
|
description: z.optional(z.string()),
|
|
interested: z.optional(z.number()),
|
|
slots: z.array(apiScheduleEventSlotSchema),
|
|
});
|
|
export type ApiScheduleEvent = z.infer<typeof apiScheduleEventSchema>;
|
|
|
|
export const apiScheduleRoleSchema = defineEntity({
|
|
name: z.string(),
|
|
description: z.optional(z.string()),
|
|
});
|
|
export type ApiScheduleRole = z.infer<typeof apiScheduleRoleSchema>;
|
|
|
|
export const apiScheduleShiftSlotSchema = z.object({
|
|
id: idSchema,
|
|
start: z.string(),
|
|
end: z.string(),
|
|
assigned: z.optional(z.array(z.number())),
|
|
});
|
|
export type ApiScheduleShiftSlot = z.infer<typeof apiScheduleShiftSlotSchema>;
|
|
|
|
export const apiScheduleShiftSchema = defineEntity({
|
|
roleId: idSchema,
|
|
name: z.string(),
|
|
description: z.optional(z.string()),
|
|
slots: z.array(apiScheduleShiftSlotSchema),
|
|
});
|
|
export type ApiScheduleShift = z.infer<typeof apiScheduleShiftSchema>;
|
|
|
|
export const apiScheduleSchema = defineEntity({
|
|
id: z.literal(111),
|
|
locations: z.optional(z.array(apiScheduleLocationSchema)),
|
|
events: z.optional(z.array(apiScheduleEventSchema)),
|
|
roles: z.optional(z.array(apiScheduleRoleSchema)),
|
|
shifts: z.optional(z.array(apiScheduleShiftSchema)),
|
|
});
|
|
export type ApiSchedule = z.infer<typeof apiScheduleSchema>;
|
|
|
|
export const apiUserSchema = defineEntity({
|
|
type: apiUserTypeSchema,
|
|
name: z.optional(z.string()),
|
|
});
|
|
export type ApiUser = z.infer<typeof apiUserSchema>;
|
|
|
|
export interface ApiAccountUpdate {
|
|
type: "account-update",
|
|
data: ApiAccount,
|
|
}
|
|
|
|
export interface ApiScheduleUpdate {
|
|
type: "schedule-update",
|
|
updatedFrom?: string,
|
|
data: ApiSchedule,
|
|
}
|
|
|
|
export type ApiEvent =
|
|
| ApiAccountUpdate
|
|
| ApiScheduleUpdate
|
|
;
|