Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import compression from 'compression';
import hpp from 'hpp';

import { globalLimiter } from './middleware/rateLimiter.js';

Check warning on line 8 in src/app.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'globalLimiter' is defined but never used
import { errorHandler } from './middleware/errorHandler.js';
import { metricsMiddleware } from './middleware/metricsMiddleware.js';
import { register } from './config/metrics.js';
Expand Down Expand Up @@ -87,7 +87,7 @@
});
});

app.use(globalLimiter);
//app.use(globalLimiter);

app.use('/api/auth', authRoutes);
app.use('/api/payment', paymentRoutes);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/aptcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const updateAppointment = async (req, res, next) => {

if (
req.user.role === "doctor" &&
appointment.doctor.toString() !== req.user.id
appointment.doctor.toString() !== req.user.id.toString()
) {
return res.status(403).json({
success: false,
Expand Down
1 change: 1 addition & 0 deletions src/controllers/authcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const login = async (req, res) => {
role: user.role,
token,
user: {
id: user._id,
email: user.email,
role: user.role,
status: user.status,
Expand Down
5 changes: 3 additions & 2 deletions src/middleware/authmiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const protect = async (req, res, next) => {

req.user = {
id: user._id,
role: user.role.toLowerCase(),
role: String(user.role || '').trim().toLowerCase(),
email: user.email,
};

Expand All @@ -57,8 +57,9 @@ export const protect = async (req, res, next) => {
export const authorize = (...roles) => {
return (req, res, next) => {
const allowedRoles = Array.isArray(roles[0]) ? roles[0] : roles;
const normalizedAllowed = allowedRoles.map((r) => String(r || '').trim().toLowerCase());

if (!req.user || !allowedRoles.includes(req.user.role)) {
if (!req.user || !normalizedAllowed.includes(String(req.user.role || '').trim().toLowerCase())) {
return res.status(403).json({
success: false,
message: "Access denied",
Expand Down
8 changes: 4 additions & 4 deletions src/routes/appointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ const router = express.Router();
router.post(
'/',
protect,
authorize('admin', 'doctor', 'receptionist'),
authorize('admin', 'doctor', 'receptionist','billing'),
appointmentController.createAppointment
);

router.get(
'/',
protect,
authorize('admin', 'doctor', 'receptionist', 'patient'),
authorize('admin', 'doctor', 'receptionist', 'patient', 'billing'),
appointmentController.getAppointments
);

router.get(
'/:id',
protect,
authorize('admin', 'doctor', 'receptionist', 'patient'),
authorize('admin', 'doctor', 'receptionist', 'patient', 'billing'),
appointmentController.getAppointmentById
);

router.put(
'/:id',
protect,
authorize('admin', 'doctor', 'receptionist'),
authorize('admin', 'doctor', 'receptionist','billing'),
appointmentController.updateAppointment
);

Expand Down
10 changes: 6 additions & 4 deletions src/routes/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import * as patientController from '../controllers/patient.js';
const router = express.Router();


router.get('/', protect, authorize('admin', 'doctor','receptionist'), patientController.getPatients);
router.get('/', protect, authorize('admin', 'doctor', 'receptionist','billing'), patientController.getPatients);

router.post('/', protect, authorize('admin', 'doctor','receptionist'), patientController.createPatient);
router.get('/:id', protect, authorize('admin', 'doctor', 'receptionist','billing'), patientController.getPatientById);

router.put('/:id', protect, authorize('admin', 'doctor','receptionist'), patientController.updatePatient);
router.post('/', protect, authorize('admin', 'doctor', 'receptionist','billing'), patientController.createPatient);

router.delete('/:id', protect, authorize('admin','receptionist'), patientController.deletePatient);
router.put('/:id', protect, authorize('admin', 'doctor', 'receptionist','billing'), patientController.updatePatient);

router.delete('/:id', protect, authorize('admin'), patientController.deletePatient);

export default router;
Loading