Added webhook for currencies and language updates

This commit is contained in:
DrMint 2024-03-09 12:11:11 +01:00
parent b06c624d41
commit a847b73363
2 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,6 @@
--- ---
import { Collections } from "src/shared/payload/payload-sdk"; import { Collections } from "src/shared/payload/payload-sdk";
import { refreshWordings } from "src/utils/cachedPayload"; import { refreshCurrencies, refreshLocales, refreshWordings } from "src/utils/cachedPayload";
const auth = Astro.request.headers.get("Authorization"); const auth = Astro.request.headers.get("Authorization");
@ -15,6 +15,14 @@ switch (collectionSlug) {
await refreshWordings(); await refreshWordings();
break; break;
case Collections.Currencies:
await refreshCurrencies();
break;
case Collections.Languages:
await refreshLocales()
break;
default: default:
return new Response(null, { status: 400, statusText: "Bad Request" }); return new Response(null, { status: 400, statusText: "Bad Request" });
} }

View File

@ -18,7 +18,10 @@ export const refreshWordings = async () => {
cache.wordings = await payload.getWordings(); cache.wordings = await payload.getWordings();
}; };
setInterval(async () => { export const refreshCurrencies = async () => {
console.log("Refreshing cached Payload data"); cache.currencies = (await payload.getCurrencies()).map(({ id }) => id)
cache = await fetchNewData(); };
}, 1000_000);
export const refreshLocales = async () => {
cache.locales = await payload.getLanguages();
};