From 76bca61a5ca50a5033486b51d7b7829ec831fd98 Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Fri, 23 Feb 2024 11:48:48 -0700 Subject: update with new api logic --- src/aggietime.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/aggietime.js') diff --git a/src/aggietime.js b/src/aggietime.js index 8fa1880..b7ba63b 100644 --- a/src/aggietime.js +++ b/src/aggietime.js @@ -26,9 +26,10 @@ const replace_path_args = (path, map) => const get_user_position_or_specified = async (position_id) => { const { positions } = await get_user_info(); - if (position_id === undefined && positions.length != 1) { - throw "Must specify a position when there's not only one to choose from"; - } else if (position_id === undefined) { + if (position_id === undefined) { + if (positions.length != 1) { + throw "Must specify a position when there's not only one to choose from"; + } return positions[0]; } @@ -83,20 +84,16 @@ export const clock_out = async (rest) => do_clock_mutation(CLOCKOUT_PATH, rest); export const current_shift = async () => { const req_path = replace_path_args(OPEN_SHIFT_PATH, await get_user_info()); - const { - request: { - res: { responseUrl: response_url }, - }, - data, - } = await aggietime.get(req_path); - - if (`${AGGIETIME_URI}/${req_path}` != response_url) { - // IMO a very weird decision - when there is no open shift the api redirects - // home instead of sending back a 404 or something - return null; - } - return data; + try { + const resp = await aggietime.get(req_path); + return resp.data; + } catch (e) { + if (e.response && e.response.status === 404) { + return null; + } + throw e; + } }; export const get_status_line = async () => { @@ -122,8 +119,8 @@ export const get_status_line = async () => { return { status: expireCache.get("status_line") }; }; -export const last_week = async ({ position_id }) => { - position_id = await get_user_position_or_specified(position_id); +export const last_week = async (args) => { + const position_id = await get_user_position_or_specified(args.position_id); const [start, end] = [ ((d) => { const day = d.getDay(); -- cgit v1.3