Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. UserSchema.methods.formatDob = function (day, month, year) {
  2. let dob = new Date( parseInt(year), parseInt(month) - 1, parseInt(day), 0, 0, 0, 0 );
  3. return new Date(dob, '<YYYY-MM-DD>');
  4. }
  5.  
  6. exports.register = async function(req, res, next) {
  7. try {
  8. // instance methods not available yet
  9. let user = db.User.create(req.body);
  10. // method now available but too late to modify before inserting
  11.  
  12. const { dobYear, dobMonth, dobDay } = req.body;
  13. const dob = formatDob(dobDay, dobMonth, dobYear);
  14. user = new db.User(); // can't pass in req.body here
  15. // Now I have to manually set all the fields!
  16. ...
  17. user.dob = dob;
  18. user.save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement