fixing some rendering issues in map

This commit is contained in:
orangecoding
2026-01-16 10:46:50 +01:00
parent d43c5b3f97
commit fa1899765c
7 changed files with 1136 additions and 1487 deletions

View File

@@ -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),
});

View File

@@ -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,
};
};