hometify/server/domain/house.ts

108 lines
2.3 KiB
TypeScript

export class House {
_id: string;
_title: string | null;
_url: string | null;
_neighborhood: string | null;
_area: number | null;
_rooms: number | null;
_price: number | null;
_rawPrice: string | null;
_description: string| null;
_pic: string | null;
_baths: number | null;
_level: string | null;
_phone: string | null;
private constructor() {}
public static create(
id : string,
title : string,
url : string,
neighborhood: string,
area : number | string,
rooms : number | string,
price : number | string,
description : string,
pic : string,
baths : number | string,
level : string,
phone : string
) {
const house = new House();
house._id = id;
house._title = title?.trim() || "";
house._url = url?.trim() || "";
house._neighborhood = neighborhood?.trim() || "";
house._area = area ? parseInt(area.toString()) : 0;
house._rooms = rooms ? parseInt(rooms.toString()) : 0;
house._price = price ? parseInt(price.toString()?.replace(/\./g,'')) : 0;
house._rawPrice = price.toString() || "";
house._description = description?.trim() || "";
house._pic = pic?.trim() || "";
house._baths = baths ? parseInt(baths.toString()) : 0;
house._level = level?.trim() || "";
house._phone = phone?.trim() || "";
return house;
}
// Método para verificar coincidencia exacta en habitaciones, baños y precio
matchesExact(other: House): boolean {
return this.rooms === other.rooms && this.baths === other.baths && this.price === other.price;
}
public get id() {
return this._id;
}
public get title() {
return this._title;
}
public get url() {
return this._url;
}
public get neighborhood() {
return this._neighborhood;
}
public get area() {
return this._area;
}
public get rooms() {
return this._rooms;
}
public get price() {
return this._price;
}
public get rawPrice() {
return this._rawPrice;
}
public get description() {
return this._description;
}
public get pic() {
return this._pic;
}
public get baths() {
return this._baths;
}
public get level() {
return this._level;
}
public get phone() {
return this._phone;
}
}