Skip to content

Commit

Permalink
🎨 chore: Make the attendanceRecords destructured from the request bod…
Browse files Browse the repository at this point in the history
…y & add some comments
  • Loading branch information
akramhany committed Dec 29, 2023
1 parent 4f9bcd8 commit 3dfe2cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion server/controllers/captainAttendance.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import db from "../database/db.js"
const captainAttendanceController = {
upsertAttendance: async (req, res) => {
try {
const attendanceRecords = req.body.body
// NOTE: attendanceRecords must be sent as an array of objects in the request body
const { attendanceRecords } = req.body

if (attendanceRecords === 0) {
return res.status(404).json({
Expand All @@ -14,6 +15,7 @@ const captainAttendanceController = {
const weekNumber = attendanceRecords[0].weekNumber;
const termNumber = attendanceRecords[0].termNumber;

// Query to check if there are an exisiting records for this week & term or not
const prevRecords = await db.query(`
SELECT *
FROM "CaptainAttendance"
Expand Down
6 changes: 4 additions & 2 deletions server/controllers/scoutAttendance.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const scoutAttendanceController = {
// @access Private
upsertAttendance: async (req, res) => {
try {
const attendanceRecords = req.body.body
// NOTE: attendanceRecords must be sent as an array of objects in the request body
const { attendanceRecords } = req.body

if (attendanceRecords === 0) {
return res.status(404).json({
Expand All @@ -16,7 +17,8 @@ const scoutAttendanceController = {

const weekNumber = attendanceRecords[0].weekNumber;
const termNumber = attendanceRecords[0].termNumber;


// Query to check if there are an exisiting records for this week & term or not
const prevRecords = await db.query(`
SELECT *
FROM "ScoutAttendance"
Expand Down

0 comments on commit 3dfe2cf

Please sign in to comment.