From 47c8132f01e0b23ea7b096398e94d03a40bb08b0 Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 17:51:31 +0200 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=9A=91=20fix:=20Migrate=20all=20path?= =?UTF-8?q?=20params=20to=20query=20params=20for=20sector=20&=20modify=20t?= =?UTF-8?q?he=20api's?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/redux/slices/sectorApiSlice.js | 8 +++++--- server/controllers/sector.controller.js | 21 ++++++++------------- server/routes/sector.route.js | 9 ++++----- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/client/src/redux/slices/sectorApiSlice.js b/client/src/redux/slices/sectorApiSlice.js index d801b5aa..9c88ae2b 100644 --- a/client/src/redux/slices/sectorApiSlice.js +++ b/client/src/redux/slices/sectorApiSlice.js @@ -6,7 +6,7 @@ export const captainsApi = apiSlice.injectEndpoints({ endpoints: (builder) => ({ GetSectors: builder.query({ query: () => ({ - url: `${SECTOR_URL}/`, + url: `${SECTOR_URL}/all/`, method: "GET", }), providesTags: ["Sector"], @@ -21,17 +21,19 @@ export const captainsApi = apiSlice.injectEndpoints({ }), UpdateSectorUnitCaptain: builder.mutation({ query: (sector) => ({ - url: `${SECTOR_URL}/${sector.baseName}/${sector.suffixName}`, + url: `${SECTOR_URL}/unit/`, method: "PATCH", body: sector, + query: sector, }), invalidatesTags: ["Sector"], }), UpdateSectorRegularCaptain: builder.mutation({ query: (sector) => ({ - url: `${SECTOR_URL}/captain/${sector.baseName}/${sector.suffixName}`, + url: `${SECTOR_URL}/assign/`, method: "PATCH", body: sector, + query: sector, }), invalidatesTags: ["Sector"], }), diff --git a/server/controllers/sector.controller.js b/server/controllers/sector.controller.js index f25ef7d3..8ef0ff7b 100644 --- a/server/controllers/sector.controller.js +++ b/server/controllers/sector.controller.js @@ -25,17 +25,12 @@ const sectorController = { } }, - // @desc Get sector by id (baseName and suffixName send as params) + // @desc Get sector by id (baseName and suffixName send as query) // @route GET /api/sector/:baseName/:suffixName // @access Private getSector: async (req, res) => { try { - let { baseName, suffixName } = req.params - - // If the suffix name wasn't provided (meaning it would be :suffixName) then make it an empty string - if (suffixName === ':suffixName') { - suffixName = "" - } + const { baseName, suffixName } = req.query const result = await db.query( ` @@ -69,7 +64,7 @@ const sectorController = { // @access Private insertSector: async (req, res) => { try { - let { baseName, suffixName, unitCaptainId } = req.body + const { baseName, suffixName, unitCaptainId } = req.body if (!baseName) { return res.status(404).json({ @@ -77,9 +72,9 @@ const sectorController = { }) } - if (!suffixName) { - suffixName = "" - } +// if (!suffixName) { +// suffixName = "" +// } const result = await db.query( ` @@ -107,7 +102,7 @@ const sectorController = { // @access Private setUnitCaptain: async (req, res) => { try { - const { baseName, suffixName } = req.params + const { baseName, suffixName } = req.query const { unitCaptainId } = req.body if (!unitCaptainId) { @@ -172,7 +167,7 @@ const sectorController = { }, assignCaptain: async (req, res) => { try { - const { baseName, suffixName } = req.params + const { baseName, suffixName } = req.query const { captainId } = req.body const result = await db.query(` diff --git a/server/routes/sector.route.js b/server/routes/sector.route.js index 618805cc..a9175f2e 100644 --- a/server/routes/sector.route.js +++ b/server/routes/sector.route.js @@ -5,13 +5,12 @@ import checkRankMiddleware from '../middlewares/checkRank.middleware.js' const sectorRouter = Router() sectorRouter.post('/', sectorController.insertSector) -sectorRouter.get('/', sectorController.getAllSectors) -sectorRouter.get('/:baseName/:suffixName', sectorController.getSector) +sectorRouter.get('/all', sectorController.getAllSectors) +sectorRouter.get('/', sectorController.getSector) sectorRouter.patch( - '/:baseName/:suffixName', - //TODO: Check if the captain id is for a unit captain + '/unit', sectorController.setUnitCaptain ) -sectorRouter.patch('/captain/:baseName/:suffixName', sectorController.assignCaptain) +sectorRouter.patch('/assign', sectorController.assignCaptain) export default sectorRouter From 02eca0901ff6c1850a39e2f23e163918f65968e9 Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 18:34:25 +0200 Subject: [PATCH 2/7] =?UTF-8?q?revert=20"=F0=9F=9A=91=20fix:=20Migrate=20a?= =?UTF-8?q?ll=20path=20params=20to=20query=20params=20for=20sector=20&=20m?= =?UTF-8?q?odify=20the=20api's"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 47c8132f01e0b23ea7b096398e94d03a40bb08b0. --- client/src/redux/slices/sectorApiSlice.js | 8 +++----- server/controllers/sector.controller.js | 21 +++++++++++++-------- server/routes/sector.route.js | 9 +++++---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/client/src/redux/slices/sectorApiSlice.js b/client/src/redux/slices/sectorApiSlice.js index 9c88ae2b..d801b5aa 100644 --- a/client/src/redux/slices/sectorApiSlice.js +++ b/client/src/redux/slices/sectorApiSlice.js @@ -6,7 +6,7 @@ export const captainsApi = apiSlice.injectEndpoints({ endpoints: (builder) => ({ GetSectors: builder.query({ query: () => ({ - url: `${SECTOR_URL}/all/`, + url: `${SECTOR_URL}/`, method: "GET", }), providesTags: ["Sector"], @@ -21,19 +21,17 @@ export const captainsApi = apiSlice.injectEndpoints({ }), UpdateSectorUnitCaptain: builder.mutation({ query: (sector) => ({ - url: `${SECTOR_URL}/unit/`, + url: `${SECTOR_URL}/${sector.baseName}/${sector.suffixName}`, method: "PATCH", body: sector, - query: sector, }), invalidatesTags: ["Sector"], }), UpdateSectorRegularCaptain: builder.mutation({ query: (sector) => ({ - url: `${SECTOR_URL}/assign/`, + url: `${SECTOR_URL}/captain/${sector.baseName}/${sector.suffixName}`, method: "PATCH", body: sector, - query: sector, }), invalidatesTags: ["Sector"], }), diff --git a/server/controllers/sector.controller.js b/server/controllers/sector.controller.js index 8ef0ff7b..f25ef7d3 100644 --- a/server/controllers/sector.controller.js +++ b/server/controllers/sector.controller.js @@ -25,12 +25,17 @@ const sectorController = { } }, - // @desc Get sector by id (baseName and suffixName send as query) + // @desc Get sector by id (baseName and suffixName send as params) // @route GET /api/sector/:baseName/:suffixName // @access Private getSector: async (req, res) => { try { - const { baseName, suffixName } = req.query + let { baseName, suffixName } = req.params + + // If the suffix name wasn't provided (meaning it would be :suffixName) then make it an empty string + if (suffixName === ':suffixName') { + suffixName = "" + } const result = await db.query( ` @@ -64,7 +69,7 @@ const sectorController = { // @access Private insertSector: async (req, res) => { try { - const { baseName, suffixName, unitCaptainId } = req.body + let { baseName, suffixName, unitCaptainId } = req.body if (!baseName) { return res.status(404).json({ @@ -72,9 +77,9 @@ const sectorController = { }) } -// if (!suffixName) { -// suffixName = "" -// } + if (!suffixName) { + suffixName = "" + } const result = await db.query( ` @@ -102,7 +107,7 @@ const sectorController = { // @access Private setUnitCaptain: async (req, res) => { try { - const { baseName, suffixName } = req.query + const { baseName, suffixName } = req.params const { unitCaptainId } = req.body if (!unitCaptainId) { @@ -167,7 +172,7 @@ const sectorController = { }, assignCaptain: async (req, res) => { try { - const { baseName, suffixName } = req.query + const { baseName, suffixName } = req.params const { captainId } = req.body const result = await db.query(` diff --git a/server/routes/sector.route.js b/server/routes/sector.route.js index a9175f2e..618805cc 100644 --- a/server/routes/sector.route.js +++ b/server/routes/sector.route.js @@ -5,12 +5,13 @@ import checkRankMiddleware from '../middlewares/checkRank.middleware.js' const sectorRouter = Router() sectorRouter.post('/', sectorController.insertSector) -sectorRouter.get('/all', sectorController.getAllSectors) -sectorRouter.get('/', sectorController.getSector) +sectorRouter.get('/', sectorController.getAllSectors) +sectorRouter.get('/:baseName/:suffixName', sectorController.getSector) sectorRouter.patch( - '/unit', + '/:baseName/:suffixName', + //TODO: Check if the captain id is for a unit captain sectorController.setUnitCaptain ) -sectorRouter.patch('/assign', sectorController.assignCaptain) +sectorRouter.patch('/captain/:baseName/:suffixName', sectorController.assignCaptain) export default sectorRouter From e2de42812da5c666c2cdcebb9224504c34b78d3c Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 18:51:07 +0200 Subject: [PATCH 3/7] =?UTF-8?q?=E2=9C=8D=EF=B8=8F=20fix:=20Change=20all=20?= =?UTF-8?q?the=20path=20variables=20into=20sector=20to=20query=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/redux/slices/sectorApiSlice.js | 8 +++++--- server/controllers/sector.controller.js | 13 ++++--------- server/routes/sector.route.js | 8 ++++---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/client/src/redux/slices/sectorApiSlice.js b/client/src/redux/slices/sectorApiSlice.js index d801b5aa..ebd33cc4 100644 --- a/client/src/redux/slices/sectorApiSlice.js +++ b/client/src/redux/slices/sectorApiSlice.js @@ -6,7 +6,7 @@ export const captainsApi = apiSlice.injectEndpoints({ endpoints: (builder) => ({ GetSectors: builder.query({ query: () => ({ - url: `${SECTOR_URL}/`, + url: `${SECTOR_URL}/all`, method: "GET", }), providesTags: ["Sector"], @@ -21,17 +21,19 @@ export const captainsApi = apiSlice.injectEndpoints({ }), UpdateSectorUnitCaptain: builder.mutation({ query: (sector) => ({ - url: `${SECTOR_URL}/${sector.baseName}/${sector.suffixName}`, + url: `${SECTOR_URL}/unit`, method: "PATCH", body: sector, + query: sector, }), invalidatesTags: ["Sector"], }), UpdateSectorRegularCaptain: builder.mutation({ query: (sector) => ({ - url: `${SECTOR_URL}/captain/${sector.baseName}/${sector.suffixName}`, + url: `${SECTOR_URL}/captain/assign`, method: "PATCH", body: sector, + query: sector, }), invalidatesTags: ["Sector"], }), diff --git a/server/controllers/sector.controller.js b/server/controllers/sector.controller.js index f25ef7d3..b2b2a975 100644 --- a/server/controllers/sector.controller.js +++ b/server/controllers/sector.controller.js @@ -30,13 +30,8 @@ const sectorController = { // @access Private getSector: async (req, res) => { try { - let { baseName, suffixName } = req.params - - // If the suffix name wasn't provided (meaning it would be :suffixName) then make it an empty string - if (suffixName === ':suffixName') { - suffixName = "" - } - + const { baseName, suffixName } = req.query + const result = await db.query( ` SELECT * @@ -107,7 +102,7 @@ const sectorController = { // @access Private setUnitCaptain: async (req, res) => { try { - const { baseName, suffixName } = req.params + const { baseName, suffixName } = req.query const { unitCaptainId } = req.body if (!unitCaptainId) { @@ -172,7 +167,7 @@ const sectorController = { }, assignCaptain: async (req, res) => { try { - const { baseName, suffixName } = req.params + const { baseName, suffixName } = req.query const { captainId } = req.body const result = await db.query(` diff --git a/server/routes/sector.route.js b/server/routes/sector.route.js index 618805cc..6946775a 100644 --- a/server/routes/sector.route.js +++ b/server/routes/sector.route.js @@ -5,13 +5,13 @@ import checkRankMiddleware from '../middlewares/checkRank.middleware.js' const sectorRouter = Router() sectorRouter.post('/', sectorController.insertSector) -sectorRouter.get('/', sectorController.getAllSectors) -sectorRouter.get('/:baseName/:suffixName', sectorController.getSector) +sectorRouter.get('/all', sectorController.getAllSectors) +sectorRouter.get('/', sectorController.getSector) sectorRouter.patch( - '/:baseName/:suffixName', + '/unit', //TODO: Check if the captain id is for a unit captain sectorController.setUnitCaptain ) -sectorRouter.patch('/captain/:baseName/:suffixName', sectorController.assignCaptain) +sectorRouter.patch('/captain/assign', sectorController.assignCaptain) export default sectorRouter From 4f1b1b067d4589118d2790c5ffc77b7a79c87418 Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 18:59:55 +0200 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=9A=91=20fix:=20Change=20all=20the=20?= =?UTF-8?q?stats=20get=20request=20(for=20sector=20base=20and=20suffix=20n?= =?UTF-8?q?ame)=20to=20query=20params=20instead=20of=20path=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/stats.controller.js | 2 +- server/routes/stats.route.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/controllers/stats.controller.js b/server/controllers/stats.controller.js index 603889e1..c4011863 100644 --- a/server/controllers/stats.controller.js +++ b/server/controllers/stats.controller.js @@ -96,7 +96,7 @@ const statsController = { // @access Private getScoutsInSectorAbsenceRate: async (req, res) => { try { - const { sectorBaseName, sectorSuffixName } = req.params + const { sectorBaseName, sectorSuffixName } = req.query if (req.currentTerm.termNumber === 0) { return res.status(400).json({ diff --git a/server/routes/stats.route.js b/server/routes/stats.route.js index faca40d1..f7d14841 100644 --- a/server/routes/stats.route.js +++ b/server/routes/stats.route.js @@ -17,7 +17,7 @@ statsRouter.get( statsController.getScoutsInUnitAbsenceRate ) statsRouter.get( - '/scouts/:sectorBaseName/:sectorSuffixName', + '/scouts/sector', getCurrentTermMiddleware, statsController.getScoutsInSectorAbsenceRate ) From 24004163acef503028614a8e3155a9d4d6d7391e Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 19:11:02 +0200 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=9A=91=20fix:=20Change=20any=20get=20?= =?UTF-8?q?with=20sector=20as=20path=20params=20to=20query=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/scout.controller.js | 2 +- server/routes/scout.route.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/controllers/scout.controller.js b/server/controllers/scout.controller.js index a26d5472..d9bfd2b1 100644 --- a/server/controllers/scout.controller.js +++ b/server/controllers/scout.controller.js @@ -19,7 +19,7 @@ const scoutController = { }, getScoutsInSector: async (req, res) => { try { - const { baseName, suffixName } = req.params + const { baseName, suffixName } = req.query const result = await db.query( `SELECT * diff --git a/server/routes/scout.route.js b/server/routes/scout.route.js index c528fbbb..7dcbfa96 100644 --- a/server/routes/scout.route.js +++ b/server/routes/scout.route.js @@ -9,7 +9,7 @@ scoutRouter.put('/:scoutId', scoutController.updateScout) scoutRouter.get('/', scoutController.getAllScouts) scoutRouter.get('/unit/:unitCaptainId', scoutController.getScoutsInUnit) scoutRouter.get( - '/sector/:baseName/:suffixName', + '/sector/all', scoutController.getScoutsInSector ) From 5aaa8a6a42ed5c566b90d7bf59e29c3b20e8b68a Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 19:17:58 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=9A=91=20fix:=20Change=20any=20path?= =?UTF-8?q?=20params=20with=20sector=20to=20query=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/captain.controller.js | 4 ++-- server/routes/captain.route.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/controllers/captain.controller.js b/server/controllers/captain.controller.js index cc4609fe..9a167d3d 100644 --- a/server/controllers/captain.controller.js +++ b/server/controllers/captain.controller.js @@ -3,7 +3,7 @@ import db from '../database/db.js' const captainController = { getAllCaptains: async (req, res) => { try { - const { type } = req.body + const { type } = req.query let result; if (type === 'regular') { @@ -35,7 +35,7 @@ const captainController = { }, getCaptainsInSector: async (req, res) => { try { - const { baseName, suffixName } = req.params + const { baseName, suffixName } = req.query // Query on the database to get all the captains info in a specific sector const result = await db.query( diff --git a/server/routes/captain.route.js b/server/routes/captain.route.js index 189f6a98..51b4d726 100644 --- a/server/routes/captain.route.js +++ b/server/routes/captain.route.js @@ -6,7 +6,7 @@ const captainRouter = Router() captainRouter.get('/', captainController.getAllCaptains) captainRouter.get('/unit/:unitCaptainId', captainController.getCaptainsInUnit) captainRouter.get( - '/sector/:baseName/:suffixName', + '/sector/all', captainController.getCaptainsInSector ) captainRouter.get('/:captainId', captainController.getCaptain) From 840ee389d7ef45821adaf8a5e5895485968231df Mon Sep 17 00:00:00 2001 From: akram Date: Wed, 27 Dec 2023 20:12:51 +0200 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=9A=91=20fix:=20Change=20the=20path?= =?UTF-8?q?=20params=20to=20query=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/alert.controller.js | 2 +- server/controllers/attendance.controller.js | 2 +- server/routes/alert.route.js | 2 +- server/routes/attendance.route.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/controllers/alert.controller.js b/server/controllers/alert.controller.js index c0aac86f..aa08d808 100644 --- a/server/controllers/alert.controller.js +++ b/server/controllers/alert.controller.js @@ -146,7 +146,7 @@ const alertController = { getAllAlerts: async (req, res) => { try { - const { status, contentType } = req.params + const { status, contentType } = req.query const result = await db.query( `SELECT N.*, R."status" FROM "Notification" AS N, "RecieveNotification" AS R diff --git a/server/controllers/attendance.controller.js b/server/controllers/attendance.controller.js index 64b62f83..0331c7a0 100644 --- a/server/controllers/attendance.controller.js +++ b/server/controllers/attendance.controller.js @@ -71,7 +71,7 @@ const attendanceController = { // @access Private getSectorAttendance: async (req, res) => { try { - const { baseName, suffixName, weekNumber, termNumber } = req.params + const { baseName, suffixName, weekNumber, termNumber } = req.query const result = await db.query(` SELECT "ScoutAttendance".* diff --git a/server/routes/alert.route.js b/server/routes/alert.route.js index 2b7c9d2f..7250e617 100644 --- a/server/routes/alert.route.js +++ b/server/routes/alert.route.js @@ -4,9 +4,9 @@ import alertController from '../controllers/alert.controller.js' const alertRouter = Router() alertRouter.post('/', alertController.createAlert) +alertRouter.get('/all', alertController.getAllAlerts) alertRouter.get('/:id', alertController.getAlert) alertRouter.post('/:id', alertController.sendAlert) alertRouter.delete('/:id', alertController.deleteAlert) -alertRouter.get('/:status/:contentType', alertController.getAllAlerts) export default alertRouter diff --git a/server/routes/attendance.route.js b/server/routes/attendance.route.js index 44b6b1a7..56bd2e54 100644 --- a/server/routes/attendance.route.js +++ b/server/routes/attendance.route.js @@ -5,7 +5,7 @@ const attendanceRouter = Router() // Insert a new attendance for a scout attendanceRouter.post('/', attendanceController.insertAttendance) -attendanceRouter.get('/sector/:baseName/:suffixName/:weekNumber/:termNumber', attendanceController.getSectorAttendance) +attendanceRouter.get('/sector/all', attendanceController.getSectorAttendance) attendanceRouter.get('/:scoutId/:weekNumber/:termNumber', attendanceController.getScoutAttendance) export default attendanceRouter; \ No newline at end of file