Updated website config endpoint
This commit is contained in:
parent
39e2642c55
commit
8e36642715
|
@ -3,6 +3,7 @@ import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
|
||||||
import { CollectionGroups, Collections } from "../../constants";
|
import { CollectionGroups, Collections } 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 { afterChangeWebhook } from "../../hooks/afterChangeWebhook";
|
||||||
import { getConfigEndpoint } from "./endpoints/getConfigEndpoint";
|
import { getConfigEndpoint } from "./endpoints/getConfigEndpoint";
|
||||||
|
|
||||||
const fields = {
|
const fields = {
|
||||||
|
@ -27,6 +28,9 @@ export const WebsiteConfig: GlobalConfig = {
|
||||||
},
|
},
|
||||||
access: { update: mustBeAdmin, read: mustBeAdmin },
|
access: { update: mustBeAdmin, read: mustBeAdmin },
|
||||||
endpoints: [getConfigEndpoint],
|
endpoints: [getConfigEndpoint],
|
||||||
|
hooks: {
|
||||||
|
afterChange: [afterChangeWebhook],
|
||||||
|
},
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: fields.homeFolders,
|
name: fields.homeFolders,
|
||||||
|
|
|
@ -23,6 +23,24 @@ export const getConfigEndpoint: CollectionEndpoint = {
|
||||||
slug: Collections.WebsiteConfig,
|
slug: Collections.WebsiteConfig,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const events = (
|
||||||
|
await payload.find({
|
||||||
|
collection: Collections.ChronologyEvents,
|
||||||
|
pagination: false,
|
||||||
|
draft: false,
|
||||||
|
where: {
|
||||||
|
_status: {
|
||||||
|
equals: "published",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).docs;
|
||||||
|
|
||||||
|
let eventCount = 0;
|
||||||
|
events.forEach(({ events }) => {
|
||||||
|
eventCount += events.length;
|
||||||
|
});
|
||||||
|
|
||||||
const endpointWebsiteConfig: EndpointWebsiteConfig = {
|
const endpointWebsiteConfig: EndpointWebsiteConfig = {
|
||||||
homeFolders:
|
homeFolders:
|
||||||
homeFolders?.flatMap(({ folder, darkThumbnail, lightThumbnail }) => {
|
homeFolders?.flatMap(({ folder, darkThumbnail, lightThumbnail }) => {
|
||||||
|
@ -35,6 +53,7 @@ export const getConfigEndpoint: CollectionEndpoint = {
|
||||||
}) ?? [],
|
}) ?? [],
|
||||||
timeline: {
|
timeline: {
|
||||||
breaks: timeline?.breaks ?? [],
|
breaks: timeline?.breaks ?? [],
|
||||||
|
eventCount,
|
||||||
eras:
|
eras:
|
||||||
timeline?.eras?.flatMap(({ endingYear, name, startingYear }) => {
|
timeline?.eras?.flatMap(({ endingYear, name, startingYear }) => {
|
||||||
if (!isPayloadType(name)) return [];
|
if (!isPayloadType(name)) return [];
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { AfterChangeHook } from "payload/dist/globals/config/types";
|
||||||
|
|
||||||
|
export const afterChangeWebhook: AfterChangeHook = async ({ doc, global }) => {
|
||||||
|
const url = `${process.env.WEB_HOOK_URI}/collection-operation`;
|
||||||
|
await fetch(url, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${process.env.WEB_HOOK_TOKEN}`,
|
||||||
|
Collection: global.slug,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return doc;
|
||||||
|
};
|
|
@ -136,6 +136,7 @@ export type EndpointWebsiteConfig = {
|
||||||
})[];
|
})[];
|
||||||
timeline: {
|
timeline: {
|
||||||
breaks: number[];
|
breaks: number[];
|
||||||
|
eventCount: number;
|
||||||
eras: {
|
eras: {
|
||||||
startingYear: number;
|
startingYear: number;
|
||||||
endingYear: number;
|
endingYear: number;
|
||||||
|
|
Loading…
Reference in New Issue