Skip to content

Instantly share code, notes, and snippets.

@hgsigner
Last active September 13, 2020 16:58
Show Gist options
  • Save hgsigner/2403abcbf502671543523502b46e16cf to your computer and use it in GitHub Desktop.
Save hgsigner/2403abcbf502671543523502b46e16cf to your computer and use it in GitHub Desktop.
app.post("/movies/:id/comment", async (req, res) => {
const { id } = req.params;
const { name, comment } = req.body;
const [res] = await knex.raw(
"insert into comments(comment, name, movie_id) values (?, ?, ?) returning id;"
[name, comment, id],
);
const [newComment] = await knex.raw("select * from comments where id = ? limit 1;", res[0]);
res.staus(200).json(newComment);
});
app.post("/playlists/:id/movies/:movieID", async (req, res) => {
const { id, movieID } = req.params;
const [res] = await knex.raw(
"insert into playlists_movies (plalist_id, movie_id) values (?, ?);",
[id, movie_id]
);
res.staus(200).json(res);
});
app.delete("/playlists/:id/movies/:movieID", async (req, res) => {
const { id, movieID } = req.params;
const [res] = await knex.raw(
"delete from playlists_movies where plalist_id = ? and movei_id = ?;",
[id, movieID]
);
res.staus(200).json(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment