Refactor updateCreations.

This commit is contained in:
elweyn 2022-07-04 07:40:10 +02:00
parent 78195612c2
commit b580f8755d
2 changed files with 12 additions and 10 deletions

View File

@ -52,6 +52,7 @@ import {
getUserCreations,
isContributionValid,
isStartEndDateValid,
updateCreations,
} from './util/isContributionValid'
import {
CONTRIBUTIONLINK_MEMO_MAX_CHARS,
@ -688,13 +689,3 @@ export class AdminResolver {
return new ContributionLink(dbContributionLink)
}
}
function updateCreations(creations: Decimal[], contribution: Contribution): Decimal[] {
const index = getCreationIndex(contribution.contributionDate.getMonth())
if (index < 0) {
throw new Error('You cannot create GDD for a month older than the last three months.')
}
creations[index] = creations[index].plus(contribution.amount.toString())
return creations
}

View File

@ -1,6 +1,7 @@
import { TransactionTypeId } from '@/graphql/enum/TransactionTypeId'
import { backendLogger as logger } from '@/server/logger'
import { getConnection } from '@dbTools/typeorm'
import { Contribution } from '@entity/Contribution'
import Decimal from 'decimal.js-light'
import { FULL_CREATION_AVAILABLE, MAX_CREATION_AMOUNT } from '../const/const'
@ -117,3 +118,13 @@ export const isStartEndDateValid = (
throw new Error(`The value of validFrom must before or equals the validTo!`)
}
}
export const updateCreations = (creations: Decimal[], contribution: Contribution): Decimal[] => {
const index = getCreationIndex(contribution.contributionDate.getMonth())
if (index < 0) {
throw new Error('You cannot create GDD for a month older than the last three months.')
}
creations[index] = creations[index].plus(contribution.amount.toString())
return creations
}