This commit is contained in:
2025-07-07 18:28:28 +05:00
parent 00c840abb7
commit a74b3ca12e
4 changed files with 54 additions and 14 deletions
+12 -12
View File
@@ -5,6 +5,7 @@ import getByPhone from "../services/clients/getByPhone";
import getClients from "../services/clients/getClients";
import getCount from "../services/clients/getCount";
import { editClient } from "../services/clients/editClient";
import { getOne } from "../services/clients/getOne";
export const clientsController = new Elysia({ prefix: "/clients" })
.use(authMiddleware)
@@ -19,6 +20,9 @@ export const clientsController = new Elysia({ prefix: "/clients" })
query: t.Partial(t.Object({ limit: t.Number(), search: t.String() })),
}
)
.get("/:id", async ({ params: { id } }) => getOne(id), {
params: t.Object({ id: t.String({ format: "uuid" }) }),
})
.get(
"/count",
async ({ auth: { companyId }, query }) => getCount({ companyId, ...query }),
@@ -33,15 +37,11 @@ export const clientsController = new Elysia({ prefix: "/clients" })
email: t.Nullable(t.String()),
}),
})
.put(
"/:clientId",
async ({ body, params: { clientId } }) => editClient(clientId, body),
{
params: t.Object({ clientId: t.String() }),
body: t.Object({
name: t.String(),
phone: t.String(),
email: t.Nullable(t.String()),
}),
}
);
.put("/:id", async ({ body, params: { id } }) => editClient(id, body), {
params: t.Object({ id: t.String({ format: "uuid" }) }),
body: t.Object({
name: t.String(),
phone: t.String(),
email: t.Nullable(t.String()),
}),
});
+1 -1
View File
@@ -1,5 +1,5 @@
import Elysia, { status, t } from "elysia";
import got from "got";
import got, { HTTPError } from "got";
import db from "../db";
import { eq } from "drizzle-orm";
import { sessionsTable } from "../db/schema";
+40
View File
@@ -0,0 +1,40 @@
import { eq } from "drizzle-orm";
import db from "../../db";
import { clientsTable } from "../../db/schema";
import { status } from "elysia";
export async function getOne(id: string) {
try {
const client = await db.query.clientsTable.findFirst({
where: eq(clientsTable.id, id),
with: {
clientsToManagers: {
with: {
manager: { columns: { password: false } },
},
},
sessions: {
with: {
manager: { columns: { password: false } },
app: true,
server: true,
client: true,
comments: { with: { manager: { columns: { password: false } } } },
},
},
},
});
if (!client) return status(404, "Client not found");
const { clientsToManagers, ...rest } = client;
return {
...rest,
managers: clientsToManagers.map(({ manager }) => manager),
};
} catch (error) {
console.log((error as Error).message);
return status(500, "Internal Server Error");
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ async function updateSession(
sessionStatus: "starting" | "started" | "restarting" | "ending" | "ended"
) {
try {
const session = await db
const [session] = await db
.update(sessionsTable)
.set({ status: sessionStatus })
.where(eq(sessionsTable.id, sessionId))