Created
October 18, 2018 23:04
-
-
Save nahidakbar/8af43d5b84e5b7f323513a1d314b8a25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get("/all", USER, async function(req, res) { | |
// get summary | |
let all = await database.getContentSummary(); | |
// filter out by query | |
all = simpleFilter(all, (item: any) => item.id, req.query.id); | |
all = simpleFilter(all, (item: any) => item.type, req.query.type); | |
// filter out privates and non-configurable | |
all = all.filter((item: any) => { | |
const contentItem = findContentItemById(item.id); | |
if (contentItem) { | |
if (!contentItem.private) { | |
return true; | |
} else { | |
return req.user && req.user.isAdmin; | |
} | |
} else { | |
return false; | |
} | |
}); | |
// inline | |
if (req.query.inline) { | |
for (const item of all) { | |
switch (item.type) { | |
case "application/json": | |
item.content = (await database.getContentById( | |
item.id | |
)).caseOf({ | |
nothing: undefined, | |
just: content => JSON.parse(content.content) | |
}); | |
break; | |
} | |
} | |
} | |
res.json(all); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment