payment
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions

This commit is contained in:
Dmitry 2026-01-06 23:43:52 +03:00
parent 39eeda7fa7
commit c2e213d40e

View file

@ -51,15 +51,15 @@ class PaymentDao extends DatabaseAccessor<AppDatabase>
// (database needs to be regenerated to include id in Payment class)
// Use externalToken if available, otherwise query by unique fields
if (inserted.externalToken != null && inserted.externalToken!.isNotEmpty) {
final result = await (customSelect(
final results = await (customSelect(
'SELECT id FROM payments WHERE external_token = ? LIMIT 1',
variables: [Variable.withString(inserted.externalToken!)],
readsFrom: {payments},
).map((row) => row.read<String>('id')).getSingleOrNull());
if (result != null) return result;
).map((row) => row.read<String>('id')).get());
if (results.isNotEmpty) return results.first;
}
// Fallback: query by userId, date, and amount
final result = await (customSelect(
final results = await (customSelect(
'SELECT id FROM payments WHERE user_id = ? AND date = ? AND amount = ? ORDER BY created_at DESC LIMIT 1',
variables: [
Variable.withString(payment.userId.value),
@ -67,8 +67,8 @@ class PaymentDao extends DatabaseAccessor<AppDatabase>
Variable.withString(inserted.amount),
],
readsFrom: {payments},
).map((row) => row.read<String>('id')).getSingleOrNull());
if (result != null) return result;
).map((row) => row.read<String>('id')).get());
if (results.isNotEmpty) return results.first;
throw Exception('Failed to retrieve payment ID after creation');
}
@ -154,7 +154,6 @@ class PaymentDao extends DatabaseAccessor<AppDatabase>
}
/// Подсчитать платежи пользователя (только активные)
@override
Future<int> countPaymentsByUserId(String userId) async {
final countExpr = payments.id.count();
final query = selectOnly(payments)