mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2677 from gradido/logger_creations
refactor(backend): use LogError on creations
This commit is contained in:
commit
2f020cf06c
@ -257,17 +257,13 @@ describe('Contribution Links', () => {
|
|||||||
}),
|
}),
|
||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
errors: [
|
errors: [new GraphQLError('A Start-Date must be set')],
|
||||||
new GraphQLError('Start-Date is not initialized. A Start-Date must be set!'),
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith('A Start-Date must be set')
|
||||||
'Start-Date is not initialized. A Start-Date must be set!',
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns an error if missing endDate', async () => {
|
it('returns an error if missing endDate', async () => {
|
||||||
@ -282,15 +278,13 @@ describe('Contribution Links', () => {
|
|||||||
}),
|
}),
|
||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
errors: [new GraphQLError('End-Date is not initialized. An End-Date must be set!')],
|
errors: [new GraphQLError('An End-Date must be set')],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith('An End-Date must be set')
|
||||||
'End-Date is not initialized. An End-Date must be set!',
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns an error if endDate is before startDate', async () => {
|
it('returns an error if endDate is before startDate', async () => {
|
||||||
@ -307,7 +301,7 @@ describe('Contribution Links', () => {
|
|||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
errors: [
|
errors: [
|
||||||
new GraphQLError(`The value of validFrom must before or equals the validTo!`),
|
new GraphQLError(`The value of validFrom must before or equals the validTo`),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -315,7 +309,7 @@ describe('Contribution Links', () => {
|
|||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
`The value of validFrom must before or equals the validTo!`,
|
`The value of validFrom must before or equals the validTo`,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -245,8 +245,8 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error found', () => {
|
it('logs the error found', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'No information for available creations with the given creationDate=',
|
'No information for available creations for the given date',
|
||||||
'Invalid Date',
|
expect.any(Date),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -268,8 +268,8 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error found', () => {
|
it('logs the error found', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'No information for available creations with the given creationDate=',
|
'No information for available creations for the given date',
|
||||||
'Invalid Date',
|
expect.any(Date),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -526,14 +526,16 @@ describe('ContributionResolver', () => {
|
|||||||
})
|
})
|
||||||
expect(errorObjects).toEqual([
|
expect(errorObjects).toEqual([
|
||||||
new GraphQLError(
|
new GraphQLError(
|
||||||
'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('logs the error found', () => {
|
it('logs the error found', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
|
new Decimal(1019),
|
||||||
|
new Decimal(600),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -2008,8 +2010,8 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'No information for available creations with the given creationDate=',
|
'No information for available creations for the given date',
|
||||||
new Date(variables.creationDate).toString(),
|
new Date(variables.creationDate),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -2033,8 +2035,8 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'No information for available creations with the given creationDate=',
|
'No information for available creations for the given date',
|
||||||
new Date(variables.creationDate).toString(),
|
new Date(variables.creationDate),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -2049,7 +2051,7 @@ describe('ContributionResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
errors: [
|
errors: [
|
||||||
new GraphQLError(
|
new GraphQLError(
|
||||||
'The amount (2000 GDD) to be created exceeds the amount (790 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -2058,7 +2060,9 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'The amount (2000 GDD) to be created exceeds the amount (790 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
|
new Decimal(2000),
|
||||||
|
new Decimal(790),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -2098,7 +2102,7 @@ describe('ContributionResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
errors: [
|
errors: [
|
||||||
new GraphQLError(
|
new GraphQLError(
|
||||||
'The amount (1000 GDD) to be created exceeds the amount (590 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -2107,7 +2111,9 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'The amount (1000 GDD) to be created exceeds the amount (590 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
|
new Decimal(1000),
|
||||||
|
new Decimal(590),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -2300,7 +2306,7 @@ describe('ContributionResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
errors: [
|
errors: [
|
||||||
new GraphQLError(
|
new GraphQLError(
|
||||||
'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -2309,7 +2315,9 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
it('logs the error thrown', () => {
|
it('logs the error thrown', () => {
|
||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
|
new Decimal(1900),
|
||||||
|
new Decimal(1000),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -362,7 +362,7 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect(logger.error).toBeCalledWith(
|
expect(logger.error).toBeCalledWith(
|
||||||
'Creation from contribution link was not successful',
|
'Creation from contribution link was not successful',
|
||||||
new Error(
|
new Error(
|
||||||
'The amount (5 GDD) to be created exceeds the amount (0 GDD) still available for this month.',
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import LogError from '@/server/LogError'
|
||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { getConnection } from '@dbTools/typeorm'
|
import { getConnection } from '@dbTools/typeorm'
|
||||||
import { Contribution } from '@entity/Contribution'
|
import { Contribution } from '@entity/Contribution'
|
||||||
@ -19,19 +20,14 @@ export const validateContribution = (
|
|||||||
const index = getCreationIndex(creationDate.getMonth(), timezoneOffset)
|
const index = getCreationIndex(creationDate.getMonth(), timezoneOffset)
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
logger.error(
|
throw new LogError('No information for available creations for the given date', creationDate)
|
||||||
'No information for available creations with the given creationDate=',
|
|
||||||
creationDate.toString(),
|
|
||||||
)
|
|
||||||
throw new Error('No information for available creations for the given date')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amount.greaterThan(creations[index].toString())) {
|
if (amount.greaterThan(creations[index].toString())) {
|
||||||
logger.error(
|
throw new LogError(
|
||||||
`The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`,
|
'The amount to be created exceeds the amount still available for this month',
|
||||||
)
|
amount,
|
||||||
throw new Error(
|
creations[index],
|
||||||
`The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,19 +122,16 @@ export const isStartEndDateValid = (
|
|||||||
endDate: string | null | undefined,
|
endDate: string | null | undefined,
|
||||||
): void => {
|
): void => {
|
||||||
if (!startDate) {
|
if (!startDate) {
|
||||||
logger.error('Start-Date is not initialized. A Start-Date must be set!')
|
throw new LogError('A Start-Date must be set')
|
||||||
throw new Error('Start-Date is not initialized. A Start-Date must be set!')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!endDate) {
|
if (!endDate) {
|
||||||
logger.error('End-Date is not initialized. An End-Date must be set!')
|
throw new LogError('An End-Date must be set')
|
||||||
throw new Error('End-Date is not initialized. An End-Date must be set!')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if endDate is before startDate
|
// check if endDate is before startDate
|
||||||
if (new Date(endDate).getTime() - new Date(startDate).getTime() < 0) {
|
if (new Date(endDate).getTime() - new Date(startDate).getTime() < 0) {
|
||||||
logger.error(`The value of validFrom must before or equals the validTo!`)
|
throw new LogError(`The value of validFrom must before or equals the validTo`)
|
||||||
throw new Error(`The value of validFrom must before or equals the validTo!`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user