2020-02-03 14:57:36 +01:00
|
|
|
const { currentRealEstate } = require("../helpers/url");
|
|
|
|
|
const { createRealEstate } = require("../helpers/db/realEstate");
|
|
|
|
|
const { createKiviOriginal } = require("../helpers/db/kiviOriginal");
|
|
|
|
|
|
|
|
|
|
const { AD_CATEGORY, AD_TYPE, AD_AGENCY } = require("../common/enums");
|
2020-02-06 01:57:29 +01:00
|
|
|
const {
|
|
|
|
|
BASIC_BOOLEAN_PUBLISH,
|
|
|
|
|
BASIC_SEGMENT_PUBLISH,
|
|
|
|
|
ADDITIONAL_BOOLEAN_PUBLISH,
|
|
|
|
|
ADDITIONAL_SEGMENT_PUBLISH,
|
|
|
|
|
BASIC_INPUT_PUBLISH
|
|
|
|
|
} = require("../common/publishEnums");
|
2020-02-03 14:57:36 +01:00
|
|
|
|
|
|
|
|
const getPublishInputs = async (req, res) => {
|
|
|
|
|
const realEstate = await currentRealEstate(req);
|
|
|
|
|
|
|
|
|
|
if (!realEstate || !realEstate.dataValues) {
|
|
|
|
|
res.render("notFound", { title: " " });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const title = "Podaci o nekretnini";
|
|
|
|
|
|
2020-02-06 01:57:29 +01:00
|
|
|
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
|
|
|
|
|
} = realEstate;
|
|
|
|
|
const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT;
|
|
|
|
|
|
|
|
|
|
// TODO: Maybe this is slow, pay attention to this
|
|
|
|
|
const filterInputs = filterObject => {
|
|
|
|
|
const filterCategories = filterObject.categoriesToShow;
|
|
|
|
|
return filterCategories.indexOf(category) !== -1;
|
|
|
|
|
};
|
|
|
|
|
//Boolean inputs to be shown on Basic Data tab
|
|
|
|
|
const basicBooleanPublishInputs = BASIC_BOOLEAN_PUBLISH.filter(filterInputs);
|
|
|
|
|
const basicBooleanPublishValues = {
|
|
|
|
|
balcony,
|
|
|
|
|
elevator,
|
|
|
|
|
newBuilding,
|
|
|
|
|
recentlyAdapted
|
|
|
|
|
};
|
|
|
|
|
//Boolean inputs to be shown on Additional Data tab
|
|
|
|
|
const additionalBooleanPublishInputs = ADDITIONAL_BOOLEAN_PUBLISH.filter(
|
|
|
|
|
filterInputs
|
|
|
|
|
);
|
|
|
|
|
const additionalBooleanPublishValues = {
|
|
|
|
|
water,
|
|
|
|
|
electricity,
|
|
|
|
|
drainageSystem,
|
|
|
|
|
registeredInZkBooks,
|
|
|
|
|
parking,
|
|
|
|
|
garage,
|
|
|
|
|
gas,
|
|
|
|
|
antiTheftDoor,
|
|
|
|
|
airCondition,
|
|
|
|
|
phoneConnection,
|
|
|
|
|
cableTV,
|
|
|
|
|
internet,
|
|
|
|
|
basementAttic,
|
|
|
|
|
storeRoom,
|
|
|
|
|
videoSurveillance,
|
|
|
|
|
alarm,
|
|
|
|
|
suitableForStudents,
|
|
|
|
|
includingBills,
|
|
|
|
|
animalsAllowed,
|
|
|
|
|
pool,
|
|
|
|
|
exchange,
|
|
|
|
|
urbanPlanPermit,
|
|
|
|
|
buildingPermit
|
|
|
|
|
};
|
|
|
|
|
//Segment select inputs to be shown on Basic Data tab
|
|
|
|
|
const basicSegmentSelectInputs = BASIC_SEGMENT_PUBLISH.filter(filterInputs);
|
|
|
|
|
const basicSegmentSelectValues = {
|
|
|
|
|
furnishingType
|
|
|
|
|
};
|
|
|
|
|
//Segment select inputs to be shown on Additional Data tab
|
|
|
|
|
const additionalSegmentSelectInputs = ADDITIONAL_SEGMENT_PUBLISH.filter(
|
|
|
|
|
filterInputs
|
|
|
|
|
);
|
|
|
|
|
const additionalSegmentSelectValues = {
|
|
|
|
|
accessRoadType,
|
|
|
|
|
heatingType
|
|
|
|
|
};
|
|
|
|
|
//Input text type inputs to be shown on Basic Data tab
|
|
|
|
|
const basicInputInputs = BASIC_INPUT_PUBLISH.filter(filterInputs);
|
|
|
|
|
const basicInputValues = {
|
|
|
|
|
price,
|
|
|
|
|
area,
|
|
|
|
|
gardenSize,
|
|
|
|
|
numberOfRooms,
|
|
|
|
|
numberOfFloors,
|
|
|
|
|
floor,
|
|
|
|
|
title,
|
|
|
|
|
shortDescription,
|
|
|
|
|
streetName
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-03 14:57:36 +01:00
|
|
|
res.render("publishRealEstate", {
|
2020-02-06 01:57:29 +01:00
|
|
|
title,
|
|
|
|
|
basicBooleanPublishInputs,
|
|
|
|
|
basicBooleanPublishValues,
|
|
|
|
|
additionalBooleanPublishInputs,
|
|
|
|
|
additionalBooleanPublishValues,
|
|
|
|
|
basicSegmentSelectInputs,
|
|
|
|
|
basicSegmentSelectValues,
|
|
|
|
|
additionalSegmentSelectInputs,
|
|
|
|
|
additionalSegmentSelectValues,
|
|
|
|
|
basicInputInputs,
|
|
|
|
|
basicInputValues
|
2020-02-03 14:57:36 +01:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const postPublishInputs = async (req, res) => {
|
|
|
|
|
const realEstate = await currentRealEstate(req);
|
|
|
|
|
|
|
|
|
|
if (!realEstate || !realEstate.dataValues) {
|
|
|
|
|
res.render("notFound", { title: " " });
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-02-06 01:57:29 +01:00
|
|
|
|
|
|
|
|
const balcony = req.body.balcony === "on";
|
|
|
|
|
const elevator = req.body.elevator === "on";
|
|
|
|
|
const newBuilding = req.body.newBuilding === "on";
|
|
|
|
|
const recentlyAdapted = req.body.recentlyAdapted === "on";
|
|
|
|
|
const water = req.body.water === "on";
|
|
|
|
|
const electricity = req.body.electricity === "on";
|
|
|
|
|
const drainageSystem = req.body.drainageSystem === "on";
|
|
|
|
|
const registeredInZkBooks = req.body.registeredInZkBooks === "on";
|
|
|
|
|
const parking = req.body.parking === "on";
|
|
|
|
|
const garage = req.body.garage === "on";
|
|
|
|
|
const gas = req.body.gas === "on";
|
|
|
|
|
const antiTheftDoor = req.body.antiTheftDoor === "on";
|
|
|
|
|
const airCondition = req.body.airCondition === "on";
|
|
|
|
|
const phoneConnection = req.body.phoneConnection === "on";
|
|
|
|
|
const cableTV = req.body.cableTV === "on";
|
|
|
|
|
const internet = req.body.internet === "on";
|
|
|
|
|
const basementAttic = req.body.basementAttic === "on";
|
|
|
|
|
const storeRoom = req.body.storeRoom === "on";
|
|
|
|
|
const videoSurveillance = req.body.videoSurveillance === "on";
|
|
|
|
|
const alarm = req.body.alarm === "on";
|
|
|
|
|
const suitableForStudents = req.body.suitableForStudents === "on";
|
|
|
|
|
const includingBills = req.body.includingBills === "on";
|
|
|
|
|
const animalsAllowed = req.body.animalsAllowed === "on";
|
|
|
|
|
const pool = req.body.pool === "on";
|
|
|
|
|
const exchange = req.body.exchange === "on";
|
|
|
|
|
const urbanPlanPermit = req.body.urbanPlanPermit === "on";
|
|
|
|
|
const buildingPermit = req.body.buildingPermit === "on";
|
|
|
|
|
|
|
|
|
|
const furnishingType = req.body.furnishingType;
|
|
|
|
|
if (!FURNISHING_TYPE[furnishingType]) {
|
|
|
|
|
res.render("notFound", { title: " Greška !" });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const accessRoadType = req.body.accessRoadType;
|
|
|
|
|
if (!ACCESS_ROAD_TYPE[accessRoadType]) {
|
|
|
|
|
res.render("notFound", { title: " Greška !" });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const heatingType = req.body.heatingType;
|
|
|
|
|
if (!HEATING_TYPE[heatingType]) {
|
|
|
|
|
res.render("notFound", { title: " Greška !" });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
realEstate.balcony = balcony;
|
|
|
|
|
realEstate.elevator = elevator;
|
|
|
|
|
realEstate.newBuilding = newBuilding;
|
|
|
|
|
realEstate.recentlyAdapted = recentlyAdapted;
|
|
|
|
|
realEstate.water = water;
|
|
|
|
|
realEstate.electricity = electricity;
|
|
|
|
|
realEstate.drainageSystem = drainageSystem;
|
|
|
|
|
realEstate.registeredInZkBooks = registeredInZkBooks;
|
|
|
|
|
realEstate.parking = parking;
|
|
|
|
|
realEstate.garage = garage;
|
|
|
|
|
realEstate.gas = gas;
|
|
|
|
|
realEstate.antiTheftDoor = antiTheftDoor;
|
|
|
|
|
realEstate.airCondition = airCondition;
|
|
|
|
|
realEstate.phoneConnection = phoneConnection;
|
|
|
|
|
realEstate.cableTV = cableTV;
|
|
|
|
|
realEstate.internet = internet;
|
|
|
|
|
realEstate.basementAttic = basementAttic;
|
|
|
|
|
realEstate.storeRoom = storeRoom;
|
|
|
|
|
realEstate.videoSurveillance = videoSurveillance;
|
|
|
|
|
realEstate.alarm = alarm;
|
|
|
|
|
realEstate.suitableForStudents = suitableForStudents;
|
|
|
|
|
realEstate.includingBills = includingBills;
|
|
|
|
|
realEstate.animalsAllowed = animalsAllowed;
|
|
|
|
|
realEstate.pool = pool;
|
|
|
|
|
realEstate.exchange = exchange;
|
|
|
|
|
realEstate.urbanPlanPermit = urbanPlanPermit;
|
|
|
|
|
realEstate.buildingPermit = buildingPermit;
|
|
|
|
|
|
|
|
|
|
realEstate.furnishingType = furnishingType;
|
|
|
|
|
realEstate.accessRoadType = accessRoadType;
|
|
|
|
|
realEstate.heatingType = heatingType;
|
|
|
|
|
//
|
|
|
|
|
console.log("postPublishInputs");
|
|
|
|
|
await realEstate.save();
|
2020-02-03 14:57:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getPublishInputs,
|
|
|
|
|
postPublishInputs
|
|
|
|
|
};
|