Skip to content

Commit

Permalink
Merge pull request #45 from CMP26Projects/backend-functionalities
Browse files Browse the repository at this point in the history
Backend functionalities
  • Loading branch information
amir-kedis authored Dec 27, 2023
2 parents 6ce535b + 840ee38 commit 105a836
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 27 deletions.
8 changes: 5 additions & 3 deletions client/src/redux/slices/sectorApiSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"],
}),
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/alert.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/attendance.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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".*
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/captain.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/scout.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
13 changes: 4 additions & 9 deletions server/controllers/sector.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(`
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/stats.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion server/routes/alert.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/routes/attendance.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion server/routes/captain.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/routes/scout.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
8 changes: 4 additions & 4 deletions server/routes/sector.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/routes/stats.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ statsRouter.get(
statsController.getScoutsInUnitAbsenceRate
)
statsRouter.get(
'/scouts/:sectorBaseName/:sectorSuffixName',
'/scouts/sector',
getCurrentTermMiddleware,
statsController.getScoutsInSectorAbsenceRate
)
Expand Down

0 comments on commit 105a836

Please sign in to comment.