Added webhook for currencies and language updates
This commit is contained in:
parent
b06c624d41
commit
a847b73363
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
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");
|
||||
|
||||
|
@ -15,6 +15,14 @@ switch (collectionSlug) {
|
|||
await refreshWordings();
|
||||
break;
|
||||
|
||||
case Collections.Currencies:
|
||||
await refreshCurrencies();
|
||||
break;
|
||||
|
||||
case Collections.Languages:
|
||||
await refreshLocales()
|
||||
break;
|
||||
|
||||
default:
|
||||
return new Response(null, { status: 400, statusText: "Bad Request" });
|
||||
}
|
||||
|
|
|
@ -18,7 +18,10 @@ export const refreshWordings = async () => {
|
|||
cache.wordings = await payload.getWordings();
|
||||
};
|
||||
|
||||
setInterval(async () => {
|
||||
console.log("Refreshing cached Payload data");
|
||||
cache = await fetchNewData();
|
||||
}, 1000_000);
|
||||
export const refreshCurrencies = async () => {
|
||||
cache.currencies = (await payload.getCurrencies()).map(({ id }) => id)
|
||||
};
|
||||
|
||||
export const refreshLocales = async () => {
|
||||
cache.locales = await payload.getLanguages();
|
||||
};
|
Loading…
Reference in New Issue