Skip to content

Commit

Permalink
Sosynpl[premieroctet#120] Suggested Freelances done, TODO: add region…
Browse files Browse the repository at this point in the history
…s to announces
  • Loading branch information
SeghirOumo committed Jul 15, 2024
1 parent be6fa63 commit 7248574
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions backend/web/server/plugins/sosynpl/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,7 @@ const computeSuggestedFreelances = async (userId, params, data) => {
if (data.mobility === MOBILITY_FRANCE) {
return { mobility: MOBILITY_FRANCE }
}
if (data.mobility === MOBILITY_NONE) {
const regionKey = getRegionFromZipcode(data.city.zip_code)
return {
$or: [
{
mobility: MOBILITY_CITY,
$expr: {
$lt: [
computeDistanceKm(data.city, "$mobility_city"),
'$mobility_city_distance',
],
},
},
{
mobility: MOBILITY_REGIONS,
mobility_regions: { $in: [regionKey] },
},
],
}
}
return true
return {}
}

const availabilityFilter = {
Expand All @@ -91,6 +71,15 @@ const computeSuggestedFreelances = async (userId, params, data) => {
],
}
const suggestions = await CustomerFreelance.find(filter)
if (data.mobility === MOBILITY_NONE) {
const regionKey = getRegionFromZipcode(data.city.zip_code);
return suggestions.filter(s => {
return (
(s.mobility === MOBILITY_CITY && computeDistanceKm(data.city, s.mobility_city) < s.mobility_city_distance) ||
(s.mobility === MOBILITY_REGIONS && s.mobility_regions.includes(regionKey))
)
})
}
return suggestions
}

Expand Down

0 comments on commit 7248574

Please sign in to comment.