Populate recorders info in endpoints
This commit is contained in:
parent
7b7507b7f8
commit
a263ed6bcb
|
@ -9,7 +9,7 @@ import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||||
import { EndpointPage, EndpointPagePreview, TableOfContentEntry } from "../../../sdk";
|
import { EndpointPage, EndpointPagePreview, TableOfContentEntry } from "../../../sdk";
|
||||||
import { Page } from "../../../types/collections";
|
import { Page } from "../../../types/collections";
|
||||||
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } from "../../../utils/asserts";
|
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } from "../../../utils/asserts";
|
||||||
import { convertTagsToGroups, handleParentPages } from "../../../utils/endpoints";
|
import { convertTagsToGroups, handleParentPages, handleRecorder } from "../../../utils/endpoints";
|
||||||
|
|
||||||
export const getBySlugEndpoint = createGetByEndpoint(
|
export const getBySlugEndpoint = createGetByEndpoint(
|
||||||
Collections.Pages,
|
Collections.Pages,
|
||||||
|
@ -41,9 +41,9 @@ export const getBySlugEndpoint = createGetByEndpoint(
|
||||||
...(summary ? { summary } : {}),
|
...(summary ? { summary } : {}),
|
||||||
content: handleContent(content),
|
content: handleContent(content),
|
||||||
toc: handleToc(content),
|
toc: handleToc(content),
|
||||||
translators: isPayloadArrayType(translators) ? translators.map(({ id }) => id) : [],
|
translators: isPayloadArrayType(translators) ? translators.map(handleRecorder) : [],
|
||||||
transcribers: isPayloadArrayType(transcribers) ? transcribers.map(({ id }) => id) : [],
|
transcribers: isPayloadArrayType(transcribers) ? transcribers.map(handleRecorder) : [],
|
||||||
proofreaders: isPayloadArrayType(proofreaders) ? proofreaders.map(({ id }) => id) : [],
|
proofreaders: isPayloadArrayType(proofreaders) ? proofreaders.map(handleRecorder) : [],
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
parentPages: handleParentPages({ collectibles, folders }),
|
parentPages: handleParentPages({ collectibles, folders }),
|
||||||
|
@ -88,8 +88,6 @@ const handleToc = (content: RichTextContent, parentPrefix = ""): TableOfContentE
|
||||||
children: handleToc(fields.content, `${index + 1}.`),
|
children: handleToc(fields.content, `${index + 1}.`),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const convertPageToPreview = ({
|
export const convertPageToPreview = ({
|
||||||
authors,
|
authors,
|
||||||
slug,
|
slug,
|
||||||
|
@ -109,6 +107,6 @@ export const convertPageToPreview = ({
|
||||||
title,
|
title,
|
||||||
...(subtitle ? { subtitle } : {}),
|
...(subtitle ? { subtitle } : {}),
|
||||||
})),
|
})),
|
||||||
authors: isPayloadArrayType(authors) ? authors.map(({ id }) => id) : [],
|
authors: isPayloadArrayType(authors) ? authors.map(handleRecorder) : [],
|
||||||
status: _status === "published" ? "published" : "draft",
|
status: _status === "published" ? "published" : "draft",
|
||||||
});
|
});
|
||||||
|
|
|
@ -242,7 +242,7 @@ export type EndpointPagePreview = {
|
||||||
slug: string;
|
slug: string;
|
||||||
type: PageType;
|
type: PageType;
|
||||||
thumbnail?: PayloadImage;
|
thumbnail?: PayloadImage;
|
||||||
authors: string[];
|
authors: EndpointRecorder[];
|
||||||
tagGroups: TagGroup[];
|
tagGroups: TagGroup[];
|
||||||
translations: {
|
translations: {
|
||||||
language: string;
|
language: string;
|
||||||
|
@ -259,9 +259,9 @@ export type EndpointPage = EndpointPagePreview & {
|
||||||
sourceLanguage: string;
|
sourceLanguage: string;
|
||||||
summary?: RichTextContent;
|
summary?: RichTextContent;
|
||||||
content: RichTextContent;
|
content: RichTextContent;
|
||||||
transcribers: string[];
|
transcribers: EndpointRecorder[];
|
||||||
translators: string[];
|
translators: EndpointRecorder[];
|
||||||
proofreaders: string[];
|
proofreaders: EndpointRecorder[];
|
||||||
toc: TableOfContentEntry[];
|
toc: TableOfContentEntry[];
|
||||||
})[];
|
})[];
|
||||||
parentPages: ParentPage[];
|
parentPages: ParentPage[];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Collections } from "../constants";
|
import { Collections } from "../constants";
|
||||||
import { ParentPage, TagGroup } from "../sdk";
|
import { EndpointRecorder, ParentPage, TagGroup } from "../sdk";
|
||||||
import { Collectible, Folder, Tag } from "../types/collections";
|
import { Collectible, Folder, Recorder, Tag } from "../types/collections";
|
||||||
import { isPayloadArrayType, isPayloadType } from "./asserts";
|
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } from "./asserts";
|
||||||
|
|
||||||
export const convertTagsToGroups = (tags: (string | Tag)[] | null | undefined): TagGroup[] => {
|
export const convertTagsToGroups = (tags: (string | Tag)[] | null | undefined): TagGroup[] => {
|
||||||
if (!isPayloadArrayType(tags)) {
|
if (!isPayloadArrayType(tags)) {
|
||||||
|
@ -28,13 +28,12 @@ export const convertTagsToGroups = (tags: (string | Tag)[] | null | undefined):
|
||||||
return groups;
|
return groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const handleParentPages = ({
|
export const handleParentPages = ({
|
||||||
collectibles,
|
collectibles,
|
||||||
folders,
|
folders,
|
||||||
}: {
|
}: {
|
||||||
collectibles?: (string | Collectible)[] | null | undefined;
|
collectibles?: (string | Collectible)[] | null | undefined;
|
||||||
folders?: (string | Folder)[] | null | undefined
|
folders?: (string | Folder)[] | null | undefined;
|
||||||
}): ParentPage[] => {
|
}): ParentPage[] => {
|
||||||
const result: ParentPage[] = [];
|
const result: ParentPage[] = [];
|
||||||
|
|
||||||
|
@ -68,4 +67,23 @@ export const handleParentPages = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const handleRecorder = ({
|
||||||
|
id,
|
||||||
|
biographies,
|
||||||
|
languages,
|
||||||
|
username,
|
||||||
|
avatar,
|
||||||
|
anonymize,
|
||||||
|
}: Recorder): EndpointRecorder => ({
|
||||||
|
id,
|
||||||
|
biographies:
|
||||||
|
biographies?.map(({ biography, language }) => ({
|
||||||
|
biography,
|
||||||
|
language: isPayloadType(language) ? language.id : language,
|
||||||
|
})) ?? [],
|
||||||
|
languages: languages?.map((language) => (isPayloadType(language) ? language.id : language)) ?? [],
|
||||||
|
username: anonymize ? `Recorder#${id.substring(0, 5)}` : username,
|
||||||
|
...(isValidPayloadImage(avatar) ? { avatar } : {}),
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue