1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-04 12:45:17 +02:00

chore: Remove duplicate adventures in search results

This commit is contained in:
Sean Morley 2024-06-04 13:13:40 +00:00
parent 50a2cbcd4c
commit ca04bc0095

View file

@ -26,12 +26,20 @@ export const GET: RequestHandler = async ({
const locationResults = await locationSearch(value, locals);
const namesResults = await nameSearch(value, locals);
// remove duplicates by id
let adventures: any = {};
activityResults.adventures.forEach((a: any) => {
adventures[a.id] = a;
});
locationResults.adventures.forEach((a: any) => {
adventures[a.id] = a;
});
namesResults.adventures.forEach((a: any) => {
adventures[a.id] = a;
});
return json({
adventures: [
...activityResults.adventures,
...locationResults.adventures,
...namesResults.adventures,
],
adventures: Object.values(adventures),
});
} else if (type === "activity") {
return json(await activitySearch(value, locals, isVisited));