From 26ad6a65f6d934f5d0301bc98849eaf8d1128cda Mon Sep 17 00:00:00 2001 From: inmake Date: Mon, 7 Jul 2025 13:24:27 +0500 Subject: [PATCH] Update unit retrieval logic and schema to include unitTypeVariant --- pm2.config.js | 4 ++++ replicate.ts | 25 +++++++++++++++++++++---- src/db/schema/units.ts | 6 +++--- src/types/IUnit.ts | 1 + 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 pm2.config.js diff --git a/pm2.config.js b/pm2.config.js new file mode 100644 index 0000000..53cfb1b --- /dev/null +++ b/pm2.config.js @@ -0,0 +1,4 @@ +module.exports = { + name: "irth-new-server:4002", + script: "bun ./dist/index.js", +}; diff --git a/replicate.ts b/replicate.ts index a03b6f5..44384a4 100644 --- a/replicate.ts +++ b/replicate.ts @@ -5,13 +5,15 @@ import got from "got"; const { units: unitsOfMarasiDrive } = await got .get( - "https://irth-test-ii-16348121.dev.odoo.com/3d-fields/1?token=f82a4708-9a4d-491a-9424-1580b7173ba6" + // "https://irth-test-ii-16348121.dev.odoo.com/3d-fields/1?token=f82a4708-9a4d-491a-9424-1580b7173ba6" + "https://irth.odoo.com/3d-fields/50?token=f82a4708-9a4d-491a-9424-1580b7173ba6" ) .json<{ units: IUnit[] }>(); const { units: unitsOfDubaiMarina } = await got .get( - "https://irth-test-ii-16348121.dev.odoo.com/3d-fields/7?token=f82a4708-9a4d-491a-9424-1580b7173ba6" + // "https://irth-test-ii-16348121.dev.odoo.com/3d-fields/7?token=f82a4708-9a4d-491a-9424-1580b7173ba6" + "https://irth.odoo.com/3d-fields/1?token=f82a4708-9a4d-491a-9424-1580b7173ba6" ) .json<{ units: IUnit[] }>(); @@ -26,12 +28,24 @@ for (const { suits_area, unit_no, unit_type, + unit_type_variant, unit_view, balcony_area, -} of unitsOfMarasiDrive) { +} of unitsOfDubaiMarina) { type Unit = typeof unitsTable.$inferInsert; - const parts = unit_no.split("-"); + let parts: string[]; + + if (unit_no.includes("Retail")) { + continue; + } + + try { + parts = unit_no.split("-"); + } catch (error) { + console.log(unit_no); + continue; + } const unit: Unit = { unitNo: unit_no, @@ -48,6 +62,9 @@ for (const { salesPrice: sales_price, state: state as Unit["state"], unitType: unit_type ? (unit_type as Unit["unitType"]) : null, + unitTypeVariant: unit_type_variant + ? (unit_type_variant as Unit["unitTypeVariant"]) + : null, unitView: unit_view ? (unit_view as Unit["unitView"]) : null, suitsArea: suits_area, squareFt: square_ft, diff --git a/src/db/schema/units.ts b/src/db/schema/units.ts index 5fefdd8..0289902 100644 --- a/src/db/schema/units.ts +++ b/src/db/schema/units.ts @@ -17,9 +17,9 @@ export const unitsTable = pgTable( unitView: varchar("unit_view", { length: 256, }), - // unitTypeVariant: varchar("unit_type_variant", { - // length: 256, - // }), + unitTypeVariant: varchar("unit_type_variant", { + length: 256, + }), suitsArea: doublePrecision("suits_area").notNull(), squareFt: doublePrecision("square_ft").notNull(), noOfParkingSpace: integer("no_of_parking_space").notNull(), diff --git a/src/types/IUnit.ts b/src/types/IUnit.ts index d934636..bde40f8 100644 --- a/src/types/IUnit.ts +++ b/src/types/IUnit.ts @@ -3,6 +3,7 @@ export interface IUnit { project: string; floor: string; unit_type: string | false; + unit_type_variant: string | false; unit_view: string | false; no_of_bathrooms: number; suits_area: number;