I am currently programming a reminders app based on this project in an effort to learn JS and MEAN Stack. As part of my project, I am trying to add a date which each reminder is to be completed by. However, when using Postman to POST in a date, I am receiving an error message unless I cut the date field and only use JSON to put the reminder's title in. If I use Javascript for my POST, it greys out the title field in my POST's body and when I attempt to use JSON, the time field's entry is not recognized. The pertinent code is below. Any help is appreciated.
const express = require('express');
const app = express();
const mongoose = require('./db/mongoose');
const bodyParser = require('body-parser');
const {List, Reminder} = require('./db/models')
app.post('/lists/:listId/reminder', (req, res) => {//add a reminder to the specified list
let newReminder = new Reminder({
title: req.body.title,
_listId: req.params.listId,
time: req.body.time
});
newReminder.save().then((newReminderDoc) => {
res.send(newReminderDoc);
})
})
const mongoose = require('mongoose');
const ReminderSchema = new mongoose.Schema({
title:{
type: String,
required: true,
minlength: 1,
trim: true
},
_listId:{
type: mongoose.Types.ObjectId,
required: true
},
time:{
type: Date,
required: true
}
});
const Reminder = mongoose.model('Reminder', ReminderSchema);
module.exports = { Reminder }
JS Query I am trying to used:
{
title: "Test",
created: new Date("2016-12-12")
}