From 4a55ebd8bf98874fd38f7ed0fab69d9260d8c3ea Mon Sep 17 00:00:00 2001 From: MrKevinOConnell Date: Fri, 5 Nov 2021 16:17:44 +0000 Subject: [PATCH] Prettified Code! --- .../src/api/clarifications/getClarifications.ts | 4 ++-- backend/src/api/submissions/getSubmissions.ts | 14 +++++++++++--- backend/src/api/users/getUsers.ts | 2 +- frontend/src/pages/admin/Clarifications.tsx | 8 ++++++-- .../src/pages/admin/submissions/Submissions.tsx | 8 ++++++-- frontend/src/pages/admin/users/Users.tsx | 9 ++++++--- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/backend/src/api/clarifications/getClarifications.ts b/backend/src/api/clarifications/getClarifications.ts index c70b1f09..674dd878 100644 --- a/backend/src/api/clarifications/getClarifications.ts +++ b/backend/src/api/clarifications/getClarifications.ts @@ -64,13 +64,13 @@ const hasAccessTo = ({ type, division, uid }: any, user?: User) => { } export const getClarifications = async (req: Request, res: Response) => { - const { page } = JSON.parse(req.body); + const { page } = JSON.parse(req.body) const errors = validationResult(req).array() if (errors.length > 0) { res.status(400).json({ message: errors[0].msg }) return } - const newPage = page ? page : null; + const newPage = page ? page : null const query = matchedData(req) const users = transpose(await contest.get_users(), 'uid') as Record diff --git a/backend/src/api/submissions/getSubmissions.ts b/backend/src/api/submissions/getSubmissions.ts index 93bd5eb8..461ae76d 100644 --- a/backend/src/api/submissions/getSubmissions.ts +++ b/backend/src/api/submissions/getSubmissions.ts @@ -91,16 +91,24 @@ const showToUser = (user: User | undefined, problem: Problem, settings: Settings } export const getSubmissions = async (req: Request, res: Response) => { - const { page } = JSON.parse(req.body) + const { page } = JSON.parse(req.body) const errors = validationResult(req).array() if (errors.length > 0) { res.status(400).json({ message: errors[0].msg }) return } //if the page number isn't included in the request, make it null - const newPage = page ? page : null; + const newPage = page ? page : null const problems = transpose( - await contest.get_problems({}, undefined, ['pid', 'division', 'id', 'name', 'max_points', 'capped_points', 'practice']), + await contest.get_problems({}, undefined, [ + 'pid', + 'division', + 'id', + 'name', + 'max_points', + 'capped_points', + 'practice' + ]), 'pid' ) const users = transpose(await contest.get_users(), 'uid') as unknown as User[] diff --git a/backend/src/api/users/getUsers.ts b/backend/src/api/users/getUsers.ts index df004f5d..967832d0 100644 --- a/backend/src/api/users/getUsers.ts +++ b/backend/src/api/users/getUsers.ts @@ -83,7 +83,7 @@ export const getUsers = async (req: Request, res: Response) => { } const params = matchedData(req) - const newPage = page ? page : null; + const newPage = page ? page : null if (req.user?.role == 'team') params.uid = req.user?.uid if (req.user?.role == 'judge') { params.role = 'team' diff --git a/frontend/src/pages/admin/Clarifications.tsx b/frontend/src/pages/admin/Clarifications.tsx index ca681028..59feb84e 100644 --- a/frontend/src/pages/admin/Clarifications.tsx +++ b/frontend/src/pages/admin/Clarifications.tsx @@ -38,7 +38,7 @@ const Clarifications = (): JSX.Element => { const loadClarifications = async () => { const response = await fetch(`${config.API_URL}/clarifications`, { headers: { Authorization: `Bearer ${localStorage.accessToken}` }, - body: JSON.stringify(page), + body: JSON.stringify(page) }) if (response.ok) { const clarifications = Object.values(await response.json()) as ClarificationItem[] @@ -201,7 +201,11 @@ const Clarifications = (): JSX.Element => { )} - handlePageChange(data.activePage as number))} /> + handlePageChange(data.activePage as number)} + /> ) diff --git a/frontend/src/pages/admin/submissions/Submissions.tsx b/frontend/src/pages/admin/submissions/Submissions.tsx index 04359cf9..76dd759f 100644 --- a/frontend/src/pages/admin/submissions/Submissions.tsx +++ b/frontend/src/pages/admin/submissions/Submissions.tsx @@ -58,7 +58,7 @@ const Submissions = (): JSX.Element => { headers: { Authorization: `Bearer ${localStorage.accessToken}` }, - body: JSON.stringify(page), + body: JSON.stringify(page) }) const submissions = Object.values(await response.json()) as SubmissionItem[] @@ -218,7 +218,11 @@ const Submissions = (): JSX.Element => { )} - handlePageChange(data.activePage as number))} /> + handlePageChange(data.activePage as number)} + /> ) diff --git a/frontend/src/pages/admin/users/Users.tsx b/frontend/src/pages/admin/users/Users.tsx index fee18590..a215cb34 100644 --- a/frontend/src/pages/admin/users/Users.tsx +++ b/frontend/src/pages/admin/users/Users.tsx @@ -72,13 +72,12 @@ const Users = (): JSX.Element => { } */ const loadUsers = async (page: number) => { - try { const response = await fetch(`${config.API_URL}/users`, { headers: { Authorization: `Bearer ${localStorage.accessToken}` }, - body: JSON.stringify(page), + body: JSON.stringify(page) }) if (isMounted) { const data = Object.values(await response.json()) as UserItem[] @@ -271,7 +270,11 @@ const Users = (): JSX.Element => { ))} - handlePageChange(data.activePage as number))} /> + handlePageChange(data.activePage as number)} + /> ) }