Skip to content

Commit 6382d94

Browse files
committed
fix
1 parent 9256585 commit 6382d94

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

api-gateway/src/middlewares/auth.middleware.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export function authenticate(
2323
res: Response,
2424
next: NextFunction
2525
) {
26+
// 🔓 Skip authentication for public routes
27+
if (req.path.includes('/public')) {
28+
return next();
29+
}
30+
2631
const authHeader = req.headers.authorization;
2732

2833
if (!authHeader?.startsWith('Bearer ')) {

services/staff-service/src/modules/beds/bed.service.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { pool } from '../../db';
22
import { randomUUID } from 'crypto';
3-
import axios from 'axios';
43

54
class BedsService {
65
async createWard(name: string, description?: string) {
@@ -69,26 +68,32 @@ class BedsService {
6968
try {
7069
// 1. Fetch names and current admissions from patient-service
7170
const [patientsRes, admissionsRes] = await Promise.all([
72-
axios.post(`${process.env.PATIENT_SERVICE_URL}/patients/bulk-info`, {
73-
ids: activePatientIds,
71+
fetch(`${process.env.PATIENT_SERVICE_URL}/patients/bulk-info`, {
72+
method: 'POST',
73+
headers: { 'Content-Type': 'application/json' },
74+
body: JSON.stringify({ ids: activePatientIds }),
75+
}),
76+
fetch(`${process.env.PATIENT_SERVICE_URL}/admissions/bulk-current`, {
77+
method: 'POST',
78+
headers: { 'Content-Type': 'application/json' },
79+
body: JSON.stringify({ patientIds: activePatientIds }),
7480
}),
75-
axios.post(
76-
`${process.env.PATIENT_SERVICE_URL}/admissions/bulk-current`,
77-
{
78-
patientIds: activePatientIds,
79-
}
80-
),
8181
]);
8282

83-
const patientMap = new Map(
84-
patientsRes.data.map((p: any) => [p.id, p.name])
85-
);
83+
if (!patientsRes.ok || !admissionsRes.ok) {
84+
throw new Error('Failed to fetch patient or admission info');
85+
}
86+
87+
const patientsData = await patientsRes.json();
88+
const admissionsData = await admissionsRes.json();
89+
90+
const patientMap = new Map(patientsData.map((p: any) => [p.id, p.name]));
8691
const admissionMap = new Map(
87-
admissionsRes.data.map((a: any) => [a.patient_id, a.doctor_id])
92+
admissionsData.map((a: any) => [a.patient_id, a.doctor_id])
8893
);
8994

9095
const doctorIds = Array.from(
91-
new Set(admissionsRes.data.map((a: any) => a.doctor_id)) as Set<string>
96+
new Set(admissionsData.map((a: any) => a.doctor_id)) as Set<string>
9297
);
9398

9499
// 2. Fetch doctor names from local staff table
@@ -146,8 +151,9 @@ class BedsService {
146151
);
147152

148153
// 🔁 Notify patient-service admission is complete
149-
await axios.post(
150-
`${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/admit`
154+
await fetch(
155+
`${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/admit`,
156+
{ method: 'POST' }
151157
);
152158

153159
return assignment.rows[0];
@@ -188,8 +194,9 @@ class BedsService {
188194
[bedId]
189195
);
190196

191-
await axios.post(
192-
`${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/discharged`
197+
await fetch(
198+
`${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/discharged`,
199+
{ method: 'POST' }
193200
);
194201
}
195202

0 commit comments

Comments
 (0)