Files
old-web/app/helpers/db/dbHelper.js

107 lines
2.1 KiB
JavaScript
Raw Normal View History

const db = require("../../models/index");
2019-06-20 14:51:14 +02:00
/**
* Find all subscribed RealEstateRequests
*/
const allRERequest = async () => {
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
*/
const allRERequestByUiid = async requestArray => {
2019-07-02 21:49:56 +02:00
const Op = db.Sequelize.Op;
return await db.RealEstateRequest.findAll({
where: {
subscribed: true,
[Op.or]: requestArray
}
});
};
2019-07-02 21:49:56 +02:00
/**
* Find all , or all depending on notified bolean marketalerts, that the hasLocation is true, 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,
hasLocation: true
};
}
2019-07-12 18:00:02 +02:00
return await db.MarketAlert.findAll(queryObject);
};
/**
2019-07-12 18:00:02 +02:00
* Find all , MarketAlerts depending on request
*
2019-07-12 18:00:02 +02:00
* @param request string
*
2019-07-12 18:00:02 +02:00
* @returns array of MarketAlerts
*/
const allMarketAlertsByRequest = async request => {
2019-07-12 18:00:02 +02:00
let queryObject = {
where: {
2019-07-12 18:00:02 +02:00
request: request
}
};
2019-07-12 18:00:02 +02:00
return await db.MarketAlert.findAll(queryObject);
};
2019-07-12 18:00:02 +02: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
* @param latLng array
* @param email string
*
* @returns array of MarketAlerts
*/
const findPointInsideBoundingBox = async (latLng, email, uniqueId) => {
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 (${
latLng[0]
} ${latLng[1]})'))`
);
};
2019-06-20 14:51:14 +02:00
module.exports = {
allRERequest,
allMarketAlerts,
2019-07-02 21:49:56 +02:00
allRERequestByUiid,
2019-07-12 18:00:02 +02:00
findPointInsideBoundingBox,
allMarketAlertsByRequest,
getMarketAlertById
};