Skip to content

Commit 92f084d

Browse files
Merge pull request #13 from hms-int/dev-rohit
fix: all fix; final code
2 parents 7e4c9b0 + 3284c01 commit 92f084d

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ app.get('/', (_req, res) => {
8787
});
8888
});
8989

90-
app.use(globalLimiter);
90+
//app.use(globalLimiter);
9191

9292
app.use('/api/auth', authRoutes);
9393
app.use('/api/payment', paymentRoutes);

src/controllers/aptcontrol.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const updateAppointment = async (req, res, next) => {
8585

8686
if (
8787
req.user.role === "doctor" &&
88-
appointment.doctor.toString() !== req.user.id
88+
appointment.doctor.toString() !== req.user.id.toString()
8989
) {
9090
return res.status(403).json({
9191
success: false,

src/controllers/authcontroller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const login = async (req, res) => {
4747
role: user.role,
4848
token,
4949
user: {
50+
id: user._id,
5051
email: user.email,
5152
role: user.role,
5253
status: user.status,

src/middleware/authmiddleware.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const protect = async (req, res, next) => {
3131

3232
req.user = {
3333
id: user._id,
34-
role: user.role.toLowerCase(),
34+
role: String(user.role || '').trim().toLowerCase(),
3535
email: user.email,
3636
};
3737

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

61-
if (!req.user || !allowedRoles.includes(req.user.role)) {
62+
if (!req.user || !normalizedAllowed.includes(String(req.user.role || '').trim().toLowerCase())) {
6263
return res.status(403).json({
6364
success: false,
6465
message: "Access denied",

src/routes/appointment.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ const router = express.Router();
77
router.post(
88
'/',
99
protect,
10-
authorize('admin', 'doctor', 'receptionist'),
10+
authorize('admin', 'doctor', 'receptionist','billing'),
1111
appointmentController.createAppointment
1212
);
1313

1414
router.get(
1515
'/',
1616
protect,
17-
authorize('admin', 'doctor', 'receptionist', 'patient'),
17+
authorize('admin', 'doctor', 'receptionist', 'patient', 'billing'),
1818
appointmentController.getAppointments
1919
);
2020

2121
router.get(
2222
'/:id',
2323
protect,
24-
authorize('admin', 'doctor', 'receptionist', 'patient'),
24+
authorize('admin', 'doctor', 'receptionist', 'patient', 'billing'),
2525
appointmentController.getAppointmentById
2626
);
2727

2828
router.put(
2929
'/:id',
3030
protect,
31-
authorize('admin', 'doctor', 'receptionist'),
31+
authorize('admin', 'doctor', 'receptionist','billing'),
3232
appointmentController.updateAppointment
3333
);
3434

src/routes/patient.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import * as patientController from '../controllers/patient.js';
55
const router = express.Router();
66

77

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

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

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

14-
router.delete('/:id', protect, authorize('admin','receptionist'), patientController.deletePatient);
14+
router.put('/:id', protect, authorize('admin', 'doctor', 'receptionist','billing'), patientController.updatePatient);
15+
16+
router.delete('/:id', protect, authorize('admin'), patientController.deletePatient);
1517

1618
export default router;

0 commit comments

Comments
 (0)