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/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/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/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/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/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/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 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) 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 ) 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 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 )