refactor: Simplify unsubscribe functionality in articlePush and categoryPush by enforcing required identifiers in request body

This commit is contained in:
sebseb7
2026-03-26 21:35:26 +01:00
parent 188c883450
commit 47ed2ec231
2 changed files with 10 additions and 22 deletions

View File

@@ -97,14 +97,7 @@ export async function articlePushSubscribe(kArtikel, subscription) {
return { ...data, httpOk: res.ok }; return { ...data, httpOk: res.ok };
} }
/** /** POST /api/article/push/unsubscribe — body is always `{ endpoint, kArtikel }` (scoped row only). */
* 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]
*/
export async function articlePushUnsubscribe(endpoint, kArtikel) { export async function articlePushUnsubscribe(endpoint, kArtikel) {
const parsed = const parsed =
kArtikel != null && kArtikel !== "" kArtikel != null && kArtikel !== ""
@@ -112,10 +105,10 @@ export async function articlePushUnsubscribe(endpoint, kArtikel) {
? kArtikel ? kArtikel
: parseInt(String(kArtikel), 10) : parseInt(String(kArtikel), 10)
: NaN; : NaN;
const body = if (!Number.isFinite(parsed) || parsed <= 0) {
Number.isFinite(parsed) && parsed > 0 return { success: false, httpOk: false, error: "missing_kArtikel" };
? { endpoint, kArtikel: parsed } }
: { endpoint }; const body = { endpoint, kArtikel: parsed };
const res = await fetch("/api/article/push/unsubscribe", { const res = await fetch("/api/article/push/unsubscribe", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },

View File

@@ -45,12 +45,7 @@ export async function categoryPushSubscribe(kKategorie, subscription) {
return { ...data, httpOk: res.ok }; return { ...data, httpOk: res.ok };
} }
/** /** POST /api/category/push/unsubscribe — body is always `{ endpoint, kKategorie }` (scoped row only). */
* 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, kKategorie) { export async function categoryPushUnsubscribe(endpoint, kKategorie) {
const parsed = const parsed =
kKategorie != null && kKategorie !== "" kKategorie != null && kKategorie !== ""
@@ -58,10 +53,10 @@ export async function categoryPushUnsubscribe(endpoint, kKategorie) {
? kKategorie ? kKategorie
: parseInt(String(kKategorie), 10) : parseInt(String(kKategorie), 10)
: NaN; : NaN;
const body = if (!Number.isFinite(parsed) || parsed <= 0) {
Number.isFinite(parsed) && parsed > 0 return { success: false, httpOk: false, error: "missing_kKategorie" };
? { endpoint, kKategorie: parsed } }
: { endpoint }; const body = { endpoint, kKategorie: parsed };
const res = await fetch("/api/category/push/unsubscribe", { const res = await fetch("/api/category/push/unsubscribe", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },