Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UserSchema.methods.formatDob = function (day, month, year) {
- let dob = new Date( parseInt(year), parseInt(month) - 1, parseInt(day), 0, 0, 0, 0 );
- return new Date(dob, '<YYYY-MM-DD>');
- }
- exports.register = async function(req, res, next) {
- try {
- // instance methods not available yet
- let user = db.User.create(req.body);
- // method now available but too late to modify before inserting
- const { dobYear, dobMonth, dobDay } = req.body;
- const dob = formatDob(dobDay, dobMonth, dobYear);
- user = new db.User(); // can't pass in req.body here
- // Now I have to manually set all the fields!
- ...
- user.dob = dob;
- user.save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement