Refactor clock mutations

This commit is contained in:
Lizzy Hunt 2023-02-16 15:12:03 -07:00
parent 3fca1d7623
commit 287dc14a54
No known key found for this signature in database
GPG Key ID: 8AC6A4B840C0EC49

View File

@ -50,12 +50,12 @@ export const get_user_info = async () => {
return expireCache.get("user"); 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); position = await get_user_position_or_specified(position);
return await aggietime return await aggietime
.post( .post(
replace_path_args(CLOCKIN_PATH, { position }), replace_path_args(path, { position }),
{ {
comment: "", comment: "",
}, },
@ -71,26 +71,8 @@ export const clock_in = async ({ position } = {}) => {
}); });
}; };
export const clock_out = async ({ position } = {}) => { export const clock_in = async (rest) => do_clock_mutation(CLOCKIN_PATH, rest);
position = await get_user_position_or_specified(position); export const clock_out = async (rest) => do_clock_mutation(CLOCKOUT_PATH, rest);
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 current_shift = async () => { export const current_shift = async () => {
const req_path = replace_path_args(OPEN_SHIFT_PATH, await get_user_info()); const req_path = replace_path_args(OPEN_SHIFT_PATH, await get_user_info());