feat: Implement push subscription event handling in AddToCartButton and ProductFilters components; enhance article and category unsubscribe functionality with optional identifiers
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
|
||||
export {
|
||||
PUSH_SUBSCRIPTIONS_CHANGED_EVENT,
|
||||
emitPushSubscriptionsChanged,
|
||||
fetchPushConfiguration,
|
||||
registerPushServiceWorker,
|
||||
ensurePushSubscription,
|
||||
@@ -44,13 +46,26 @@ export async function categoryPushSubscribe(kKategorie, subscription) {
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/category/push/unsubscribe — same contract as article: optional `kKategorie` for scoped delete.
|
||||
*
|
||||
* @param {string} endpoint
|
||||
* @param {number|string} [kKategorie]
|
||||
*/
|
||||
export async function categoryPushUnsubscribe(endpoint) {
|
||||
export async function categoryPushUnsubscribe(endpoint, kKategorie) {
|
||||
const parsed =
|
||||
kKategorie != null && kKategorie !== ""
|
||||
? typeof kKategorie === "number"
|
||||
? kKategorie
|
||||
: parseInt(String(kKategorie), 10)
|
||||
: NaN;
|
||||
const body =
|
||||
Number.isFinite(parsed) && parsed > 0
|
||||
? { endpoint, kKategorie: parsed }
|
||||
: { endpoint };
|
||||
const res = await fetch("/api/category/push/unsubscribe", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ endpoint }),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ...data, httpOk: res.ok };
|
||||
|
||||
Reference in New Issue
Block a user