Skip to content

Instantly share code, notes, and snippets.

@nahidakbar
Created October 18, 2018 23:04
Show Gist options
  • Save nahidakbar/8af43d5b84e5b7f323513a1d314b8a25 to your computer and use it in GitHub Desktop.
Save nahidakbar/8af43d5b84e5b7f323513a1d314b8a25 to your computer and use it in GitHub Desktop.
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