From 3dfe2cfc08c9b80e7f7be07bc074db63963d6ffb Mon Sep 17 00:00:00 2001 From: akram Date: Fri, 29 Dec 2023 03:51:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20chore:=20Make=20the=20attendance?= =?UTF-8?q?Records=20destructured=20from=20the=20request=20body=20&=20add?= =?UTF-8?q?=20some=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/captainAttendance.controller.js | 4 +++- server/controllers/scoutAttendance.controller.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/controllers/captainAttendance.controller.js b/server/controllers/captainAttendance.controller.js index 3e63f121..90ff095c 100644 --- a/server/controllers/captainAttendance.controller.js +++ b/server/controllers/captainAttendance.controller.js @@ -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({ @@ -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" diff --git a/server/controllers/scoutAttendance.controller.js b/server/controllers/scoutAttendance.controller.js index 4f385415..25e35bcb 100644 --- a/server/controllers/scoutAttendance.controller.js +++ b/server/controllers/scoutAttendance.controller.js @@ -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({ @@ -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"