-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.ts
More file actions
84 lines (80 loc) · 2.45 KB
/
router.ts
File metadata and controls
84 lines (80 loc) · 2.45 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { GuildId, GuildSeason } from "@v1/guild/schemas";
import {
getGuildSeason,
insertGuildSeason,
updateGuildSeason,
} from "@v1/guild/service";
import { SeasonId } from "@v1/season/schemas";
import { Hono } from "hono";
import { describeRoute, resolver, validator } from "hono-openapi";
const app = new Hono();
app.get(
"/season/:guild_id",
describeRoute({
description: "Get the guild's currently active season",
responses: {
200: {
description: "Successful response",
content: {
"application/json": {
schema: resolver(GuildSeason),
},
},
},
400: {
description: "No GuildSeason found for the provided `guild_id`",
},
},
}),
validator("param", GuildId),
async (c) => {
const { guild_id } = c.req.valid("param");
const guild_season: GuildSeason | null = await getGuildSeason(guild_id);
return guild_season ? c.json({ guild_season }) : c.notFound();
},
);
app.post(
"/season/:guild_id",
describeRoute({
description: "Create a guild's registration to a season",
responses: {
200: {
description: "Successful response",
content: {
"application/json": {
schema: resolver(GuildSeason),
},
},
},
},
}),
validator("param", GuildId),
validator("json", SeasonId),
async (c) => {
const { guild_id } = c.req.valid("param");
const { season_id } = c.req.valid("json");
const guild_season: GuildSeason = await insertGuildSeason(guild_id, season_id);
return c.json({ guild_season });
},
);
app.patch(
"/season/:guild_id",
describeRoute({
description: "Change a guild's currently active season",
responses: {
200: {
description: "Successful response",
content: {},
},
},
}),
validator("param", GuildId),
validator("json", SeasonId),
async (c) => {
const { guild_id } = c.req.valid("param");
const { season_id } = c.req.valid("json");
const affected_rows: number = await updateGuildSeason(guild_id, season_id);
return affected_rows === 0 ? c.notFound() : c.status(200);
},
);
export default app;