Changed tag type and added webhooks

This commit is contained in:
DrMint 2024-03-09 23:43:12 +01:00
parent a263ed6bcb
commit ae0ccedd43
5 changed files with 33 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import { text } from "payload/dist/fields/validations"; import { text } from "payload/dist/fields/validations";
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { afterOperationWebhook } from "../../hooks/afterOperationWebhook";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { getAllEndpoint } from "./endpoints/getAllEndpoint";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
@ -24,6 +25,9 @@ export const Currencies = buildCollectionConfig({
group: CollectionGroups.Meta, group: CollectionGroups.Meta,
}, },
access: { create: mustBeAdmin, update: mustBeAdmin }, access: { create: mustBeAdmin, update: mustBeAdmin },
hooks: {
afterOperation: [afterOperationWebhook],
},
endpoints: [importFromStrapi, getAllEndpoint], endpoints: [importFromStrapi, getAllEndpoint],
timestamps: false, timestamps: false,
fields: [ fields: [

View File

@ -44,7 +44,7 @@ export const getBySlugEndpoint = createGetByEndpoint(
} }
}) ?? [], }) ?? [],
}; };
} }, 3
); );
export const convertFolderToPreview = ({ export const convertFolderToPreview = ({

View File

@ -2,6 +2,7 @@ import { text } from "payload/dist/fields/validations";
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
import { publicAccess } from "../../accesses/publicAccess"; import { publicAccess } from "../../accesses/publicAccess";
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { afterOperationWebhook } from "../../hooks/afterOperationWebhook";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { getAllEndpoint } from "./endpoints/getAllEndpoint";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
@ -26,6 +27,9 @@ export const Languages = buildCollectionConfig({
pagination: { defaultLimit: 100 }, pagination: { defaultLimit: 100 },
}, },
access: { create: mustBeAdmin, update: mustBeAdmin, read: publicAccess }, access: { create: mustBeAdmin, update: mustBeAdmin, read: publicAccess },
hooks: {
afterOperation: [afterOperationWebhook],
},
timestamps: false, timestamps: false,
endpoints: [importFromStrapi, getAllEndpoint], endpoints: [importFromStrapi, getAllEndpoint],
fields: [ fields: [

View File

@ -225,12 +225,11 @@ export type EndpointTag = {
language: string; language: string;
name: string; name: string;
}[]; }[];
group: string;
}; };
export type EndpointTagsGroup = { export type EndpointTagsGroup = {
slug: string; slug: string;
icon?: string; icon: string;
translations: { translations: {
language: string; language: string;
name: string; name: string;
@ -243,7 +242,7 @@ export type EndpointPagePreview = {
type: PageType; type: PageType;
thumbnail?: PayloadImage; thumbnail?: PayloadImage;
authors: EndpointRecorder[]; authors: EndpointRecorder[];
tagGroups: TagGroup[]; tagGroups: EndpointTagsGroup[];
translations: { translations: {
language: string; language: string;
pretitle?: string; pretitle?: string;
@ -284,7 +283,7 @@ export type EndpointCollectiblePreview = {
subtitle?: string; subtitle?: string;
description?: RichTextContent; description?: RichTextContent;
}[]; }[];
tagGroups: TagGroup[]; tagGroups: EndpointTagsGroup[];
status: "draft" | "published"; status: "draft" | "published";
releaseDate?: string; releaseDate?: string;
languages: string[]; languages: string[];
@ -350,8 +349,6 @@ export type EndpointCollectible = EndpointCollectiblePreview & {
parentPages: ParentPage[]; parentPages: ParentPage[];
}; };
export type TagGroup = { slug: string; icon: string; values: string[] };
export type TableOfContentEntry = { export type TableOfContentEntry = {
prefix: string; prefix: string;
title: string; title: string;

View File

@ -1,25 +1,40 @@
import { Collections } from "../constants"; import { Collections } from "../constants";
import { EndpointRecorder, ParentPage, TagGroup } from "../sdk"; import { EndpointRecorder, EndpointTag, EndpointTagsGroup, ParentPage } from "../sdk";
import { Collectible, Folder, Recorder, Tag } from "../types/collections"; import { Collectible, Folder, Recorder, Tag } from "../types/collections";
import { isPayloadArrayType, isPayloadType, isValidPayloadImage } 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
): EndpointTagsGroup[] => {
if (!isPayloadArrayType(tags)) { if (!isPayloadArrayType(tags)) {
return []; return [];
} }
const groups: TagGroup[] = []; const groups: EndpointTagsGroup[] = [];
tags.forEach(({ group, slug }) => { tags.forEach(({ translations, slug, group }) => {
if (isPayloadType(group)) { if (isPayloadType(group)) {
const existingGroup = groups.find((existingGroup) => existingGroup.slug === group.slug); const existingGroup = groups.find((existingGroup) => existingGroup.slug === group.slug);
const endpointTag: EndpointTag = {
slug,
translations: translations.map(({ language, name }) => ({
language: isPayloadType(language) ? language.id : language,
name,
})),
};
if (existingGroup) { if (existingGroup) {
existingGroup.values.push(slug); existingGroup.tags.push(endpointTag);
} else { } else {
groups.push({ groups.push({
slug: group.slug, slug: group.slug,
icon: group.icon ?? "material-symbols:category-outline", icon: group.icon ?? "material-symbols:category-outline",
values: [slug], tags: [endpointTag],
translations: group.translations.map(({ language, name }) => ({
language: isPayloadType(language) ? language.id : language,
name,
})),
}); });
} }
} }