Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. post.afterRemote('create', function(context, unused, next)
  2.   {
  3.     post.app.models['thread-user'].findOne({where: {'id' : context.result.userId}}, function(err, matching_User)
  4.     {
  5.       if(err !== undefined)
  6.       {
  7.         next(err);
  8.       }
  9.       else
  10.       {
  11.         matching_User.token = null;
  12.         matching_User.password = null;
  13.         context.result.user = matching_User;
  14.  
  15.         var query_Token = context.req.query.access_token || '0';
  16.         post.app.models['thread-user'].findOne({where: {"token": query_Token}}, function(err, querying_User)
  17.         {
  18.           if(err !== undefined)
  19.           {
  20.             next(err);
  21.           }
  22.           else
  23.           {
  24.             querying_User = querying_User || {"id": "0"};
  25.             post.app.models['follow-thread'].findOne({where: {"userId": querying_User.id, "threadId": context.result.threadId}}, function(err, following)
  26.             {
  27.               if(err !== undefined)
  28.               {
  29.                 next(err);
  30.               }
  31.               else
  32.               {
  33.                 if(following !== null)
  34.                 {
  35.                   following.updateAttribute('postId', context.result.id);
  36.                   next();
  37.                 }
  38.                 else
  39.                 {
  40.                   post.app.models['follow-thread'].create({"userId": matching_User.id, "threadId": context.result.threadId, "postId": context.result.id}, function(err, instance)
  41.                   {
  42.                     if(err !== undefined)
  43.                     {
  44.                       next(err);
  45.                     }
  46.                     else
  47.                     {
  48.                       next();
  49.                     }
  50.                   });
  51.                 }
  52.               }
  53.             });
  54.           }
  55.         });
  56.       }
  57.     });
  58.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement