aboutsummaryrefslogtreecommitdiffstats
path: root/views/login.html
diff options
context:
space:
mode:
Diffstat (limited to 'views/login.html')
0 files changed, 0 insertions, 0 deletions
58' href='#n58'>58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
const sequelize = require("sequelize");
const { Op } = sequelize;

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

  if (transaction) {
    params.lock = transaction.LOCK.UPDATE;
    params.transaction = transaction;
  }

  let user = await db.User.findOne(params);

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

  params = {
    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"
    }
  };

  if (transaction) {
    params.lock = transaction.LOCK.UPDATE;
    params.transaction = transaction;
  }

  user.payments = await db.Payment.findAll(params);

  return user;
};

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

  if (transaction) {
    params.lock = transaction.LOCK.UPDATE;
    params.transaction = transaction;
  }

  let user = await db.User.findOne(params);

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

  params = {
    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"
    }
  };

  if (transaction) {
    params.lock = transaction.LOCK.UPDATE;
    params.transaction = transaction;
  }

  user.payments = await db.Payment.findAll(params);

  return user;
};