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-07-02 21:49:56 +02:00
/ * *
* 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
}
} ) ;
}
2019-06-25 17:06:07 +02:00
/ * *
2019-07-10 15:21:46 +02:00
* Find all , or all depending on notified bolean marketalerts , that the hasLocation is true , and order them by email
2019-06-25 17:06:07 +02:00
*
2019-06-28 18:06:19 +02:00
* @ param fechAll bolean
2019-06-25 17:06:07 +02:00
* @ param notified bolean
*
* @ returns array of MarketAlerts
* /
2019-06-28 18:06:19 +02:00
const allMarketAlerts = async ( fetchAll , notified ) => {
2019-06-25 17:06:07 +02:00
let queryObject = {
order : [
[ 'email' , 'DESC' ] ,
]
}
2019-06-28 18:06:19 +02:00
if ( ! fetchAll ) {
2019-06-25 17:06:07 +02:00
queryObject . where = {
2019-07-10 15:21:46 +02:00
notified : notified ,
hasLocation : true
2019-06-25 17:06:07 +02:00
}
}
2019-06-28 18:06:19 +02:00
return await db . MarketAlert . findAll ( queryObject ) ;
2019-06-25 17:06:07 +02:00
}
2019-07-12 18:00:02 +02:00
/ * *
* Find all , MarketAlerts depending on request
*
* @ param request string
*
* @ returns array of MarketAlerts
* /
const allMarketAlertsByRequest = async ( request ) => {
let queryObject = {
where : {
request : request
}
}
return await db . MarketAlert . findAll ( queryObject ) ;
}
2019-06-25 17:06:07 +02:00
/ * *
* Find all unnotified marketalerts
* @ param latLng array
2019-06-28 18:06:19 +02:00
* @ param email string
2019-06-25 17:06:07 +02:00
*
* @ returns array of MarketAlerts
* /
2019-07-15 11:40:28 +02:00
const findPointInsideBoundingBox = async ( latLng , email , uniqueId ) => {
return await db . sequelize . query ( ` SELECT * FROM "RealEstateRequests" WHERE email = ' ${ email } ' AND "uniqueId" = ' ${ uniqueId } ' 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-07-02 21:49:56 +02:00
allRERequestByUiid ,
2019-07-12 18:00:02 +02:00
findPointInsideBoundingBox ,
allMarketAlertsByRequest
2019-06-24 14:20:31 +02:00
} ;