2019-11-11 04:18:28 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { fetchTags } = require('../tags');
|
|
|
|
|
|
|
|
async function fetchTagsApi(req, res) {
|
2019-11-13 02:14:24 +00:00
|
|
|
const tagId = typeof req.params.tagId === 'number' ? req.params.tagId : undefined; // null will literally include NULL results
|
|
|
|
const tagSlug = typeof req.params.tagId === 'string' ? req.params.tagId : undefined;
|
2019-11-11 04:18:28 +00:00
|
|
|
|
2019-12-01 04:32:47 +00:00
|
|
|
if (tagId || tagSlug) {
|
|
|
|
const tags = await fetchTags({
|
|
|
|
id: tagId,
|
|
|
|
slug: tagSlug,
|
|
|
|
}, req.query.limit);
|
|
|
|
|
|
|
|
if (tags.length > 0) {
|
|
|
|
res.send(tags[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.status(404).send();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-13 02:14:24 +00:00
|
|
|
const tags = await fetchTags({
|
2019-12-01 04:32:47 +00:00
|
|
|
priority: req.query.priority.split(','),
|
|
|
|
}, req.query.limit);
|
2019-11-11 04:18:28 +00:00
|
|
|
|
|
|
|
res.send(tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchTags: fetchTagsApi,
|
|
|
|
};
|