2019-09-04 07:00:27 -07:00
const db = require ( "../../models/index" ) ;
2019-06-20 14:51:14 +02:00
2019-06-25 17:06:07 +02:00
/ * *
2019-09-04 07:00:27 -07:00
* Find all subscribed RealEstateRequests
2019-06-25 17:06:07 +02:00
* /
2019-06-24 14:20:31 +02:00
const allRERequest = async ( ) => {
2019-09-04 07:00:27 -07:00
return await db . RealEstateRequest . findAll ( {
where : {
subscribed : true
}
} ) ;
} ;
2019-06-20 14:51:14 +02:00
2019-07-02 21:49:56 +02:00
/ * *
* Find all subscribed RealEstateRequests by UUID
* /
2019-09-04 07:00:27 -07:00
const allRERequestByUiid = async requestArray => {
2019-07-02 21:49:56 +02:00
const Op = db . Sequelize . Op ;
return await db . RealEstateRequest . findAll ( {
2019-09-04 07:00:27 -07:00
where : {
subscribed : true ,
[ Op . or ] : requestArray
}
} ) ;
} ;
2019-07-02 21:49:56 +02:00
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-09-04 07:00:27 -07:00
*
2019-06-28 18:06:19 +02:00
* @ param fechAll bolean
2019-06-25 17:06:07 +02:00
* @ param notified bolean
2019-09-04 07:00:27 -07:00
*
2019-06-25 17:06:07 +02:00
* @ returns array of MarketAlerts
* /
2019-06-28 18:06:19 +02:00
const allMarketAlerts = async ( fetchAll , notified ) => {
2019-09-04 07:00:27 -07:00
let queryObject = {
order : [ [ "email" , "DESC" ] ]
} ;
2019-06-25 17:06:07 +02:00
2019-09-04 07:00:27 -07:00
if ( ! fetchAll ) {
queryObject . where = {
notified : notified ,
hasLocation : true
} ;
2019-06-25 17:06:07 +02:00
}
2019-07-12 18:00:02 +02:00
2019-09-04 07:00:27 -07:00
return await db . MarketAlert . findAll ( queryObject ) ;
} ;
/ * *
2019-07-12 18:00:02 +02:00
* Find all , MarketAlerts depending on request
2019-09-04 07:00:27 -07:00
*
2019-07-12 18:00:02 +02:00
* @ param request string
2019-09-04 07:00:27 -07:00
*
2019-07-12 18:00:02 +02:00
* @ returns array of MarketAlerts
* /
2019-09-04 07:00:27 -07:00
const allMarketAlertsByRequest = async request => {
2019-07-12 18:00:02 +02:00
let queryObject = {
2019-09-04 07:00:27 -07:00
where : {
2019-07-12 18:00:02 +02:00
request : request
}
2019-09-04 07:00:27 -07:00
} ;
2019-07-12 18:00:02 +02:00
return await db . MarketAlert . findAll ( queryObject ) ;
2019-09-04 07:00:27 -07:00
} ;
2019-07-12 18:00:02 +02:00
2019-06-25 17:06:07 +02:00
/ * *
2019-09-04 07:00:27 -07:00
* Find MarketAlerts by id
*
* @ param id number
*
* @ returns single MarketAlert
* /
const getMarketAlertById = async id => {
let queryObject = {
where : {
id : id
}
} ;
return await db . MarketAlert . findOne ( queryObject ) ;
} ;
/ * *
* Find all unnotified marketalerts
2019-06-25 17:06:07 +02:00
* @ param latLng array
2019-06-28 18:06:19 +02:00
* @ param email string
2019-09-04 07:00:27 -07:00
*
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 ) => {
2019-09-04 07:00:27 -07:00
return await db . sequelize . query (
2019-09-10 10:56:16 +02:00
` SELECT * FROM "RealEstateRequests" WHERE email = ' ${ email } ' AND "uniqueId" = ' ${ uniqueId } ' AND subscribed = true AND ST_Contains("RealEstateRequests"."boundingBox", ST_GEOMFROMTEXT('POINT ( ${
2019-09-04 07:00:27 -07:00
latLng [ 0 ]
} $ { latLng [ 1 ] } ) ' ) ) `
) ;
} ;
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 ,
2019-09-04 07:00:27 -07:00
allMarketAlertsByRequest ,
getMarketAlertById
2019-06-24 14:20:31 +02:00
} ;