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