traxxx/src/web/releases.js

87 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
const {
fetchReleases,
fetchActorReleases,
fetchNetworkReleases,
fetchSiteReleases,
fetchTagReleases,
} = require('../releases');
async function fetchReleasesApi(req, res) {
const filter = req.query.filter ? [].concat(req.query.filter) : []; // don't filter for 'undefined'
const releases = await fetchReleases({}, {
filter,
after: req.query.after,
before: req.query.before,
});
2019-05-18 23:34:08 +00:00
res.send(releases);
2019-05-18 23:34:08 +00:00
}
async function fetchReleaseByIdApi(req, res) {
const [release] = await fetchReleases({
id: req.params.releaseId,
});
res.send(release);
}
async function fetchActorReleasesApi(req, res) {
const actorId = Number.isInteger(Number(req.params.actorId)) ? Number(req.params.actorId) : null;
const actorSlug = typeof req.params.actorId === 'string' ? req.params.actorId : null;
const releases = await fetchActorReleases({
id: actorId,
slug: actorSlug,
});
res.send(releases);
}
async function fetchNetworkReleasesApi(req, res) {
const networkId = typeof req.params.networkId === 'number' ? req.params.networkId : null;
const networkSlug = typeof req.params.networkId === 'string' ? req.params.networkId : null;
const releases = await fetchNetworkReleases({
id: networkId,
slug: networkSlug,
});
res.send(releases);
}
async function fetchSiteReleasesApi(req, res) {
const siteId = typeof req.params.siteId === 'number' ? req.params.siteId : null;
const siteSlug = typeof req.params.siteId === 'string' ? req.params.siteId : null;
const releases = await fetchSiteReleases({
id: siteId,
slug: siteSlug,
});
res.send(releases);
}
async function fetchTagReleasesApi(req, res) {
const tagId = typeof req.params.tagId === 'number' ? req.params.tagId : null;
const tagSlug = typeof req.params.tagId === 'string' ? req.params.tagId : null;
const releases = await fetchTagReleases({
id: tagId,
slug: tagSlug,
});
res.send(releases);
}
module.exports = {
fetchReleases: fetchReleasesApi,
fetchReleaseById: fetchReleaseByIdApi,
fetchActorReleases: fetchActorReleasesApi,
fetchNetworkReleases: fetchNetworkReleasesApi,
fetchSiteReleases: fetchSiteReleasesApi,
fetchTagReleases: fetchTagReleasesApi,
};