mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add enable-check to EventProtocol configurable as CONFIG-Property
This commit is contained in:
parent
38fcb0e9cf
commit
7f5995d2fa
@ -52,6 +52,9 @@ EMAIL_CODE_REQUEST_TIME=10
|
||||
# Webhook
|
||||
WEBHOOK_ELOPAGE_SECRET=secret
|
||||
|
||||
# EventProtocol
|
||||
EVENT_PROTOCOL_ENABLED=true
|
||||
|
||||
# SET LOG LEVEL AS NEEDED IN YOUR .ENV
|
||||
# POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal
|
||||
# LOG_LEVEL=info
|
||||
|
||||
@ -94,6 +94,11 @@ const webhook = {
|
||||
WEBHOOK_ELOPAGE_SECRET: process.env.WEBHOOK_ELOPAGE_SECRET || 'secret',
|
||||
}
|
||||
|
||||
const eventProtocol = {
|
||||
// global switch to enable writing of EventProtocol-Entries
|
||||
EVENT_PROTOCOL_ENABLED: process.env.EVENT_PROTOCOL_ENABLED === 'true' || false,
|
||||
}
|
||||
|
||||
// This is needed by graphql-directive-auth
|
||||
process.env.APP_SECRET = server.JWT_SECRET
|
||||
|
||||
@ -118,6 +123,7 @@ const CONFIG = {
|
||||
...email,
|
||||
...loginServer,
|
||||
...webhook,
|
||||
...eventProtocol,
|
||||
}
|
||||
|
||||
export default CONFIG
|
||||
|
||||
@ -4,8 +4,14 @@ import { EventProtocolType } from './EventProtocolType'
|
||||
import { EventProtocol } from '@entity/EventProtocol'
|
||||
import { getConnection } from '@dbTools/typeorm'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import CONFIG from '@/config'
|
||||
|
||||
class EventProtocolEmitter extends EventEmitter { }
|
||||
class EventProtocolEmitter extends EventEmitter {
|
||||
public isEnabled() {
|
||||
logger.info(`EventProtocol - isEnabled=${CONFIG.EVENT_PROTOCOL_ENABLED}`)
|
||||
return CONFIG.EVENT_PROTOCOL_ENABLED
|
||||
}
|
||||
}
|
||||
export const eventProtocol = new EventProtocolEmitter()
|
||||
|
||||
eventProtocol.on('error', (err) => {
|
||||
@ -329,11 +335,11 @@ async function writeEvent(
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
amount ? (dbEvent.amount = amount) : null
|
||||
// set event values here when having the result ...
|
||||
// await dbEvent.save()
|
||||
// dbEvent.save()
|
||||
|
||||
const queryRunner = getConnection().createQueryRunner('master')
|
||||
await queryRunner.connect()
|
||||
await queryRunner.startTransaction('READ UNCOMMITTED')
|
||||
await queryRunner.startTransaction('REPEATABLE READ')
|
||||
try {
|
||||
await queryRunner.manager.save(dbEvent).catch((error) => {
|
||||
logger.error('Error while saving dbEvent', error)
|
||||
@ -348,4 +354,3 @@ async function writeEvent(
|
||||
await queryRunner.release()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -387,6 +387,7 @@ export class UserResolver {
|
||||
logger.info('redeemCode found contributionLink=' + contributionLink)
|
||||
if (contributionLink) {
|
||||
dbUser.contributionLinkId = contributionLink.id
|
||||
if (eventProtocol.isEnabled()) {
|
||||
eventProtocol.emit(
|
||||
EventProtocolType.REDEEM_REGISTER,
|
||||
new Date(Date.now()),
|
||||
@ -395,11 +396,13 @@ export class UserResolver {
|
||||
contributionLink.id,
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const transactionLink = await dbTransactionLink.findOne({ code: redeemCode })
|
||||
logger.info('redeemCode found transactionLink=' + transactionLink)
|
||||
if (transactionLink) {
|
||||
dbUser.referrerId = transactionLink.userId
|
||||
if (eventProtocol.isEnabled()) {
|
||||
eventProtocol.emit(
|
||||
EventProtocolType.REDEEM_REGISTER,
|
||||
new Date(Date.now()),
|
||||
@ -410,6 +413,7 @@ export class UserResolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO this field has no null allowed unlike the loginServer table
|
||||
// dbUser.pubKey = Buffer.from(randomBytes(32)) // Buffer.alloc(32, 0) default to 0000...
|
||||
// dbUser.pubkey = keyPair[0]
|
||||
@ -461,8 +465,10 @@ export class UserResolver {
|
||||
await queryRunner.release()
|
||||
}
|
||||
logger.info('createUser() successful...')
|
||||
eventProtocol.emit(EventProtocolType.REGISTER, new Date(Date.now()), dbUser.id)
|
||||
|
||||
if (eventProtocol.isEnabled()) {
|
||||
eventProtocol.emit(EventProtocolType.REGISTER, new Date(Date.now()), dbUser.id)
|
||||
}
|
||||
return new User(dbUser)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user