2019-05-17 11:06:32 +02:00
|
|
|
const { currentRERequest } = require('../helpers/url');
|
2019-05-27 09:18:54 +02:00
|
|
|
const { getMunicipalitiesForRegion, getMunicipalityName } = require('../helpers/codes');
|
2019-05-16 23:32:18 +02:00
|
|
|
|
2019-05-17 10:49:13 +02:00
|
|
|
const getMunicipality = async (req, res) => {
|
2019-05-16 23:32:18 +02:00
|
|
|
let request = await currentRERequest(req);
|
2019-05-17 00:33:10 +02:00
|
|
|
const municipalities = getMunicipalitiesForRegion(request.region);
|
2019-05-21 15:25:28 +02:00
|
|
|
|
|
|
|
|
res.render('municipality', { municipalities });
|
2019-05-16 23:32:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const postMunicipality = async (req, res) => {
|
2019-05-27 15:17:41 +02:00
|
|
|
|
2019-05-17 11:06:32 +02:00
|
|
|
const request = await currentRERequest(req);
|
2019-05-27 15:17:41 +02:00
|
|
|
const nextStepParam = req.query.nextStep ? "?nextStep=" + req.query.nextStep : "";
|
|
|
|
|
const nextStepUrl = `/${'naselje'}/${request.uniqueId}/${getMunicipalityName(request.region, req.body.municipality)}${nextStepParam}`;
|
2019-05-21 15:25:28 +02:00
|
|
|
|
2019-05-16 23:32:18 +02:00
|
|
|
request.municipality = req.body.municipality;
|
|
|
|
|
await request.save();
|
2019-05-21 15:25:28 +02:00
|
|
|
|
|
|
|
|
res.redirect(nextStepUrl);
|
2019-05-16 23:32:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getMunicipality,
|
|
|
|
|
postMunicipality
|
|
|
|
|
};
|