Fix for getWeeklyReportsForUser
This commit is contained in:
parent
0b6edd359e
commit
d41bfcf888
1 changed files with 14 additions and 8 deletions
|
@ -4,6 +4,7 @@ import {
|
||||||
User,
|
User,
|
||||||
Project,
|
Project,
|
||||||
NewProject,
|
NewProject,
|
||||||
|
WeeklyReport,
|
||||||
} from "../Types/goTypes";
|
} from "../Types/goTypes";
|
||||||
|
|
||||||
// This type of pattern should be hard to misuse
|
// This type of pattern should be hard to misuse
|
||||||
|
@ -47,11 +48,12 @@ interface API {
|
||||||
projectName: string,
|
projectName: string,
|
||||||
week: string,
|
week: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<NewWeeklyReport>>;
|
): Promise<APIResponse<WeeklyReport>>;
|
||||||
getWeeklyReportsForProject(
|
getWeeklyReportsForProject(
|
||||||
|
username: string,
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<NewWeeklyReport[]>>;
|
): Promise<APIResponse<WeeklyReport[]>>;
|
||||||
/** Gets all the projects of a user*/
|
/** Gets all the projects of a user*/
|
||||||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||||
/** Gets a project from id*/
|
/** Gets a project from id*/
|
||||||
|
@ -250,7 +252,7 @@ export const api: API = {
|
||||||
projectName: string,
|
projectName: string,
|
||||||
week: string,
|
week: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<NewWeeklyReport>> {
|
): Promise<APIResponse<WeeklyReport>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/getWeeklyReport", {
|
const response = await fetch("/api/getWeeklyReport", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -264,7 +266,7 @@ export const api: API = {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return { success: false, message: "Failed to get weekly report" };
|
return { success: false, message: "Failed to get weekly report" };
|
||||||
} else {
|
} else {
|
||||||
const data = (await response.json()) as NewWeeklyReport;
|
const data = (await response.json()) as WeeklyReport;
|
||||||
return { success: true, data };
|
return { success: true, data };
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -272,15 +274,19 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getWeeklyReportsForProject(projectName: string, token: string) {
|
async getWeeklyReportsForProject(
|
||||||
|
username: string,
|
||||||
|
projectName: string,
|
||||||
|
token: string
|
||||||
|
): Promise<APIResponse<WeeklyReport[]>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/getWeeklyReportsForProject", {
|
const response = await fetch("/api/getWeeklyReportsUser", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
Authorization: "Bearer " + token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ projectName }),
|
body: JSON.stringify({ username, projectName }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
@ -289,7 +295,7 @@ export const api: API = {
|
||||||
message: "Failed to get weekly reports for project",
|
message: "Failed to get weekly reports for project",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const data = (await response.json()) as NewWeeklyReport[];
|
const data = (await response.json()) as WeeklyReport[];
|
||||||
return { success: true, data };
|
return { success: true, data };
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue