diff --git a/src/collections/Pages/endpoints/getBySlugEndpoint.ts b/src/collections/Pages/endpoints/getBySlugEndpoint.ts index 5e8c5ee..297406f 100644 --- a/src/collections/Pages/endpoints/getBySlugEndpoint.ts +++ b/src/collections/Pages/endpoints/getBySlugEndpoint.ts @@ -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", }); diff --git a/src/sdk.ts b/src/sdk.ts index 2c87f96..237018a 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -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[]; diff --git a/src/utils/endpoints.ts b/src/utils/endpoints.ts index 12c2e00..ae6408d 100644 --- a/src/utils/endpoints.ts +++ b/src/utils/endpoints.ts @@ -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[] = []; @@ -68,4 +67,23 @@ export const handleParentPages = ({ } return result; -}; \ No newline at end of file +}; + +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 } : {}), +});