fix APIPaths
This commit is contained in:
+6
-6
@@ -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}/`;
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user