upd
This commit is contained in:
@@ -1,32 +1,41 @@
|
||||
import Elysia, { error, t } from "elysia";
|
||||
import authMiddleware from "../middlewares/auth";
|
||||
import createSession from "../services/sessions/create";
|
||||
import getSessions from "../services/sessions/get";
|
||||
import getSessions from "../services/sessions/getSessions";
|
||||
import updateSession from "../services/sessions/update";
|
||||
import db from "../db";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { sessionsTable } from "../db/schema/sessions";
|
||||
import getCount from "../services/sessions/getCount";
|
||||
|
||||
const sessionsController = new Elysia({ prefix: "/sessions" })
|
||||
.use(authMiddleware)
|
||||
.get("/", ({ auth, query }) => getSessions(auth, query), {
|
||||
query: t.Partial(
|
||||
t.Object({
|
||||
limit: t.Number(),
|
||||
status: t.Union([
|
||||
t.Literal("starting"),
|
||||
t.Literal("started"),
|
||||
t.Literal("restarting"),
|
||||
t.Literal("ending"),
|
||||
t.Literal("ended"),
|
||||
]),
|
||||
clientSearch: t.String(),
|
||||
appId: t.String(),
|
||||
ownerId: t.String(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.get(
|
||||
"/",
|
||||
async ({ auth, query }) => {
|
||||
return await getSessions(auth, query);
|
||||
},
|
||||
"/count",
|
||||
({ query, auth: { companyId } }) => getCount({ ...query, companyId }),
|
||||
{
|
||||
query: t.Partial(
|
||||
t.Object({
|
||||
limit: t.Number(),
|
||||
status: t.Union([
|
||||
t.Literal("starting"),
|
||||
t.Literal("started"),
|
||||
t.Literal("restarting"),
|
||||
t.Literal("ending"),
|
||||
t.Literal("ended"),
|
||||
]),
|
||||
})
|
||||
),
|
||||
query: t.Object({
|
||||
ownerId: t.Optional(t.String()),
|
||||
appId: t.Optional(t.String()),
|
||||
clientSearch: t.Optional(t.String()),
|
||||
}),
|
||||
}
|
||||
)
|
||||
.get("/:id", async ({ params }) => {
|
||||
@@ -51,23 +60,17 @@ const sessionsController = new Elysia({ prefix: "/sessions" })
|
||||
return error(404, "Session not found");
|
||||
}
|
||||
})
|
||||
.post(
|
||||
"/",
|
||||
async ({ body, auth }) => {
|
||||
return await createSession(auth, body);
|
||||
},
|
||||
{
|
||||
body: t.Object({
|
||||
appId: t.String(),
|
||||
serverId: t.String(),
|
||||
clientId: t.String(),
|
||||
}),
|
||||
}
|
||||
)
|
||||
.post("/", ({ body, auth }) => createSession(auth, body), {
|
||||
body: t.Object({
|
||||
appId: t.String(),
|
||||
serverId: t.String(),
|
||||
clientId: t.String(),
|
||||
}),
|
||||
})
|
||||
.put(
|
||||
"/:id",
|
||||
async ({ params, body }) => {
|
||||
return await updateSession(
|
||||
({ params, body }) =>
|
||||
updateSession(
|
||||
params.id,
|
||||
body.status as
|
||||
| "starting"
|
||||
@@ -75,8 +78,7 @@ const sessionsController = new Elysia({ prefix: "/sessions" })
|
||||
| "restarting"
|
||||
| "ending"
|
||||
| "ended"
|
||||
);
|
||||
},
|
||||
),
|
||||
{
|
||||
params: t.Object({
|
||||
id: t.String(),
|
||||
|
||||
Reference in New Issue
Block a user