mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add global event handler middleware
This commit is contained in:
parent
7ecd96d28b
commit
bab867a1bd
@ -10,7 +10,7 @@ Decimal.set({
|
||||
})
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0040-add_contribution_link_id_to_user',
|
||||
DB_VERSION: '0041-add_event_protocol_table',
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { GraphQLSchema } from 'graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
import path from 'path'
|
||||
import { EventHandler } from '@/middleware/EventHandler'
|
||||
|
||||
import isAuthorized from './directive/isAuthorized'
|
||||
import DecimalScalar from './scalar/Decimal'
|
||||
@ -11,6 +12,7 @@ const schema = async (): Promise<GraphQLSchema> => {
|
||||
resolvers: [path.join(__dirname, 'resolver', `!(*.test).{js,ts}`)],
|
||||
authChecker: isAuthorized,
|
||||
scalarsMap: [{ type: Decimal, scalar: DecimalScalar }],
|
||||
globalMiddlewares: [EventHandler],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
15
backend/src/middleware/EventHandler.ts
Normal file
15
backend/src/middleware/EventHandler.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { MiddlewareFn } from 'type-graphql'
|
||||
import { EventProtocol } from '@entity/EventProtocol'
|
||||
|
||||
export const EventHandler: MiddlewareFn = async (
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
||||
{ root, args, context, info },
|
||||
next,
|
||||
) => {
|
||||
const event = new EventProtocol()
|
||||
// set values before calling the resolver here
|
||||
const result = await next()
|
||||
// set event values here when having the result ...
|
||||
await event.save()
|
||||
return result
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user