From d2e12ef23d46f00fb31be4b45ee3273125c91f89 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Tue, 4 Nov 2025 10:56:20 -0800 Subject: [PATCH] =?UTF-8?q?fix(models/point-transaction):=20align=20find()?= =?UTF-8?q?=20consumers=20to=20array=20API=20and=20correct=20balance/histo?= =?UTF-8?q?ry=20accessors\n\nUpdates=20findByUser/findByType/getUserBalanc?= =?UTF-8?q?e/getUserTransactionHistory=20to=20consume=20couchdbService.fin?= =?UTF-8?q?d=20as=20an=20array,=20removing=20result.docs=20assumptions.=20?= =?UTF-8?q?Prevents=20undefined=20access=20and=20ensures=20correct=20balan?= =?UTF-8?q?ce=20retrieval.\n\n=F0=9F=A4=96=20Generated=20with=20[AI=20Assi?= =?UTF-8?q?stant]\n\nCo-Authored-By:=20AI=20Assistant=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/models/PointTransaction.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/models/PointTransaction.js b/backend/models/PointTransaction.js index 389b621..819288e 100644 --- a/backend/models/PointTransaction.js +++ b/backend/models/PointTransaction.js @@ -90,7 +90,7 @@ class PointTransaction { const errorContext = createErrorContext('PointTransaction', 'findByUser', { userId, limit, skip }); return await withErrorHandling(async () => { - const result = await couchdbService.find({ + const docs = await couchdbService.find({ selector: { type: 'point_transaction', user: userId @@ -99,7 +99,7 @@ class PointTransaction { limit: limit, skip: skip }); - return result.docs; + return docs; }, errorContext); } @@ -107,7 +107,7 @@ class PointTransaction { const errorContext = createErrorContext('PointTransaction', 'findByType', { transactionType, limit, skip }); return await withErrorHandling(async () => { - const result = await couchdbService.find({ + const docs = await couchdbService.find({ selector: { type: 'point_transaction', transactionType: transactionType @@ -116,7 +116,7 @@ class PointTransaction { limit: limit, skip: skip }); - return result.docs; + return docs; }, errorContext); } @@ -144,7 +144,7 @@ class PointTransaction { return await withErrorHandling(async () => { // Get the most recent transaction for the user to find current balance - const result = await couchdbService.find({ + const transactions = await couchdbService.find({ selector: { type: 'point_transaction', user: userId @@ -153,11 +153,11 @@ class PointTransaction { limit: 1 }); - if (result.docs.length === 0) { + if (transactions.length === 0) { return 0; } - return result.docs[0].balanceAfter; + return transactions[0].balanceAfter; }, errorContext); } @@ -180,12 +180,12 @@ class PointTransaction { } } - const result = await couchdbService.find({ + const transactions = await couchdbService.find({ selector: selector, sort: [{ createdAt: 'desc' }] }); - return result.docs; + return transactions; }, errorContext); } @@ -222,4 +222,4 @@ class PointTransaction { } } -module.exports = PointTransaction; \ No newline at end of file +module.exports = PointTransaction;