summaryrefslogtreecommitdiff
path: root/src/aggietime.js
diff options
context:
space:
mode:
authorLizzy Hunt <lizzy.hunt@usu.edu>2023-03-24 15:44:30 -0600
committerLizzy Hunt <lizzy.hunt@usu.edu>2023-03-24 15:44:30 -0600
commitaf29569ed5cfc7df6337a9dab51c743116c07343 (patch)
tree897c623a2cb8817d5f92e421bf5f14aa7fc95786 /src/aggietime.js
parent2201d2d9c9729deb33d3596e7b1d0875fb73ca55 (diff)
downloadaggietimed-af29569ed5cfc7df6337a9dab51c743116c07343.tar.gz
aggietimed-af29569ed5cfc7df6337a9dab51c743116c07343.zip
Add position id in req body, auto fake remember me
Diffstat (limited to 'src/aggietime.js')
-rw-r--r--src/aggietime.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/aggietime.js b/src/aggietime.js
index b887e36..413188a 100644
--- a/src/aggietime.js
+++ b/src/aggietime.js
@@ -21,16 +21,16 @@ const aggietime = client.create({
const replace_path_args = (path, map) =>
path.replaceAll(/:([a-zA-Z0-9_]+)/g, (_, key) => map[key]);
-const get_user_position_or_specified = async (position) => {
+const get_user_position_or_specified = async (position_id) => {
const { positions } = await get_user_info();
- if (!position && positions.length != 1) {
+ if (position_id === undefined && positions.length != 1) {
throw "Must specify a position when there's not only one to choose from";
- } else if (!position) {
- position = positions[0];
+ } else if (position_id === undefined) {
+ return positions[0];
}
- return position;
+ return position_id;
};
export const get_user_info = async () => {
@@ -53,12 +53,12 @@ export const get_user_info = async () => {
return expireCache.get("user");
};
-const do_clock_mutation = async (path, { position } = {}) => {
- position = await get_user_position_or_specified(position);
+const do_clock_mutation = async (path, { position_id } = {}) => {
+ position_id = await get_user_position_or_specified(position_id);
return await aggietime
.post(
- replace_path_args(path, { position }),
+ replace_path_args(path, { position_id }),
{
comment: "",
},
@@ -74,6 +74,8 @@ const do_clock_mutation = async (path, { position } = {}) => {
});
};
+// Actions
+
export const clock_in = async (rest) => do_clock_mutation(CLOCKIN_PATH, rest);
export const clock_out = async (rest) => do_clock_mutation(CLOCKOUT_PATH, rest);