traxxx/assets/js/releases/actions.js

52 lines
1.3 KiB
JavaScript

import { graphql } from '../api';
import { releasesFragment, releaseFragment } from '../fragments';
import { curateRelease } from '../curate';
import getDateRange from '../get-date-range';
function initReleasesActions(store, _router) {
async function fetchReleases({ _commit }, { limit = 100, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range);
const { releases } = await graphql(`
query Releases(
$limit:Int = 1000,
$after:Date = "1900-01-01",
$before:Date = "2100-01-01",
$orderBy:[ReleasesOrderBy!],
$exclude: [String!]
) {
${releasesFragment}
}
`, {
limit,
after,
before,
orderBy,
exclude: store.state.ui.filter,
});
return releases.map(release => curateRelease(release));
}
async function fetchReleaseById({ _commit }, releaseId) {
// const release = await get(`/releases/${releaseId}`);
const { release } = await graphql(`
query Release($releaseId:Int!) {
${releaseFragment}
}
`, {
releaseId: Number(releaseId),
});
return curateRelease(release);
}
return {
fetchReleases,
fetchReleaseById,
};
}
export default initReleasesActions;