mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
25 lines
735 B
TypeScript
25 lines
735 B
TypeScript
import { backendLogger as logger } from '@/server/logger'
|
|
import Decimal from 'decimal.js-light'
|
|
import { getCreationIndex } from '../AdminResolver'
|
|
|
|
export const isContributionValid = (
|
|
creations: Decimal[],
|
|
amount: Decimal,
|
|
creationDate: Date,
|
|
): boolean => {
|
|
logger.trace('isContributionValid', creations, amount, creationDate)
|
|
const index = getCreationIndex(creationDate.getMonth())
|
|
|
|
if (index < 0) {
|
|
throw new Error('No information for available creations for the given date')
|
|
}
|
|
|
|
if (amount.greaterThan(creations[index].toString())) {
|
|
throw new Error(
|
|
`The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`,
|
|
)
|
|
}
|
|
|
|
return true
|
|
}
|