Skip to content

Commit

Permalink
Update syntax in bookController to match lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
columk1 authored Nov 23, 2023
1 parent 34f8769 commit f79e525
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions controllers/bookController.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ exports.book_create_get = asyncHandler(async (req, res, next) => {
exports.book_create_post = [
// Convert the genre to an array.
(req, res, next) => {
if (!(req.body.genre instanceof Array)) {
if (typeof req.body.genre === "undefined") req.body.genre = [];
else req.body.genre = new Array(req.body.genre);
if (!Array.isArray(req.body.genre)) {
req.body.genre =
typeof req.body.genre === "undefined" ? [] : [req.body.genre];
}
next();
},
Expand Down Expand Up @@ -235,12 +235,9 @@ exports.book_update_get = asyncHandler(async (req, res, next) => {
exports.book_update_post = [
// Convert the genre to an array.
(req, res, next) => {
if (!(req.body.genre instanceof Array)) {
if (typeof req.body.genre === "undefined") {
req.body.genre = [];
} else {
req.body.genre = new Array(req.body.genre);
}
if (!Array.isArray(req.body.genre)) {
req.body.genre =
typeof req.body.genre === "undefined" ? [] : [req.body.genre];
}
next();
},
Expand Down

0 comments on commit f79e525

Please sign in to comment.