skip to query review directly when editing data

This commit is contained in:
Bilal Catic
2019-05-21 15:25:28 +02:00
parent 126da48852
commit aa3c965d5c
7 changed files with 74 additions and 57 deletions

View File

@@ -2,19 +2,19 @@ const { currentRERequest } = require('../helpers/url');
const { gardenSizes } = require('../helpers/enums');
const getGardenSize = (req,res) => {
const nextStep = req.query.nextStep;
res.render('gardenSize', {
nextStep,
gardenSizes
});
res.render('gardenSize', { gardenSizes });
};
const postGardenSize = async (req, res) => {
const request = await currentRERequest(req);
const nextStep = req.query.nextStep || `/cijena/${request.uniqueId}`;
const nextStepPage = req.query.nextStep || 'cijena';
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
request.gardenSize = req.body.gardensize;
await request.save();
res.redirect(nextStep);
res.redirect(nextStepUrl);
};
module.exports = {

View File

@@ -4,19 +4,20 @@ const { getMunicipalitiesForRegion } = require('../helpers/codes');
const getMunicipality = async (req,res) => {
let request = await currentRERequest(req);
const municipalities = getMunicipalitiesForRegion(request.region);
const nextStep = req.query.nextStep || '/';
res.render('municipality', {
nextStep,
municipalities
});
res.render('municipality', { municipalities });
};
const postMunicipality = async (req, res) => {
const request = await currentRERequest(req);
const nextStep = req.query.nextStep || `/povrsina/${request.uniqueId}`;
const nextStepPage = req.query.nextStep || 'povrsina';
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
request.municipality = req.body.municipality;
await request.save();
res.redirect(nextStep);
res.redirect(nextStepUrl);
};
module.exports = {

View File

@@ -2,19 +2,19 @@ const { currentRERequest } = require('../helpers/url');
const { prices } = require('../helpers/enums');
const getPrice = (req,res) => {
const nextStep = req.query.nextStep;
res.render('price', {
nextStep,
prices
});
res.render('price', { prices });
};
const postPrice = async (req, res) => {
const request = await currentRERequest(req);
const nextStep = req.query.nextStep || `/pregled/${request.uniqueId}`;
const nextStepPage = req.query.nextStep || 'pregled';
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
request.price = req.body.price;
await request.save();
res.redirect(nextStep);
res.redirect(nextStepUrl);
};
module.exports = {

View File

@@ -25,32 +25,32 @@ const getQueryReview = async (req,res) => {
{
id: 'realEstateType',
title: realEstateTypeTitle,
url: `/vrstanekretnine/${uniqueId}`,
url: `/vrstanekretnine/${uniqueId}?nextStep=pregled`,
},
{
id: 'region',
title: regionName,
url: `/region/${uniqueId}`,
url: `/grad/${uniqueId}?nextStep=mjesto`,
},
{
id: 'municipality',
title: municipalityName,
url: `/mjesto/${uniqueId}`,
url: `/mjesto/${uniqueId}?nextStep=pregled`,
},
{
id: 'size',
title: sizeTitle,
url: `/povrsina/${uniqueId}`,
url: `/povrsina/${uniqueId}?nextStep=pregled`,
},
{
id: 'gardenSize',
title: gardenSizeTitle,
url: `/okucnica/${uniqueId}`,
url: `/okucnica/${uniqueId}?nextStep=pregled`,
},
{
id: 'price',
title: priceTitle,
url: `/cijena/${uniqueId}`
url: `/cijena/${uniqueId}?nextStep=pregled`
}
];

View File

@@ -1,24 +1,38 @@
const db = require('../models/index');
const { currentRERequest } = require('../helpers/url');
const { realEstateTypes } = require('../helpers/enums');
const getRealEstateTypes = (req,res) => {
const nextStep = req.query.nextStep;
res.render('realEstateType', {
nextStep,
realEstateTypes: realEstateTypes
});
res.render('realEstateType', { realEstateTypes });
};
const postRealEstateTypes = (req, res) => {
let nextStep = req.query.nextStep;
db.RealEstateRequest.create({
realEstateType: req.body.realestatetype
}).then( (result) => {
nextStep = nextStep || `/grad/${result.uniqueId}`;
res.redirect(nextStep);
}).catch( (e) => {
res.send(e);
});
const postRealEstateTypes = async (req, res) => {
const request = await currentRERequest(req);
const nextStepPage = req.query.nextStep || 'grad';
if (request && request.uniqueId) {
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
request.realEstateType = req.body.realestatetype;
await request.save();
res.redirect(nextStepUrl)
} else {
db.RealEstateRequest.create({
realEstateType: req.body.realestatetype
}).then( (result) => {
const nextStepUrl = `/${nextStepPage}/${result.uniqueId}`;
res.redirect(nextStepUrl);
}).catch( (e) => {
res.send(e);
});
}
};
module.exports = {

View File

@@ -1,22 +1,24 @@
const { currentRERequest } = require('../helpers/url');
const { currentRERequest } = require('../helpers/url');
const { getRegions } = require('../helpers/codes');
const regions = getRegions();
const getRegion = (req,res) => {
const nextStep = req.query.nextStep || '/';
res.render('region', {
nextStep,
regions
});
res.render('region', { regions });
};
const postRegion = async (req, res) => {
const request = await currentRERequest(req);
const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`;
const nextStepQueryParam = req.query.nextStep ? '?nextStep=pregled' : '';
const nextStepPage = req.query.nextStep || 'mjesto';
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}${nextStepQueryParam}`;
request.region = req.body.region;
request.municipality = null;
await request.save();
res.redirect(nextStep)
res.redirect(nextStepUrl)
};
module.exports = {

View File

@@ -2,19 +2,19 @@ const { currentRERequest } = require('../helpers/url');
const { sizes } = require('../helpers/enums');
const getSize = (req,res) => {
const nextStep = req.query.nextStep;
res.render('size', {
nextStep,
sizes
});
res.render('size', { sizes });
};
const postSize = async (req, res) => {
const request = await currentRERequest(req);
const nextStep = req.query.nextStep || `/okucnica/${request.uniqueId}`;
const nextStepPage = req.query.nextStep || 'okucnica';
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
request.size = req.body.size;
await request.save();
res.redirect(nextStep);
res.redirect(nextStepUrl);
};
module.exports = {