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

View File

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

View File

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

View File

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

View File

@ -1,25 +1,40 @@
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 { 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)) {
return [];
}
const groups: TagGroup[] = [];
const groups: EndpointTagsGroup[] = [];
tags.forEach(({ group, slug }) => {
tags.forEach(({ translations, slug, group }) => {
if (isPayloadType(group)) {
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) {
existingGroup.values.push(slug);
existingGroup.tags.push(endpointTag);
} else {
groups.push({
slug: group.slug,
icon: group.icon ?? "material-symbols:category-outline",
values: [slug],
tags: [endpointTag],
translations: group.translations.map(({ language, name }) => ({
language: isPayloadType(language) ? language.id : language,
name,
})),
});
}
}