Merge branch 'master' into 2594-contributions-list-frontend

This commit is contained in:
Alexander Friedland 2023-02-07 07:50:22 +01:00 committed by GitHub
commit 8cffe8ed0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 45 additions and 128 deletions

View File

@ -55,9 +55,6 @@ EMAIL_CODE_REQUEST_TIME=10
# Webhook # Webhook
WEBHOOK_ELOPAGE_SECRET=secret WEBHOOK_ELOPAGE_SECRET=secret
# EventProtocol
EVENT_PROTOCOL_DISABLED=false
# 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

View File

@ -54,9 +54,6 @@ EMAIL_CODE_REQUEST_TIME=$EMAIL_CODE_REQUEST_TIME
# Webhook # Webhook
WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET
# EventProtocol
EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED
# Federation # Federation
FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC
FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED

View File

@ -17,7 +17,7 @@ const constants = {
LOG_LEVEL: process.env.LOG_LEVEL || 'info', LOG_LEVEL: process.env.LOG_LEVEL || 'info',
CONFIG_VERSION: { CONFIG_VERSION: {
DEFAULT: 'DEFAULT', DEFAULT: 'DEFAULT',
EXPECTED: 'v14.2022-12-22', EXPECTED: 'v15.2023-02-07',
CURRENT: '', CURRENT: '',
}, },
} }
@ -99,11 +99,6 @@ 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_DISABLED: process.env.EVENT_PROTOCOL_DISABLED === '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
@ -139,7 +134,6 @@ const CONFIG = {
...email, ...email,
...loginServer, ...loginServer,
...webhook, ...webhook,
...eventProtocol,
...federation, ...federation,
} }

View File

