This commit is contained in:
2025-06-03 15:00:39 +05:00
parent edfa56270e
commit d0562c4629
2 changed files with 49 additions and 1 deletions
-1
View File
@@ -2,7 +2,6 @@ import { db } from "./src/db/index";
import { IUnit } from "./src/types/IUnit";
import { unitsTable } from "./src/db/schema/units";
import got from "got";
// import { and, eq, exists } from "drizzle-orm";
const { units: unitsOfMarasiDrive } = await got
.get(
+49
View File
@@ -413,4 +413,53 @@ export const unitsController = new Elysia({ prefix: "/units" })
project: t.String(),
}),
}
)
.get(
"/:unitNumber",
async ({ params: { unitNumber }, query: { project } }) => {
try {
return await db.query.unitsTable.findFirst({
where: and(
eq(unitsTable.unitNo, unitNumber),
eq(unitsTable.project, decodeURIComponent(project))
),
});
} catch (error) {
console.log((error as Error).message);
return status(500, "Internal server error");
}
},
{
query: t.Object({
project: t.String(),
}),
params: t.Object({
unitNumber: t.String(),
}),
}
)
.get(
"/on-floor",
async ({ query: { floor, project, wing } }) => {
try {
return await db.query.unitsTable.findMany({
where: and(
eq(unitsTable.project, decodeURIComponent(project)),
eq(unitsTable.floor, floor),
wing ? eq(unitsTable.wing, wing) : undefined
),
orderBy: [asc(unitsTable.number)],
});
} catch (error) {
console.log((error as Error).message);
return status(500, "Internal server error");
}
},
{
query: t.Object({
project: t.String(),
floor: t.Number(),
wing: t.Optional(t.Union([t.Literal("East"), t.Literal("West")])),
}),
}
);