This commit is contained in:
2025-03-20 14:39:30 +05:00
parent a44eae17dc
commit 609b94b753
38 changed files with 1382 additions and 102 deletions
+62
View File
@@ -0,0 +1,62 @@
import Elysia, { t } from "elysia";
import authMiddleware from "../middlewares/auth";
import createSession from "../services/sessions/create";
import getSessions from "../services/sessions/get";
import updateSession from "../services/sessions/update";
const sessionsController = new Elysia({ prefix: "/sessions" })
.use(authMiddleware)
.get(
"/",
async ({ auth, query }) => {
return await getSessions(auth, query);
},
{
query: t.Object({ limit: t.Optional(t.Number()) }),
}
)
.post(
"/",
async ({ body, auth }) => {
return await createSession(auth, body);
},
{
body: t.Object({
appId: t.String(),
serverId: t.String(),
clientId: t.String(),
}),
}
)
.put(
"/:id",
async ({ params, body }) => {
return await updateSession(
params.id,
body.status as
| "starting"
| "started"
| "restarting"
| "ending"
| "ended"
);
},
{
params: t.Object({
id: t.String(),
}),
body: t.Object({
status: t.Union([
t.Literal("starting"),
t.Literal("started"),
t.Literal("restarting"),
t.Literal("ending"),
t.Literal("ended"),
t.Literal("null"),
t.Literal("undefined"),
]),
}),
}
);
export default sessionsController;