Posted By

canuto on 02/26/19


Tagged

date default Value restdb codehook


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

canuto


restdb.io codehook to set default date values on POST


 / Published in: JavaScript
 

URL: https://restdb.io

This is a serverless codehook that can be used with the restdb.io database for setting a date value to be the same as the _created value if not supplied.

  1. // Codehooks for testcoll
  2. const beforePOST = async (req, res) => {
  3. try{
  4. if (!req.body.defaultdate){
  5. req.body.defaultdate = req.body._created;
  6. }
  7. res.end({data:req.body});
  8. }
  9. catch(ex){
  10. console.log("Codehook beforePOST failed",ex)
  11. res.end();
  12. }
  13. }

Report this snippet  

You need to login to post a comment.