refactor: Simplify unsubscribe functionality in articlePush and categoryPush by enforcing required identifiers in request body
This commit is contained in:
@@ -97,14 +97,7 @@ export async function articlePushSubscribe(kArtikel, subscription) {
|
||||
return { ...data, httpOk: res.ok };
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/article/push/unsubscribe — body: `{ endpoint }` or `{ subscription: { endpoint } }` (pickup-style).
|
||||
* Optional `kArtikel` (number or numeric string): if it parses to a finite id > 0, only that row is removed.
|
||||
* Otherwise legacy: server clears all push rows for that endpoint (article + category + pickup).
|
||||
*
|
||||
* @param {string} endpoint
|
||||
* @param {number|string} [kArtikel]
|
||||
*/
|
||||
/** POST /api/article/push/unsubscribe — body is always `{ endpoint, kArtikel }` (scoped row only). */
|
||||
export async function articlePushUnsubscribe(endpoint, kArtikel) {
|
||||
const parsed =
|
||||
kArtikel != null && kArtikel !== ""
|
||||
@@ -112,10 +105,10 @@ export async function articlePushUnsubscribe(endpoint, kArtikel) {
|
||||
? kArtikel
|
||||
: parseInt(String(kArtikel), 10)
|
||||
: NaN;
|
||||
const body =
|
||||
Number.isFinite(parsed) && parsed > 0
|
||||
? { endpoint, kArtikel: parsed }
|
||||
: { endpoint };
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return { success: false, httpOk: false, error: "missing_kArtikel" };
|
||||
}
|
||||
const body = { endpoint, kArtikel: parsed };
|
||||
const res = await fetch("/api/article/push/unsubscribe", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
||||
@@ -45,12 +45,7 @@ export async function categoryPushSubscribe(kKategorie, subscription) {
|
||||
return { ...data, httpOk: res.ok };
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/category/push/unsubscribe — same contract as article: optional `kKategorie` for scoped delete.
|
||||
*
|
||||
* @param {string} endpoint
|
||||
* @param {number|string} [kKategorie]
|
||||
*/
|
||||
/** POST /api/category/push/unsubscribe — body is always `{ endpoint, kKategorie }` (scoped row only). */
|
||||
export async function categoryPushUnsubscribe(endpoint, kKategorie) {
|
||||
const parsed =
|
||||
kKategorie != null && kKategorie !== ""
|
||||
@@ -58,10 +53,10 @@ export async function categoryPushUnsubscribe(endpoint, kKategorie) {
|
||||
? kKategorie
|
||||
: parseInt(String(kKategorie), 10)
|
||||
: NaN;
|
||||
const body =
|
||||
Number.isFinite(parsed) && parsed > 0
|
||||
? { endpoint, kKategorie: parsed }
|
||||
: { endpoint };
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return { success: false, httpOk: false, error: "missing_kKategorie" };
|
||||
}
|
||||
const body = { endpoint, kKategorie: parsed };
|
||||
const res = await fetch("/api/category/push/unsubscribe", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
||||
Reference in New Issue
Block a user