-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from advanced-computer-lab-2023/VCP-20-backend
Vcp 20 backend
- Loading branch information
Showing
8 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,6 @@ export const healthPackage = (app) => { | |
} | ||
}); | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import DoctorService from '../service/doctor-service.js'; | ||
import { isValidMongoId } from '../utils/Validation.js'; | ||
import { NOT_FOUND_STATUS_CODE, ERROR_STATUS_CODE, OK_STATUS_CODE } from '../utils/Constants.js'; | ||
|
||
export const doctor = (app) => { | ||
const service = new DoctorService(); | ||
|
||
app.get('/doctor/:id', async (req,res) => { | ||
try{ | ||
const id = req.params.id; | ||
if(!isValidMongoId(id)) | ||
return res.status(ERROR_STATUS_CODE).json({ message:'Invalid ID' }); | ||
const doctor = await service.getDoctorById(id); | ||
if(doctor){ | ||
res.status(OK_STATUS_CODE).json({ doctor }); | ||
} | ||
else{ | ||
res.status(NOT_FOUND_STATUS_CODE).json({ message:'doctor not found' }); | ||
} | ||
} | ||
catch(error){ | ||
res.status(ERROR_STATUS_CODE).json({ message:error }); | ||
} | ||
}); | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
//import DoctorModel from '../models/Doctor.js'; | ||
import Doctor from '../models/Doctor.js'; | ||
|
||
class DoctorRepository{ | ||
|
||
|
||
async findDoctorById(id){ | ||
const doctor = await Doctor.findById(id, '-userData.password'); | ||
return doctor; | ||
} | ||
|
||
} | ||
|
||
export default DoctorRepository; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
//import DoctorRepository from '../database/repository/doctor-repository.js'; | ||
import DoctorRepository from '../database/repository/doctor-repository.js'; | ||
|
||
class DoctorService{ | ||
class DoctorService { | ||
constructor() { | ||
this.repository = new DoctorRepository(); | ||
} | ||
|
||
async getDoctorById(id){ | ||
const doctor = await this.repository.findDoctorById(id); | ||
if(doctor){ | ||
return doctor; | ||
} | ||
else{ | ||
console.log('no doctor wuth this id was found'); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default DoctorService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
export const isValidMongoId = (id) => { | ||
return mongoose.Types.ObjectId.isValid(id); | ||
}; |