init
This commit is contained in:
@@ -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() })),
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user