SHARE
TWEET

Untitled

a guest Apr 2nd, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onPreSave(request, response, modules) {
  2.     if (request.method === 'POST') {
  3.         if (!request.body.hasOwnProperty('username')) {
  4.             request.body.views = 0;
  5.         }
  6.     } else if (request.method === 'PUT') {
  7.         var collectionAccess = modules.collectionAccess;
  8.         var myID = collectionAccess.objectID(request.entityId);
  9.         var ads = collectionAccess.collection("ads");
  10.         var logger = modules.logger;
  11.         logger.info(request);
  12.      
  13.         ads.findOne({"_id": myID}, [], function (err, result) {
  14.             if (err) {
  15.                 response.error(err);
  16.             }
  17.           request.body.views = result.views;
  18.           response.continue();
  19.         });
  20.     }
  21.  
  22.     response.continue();
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top