From c585b2c234e1c577d1ce47d006e72e2b95f04bbb Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 11 Jan 2023 13:08:47 +0100 Subject: [PATCH] check for confirmed transaction within semaphore lock --- .../src/graphql/resolver/ContributionResolver.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 2587aab61..4c78ae1e7 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -553,11 +553,15 @@ export class ContributionResolver { @Arg('id', () => Int) id: number, @Ctx() context: Context, ): Promise { + // acquire lock + const releaseLock = await TRANSACTIONS_LOCK.acquire() + const clientTimezoneOffset = getClientTimezoneOffset(context) - const contribution = await DbContribution.findOne(id) + + const contribution = await DbContribution.findOne({ id, confirmedAt: IsNull() }) if (!contribution) { - logger.error(`Contribution not found for given id: ${id}`) - throw new Error('Contribution not found to given id.') + logger.error(`Contribution not found to given id (${id}) or already confirmed`) + throw new Error('Contribution not found to given id or already confirmed.') } const moderatorUser = getUser(context) if (moderatorUser.id === contribution.userId) { @@ -580,9 +584,6 @@ export class ContributionResolver { clientTimezoneOffset, ) - // acquire lock - const releaseLock = await TRANSACTIONS_LOCK.acquire() - const receivedCallDate = new Date() const queryRunner = getConnection().createQueryRunner() await queryRunner.connect()