Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const paidAgreement = async (body, userId) => {
  2.     return postModel.findOne({
  3.         include: {
  4.             model: agreementModel,
  5.             where: {
  6.                 id: body.agreementId
  7.             }
  8.         }
  9.     }).then(post => {
  10.         if (isPostCreator(post, userId)) {
  11.             if (post.agreements[0].status === enums.agreementStatus.done) {
  12.                 return agreementModel.update({
  13.                     status: enums.agreementStatus.paid
  14.                 }, {
  15.                     where: {
  16.                         id: post.agreements[0].id
  17.                     },
  18.                     returning: true
  19.                 });
  20.             } else {
  21.                 throw "agreement not accepted"
  22.             }
  23.         }
  24.         else
  25.             throw "wrong user"
  26.  
  27.     });
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement