mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
remove EventEmitter from events-modul and replace it with
writeEvent-Methode
This commit is contained in:
parent
c570e5d2e5
commit
46e2473a88
@ -1,4 +1,3 @@
|
||||
import { EventEmitter } from 'events'
|
||||
import { Event } from '@/event/Event'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
// import { EventProtocolType } from './EventProtocolType'
|
||||
@ -6,7 +5,8 @@ import { EventProtocol } from '@entity/EventProtocol'
|
||||
// import { getConnection } from '@dbTools/typeorm'
|
||||
import CONFIG from '@/config'
|
||||
|
||||
class EventProtocolEmitter extends EventEmitter {
|
||||
class EventProtocolEmitter {
|
||||
/* }extends EventEmitter { */
|
||||
private events: Event[]
|
||||
|
||||
public addEvent(event: Event) {
|
||||
@ -21,9 +21,25 @@ class EventProtocolEmitter extends EventEmitter {
|
||||
logger.info(`EventProtocol - isEnabled=${CONFIG.EVENT_PROTOCOL_ENABLED}`)
|
||||
return CONFIG.EVENT_PROTOCOL_ENABLED
|
||||
}
|
||||
|
||||
public async writeEvent(event: Event): Promise<void> {
|
||||
// if (!eventProtocol.isEnabled()) return
|
||||
logger.info(`writeEvent(${JSON.stringify(event)})`)
|
||||
const dbEvent = new EventProtocol()
|
||||
dbEvent.type = event.type
|
||||
dbEvent.createdAt = event.createdAt
|
||||
dbEvent.userId = event.userId
|
||||
if (event.xUserId) dbEvent.xUserId = event.xUserId
|
||||
if (event.xCommunityId) dbEvent.xCommunityId = event.xCommunityId
|
||||
if (event.contributionId) dbEvent.contributionId = event.contributionId
|
||||
if (event.transactionId) dbEvent.transactionId = event.transactionId
|
||||
if (event.amount) dbEvent.amount = event.amount
|
||||
await dbEvent.save()
|
||||
}
|
||||
}
|
||||
export const eventProtocol = new EventProtocolEmitter()
|
||||
|
||||
/*
|
||||
eventProtocol.on('error', (err) => {
|
||||
logger.error(`ERROR in EventProtocol: ${err}`)
|
||||
})
|
||||
@ -37,18 +53,4 @@ eventProtocol.on('writeEvents', async (events: Event[]) => {
|
||||
eventProtocol.on('writeEvent', async (event: Event) => {
|
||||
await writeEvent(event)
|
||||
})
|
||||
|
||||
const writeEvent = async (event: Event): Promise<void> => {
|
||||
// if (!eventProtocol.isEnabled()) return
|
||||
logger.info(`writeEvent(${JSON.stringify(event)})`)
|
||||
const dbEvent = new EventProtocol()
|
||||
dbEvent.type = event.type
|
||||
dbEvent.createdAt = event.createdAt
|
||||
dbEvent.userId = event.userId
|
||||
if (event.xUserId) dbEvent.xUserId = event.xUserId
|
||||
if (event.xCommunityId) dbEvent.xCommunityId = event.xCommunityId
|
||||
if (event.contributionId) dbEvent.contributionId = event.contributionId
|
||||
if (event.transactionId) dbEvent.transactionId = event.transactionId
|
||||
if (event.amount) dbEvent.amount = event.amount
|
||||
await dbEvent.save()
|
||||
}
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user