mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into open-creations-call
This commit is contained in:
commit
0c65d8c4ab
@ -32,7 +32,7 @@ export class BalanceResolver {
|
|||||||
|
|
||||||
const lastTransaction = context.lastTransaction
|
const lastTransaction = context.lastTransaction
|
||||||
? context.lastTransaction
|
? context.lastTransaction
|
||||||
: await dbTransaction.findOne({ userId: user.id }, { order: { balanceDate: 'DESC' } })
|
: await dbTransaction.findOne({ userId: user.id }, { order: { id: 'DESC' } })
|
||||||
|
|
||||||
logger.debug(`lastTransaction=${lastTransaction}`)
|
logger.debug(`lastTransaction=${lastTransaction}`)
|
||||||
|
|
||||||
|
|||||||
@ -1947,6 +1947,23 @@ describe('ContributionResolver', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('confirm same contribution again', () => {
|
||||||
|
it('throws an error', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({
|
||||||
|
mutation: confirmContribution,
|
||||||
|
variables: {
|
||||||
|
id: creation ? creation.id : -1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('Contribution already confirmd.')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('confirm two creations one after the other quickly', () => {
|
describe('confirm two creations one after the other quickly', () => {
|
||||||
|
|||||||
@ -555,12 +555,20 @@ export class ContributionResolver {
|
|||||||
@Arg('id', () => Int) id: number,
|
@Arg('id', () => Int) id: number,
|
||||||
@Ctx() context: Context,
|
@Ctx() context: Context,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
// acquire lock
|
||||||
|
const releaseLock = await TRANSACTIONS_LOCK.acquire()
|
||||||
|
|
||||||
|
try {
|
||||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||||
const contribution = await DbContribution.findOne(id)
|
const contribution = await DbContribution.findOne(id)
|
||||||
if (!contribution) {
|
if (!contribution) {
|
||||||
logger.error(`Contribution not found for given id: ${id}`)
|
logger.error(`Contribution not found for given id: ${id}`)
|
||||||
throw new Error('Contribution not found to given id.')
|
throw new Error('Contribution not found to given id.')
|
||||||
}
|
}
|
||||||
|
if (contribution.confirmedAt) {
|
||||||
|
logger.error(`Contribution already confirmd: ${id}`)
|
||||||
|
throw new Error('Contribution already confirmd.')
|
||||||
|
}
|
||||||
const moderatorUser = getUser(context)
|
const moderatorUser = getUser(context)
|
||||||
if (moderatorUser.id === contribution.userId) {
|
if (moderatorUser.id === contribution.userId) {
|
||||||
logger.error('Moderator can not confirm own contribution')
|
logger.error('Moderator can not confirm own contribution')
|
||||||
@ -582,9 +590,6 @@ export class ContributionResolver {
|
|||||||
clientTimezoneOffset,
|
clientTimezoneOffset,
|
||||||
)
|
)
|
||||||
|
|
||||||
// acquire lock
|
|
||||||
const releaseLock = await TRANSACTIONS_LOCK.acquire()
|
|
||||||
|
|
||||||
const receivedCallDate = new Date()
|
const receivedCallDate = new Date()
|
||||||
const queryRunner = getConnection().createQueryRunner()
|
const queryRunner = getConnection().createQueryRunner()
|
||||||
await queryRunner.connect()
|
await queryRunner.connect()
|
||||||
@ -648,7 +653,6 @@ export class ContributionResolver {
|
|||||||
throw new Error('Creation was not successful.')
|
throw new Error('Creation was not successful.')
|
||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
releaseLock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = new Event()
|
const event = new Event()
|
||||||
@ -657,6 +661,10 @@ export class ContributionResolver {
|
|||||||
eventContributionConfirm.amount = contribution.amount
|
eventContributionConfirm.amount = contribution.amount
|
||||||
eventContributionConfirm.contributionId = contribution.id
|
eventContributionConfirm.contributionId = contribution.id
|
||||||
await eventProtocol.writeEvent(event.setEventContributionConfirm(eventContributionConfirm))
|
await eventProtocol.writeEvent(event.setEventContributionConfirm(eventContributionConfirm))
|
||||||
|
} finally {
|
||||||
|
releaseLock()
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -211,7 +211,7 @@ export class TransactionResolver {
|
|||||||
// find current balance
|
// find current balance
|
||||||
const lastTransaction = await dbTransaction.findOne(
|
const lastTransaction = await dbTransaction.findOne(
|
||||||
{ userId: user.id },
|
{ userId: user.id },
|
||||||
{ order: { balanceDate: 'DESC' }, relations: ['contribution'] },
|
{ order: { id: 'DESC' }, relations: ['contribution'] },
|
||||||
)
|
)
|
||||||
logger.debug(`lastTransaction=${lastTransaction}`)
|
logger.debug(`lastTransaction=${lastTransaction}`)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user