Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit e8a65ae

Browse files
authored
Added support for multiple blocks (#19)
Signed-off-by: Arnau Mora Gras <[email protected]>
1 parent a5b58d4 commit e8a65ae

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

endpoints/blocking.mjs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@ export default async (req, res) => {
2424
*/
2525
let blockages = processBlockingData(query);
2626

27-
/**
28-
* @type {{path: string, blocked: boolean, type: string, endDate: (Date|null)}|Object<string, {path: string, blocked: boolean, type: string, endDate: (Date|null)}[]>}
29-
*/
30-
let result = blockages.length === 1 ?
31-
// If only one item, result is that item
32-
blockages[0] :
33-
// If multiple items, create a map with all the items and the respective path ids
34-
blockages.reduce((map, obj) => {
35-
const path = obj.path;
36-
delete obj.path;
37-
map[path] = obj;
38-
return map;
39-
}, {});
27+
/** @type {Object} */
28+
let result = {};
29+
30+
for (const blockage of blockages) {
31+
const id = blockage.path;
32+
const paths = result.hasOwnProperty(id) ? result[id] : [];
33+
delete blockage.path;
34+
paths.push(blockage);
35+
result[id] = paths;
36+
}
4037

4138
// If the result was single item, remove the path property
4239
if (result.hasOwnProperty('path'))

0 commit comments

Comments
 (0)