2020-02-14 13:38:31 +01:00
|
|
|
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
|
|
|
|
const { currentKiviRealEstate } = require("../helpers/url");
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
BASIC_BOOLEAN_PUBLISH,
|
|
|
|
|
BASIC_SEGMENT_PUBLISH,
|
|
|
|
|
ADDITIONAL_BOOLEAN_PUBLISH,
|
|
|
|
|
ADDITIONAL_SEGMENT_PUBLISH,
|
|
|
|
|
BASIC_INPUT_PUBLISH,
|
|
|
|
|
ADDITIONAL_INPUT_PUBLISH
|
|
|
|
|
} = require("../common/publishEnums");
|
|
|
|
|
|
|
|
|
|
const getViewRealEstate = async (req, res) => {
|
|
|
|
|
const kiviOriginal = await currentKiviRealEstate(req);
|
|
|
|
|
|
|
|
|
|
if (!kiviOriginal || !kiviOriginal.kiviAdId) {
|
|
|
|
|
res.render("notFound", { title: " " });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
|
|
|
|
|
|
|
|
|
if (!realEstate || !realEstate.dataValues) {
|
|
|
|
|
res.render("notFound", { title: " " });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pageTitle = "Pregled nekretnine";
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
price,
|
|
|
|
|
area,
|
|
|
|
|
adType,
|
|
|
|
|
realEstateType,
|
|
|
|
|
locationLat,
|
|
|
|
|
locationLong,
|
|
|
|
|
accessRoadType,
|
|
|
|
|
heatingType,
|
|
|
|
|
balcony,
|
|
|
|
|
newBuilding,
|
|
|
|
|
elevator,
|
|
|
|
|
recentlyAdapted,
|
|
|
|
|
gardenSize,
|
|
|
|
|
numberOfRooms,
|
|
|
|
|
numberOfFloors,
|
|
|
|
|
floor,
|
|
|
|
|
water,
|
|
|
|
|
electricity,
|
|
|
|
|
drainageSystem,
|
|
|
|
|
registeredInZkBooks,
|
|
|
|
|
parking,
|
|
|
|
|
garage,
|
|
|
|
|
gas,
|
|
|
|
|
antiTheftDoor,
|
|
|
|
|
airCondition,
|
|
|
|
|
phoneConnection,
|
|
|
|
|
cableTV,
|
|
|
|
|
internet,
|
|
|
|
|
basementAttic,
|
|
|
|
|
storeRoom,
|
|
|
|
|
videoSurveillance,
|
|
|
|
|
alarm,
|
|
|
|
|
suitableForStudents,
|
|
|
|
|
includingBills,
|
|
|
|
|
animalsAllowed,
|
|
|
|
|
pool,
|
|
|
|
|
exchange,
|
|
|
|
|
urbanPlanPermit,
|
|
|
|
|
buildingPermit,
|
|
|
|
|
furnishingType,
|
|
|
|
|
shortDescription,
|
|
|
|
|
streetName,
|
|
|
|
|
title,
|
|
|
|
|
longDescription
|
|
|
|
|
} = realEstate;
|
|
|
|
|
//Categorize all database values by value type - input, boolean or segment selected
|
|
|
|
|
const allInputValues = {
|
|
|
|
|
price,
|
|
|
|
|
area,
|
|
|
|
|
gardenSize,
|
|
|
|
|
numberOfRooms,
|
|
|
|
|
numberOfFloors,
|
|
|
|
|
floor,
|
|
|
|
|
title,
|
|
|
|
|
shortDescription,
|
|
|
|
|
streetName,
|
|
|
|
|
longDescription
|
|
|
|
|
};
|
|
|
|
|
const allBooleanValues = {
|
|
|
|
|
balcony,
|
|
|
|
|
elevator,
|
|
|
|
|
newBuilding,
|
|
|
|
|
recentlyAdapted,
|
|
|
|
|
water,
|
|
|
|
|
electricity,
|
|
|
|
|
drainageSystem,
|
|
|
|
|
registeredInZkBooks,
|
|
|
|
|
parking,
|
|
|
|
|
garage,
|
|
|
|
|
gas,
|
|
|
|
|
antiTheftDoor,
|
|
|
|
|
airCondition,
|
|
|
|
|
phoneConnection,
|
|
|
|
|
cableTV,
|
|
|
|
|
internet,
|
|
|
|
|
basementAttic,
|
|
|
|
|
storeRoom,
|
|
|
|
|
videoSurveillance,
|
|
|
|
|
alarm,
|
|
|
|
|
suitableForStudents,
|
|
|
|
|
includingBills,
|
|
|
|
|
animalsAllowed,
|
|
|
|
|
pool,
|
|
|
|
|
exchange,
|
|
|
|
|
urbanPlanPermit,
|
|
|
|
|
buildingPermit
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const allSegmentSelectedValues = {
|
|
|
|
|
furnishingType,
|
|
|
|
|
accessRoadType,
|
|
|
|
|
heatingType
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//We need titles of fields ex Balkon, Novogradnja
|
|
|
|
|
const ALL_BOOLEAN_FIELDS = [
|
|
|
|
|
...BASIC_BOOLEAN_PUBLISH,
|
|
|
|
|
...ADDITIONAL_BOOLEAN_PUBLISH
|
|
|
|
|
];
|
|
|
|
|
const ALL_INPUT_FIELDS = [
|
|
|
|
|
...BASIC_INPUT_PUBLISH,
|
|
|
|
|
...ADDITIONAL_INPUT_PUBLISH
|
|
|
|
|
];
|
|
|
|
|
const ALL_SEGMENT_FIELDS = [
|
|
|
|
|
...BASIC_SEGMENT_PUBLISH,
|
|
|
|
|
...ADDITIONAL_SEGMENT_PUBLISH
|
|
|
|
|
];
|
2020-02-23 01:52:43 +01:00
|
|
|
|
2020-02-14 13:38:31 +01:00
|
|
|
//On view add page we will show only values that are not - null, or "", or undefined
|
|
|
|
|
const forShowing = value => {
|
|
|
|
|
return value !== false && value !== null && value !== "";
|
|
|
|
|
};
|
|
|
|
|
//Filter all values to be shown on page or not
|
|
|
|
|
//For showing on page we also need title ex. "Balkon"
|
|
|
|
|
const booleanFields = ALL_BOOLEAN_FIELDS.filter(object => {
|
|
|
|
|
return forShowing(allBooleanValues[object.dbField]);
|
|
|
|
|
});
|
|
|
|
|
const inputFields = ALL_INPUT_FIELDS.filter(object => {
|
|
|
|
|
return forShowing(allInputValues[object.dbField]);
|
|
|
|
|
});
|
|
|
|
|
const segmentFields = ALL_SEGMENT_FIELDS.filter(object => {
|
|
|
|
|
return forShowing(allSegmentSelectedValues[object.dbField]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.render("viewRealEstate", {
|
|
|
|
|
title: pageTitle,
|
|
|
|
|
booleanFields,
|
|
|
|
|
inputFields,
|
|
|
|
|
allInputValues,
|
|
|
|
|
segmentFields,
|
2020-02-23 01:52:43 +01:00
|
|
|
allSegmentSelectedValues,
|
|
|
|
|
locationLat,
|
|
|
|
|
locationLong
|
2020-02-14 13:38:31 +01:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getViewRealEstate
|
|
|
|
|
};
|