Repository navigation
Expand file tree
/
Copy pathapponiment.js
More file actions
103 lines (82 loc) · 3.49 KB
/
Copy pathapponiment.js
File metadata and controls
103 lines (82 loc) · 3.49 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.json());
let appointments = [];
app.get('/', (req, res) => {
res.status(200).send('Welcome to the Appointments API');
});
app.post('/appointments', (req, res) => {
const appointment = req.body;
appointments.push(appointment);
res.status(201).send(appointment);
});
app.post('/appointments', (req, res) => {
const appointment = req.body;
appointments.push(appointment);
res.status(201).send(appointment);
});
app.get('/appointments', (req, res) => {
res.status(200).send(appointments);
});
app.get('/appointments/:id', (req, res) => {
const appointment = appointments.find(a => a.id === parseInt(req.params.id));
if (!appointment) return res.status(404).send('Appointment not found');
res.status(200).send(appointment);
});
app.put ('/appointments/:id', (req, res) => {
const appointment = appointments.find(a => a.id === parseInt(req.params.id));
if (!appointment) return res.status(404).send('Appointment not found');
Object.assign(appointment, req.body);
res.status(200).send(appointment);
});
app.put('/appointments/:id', (req, res) => {
const appointment = appointments.find(a => a.id === parseInt(req.params.id));
if (!appointment) return res.status(404).send('Appointment not found');
Object.assign(appointment, req.body);
res.status(200).send(appointment);
});
app.put('/appointments/:id', (req, res) => {
const appointment = appointments.find(a => a.id === parseInt(req.params.id));
if (!appointment) return res.status(404).send('Appointment Sheduled');
Object.assign(appointment, req.body);
res.status(200).send(appointment);
});
app.delete('/appointments/:id', (req, res) => {
const appointmentIndex = appointments.findIndex(a => a.id === parseInt(req.params.id));
if (appointmentIndex === -1) return res.status(404).send('Appointment not found');
appointments.splice(appointmentIndex, 1);
res.status(204).send();
});
app.disable('etag');
app.use((req, res) => {
res.status(404).send('Resource not found');
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
app.listeners = 0;
module.Object=app;
module.exports = app;
appointments.push({ id: 1, name: ' ' ,email: ' ', phone: ' ', date: ' ', time: ' ' });
appointments.push({ id: 2, name: ' ', email: ' ', phone: ' ', date: ' ', time: ' ' });
appointments.push({ id: 3, name: ' ', email: ' ', phone: ' ', date: ' ', time: ' ' });
appointments.push({ id: 4, name: ' ', email: ' ', phone: ' ', date: ' ', time: ' ' });
appointments.push({ id: 5, name: ' ', email: ' ', phone: ' ', date: ' ', time: ' ' });
appointments.push({ id: 6, name: ' ', email: ' ', phone: ' ', date: ' ', time: ' ' });
appointments.push({ id: 7, name: ' ', email: ' ', phone: ' ', date: ' ', time: ' ' });
app.delete('/appointments/:id', (req, res) => {
const appointmentIndex = appointments.findIndex(a => a.id === parseInt(req.params.id));
if (appointmentIndex === -1) return res.status(404).send('Appointment not Shedueld');
appointments.splice(appointmentIndex, 1);
res.status(204).send();
});
app.disable('etag');
app.use((req, res) => {
res.status(404).send('Resource not found');
});
app.enable('etag');
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});