-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (51 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require('express');
const Patient = require('./api/Patient');
const app = express();
app.post('/Patient', (req, res) => {
const {name, age} = req.body;
const newPatient = new Patient({ name, age });
newPatient.save()
.then((patient) => {
res.status(201).json(patient);
})
.catch((err) => {
res.status(500).json(err);
});
});
app.post('/api/patients/:id/encounter', (req, res) => {
const patientID = req.params.id;
const { vitals } = req.body;
Patient.findByIDandUpdate(patientID, { vitals }, { new: true })
.then((patient) => {
if (!patient) {
return res.status(404).json({ error: 'Patient not found'});
}
res.json(patient);
})
.catch((error) => {
res.status(500).json(error);
res.status(500).json({ error: 'Error has occured'});
});
});
app.get('/api/patients', (req, res) => {
Patient.find()
.then((patients) => {
res.json(patients);
})
.catch((err) => {
res.status(500).json(err);
});
});
app.get('/api/patients/:id', (req, res) => {
const patientID = req.params.id;
Patient.findById(patientID)
.then((patient) => {
if (!patient) {
return res.status(404).json({ error: 'Patient not found'});
}
res.join(patient);
})
.catch((error) => {
res.status(500).json(error);
});
});