completely dismiss class based approach, use EVENT function

This commit is contained in:
Ulf Gebhardt 2023-02-10 03:44:34 +01:00
parent f9b6b887e0
commit 362226a94f
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 41 additions and 47 deletions

View File

@ -2,9 +2,7 @@ import { EventProtocol as DbEvent } from '@entity/EventProtocol'
import Decimal from 'decimal.js-light' import Decimal from 'decimal.js-light'
import { EventProtocolType } from './EventProtocolType' import { EventProtocolType } from './EventProtocolType'
export class Event { export const EVENT = (
event: DbEvent
constructor(
type: EventProtocolType, type: EventProtocolType,
userId: number, userId: number,
xUserId: number | null = null, xUserId: number | null = null,
@ -13,21 +11,17 @@ export class Event {
contributionId: number | null = null, contributionId: number | null = null,
amount: Decimal | null = null, amount: Decimal | null = null,
messageId: number | null = null, messageId: number | null = null,
) { ): DbEvent => {
this.event = new DbEvent() const event = new DbEvent()
this.event.type = type event.type = type
this.event.userId = userId event.userId = userId
this.event.xUserId = xUserId event.xUserId = xUserId
this.event.xCommunityId = xCommunityId event.xCommunityId = xCommunityId
this.event.transactionId = transactionId event.transactionId = transactionId
this.event.contributionId = contributionId event.contributionId = contributionId
this.event.amount = amount event.amount = amount
this.event.messageId = messageId event.messageId = messageId
} return event
save(): Promise<DbEvent> {
return this.event.save()
}
} }
export const EVENT_CONTRIBUTION_CREATE = async ( export const EVENT_CONTRIBUTION_CREATE = async (
@ -35,7 +29,7 @@ export const EVENT_CONTRIBUTION_CREATE = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.CONTRIBUTION_CREATE, EventProtocolType.CONTRIBUTION_CREATE,
userId, userId,
null, null,
@ -51,7 +45,7 @@ export const EVENT_CONTRIBUTION_DELETE = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.CONTRIBUTION_DELETE, EventProtocolType.CONTRIBUTION_DELETE,
userId, userId,
null, null,
@ -67,7 +61,7 @@ export const EVENT_CONTRIBUTION_UPDATE = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.CONTRIBUTION_UPDATE, EventProtocolType.CONTRIBUTION_UPDATE,
userId, userId,
null, null,
@ -83,7 +77,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.ADMIN_CONTRIBUTION_CREATE, EventProtocolType.ADMIN_CONTRIBUTION_CREATE,
userId, userId,
null, null,
@ -99,7 +93,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
userId, userId,
null, null,
@ -115,7 +109,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.ADMIN_CONTRIBUTION_DELETE, EventProtocolType.ADMIN_CONTRIBUTION_DELETE,
userId, userId,
null, null,
@ -131,7 +125,7 @@ export const EVENT_CONTRIBUTION_CONFIRM = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.CONTRIBUTION_CONFIRM, EventProtocolType.CONTRIBUTION_CONFIRM,
userId, userId,
null, null,
@ -147,7 +141,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async (
contributionId: number, contributionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.ADMIN_CONTRIBUTION_DENY, EventProtocolType.ADMIN_CONTRIBUTION_DENY,
userId, userId,
null, null,
@ -164,7 +158,7 @@ export const EVENT_TRANSACTION_SEND = async (
transactionId: number, transactionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.TRANSACTION_SEND, EventProtocolType.TRANSACTION_SEND,
userId, userId,
xUserId, xUserId,
@ -181,7 +175,7 @@ export const EVENT_TRANSACTION_RECEIVE = async (
transactionId: number, transactionId: number,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.TRANSACTION_RECEIVE, EventProtocolType.TRANSACTION_RECEIVE,
userId, userId,
xUserId, xUserId,
@ -193,12 +187,12 @@ export const EVENT_TRANSACTION_RECEIVE = async (
).save() ).save()
export const EVENT_LOGIN = async (userId: number): Promise<DbEvent> => export const EVENT_LOGIN = async (userId: number): Promise<DbEvent> =>
new Event(EventProtocolType.LOGIN, userId, null, null, null, null, null, null).save() EVENT(EventProtocolType.LOGIN, userId, null, null, null, null, null, null).save()
export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async ( export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (
userId: number, userId: number,
): Promise<DbEvent> => ): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL,
userId, userId,
null, null,
@ -210,7 +204,7 @@ export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (
).save() ).save()
export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbEvent> => export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbEvent> =>
new Event( EVENT(
EventProtocolType.SEND_CONFIRMATION_EMAIL, EventProtocolType.SEND_CONFIRMATION_EMAIL,
userId, userId,
null, null,
@ -226,7 +220,7 @@ export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbE
transactionId: number | null = null, transactionId: number | null = null,
contributionId: number | null = null, contributionId: number | null = null,
): Promise<Event> => ): Promise<Event> =>
new Event( EVENT(
EventProtocolType.REDEEM_REGISTER, EventProtocolType.REDEEM_REGISTER,
userId, userId,
null, null,
@ -239,7 +233,7 @@ export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbE
*/ */
export const EVENT_REGISTER = async (userId: number): Promise<DbEvent> => export const EVENT_REGISTER = async (userId: number): Promise<DbEvent> =>
new Event(EventProtocolType.REGISTER, userId, null, null, null, null, null, null).save() EVENT(EventProtocolType.REGISTER, userId, null, null, null, null, null, null).save()
export const EVENT_ACTIVATE_ACCOUNT = async (userId: number): Promise<DbEvent> => export const EVENT_ACTIVATE_ACCOUNT = async (userId: number): Promise<DbEvent> =>
new Event(EventProtocolType.ACTIVATE_ACCOUNT, userId, null, null, null, null, null, null).save() EVENT(EventProtocolType.ACTIVATE_ACCOUNT, userId, null, null, null, null, null, null).save()

View File

@ -49,7 +49,7 @@ 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 { import {
Event, EVENT,
EVENT_LOGIN, EVENT_LOGIN,
EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL,
EVENT_SEND_CONFIRMATION_EMAIL, EVENT_SEND_CONFIRMATION_EMAIL,
@ -265,7 +265,7 @@ export class UserResolver {
const gradidoID = await newGradidoID() const gradidoID = await newGradidoID()
const eventRegisterRedeem = new Event(EventProtocolType.REDEEM_REGISTER, 0) const eventRegisterRedeem = EVENT(EventProtocolType.REDEEM_REGISTER, 0)
let dbUser = new DbUser() let dbUser = new DbUser()
dbUser.gradidoID = gradidoID dbUser.gradidoID = gradidoID
dbUser.firstName = firstName dbUser.firstName = firstName
@ -282,14 +282,14 @@ 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
eventRegisterRedeem.event.contributionId = contributionLink.id eventRegisterRedeem.contributionId = 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
eventRegisterRedeem.event.transactionId = transactionLink.id eventRegisterRedeem.transactionId = transactionLink.id
} }
} }
} }
@ -346,7 +346,7 @@ export class UserResolver {
logger.info('createUser() successful...') logger.info('createUser() successful...')
if (redeemCode) { if (redeemCode) {
eventRegisterRedeem.event.userId = dbUser.id eventRegisterRedeem.userId = dbUser.id
await eventRegisterRedeem.save() await eventRegisterRedeem.save()
} else { } else {
await EVENT_REGISTER(dbUser.id) await EVENT_REGISTER(dbUser.id)