Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcp 9 backend #2

Merged
merged 6 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
30 changes: 15 additions & 15 deletions clinic/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ const app = express();
const mongoURL = process.env.MONGO_URI;

const connect = async () => {
try {
await mongoose.connect(mongoURL);
console.log('Database connected');
} catch (err) {
console.error('Error connecting to the database:', err);
}
try {
await mongoose.connect(mongoURL);
console.log('Database connected');
} catch (err) {
console.error('Error connecting to the database:', err);
}
};

await connect();

app.use(express.json());
app.use(
cors({
origin: [
'http://localhost:3000',
'http://localhost:3001',
'http://localhost:3002',
],
credentials: true,
})
cors({
origin: [
'http://localhost:3000',
'http://localhost:3001',
'http://localhost:3002',
],
credentials: true,
})
);

healthPackage(app);
Expand All @@ -48,5 +48,5 @@ appointment(app);
const port = process.env.PORT || PORT;

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
console.log(`Server is running on port ${port}`);
});
19 changes: 18 additions & 1 deletion patient/src/api/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isValidMongoId } from '../utils/Validation.js';
export const patient = (app) => {
const service = new PatientService();

app.get('/all-patients', async (req, res) => {
app.get('/patients', async (req, res) => {
const allPatients = await service.getAllPatient();
if (allPatients.length > EMPTY_SIZE) {
res.status(OK_STATUS_CODE).json(allPatients);
Expand All @@ -21,6 +21,23 @@ export const patient = (app) => {
}
});

app.get('/family-members/:id', async (req, res) => {
const { id } = req.params;
if (!isValidMongoId(id)) {
return res
.status(NOT_FOUND_STATUS_CODE)
.json({ message: 'family members not found' });
}
try {
const data = await service.getFamilyMembers(id);
res.status(OK_STATUS_CODE).json(data);
} catch (err) {
res.status(NOT_FOUND_STATUS_CODE).json({
message: 'family members not found',
});
}
});

app.patch('/family-members/:id', async (req, res) => {
const { id } = req.params;
if (!isValidMongoId(id)) {
Expand Down
7 changes: 7 additions & 0 deletions patient/src/service/patient-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ class PatientService {
constructor() {
this.repository = new PatientRepository();
}
constructor() {
this.repository = new PatientRepository();
}

async getAllPatient() {
const patients = await this.repository.findAllPatients();
return patients;
}
async getAllPatient() {
const patients = await this.repository.findAllPatients();
return patients;
Expand Down
1 change: 1 addition & 0 deletions patient/src/utils/Validation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mongoose from 'mongoose';
import mongoose from 'mongoose';

export const isValidMongoId = (id) => {
return mongoose.Types.ObjectId.isValid(id);
Expand Down
Loading