Skip to content

Commit 3161ccb

Browse files
Dist (#29)
* Добавляет проверку на существание книги в базе * add some dependencies Co-authored-by: Kseniia <[email protected]>
1 parent f5001c0 commit 3161ccb

File tree

4 files changed

+197
-7
lines changed

4 files changed

+197
-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;

package-lock.json

+189
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"homepage": "https://github.com/AlexanderDmitriev/FinalProjectReact-Node-Back#readme",
2424
"dependencies": {
25+
"axios": "^0.27.2",
2526
"bcryptjs": "^2.4.3",
2627
"cors": "^2.8.5",
2728
"dotenv": "^16.0.2",
@@ -31,6 +32,7 @@
3132
"jsonwebtoken": "^8.5.1",
3233
"mongoose": "^6.6.1",
3334
"morgan": "^1.10.0",
35+
"query-string": "^7.1.1",
3436
"swagger-ui-express": "^4.5.0",
3537
"uuid": "^9.0.0"
3638
},

0 commit comments

Comments
 (0)