Added send notification service, and queried unsent marketalerts, fixed some issues with crawler, and added proper logging
This commit is contained in:
@@ -1,15 +1,62 @@
|
||||
const db = require('../../models/index');
|
||||
|
||||
// TODO Fetch only subscribed realestate requests
|
||||
/**
|
||||
* Find all subscribed RealEstateRequests
|
||||
*/
|
||||
const allRERequest = async () => {
|
||||
return await db.RealEstateRequest.findAll();
|
||||
return await db.RealEstateRequest.findAll({
|
||||
where: {
|
||||
subscribed: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const findPointInsideBoundingBox = async (latLng) => {
|
||||
return await db.sequelize.query("SELECT * FROM \"RealEstateRequests\" WHERE ST_Contains(\"RealEstateRequests\".bounding_box, ST_GEOMFROMTEXT(\'POINT (" + latLng[0] + " " + latLng[1]+ ")\'))");
|
||||
|
||||
/**
|
||||
* Find all unnotified marketalerts, and order them by email
|
||||
*
|
||||
* @param notified bolean
|
||||
*
|
||||
* @returns array of MarketAlerts
|
||||
*/
|
||||
const allMarketAlerts = async (notified) => {
|
||||
|
||||
let queryObject = {
|
||||
order: [
|
||||
['email', 'DESC'],
|
||||
]
|
||||
}
|
||||
|
||||
if (notified){
|
||||
queryObject.where = {
|
||||
notified: notified
|
||||
}
|
||||
}
|
||||
return await db.MarketAlert.findAll(queryObject);
|
||||
|
||||
// return await db.MarketAlerts.findAll({
|
||||
// where: {
|
||||
// notified: notified
|
||||
// },
|
||||
// order: [
|
||||
// ['email', 'DESC'],
|
||||
// ]
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all unnotified marketalerts
|
||||
* @param latLng array
|
||||
* @param email strig
|
||||
*
|
||||
* @returns array of MarketAlerts
|
||||
*/
|
||||
const findPointInsideBoundingBox = async (latLng, email) => {
|
||||
return await db.sequelize.query(`SELECT * FROM "RealEstateRequests" WHERE email = '${email}' AND subscribed = true AND ST_Contains("RealEstateRequests".bounding_box, ST_GEOMFROMTEXT('POINT (${latLng[0]} ${latLng[1]})'))`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
allRERequest,
|
||||
allMarketAlerts,
|
||||
findPointInsideBoundingBox
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user