mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
fixing some rendering issues in map
This commit is contained in:
@@ -64,12 +64,10 @@ listingsRouter.get('/table', async (req, res) => {
|
||||
});
|
||||
|
||||
listingsRouter.get('/map', async (req, res) => {
|
||||
const { jobId, minPrice, maxPrice } = req.query || {};
|
||||
const { jobId } = req.query || {};
|
||||
|
||||
res.body = listingStorage.getListingsForMap({
|
||||
jobId: nullOrEmpty(jobId) ? null : jobId,
|
||||
minPrice: minPrice ? parseInt(minPrice, 10) : null,
|
||||
maxPrice: maxPrice ? parseInt(maxPrice, 10) : null,
|
||||
userId: req.session.currentUser,
|
||||
isAdmin: isAdminFn(req),
|
||||
});
|
||||
|
||||
@@ -432,14 +432,11 @@ export const updateListingGeocoordinates = (id, latitude, longitude) => {
|
||||
*
|
||||
* @param {Object} params
|
||||
* @param {string} [params.jobId]
|
||||
* @param {boolean} [params.activeOnly=true]
|
||||
* @param {number} [params.minPrice]
|
||||
* @param {number} [params.maxPrice]
|
||||
* @param {string} [params.userId]
|
||||
* @param {boolean} [params.isAdmin=false]
|
||||
* @returns {{listings: Object[], maxPrice: number}} Object containing listings and maxPrice.
|
||||
*/
|
||||
export const getListingsForMap = ({ jobId, minPrice, maxPrice, userId = null, isAdmin = false } = {}) => {
|
||||
export const getListingsForMap = ({ jobId, userId = null, isAdmin = false } = {}) => {
|
||||
const baseWhereParts = [
|
||||
'l.latitude IS NOT NULL',
|
||||
'l.longitude IS NOT NULL',
|
||||
@@ -461,15 +458,6 @@ export const getListingsForMap = ({ jobId, minPrice, maxPrice, userId = null, is
|
||||
}
|
||||
|
||||
const wherePartsForListings = [...baseWhereParts];
|
||||
if (minPrice !== undefined && minPrice !== null) {
|
||||
params.minPrice = minPrice;
|
||||
wherePartsForListings.push('l.price >= @minPrice');
|
||||
}
|
||||
|
||||
if (maxPrice !== undefined && maxPrice !== null) {
|
||||
params.maxPrice = maxPrice;
|
||||
wherePartsForListings.push('l.price <= @maxPrice');
|
||||
}
|
||||
|
||||
const listings = SqliteConnection.query(
|
||||
`SELECT l.*, j.name AS job_name
|
||||
@@ -479,17 +467,8 @@ export const getListingsForMap = ({ jobId, minPrice, maxPrice, userId = null, is
|
||||
params,
|
||||
);
|
||||
|
||||
const maxPriceRow = SqliteConnection.query(
|
||||
`SELECT MAX(l.price) AS maxPrice
|
||||
FROM listings l
|
||||
LEFT JOIN jobs j ON j.id = l.job_id
|
||||
WHERE ${baseWhereParts.join(' AND ')}`,
|
||||
params,
|
||||
)[0];
|
||||
|
||||
return {
|
||||
listings,
|
||||
maxPrice: maxPriceRow?.maxPrice || 0,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user