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(
|
submitWeeklyReport(
|
||||||
project: NewWeeklyReport,
|
project: NewWeeklyReport,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>>;
|
): Promise<APIResponse<NewWeeklyReport>>;
|
||||||
/**Gets a weekly report*/
|
/**Gets a weekly report*/
|
||||||
getWeeklyReport(
|
getWeeklyReport(
|
||||||
username: string,
|
username: string,
|
||||||
projectName: string,
|
projectName: string,
|
||||||
week: string,
|
week: string,
|
||||||
): Promise<APIResponse<Project>>;
|
token: string,
|
||||||
|
): Promise<APIResponse<NewWeeklyReport>>;
|
||||||
/** Gets all the projects of a user*/
|
/** Gets all the projects of a user*/
|
||||||
getUserProjects(
|
getUserProjects(
|
||||||
username: string,
|
username: string,
|
||||||
|
@ -169,9 +170,9 @@ export const api: API = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async submitWeeklyReport(
|
async submitWeeklyReport(
|
||||||
project: NewWeeklyReport,
|
weeklyReport: NewWeeklyReport,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>> {
|
): Promise<APIResponse<NewWeeklyReport>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/submitWeeklyReport", {
|
const response = await fetch("/api/submitWeeklyReport", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -179,7 +180,7 @@ export const api: API = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
Authorization: "Bearer " + token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(project),
|
body: JSON.stringify(weeklyReport),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
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 };
|
return { success: true, data };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
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>> {
|
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/login", {
|
const response = await fetch("/api/login", {
|
||||||
|
|
Loading…
Reference in a new issue