mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-12 23:35:50 +00:00
fix another order by id instead of balanceDate.
Have the now calculation for contribution links within the semaphore lock
This commit is contained in:
parent
f306dddfaf
commit
55236f1f8e
@ -166,13 +166,13 @@ export class TransactionLinkResolver {
|
||||
): Promise<boolean> {
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
const user = getUser(context)
|
||||
const now = new Date()
|
||||
|
||||
if (code.match(/^CL-/)) {
|
||||
// acquire lock
|
||||
const releaseLock = await TRANSACTIONS_LOCK.acquire()
|
||||
console.log(`locked for redeemTransactionLink ${code}`)
|
||||
logger.info('redeem contribution link...')
|
||||
const now = new Date()
|
||||
const queryRunner = getConnection().createQueryRunner()
|
||||
await queryRunner.connect()
|
||||
await queryRunner.startTransaction('REPEATABLE READ')
|
||||
@ -277,7 +277,7 @@ export class TransactionLinkResolver {
|
||||
.select('transaction')
|
||||
.from(DbTransaction, 'transaction')
|
||||
.where('transaction.userId = :id', { id: user.id })
|
||||
.orderBy('transaction.balanceDate', 'DESC')
|
||||
.orderBy('transaction.id', 'DESC')
|
||||
.getOne()
|
||||
let newBalance = new Decimal(0)
|
||||
|
||||
@ -318,6 +318,7 @@ export class TransactionLinkResolver {
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
const now = new Date()
|
||||
const transactionLink = await DbTransactionLink.findOneOrFail({ code })
|
||||
const linkedUser = await DbUser.findOneOrFail(
|
||||
{ id: transactionLink.userId },
|
||||
@ -328,6 +329,9 @@ export class TransactionLinkResolver {
|
||||
throw new Error('Cannot redeem own transaction link.')
|
||||
}
|
||||
|
||||
// TODO: The now check should be done within the semaphore lock,
|
||||
// since the program might wait a while till it is ready to proceed
|
||||
// writing the transaction.
|
||||
if (transactionLink.validUntil.getTime() < now.getTime()) {
|
||||
throw new Error('Transaction Link is not valid anymore.')
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user