-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflightController.js
65 lines (51 loc) · 1.16 KB
/
flightController.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
const flight = require("../models/Flight.js");
let flightDetails = flight.exampleModel;
exports.example = (req, res) => {
console.log("example");
res.send("Flight example");
};
exports.getFlights = (req, res) => {
res.json(flightDetails);
};
exports.addFlight = (req, res) => {
const { title, time, price, date, id } = req.body;
flightDetails.push({
title,
time,
price,
date,
id: title.slice(10),
});
res.json(flightDetails);
};
exports.getSingleFlight = (req, res) => {
const flightId = req.params.id;
const singleFlight = flightDetails.find((flight) => {
return flight.id.toString() === flightId;
});
res.json(singleFlight);
};
exports.deleteFlight = (req, res) => {
const flightId = req.params.id;
deletedFlight = flightDetails.filter((flight) => {
return flight.id !== flightId;
});
res.json(deletedFlight);
};
exports.updateFlights = (req, res) => {
const flightId = req.params.id;
let { title, time, price, date } = req.body;
flightDetails = flightDetails.map((flight) => {
if (flight.id === flightId) {
return {
title,
time,
price,
date,
id: flight.id,
};
}
return flight;
});
res.json(flightDetails);
};