aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-08-23 15:56:16 -0700
committerAdam Soltys <[email protected]>2022-08-23 15:56:16 -0700
commit73685635d43e344abac591cb9ffa1e38c8d0f911 (patch)
tree76f0f516fbb989252ca959cdb8f44b9caad94987 /routes
parent653d14e8f7b8bee93847f1d330ad1d38ac2ffddf (diff)
parent3f144a605f8f24c526581a2050d21a62b66c2f72 (diff)
downloadcoinos-server-73685635d43e344abac591cb9ffa1e38c8d0f911.tar.gz
coinos-server-73685635d43e344abac591cb9ffa1e38c8d0f911.zip
Merge branch 'master' into prod
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.js2
-rw-r--r--routes/send.js1
-rw-r--r--routes/users.js8
3 files changed, 9 insertions, 2 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index b5650735..02a8308d 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -12,7 +12,7 @@ app.get(
include: {
model: db.User,
as: "user",
- attributes: ['username']
+ attributes: ['username', 'currency']
}
});
diff --git a/routes/send.js b/routes/send.js
index 4c8afa34..653da87b 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -66,7 +66,6 @@ module.exports = ah(async (req, res, next) => {
};
if (!username) {
- throw new Error("Vouchers temporarily disabled");
l.info("creating redeemable payment");
params.redeemcode = uuidv4();
params.hash = `${req.get("origin")}/redeem/${params.redeemcode}`;
diff --git a/routes/users.js b/routes/users.js
index 4fe1362b..c9367c9a 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -634,12 +634,16 @@ app.post(
})
);
+let redeeming = {};
app.post(
"/redeem",
optionalAuth,
ah(async function(req, res) {
+ try {
await db.transaction(async transaction => {
const { redeemcode } = req.body;
+ if (redeeming[redeemcode]) fail("redemption in progress");
+ redeeming[redeemcode] = true;
if (!redeemcode) fail("no code provided");
let { user } = req;
@@ -652,6 +656,7 @@ app.post(
model: db.Account,
as: "account"
},
+ lock: transaction.LOCK.UPDATE,
transaction
});
@@ -717,6 +722,9 @@ app.post(
res.send({ payment });
});
+ } catch(e) {
+ l.error("problem redeeming", e.message);
+ return res.status(500).send("There was a problem redeeming the voucher");
})
);