upd
This commit is contained in:
@@ -2,6 +2,7 @@ import Elysia, { t } from "elysia";
|
||||
import getServers from "../services/servers/get";
|
||||
import authMiddleware from "../middlewares/auth";
|
||||
import createServer from "../services/servers/create";
|
||||
import updateServer from "../services/servers/update";
|
||||
|
||||
const serversController = new Elysia({ prefix: "/servers" })
|
||||
.use(authMiddleware)
|
||||
@@ -13,6 +14,19 @@ const serversController = new Elysia({ prefix: "/servers" })
|
||||
location: t.String(),
|
||||
companyId: t.String(),
|
||||
}),
|
||||
});
|
||||
})
|
||||
.put(
|
||||
"/:id",
|
||||
async ({ params, body }) => await updateServer({ body, params }),
|
||||
{
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
location: t.String(),
|
||||
}),
|
||||
params: t.Object({
|
||||
id: t.String(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
export default serversController;
|
||||
|
||||
@@ -14,6 +14,7 @@ export default async function getServers(
|
||||
try {
|
||||
const servers = await db.query.serversTable.findMany({
|
||||
where: eq(serversTable.companyId, auth.companyId),
|
||||
orderBy: desc(serversTable.createdAt),
|
||||
with: {
|
||||
...(query?.with
|
||||
? Object.fromEntries(
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { error } from "elysia";
|
||||
import { eq } from "drizzle-orm";
|
||||
import db from "../../db";
|
||||
import { serversTable } from "../../db/schema/servers";
|
||||
|
||||
async function updateServer({
|
||||
params,
|
||||
body,
|
||||
}: {
|
||||
body: {
|
||||
name: string;
|
||||
location: string;
|
||||
};
|
||||
params: {
|
||||
id: string;
|
||||
};
|
||||
}) {
|
||||
try {
|
||||
return (
|
||||
await db
|
||||
.update(serversTable)
|
||||
.set({
|
||||
name: body.name,
|
||||
location: body.location,
|
||||
})
|
||||
.where(eq(serversTable.id, params.id))
|
||||
.returning()
|
||||
)[0];
|
||||
} catch (err) {
|
||||
console.log((err as Error).message);
|
||||
return error(500, "Internal Server Error");
|
||||
}
|
||||
}
|
||||
|
||||
export default updateServer;
|
||||
@@ -20,6 +20,12 @@ async function getSessions(
|
||||
client: true,
|
||||
app: true,
|
||||
server: true,
|
||||
owner: {
|
||||
columns: {
|
||||
password: false,
|
||||
fullname: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
limit: query?.limit,
|
||||
orderBy: desc(sessionsTable.createdAt),
|
||||
|
||||
Reference in New Issue
Block a user