I'm experiencing an issue with my JavaScript code for writing reviews. Previously, it worked fine, but now the 'datePosted' column consistently outputs the default '0000-00-00 00:00:00'.
writeReview(request, respond) {
var now = new Date();
var reviewObject = new Review(null, request.body.reviewUserId, request.body.reviewResId, request.body.review,
request.body.rating, request.body.numberOfLikes, now.toString());
var sql = "INSERT INTO resreview.reviews (reviewUserId, reviewResId, review, rating, numberOfLikes, datePosted) VALUES(?,?,?,?,?,?)";
var values = [reviewObject.getReviewUserId(), reviewObject.getReviewResId(), reviewObject.getReview(),
reviewObject.getRating(), reviewObject.getNumberOfLikes(), reviewObject.getDatePosted()];
db.query(sql, values, function (error, result) {
if (error) {
throw error;
}
else {
respond.json(result);
}
});
}
This code is from my 'Review.js' file:
"use strict"
class Review {
constructor(reviewId, reviewUserId, reviewResId, review, rating, numberOfLikes, datePosted) {
this.reviewId = reviewId;
this.reviewUserId = reviewUserId;
this.reviewResId = reviewResId;
this.review = review;
this.rating = rating;
this.numberOfLikes = numberOfLikes;
this.datePosted = datePosted;
}
//add the get methods here
getReviewId() {
return this.reviewId;
}
getReviewUserId() {
return this.reviewUserId;
}
getReviewResId() {
return this.reviewResId;
}
getReview() {
return this.review;
}
getRating() {
return this.rating;
}
getNumberOfLikes() {
return this.numberOfLikes;
}
getDatePosted() {
return this.datePosted;
}
//id is automatically-incremented
setReviewId(reviewId) {
this.reviewId = reviewId;
}
setReviewUserId(reviewUserId) {
this.reviewUserId = reviewUserId;
}
setReviewResId(reviewResId) {
this.reviewResId = reviewResId;
}
setReview(review) {
this.review = review;
}
setRating(rating) {
this.rating = rating;
}
setNumberOfLikes(numberOfLikes) {
this.numberOfLikes = numberOfLikes;
}
setDatePosted(datePosted) {
this.datePosted = datePosted;
}
}
module.exports = Review;
This is the data being stored in my MySQL database. https://i.sstatic.net/5KvMB.png
After reviewing my previously working files, I couldn't find any issues with the code. Notably, I am not utilizing PHP in this project. The datePosted column in this case uses DATETIME as the datatype, whereas in previous files I used VARCHAR for the same column. Could this difference be causing the issue? Thank you for your assistance!