AddUserToProject API
This commit is contained in:
parent
a73432669c
commit
2694beb0e8
1 changed files with 29 additions and 2 deletions
|
@ -7,6 +7,7 @@ import {
|
|||
UserProjectMember,
|
||||
WeeklyReport,
|
||||
StrNameChange,
|
||||
NewProjMember,
|
||||
} from "../Types/goTypes";
|
||||
|
||||
/**
|
||||
|
@ -144,6 +145,10 @@ interface API {
|
|||
data: StrNameChange,
|
||||
token: string,
|
||||
): Promise<APIResponse<void>>;
|
||||
addUserToProject(
|
||||
user: NewProjMember,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewProjMember>>;
|
||||
}
|
||||
|
||||
/** An instance of the API */
|
||||
|
@ -254,6 +259,30 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async addUserToProject(
|
||||
user: NewProjMember,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewProjMember>> {
|
||||
try {
|
||||
const response = await fetch("/api/addUserToProject", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify(user),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to add member" };
|
||||
} else {
|
||||
return { success: true, message: "Added member" };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to add member" };
|
||||
}
|
||||
},
|
||||
|
||||
async renewToken(token: string): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/loginrenew", {
|
||||
|
@ -353,9 +382,7 @@ export const api: API = {
|
|||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const data = (await response.json()) as WeeklyReport;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
Loading…
Reference in a new issue