-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben Turner
authored and
Ben Turner
committed
Feb 16, 2024
1 parent
5d7a42b
commit 18bc0a6
Showing
9 changed files
with
322 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.