-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
49 lines (39 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const axios = require("axios");
const FormData = require("form-data");
const codec = require("string-codec");
const prepForm = (obj) => {
const { long, lat, desc, cookies, isCheckOut = false } = obj;
const data = new FormData();
const status = isCheckOut ? "checkout" : "checkin";
const longEncoded = codec.encoder(codec.encoder(long, "base64"), "rot13");
const latEncoded = codec.encoder(codec.encoder(lat, "base64"), "rot13");
data.append("longitude", longEncoded);
data.append("latitude", latEncoded);
data.append("status", status);
data.append("description", desc);
const config = {
method: "post",
url: "https://hr.talenta.co/api/web/live-attendance/request",
headers: {
Cookie: cookies,
...data.getHeaders(),
},
data: data,
};
return config;
};
const attendancePost = async (obj) => {
const config = prepForm(obj);
const resp = await axios(config);
return resp.data;
};
const clockIn = async (obj) => {
return await attendancePost({ ...obj, isCheckOut: false });
};
const clockOut = async (obj) => {
return await attendancePost({ ...obj, isCheckOut: true });
};
module.exports = {
clockIn,
clockOut,
};