Formatting and typing to make linter happy
This commit is contained in:
parent
8d0da111eb
commit
cab7c3bdfd
1 changed files with 34 additions and 15 deletions
|
@ -22,12 +22,17 @@ interface API {
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>>;
|
): Promise<APIResponse<Project>>;
|
||||||
/** Submit a weekly report */
|
/** Submit a weekly report */
|
||||||
submitWeeklyReport(project: NewWeeklyReport, token: string): Promise<APIResponse<Project>>;
|
submitWeeklyReport(
|
||||||
|
project: NewWeeklyReport,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<Project>>;
|
||||||
/** Renew the token */
|
/** Renew the token */
|
||||||
renewToken(token: string): Promise<APIResponse<string>>;
|
renewToken(token: string): Promise<APIResponse<string>>;
|
||||||
/** Gets all the projects of a user*/
|
/** Gets all the projects of a user*/
|
||||||
getUserProjects(username: string, token: string): Promise<APIResponse<Project[]>>;
|
getUserProjects(
|
||||||
|
username: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<Project[]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export an instance of the API
|
// Export an instance of the API
|
||||||
|
@ -55,7 +60,7 @@ export const api: API = {
|
||||||
|
|
||||||
async removeUser(
|
async removeUser(
|
||||||
username: string,
|
username: string,
|
||||||
token: string
|
token: string,
|
||||||
): Promise<APIResponse<User>> {
|
): Promise<APIResponse<User>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/userdelete", {
|
const response = await fetch("/api/userdelete", {
|
||||||
|
@ -80,7 +85,7 @@ export const api: API = {
|
||||||
|
|
||||||
async createProject(
|
async createProject(
|
||||||
project: NewProject,
|
project: NewProject,
|
||||||
token: string
|
token: string,
|
||||||
): Promise<APIResponse<Project>> {
|
): Promise<APIResponse<Project>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/project", {
|
const response = await fetch("/api/project", {
|
||||||
|
@ -135,18 +140,26 @@ export const api: API = {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return Promise.resolve({ success: false, message: "Failed to get user projects" });
|
return Promise.resolve({
|
||||||
|
success: false,
|
||||||
|
message: "Failed to get user projects",
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
const data = (await response.json()) as Project[];
|
const data = (await response.json()) as Project[];
|
||||||
return Promise.resolve({ success: true, data });
|
return Promise.resolve({ success: true, data });
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
return Promise.resolve({
|
||||||
return Promise.resolve({ success: false, message: "Failed to get user projects" });
|
success: false,
|
||||||
|
message: "Failed to get user projects",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
submitWeeklyReport: function (project: NewWeeklyReport, token: string): Promise<APIResponse<Project>> {
|
submitWeeklyReport: function (
|
||||||
|
project: NewWeeklyReport,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<Project>> {
|
||||||
try {
|
try {
|
||||||
return fetch("/api/submitWeeklyReport", {
|
return fetch("/api/submitWeeklyReport", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -158,16 +171,22 @@ export const api: API = {
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return { success: false, message: "Failed to submit weekly report" };
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to submit weekly report",
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data: Project) => {
|
||||||
return { success: true, data };
|
return { success: true, data };
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.resolve({ success: false, message: "Failed to submit weekly report" });
|
return Promise.resolve({
|
||||||
}
|
success: false,
|
||||||
|
message: "Failed to submit weekly report",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue