fixes
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
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:
parent
f36b440bff
commit
496aac9135
1 changed files with 26 additions and 25 deletions
|
|
@ -58,39 +58,40 @@ class PaymentDao extends DatabaseAccessor<AppDatabase>
|
|||
final inserted = await into(payments).insertReturning(payment);
|
||||
print('✅ PaymentDao.createPayment: Payment inserted, date=${inserted.date.dateTime}');
|
||||
|
||||
// Query back to get the id since Payment class doesn't have id field
|
||||
// (database needs to be regenerated to include id in Payment class)
|
||||
// Try to get id from inserted object first
|
||||
if (inserted.id.isNotEmpty) {
|
||||
print('✅ PaymentDao.createPayment: Got id from inserted object, id=${inserted.id}');
|
||||
return inserted.id;
|
||||
}
|
||||
|
||||
// Query back to get the id using type-safe queries
|
||||
// Use externalToken if available, otherwise query by unique fields
|
||||
if (inserted.externalToken != null && inserted.externalToken!.isNotEmpty) {
|
||||
print('🔍 PaymentDao.createPayment: Querying by externalToken=${inserted.externalToken}');
|
||||
print('🔍 PaymentDao.createPayment: SQL: SELECT id FROM payments WHERE external_token = ? LIMIT 1');
|
||||
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')).get());
|
||||
if (results.isNotEmpty) {
|
||||
print('✅ PaymentDao.createPayment: Found payment by externalToken, id=${results.first}');
|
||||
return results.first;
|
||||
final foundPayment = await getPaymentByExternalToken(inserted.externalToken!);
|
||||
if (foundPayment != null && foundPayment.id.isNotEmpty) {
|
||||
print('✅ PaymentDao.createPayment: Found payment by externalToken, id=${foundPayment.id}');
|
||||
return foundPayment.id;
|
||||
}
|
||||
print('⚠️ PaymentDao.createPayment: No payment found by externalToken');
|
||||
}
|
||||
// Fallback: query by userId, date, and amount
|
||||
|
||||
// Fallback: query by userId, date, and amount using type-safe queries
|
||||
print('🔍 PaymentDao.createPayment: Querying by userId, date, amount (fallback)');
|
||||
print('🔍 PaymentDao.createPayment: SQL: SELECT id FROM payments WHERE user_id = ? AND date = ? AND amount = ? ORDER BY created_at DESC LIMIT 1');
|
||||
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),
|
||||
Variable.withDateTime(inserted.date.dateTime),
|
||||
Variable.withString(inserted.amount),
|
||||
],
|
||||
readsFrom: {payments},
|
||||
).map((row) => row.read<String>('id')).get());
|
||||
if (results.isNotEmpty) {
|
||||
print('✅ PaymentDao.createPayment: Found payment by fallback query, id=${results.first}');
|
||||
return results.first;
|
||||
final query = select(payments)
|
||||
..where((p) =>
|
||||
p.userId.equals(payment.userId.value) &
|
||||
p.date.equals(inserted.date) &
|
||||
p.amount.equals(inserted.amount))
|
||||
..orderBy([(p) => OrderingTerm.desc(p.createdAt)])
|
||||
..limit(1);
|
||||
|
||||
final results = await query.get();
|
||||
if (results.isNotEmpty && results.first.id.isNotEmpty) {
|
||||
print('✅ PaymentDao.createPayment: Found payment by fallback query, id=${results.first.id}');
|
||||
return results.first.id;
|
||||
}
|
||||
|
||||
print('❌ PaymentDao.createPayment: Failed to retrieve payment ID after creation');
|
||||
throw Exception('Failed to retrieve payment ID after creation');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue