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 { 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" });
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
};
|
Loading…
Reference in New Issue