mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
add logging for automatic validation
This commit is contained in:
parent
7c4d55928f
commit
51d1c6b64b
@ -1,9 +1,12 @@
|
||||
import path from 'path'
|
||||
|
||||
import { validate } from 'class-validator'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { GraphQLSchema } from 'graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
|
||||
import { LogError } from '@/server/LogError'
|
||||
|
||||
import { isAuthorized } from './directive/isAuthorized'
|
||||
import { DecimalScalar } from './scalar/Decimal'
|
||||
|
||||
@ -12,5 +15,20 @@ export const schema = async (): Promise<GraphQLSchema> => {
|
||||
resolvers: [path.join(__dirname, 'resolver', `!(*.test).{js,ts}`)],
|
||||
authChecker: isAuthorized,
|
||||
scalarsMap: [{ type: Decimal, scalar: DecimalScalar }],
|
||||
validate: (argValue) => {
|
||||
if (argValue) {
|
||||
validate(argValue)
|
||||
.then((errors) => {
|
||||
if (errors.length > 0) {
|
||||
throw new LogError('validation failed. errors: ', errors)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
throw new LogError('validation throw an exception: ', e)
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user