diff --git a/app/controllers/welcome.js b/app/controllers/welcome.js index 4ae84d4..3104d4e 100644 --- a/app/controllers/welcome.js +++ b/app/controllers/welcome.js @@ -1,7 +1,42 @@ +const { createSearchRequest } = require("../helpers/db/searchRequest"); + +const { AD_TYPE, AD_CATEGORY } = require("../common/enums"); + const getWelcome = (req, res) => { - res.render("welcome", { nextStep: "/vrstanekretnine", title: false }); + res.render("welcome", { + title: false, + AD_TYPE + }); +}; + +const postWelcome = async (req, res) => { + const adType = parseInt(req.body.adType); + + const adTypeStringIds = { + [AD_TYPE.AD_TYPE_SALE.id]: AD_TYPE.AD_TYPE_SALE.stringId, + [AD_TYPE.AD_TYPE_RENT.id]: AD_TYPE.AD_TYPE_RENT.stringId + }; + + const adTypeStringId = + adTypeStringIds[adType] || AD_TYPE.AD_TYPE_SALE.stringId; + + let nextStepUrl = ""; + try { + const newSearchRequest = await createSearchRequest({ + adType: adTypeStringId, + realEstateType: AD_CATEGORY.FLAT.id + }); + + nextStepUrl = `/vrstanekretnine/${newSearchRequest.id}`; + } catch (error) { + console.log(error); + nextStepUrl = `/`; + } + + res.redirect(nextStepUrl); }; module.exports = { - getWelcome + getWelcome, + postWelcome }; diff --git a/app/public/main.css b/app/public/main.css index 7b688a6..2e0d7d4 100644 --- a/app/public/main.css +++ b/app/public/main.css @@ -102,3 +102,11 @@ h3 { border-radius: 4px !important; text-align: center; } + +.collection a.collection-item { + color: #02adba; +} + +.collection a.collection-item:not(.active):hover { + background-color: rgba(2, 173, 186, 0.2); +} diff --git a/app/routes/index.js b/app/routes/index.js index 61e67f7..9043bbf 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -2,7 +2,7 @@ const express = require("express"); -const welcome = require("../controllers/welcome").getWelcome; +const { getWelcome, postWelcome } = require("../controllers/welcome"); const { getRealEstateTypes, postRealEstateTypes @@ -20,7 +20,8 @@ const { getFilters, postFilters } = require("../controllers/realEstateFilters"); const router = express.Router(); -router.get("/", welcome); +router.get("/", getWelcome); +router.post("/", postWelcome); router.get("/vrstanekretnine/:searchRequestId", getRealEstateTypes); router.get("/vrstanekretnine", getRealEstateTypes); diff --git a/app/views/welcome.ejs b/app/views/welcome.ejs index bfa640a..dd6b8e7 100644 --- a/app/views/welcome.ejs +++ b/app/views/welcome.ejs @@ -1,4 +1,3 @@ -

kivi logo @@ -8,8 +7,26 @@
Na vaš email.
BESPLATNO
-
-
- Javi mi +
+
+
+ Prodaja +
+
+ Najam +
-
+ + + +