Merge branch 'BumBranch' into dev
This commit is contained in:
commit
49e3542dce
1 changed files with 76 additions and 3 deletions
|
@ -4,6 +4,7 @@ import {
|
|||
User,
|
||||
Project,
|
||||
NewProject,
|
||||
WeeklyReport,
|
||||
} from "../Types/goTypes";
|
||||
|
||||
// This type of pattern should be hard to misuse
|
||||
|
@ -20,10 +21,17 @@ interface API {
|
|||
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
||||
/** Remove a user */
|
||||
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
||||
/** Check if user is project manager */
|
||||
checkIfProjectManager(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>>;
|
||||
/** Login */
|
||||
login(NewUser: NewUser): Promise<APIResponse<string>>;
|
||||
/** Renew the token */
|
||||
renewToken(token: string): Promise<APIResponse<string>>;
|
||||
/** Promote user to admin */
|
||||
/** Create a project */
|
||||
createProject(
|
||||
project: NewProject,
|
||||
|
@ -40,7 +48,12 @@ interface API {
|
|||
projectName: string,
|
||||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
): Promise<APIResponse<WeeklyReport>>;
|
||||
getWeeklyReportsForUser(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport[]>>;
|
||||
/** Gets all the projects of a user*/
|
||||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||
/** Gets a project from id*/
|
||||
|
@ -101,6 +114,35 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async checkIfProjectManager(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>> {
|
||||
try {
|
||||
const response = await fetch("/api/checkIfProjectManager", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ username, projectName }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to check if project manager",
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as boolean;
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "fuck" };
|
||||
}
|
||||
},
|
||||
|
||||
async createProject(
|
||||
project: NewProject,
|
||||
token: string,
|
||||
|
@ -210,7 +252,7 @@ export const api: API = {
|
|||
projectName: string,
|
||||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>> {
|
||||
): Promise<APIResponse<WeeklyReport>> {
|
||||
try {
|
||||
const response = await fetch("/api/getWeeklyReport", {
|
||||
method: "GET",
|
||||
|
@ -224,7 +266,7 @@ export const api: API = {
|
|||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
} else {
|
||||
const data = (await response.json()) as NewWeeklyReport;
|
||||
const data = (await response.json()) as WeeklyReport;
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -232,6 +274,37 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async getWeeklyReportsForUser(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport[]>> {
|
||||
try {
|
||||
const response = await fetch(`/api/getWeeklyReportsUser?username=${username}&projectName=${projectName}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get weekly reports for project",
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as WeeklyReport[];
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
success: false,
|
||||
message: "fucked again",
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/login", {
|
||||
|
|
Loading…
Reference in a new issue