This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
/
event.ts
63 lines (52 loc) · 1.42 KB
/
event.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Static, Type } from "@sinclair/typebox";
import { Item } from "./item";
import type { Route } from "./route";
import { Code, Date, Name } from "./common";
export const Event = Type.Object({
code: Code,
name: Name,
date: Date,
calculator: Type.String(),
items: Type.Array(Item),
});
export type Event = Static<typeof Event>;
export const CreateEvent = Type.Object({
code: Code,
name: Name,
date: Date,
calculator: Type.Optional(Type.String()),
items: Type.Optional(Type.Array(Code)),
});
export type CreateEvent = Static<typeof CreateEvent>;
export const UpdateEvent = Type.Partial(CreateEvent);
export type UpdateEvent = Static<typeof UpdateEvent>;
export const readEvents = {
method: "GET",
path: "/api/events",
response: Type.Array(Event),
} satisfies Route;
export const createEvent = {
method: "POST",
path: "/api/events",
body: CreateEvent,
response: Event,
} satisfies Route;
export const readEvent = {
method: "GET",
path: "/api/events/[eventcode]",
params: Type.Object({ eventcode: Code }),
response: Event,
} satisfies Route;
export const updateEvent = {
method: "PATCH",
path: "/api/events/[eventcode]",
params: Type.Object({ eventcode: Code }),
body: UpdateEvent,
response: Event,
} satisfies Route;
export const deleteEvent = {
method: "DELETE",
path: "/api/events/[eventcode]",
params: Type.Object({ eventcode: Code }),
response: Type.Null(),
} satisfies Route;