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
|
||||||
WEBHOOK_ELOPAGE_SECRET=secret
|
WEBHOOK_ELOPAGE_SECRET=secret
|
||||||
|
|
||||||
|
# EventProtocol
|
||||||
|
EVENT_PROTOCOL_ENABLED=true
|
||||||
|
|
||||||
# SET LOG LEVEL AS NEEDED IN YOUR .ENV
|
# SET LOG LEVEL AS NEEDED IN YOUR .ENV
|
||||||
# POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal
|
# POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal
|
||||||
# LOG_LEVEL=info
|
# LOG_LEVEL=info
|
||||||
|
|||||||
@ -94,6 +94,11 @@ const webhook = {
|
|||||||
WEBHOOK_ELOPAGE_SECRET: process.env.WEBHOOK_ELOPAGE_SECRET || 'secret',
|
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
|
// This is needed by graphql-directive-auth
|
||||||
process.env.APP_SECRET = server.JWT_SECRET
|
process.env.APP_SECRET = server.JWT_SECRET
|
||||||
|
|
||||||
@ -118,6 +123,7 @@ const CONFIG = {
|
|||||||
...email,
|
...email,
|
||||||
...loginServer,
|
...loginServer,
|
||||||
...webhook,
|
...webhook,
|
||||||
|
...eventProtocol,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CONFIG
|
export default CONFIG
|
||||||
|
|||||||
@ -4,8 +4,14 @@ import { EventProtocolType } from './EventProtocolType'
|
|||||||
import { EventProtocol } from '@entity/EventProtocol'
|
import { EventProtocol } from '@entity/EventProtocol'
|
||||||
import { getConnection } from '@dbTools/typeorm'
|
import { getConnection } from '@dbTools/typeorm'
|
||||||
import Decimal from 'decimal.js-light'
|
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()
|
export const eventProtocol = new EventProtocolEmitter()
|
||||||
|
|
||||||
eventProtocol.on('error', (err) => {
|
eventProtocol.on('error', (err) => {
|
||||||
@ -329,11 +335,11 @@ async function writeEvent(
|
|||||||
// eslint-disable-next-line no-unused-expressions
|
// eslint-disable-next-line no-unused-expressions
|
||||||
amount ? (dbEvent.amount = amount) : null
|
amount ? (dbEvent.amount = amount) : null
|
||||||
// set event values here when having the result ...
|
// set event values here when having the result ...
|
||||||
// await dbEvent.save()
|
// dbEvent.save()
|
||||||
|
|
||||||
const queryRunner = getConnection().createQueryRunner('master')
|
const queryRunner = getConnection().createQueryRunner('master')
|
||||||
await queryRunner.connect()
|
await queryRunner.connect()
|
||||||
await queryRunner.startTransaction('READ UNCOMMITTED')
|
await queryRunner.startTransaction('REPEATABLE READ')
|
||||||
try {
|
try {
|
||||||
await queryRunner.manager.save(dbEvent).catch((error) => {
|
await queryRunner.manager.save(dbEvent).catch((error) => {
|
||||||
logger.error('Error while saving dbEvent', error)
|
logger.error('Error while saving dbEvent', error)
|
||||||
@ -348,4 +354,3 @@ async function writeEvent(
|
|||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -387,6 +387,7 @@ export class UserResolver {
|
|||||||
logger.info('redeemCode found contributionLink=' + contributionLink)
|
logger.info('redeemCode found contributionLink=' + contributionLink)
|
||||||
if (contributionLink) {
|
if (contributionLink) {
|
||||||
dbUser.contributionLinkId = contributionLink.id
|
dbUser.contributionLinkId = contributionLink.id
|
||||||
|
if (eventProtocol.isEnabled()) {
|
||||||
eventProtocol.emit(
|
eventProtocol.emit(
|
||||||
EventProtocolType.REDEEM_REGISTER,
|
EventProtocolType.REDEEM_REGISTER,
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
@ -395,11 +396,13 @@ export class UserResolver {
|
|||||||
contributionLink.id,
|
contributionLink.id,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const transactionLink = await dbTransactionLink.findOne({ code: redeemCode })
|
const transactionLink = await dbTransactionLink.findOne({ code: redeemCode })
|
||||||
logger.info('redeemCode found transactionLink=' + transactionLink)
|
logger.info('redeemCode found transactionLink=' + transactionLink)
|
||||||
if (transactionLink) {
|
if (transactionLink) {
|
||||||
dbUser.referrerId = transactionLink.userId
|
dbUser.referrerId = transactionLink.userId
|
||||||
|
if (eventProtocol.isEnabled()) {
|
||||||
eventProtocol.emit(
|
eventProtocol.emit(
|
||||||
EventProtocolType.REDEEM_REGISTER,
|
EventProtocolType.REDEEM_REGISTER,
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
@ -410,6 +413,7 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// TODO this field has no null allowed unlike the loginServer table
|
// 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 = Buffer.from(randomBytes(32)) // Buffer.alloc(32, 0) default to 0000...
|
||||||
// dbUser.pubkey = keyPair[0]
|
// dbUser.pubkey = keyPair[0]
|
||||||
@ -461,8 +465,10 @@ export class UserResolver {
|
|||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
}
|
}
|
||||||
logger.info('createUser() successful...')
|
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)
|
return new User(dbUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user