aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-10-26 15:32:10 -0700
committerAdam Soltys <[email protected]>2022-10-26 15:32:10 -0700
commit25f27e55943562215139de8a11db07d1cfb6df5f (patch)
tree81d860345b8163611aee6c2ed30c5cf4a9fa75bd
parent6c597132a7424317d2db33a11b6cff86c24875b1 (diff)
downloadcoinos-server-25f27e55943562215139de8a11db07d1cfb6df5f.tar.gz
coinos-server-25f27e55943562215139de8a11db07d1cfb6df5f.zip
payment pagination
-rw-r--r--routes/payments.js37
1 files changed, 30 insertions, 7 deletions
diff --git a/routes/payments.js b/routes/payments.js
index 7a728daa..0cd45829 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -26,8 +26,6 @@ app.post("/send", auth, send);
app.post("/sendToTokenHolders", auth, async (req, res, next) => {
let { asset, amount } = req.body;
-
-
let accounts = await db.Account.findAll({
where: {
asset,
@@ -103,19 +101,44 @@ setTimeout(async () => {
}, 50);
app.get("/payments", auth, async (req, res) => {
+ let { start, end, limit, offset, v2 } = req.query;
+
+ if (limit) limit = parseInt(limit);
+ if (offset) offset = parseInt(offset);
+
+ let dayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
+
+ let where = {
+ account_id: req.user.account_id,
+ createdAt: { [Op.gte]: dayAgo }
+ };
+
+ if (start) where.createdAt[Op.gte] = new Date(start * 1000);
+ if (end) where.createdAt[Op.lte] = new Date(end * 1000);
+
if (!req.user.account_id) return res.send([]);
+
+ let total = await db.Payment.count({
+ where
+ });
+
let payments = await db.Payment.findAll({
- where: {
- account_id: req.user.account_id
- },
+ where,
order: [["id", "DESC"]],
include: {
model: db.Account,
as: "account"
- }
+ },
+ limit,
+ offset
});
- res.send(payments);
+
+ if (v2) {
+ res.send({ transactions: payments, total });
+ } else {
+ res.send(payments);
+ }
});
app.get("/payment/:redeemcode", async (req, res) => {