Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // @ route GET api/patient/:patientId
  2. // @ desc Get patient by patientId
  3. // @ access Private
  4.  
  5. router.get('/:patientId', auth, async (req, res) => {
  6. try {
  7. const patient_profile = await Patient.findOne({
  8.  
  9. patient: req.params.patientId
  10.  
  11. }).populate('patient',['name','phonenumber']);
  12. //console.log(patient);
  13. console.log(patient_profile);
  14. if (!patient_profile) return res.status(400).json({ msg: 'Patient not found' });
  15.  
  16. res.json(patient_profile);
  17. } catch (err) {
  18. console.error(err.message);
  19. if (err.kind == 'ObjectId') {
  20. return res.status(400).json({ msg: 'Profile not found' });
  21. }
  22. res.status(500).send('Server Error');
  23. }
  24. });
  25.  
  26. module.exports=router;
  27.  
  28. const mongoose= require('mongoose');
  29. autoIncrement = require('mongoose-auto-increment');
  30. const config =require('config');
  31. const db=config.get('mongoURI');
  32.  
  33. var connection = mongoose.createConnection(db);
  34.  
  35. autoIncrement.initialize(connection);
  36.  
  37. const PatientSchema = new mongoose.Schema({
  38. name:{
  39. type:String,
  40. required: true
  41. },
  42. phonenumber:{
  43. type:Number,
  44. required:true
  45. },
  46. date: {
  47. type: Date,
  48. default: Date.now
  49. },
  50. slider_1:{
  51. type:Number,
  52. required: true
  53. },
  54. slider_2:{
  55. type:Number,
  56. required:true
  57. },
  58. slider_3:{
  59. type:Number,
  60. required:true
  61. }
  62.  
  63. });
  64. PatientSchema.plugin(autoIncrement.plugin, {
  65. model:'Patient',
  66. field:'patientId',
  67. startAt:1,
  68. incrementBy:1
  69. });
  70.  
  71. module.exports=Patient=mongoose.model('patient',PatientSchema,'patient');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement