From ed29d11b89bd1e1602dcaea126942540ad0e7dc2 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Fri, 14 Jan 2022 02:16:38 +0200 Subject: [PATCH] fix APIPaths --- src/api/backend.ts | 12 ++++++------ src/api/signupApi.ts | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api/backend.ts b/src/api/backend.ts index ad70c0e..96d94a2 100644 --- a/src/api/backend.ts +++ b/src/api/backend.ts @@ -11,7 +11,7 @@ export enum APIPath { FEED = "/feed/:id", JOBADS = "/jobads/:id", SIGNUPS = "/signup/:id", - SIGNUPS_EDIT = "/signup/:id/edit/:uuid", + SIGNUPS_EDIT = "/signup/:id/edit", SIGNUP_FORMS = "/signupForm/:id", SIGNUP_FORMS_EMAIL = "/signupForm/:id/sendemail", SIGNUP_FORMS_SIGNUPS = "/signupForm/:id/signups", @@ -23,12 +23,12 @@ type API = { path: APIPath; urlParams?: { id?: string | number; - uuid?: string; }; queryParams?: { limit?: number; offset?: number; since?: Date; + uuid?: string; }; authenticated?: boolean; }; @@ -53,18 +53,18 @@ const getHeaders = (auth?: boolean): Headers => { const fillUrlParams = (apiPath: APIPath, params: API["urlParams"] = {}): string => { const path = apiPath - .split("/") // ["", jobads", ":id"] - .filter(Boolean) // [jobads", ":id"] + .split("/") .map((urlComponent) => { // fill in each placeholder component like ':id' with value from params if (urlComponent.startsWith(":")) { const key = urlComponent.substring(1); - const value = params[key]; + const value = params[key] ?? ""; return value; } return urlComponent; }) - .join("/"); // "jobads/:id" + .filter(Boolean) + .join("/"); // code above strips leading and trailing '/' from path return `/${path}/`; }; diff --git a/src/api/signupApi.ts b/src/api/signupApi.ts index 908a3b9..467ca23 100644 --- a/src/api/signupApi.ts +++ b/src/api/signupApi.ts @@ -41,6 +41,8 @@ class SignupApi { path: APIPath.SIGNUPS_EDIT, urlParams: { id, + }, + queryParams: { uuid, }, }, data); @@ -56,6 +58,8 @@ class SignupApi { path: APIPath.SIGNUPS_EDIT, urlParams: { id, + }, + queryParams: { uuid, }, });