-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallFunctions.js
More file actions
76 lines (71 loc) · 2.05 KB
/
callFunctions.js
File metadata and controls
76 lines (71 loc) · 2.05 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
const callMovie = require('./getFunctions');
app.get('/movies', (req, res) => {
callMovie.getAllMovies().then((result) => {
res.status(200).send(result);
}).catch(() => {
res.sendStatus(500);
});
});
app.get('/movies/:movieid', (req, res) => {
callMovie.getmoviesByID(req.params.movieid).then((result) => {
(result.length > 0) ? res.status(200).send(result) : res.sendStatus(404);
}).catch(() => {
res.sendStatus(500);
});
});
// Delete movie by id
app.delete('/movies/:movieid', (req, res) => {
callMovie.deleteMovie(req.params.movieid).then((data) => {
if (data.affectedRows) { res.sendStatus(202); } else { res.sendStatus(404); }
}).catch(() => {
res.sendStatus(500);
});
});
// Updating movie by id
app.put('/movies/:movieid', (req, res) => {
const { body } = req;
const dir = {
title: body.title,
description: body.description,
runtime: body.runtime,
genre: body.genre,
rating: body.rating,
metascore: body.metascore,
votes: body.votes,
gross: body.Gross_Earning_in_Mil,
director: body.director,
actor: body.actor,
year: body.year,
};
callMovie.updateMovie(req.params.movieid, dir).then((data) => {
if (data.affectedRows) {
res.sendStatus(202);
} else {
res.sendStatus(404);
}
}).catch(() => {
res.sendStatus(500);
});
});
// Adding a new movie
app.post('/movies/', (req, res) => {
const { body } = req;
const dir = {
title: body.title,
description: body.description,
runtime: body.runtime,
genre: body.genre,
rating: body.rating,
metascore: body.metascore,
votes: body.votes,
gross: body.gross,
director: body.director,
actor: body.actor,
year: body.year,
};
callMovie.addNewMovie(dir).then((data) => {
res.send(`Last person added whose rank is: ${data.rank}`);
}).catch(() => {
res.sendStatus(500);
});
});