Email notifications kivi ads #107
@@ -165,7 +165,7 @@ const BASIC_INPUT_PUBLISH = [
|
||||
const BASIC_SEGMENT_PUBLISH = [
|
||||
{
|
||||
dbField: "furnishingType",
|
||||
title: "Namješten?",
|
||||
title: "Namještaj",
|
||||
values: Object.keys(FURNISHING_TYPE).map(key => FURNISHING_TYPE[key]),
|
||||
categoriesToShow: [
|
||||
AD_CATEGORY.FLAT,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { currentRealEstate } = require("../helpers/url");
|
||||
const { createRealEstate } = require("../helpers/db/realEstate");
|
||||
const { getKiviOriginalById } = require("../helpers/db/kiviOriginal");
|
||||
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
||||
const { currentKiviRealEstate } = require("../helpers/url");
|
||||
|
||||
const validate = require("validate.js");
|
||||
|
||||
@@ -20,7 +19,9 @@ const {
|
||||
} = require("../common/publishEnums");
|
||||
|
||||
const getPublishInputs = async (req, res) => {
|
||||
const realEstate = await currentRealEstate(req);
|
||||
const kiviOriginal = await currentKiviRealEstate(req);
|
||||
|
||||
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
||||
|
||||
if (!realEstate || !realEstate.dataValues) {
|
||||
res.render("notFound", { title: " " });
|
||||
@@ -170,17 +171,15 @@ const getPublishInputs = async (req, res) => {
|
||||
};
|
||||
|
||||
const postPublishInputs = async (req, res) => {
|
||||
const realEstate = await currentRealEstate(req);
|
||||
const kiviOriginal = await currentKiviRealEstate(req);
|
||||
|
||||
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
||||
|
||||
if (!realEstate || !realEstate.dataValues) {
|
||||
res.render("notFound", { title: " " });
|
||||
return;
|
||||
}
|
||||
|
||||
const kiviOriginal = await getKiviOriginalById(
|
||||
parseInt(realEstate.dataValues.agencyObjectId)
|
||||
);
|
||||
|
||||
const nextStepPage = req.query.nextStep || "/uspjesnaobjava";
|
||||
|
||||
const balcony = req.body.balcony === "on";
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
const { currentRealEstate } = require("../helpers/url");
|
||||
const { createRealEstate } = require("../helpers/db/realEstate");
|
||||
const { currentKiviRealEstate } = require("../helpers/url");
|
||||
const {
|
||||
createRealEstate,
|
||||
findRealEstateByAgencyId
|
||||
} = 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 kiviOriginal = await currentKiviRealEstate(req);
|
||||
|
||||
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
||||
|
||||
const title = "Koju nekretninu nudite?";
|
||||
let selectedAdType = AD_TYPE.AD_TYPE_SALE.id;
|
||||
@@ -32,7 +37,9 @@ const getPublishTypes = async (req, res) => {
|
||||
};
|
||||
|
||||
const postPublishTypes = async (req, res) => {
|
||||
const realEstate = await currentRealEstate(req);
|
||||
const kiviOriginal = await currentKiviRealEstate(req);
|
||||
|
||||
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
||||
|
||||
const adType = parseInt(req.body.adType);
|
||||
|
||||
@@ -57,8 +64,10 @@ const postPublishTypes = async (req, res) => {
|
||||
const nextStepPage = req.query.nextStep || "podacionekretnini";
|
||||
|
||||
let nextStepUrl = "";
|
||||
if (realEstate && realEstate.id) {
|
||||
nextStepUrl = `/${nextStepPage}/${realEstate.id}`;
|
||||
if (kiviOriginal && kiviOriginal.kiviAdId && realEstate && realEstate.id) {
|
||||
//
|
||||
nextStepUrl = `/${nextStepPage}/${kiviOriginal.kiviAdId}`;
|
||||
|
||||
realEstate.adType = adTypeStringId;
|
||||
realEstate.realEstateType = selectedRealEstateType;
|
||||
|
||||
@@ -77,8 +86,7 @@ const postPublishTypes = async (req, res) => {
|
||||
agencyObjectId: newKiviOriginal.kiviAdId
|
||||
});
|
||||
|
||||
//Da li ovaj id ili kivioriginal id ???
|
||||
nextStepUrl = `/${nextStepPage}/${newRealEstate.id}`;
|
||||
nextStepUrl = `/${nextStepPage}/${newKiviOriginal.kiviAdId}`;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
nextStepUrl = `/`;
|
||||
|
||||
@@ -33,7 +33,7 @@ const postWelcome = async (req, res) => {
|
||||
const adTypeStringId = getAdTypeString(publishAdType);
|
||||
|
||||
try {
|
||||
//Firt we create new Kivi Ad Original object in db then new Real Estate
|
||||
//First we create new Kivi Ad Original object in db then new Real Estate
|
||||
//Problem with id-s
|
||||
const newKiviOriginal = await createKiviOriginal({
|
||||
email: ""
|
||||
@@ -42,13 +42,13 @@ const postWelcome = async (req, res) => {
|
||||
const newRealEstate = await createRealEstate({
|
||||
adType: adTypeStringId,
|
||||
realEstateType: AD_CATEGORY.FLAT.id,
|
||||
//Temp variables because of the not null constraints
|
||||
//Temp variable because of the not null constraints
|
||||
url: "http://localhost:5000/",
|
||||
originAgencyName: AD_AGENCY.KIVI,
|
||||
agencyObjectId: newKiviOriginal.kiviAdId
|
||||
});
|
||||
|
||||
nextStepUrl = `/objavinekretninu/${newRealEstate.id}`;
|
||||
nextStepUrl = `/objavinekretninu/${newKiviOriginal.kiviAdId}`;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
nextStepUrl = `/`;
|
||||
|
||||
@@ -89,6 +89,16 @@ const createRealEstate = async (realEstateFields = {}) => {
|
||||
return await db.RealEstate.create(realEstateFields);
|
||||
};
|
||||
|
||||
const findRealEstateByAgencyId = async kiviId => {
|
||||
try {
|
||||
return db.RealEstate.findOne({
|
||||
where: { agencyObjectId: kiviId }
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("realEstate.js", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
const {
|
||||
priceMin,
|
||||
@@ -354,5 +364,6 @@ module.exports = {
|
||||
bulkUpsertRealEstates,
|
||||
getRealEstateById,
|
||||
createRealEstate,
|
||||
findRealEstatesForSearchRequest
|
||||
findRealEstatesForSearchRequest,
|
||||
findRealEstateByAgencyId
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { getSearchRequest } = require("./db/searchRequest");
|
||||
const { getRealEstateById } = require("./db/realEstate");
|
||||
const { getKiviOriginalById } = require("./db/kiviOriginal");
|
||||
|
||||
const currentSearchRequest = async req => {
|
||||
const searchRequestId =
|
||||
@@ -15,7 +16,16 @@ const currentRealEstate = async req => {
|
||||
|
||||
return await getRealEstateById(parseInt(realEstateId));
|
||||
};
|
||||
const currentKiviRealEstate = async req => {
|
||||
const kiviRealEstateId =
|
||||
req && req.params ? req.params["kiviRealEstateId"] : null;
|
||||
if (!kiviRealEstateId) return null;
|
||||
|
||||
return await getKiviOriginalById(kiviRealEstateId);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
currentSearchRequest,
|
||||
currentRealEstate
|
||||
currentRealEstate,
|
||||
currentKiviRealEstate
|
||||
};
|
||||
|
||||
@@ -4,8 +4,9 @@ module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
const tableFields = {
|
||||
kiviAdId: {
|
||||
type: Sequelize.BIGINT,
|
||||
autoIncrement: true,
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
email: Sequelize.TEXT,
|
||||
|
||||
@@ -5,8 +5,9 @@ module.exports = (sequalize, DataTypes) => {
|
||||
"KiviOriginal",
|
||||
{
|
||||
kiviAdId: {
|
||||
type: DataTypes.BIGINT,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
email: DataTypes.TEXT
|
||||
|
||||
@@ -37,13 +37,13 @@ router.get("/vrstanekretnine", getRealEstateTypes);
|
||||
router.post("/vrstanekretnine/:searchRequestId", postRealEstateTypes);
|
||||
router.post("/vrstanekretnine", postRealEstateTypes);
|
||||
|
||||
router.get("/objavinekretninu/:realEstateId", getPublishTypes);
|
||||
router.get("/objavinekretninu/:kiviRealEstateId", getPublishTypes);
|
||||
router.get("/objavinekretninu", getPublishTypes);
|
||||
router.post("/objavinekretninu/:realEstateId", postPublishTypes);
|
||||
router.post("/objavinekretninu/:kiviRealEstateId", postPublishTypes);
|
||||
router.post("/objavinekretninu", postPublishTypes);
|
||||
|
||||
router.get("/podacionekretnini/:realEstateId", getPublishInputs);
|
||||
router.post("/podacionekretnini/:realEstateId", postPublishInputs);
|
||||
router.get("/podacionekretnini/:kiviRealEstateId", getPublishInputs);
|
||||
router.post("/podacionekretnini/:kiviRealEstateId", postPublishInputs);
|
||||
|
||||
router.get("/lokacija/:searchRequestId", getLocation);
|
||||
router.post("/lokacija/:searchRequestId", postLocation);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<label class="checkbox-label"><%= input.title %>: </label><br><br>
|
||||
<span class="segmented small">
|
||||
<% for (const segmentObject of input.values) { %>
|
||||
<% if (segmentObject.id!=="ANY") { %>
|
||||
<label>
|
||||
<input type="radio" name="<%= input.dbField %>" value="<%= segmentObject.id %>"
|
||||
<% if (additionalSegmentSelectValues[input.dbField] === segmentObject.id) { %>
|
||||
@@ -41,6 +42,7 @@
|
||||
<% } %>>
|
||||
<span class="label"><%= segmentObject.title %></span>
|
||||
</label>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -149,14 +149,9 @@
|
||||
}
|
||||
|
||||
$("#submit").click( function () {
|
||||
const mapBounds = map.getBounds();
|
||||
const currentLocation = marker.getPosition();
|
||||
|
||||
|
||||
$("#north").val(mapBounds.getNorthEast().lat());
|
||||
$("#south").val(mapBounds.getSouthWest().lat());
|
||||
$("#east").val(mapBounds.getNorthEast().lng());
|
||||
$("#west").val(mapBounds.getSouthWest().lng());
|
||||
if (marker) {
|
||||
const currentLocation = marker.getPosition();
|
||||
|
||||
$("#lat").val(currentLocation.lat());
|
||||
|
||||
@@ -164,7 +159,13 @@
|
||||
|
||||
$("#locationInput").val(
|
||||
document.getElementById("autocompleteInput").value
|
||||
);
|
||||
);
|
||||
} else {
|
||||
$("#lat").val(0);
|
||||
|
||||
$("#lng").val(0);
|
||||
}
|
||||
|
||||
|
||||
//Tag for checking of error presence
|
||||
let hasErrors = false;
|
||||
|
||||
Reference in New Issue
Block a user