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 { Page } from "../../../types/collections";
|
||||
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } from "../../../utils/asserts";
|
||||
import { convertTagsToGroups, handleParentPages } from "../../../utils/endpoints";
|
||||
import { convertTagsToGroups, handleParentPages, handleRecorder } from "../../../utils/endpoints";
|
||||
|
||||
export const getBySlugEndpoint = createGetByEndpoint(
|
||||
Collections.Pages,
|
||||
|
@ -41,9 +41,9 @@ export const getBySlugEndpoint = createGetByEndpoint(
|
|||
...(summary ? { summary } : {}),
|
||||
content: handleContent(content),
|
||||
toc: handleToc(content),
|
||||
translators: isPayloadArrayType(translators) ? translators.map(({ id }) => id) : [],
|
||||
transcribers: isPayloadArrayType(transcribers) ? transcribers.map(({ id }) => id) : [],
|
||||
proofreaders: isPayloadArrayType(proofreaders) ? proofreaders.map(({ id }) => id) : [],
|
||||
translators: isPayloadArrayType(translators) ? translators.map(handleRecorder) : [],
|
||||
transcribers: isPayloadArrayType(transcribers) ? transcribers.map(handleRecorder) : [],
|
||||
proofreaders: isPayloadArrayType(proofreaders) ? proofreaders.map(handleRecorder) : [],
|
||||
})
|
||||
),
|
||||
parentPages: handleParentPages({ collectibles, folders }),
|
||||
|
@ -88,8 +88,6 @@ const handleToc = (content: RichTextContent, parentPrefix = ""): TableOfContentE
|
|||
children: handleToc(fields.content, `${index + 1}.`),
|
||||
}));
|
||||
|
||||
|
||||
|
||||
export const convertPageToPreview = ({
|
||||
authors,
|
||||
slug,
|
||||
|
@ -109,6 +107,6 @@ export const convertPageToPreview = ({
|
|||
title,
|
||||
...(subtitle ? { subtitle } : {}),
|
||||
})),
|
||||
authors: isPayloadArrayType(authors) ? authors.map(({ id }) => id) : [],
|
||||
authors: isPayloadArrayType(authors) ? authors.map(handleRecorder) : [],
|
||||
status: _status === "published" ? "published" : "draft",
|
||||
});
|
||||
|
|
|
@ -242,7 +242,7 @@ export type EndpointPagePreview = {
|
|||
slug: string;
|
||||
type: PageType;
|
||||
thumbnail?: PayloadImage;
|
||||
authors: string[];
|
||||
authors: EndpointRecorder[];
|
||||
tagGroups: TagGroup[];
|
||||
translations: {
|
||||
language: string;
|
||||
|
@ -259,9 +259,9 @@ export type EndpointPage = EndpointPagePreview & {
|
|||
sourceLanguage: string;
|
||||
summary?: RichTextContent;
|
||||
content: RichTextContent;
|
||||
transcribers: string[];
|
||||
translators: string[];
|
||||
proofreaders: string[];
|
||||
transcribers: EndpointRecorder[];
|
||||
translators: EndpointRecorder[];
|
||||
proofreaders: EndpointRecorder[];
|
||||
toc: TableOfContentEntry[];
|
||||
})[];
|
||||
parentPages: ParentPage[];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Collections } from "../constants";
|
||||
import { ParentPage, TagGroup } from "../sdk";
|
||||
import { Collectible, Folder, Tag } from "../types/collections";
|
||||
import { isPayloadArrayType, isPayloadType } from "./asserts";
|
||||
import { EndpointRecorder, ParentPage, TagGroup } from "../sdk";
|
||||
import { Collectible, Folder, Recorder, Tag } from "../types/collections";
|
||||
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } from "./asserts";
|
||||
|
||||
export const convertTagsToGroups = (tags: (string | Tag)[] | null | undefined): TagGroup[] => {
|
||||
if (!isPayloadArrayType(tags)) {
|
||||
|
@ -28,13 +28,12 @@ export const convertTagsToGroups = (tags: (string | Tag)[] | null | undefined):
|
|||
return groups;
|
||||
};
|
||||
|
||||
|
||||
export const handleParentPages = ({
|
||||
collectibles,
|
||||
folders,
|
||||
}: {
|
||||
collectibles?: (string | Collectible)[] | null | undefined;
|
||||
folders?: (string | Folder)[] | null | undefined
|
||||
folders?: (string | Folder)[] | null | undefined;
|
||||
}): ParentPage[] => {
|
||||
const result: ParentPage[] = [];
|
||||
|
||||
|
@ -69,3 +68,22 @@ export const handleParentPages = ({
|
|||
|
||||
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