fix(models/point-transaction): align find() consumers to array API and correct balance/history accessors\n\nUpdates findByUser/findByType/getUserBalance/getUserTransactionHistory to consume couchdbService.find as an array, removing result.docs assumptions. Prevents undefined access and ensures correct balance retrieval.\n\n🤖 Generated with [AI Assistant]\n\nCo-Authored-By: AI Assistant <noreply@ai-assistant.com>

This commit is contained in:
William Valentin
2025-11-04 10:56:20 -08:00
parent cfc9b09a1f
commit d2e12ef23d

View File

@@ -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;
module.exports = PointTransaction;