Adapted Recorders' collection
This commit is contained in:
parent
46613c8500
commit
18781e701c
|
@ -19,7 +19,7 @@ import {
|
||||||
import { convertAudioToEndpointAudio } from "../../Audios/endpoints/getByID";
|
import { convertAudioToEndpointAudio } from "../../Audios/endpoints/getByID";
|
||||||
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
||||||
import { convertPageToEndpointPage } from "../../Pages/endpoints/getBySlugEndpoint";
|
import { convertPageToEndpointPage } from "../../Pages/endpoints/getBySlugEndpoint";
|
||||||
import { convertRecorderToEndpointRecorder } from "../../Recorders/endpoints/getByUsername";
|
import { convertRecorderToEndpointRecorder } from "../../Recorders/endpoints/getByID";
|
||||||
import { convertVideoToEndpointVideo } from "../../Videos/endpoints/getByID";
|
import { convertVideoToEndpointVideo } from "../../Videos/endpoints/getByID";
|
||||||
|
|
||||||
export const getBySlugEndpoint = createGetByEndpoint({
|
export const getBySlugEndpoint = createGetByEndpoint({
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
convertSourceToEndpointSource,
|
convertSourceToEndpointSource,
|
||||||
} from "../../../utils/endpoints";
|
} from "../../../utils/endpoints";
|
||||||
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
||||||
import { convertRecorderToEndpointRecorder } from "../../Recorders/endpoints/getByUsername";
|
import { convertRecorderToEndpointRecorder } from "../../Recorders/endpoints/getByID";
|
||||||
|
|
||||||
export const getBySlugEndpoint = createGetByEndpoint({
|
export const getBySlugEndpoint = createGetByEndpoint({
|
||||||
collection: Collections.Pages,
|
collection: Collections.Pages,
|
||||||
|
|
|
@ -5,9 +5,10 @@ import { QuickFilters } from "../../components/QuickFilters";
|
||||||
import { CollectionGroups, Collections, RecordersRoles } from "../../constants";
|
import { CollectionGroups, Collections, RecordersRoles } from "../../constants";
|
||||||
import { imageField } from "../../fields/imageField/imageField";
|
import { imageField } from "../../fields/imageField/imageField";
|
||||||
import { rowField } from "../../fields/rowField/rowField";
|
import { rowField } from "../../fields/rowField/rowField";
|
||||||
|
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||||
import { getAllEndpoint } from "./endpoints/getAllEndpoint";
|
import { createEditor } from "../../utils/editor";
|
||||||
import { getByUsernameEndpoint } from "./endpoints/getByUsername";
|
import { getByID } from "./endpoints/getByID";
|
||||||
import { importFromStrapi } from "./endpoints/importFromStrapi";
|
import { importFromStrapi } from "./endpoints/importFromStrapi";
|
||||||
import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole";
|
import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole";
|
||||||
|
|
||||||
|
@ -15,8 +16,8 @@ const fields = {
|
||||||
username: "username",
|
username: "username",
|
||||||
anonymize: "anonymize",
|
anonymize: "anonymize",
|
||||||
languages: "languages",
|
languages: "languages",
|
||||||
biographies: "biographies",
|
translations: "translations",
|
||||||
biography: "biography",
|
translationsBiography: "biography",
|
||||||
avatar: "avatar",
|
avatar: "avatar",
|
||||||
role: "role",
|
role: "role",
|
||||||
} as const satisfies Record<string, string>;
|
} as const satisfies Record<string, string>;
|
||||||
|
@ -37,7 +38,7 @@ export const Recorders = buildCollectionConfig({
|
||||||
fields.avatar,
|
fields.avatar,
|
||||||
fields.username,
|
fields.username,
|
||||||
fields.anonymize,
|
fields.anonymize,
|
||||||
fields.biographies,
|
fields.translations,
|
||||||
fields.languages,
|
fields.languages,
|
||||||
fields.role,
|
fields.role,
|
||||||
],
|
],
|
||||||
|
@ -79,7 +80,7 @@ export const Recorders = buildCollectionConfig({
|
||||||
hooks: {
|
hooks: {
|
||||||
beforeLogin: [beforeLoginMustHaveAtLeastOneRole],
|
beforeLogin: [beforeLoginMustHaveAtLeastOneRole],
|
||||||
},
|
},
|
||||||
endpoints: [importFromStrapi, getAllEndpoint, getByUsernameEndpoint],
|
endpoints: [importFromStrapi, getByID],
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
fields: [
|
fields: [
|
||||||
rowField([
|
rowField([
|
||||||
|
@ -105,6 +106,17 @@ export const Recorders = buildCollectionConfig({
|
||||||
description: "List of language(s) that this recorder is familiar with",
|
description: "List of language(s) that this recorder is familiar with",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
translatedFields({
|
||||||
|
name: fields.translations,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: fields.translationsBiography,
|
||||||
|
type: "richText",
|
||||||
|
editor: createEditor({ inlines: true, lists: true, links: true }),
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
{
|
{
|
||||||
name: fields.role,
|
name: fields.role,
|
||||||
type: "select",
|
type: "select",
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import payload from "payload";
|
|
||||||
import { Collections } from "../../../constants";
|
|
||||||
import { EndpointRecorder } from "../../../sdk";
|
|
||||||
import { CollectionEndpoint } from "../../../types/payload";
|
|
||||||
import { isPayloadArrayType, isValidPayloadImage } from "../../../utils/asserts";
|
|
||||||
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
|
||||||
|
|
||||||
export const getAllEndpoint: CollectionEndpoint = {
|
|
||||||
method: "get",
|
|
||||||
path: "/all",
|
|
||||||
handler: async (req, res) => {
|
|
||||||
if (!req.user) {
|
|
||||||
return res.status(403).send({
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "You are not allowed to perform this action.",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const recorders = (
|
|
||||||
await payload.find({
|
|
||||||
collection: Collections.Recorders,
|
|
||||||
sort: "id",
|
|
||||||
pagination: false,
|
|
||||||
})
|
|
||||||
).docs;
|
|
||||||
|
|
||||||
const result: EndpointRecorder[] = recorders.map(
|
|
||||||
({ anonymize, id, username, avatar, languages }) => ({
|
|
||||||
id,
|
|
||||||
username: anonymize ? `Recorder#${id.substring(0, 5)}` : username,
|
|
||||||
...(isValidPayloadImage(avatar) ? { avatar: convertImageToEndpointImage(avatar) } : {}),
|
|
||||||
languages: isPayloadArrayType(languages) ? languages.map(({ id }) => id) : [],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
res.status(200).json(result);
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
import payload from "payload";
|
||||||
|
import { Collections } from "../../../constants";
|
||||||
|
import { EndpointRecorder } from "../../../sdk";
|
||||||
|
import { Recorder } from "../../../types/collections";
|
||||||
|
import { CollectionEndpoint } from "../../../types/payload";
|
||||||
|
import { isPayloadType, isValidPayloadImage } from "../../../utils/asserts";
|
||||||
|
import { convertRTCToEndpointRTC } from "../../../utils/endpoints";
|
||||||
|
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
||||||
|
|
||||||
|
export const getByID: CollectionEndpoint = {
|
||||||
|
method: "get",
|
||||||
|
path: "/id/:id",
|
||||||
|
handler: async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(403).send({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: "You are not allowed to perform this action.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.params.id) {
|
||||||
|
return res.status(400).send({ errors: [{ message: "Missing 'id' query params" }] });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await payload.findByID({
|
||||||
|
collection: Collections.Recorders,
|
||||||
|
id: req.params.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json(convertRecorderToEndpointRecorder(result));
|
||||||
|
} catch {
|
||||||
|
return res.sendStatus(404);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const convertRecorderToEndpointRecorder = ({
|
||||||
|
id,
|
||||||
|
languages,
|
||||||
|
username,
|
||||||
|
avatar,
|
||||||
|
anonymize,
|
||||||
|
translations,
|
||||||
|
}: Recorder): EndpointRecorder => ({
|
||||||
|
id,
|
||||||
|
languages: languages?.map((language) => (isPayloadType(language) ? language.id : language)) ?? [],
|
||||||
|
username: anonymize ? `Recorder#${id.substring(0, 5)}` : username,
|
||||||
|
...(isValidPayloadImage(avatar) ? { avatar: convertImageToEndpointImage(avatar) } : {}),
|
||||||
|
translations:
|
||||||
|
translations?.map(({ language, biography }) => ({
|
||||||
|
language: isPayloadType(language) ? language.id : language,
|
||||||
|
biography: convertRTCToEndpointRTC(biography),
|
||||||
|
})) ?? [],
|
||||||
|
});
|
|
@ -1,25 +0,0 @@
|
||||||
import { Collections } from "../../../constants";
|
|
||||||
import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
|
||||||
import { EndpointRecorder } from "../../../sdk";
|
|
||||||
import { Recorder } from "../../../types/collections";
|
|
||||||
import { isPayloadType, isValidPayloadImage } from "../../../utils/asserts";
|
|
||||||
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
|
||||||
|
|
||||||
export const getByUsernameEndpoint = createGetByEndpoint({
|
|
||||||
collection: Collections.Recorders,
|
|
||||||
attribute: "username",
|
|
||||||
handler: (recorder) => convertRecorderToEndpointRecorder(recorder),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const convertRecorderToEndpointRecorder = ({
|
|
||||||
id,
|
|
||||||
languages,
|
|
||||||
username,
|
|
||||||
avatar,
|
|
||||||
anonymize,
|
|
||||||
}: Recorder): EndpointRecorder => ({
|
|
||||||
id,
|
|
||||||
languages: languages?.map((language) => (isPayloadType(language) ? language.id : language)) ?? [],
|
|
||||||
username: anonymize ? `Recorder#${id.substring(0, 5)}` : username,
|
|
||||||
...(isValidPayloadImage(avatar) ? { avatar: convertImageToEndpointImage(avatar) } : {}),
|
|
||||||
});
|
|
|
@ -161,6 +161,10 @@ export type EndpointRecorder = {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
avatar?: EndpointImage;
|
avatar?: EndpointImage;
|
||||||
|
translations: {
|
||||||
|
language: string;
|
||||||
|
biography: RichTextContent;
|
||||||
|
}[];
|
||||||
languages: string[];
|
languages: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -544,8 +548,6 @@ export const payload = {
|
||||||
await (await request(payloadApiUrl(Collections.Currencies, `all`))).json(),
|
await (await request(payloadApiUrl(Collections.Currencies, `all`))).json(),
|
||||||
getWordings: async (): Promise<EndpointWording[]> =>
|
getWordings: async (): Promise<EndpointWording[]> =>
|
||||||
await (await request(payloadApiUrl(Collections.Wordings, `all`))).json(),
|
await (await request(payloadApiUrl(Collections.Wordings, `all`))).json(),
|
||||||
getRecorders: async (): Promise<EndpointRecorder[]> =>
|
|
||||||
await (await request(payloadApiUrl(Collections.Recorders, `all`))).json(),
|
|
||||||
getPage: async (slug: string): Promise<EndpointPage> =>
|
getPage: async (slug: string): Promise<EndpointPage> =>
|
||||||
await (await request(payloadApiUrl(Collections.Pages, `slug/${slug}`))).json(),
|
await (await request(payloadApiUrl(Collections.Pages, `slug/${slug}`))).json(),
|
||||||
getCollectible: async (slug: string): Promise<EndpointCollectible> =>
|
getCollectible: async (slug: string): Promise<EndpointCollectible> =>
|
||||||
|
@ -578,4 +580,6 @@ export const payload = {
|
||||||
await (await request(payloadApiUrl(Collections.Audios, `id/${id}`))).json(),
|
await (await request(payloadApiUrl(Collections.Audios, `id/${id}`))).json(),
|
||||||
getVideoByID: async (id: string): Promise<EndpointVideo> =>
|
getVideoByID: async (id: string): Promise<EndpointVideo> =>
|
||||||
await (await request(payloadApiUrl(Collections.Videos, `id/${id}`))).json(),
|
await (await request(payloadApiUrl(Collections.Videos, `id/${id}`))).json(),
|
||||||
|
getRecorderByID: async (id: string): Promise<EndpointRecorder> =>
|
||||||
|
await (await request(payloadApiUrl(Collections.Recorders, `id/${id}`))).json(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -262,6 +262,27 @@ export interface Recorder {
|
||||||
username: string;
|
username: string;
|
||||||
avatar?: string | Image | null;
|
avatar?: string | Image | null;
|
||||||
languages?: (string | Language)[] | null;
|
languages?: (string | Language)[] | null;
|
||||||
|
translations?:
|
||||||
|
| {
|
||||||
|
language: string | Language;
|
||||||
|
biography: {
|
||||||
|
root: {
|
||||||
|
type: string;
|
||||||
|
children: {
|
||||||
|
type: string;
|
||||||
|
version: number;
|
||||||
|
[k: string]: unknown;
|
||||||
|
}[];
|
||||||
|
direction: ("ltr" | "rtl") | null;
|
||||||
|
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
|
||||||
|
indent: number;
|
||||||
|
version: number;
|
||||||
|
};
|
||||||
|
[k: string]: unknown;
|
||||||
|
};
|
||||||
|
id?: string | null;
|
||||||
|
}[]
|
||||||
|
| null;
|
||||||
role?: ("Admin" | "Recorder" | "Api")[] | null;
|
role?: ("Admin" | "Recorder" | "Api")[] | null;
|
||||||
anonymize: boolean;
|
anonymize: boolean;
|
||||||
email: string;
|
email: string;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { convertCollectibleToEndpointCollectible } from "../collections/Collecti
|
||||||
import { convertFolderToEndpointFolder } from "../collections/Folders/endpoints/getBySlugEndpoint";
|
import { convertFolderToEndpointFolder } from "../collections/Folders/endpoints/getBySlugEndpoint";
|
||||||
import { convertImageToEndpointImage } from "../collections/Images/endpoints/getByID";
|
import { convertImageToEndpointImage } from "../collections/Images/endpoints/getByID";
|
||||||
import { convertPageToEndpointPage } from "../collections/Pages/endpoints/getBySlugEndpoint";
|
import { convertPageToEndpointPage } from "../collections/Pages/endpoints/getBySlugEndpoint";
|
||||||
import { convertRecorderToEndpointRecorder } from "../collections/Recorders/endpoints/getByUsername";
|
import { convertRecorderToEndpointRecorder } from "../collections/Recorders/endpoints/getByID";
|
||||||
import { convertVideoToEndpointVideo } from "../collections/Videos/endpoints/getByID";
|
import { convertVideoToEndpointVideo } from "../collections/Videos/endpoints/getByID";
|
||||||
import {
|
import {
|
||||||
AttributeTypes,
|
AttributeTypes,
|
||||||
|
|
Loading…
Reference in New Issue