upd
This commit is contained in:
+14
-6
@@ -1,6 +1,10 @@
|
|||||||
import { db } from "./src/db/index";
|
import { db } from "./src/db/index";
|
||||||
import { IUnit } from "./src/types/IUnit";
|
import { IUnit } from "./src/types/IUnit";
|
||||||
import { unitsTable } from "./src/db/schema/units";
|
import { unitsTable } from "./src/db/schema/units";
|
||||||
|
import { getUnitTypeVariantMarasiDrive } from "./src/utils/getUnitTypeVariantMarasiDrive";
|
||||||
|
import { getUnitTypeVariantDubaiMarina } from "./src/utils/getUnitTypeVariantDubaiMarina";
|
||||||
|
import { getUnitSideMarasiDrive } from "./src/utils/getUnitSideMarasiDrive";
|
||||||
|
import { getUnitSideDubaiMarina } from "./src/utils/getUnitSideDubaiMarina";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
|
|
||||||
const { units: unitsOfMarasiDrive } = await got
|
const { units: unitsOfMarasiDrive } = await got
|
||||||
@@ -31,7 +35,7 @@ for (const {
|
|||||||
unit_type_variant,
|
unit_type_variant,
|
||||||
unit_view,
|
unit_view,
|
||||||
balcony_area,
|
balcony_area,
|
||||||
} of unitsOfDubaiMarina) {
|
} of unitsOfDubaiMarina.concat(unitsOfMarasiDrive)) {
|
||||||
type Unit = typeof unitsTable.$inferInsert;
|
type Unit = typeof unitsTable.$inferInsert;
|
||||||
|
|
||||||
let parts: string[];
|
let parts: string[];
|
||||||
@@ -53,18 +57,22 @@ for (const {
|
|||||||
parts.length === 1
|
parts.length === 1
|
||||||
? +parts[0]
|
? +parts[0]
|
||||||
: !Number.isNaN(+parts[0])
|
: !Number.isNaN(+parts[0])
|
||||||
? +parts[0]
|
? +parts[0]
|
||||||
: +parts[1],
|
: +parts[1],
|
||||||
project,
|
project,
|
||||||
|
projectSlug: project === "Rove Home Marasi Drive" ? "marasi-drive" : "dubai-marina",
|
||||||
floor: +floor,
|
floor: +floor,
|
||||||
noOfBathrooms: no_of_bathrooms,
|
noOfBathrooms: no_of_bathrooms,
|
||||||
noOfParkingSpace: no_of_parking_space,
|
noOfParkingSpace: no_of_parking_space,
|
||||||
salesPrice: sales_price,
|
salesPrice: sales_price,
|
||||||
state: state as Unit["state"],
|
state: state !== "available" ? "unavailable" : state,
|
||||||
unitType: unit_type ? (unit_type as Unit["unitType"]) : null,
|
unitType: unit_type ? (unit_type as Unit["unitType"]) : null,
|
||||||
unitTypeVariant: unit_type_variant
|
unitTypeVariant: unit_type_variant
|
||||||
? (unit_type_variant as Unit["unitTypeVariant"])
|
? (unit_type_variant as Unit["unitTypeVariant"])
|
||||||
: null,
|
: null,
|
||||||
|
unitTypeVariantSlug: project === "Rove Home Marasi Drive" ? getUnitTypeVariantMarasiDrive(unit_no) : getUnitTypeVariantDubaiMarina(unit_no),
|
||||||
|
isLoft: project === "Rove Home Dubai Marina" && +floor > 38,
|
||||||
|
side: project === "Rove Home Marasi Drive" ? getUnitSideMarasiDrive(unit_no) : getUnitSideDubaiMarina(unit_no),
|
||||||
unitView: unit_view ? (unit_view as Unit["unitView"]) : null,
|
unitView: unit_view ? (unit_view as Unit["unitView"]) : null,
|
||||||
suitsArea: suits_area,
|
suitsArea: suits_area,
|
||||||
squareFt: square_ft,
|
squareFt: square_ft,
|
||||||
@@ -72,8 +80,8 @@ for (const {
|
|||||||
wing: unit_no.startsWith("E")
|
wing: unit_no.startsWith("E")
|
||||||
? "East"
|
? "East"
|
||||||
: unit_no.startsWith("W")
|
: unit_no.startsWith("W")
|
||||||
? "West"
|
? "West"
|
||||||
: null,
|
: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
await db
|
await db
|
||||||
|
|||||||
+10
-2
@@ -1,4 +1,4 @@
|
|||||||
import { unique } from "drizzle-orm/pg-core";
|
import { boolean, unique } from "drizzle-orm/pg-core";
|
||||||
import { doublePrecision } from "drizzle-orm/pg-core";
|
import { doublePrecision } from "drizzle-orm/pg-core";
|
||||||
import { integer, pgTable, uuid, varchar } from "drizzle-orm/pg-core";
|
import { integer, pgTable, uuid, varchar } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ export const unitsTable = pgTable(
|
|||||||
unitNo: varchar("unit_no", { length: 10 }).notNull(),
|
unitNo: varchar("unit_no", { length: 10 }).notNull(),
|
||||||
number: integer("number"),
|
number: integer("number"),
|
||||||
project: varchar("project", { length: 256 }).notNull(),
|
project: varchar("project", { length: 256 }).notNull(),
|
||||||
|
projectSlug: varchar("project_slug", { length: 256 }),
|
||||||
floor: integer("floor").notNull(),
|
floor: integer("floor").notNull(),
|
||||||
unitType: varchar("unit_type", {
|
unitType: varchar("unit_type", {
|
||||||
length: 256,
|
length: 256,
|
||||||
@@ -20,18 +21,25 @@ export const unitsTable = pgTable(
|
|||||||
unitTypeVariant: varchar("unit_type_variant", {
|
unitTypeVariant: varchar("unit_type_variant", {
|
||||||
length: 256,
|
length: 256,
|
||||||
}),
|
}),
|
||||||
|
unitTypeVariantSlug: varchar("unit_type_variant_slug", {
|
||||||
|
length: 256,
|
||||||
|
}),
|
||||||
suitsArea: doublePrecision("suits_area").notNull(),
|
suitsArea: doublePrecision("suits_area").notNull(),
|
||||||
squareFt: doublePrecision("square_ft").notNull(),
|
squareFt: doublePrecision("square_ft").notNull(),
|
||||||
noOfParkingSpace: integer("no_of_parking_space").notNull(),
|
noOfParkingSpace: integer("no_of_parking_space").notNull(),
|
||||||
salesPrice: integer("sales_price").notNull(),
|
salesPrice: integer("sales_price").notNull(),
|
||||||
state: varchar("state", {
|
state: varchar("state", {
|
||||||
length: 256,
|
length: 256,
|
||||||
enum: ["reserved", "sold_spa", "available", "sold_registered"],
|
enum: ["reserved", "sold_spa", "available", "sold_registered", "unavailable"],
|
||||||
}).notNull(),
|
}).notNull(),
|
||||||
balconyArea: doublePrecision("balcony_area").notNull(),
|
balconyArea: doublePrecision("balcony_area").notNull(),
|
||||||
wing: varchar("wing", {
|
wing: varchar("wing", {
|
||||||
enum: ["East", "West"],
|
enum: ["East", "West"],
|
||||||
}),
|
}),
|
||||||
|
side: varchar("side", {
|
||||||
|
enum: ["left", "right"],
|
||||||
|
}),
|
||||||
|
isLoft: boolean("is_loft").default(false),
|
||||||
},
|
},
|
||||||
(t) => [unique().on(t.project, t.unitNo)]
|
(t) => [unique().on(t.project, t.unitNo)]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
export function getUnitSideDubaiMarina(
|
||||||
|
unitNumber: string,
|
||||||
|
) {
|
||||||
|
const isCombinable = unitNumber.endsWith('C')
|
||||||
|
const formattedUnitNumber = isCombinable ? +unitNumber.slice(-4, -2) : +unitNumber.slice(-2);
|
||||||
|
const floor = +unitNumber.slice(0, 2);
|
||||||
|
|
||||||
|
if (floor > 38) {
|
||||||
|
if ([1, 2, 3, 5, 8, 9, 11].includes(formattedUnitNumber)) return 'right'
|
||||||
|
return 'left'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCombinable) {
|
||||||
|
if ([2, 5, 8, 10, 11].includes(formattedUnitNumber)) return 'left'
|
||||||
|
return 'right'
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([3, 4, 5, 6, 7, 8, 9, 10, 11, 21].includes(formattedUnitNumber)) return 'right'
|
||||||
|
return 'left'
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
export function getUnitSideMarasiDrive(
|
||||||
|
unitNumber: string
|
||||||
|
) {
|
||||||
|
const floor = +unitNumber.slice(2, -2);
|
||||||
|
const wing = unitNumber[0] === 'W' ? 'West' : 'East'
|
||||||
|
const formattedUnitNumber = +unitNumber.slice(-2);
|
||||||
|
|
||||||
|
if (wing === "West") {
|
||||||
|
if (floor >= 5 && floor <= 21) {
|
||||||
|
if ([3, 4, 9, 10, 11, 12, 13, 14, 16].includes(formattedUnitNumber)) return 'right'
|
||||||
|
else if (formattedUnitNumber === 17) return null;
|
||||||
|
return 'left'
|
||||||
|
}
|
||||||
|
if (floor >= 24 && floor <= 31) {
|
||||||
|
if ([1, 3, 4, 7, 9, 10, 14].includes(formattedUnitNumber)) return 'right'
|
||||||
|
return 'left'
|
||||||
|
}
|
||||||
|
return 'left'
|
||||||
|
}
|
||||||
|
if ([3, 4, 7, 8, 10, 11, 13, 16].includes(formattedUnitNumber)) return 'left'
|
||||||
|
return 'right'
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
export function getUnitTypeVariantDubaiMarina(
|
||||||
|
unitNumber: string,
|
||||||
|
): string {
|
||||||
|
const isCombinable = unitNumber.endsWith('C')
|
||||||
|
const formattedUnitNumber = isCombinable ? +unitNumber.slice(-4, -2) : +unitNumber.slice(-2);
|
||||||
|
const floor = +unitNumber.slice(0, isCombinable ? -4 : -2);
|
||||||
|
|
||||||
|
if (floor > 38) {
|
||||||
|
if ([1, 7, 8, 14].includes(formattedUnitNumber)) return '1-bedroom-loft-c'
|
||||||
|
if ([2, 6, 9, 13].includes(formattedUnitNumber)) return '1-bedroom-loft-b'
|
||||||
|
if ([3, 5, 10, 12].includes(formattedUnitNumber)) return '2-bedroom-loft'
|
||||||
|
return '1-bedroom-loft-a'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCombinable) {
|
||||||
|
if ([6, 17].includes(formattedUnitNumber)) return '1-bedroom-a'
|
||||||
|
if ([2, 10, 13, 21].includes(formattedUnitNumber)) return '2-bedroom-a'
|
||||||
|
if ([5, 8, 15, 18].includes(formattedUnitNumber)) return '1-bedroom-c'
|
||||||
|
if (formattedUnitNumber === 1) return '1-bedroom-d'
|
||||||
|
return '1-bedroom-b'
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([4, 5, 7, 8, 15, 16, 18, 19].includes(formattedUnitNumber)) return 'studio-2-a'
|
||||||
|
if ([2, 10, 13, 21].includes(formattedUnitNumber)) return 'studio-2-b'
|
||||||
|
if ([11, 12].includes(formattedUnitNumber)) return 'studio-2-c'
|
||||||
|
if ([3, 6, 9, 14, 17, 20].includes(formattedUnitNumber)) return '1-bedroom-a'
|
||||||
|
return '1-bedroom-b'
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
export function getUnitTypeVariantMarasiDrive(unitNumber: string): string {
|
||||||
|
const floor = +unitNumber.slice(2, -2);
|
||||||
|
const wing = unitNumber[0] === 'W' ? 'West' : 'East'
|
||||||
|
const formattedUnitNumber = +unitNumber.slice(-2)
|
||||||
|
|
||||||
|
if (wing === "West") {
|
||||||
|
if (floor >= 5 && floor <= 21) {
|
||||||
|
if ([9, 10, 11, 12, 13, 14].includes(formattedUnitNumber)) return 'studio-flex'
|
||||||
|
if ([2, 4, 5].includes(formattedUnitNumber)) return 'studio-2'
|
||||||
|
if ([7, 8].includes(formattedUnitNumber)) return '1-bedroom-a'
|
||||||
|
if ([3, 6].includes(formattedUnitNumber)) return '1-bedroom-d'
|
||||||
|
if (formattedUnitNumber === 1) return '2-bedroom-a'
|
||||||
|
if (formattedUnitNumber === 17) return '2-bedroom-b'
|
||||||
|
return '1-bedroom-c'
|
||||||
|
}
|
||||||
|
if (floor >= 24 && floor <= 31) {
|
||||||
|
if ([2, 4, 5, 10, 11].includes(formattedUnitNumber)) return 'studio-2'
|
||||||
|
if ([7, 8].includes(formattedUnitNumber)) return '1-bedroom-a'
|
||||||
|
if (formattedUnitNumber === 15) return '2-bedroom-b'
|
||||||
|
if ([3, 6, 9, 12].includes(formattedUnitNumber)) return '1-bedroom-d'
|
||||||
|
return '1-bedroom-c'
|
||||||
|
}
|
||||||
|
return '2-bedroom-a'
|
||||||
|
} else {
|
||||||
|
if ([2, 4, 5, 11, 12, 13, 14].includes(formattedUnitNumber)) return 'studio-2'
|
||||||
|
if ([8, 9].includes(formattedUnitNumber)) return '1-bedroom-b'
|
||||||
|
if ([6, 7, 10, 15, 16].includes(formattedUnitNumber)) return '1-bedroom-c'
|
||||||
|
if (formattedUnitNumber === 3) return '1-bedroom-d'
|
||||||
|
return '2-bedroom-a'
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user