Full implementation of getWeeklyProject
This commit is contained in:
parent
6823102b44
commit
c3ce25236f
1 changed files with 34 additions and 6 deletions
|
@ -33,13 +33,14 @@ interface API {
|
|||
submitWeeklyReport(
|
||||
project: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<Project>>;
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
/**Gets a weekly report*/
|
||||
getWeeklyReport(
|
||||
username: string,
|
||||
projectName: string,
|
||||
week: string,
|
||||
): Promise<APIResponse<Project>>;
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
/** Gets all the projects of a user*/
|
||||
getUserProjects(
|
||||
username: string,
|
||||
|
@ -169,9 +170,9 @@ export const api: API = {
|
|||
},
|
||||
|
||||
async submitWeeklyReport(
|
||||
project: NewWeeklyReport,
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<Project>> {
|
||||
): Promise<APIResponse<NewWeeklyReport>> {
|
||||
try {
|
||||
const response = await fetch("/api/submitWeeklyReport", {
|
||||
method: "POST",
|
||||
|
@ -179,7 +180,7 @@ export const api: API = {
|
|||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify(project),
|
||||
body: JSON.stringify(weeklyReport),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
@ -189,7 +190,7 @@ export const api: API = {
|
|||
};
|
||||
}
|
||||
|
||||
const data = (await response.json()) as Project;
|
||||
const data = (await response.json()) as NewWeeklyReport;
|
||||
return { success: true, data };
|
||||
} catch (e) {
|
||||
return {
|
||||
|
@ -199,6 +200,33 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async getWeeklyReport(
|
||||
username: string,
|
||||
projectName: string,
|
||||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>> {
|
||||
try {
|
||||
const response = await fetch("/api/getWeeklyReport", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ username, projectName, week }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
} else {
|
||||
const data = (await response.json()) as NewWeeklyReport;
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
}
|
||||
},
|
||||
|
||||
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/login", {
|
||||
|
|
Loading…
Reference in a new issue