htning, on-chain, Liquid)
aboutsummaryrefslogblamecommitdiffstats
path: root/lib/utils.js
blob: a861f8b79d8a6a52209a8d79544fb271a22c42f3 (plain) (tree)
1
2
3
4
5
6
7

                                       
 
                             
                                    

              









                          






                                            
                                  






                       




                        


              


                           
                                    

              









                          






                                            
                                  






                       




                        


              
  
const sequelize = require("sequelize");
const { Op } = sequelize;

getUser = async username => {
  let user = await db.User.findOne({
    include: [
      {
        model: db.Account,
        as: "accounts"
      },
      {
        model: db.Account,
        as: "account"
      }
    ],
    where: { username }
  });

  user = user.get({ plain: true });

  user.payments = await db.Payment.findAll({
    order: [["id", "DESC"]],
    where: {
      user_id: user.id,
      account_id: user.account_id,
      [Op.or]: {
        received: true,
        amount: {
          [Op.lt]: 0
        }
      }
    },
    limit: 12,
    include: {
      model: db.Account,
      as: "account"
    }
  });

  return user;
};

getUserById = async id => {
  let user = await db.User.findOne({
    include: [
      {
        model: db.Account,
        as: "accounts"
      },
      {
        model: db.Account,
        as: "account"
      }
    ],
    where: { id }
  });

  user = user.get({ plain: true });

  user.payments = await db.Payment.findAll({
    order: [["id", "DESC"]],
    where: {
      user_id: user.id,
      account_id: user.account_id,
      [Op.or]: {
        received: true,
        amount: {
          [Op.lt]: 0
        }
      }
    },
    limit: 12,
    include: {
      model: db.Account,
      as: "account"
    }
  });

  return user;
};