Skip to content

Commit

Permalink
Set title publish date to null if no input
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonglittle committed Dec 5, 2021
1 parent 3333aa3 commit 6fc394a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library-express/titles.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ module.exports = function(){
console.log(req.body);
var mysql = req.app.get('mysql');
var sql = "INSERT INTO Titles (ISBN, bookTitle, author, publisher, datePublished) VALUES (?, ?, ?, ?, ?)";
var inserts = [req.body.ISBN, req.body.bookTitle, req.body.author, req.body.publisher, req.body.datePublished];
// check if the date published should be a null value
var datePublished = req.body.datePublished;
if (datePublished == '') {
datePublished = null;
}
var inserts = [req.body.ISBN, req.body.bookTitle, req.body.author, req.body.publisher, datePublished];
sql = mysql.pool.query(sql, inserts, function(error, results, fields){
if(error){
console.log(JSON.stringify(error));
Expand Down

0 comments on commit 6fc394a

Please sign in to comment.