This commit is contained in:
2025-05-22 12:37:14 +05:00
parent ea830f0289
commit 0ec4ba5d18
5 changed files with 447 additions and 94 deletions
+61 -39
View File
@@ -1,43 +1,65 @@
// import { db } from "./src/db/index";
// import { IUnit } from "./src/types/IUnit";
// import { unitsTable } from "./src/db/schema/units";
// import got from "got";
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 } = await got
// .get(
// "https://irth-test-ii-16348121.dev.odoo.com/3d-fields/1?token=f82a4708-9a4d-491a-9424-1580b7173ba6"
// )
// .json<{ units: IUnit[] }>();
const { units: unitsOfMarasiDrive } = await got
.get(
"https://irth-test-ii-16348121.dev.odoo.com/3d-fields/1?token=f82a4708-9a4d-491a-9424-1580b7173ba6"
)
.json<{ units: IUnit[] }>();
// for (const {
// no_of_bathrooms,
// floor,
// no_of_parking_space,
// project,
// sales_price,
// square_ft,
// state,
// suits_area,
// unit_no,
// unit_type,
// unit_view,
// } of units) {
// type Unit = typeof unitsTable.$inferInsert;
const { units: unitsOfDubaiMarina } = await got
.get(
"https://irth-test-ii-16348121.dev.odoo.com/3d-fields/7?token=f82a4708-9a4d-491a-9424-1580b7173ba6"
)
.json<{ units: IUnit[] }>();
// const unit: Unit = {
// unitNo: unit_no,
// number: +unit_no.slice(2),
// project,
// floor: +floor,
// noOfBathrooms: no_of_bathrooms,
// noOfParkingSpace: no_of_parking_space,
// salesPrice: sales_price,
// state: state as Unit["state"],
// unitType: unit_type as Unit["unitType"],
// unitView: unit_view as Unit["unitView"],
// suitsArea: suits_area.toString(),
// squareFt: square_ft.toString(),
// };
for (const {
no_of_bathrooms,
floor,
no_of_parking_space,
project,
sales_price,
square_ft,
state,
suits_area,
unit_no,
unit_type,
unit_view,
balcony_area,
} of unitsOfMarasiDrive.concat(unitsOfDubaiMarina)) {
type Unit = typeof unitsTable.$inferInsert;
// await db.insert(unitsTable).values(unit);
// }
const parts = unit_no.split("-");
const unit: Unit = {
unitNo: unit_no,
number:
parts.length === 1
? +parts[0]
: !Number.isNaN(+parts[0])
? +parts[0]
: +parts[1],
project,
floor: +floor,
noOfBathrooms: no_of_bathrooms,
noOfParkingSpace: no_of_parking_space,
salesPrice: sales_price,
state: state as Unit["state"],
unitType: unit_type ? (unit_type as Unit["unitType"]) : null,
unitView: unit_view ? (unit_view as Unit["unitView"]) : null,
suitsArea: suits_area,
squareFt: square_ft,
balconyArea: balcony_area,
};
await db
.insert(unitsTable)
.values(unit)
.onConflictDoUpdate({
target: [unitsTable.project, unitsTable.unitNo],
set: unit,
});
}