2019-06-24 14:20:31 +02:00
const db = require ( '../../models/index' ) ;
2019-06-20 14:51:14 +02:00
2019-06-25 17:06:07 +02:00
/ * *
* Find all subscribed RealEstateRequests
* /
2019-06-24 14:20:31 +02:00
const allRERequest = async ( ) => {
2019-06-25 17:06:07 +02:00
return await db . RealEstateRequest . findAll ( {
where : {
subscribed : true
}
} ) ;
2019-06-24 14:20:31 +02:00
}
2019-06-20 14:51:14 +02:00
2019-06-25 17:06:07 +02:00
/ * *
* 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 ] } )')) ` ) ;
2019-06-24 14:20:31 +02:00
}
2019-06-20 14:51:14 +02:00
2019-06-24 14:20:31 +02:00
module . exports = {
allRERequest ,
2019-06-25 17:06:07 +02:00
allMarketAlerts ,
2019-06-24 14:20:31 +02:00
findPointInsideBoundingBox
} ;