summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLizzy Hunt <logan.hunt@usu.edu>2023-02-16 15:12:03 -0700
committerLizzy Hunt <logan.hunt@usu.edu>2023-02-16 15:12:03 -0700
commit287dc14a540214b32809fb24ae9cc08a4df58c22 (patch)
tree00ae13e2c59688143996aaff8c755d6f119b241d /src
parent3fca1d76238636b253b1b6f5bbb725d39e2a2c9e (diff)
downloadaggietimed-287dc14a540214b32809fb24ae9cc08a4df58c22.tar.gz
aggietimed-287dc14a540214b32809fb24ae9cc08a4df58c22.zip
Refactor clock mutations
Diffstat (limited to 'src')
-rw-r--r--src/aggietime.js26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/aggietime.js b/src/aggietime.js
index e039766..2cc69e3 100644
--- a/src/aggietime.js
+++ b/src/aggietime.js
@@ -50,12 +50,12 @@ export const get_user_info = async () => {
return expireCache.get("user");
};
-export const clock_in = async ({ position } = {}) => {
+const do_clock_mutation = async (path, { position } = {}) => {
position = await get_user_position_or_specified(position);
return await aggietime
.post(
- replace_path_args(CLOCKIN_PATH, { position }),
+ replace_path_args(path, { position }),
{
comment: "",
},
@@ -71,26 +71,8 @@ export const clock_in = async ({ position } = {}) => {
});
};
-export const clock_out = async ({ position } = {}) => {
- position = await get_user_position_or_specified(position);
-
- return await aggietime
- .post(
- replace_path_args(CLOCKOUT_PATH, { position }),
- {
- comment: "",
- },
- {
- headers: {
- "X-XSRF-TOKEN": expireCache.get("aggietime-csrf"),
- },
- }
- )
- .then(({ data }) => {
- expireCache.remove("status_line");
- return data;
- });
-};
+export const clock_in = async (rest) => do_clock_mutation(CLOCKIN_PATH, rest);
+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());