refactor: Simplify unsubscribe functionality in articlePush and categoryPush by enforcing required identifiers in request body
This commit is contained in:
@@ -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