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() })),
}
);
+5
View File
@@ -0,0 +1,5 @@
import { drizzle } from 'drizzle-orm/bun-sql';
import * as schema from './schema';
import { SQL } from 'bun';
export const db = drizzle({ schema, client: new SQL(process.env.DB_URL) });
+1
View File
@@ -0,0 +1 @@
export * from './units';
+37
View File
@@ -0,0 +1,37 @@
import { integer, pgTable, uuid, varchar, decimal } from "drizzle-orm/pg-core";
export const unitsTable = pgTable("units", {
id: uuid("id").defaultRandom().primaryKey(),
unitNo: varchar("unit_no", { length: 10 }).notNull(),
number: integer("number").notNull(),
project: varchar("project", { length: 256 }).notNull(),
floor: integer("floor").notNull(),
unitType: varchar("unit_type", {
length: 256,
enum: ["Studio Squared", "1 BR Squared", "Studio Flex", "2 BR Squared"],
}).notNull(),
noOfBathrooms: integer("no_of_bathrooms").notNull(),
unitView: varchar("unit_view", {
length: 256,
enum: [
"Canal / Amenities",
"Corner-Canal / Amenities",
"Corner-Canal View",
"Business Bay",
"Park Facing",
"Corner-Park Facing",
"Partial Park",
"BK/DT / Amenities",
"Corner-BK/DT / Amenities",
"Corner-Canal / BK/DT View",
],
}).notNull(),
suitsArea: decimal("suits_area", { mode: "number" }).notNull(),
squareFt: decimal("square_ft", { mode: "number" }).notNull(),
noOfParkingSpace: integer("no_of_parking_space").notNull(),
salesPrice: integer("sales_price").notNull(),
state: varchar("state", {
length: 256,
enum: ["reserved", "sold_spa", "available", "sold_registered"],
}).notNull(),
});
+2 -1
View File
@@ -1,6 +1,7 @@
import { Elysia } from "elysia";
import { unitsController } from "./controllers/units";
const app = new Elysia().get("/", () => "Hello Elysia").listen(3000);
const app = new Elysia().use(unitsController).listen(3000);
console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
+13
View File
@@ -0,0 +1,13 @@
export interface IUnit {
unit_no: string;
project: string;
floor: string;
unit_type: string;
no_of_bathrooms: number;
unit_view: string;
suits_area: number;
square_ft: number;
no_of_parking_space: number;
sales_price: number;
state: string;
}