Formatting and typing to make linter happy v2

This commit is contained in:
Imbus 2024-03-17 14:52:13 +01:00
commit ff00b984fe

View file

@ -33,6 +33,8 @@ interface API {
username: string,
token: string,
): Promise<APIResponse<Project[]>>;
/** Login */
login(NewUser: NewUser): Promise<APIResponse<JSON>>;
}
// Export an instance of the API
@ -156,7 +158,7 @@ export const api: API = {
}
},
submitWeeklyReport: function (
async submitWeeklyReport(
project: NewWeeklyReport,
token: string,
): Promise<APIResponse<Project>> {
@ -189,4 +191,25 @@ export const api: API = {
});
}
},
async login(NewUser: NewUser): Promise<APIResponse<JSON>> {
try {
const response = await fetch("/api/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(NewUser),
});
if (!response.ok) {
return { success: false, message: "Failed to login" };
} else {
const data = (await response.json()) as JSON;
return { success: true, data };
}
} catch (e) {
return Promise.resolve({ success: false, message: "Failed to login" });
}
},
};