mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
test for valid date string for creation date
This commit is contained in:
parent
5e2d6c3bc9
commit
2b27e6aaa8
@ -1066,7 +1066,7 @@ describe('AdminResolver', () => {
|
||||
it('logs the error thrown', () => {
|
||||
expect(logger.error).toBeCalledWith(
|
||||
'No information for available creations with the given creationDate=',
|
||||
new Date(variables.creationDate).toISOString(),
|
||||
new Date(variables.creationDate).toString(),
|
||||
)
|
||||
})
|
||||
})
|
||||
@ -1091,7 +1091,7 @@ describe('AdminResolver', () => {
|
||||
it('logs the error thrown', () => {
|
||||
expect(logger.error).toBeCalledWith(
|
||||
'No information for available creations with the given creationDate=',
|
||||
new Date(variables.creationDate).toISOString(),
|
||||
new Date(variables.creationDate).toString(),
|
||||
)
|
||||
})
|
||||
})
|
||||
@ -1353,7 +1353,7 @@ describe('AdminResolver', () => {
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
new GraphQLError(
|
||||
'The amount (1900 GDD) to be created exceeds the amount (600 GDD) still available for this month.',
|
||||
'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
|
||||
),
|
||||
],
|
||||
}),
|
||||
@ -1362,7 +1362,7 @@ describe('AdminResolver', () => {
|
||||
|
||||
it('logs the error thrown', () => {
|
||||
expect(logger.error).toBeCalledWith(
|
||||
'The amount (1900 GDD) to be created exceeds the amount (600 GDD) still available for this month.',
|
||||
'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@ -49,6 +49,7 @@ import {
|
||||
validateContribution,
|
||||
isStartEndDateValid,
|
||||
updateCreations,
|
||||
isValidDateString,
|
||||
} from './util/creations'
|
||||
import {
|
||||
CONTRIBUTIONLINK_NAME_MAX_CHARS,
|
||||
@ -237,6 +238,10 @@ export class AdminResolver {
|
||||
logger.info(
|
||||
`adminCreateContribution(email=${email}, amount=${amount}, memo=${memo}, creationDate=${creationDate})`,
|
||||
)
|
||||
if (!isValidDateString(creationDate)) {
|
||||
logger.error(`invalid Date for creationDate=${creationDate}`)
|
||||
throw new Error(`invalid Date for creationDate=${creationDate}`)
|
||||
}
|
||||
const emailContact = await UserContact.findOne({
|
||||
where: { email },
|
||||
withDeleted: true,
|
||||
|
||||
@ -137,3 +137,7 @@ export const updateCreations = (creations: Decimal[], contribution: Contribution
|
||||
creations[index] = creations[index].plus(contribution.amount.toString())
|
||||
return creations
|
||||
}
|
||||
|
||||
export const isValidDateString = (dateString: string): boolean => {
|
||||
return new Date(dateString).toString() !== 'Invalid Date'
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user