Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- post.afterRemote('create', function(context, unused, next)
- {
- post.app.models['thread-user'].findOne({where: {'id' : context.result.userId}}, function(err, matching_User)
- {
- if(err !== undefined)
- {
- next(err);
- }
- else
- {
- matching_User.token = null;
- matching_User.password = null;
- context.result.user = matching_User;
- var query_Token = context.req.query.access_token || '0';
- post.app.models['thread-user'].findOne({where: {"token": query_Token}}, function(err, querying_User)
- {
- if(err !== undefined)
- {
- next(err);
- }
- else
- {
- querying_User = querying_User || {"id": "0"};
- post.app.models['follow-thread'].findOne({where: {"userId": querying_User.id, "threadId": context.result.threadId}}, function(err, following)
- {
- if(err !== undefined)
- {
- next(err);
- }
- else
- {
- if(following !== null)
- {
- following.updateAttribute('postId', context.result.id);
- next();
- }
- else
- {
- post.app.models['follow-thread'].create({"userId": matching_User.id, "threadId": context.result.threadId, "postId": context.result.id}, function(err, instance)
- {
- if(err !== undefined)
- {
- next(err);
- }
- else
- {
- next();
- }
- });
- }
- }
- });
- }
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement