diff --git a/.env.vault b/.env.vault index 7cc7ca6..b9f6e05 100644 --- a/.env.vault +++ b/.env.vault @@ -13,8 +13,8 @@ SECRET="dev only" ADMIN_CLIENT_BASE_URL="http://localhost:5500/index.html" # development -DOTENV_VAULT_DEVELOPMENT="EHZwGTtKQLGUYQt4k+NY2zGn+9ZyczaVYHuSCw7Owe8UiAqE+8YpPjf12mPwJpOV799J3CS2MldTtraodS82nXPcpE/B5S5yfWee2tjcOrMud7WG2Dw8+VjqJMRfKwjYF8cocy+tbqwnVw5iA1xx/iYUuADTzAvx1Ze2Fjc7oihqpWHZ0wpBQKYKA06PTN9D+Guw0FYWRTESxzSivv/oEo/G7G7ZNyDwe1P26V9N0iJl9IpWp3irh7oU1VeCa4jKvsDG6g3cnr8hGn48QMyrGMKuI93ckU60QaEhqnZFGbbYomuZ4v/nxCtAYjuLOhnh3QcRb+DQhXE86LzZ/XwUHrIdDyFNDIGj8eZtINGKu3ChUUSIFV9EmSPV4Tgm0YMFHV7Ndywd//pEbC45oF2lUO1dVS27t3RcCM8emzRAK+cm2uRzmG2L0nw6ZSifvUuVnCCiW7cP4qSVDO6LADZD7JlrHulxhev//GjlTIztUXoIw+uK8S6hrBrDjaLwqTijvh2Ak+akmJ2r7jGA" +DOTENV_VAULT_DEVELOPMENT="mk0ti7lLmG/jrGuAPr+qSYjuNneSX64I5tl1Jf1nVQr50vuBKUH9rDwasUlufWBn7f/IWF41+abK62LhoW/8FSqsHNjxa+q3UPSk34CdChVRPMs/szFNU3vbWfj5D/O+52/OM/M+W1kUqqTNacDsyhn1ZaR0td0CPe0JTeH2bZeR1aPhgUk69buhvho5jfRwtTYkb8SkwbW970fciMg9CHerWn29BWvZ6y4VUJnOqPzZ24xLMS/FgKyJHgKLmuWOircATgUS6RymWGX/NMdMV086ZWgIL7JhsnVWyYTI3i/RTMisIN+PTjTEVYLHSHvDdv3Ra1LTUYPXr+KSm4aJqfT76xL4O59QV3GpRWafPzDqLN4Bs9bPRN5NtUlLoux19txE0aBxA2ibZUCBYsJTR7+NDS37OqznC5IpEnYmbiEenMmdZQ69efizCViXsuwwNfoe7MtXUIbiVNPSayySKALihB99eepvI4PMFHGktcmgjZ7CxVabjr0vL865g11EUvLUwX/ljhqlL1NGLojuylTy2KIIK9oNmiyuKty22DPHku2VbXijB67XQtkKFwpnMZiXXMOTNBNkPIeBPkUv2YCLYNQ4ETtLzD/NrCsxDRMmXCaMmY7YURkeC36kraeHmLGILO8HIX1RZkXg5OTsVDpKDFm4" # ci -DOTENV_VAULT_CI="zHX8DJS9P2rCTlfnB5muJw+R/+S7uHi0DRGvz8VrjORTjYC2vztLkmhOyOv2iwk9tWrN9UqSmrL/Y/8CtfrJ4Y4xmfH5Zql1WUfx9x/UTj/1l0HidItQ4hZdMMWWAdMEswEnCk+Nmh5YlA7iV+DRZXdNF0SLzMTvnJLhK29txVh9hFNgCx+tSA5Umnod7NA1xCHexQoPp5gWl7mvampySnegmFSYmzwO6Zrgt6dv3X8T+4d+nHb6KkZP6FblBMcwsf1L0TGpv3AVHAg6qIkRYg3hEyRYKT+ABPsIYBZIkuXQTcbPFSmOUV/LRpf3T9h4JJCb6BT62IVNjlbY2B8GEZmKIHQchgl7Z92IABwUD3Bg77DpfXY1zEfDPg==" +DOTENV_VAULT_CI="ZG6WoGa4agRarWODwHiy3hbJV4xANDDBTiiCr+pc52CYYjZOT6BDlKoqqpc1eKce+pRW5yj2C2vvJW72se2IMmE5lRdswu35tQhQ3sI+fQjWCNOLSyshZLBNdz3rDFOFrCbW7EfnZtwEsK3vHIpTKVYkl4x1x7zQ59XC879xNuH8zi79NCBGj/BbvwEGl64/pqJyH6gh3Q/S2hqXmsPlL5a5Np40bJh6YNWZRmNhLvZVdw1lHNQ/SrVvsVu0L9XGqWF4OY9WcuwpgSlJpnbXBtqc2p8K9eOAxLstGJBg9j1t6t0BbW1OVzSP/xuJnu7noBrl48/1diiFiK4A1yl80sT3cO1ZyaBoRB3VTisQe3DuSk8KWx4I3hDVV7C2djNKorCXFrbtbIrCVdZaJ+Ql0B/Cimmj3jociCuxDumHmlzGV3EoEFS4G3qfphgMs8x7epXpCliR324wzNmZTj9LYJ8SCzU+29u9yiTIqFx3Ow4=" diff --git a/package-lock.json b/package-lock.json index 43d93f0..cc99b4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,12 +17,14 @@ "jimp": "^0.22.10", "jsonwebtoken": "^9.0.2", "jsqr": "^1.4.0", + "mongoose": "^8.1.2", "qrcode": "^1.5.3" }, "devDependencies": { "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/jest": "^29.5.12", + "@types/mongoose": "^5.11.97", "@types/node": "^20.11.17", "@types/qrcode": "^1.5.5", "@types/supertest": "^6.0.2", @@ -1979,6 +1981,14 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.4.tgz", + "integrity": "sha512-8zJ8N1x51xo9hwPh6AWnKdLGEC5N3lDa6kms1YHmFBoRhTpJR6HG8wWk0td1MVCu9cD4YBrvjZEtd5Obw0Fbnw==", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2289,6 +2299,16 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", "dev": true }, + "node_modules/@types/mongoose": { + "version": "5.11.97", + "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.11.97.tgz", + "integrity": "sha512-cqwOVYT3qXyLiGw7ueU2kX9noE8DPGRY6z8eUxudhXY8NZ7DMKYAxyZkLSevGfhCX3dO/AoX5/SO9lAzfjon0Q==", + "deprecated": "Mongoose publishes its own types, so you do not need to install this package.", + "dev": true, + "dependencies": { + "mongoose": "*" + } + }, "node_modules/@types/mute-stream": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz", @@ -2385,6 +2405,19 @@ "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", "integrity": "sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==" }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==" + }, + "node_modules/@types/whatwg-url": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.4.tgz", + "integrity": "sha512-lXCmTWSHJvf0TRSO58nm978b8HJ/EdsSsEKLd3ODHFjo+3VGAyyTp4v50nWvwtzBxSMQrVOK7tcuN0zGPLICMw==", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, "node_modules/@types/wrap-ansi": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz", @@ -3373,6 +3406,14 @@ "node-int64": "^0.4.0" } }, + "node_modules/bson": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.3.0.tgz", + "integrity": "sha512-balJfqwwTBddxfnidJZagCBPP/f48zj9Sdp3OJswREOgsJzHiQSaOIAtApSgDQFYgHqAvFkp53AFSqjMDZoTFw==", + "engines": { + "node": ">=16.20.1" + } + }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", @@ -6802,6 +6843,14 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/kareem": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", + "integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -7037,6 +7086,11 @@ "node": ">= 0.6" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==" + }, "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -7154,6 +7208,136 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/mongodb": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz", + "integrity": "sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA==", + "dependencies": { + "@mongodb-js/saslprep": "^1.1.0", + "bson": "^6.2.0", + "mongodb-connection-string-url": "^3.0.0" + }, + "engines": { + "node": ">=16.20.1" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.0.tgz", + "integrity": "sha512-t1Vf+m1I5hC2M5RJx/7AtxgABy1cZmIPQRMXw+gEIPn/cZNF3Oiy+l0UIypUwVB5trcWHq3crg2g3uAR9aAwsQ==", + "dependencies": { + "@types/whatwg-url": "^11.0.2", + "whatwg-url": "^13.0.0" + } + }, + "node_modules/mongodb-connection-string-url/node_modules/tr46": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", + "integrity": "sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==", + "dependencies": { + "punycode": "^2.3.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/mongodb-connection-string-url/node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/mongodb-connection-string-url/node_modules/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==", + "dependencies": { + "tr46": "^4.1.1", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/mongoose": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.1.2.tgz", + "integrity": "sha512-5KMq7k6KmFCIB8/YMKMFsWdsdNkBwuARDRHDRpp5GKC78eT0LwHIaMEKo6gDUg3zBuMoy9OdcM/6f4dkW06C/A==", + "dependencies": { + "bson": "^6.2.0", + "kareem": "2.5.1", + "mongodb": "6.3.0", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "16.0.1" + }, + "engines": { + "node": ">=16.20.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mongoose/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -8692,6 +8876,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz", + "integrity": "sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ==" + }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -8756,6 +8945,14 @@ "source-map": "^0.6.0" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", diff --git a/package.json b/package.json index 98f599a..1b6c7c5 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,14 @@ "jimp": "^0.22.10", "jsonwebtoken": "^9.0.2", "jsqr": "^1.4.0", + "mongoose": "^8.1.2", "qrcode": "^1.5.3" }, "devDependencies": { "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/jest": "^29.5.12", + "@types/mongoose": "^5.11.97", "@types/node": "^20.11.17", "@types/qrcode": "^1.5.5", "@types/supertest": "^6.0.2", diff --git a/src/index.ts b/src/index.ts index 6d74436..5f085a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,10 @@ import { server } from "./server"; import { hostname } from "os"; +import mg from "mongoose"; -server.listen(process.env.PORT, () => { - console.log(`Server listening on ${hostname}:${process.env.PORT}`); +mg.connect(process.env.MONGODB_URI as string).then(() => { + console.log(`Connected to DB ${mg.connection.host}`); + server.listen(process.env.PORT, () => { + console.log(`Server listening on ${hostname}:${process.env.PORT}`); + }); }); diff --git a/src/models/entry.model.ts b/src/models/entry.model.ts new file mode 100644 index 0000000..ecfad5d --- /dev/null +++ b/src/models/entry.model.ts @@ -0,0 +1,23 @@ +import mg from "mongoose"; + +const EntrySchema = new mg.Schema( + { + first_name: String, + last_name: String, + email: String, + start: Date, + end: Date, + }, + { + timestamps: true, + virtuals: { + full_name: { + get() { + return this.first_name + " " + this.last_name; + }, + }, + }, + }, +); + +export const EntryModel = mg.model("Entry", EntrySchema); diff --git a/src/routers/attendance.router.ts b/src/routers/attendance.router.ts index 129e2f5..0ea7fee 100644 --- a/src/routers/attendance.router.ts +++ b/src/routers/attendance.router.ts @@ -1,27 +1,29 @@ import ex from "express"; -import { checkIn } from "../services/attendance.service"; +import { checkIn, checkOut } from "../services/attendance.service"; import { expressjwt } from "express-jwt"; import { SubmissionType, User } from "../types"; const attendanceRouter = ex.Router(); -attendanceRouter.use(expressjwt({ secret: process.env.SECRET as string, algorithms: ["HS256"] })) +attendanceRouter.use( + expressjwt({ secret: process.env.SECRET as string, algorithms: ["HS256"] }), +); -attendanceRouter.post('/log-entry', async (req, res, next) => { - const { fields, type } = req.body as { fields: User, type: SubmissionType }; - // add entry or update existing entry based on type - // if check in, create new record with uid, fields, entry, - try { - if (type === SubmissionType.CheckIn) { - await checkIn(fields); - } else { - // check out - } - } catch (err) { - console.error(err); - return next('There was a problem processing the request') +attendanceRouter.post("/log-entry", async (req, res, next) => { + const { fields, type } = req.body as { fields: User; type: SubmissionType }; + try { + switch (type) { + case SubmissionType.CheckIn: + await checkIn(fields); + break; + case SubmissionType.CheckOut: + await checkOut(fields); } - res.status(200).send({ success: true }) -}) + res.status(200).send({ success: true }); + } catch (err) { + console.error(err); + return next(Error("There was a problem processing the request")); + } +}); export { attendanceRouter }; diff --git a/src/server.ts b/src/server.ts index 6d1d012..b0038c3 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,18 +7,19 @@ import { attendanceRouter } from "./routers/attendance.router"; const server = ex(); -server.use(ex.json()) +server.use(ex.json()); server.use((req, res, next) => { - console.log(req.method, req.hostname, req.headers.origin, req.body); - next() -}) -server.use(ex.static(path.resolve(__dirname, "..", "public")) -) -server.use(cors((req, cb) => { - cb(null, { origin: ORIGIN_WHITELIST.includes(req.headers.origin || "") }); -})) + console.log(req.method); + console.log(req.body); + next(); +}); +server.use(ex.static(path.resolve(__dirname, "..", "public"))); +server.use( + cors((req, cb) => { + cb(null, { origin: ORIGIN_WHITELIST.includes(req.headers.origin || "") }); + }), +); server.use(ex.static(path.resolve(__dirname, "..", "public"))); - server.get("/ping", (req, res) => res.status(200).send({ message: "pong" })); diff --git a/src/services/attendance.service.ts b/src/services/attendance.service.ts index 2f1060f..e02cdff 100644 --- a/src/services/attendance.service.ts +++ b/src/services/attendance.service.ts @@ -1,42 +1,64 @@ -import { google } from "googleapis"; -import { client } from "./google-auth.service"; +// import { google } from "googleapis"; +// import { client } from "./google-auth.service"; +// import { User } from "../types"; +// import { randomUUID } from "crypto"; + +import { EntryModel } from "../models/entry.model"; import { User } from "../types"; -import { randomUUID } from "crypto"; +export const checkIn = async (user: User) => { + const entry = new EntryModel({ + first_name: user.firstName, + last_name: user.lastName, + start: new Date(), + email: user.email, + }); + await entry.save(); +}; -const sheetsAPI = google.sheets({ version: "v4", auth: client }); +export const checkOut = async (user: User) => { + const entries = await EntryModel.find({ email: user.email }).sort({ + createdAt: "desc", + }); + const latest = entries[0]; + if (!latest) throw Error("No entries found. Cannot check out"); + if (latest.end) + throw Error("Latest entry already has checked out: " + latest.end); + await latest.updateOne({ end: new Date() }); +}; -export const checkIn = async (user: User) => { - // proof of concept: - await sheetsAPI.spreadsheets.batchUpdate({ - spreadsheetId: process.env.SPREADSHEET_ID, - requestBody: { - requests: [ - { - insertDimension: { - range: { - dimension: 'ROWS', - startIndex: 1, - endIndex: 2, - }, - } - } - ] - } - }) +// const sheetsAPI = google.sheets({ version: "v4", auth: client }); - const date = new Date(); - await sheetsAPI.spreadsheets.values.update({ - spreadsheetId: process.env.SPREADSHEET_ID, - range: "Input!A2:H", - valueInputOption: "USER_ENTERED", - requestBody: { - range: "Input!A2:H", - majorDimension: "ROWS", - // determine entry # - values: [[randomUUID(), 1, date.toLocaleDateString(), `${user.firstName} ${user.lastName}`, user.email, `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`, '', '=if(g2,(G2-F2)*24,0)']] - } - }) +// export const checkIn = async (user: User) => { +// // proof of concept: +// await sheetsAPI.spreadsheets.batchUpdate({ +// spreadsheetId: process.env.SPREADSHEET_ID, +// requestBody: { +// requests: [ +// { +// insertDimension: { +// range: { +// dimension: 'ROWS', +// startIndex: 1, +// endIndex: 2, +// }, +// } +// } +// ] +// } +// }) +// const date = new Date(); +// await sheetsAPI.spreadsheets.values.update({ +// spreadsheetId: process.env.SPREADSHEET_ID, +// range: "Input!A2:H", +// valueInputOption: "USER_ENTERED", +// requestBody: { +// range: "Input!A2:H", +// majorDimension: "ROWS", +// // determine entry # +// values: [[randomUUID(), 1, date.toLocaleDateString(), `${user.firstName} ${user.lastName}`, user.email, `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`, '', '=if(g2,(G2-F2)*24,0)']] +// } +// }) -}; +// }; diff --git a/src/types.ts b/src/types.ts index 56e20e6..30a3c62 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,10 @@ export interface User { - firstName: string; - lastName: string; - email: string; + firstName: string; + lastName: string; + email: string; } export enum SubmissionType { - CheckIn = 'CHECK_IN', - CheckOut = 'CHECK_OUT' + CheckIn = "CHECK_IN", + CheckOut = "CHECK_OUT", }