|
3 | 3 | var utils = require('../utils/writer.js'); |
4 | 4 | var Spot = require('../service/SpotService'); |
5 | 5 |
|
| 6 | +//Function to handle creating a new spot |
6 | 7 | module.exports.createSpot = function createSpot (req, res, next, body) { |
7 | 8 | Spot.createSpot(body) |
8 | 9 | .then(function (response) { |
| 10 | + // Write the response using the utility function |
9 | 11 | utils.writeJson(res, response); |
10 | 12 | }) |
11 | 13 | .catch(function (response) { |
| 14 | + // Write the error response using the utility function |
12 | 15 | utils.writeJson(res, response); |
13 | 16 | }); |
14 | 17 | }; |
15 | 18 |
|
| 19 | +//Function to handle retrieving all spots |
16 | 20 | module.exports.getSpots = function getSpots (req, res, next) { |
17 | 21 | Spot.getSpots() |
18 | 22 | .then(function (response) { |
| 23 | + // Write the response using the utility function |
19 | 24 | utils.writeJson(res, response); |
20 | 25 | }) |
21 | 26 | .catch(function (response) { |
| 27 | + // Write the error response using the utility function |
22 | 28 | utils.writeJson(res, response); |
23 | 29 | }); |
24 | 30 | }; |
25 | 31 |
|
| 32 | +//Function to handle modifying an existing parking spot |
26 | 33 | module.exports.modifySpot = function modifySpot (req, res, next, body, address, type, charger, id) { |
27 | 34 | Spot.modifySpot(body, address, type, charger, id) |
28 | 35 | .then(function (response) { |
| 36 | + // Write the response using the utility function |
29 | 37 | utils.writeJson(res, response); |
30 | 38 | }) |
31 | 39 | .catch(function (response) { |
| 40 | + // Write the error response using the utility function |
32 | 41 | utils.writeJson(res, response); |
33 | 42 | }); |
34 | 43 | }; |
35 | 44 |
|
| 45 | +// Function to handle removing a parking spot |
36 | 46 | module.exports.removeSpot = function removeSpot (req, res, next, id) { |
37 | 47 | Spot.removeSpot(id) |
38 | 48 | .then(function (response) { |
| 49 | + // Write the response using the utility function |
39 | 50 | utils.writeJson(res, response); |
40 | 51 | }) |
41 | 52 | .catch(function (response) { |
| 53 | + // Write the error response using the utility function |
42 | 54 | utils.writeJson(res, response); |
43 | 55 | }); |
44 | 56 | }; |
45 | 57 |
|
| 58 | +//Function to handle searching for a parking spot |
46 | 59 | module.exports.searchSpot = function searchSpot (req, res, next, address, type, charger) { |
47 | 60 | Spot.searchSpot(address, type, charger) |
48 | 61 | .then(function (response) { |
| 62 | + // Write the response using the utility function |
49 | 63 | utils.writeJson(res, response); |
50 | 64 | }) |
51 | 65 | .catch(function (response) { |
| 66 | + // Write the error response using the utility function |
52 | 67 | utils.writeJson(res, response); |
53 | 68 | }); |
54 | 69 | }; |
0 commit comments