2020-06-27 00:57:30 +00:00
|
|
|
import { graphql } from '../api';
|
|
|
|
// import { sitesFragment, releaseFields } from '../fragments';
|
2023-06-15 22:47:19 +00:00
|
|
|
import { releaseFields, batchFragment, campaignsFragment } from '../fragments';
|
2020-06-27 00:57:30 +00:00
|
|
|
import { curateEntity } from '../curate';
|
|
|
|
import getDateRange from '../get-date-range';
|
|
|
|
|
2020-09-10 01:17:19 +00:00
|
|
|
function initEntitiesActions(store, router) {
|
2020-06-27 00:57:30 +00:00
|
|
|
async function fetchEntityBySlugAndType({ _commit }, {
|
|
|
|
entitySlug,
|
|
|
|
entityType,
|
|
|
|
limit = 10,
|
|
|
|
pageNumber = 1,
|
|
|
|
range = 'latest',
|
|
|
|
}) {
|
|
|
|
const { before, after, orderBy } = getDateRange(range);
|
|
|
|
|
2023-06-18 00:29:10 +00:00
|
|
|
const { entity, connection, batches: [lastBatch] } = await graphql(`
|
2020-06-27 00:57:30 +00:00
|
|
|
query Entity(
|
|
|
|
$entitySlug: String!
|
|
|
|
$entityType: String! = "channel"
|
|
|
|
$limit: Int = 10,
|
|
|
|
$offset: Int = 0,
|
2020-07-16 13:55:03 +00:00
|
|
|
$after: Datetime = "1900-01-01",
|
|
|
|
$before: Datetime = "2100-01-01",
|
2023-07-16 23:59:26 +00:00
|
|
|
$orderBy: [ReleasesSummariesOrderBy!]
|
2020-06-27 00:57:30 +00:00
|
|
|
$exclude: [String!]
|
2021-03-19 02:27:48 +00:00
|
|
|
$hasAuth: Boolean!
|
|
|
|
$userId: Int
|
2020-06-27 00:57:30 +00:00
|
|
|
) {
|
|
|
|
entity: entityBySlugAndType(slug: $entitySlug, type: $entityType) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
2020-07-02 02:04:28 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-07-05 02:10:35 +00:00
|
|
|
tags: entitiesTags {
|
|
|
|
tag {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
2022-03-04 22:31:59 +00:00
|
|
|
sceneTags {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
2020-06-28 01:58:16 +00:00
|
|
|
children: childEntitiesConnection(
|
2020-06-27 00:57:30 +00:00
|
|
|
orderBy: [PRIORITY_DESC, NAME_ASC],
|
2020-07-02 23:28:22 +00:00
|
|
|
filter: {
|
|
|
|
type: {
|
|
|
|
notEqualTo: "info"
|
|
|
|
}
|
2020-07-08 00:53:46 +00:00
|
|
|
visible: {
|
|
|
|
equalTo: true
|
|
|
|
}
|
2020-07-02 23:28:22 +00:00
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
) {
|
2020-06-28 01:58:16 +00:00
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
type
|
|
|
|
priority
|
2020-07-02 23:28:22 +00:00
|
|
|
independent
|
2020-06-28 01:58:16 +00:00
|
|
|
hasLogo
|
2021-06-28 00:50:06 +00:00
|
|
|
${campaignsFragment}
|
2021-10-30 20:41:58 +00:00
|
|
|
children: childEntitiesConnection {
|
|
|
|
totalCount
|
|
|
|
}
|
2020-06-28 01:58:16 +00:00
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
2021-06-27 22:05:24 +00:00
|
|
|
${campaignsFragment}
|
2020-06-27 00:57:30 +00:00
|
|
|
parent {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-07-02 02:04:28 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2021-06-27 22:05:24 +00:00
|
|
|
${campaignsFragment}
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
2023-06-18 00:29:10 +00:00
|
|
|
}
|
2023-07-16 23:59:26 +00:00
|
|
|
connection: releasesSummariesConnection(
|
2023-06-18 00:29:10 +00:00
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
orderBy: $orderBy
|
|
|
|
filter: {
|
2023-07-16 23:59:26 +00:00
|
|
|
not: { tags: { overlaps: $exclude } }
|
|
|
|
effectiveDate: { lessThan: $before, greaterThan: $after }
|
|
|
|
showcased: { equalTo: true }
|
|
|
|
or: [
|
|
|
|
{
|
|
|
|
channelSlug: { equalTo: $entitySlug }
|
|
|
|
channelType: { equalTo: $entityType }
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
2023-07-16 23:59:26 +00:00
|
|
|
{
|
|
|
|
networkSlug: { equalTo: $entitySlug }
|
|
|
|
networkType: { equalTo: $entityType }
|
|
|
|
}
|
|
|
|
{
|
|
|
|
parentNetworkSlug: { equalTo: $entitySlug }
|
|
|
|
parentNetworkType: { equalTo: $entityType }
|
|
|
|
}
|
|
|
|
]
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
2023-06-18 00:29:10 +00:00
|
|
|
) {
|
|
|
|
releases: nodes {
|
2023-07-16 23:59:26 +00:00
|
|
|
release {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
2023-06-18 00:29:10 +00:00
|
|
|
}
|
|
|
|
totalCount
|
|
|
|
}
|
2023-06-15 22:47:19 +00:00
|
|
|
${batchFragment}
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
`, {
|
|
|
|
entitySlug,
|
|
|
|
entityType,
|
|
|
|
limit,
|
|
|
|
offset: Math.max(0, (pageNumber - 1)) * limit,
|
|
|
|
after,
|
|
|
|
before,
|
|
|
|
orderBy,
|
2021-01-03 21:53:51 +00:00
|
|
|
exclude: store.state.ui.tagFilter,
|
2021-03-19 02:27:48 +00:00
|
|
|
hasAuth: !!store.state.auth.user,
|
|
|
|
userId: store.state.auth.user?.id,
|
2020-06-27 00:57:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-10 01:17:19 +00:00
|
|
|
if (!entity) {
|
|
|
|
router.replace('/not-found');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-27 00:57:30 +00:00
|
|
|
return {
|
2023-07-16 23:59:26 +00:00
|
|
|
entity: curateEntity(entity, null, connection.releases.map(({ release }) => release), { lastBatch: lastBatch?.id }),
|
2023-06-18 00:29:10 +00:00
|
|
|
totalCount: connection.totalCount,
|
2020-06-27 00:57:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-27 22:15:13 +00:00
|
|
|
async function fetchEntities({ _commit }, { type, entitySlugs }) {
|
2020-06-27 00:57:30 +00:00
|
|
|
const { entities } = await graphql(`
|
|
|
|
query Entities(
|
2020-06-27 22:15:13 +00:00
|
|
|
$entitySlugs: [String!] = []
|
2020-06-27 00:57:30 +00:00
|
|
|
) {
|
|
|
|
entities(
|
2020-09-16 02:55:30 +00:00
|
|
|
orderBy: SLUG_ASC
|
2020-06-27 00:57:30 +00:00
|
|
|
filter: {
|
2020-06-27 22:15:13 +00:00
|
|
|
or: [
|
|
|
|
{
|
|
|
|
type: {
|
2020-07-02 02:04:28 +00:00
|
|
|
equalTo: "network"
|
2020-06-27 22:15:13 +00:00
|
|
|
}
|
2020-08-01 13:11:07 +00:00
|
|
|
childEntitiesConnection: {
|
|
|
|
some: {
|
|
|
|
type: {
|
|
|
|
equalTo: "channel"
|
|
|
|
}
|
2020-09-05 02:08:10 +00:00
|
|
|
independent: {
|
|
|
|
notEqualTo: true
|
|
|
|
}
|
2020-08-01 13:11:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-27 22:15:13 +00:00
|
|
|
}
|
2020-07-02 02:04:28 +00:00
|
|
|
{
|
|
|
|
independent: {
|
|
|
|
equalTo: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
type: {
|
|
|
|
equalTo: "channel"
|
|
|
|
}
|
|
|
|
parentExists: false
|
|
|
|
}
|
2020-06-27 22:15:13 +00:00
|
|
|
{
|
|
|
|
slug: {
|
|
|
|
in: $entitySlugs
|
|
|
|
}
|
|
|
|
}
|
2020-08-01 13:11:07 +00:00
|
|
|
],
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-07-02 23:28:22 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2022-01-29 16:13:09 +00:00
|
|
|
children: childEntitiesConnection {
|
|
|
|
totalCount
|
|
|
|
}
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-27 22:15:13 +00:00
|
|
|
`, {
|
|
|
|
type,
|
|
|
|
entitySlugs,
|
|
|
|
});
|
2020-06-27 00:57:30 +00:00
|
|
|
|
2021-11-20 22:59:15 +00:00
|
|
|
return entities.map((entity) => curateEntity(entity));
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function searchEntities({ _commit }, { query, limit = 20 }) {
|
|
|
|
const { entities } = await graphql(`
|
|
|
|
query SearchEntities(
|
|
|
|
$query: String!
|
2021-09-17 02:28:48 +00:00
|
|
|
$limit: Int = 20,
|
2020-06-27 00:57:30 +00:00
|
|
|
) {
|
|
|
|
entities: searchEntities(
|
2021-09-17 02:28:48 +00:00
|
|
|
search: $query
|
2020-06-27 00:57:30 +00:00
|
|
|
first: $limit
|
|
|
|
) {
|
2021-04-04 19:52:19 +00:00
|
|
|
id
|
2020-06-27 00:57:30 +00:00
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-07-02 23:28:22 +00:00
|
|
|
independent
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-06-27 00:57:30 +00:00
|
|
|
parent {
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
type
|
|
|
|
url
|
2020-06-27 22:44:53 +00:00
|
|
|
hasLogo
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
query,
|
|
|
|
limit,
|
|
|
|
});
|
|
|
|
|
2021-11-20 22:59:15 +00:00
|
|
|
return entities.map((entity) => curateEntity(entity));
|
2020-06-27 00:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fetchEntityBySlugAndType,
|
|
|
|
fetchEntities,
|
|
|
|
searchEntities,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initEntitiesActions;
|