This commit is contained in:
2025-04-15 18:03:18 +05:00
parent ca5620f1d0
commit ea830f0289
14 changed files with 397 additions and 12 deletions
+24
View File
@@ -0,0 +1,24 @@
import Elysia, { error, t } from "elysia";
import { unitsTable } from "../db/schema";
import { createSelectSchema } from "drizzle-typebox";
import { db } from "../db";
import { eq, and } from "drizzle-orm";
export const getUnitSchema = createSelectSchema(unitsTable);
export const unitsController = new Elysia({ prefix: "/units" }).get(
"/",
async ({ query: { project } }) => {
try {
return await db.query.unitsTable.findMany({
where: and(project ? eq(unitsTable.project, project) : undefined),
});
} catch (err) {
console.log((err as Error).message);
return error(500, "Internal server error");
}
},
{
query: t.Partial(t.Object({ project: t.String() })),
}
);