For revision kivi ads input.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
||||||
|
const { bulkUpsertKiviPhotos } = require("../helpers/db/kiviOriginalAdsPhotos");
|
||||||
const { currentKiviRealEstate } = require("../helpers/url");
|
const { currentKiviRealEstate } = require("../helpers/url");
|
||||||
|
|
||||||
const validate = require("validate.js");
|
const validate = require("validate.js");
|
||||||
@@ -183,7 +184,7 @@ const postPublishInputs = async (req, res) => {
|
|||||||
const nextStepPage = req.query.nextStep || "/uspjesnaobjava";
|
const nextStepPage = req.query.nextStep || "/uspjesnaobjava";
|
||||||
|
|
||||||
//Request body
|
//Request body
|
||||||
console.log("Body:", req.body);
|
//console.log("Body:", req.body);
|
||||||
|
|
||||||
const balcony = req.body.balcony === "on";
|
const balcony = req.body.balcony === "on";
|
||||||
const elevator = req.body.elevator === "on";
|
const elevator = req.body.elevator === "on";
|
||||||
@@ -245,9 +246,16 @@ const postPublishInputs = async (req, res) => {
|
|||||||
const locationLong = req.body.lng || null;
|
const locationLong = req.body.lng || null;
|
||||||
//Contact email saved in other table
|
//Contact email saved in other table
|
||||||
const contactEmail = req.body.email || "";
|
const contactEmail = req.body.email || "";
|
||||||
|
//Image urls are stored in new table
|
||||||
const imageUrls = req.body.imageUrls.split("|") || [];
|
const imageUrls =
|
||||||
console.log(imageUrls);
|
req.body.imageUrls.split("|").filter(url => url !== "") || [];
|
||||||
|
const imageUrlsData = imageUrls.map(url => {
|
||||||
|
return {
|
||||||
|
kiviAdId: kiviOriginal.kiviAdId,
|
||||||
|
photoUrl: url
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const savedImageUrls = await bulkUpsertKiviPhotos(imageUrlsData);
|
||||||
|
|
||||||
realEstate.balcony = balcony;
|
realEstate.balcony = balcony;
|
||||||
realEstate.elevator = elevator;
|
realEstate.elevator = elevator;
|
||||||
|
|||||||
17
app/helpers/db/kiviOriginalAdsPhotos.js
Normal file
17
app/helpers/db/kiviOriginalAdsPhotos.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
const db = require("../../models/index");
|
||||||
|
const sequelize = require("sequelize");
|
||||||
|
|
||||||
|
const bulkUpsertKiviPhotos = async kiviPhotosData => {
|
||||||
|
try {
|
||||||
|
return await db.KiviOriginalAdsPhotos.bulkCreate(kiviPhotosData, {
|
||||||
|
ignoreDuplicates: true
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Error bulk upserting kiviOriginalAdsPhotos : ", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
bulkUpsertKiviPhotos
|
||||||
|
};
|
||||||
39
app/migrations/20200312210336-add-table-kivi-photos.js
Normal file
39
app/migrations/20200312210336-add-table-kivi-photos.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
const tableFields = {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.BIGINT,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
kiviAdId: {
|
||||||
|
type: Sequelize.UUID,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: "KiviOriginal",
|
||||||
|
key: "kiviAdId"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
photoUrl: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal("NOW()")
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: Sequelize.literal("NOW()")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return queryInterface.createTable("KiviOriginalAdsPhotos", tableFields);
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.dropTable("KiviOriginalAdsPhotos", {});
|
||||||
|
}
|
||||||
|
};
|
||||||
41
app/models/kiviOriginalAdsPhotos.js
Normal file
41
app/models/kiviOriginalAdsPhotos.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = (sequalize, DataTypes) => {
|
||||||
|
const KiviOriginalAdsPhotos = sequalize.define(
|
||||||
|
"KiviOriginalAdsPhotos",
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
type: DataTypes.BIGINT,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
kiviAdId: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: "KiviOriginal",
|
||||||
|
key: "kiviAdId"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
photoUrl: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
freezeTableName: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
KiviOriginalAdsPhotos.associate = models => {
|
||||||
|
KiviOriginalAdsPhotos.hasMany(models.KiviOriginal, {
|
||||||
|
foreignKey: "kiviAdId",
|
||||||
|
sourceKey: "kiviAdId",
|
||||||
|
targetKey: "kiviAdId",
|
||||||
|
as: "kiviOriginal"
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return KiviOriginalAdsPhotos;
|
||||||
|
};
|
||||||
@@ -8,8 +8,5 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<div class="row center-align">
|
|
||||||
<button id="test" class="welcome-center-button waves-effect waves-light btn col s4">UPLOAD</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<input type="hidden" name="imageUrls" id="imageUrls" value="">
|
<input type="hidden" name="imageUrls" id="imageUrls" value="">
|
||||||
|
|||||||
@@ -91,11 +91,11 @@
|
|||||||
autoProcessQueue:false, //not to upload files automaticly
|
autoProcessQueue:false, //not to upload files automaticly
|
||||||
method: "put", //or post
|
method: "put", //or post
|
||||||
parallelUploads: 1,
|
parallelUploads: 1,
|
||||||
uploadMultiple: false, //or true ??
|
uploadMultiple: false,
|
||||||
addRemoveLinks: true,
|
addRemoveLinks: true,
|
||||||
maxFilesize: 2, //MB,
|
maxFilesize: 2, //MB,
|
||||||
resizeWidth: 600,
|
resizeWidth: 600,
|
||||||
maxFiles: 10, // ??
|
maxFiles: 10,
|
||||||
acceptedFiles: "image/*",
|
acceptedFiles: "image/*",
|
||||||
dictDefaultMessage: `<span class="text-center">
|
dictDefaultMessage: `<span class="text-center">
|
||||||
<h3>Prevuci fotografije ili klikni za dodavanje!</h3>
|
<h3>Prevuci fotografije ili klikni za dodavanje!</h3>
|
||||||
@@ -227,20 +227,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#submit").click( async function (e) {
|
||||||
$("#test").click(function(e){
|
e.preventDefault();
|
||||||
e.preventDefault();
|
|
||||||
const addedFiles = photosUploader.files.filter(file => file.status!=="error");
|
|
||||||
console.log(addedFiles);
|
|
||||||
addedFiles.forEach( async (file) => {
|
|
||||||
await generateSignedURL(file);
|
|
||||||
})
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$("#submit").click( function () {
|
|
||||||
|
|
||||||
|
|
||||||
if (marker) {
|
if (marker) {
|
||||||
const currentLocation = marker.getPosition();
|
const currentLocation = marker.getPosition();
|
||||||
@@ -258,7 +246,6 @@ $("#test").click(function(e){
|
|||||||
$("#lng").val(0);
|
$("#lng").val(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Tag for checking of error presence
|
//Tag for checking of error presence
|
||||||
let hasErrors = false;
|
let hasErrors = false;
|
||||||
//Check if email is valid
|
//Check if email is valid
|
||||||
@@ -284,14 +271,19 @@ $("#test").click(function(e){
|
|||||||
|
|
||||||
validate (input);
|
validate (input);
|
||||||
} */
|
} */
|
||||||
|
const addedFiles = photosUploader.files.filter(file => file.status!=="error");
|
||||||
|
const asyncUpload =[];
|
||||||
|
|
||||||
|
addedFiles.forEach( file => {
|
||||||
|
asyncUpload.push(generateSignedURL(file));
|
||||||
|
})
|
||||||
|
|
||||||
if (!hasErrors) {
|
if (!hasErrors) {
|
||||||
|
await Promise.all(asyncUpload);
|
||||||
$("#publishForm").submit();
|
$("#publishForm").submit();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user