70 lines
1.5 KiB
JavaScript
70 lines
1.5 KiB
JavaScript
const db = require('../../models/index');
|
|
|
|
/**
|
|
* Find all subscribed RealEstateRequests
|
|
*/
|
|
const allRERequest = async () => {
|
|
return await db.RealEstateRequest.findAll({
|
|
where: {
|
|
subscribed: true
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Find all subscribed RealEstateRequests by UUID
|
|
*/
|
|
const allRERequestByUiid = async (requestArray) => {
|
|
|
|
const Op = db.Sequelize.Op;
|
|
return await db.RealEstateRequest.findAll({
|
|
where: {
|
|
subscribed: true,
|
|
[Op.or]: requestArray
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Find all , or all depending on notified bolean marketalerts, and order them by email
|
|
*
|
|
* @param fechAll bolean
|
|
* @param notified bolean
|
|
*
|
|
* @returns array of MarketAlerts
|
|
*/
|
|
const allMarketAlerts = async (fetchAll, notified) => {
|
|
|
|
let queryObject = {
|
|
order: [
|
|
['email', 'DESC'],
|
|
]
|
|
}
|
|
|
|
if (!fetchAll){
|
|
queryObject.where = {
|
|
notified: notified
|
|
}
|
|
}
|
|
|
|
return await db.MarketAlert.findAll(queryObject);
|
|
}
|
|
|
|
/**
|
|
* Find all unnotified marketalerts
|
|
* @param latLng array
|
|
* @param email string
|
|
*
|
|
* @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,
|
|
allRERequestByUiid,
|
|
findPointInsideBoundingBox
|
|
};
|