WIP Form submit added.

This commit is contained in:
Naida Vatric
2020-02-07 12:26:29 +01:00
parent 6a957db183
commit 7777081c99
5 changed files with 46 additions and 25 deletions

View File

@@ -2,7 +2,12 @@ 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");
const {
AD_CATEGORY,
FURNISHING_TYPE,
ACCESS_ROAD_TYPE,
HEATING_TYPE
} = require("../common/enums");
const {
BASIC_BOOLEAN_PUBLISH,
BASIC_SEGMENT_PUBLISH,
@@ -169,6 +174,10 @@ const postPublishInputs = async (req, res) => {
return;
}
//const nextStepPage = req.query.nextStep || "pregled";
// const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
const nextStepUrl = "/unsubscribe/";
const balcony = req.body.balcony === "on";
const elevator = req.body.elevator === "on";
const newBuilding = req.body.newBuilding === "on";
@@ -198,31 +207,32 @@ const postPublishInputs = async (req, res) => {
const buildingPermit = req.body.buildingPermit === "on";
const furnishingType = req.body.furnishingType;
if (!FURNISHING_TYPE[furnishingType]) {
//VALIDACIJA TAKO POTVRDITI DA JE ISPRAVNA VRIJEDNOST
/* if (!FURNISHING_TYPE[furnishingType]) {
res.render("notFound", { title: " Greška !" });
return;
}
} */
const accessRoadType = req.body.accessRoadType;
if (!ACCESS_ROAD_TYPE[accessRoadType]) {
/*if (!ACCESS_ROAD_TYPE[accessRoadType]) {
res.render("notFound", { title: " Greška !" });
return;
}
} */
const heatingType = req.body.heatingType;
if (!HEATING_TYPE[heatingType]) {
/*if (!HEATING_TYPE[heatingType]) {
res.render("notFound", { title: " Greška !" });
return;
}
}*/
const price = parseFloat(req.body.price);
const area = parseFloat(req.body.area);
const gardenSize = parseFloat(req.body.gardenSize);
const numberOfRooms = parseInt(req.body.numberOfRooms);
const numberOfFloors = parseInt(req.body.numberOfFloors);
const floor = parseInt(req.body.floor);
const title = req.body.title;
const shortDescription = req.body.shortDescription;
const streetName = req.body.streetName;
const longDescription = req.body.longDescription;
const price = parseFloat(req.body.price) || null;
const area = parseFloat(req.body.area) || null;
const gardenSize = parseFloat(req.body.gardenSize) || null;
const numberOfRooms = parseInt(req.body.numberOfRooms) || null;
const numberOfFloors = parseInt(req.body.numberOfFloors) || null;
const floor = parseInt(req.body.floor) || null;
const title = req.body.title || "";
const shortDescription = req.body.shortDescription || "";
const streetName = req.body.streetName || "";
const longDescription = req.body.longDescription || "";
realEstate.balcony = balcony;
realEstate.elevator = elevator;
@@ -267,9 +277,10 @@ const postPublishInputs = async (req, res) => {
realEstate.streetName = streetName;
realEstate.longDescription = longDescription;
//
console.log("postPublishInputs");
await realEstate.save();
res.redirect(nextStepUrl);
};
module.exports = {

View File

@@ -122,6 +122,8 @@ const getFilters = async (req, res) => {
};
const postFilters = async (req, res) => {
//
console.log("postFilters");
const searchRequest = await currentSearchRequest(req);
if (!searchRequest || !searchRequest.dataValues) {

View File

@@ -13,7 +13,7 @@ const currentRealEstate = async req => {
const realEstateId = req && req.params ? req.params["realEstateId"] : null;
if (!realEstateId) return null;
return await getRealEstateById(realEstateId);
return await getRealEstateById(parseInt(realEstateId));
};
module.exports = {
currentSearchRequest,

View File

@@ -1,5 +1,13 @@
<br>
<div class="row center-align">
Vaš oglas je spreman za objavu.
</div>
<div class="row">
<div class="col s6 push-s3">
<a id="submit" href="#" form="publishForm" class="welcome-center-button waves-effect waves-light btn">Objavi oglas</a>
</div>
</div>
<br>

View File

@@ -21,11 +21,6 @@
</div>
<div id="publishEnd" class="col s12">
<%- include("./publishEnd.ejs") %>
<div class="row">
<div class="col s6 push-s3">
<a id="submit" href="#" class="welcome-center-button waves-effect waves-light btn">Objavi oglas</a>
</div>
</div>
</div>
</div>
@@ -35,5 +30,10 @@
<script>
$(document).ready(function(){
$('.tabs').tabs();
$("#submit").click( function () {
$("#publishForm").submit();
})
});
</script>