aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-04-29 20:59:05 -0700
committerAdam Soltys <[email protected]>2020-04-29 21:03:33 -0700
commitfa84d5a65844602c7e97e9bf0e5a51befdebaf53 (patch)
tree3e0335eea275a5de9040eb3cc6dfc62c6e190575 /lib
parent001c0291ad6eabe5684138422adfa0e851d507a6 (diff)
downloadcoinos-server-fa84d5a65844602c7e97e9bf0e5a51befdebaf53.tar.gz
coinos-server-fa84d5a65844602c7e97e9bf0e5a51befdebaf53.zip
update account balance properly after lightning payment
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.js48
1 files changed, 38 insertions, 10 deletions
diff --git a/lib/utils.js b/lib/utils.js
index a861f8b7..cd1b3d69 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,8 +1,8 @@
const sequelize = require("sequelize");
const { Op } = sequelize;
-getUser = async username => {
- let user = await db.User.findOne({
+getUser = async (username, transaction) => {
+ let params = {
include: [
{
model: db.Account,
@@ -14,11 +14,18 @@ getUser = async username => {
}
],
where: { username }
- });
+ };
+
+ if (transaction) {
+ params.lock = transaction.LOCK.UPDATE;
+ params.transaction = transaction;
+ }
+
+ let user = await db.User.findOne(params);
user = user.get({ plain: true });
- user.payments = await db.Payment.findAll({
+ params = {
order: [["id", "DESC"]],
where: {
user_id: user.id,
@@ -35,13 +42,20 @@ getUser = async username => {
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 => {
- let user = await db.User.findOne({
+getUserById = async (id, transaction) => {
+ let params = {
include: [
{
model: db.Account,
@@ -53,11 +67,18 @@ getUserById = async id => {
}
],
where: { id }
- });
+ };
+
+ if (transaction) {
+ params.lock = transaction.LOCK.UPDATE;
+ params.transaction = transaction;
+ }
+
+ let user = await db.User.findOne(params);
user = user.get({ plain: true });
- user.payments = await db.Payment.findAll({
+ params = {
order: [["id", "DESC"]],
where: {
user_id: user.id,
@@ -74,7 +95,14 @@ getUserById = async id => {
model: db.Account,
as: "account"
}
- });
+ };
+
+ if (transaction) {
+ params.lock = transaction.LOCK.UPDATE;
+ params.transaction = transaction;
+ }
+
+ user.payments = await db.Payment.findAll(params);
return user;
};