diff options
author | Lizzy Hunt <lizzy.hunt@usu.edu> | 2023-03-24 16:34:55 -0600 |
---|---|---|
committer | Lizzy Hunt <lizzy.hunt@usu.edu> | 2023-03-24 16:34:55 -0600 |
commit | 633965afaab042ceb49ae52b0ccd7cec3430c756 (patch) | |
tree | de18603c9fbdf0f96532fff241f5fc60f68ed6fd /src/aggietime.js | |
parent | 3bda8ced7d0e18eb82f77f7427c41cb93f89dd2f (diff) | |
download | aggietimed-633965afaab042ceb49ae52b0ccd7cec3430c756.tar.gz aggietimed-633965afaab042ceb49ae52b0ccd7cec3430c756.zip |
Add past week action
Diffstat (limited to 'src/aggietime.js')
-rw-r--r-- | src/aggietime.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/aggietime.js b/src/aggietime.js index 413188a..5c0ff72 100644 --- a/src/aggietime.js +++ b/src/aggietime.js @@ -5,8 +5,10 @@ import { USER_CACHE_EXP_SEC, CLOCKIN_PATH, CLOCKOUT_PATH, + SUMMARY_PATH, OPEN_SHIFT_PATH, OPEN_SHIFT_EXP_SEC, + PAST_WEEK_EXP_SEC, } from "./constants.js"; import { with_exponential_retry } from "./exponential_retry.js"; @@ -119,3 +121,30 @@ 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); + const [start, end] = [ + ((d) => { + const day = d.getDay(); + const diff = d.getDate() - day + (day == 0 ? -6 : 1); + return new Date(d.setDate(diff)); + })(new Date()), + new Date(), + ].map((d) => d.toISOString().split("T")[0]); + + if (!expireCache.get("past_week")) { + const { anumber } = await get_user_info(); + + const hours = await aggietime + .get(replace_path_args(SUMMARY_PATH, { position_id, start, end })) + .then(({ data: { undisputed_hours } }) => undisputed_hours); + + expireCache.set( + "past_week", + `${anumber} - ${hours} hours`, + PAST_WEEK_EXP_SEC + ); + } + return { status: expireCache.get("past_week") }; +}; |