mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix validation rules for redeem contribution link
This commit is contained in:
parent
1bfd463a2d
commit
9ca1ee3455
@ -197,7 +197,7 @@ export class TransactionLinkResolver {
|
|||||||
throw new Error('Contribution link not valid yet')
|
throw new Error('Contribution link not valid yet')
|
||||||
}
|
}
|
||||||
if (contributionLink.validTo) {
|
if (contributionLink.validTo) {
|
||||||
if (new Date(contributionLink.validTo).setHours(23, 59, 59) > now.getTime()) {
|
if (new Date(contributionLink.validTo).setHours(23, 59, 59) < now.getTime()) {
|
||||||
logger.error('contribution link is depricated. Valid to: ', contributionLink.validTo)
|
logger.error('contribution link is depricated. Valid to: ', contributionLink.validTo)
|
||||||
throw new Error('Contribution link is depricated')
|
throw new Error('Contribution link is depricated')
|
||||||
}
|
}
|
||||||
@ -206,6 +206,21 @@ export class TransactionLinkResolver {
|
|||||||
logger.error('contribution link has unknown cycle', contributionLink.cycle)
|
logger.error('contribution link has unknown cycle', contributionLink.cycle)
|
||||||
throw new Error('Contribution link has unknown cycle')
|
throw new Error('Contribution link has unknown cycle')
|
||||||
}
|
}
|
||||||
|
// Test ONCE rule
|
||||||
|
const alreadyRedeemed = await queryRunner.manager
|
||||||
|
.createQueryBuilder()
|
||||||
|
.select('contribution')
|
||||||
|
.from(DbContribution, 'contribution')
|
||||||
|
.where('contribution.contributionLinkId = :linkId AND contribution.userId = :id', {
|
||||||
|
linkId: contributionLink.id,
|
||||||
|
id: user.id,
|
||||||
|
})
|
||||||
|
.getOne()
|
||||||
|
if (alreadyRedeemed) {
|
||||||
|
logger.error('contribution link with rule ONCE already redeemed by user with id', user.id)
|
||||||
|
throw new Error('Contribution link already redeemed')
|
||||||
|
}
|
||||||
|
|
||||||
const creations = await getUserCreation(user.id, false)
|
const creations = await getUserCreation(user.id, false)
|
||||||
logger.info('open creations', creations)
|
logger.info('open creations', creations)
|
||||||
if (!isContributionValid(creations, contributionLink.amount, now)) {
|
if (!isContributionValid(creations, contributionLink.amount, now)) {
|
||||||
@ -262,7 +277,7 @@ export class TransactionLinkResolver {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
await queryRunner.rollbackTransaction()
|
await queryRunner.rollbackTransaction()
|
||||||
logger.error(`Creation from contribution link was not successful: ${e}`)
|
logger.error(`Creation from contribution link was not successful: ${e}`)
|
||||||
throw new Error(`Creation from contribution link was not successful.`)
|
throw new Error(`Creation from contribution link was not successful. ${e}`)
|
||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export const contributionLinks: ContributionLinkInterface[] = [
|
|||||||
name: 'Dokumenta 2022',
|
name: 'Dokumenta 2022',
|
||||||
memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2022',
|
memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2022',
|
||||||
amount: 200,
|
amount: 200,
|
||||||
validFrom: new Date(2022, 5, 18),
|
validFrom: new Date(2022, 5, 16),
|
||||||
validTo: new Date(2022, 8, 25),
|
validTo: new Date(2022, 8, 25),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user