Skip to content

Commit

Permalink
implement db
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Turner authored and Ben Turner committed Feb 16, 2024
1 parent 5d7a42b commit 18bc0a6
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 71 deletions.
4 changes: 2 additions & 2 deletions .env.vault
Original file line number Diff line number Diff line change
Expand Up @@ -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/FgKyJHgKLmuWOircATg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OY9WcuwpgSlJpnbXBtqc2p8K9eOAxLstGJBg9j1t6t0BbW1OVzSP/xuJnu7noBrl48/1diiFiK4A1yl80sT3cO1ZyaBoRB3VTisQe3DuSk8KWx4I3hDVV7C2djNKorCXFrbtbIrCVdZaJ+Ql0B/Cimmj3jociCuxDumHmlzGV3EoEFS4G3qfphgMs8x7epXpCliR324wzNmZTj9LYJ8SCzU+29u9yiTIqFx3Ow4="

197 changes: 197 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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}`);
});
});
23 changes: 23 additions & 0 deletions src/models/entry.model.ts
Original file line number Diff line number Diff line change
@@ -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);
36 changes: 19 additions & 17 deletions src/routers/attendance.router.ts
Original file line number Diff line number Diff line change
@@ -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 };
Loading

0 comments on commit 18bc0a6

Please sign in to comment.