Email notifications kivi ads #107
@@ -303,7 +303,8 @@ const AD_AGENCY = {
|
||||
OLX: "OLX",
|
||||
RENTAL: "RENTAL",
|
||||
PROSTOR: "PROSTOR",
|
||||
AKTIDO: "AKTIDO"
|
||||
AKTIDO: "AKTIDO",
|
||||
KIVI: "KIVI"
|
||||
};
|
||||
|
||||
const CRAWLER_AD_TYPE = {
|
||||
|
||||
95
app/controllers/publishRealEstateTypes.js
Normal file
95
app/controllers/publishRealEstateTypes.js
Normal file
@@ -0,0 +1,95 @@
|
||||
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 getPublishTypes = async (req, res) => {
|
||||
const realEstate = await currentRealEstate(req);
|
||||
|
||||
const title = "Koju nekretninu nudite?";
|
||||
let selectedAdType = AD_TYPE.AD_TYPE_SALE.id;
|
||||
const labelAdType = ["Prodaj", "Iznajmi"];
|
||||
|
||||
if (
|
||||
realEstate &&
|
||||
realEstate.adType &&
|
||||
realEstate.adType === AD_TYPE.AD_TYPE_RENT.stringId
|
||||
) {
|
||||
selectedAdType = AD_TYPE.AD_TYPE_RENT.id;
|
||||
}
|
||||
const realEstateTypes = Object.keys(AD_CATEGORY)
|
||||
.map(category => AD_CATEGORY[category])
|
||||
.filter(category => category.title);
|
||||
|
||||
res.render("realEstateType", {
|
||||
selectedAdType,
|
||||
labelAdType,
|
||||
realEstateTypes,
|
||||
title,
|
||||
AD_TYPE
|
||||
});
|
||||
};
|
||||
|
||||
const postPublishTypes = async (req, res) => {
|
||||
const realEstate = await currentRealEstate(req);
|
||||
|
||||
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;
|
||||
|
||||
const validRealEstateTypes = Object.keys(AD_CATEGORY).filter(
|
||||
category => !!AD_CATEGORY[category].title
|
||||
);
|
||||
|
||||
const selectedRealEstateType = req.body.realEstateType || null;
|
||||
if (validRealEstateTypes.indexOf(selectedRealEstateType) === -1) {
|
||||
res.render("notFound", { title: " " });
|
||||
return;
|
||||
}
|
||||
// Sta je nextStepPage - treba napraviti !!!!
|
||||
/////
|
||||
/////
|
||||
const nextStepPage = req.query.nextStep || "/lokacija";
|
||||
|
||||
let nextStepUrl = "";
|
||||
if (realEstate && realEstate.id) {
|
||||
nextStepUrl = `/${nextStepPage}/${realEstate.id}`;
|
||||
realEstate.adType = adTypeStringId;
|
||||
realEstate.realEstateType = selectedRealEstateType;
|
||||
|
||||
await realEstate.save();
|
||||
} else {
|
||||
try {
|
||||
const newKiviOriginal = await createKiviOriginal({
|
||||
email: ""
|
||||
});
|
||||
|
||||
const newRealEstate = await createRealEstate({
|
||||
adType: adTypeStringId,
|
||||
realEstateType: selectedRealEstateType,
|
||||
url: "http://localhost:5000/",
|
||||
originAgencyName: AD_AGENCY.KIVI,
|
||||
agencyObjectId: newKiviOriginal.kiviAdId
|
||||
});
|
||||
|
||||
//Da li ovaj id ili kivioriginal id
|
||||
nextStepUrl = `/${nextStepPage}/${newRealEstate.id}`;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
nextStepUrl = `/`;
|
||||
}
|
||||
}
|
||||
res.redirect(nextStepUrl);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getPublishTypes,
|
||||
postPublishTypes
|
||||
};
|
||||
@@ -8,6 +8,7 @@ const getRealEstateTypes = async (req, res) => {
|
||||
|
||||
const title = "Koju nekretninu tražite?";
|
||||
let selectedAdType = AD_TYPE.AD_TYPE_SALE.id;
|
||||
const labelAdType = [AD_TYPE.AD_TYPE_SALE.title, AD_TYPE.AD_TYPE_RENT.title];
|
||||
if (
|
||||
searchRequest &&
|
||||
searchRequest.adType &&
|
||||
@@ -21,6 +22,7 @@ const getRealEstateTypes = async (req, res) => {
|
||||
|
||||
res.render("realEstateType", {
|
||||
selectedAdType,
|
||||
labelAdType,
|
||||
realEstateTypes,
|
||||
title,
|
||||
AD_TYPE
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const { createSearchRequest } = require("../helpers/db/searchRequest");
|
||||
|
||||
const { AD_TYPE, AD_CATEGORY } = require("../common/enums");
|
||||
const { createRealEstate } = require("../helpers/db/realEstate");
|
||||
const { createKiviOriginal } = require("../helpers/db/kiviOriginal");
|
||||
const { AD_TYPE, AD_CATEGORY, AD_AGENCY } = require("../common/enums");
|
||||
|
||||
const getWelcome = (req, res) => {
|
||||
res.render("welcome", {
|
||||
@@ -11,7 +12,54 @@ const getWelcome = (req, res) => {
|
||||
|
||||
const postWelcome = async (req, res) => {
|
||||
const adType = parseInt(req.body.adType);
|
||||
const publishAdType = parseInt(req.body.publishAdType);
|
||||
|
||||
let nextStepUrl = "";
|
||||
|
||||
if (adType) {
|
||||
const adTypeStringId = getAdTypeString(adType);
|
||||
try {
|
||||
const newSearchRequest = await createSearchRequest({
|
||||
adType: adTypeStringId,
|
||||
realEstateType: AD_CATEGORY.FLAT.id
|
||||
});
|
||||
|
||||
nextStepUrl = `/vrstanekretnine/${newSearchRequest.id}`;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
nextStepUrl = `/`;
|
||||
}
|
||||
} else if (publishAdType) {
|
||||
const adTypeStringId = getAdTypeString(publishAdType);
|
||||
|
||||
try {
|
||||
//Firt we create new Kivi Ad Original object in db then new Real Estate
|
||||
//Problem with id-s
|
||||
const newKiviOriginal = await createKiviOriginal({
|
||||
email: ""
|
||||
});
|
||||
|
||||
const newRealEstate = await createRealEstate({
|
||||
adType: adTypeStringId,
|
||||
realEstateType: AD_CATEGORY.FLAT.id,
|
||||
//Temp variables because of the not null constraints
|
||||
url: "http://localhost:5000/",
|
||||
originAgencyName: AD_AGENCY.KIVI,
|
||||
agencyObjectId: newKiviOriginal.kiviAdId
|
||||
});
|
||||
|
||||
nextStepUrl = `/objavinekretninu/${newRealEstate.id}`;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
nextStepUrl = `/`;
|
||||
}
|
||||
}
|
||||
|
||||
res.redirect(nextStepUrl);
|
||||
};
|
||||
|
||||
//--- Helper function
|
||||
const getAdTypeString = 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
|
||||
@@ -20,20 +68,7 @@ const postWelcome = async (req, res) => {
|
||||
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);
|
||||
return adTypeStringId;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
11
app/helpers/db/kiviOriginal.js
Normal file
11
app/helpers/db/kiviOriginal.js
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
const db = require("../../models/index");
|
||||
const sequelize = require("sequelize");
|
||||
|
||||
const createKiviOriginal = async (kiviAdFields = {}) => {
|
||||
return await db.KiviOriginal.create(kiviAdFields);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createKiviOriginal
|
||||
};
|
||||
@@ -77,7 +77,16 @@ const bulkUpsertRealEstates = async realEstateData => {
|
||||
};
|
||||
|
||||
const getRealEstateById = async id => {
|
||||
return db.RealEstate.findByPk(id);
|
||||
try {
|
||||
return db.RealEstate.findByPk(id);
|
||||
} catch (error) {
|
||||
console.log("realEstate.js", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const createRealEstate = async (realEstateFields = {}) => {
|
||||
return await db.RealEstate.create(realEstateFields);
|
||||
};
|
||||
|
||||
const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
@@ -344,5 +353,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
module.exports = {
|
||||
bulkUpsertRealEstates,
|
||||
getRealEstateById,
|
||||
createRealEstate,
|
||||
findRealEstatesForSearchRequest
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { getSearchRequest } = require("./db/searchRequest");
|
||||
const { getRealEstateById } = require("./db/realEstate");
|
||||
|
||||
const currentSearchRequest = async req => {
|
||||
const searchRequestId =
|
||||
@@ -7,6 +8,14 @@ const currentSearchRequest = async req => {
|
||||
|
||||
return await getSearchRequest(searchRequestId);
|
||||
};
|
||||
module.exports = {
|
||||
currentSearchRequest
|
||||
|
||||
const currentRealEstate = async req => {
|
||||
const realEstateId = req && req.params ? req.params["realEstateId"] : null;
|
||||
if (!realEstateId) return null;
|
||||
|
||||
return await getRealEstateById(realEstateId);
|
||||
};
|
||||
module.exports = {
|
||||
currentSearchRequest,
|
||||
currentRealEstate
|
||||
};
|
||||
|
||||
27
app/migrations/20200203114630-add-kiviOriginal-table.js
Normal file
27
app/migrations/20200203114630-add-kiviOriginal-table.js
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
const tableFields = {
|
||||
kiviAdId: {
|
||||
type: Sequelize.BIGINT,
|
||||
autoIncrement: true,
|
||||
primaryKey: true
|
||||
},
|
||||
email: Sequelize.TEXT,
|
||||
createdAt: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal("NOW()")
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal("NOW()")
|
||||
}
|
||||
};
|
||||
return queryInterface.createTable("KiviOriginal", tableFields);
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable("KiviOriginal", {});
|
||||
}
|
||||
};
|
||||
20
app/models/kiviOriginal.js
Normal file
20
app/models/kiviOriginal.js
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = (sequalize, DataTypes) => {
|
||||
const KiviOriginal = sequalize.define(
|
||||
"KiviOriginal",
|
||||
{
|
||||
kiviAdId: {
|
||||
type: DataTypes.BIGINT,
|
||||
autoIncrement: true,
|
||||
primaryKey: true
|
||||
},
|
||||
email: DataTypes.TEXT
|
||||
},
|
||||
{
|
||||
freezeTableName: true
|
||||
}
|
||||
);
|
||||
|
||||
return KiviOriginal;
|
||||
};
|
||||
@@ -7,6 +7,10 @@ const {
|
||||
getRealEstateTypes,
|
||||
postRealEstateTypes
|
||||
} = require("../controllers/realEstateTypes");
|
||||
const {
|
||||
getPublishTypes,
|
||||
postPublishTypes
|
||||
} = require("../controllers/publishRealEstateTypes");
|
||||
const {
|
||||
getQueryReview,
|
||||
postQueryReview
|
||||
@@ -28,6 +32,11 @@ router.get("/vrstanekretnine", getRealEstateTypes);
|
||||
router.post("/vrstanekretnine/:searchRequestId", postRealEstateTypes);
|
||||
router.post("/vrstanekretnine", postRealEstateTypes);
|
||||
|
||||
router.get("/objavinekretninu/:realEstateId", getPublishTypes);
|
||||
router.get("/objavinekretninu", getPublishTypes);
|
||||
router.post("/objavinekretninu/:realEstateId", postPublishTypes);
|
||||
router.post("/objavinekretninu", postPublishTypes);
|
||||
|
||||
router.get("/lokacija/:searchRequestId", getLocation);
|
||||
router.post("/lokacija/:searchRequestId", postLocation);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<% if (selectedAdType === AD_TYPE.AD_TYPE_SALE.id) { %>
|
||||
checked
|
||||
<% } %>>
|
||||
<span class="label"><%= AD_TYPE.AD_TYPE_SALE.title %></span>
|
||||
<span class="label"><%= labelAdType[0] %></span>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@@ -17,7 +17,7 @@
|
||||
<% if (selectedAdType === AD_TYPE.AD_TYPE_RENT.id) { %>
|
||||
checked
|
||||
<% } %>>
|
||||
<span class="label"><%= AD_TYPE.AD_TYPE_RENT.title %></span>
|
||||
<span class="label"><%= labelAdType[1] %></span>
|
||||
</label>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -18,7 +18,20 @@
|
||||
</div>
|
||||
<input type="hidden" id="adType" name="adType">
|
||||
</form>
|
||||
|
||||
<div class="row center-align">
|
||||
<div>Objavite svoj oglas.</div>
|
||||
</div>
|
||||
<form method="POST" name="welcomePublishForm">
|
||||
<div class="row center-align">
|
||||
<div class="col s5 m4 l3 push-s1 push-m2 push-l3">
|
||||
<a href="#" onclick="publishSaleClick()" class="welcome-center-button btn">Prodaj</a>
|
||||
</div>
|
||||
<div class="col s5 m4 l3 push-s1 push-m2 push-l3">
|
||||
<a href="#" onclick="publishRentClick()" class="welcome-center-button btn">Iznajmi</a>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="publishAdType" name="publishAdType">
|
||||
</form>
|
||||
<script>
|
||||
function saleClick(){
|
||||
$("#adType").val("<%= AD_TYPE.AD_TYPE_SALE.id %>");
|
||||
@@ -29,4 +42,13 @@
|
||||
$("#adType").val("<%= AD_TYPE.AD_TYPE_RENT.id %>");
|
||||
document.welcomeForm.submit();
|
||||
}
|
||||
function publishSaleClick(){
|
||||
$("#publishAdType").val("<%= AD_TYPE.AD_TYPE_SALE.id %>");
|
||||
document.welcomePublishForm.submit();
|
||||
}
|
||||
|
||||
function publishRentClick(){
|
||||
$("#publishAdType").val("<%= AD_TYPE.AD_TYPE_RENT.id %>");
|
||||
document.welcomePublishForm.submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user