@ -1,4 +1,3 @@
import { EventProtocol } from '@entity/EventProtocol'
import decimal from 'decimal.js-light' import decimal from 'decimal.js-light'
import { EventProtocolType } from './EventProtocolType' import { EventProtocolType } from './EventProtocolType'
@ -87,21 +86,6 @@ export class EventDeleteContributionLink extends EventBasicCt {}
export class EventUpdateContributionLink extends EventBasicCt {} export class EventUpdateContributionLink extends EventBasicCt {}
export class Event { export class Event {
constructor()
constructor(event?: EventProtocol) {
if (event) {
this.id = event.id
this.type = event.type
this.createdAt = event.createdAt
this.userId = event.userId
this.xUserId = event.xUserId
this.xCommunityId = event.xCommunityId
this.transactionId = event.transactionId
this.contributionId = event.contributionId
this.amount = event.amount
}
}
public setEventBasic(): Event { public setEventBasic(): Event {
this.type = EventProtocolType.BASIC this.type = EventProtocolType.BASIC
this.createdAt = new Date() this.createdAt = new Date()

View File

@ -1,41 +1,17 @@
import { Event } from '@/event/Event' import { Event } from '@/event/Event'
import { backendLogger as logger } from '@/server/logger' import { backendLogger as logger } from '@/server/logger'
import { EventProtocol } from '@entity/EventProtocol' import { EventProtocol } from '@entity/EventProtocol'
import CONFIG from '@/config'
class EventProtocolEmitter { export const writeEvent = async (event: Event): Promise<EventProtocol | null> => {
/* }extends EventEmitter { */ logger.info('writeEvent', event)
private events: Event[]
/*
public addEvent(event: Event) {
this.events.push(event)
}
public getEvents(): Event[] {
return this.events
}
*/
public isDisabled() {
logger.info(`EventProtocol - isDisabled=${CONFIG.EVENT_PROTOCOL_DISABLED}`)
return CONFIG.EVENT_PROTOCOL_DISABLED === true
}
public async writeEvent(event: Event): Promise<void> {
if (!eventProtocol.isDisabled()) {
logger.info(`writeEvent(${JSON.stringify(event)})`)
const dbEvent = new EventProtocol() const dbEvent = new EventProtocol()
dbEvent.type = event.type dbEvent.type = event.type
dbEvent.createdAt = event.createdAt dbEvent.createdAt = event.createdAt
dbEvent.userId = event.userId dbEvent.userId = event.userId
if (event.xUserId) dbEvent.xUserId = event.xUserId dbEvent.xUserId = event.xUserId || null
if (event.xCommunityId) dbEvent.xCommunityId = event.xCommunityId dbEvent.xCommunityId = event.xCommunityId || null
if (event.contributionId) dbEvent.contributionId = event.contributionId dbEvent.contributionId = event.contributionId || null
if (event.transactionId) dbEvent.transactionId = event.transactionId dbEvent.transactionId = event.transactionId || null
if (event.amount) dbEvent.amount = event.amount dbEvent.amount = event.amount || null
await dbEvent.save() return dbEvent.save()
}
}
} }
export const eventProtocol = new EventProtocolEmitter()

View File

@ -46,7 +46,7 @@ import {
EventAdminContributionDelete, EventAdminContributionDelete,
EventAdminContributionUpdate, EventAdminContributionUpdate,
} from '@/event/Event' } from '@/event/Event'
import { eventProtocol } from '@/event/EventProtocolEmitter' import { writeEvent } from '@/event/EventProtocolEmitter'
import { calculateDecay } from '@/util/decay' import { calculateDecay } from '@/util/decay'
import { import {
sendContributionConfirmedEmail, sendContributionConfirmedEmail,
@ -97,7 +97,7 @@ export class ContributionResolver {
eventCreateContribution.userId = user.id eventCreateContribution.userId = user.id
eventCreateContribution.amount = amount eventCreateContribution.amount = amount
eventCreateContribution.contributionId = contribution.id eventCreateContribution.contributionId = contribution.id
await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) await writeEvent(event.setEventContributionCreate(eventCreateContribution))
return new UnconfirmedContribution(contribution, user, creations) return new UnconfirmedContribution(contribution, user, creations)
} }
@ -133,7 +133,7 @@ export class ContributionResolver {
eventDeleteContribution.userId = user.id eventDeleteContribution.userId = user.id
eventDeleteContribution.contributionId = contribution.id eventDeleteContribution.contributionId = contribution.id
eventDeleteContribution.amount = contribution.amount eventDeleteContribution.amount = contribution.amount
await eventProtocol.writeEvent(event.setEventContributionDelete(eventDeleteContribution)) await writeEvent(event.setEventContributionDelete(eventDeleteContribution))
const res = await contribution.softRemove() const res = await contribution.softRemove()
return !!res return !!res
@ -291,7 +291,7 @@ export class ContributionResolver {
eventUpdateContribution.userId = user.id eventUpdateContribution.userId = user.id
eventUpdateContribution.contributionId = contributionId eventUpdateContribution.contributionId = contributionId
eventUpdateContribution.amount = amount eventUpdateContribution.amount = amount
await eventProtocol.writeEvent(event.setEventContributionUpdate(eventUpdateContribution)) await writeEvent(event.setEventContributionUpdate(eventUpdateContribution))
return new UnconfirmedContribution(contributionToUpdate, user, creations) return new UnconfirmedContribution(contributionToUpdate, user, creations)
} }
@ -358,9 +358,7 @@ export class ContributionResolver {
eventAdminCreateContribution.userId = moderator.id eventAdminCreateContribution.userId = moderator.id
eventAdminCreateContribution.amount = amount eventAdminCreateContribution.amount = amount
eventAdminCreateContribution.contributionId = contribution.id eventAdminCreateContribution.contributionId = contribution.id
await eventProtocol.writeEvent( await writeEvent(event.setEventAdminContributionCreate(eventAdminCreateContribution))
event.setEventAdminContributionCreate(eventAdminCreateContribution),
)
return getUserCreation(emailContact.userId, clientTimezoneOffset) return getUserCreation(emailContact.userId, clientTimezoneOffset)
} }
@ -470,9 +468,7 @@ export class ContributionResolver {
eventAdminContributionUpdate.userId = user.id eventAdminContributionUpdate.userId = user.id
eventAdminContributionUpdate.amount = amount eventAdminContributionUpdate.amount = amount
eventAdminContributionUpdate.contributionId = contributionToUpdate.id eventAdminContributionUpdate.contributionId = contributionToUpdate.id
await eventProtocol.writeEvent( await writeEvent(event.setEventAdminContributionUpdate(eventAdminContributionUpdate))
event.setEventAdminContributionUpdate(eventAdminContributionUpdate),
)
return result return result
} }
@ -550,9 +546,7 @@ export class ContributionResolver {
eventAdminContributionDelete.userId = contribution.userId eventAdminContributionDelete.userId = contribution.userId
eventAdminContributionDelete.amount = contribution.amount eventAdminContributionDelete.amount = contribution.amount
eventAdminContributionDelete.contributionId = contribution.id eventAdminContributionDelete.contributionId = contribution.id
await eventProtocol.writeEvent( await writeEvent(event.setEventAdminContributionDelete(eventAdminContributionDelete))
event.setEventAdminContributionDelete(eventAdminContributionDelete),
)
sendContributionDeniedEmail({ sendContributionDeniedEmail({
firstName: user.firstName, firstName: user.firstName,
lastName: user.lastName, lastName: user.lastName,
@ -680,7 +674,7 @@ export class ContributionResolver {
eventContributionConfirm.userId = user.id eventContributionConfirm.userId = user.id
eventContributionConfirm.amount = contribution.amount eventContributionConfirm.amount = contribution.amount
eventContributionConfirm.contributionId = contribution.id eventContributionConfirm.contributionId = contribution.id
await eventProtocol.writeEvent(event.setEventContributionConfirm(eventContributionConfirm)) await writeEvent(event.setEventContributionConfirm(eventContributionConfirm))
} finally { } finally {
releaseLock() releaseLock()
} }

View File

@ -30,7 +30,7 @@ import {
sendTransactionReceivedEmail, sendTransactionReceivedEmail,
} from '@/emails/sendEmailVariants' } from '@/emails/sendEmailVariants'
import { Event, EventTransactionReceive, EventTransactionSend } from '@/event/Event' import { Event, EventTransactionReceive, EventTransactionSend } from '@/event/Event'
import { eventProtocol } from '@/event/EventProtocolEmitter' import { writeEvent } from '@/event/EventProtocolEmitter'
import { BalanceResolver } from './BalanceResolver' import { BalanceResolver } from './BalanceResolver'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
@ -144,16 +144,14 @@ export const executeTransaction = async (
eventTransactionSend.xUserId = transactionSend.linkedUserId eventTransactionSend.xUserId = transactionSend.linkedUserId
eventTransactionSend.transactionId = transactionSend.id eventTransactionSend.transactionId = transactionSend.id
eventTransactionSend.amount = transactionSend.amount.mul(-1) eventTransactionSend.amount = transactionSend.amount.mul(-1)
await eventProtocol.writeEvent(new Event().setEventTransactionSend(eventTransactionSend)) await writeEvent(new Event().setEventTransactionSend(eventTransactionSend))
const eventTransactionReceive = new EventTransactionReceive() const eventTransactionReceive = new EventTransactionReceive()
eventTransactionReceive.userId = transactionReceive.userId eventTransactionReceive.userId = transactionReceive.userId
eventTransactionReceive.xUserId = transactionReceive.linkedUserId eventTransactionReceive.xUserId = transactionReceive.linkedUserId
eventTransactionReceive.transactionId = transactionReceive.id eventTransactionReceive.transactionId = transactionReceive.id
eventTransactionReceive.amount = transactionReceive.amount eventTransactionReceive.amount = transactionReceive.amount
await eventProtocol.writeEvent( await writeEvent(new Event().setEventTransactionReceive(eventTransactionReceive))
new Event().setEventTransactionReceive(eventTransactionReceive),
)
} catch (e) { } catch (e) {
await queryRunner.rollbackTransaction() await queryRunner.rollbackTransaction()
logger.error(`Transaction was not successful: ${e}`) logger.error(`Transaction was not successful: ${e}`)

View File

@ -48,7 +48,7 @@ import { klicktippNewsletterStateMiddleware } from '@/middleware/klicktippMiddle
import { klicktippSignIn } from '@/apis/KlicktippController' import { klicktippSignIn } from '@/apis/KlicktippController'
import { RIGHTS } from '@/auth/RIGHTS' import { RIGHTS } from '@/auth/RIGHTS'
import { hasElopageBuys } from '@/util/hasElopageBuys' import { hasElopageBuys } from '@/util/hasElopageBuys'
import { eventProtocol } from '@/event/EventProtocolEmitter' import { writeEvent } from '@/event/EventProtocolEmitter'
import { import {
Event, Event,
EventLogin, EventLogin,
@ -179,7 +179,7 @@ export class UserResolver {
}) })
const ev = new EventLogin() const ev = new EventLogin()
ev.userId = user.id ev.userId = user.id
eventProtocol.writeEvent(new Event().setEventLogin(ev)) writeEvent(new Event().setEventLogin(ev))
logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`) logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`)
return user return user
} }
@ -251,9 +251,7 @@ export class UserResolver {
}) })
const eventSendAccountMultiRegistrationEmail = new EventSendAccountMultiRegistrationEmail() const eventSendAccountMultiRegistrationEmail = new EventSendAccountMultiRegistrationEmail()
eventSendAccountMultiRegistrationEmail.userId = foundUser.id eventSendAccountMultiRegistrationEmail.userId = foundUser.id
eventProtocol.writeEvent( writeEvent(event.setEventSendConfirmationEmail(eventSendAccountMultiRegistrationEmail))
event.setEventSendConfirmationEmail(eventSendAccountMultiRegistrationEmail),
)
logger.info( logger.info(
`sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`, `sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`,
) )
@ -336,7 +334,7 @@ export class UserResolver {
}) })
logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`) logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`)
eventSendConfirmEmail.userId = dbUser.id eventSendConfirmEmail.userId = dbUser.id
eventProtocol.writeEvent(event.setEventSendConfirmationEmail(eventSendConfirmEmail)) writeEvent(event.setEventSendConfirmationEmail(eventSendConfirmEmail))
if (!emailSent) { if (!emailSent) {
logger.debug(`Account confirmation link: ${activationLink}`) logger.debug(`Account confirmation link: ${activationLink}`)
@ -354,10 +352,10 @@ export class UserResolver {
if (redeemCode) { if (redeemCode) {
eventRedeemRegister.userId = dbUser.id eventRedeemRegister.userId = dbUser.id
await eventProtocol.writeEvent(event.setEventRedeemRegister(eventRedeemRegister)) await writeEvent(event.setEventRedeemRegister(eventRedeemRegister))
} else { } else {
eventRegister.userId = dbUser.id eventRegister.userId = dbUser.id
await eventProtocol.writeEvent(event.setEventRegister(eventRegister)) await writeEvent(event.setEventRegister(eventRegister))
} }
return new User(dbUser) return new User(dbUser)
@ -477,7 +475,7 @@ export class UserResolver {
const eventActivateAccount = new EventActivateAccount() const eventActivateAccount = new EventActivateAccount()
eventActivateAccount.userId = user.id eventActivateAccount.userId = user.id
eventProtocol.writeEvent(event.setEventActivateAccount(eventActivateAccount)) writeEvent(event.setEventActivateAccount(eventActivateAccount))
} catch (e) { } catch (e) {
await queryRunner.rollbackTransaction() await queryRunner.rollbackTransaction()
throw new LogError('Error on writing User and User Contact data', e) throw new LogError('Error on writing User and User Contact data', e)
@ -824,9 +822,7 @@ export class UserResolver {
const event = new Event() const event = new Event()
const eventSendConfirmationEmail = new EventSendConfirmationEmail() const eventSendConfirmationEmail = new EventSendConfirmationEmail()
eventSendConfirmationEmail.userId = user.id eventSendConfirmationEmail.userId = user.id
await eventProtocol.writeEvent( await writeEvent(event.setEventSendConfirmationEmail(eventSendConfirmationEmail))
event.setEventSendConfirmationEmail(eventSendConfirmationEmail),
)
} }
return true return true

View File

@ -16,17 +16,17 @@ export class EventProtocol extends BaseEntity {
@Column({ name: 'user_id', unsigned: true, nullable: false }) @Column({ name: 'user_id', unsigned: true, nullable: false })
userId: number userId: number
@Column({ name: 'x_user_id', unsigned: true, nullable: true }) @Column({ name: 'x_user_id', type: 'int', unsigned: true, nullable: true })
xUserId: number xUserId: number | null
@Column({ name: 'x_community_id', unsigned: true, nullable: true }) @Column({ name: 'x_community_id', type: 'int', unsigned: true, nullable: true })
xCommunityId: number xCommunityId: number | null
@Column({ name: 'transaction_id', unsigned: true, nullable: true }) @Column({ name: 'transaction_id', type: 'int', unsigned: true, nullable: true })
transactionId: number transactionId: number | null
@Column({ name: 'contribution_id', unsigned: true, nullable: true }) @Column({ name: 'contribution_id', type: 'int', unsigned: true, nullable: true })
contributionId: number contributionId: number | null
@Column({ @Column({
type: 'decimal', type: 'decimal',
@ -35,8 +35,8 @@ export class EventProtocol extends BaseEntity {
nullable: true, nullable: true,
transformer: DecimalTransformer, transformer: DecimalTransformer,
}) })
amount: Decimal amount: Decimal | null
@Column({ name: 'message_id', unsigned: true, nullable: true }) @Column({ name: 'message_id', type: 'int', unsigned: true, nullable: true })
messageId: number messageId: number | null
} }

View File

@ -27,7 +27,7 @@ COMMUNITY_DESCRIPTION="Gradido Development Stage1 Test Community"
COMMUNITY_SUPPORT_MAIL=support@supportmail.com COMMUNITY_SUPPORT_MAIL=support@supportmail.com
# backend # backend
BACKEND_CONFIG_VERSION=v14.2022-12-22 BACKEND_CONFIG_VERSION=v15.2023-02-07
JWT_EXPIRES_IN=10m JWT_EXPIRES_IN=10m
GDT_API_URL=https://gdt.gradido.net GDT_API_URL=https://gdt.gradido.net
@ -56,9 +56,6 @@ EMAIL_CODE_REQUEST_TIME=10
WEBHOOK_ELOPAGE_SECRET=secret WEBHOOK_ELOPAGE_SECRET=secret
# EventProtocol
EVENT_PROTOCOL_DISABLED=false
# Federation # Federation
# if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen # if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen
# on an hash created from this topic # on an hash created from this topic

View File

@ -8,9 +8,6 @@ DB_PASSWORD=
DB_DATABASE=gradido_community DB_DATABASE=gradido_community
TYPEORM_LOGGING_RELATIVE_PATH=typeorm.dht-node.log TYPEORM_LOGGING_RELATIVE_PATH=typeorm.dht-node.log
# EventProtocol
EVENT_PROTOCOL_DISABLED=false
# 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

View File

@ -8,9 +8,6 @@ DB_PASSWORD=$DB_PASSWORD
DB_DATABASE=gradido_community DB_DATABASE=gradido_community
TYPEORM_LOGGING_RELATIVE_PATH=$TYPEORM_LOGGING_RELATIVE_PATH TYPEORM_LOGGING_RELATIVE_PATH=$TYPEORM_LOGGING_RELATIVE_PATH
# EventProtocol
EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED
# Federation # Federation
FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC
FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED

View File

@ -9,7 +9,7 @@ const constants = {
LOG_LEVEL: process.env.LOG_LEVEL || 'info', LOG_LEVEL: process.env.LOG_LEVEL || 'info',
CONFIG_VERSION: { CONFIG_VERSION: {
DEFAULT: 'DEFAULT', DEFAULT: 'DEFAULT',
EXPECTED: 'v1.2023-01-01', EXPECTED: 'v2.2023-02-07',
CURRENT: '', CURRENT: '',
}, },
} }
@ -28,11 +28,6 @@ const database = {
process.env.TYPEORM_LOGGING_RELATIVE_PATH || 'typeorm.dht-node.log', process.env.TYPEORM_LOGGING_RELATIVE_PATH || 'typeorm.dht-node.log',
} }
const eventProtocol = {
// global switch to enable writing of EventProtocol-Entries
EVENT_PROTOCOL_DISABLED: process.env.EVENT_PROTOCOL_DISABLED === 'true' || false,
}
const federation = { const federation = {
FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || 'GRADIDO_HUB', FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || 'GRADIDO_HUB',
FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null,
@ -55,7 +50,6 @@ const CONFIG = {
...constants, ...constants,
...server, ...server,
...database, ...database,
...eventProtocol,
...federation, ...federation,
} }

View File

@ -52,10 +52,6 @@ const community = {
process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.', process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.',
} }
*/ */
// const eventProtocol = {
// global switch to enable writing of EventProtocol-Entries
// EVENT_PROTOCOL_DISABLED: process.env.EVENT_PROTOCOL_DISABLED === '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