Skip to content

Commit a36234a

Browse files
2 parents ef0d7f3 + 3161ccb commit a36234a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

FinalProjectReact-Node-Back

-1
This file was deleted.

controllers/books/add.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const {Book} = require("../../models/book");
2-
3-
// const add = async (req, res) => {
4-
// const result = await Book.create(req.body);
5-
// res.status(201).json(result);
6-
// }
2+
const { RequestError } = require("../../helpers");
73

84
const add = async(req, res) => {
95
const {_id: owner} = req.user;
6+
const {author, title} = req.body;
7+
const book = await Book.findOne({author, title});
8+
if (book) {
9+
throw RequestError(409, "This book already exsist in your library")
10+
}
1011
const result = await Book.create({...req.body, owner});
1112
res.status(201).json(result);
1213
}
1314

14-
1515
module.exports = add;

0 commit comments

Comments
 (0)