diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts index 140ba8497..c85a7a12c 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CONFIRM = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts index c95ba5b9b..a10ff1a35 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts index 30cfd8b93..d3dd5508e 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts index d84467f4f..5f1203766 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts new file mode 100644 index 000000000..2ead791ed --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts @@ -0,0 +1,23 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_LINK_CREATE = async ( + moderator: DbUser, + contributionLink: DbContributionLink, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_LINK_CREATE, + { id: 0 } as DbUser, + moderator, + null, + null, + null, + null, + null, + contributionLink, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts new file mode 100644 index 000000000..b5816e45d --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts @@ -0,0 +1,20 @@ +import { User as DbUser } from '@entity/User' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_LINK_DELETE = async ( + moderator: DbUser, + contributionLink: DbContributionLink, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_LINK_DELETE, + { id: 0 } as DbUser, + moderator, + null, + null, + null, + null, + null, + contributionLink, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts new file mode 100644 index 000000000..6824833b8 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts @@ -0,0 +1,23 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE = async ( + moderator: DbUser, + contributionLink: DbContributionLink, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_LINK_UPDATE, + { id: 0 } as DbUser, + moderator, + null, + null, + null, + null, + null, + contributionLink, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts index 3fc17f7d2..60315249a 100644 --- a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts @@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( null, contribution, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts index cbc514dc8..50cdbcd18 100644 --- a/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts +++ b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts @@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_CREATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() + Event( + EventType.CONTRIBUTION_CREATE, + user, + user, + null, + null, + contribution, + null, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts index b15e57ea8..eab04bf47 100644 --- a/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts +++ b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts @@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_DELETE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() + Event( + EventType.CONTRIBUTION_DELETE, + user, + user, + null, + null, + contribution, + null, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts index 2fb56dc77..82f14edd6 100644 --- a/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts +++ b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts @@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_UPDATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() + Event( + EventType.CONTRIBUTION_UPDATE, + user, + user, + null, + null, + contribution, + null, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts index 78f561148..acb2f5881 100644 --- a/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts +++ b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts @@ -18,5 +18,7 @@ export const EVENT_TRANSACTION_RECEIVE = async ( transaction, null, null, + null, + null, amount, ).save() diff --git a/backend/src/event/EVENT_TRANSACTION_SEND.ts b/backend/src/event/EVENT_TRANSACTION_SEND.ts index e281b0d30..a342cb0aa 100644 --- a/backend/src/event/EVENT_TRANSACTION_SEND.ts +++ b/backend/src/event/EVENT_TRANSACTION_SEND.ts @@ -18,5 +18,7 @@ export const EVENT_TRANSACTION_SEND = async ( transaction, null, null, + null, + null, amount, ).save() diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 163b0b646..2e7cca6af 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -1,8 +1,10 @@ import { Event as DbEvent } from '@entity/Event' import { User as DbUser } from '@entity/User' -import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage' -import { Contribution as DbContribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' +import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' +import { Contribution as DbContribution } from '@entity/Contribution' +import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage' +import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import Decimal from 'decimal.js-light' import { EventType } from './Event' @@ -14,6 +16,8 @@ export const Event = ( involvedTransaction: DbTransaction | null = null, involvedContribution: DbContribution | null = null, involvedContributionMessage: DbContributionMessage | null = null, + involvedTransactionLink: DbTransactionLink | null = null, + involvedContributionLink: DbContributionLink | null = null, amount: Decimal | null = null, ): DbEvent => { const event = new DbEvent() @@ -24,6 +28,8 @@ export const Event = ( event.involvedTransaction = involvedTransaction event.involvedContribution = involvedContribution event.involvedContributionMessage = involvedContributionMessage + event.involvedTransactionLink = involvedTransactionLink + event.involvedContributionLink = involvedContributionLink event.amount = amount return event } @@ -36,6 +42,9 @@ export { EVENT_ADMIN_CONTRIBUTION_CREATE } from './EVENT_ADMIN_CONTRIBUTION_CREA export { EVENT_ADMIN_CONTRIBUTION_DELETE } from './EVENT_ADMIN_CONTRIBUTION_DELETE' export { EVENT_ADMIN_CONTRIBUTION_DENY } from './EVENT_ADMIN_CONTRIBUTION_DENY' export { EVENT_ADMIN_CONTRIBUTION_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_UPDATE' +export { EVENT_ADMIN_CONTRIBUTION_LINK_CREATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_CREATE' +export { EVENT_ADMIN_CONTRIBUTION_LINK_DELETE } from './EVENT_ADMIN_CONTRIBUTION_LINK_DELETE' +export { EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE' export { EVENT_ADMIN_SEND_CONFIRMATION_EMAIL } from './EVENT_ADMIN_SEND_CONFIRMATION_EMAIL' export { EVENT_CONTRIBUTION_CREATE } from './EVENT_CONTRIBUTION_CREATE' export { EVENT_CONTRIBUTION_DELETE } from './EVENT_CONTRIBUTION_DELETE' diff --git a/backend/src/event/EventType.ts b/backend/src/event/EventType.ts index 241923ffd..e40aa91ab 100644 --- a/backend/src/event/EventType.ts +++ b/backend/src/event/EventType.ts @@ -11,6 +11,9 @@ export enum EventType { ADMIN_CONTRIBUTION_DELETE = 'ADMIN_CONTRIBUTION_DELETE', ADMIN_CONTRIBUTION_DENY = 'ADMIN_CONTRIBUTION_DENY', ADMIN_CONTRIBUTION_UPDATE = 'ADMIN_CONTRIBUTION_UPDATE', + ADMIN_CONTRIBUTION_LINK_CREATE = 'ADMIN_CONTRIBUTION_LINK_CREATE', + ADMIN_CONTRIBUTION_LINK_DELETE = 'ADMIN_CONTRIBUTION_LINK_DELETE', + ADMIN_CONTRIBUTION_LINK_UPDATE = 'ADMIN_CONTRIBUTION_LINK_UPDATE', ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL', CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE', CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE', @@ -40,8 +43,6 @@ export enum EventType { // SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL', // SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL', // SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL', - // CONTRIBUTION_DENY = 'CONTRIBUTION_DENY', - // CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE', // CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM', // USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE', // ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index d3c77cb82..850117084 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -1,5 +1,5 @@ import Decimal from 'decimal.js-light' -import { Resolver, Args, Arg, Authorized, Mutation, Query, Int } from 'type-graphql' +import { Resolver, Args, Arg, Authorized, Mutation, Query, Int, Ctx } from 'type-graphql' import { MoreThan, IsNull } from '@dbTools/typeorm' import { @@ -21,6 +21,12 @@ import Paginated from '@arg/Paginated' // TODO: this is a strange construct import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver' import LogError from '@/server/LogError' +import { Context, getUser } from '@/server/context' +import { + EVENT_ADMIN_CONTRIBUTION_LINK_CREATE, + EVENT_ADMIN_CONTRIBUTION_LINK_DELETE, + EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE, +} from '@/event/Event' @Resolver() export class ContributionLinkResolver { @@ -38,6 +44,7 @@ export class ContributionLinkResolver { maxAmountPerMonth, maxPerCycle, }: ContributionLinkArgs, + @Ctx() context: Context, ): Promise { isStartEndDateValid(validFrom, validTo) if (name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS) { @@ -68,7 +75,8 @@ export class ContributionLinkResolver { dbContributionLink.maxAmountPerMonth = maxAmountPerMonth dbContributionLink.maxPerCycle = maxPerCycle await dbContributionLink.save() - logger.debug(`createContributionLink successful!`) + await EVENT_ADMIN_CONTRIBUTION_LINK_CREATE(getUser(context), dbContributionLink, amount) + return new ContributionLink(dbContributionLink) } @@ -92,15 +100,18 @@ export class ContributionLinkResolver { @Authorized([RIGHTS.ADMIN_DELETE_CONTRIBUTION_LINK]) @Mutation(() => Date, { nullable: true }) - async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { - const contributionLink = await DbContributionLink.findOne(id) - if (!contributionLink) { + async deleteContributionLink( + @Arg('id', () => Int) id: number, + @Ctx() context: Context, + ): Promise { + const dbContributionLink = await DbContributionLink.findOne(id) + if (!dbContributionLink) { throw new LogError('Contribution Link not found', id) } - await contributionLink.softRemove() - logger.debug(`deleteContributionLink successful!`) - const newContributionLink = await DbContributionLink.findOne({ id }, { withDeleted: true }) - return newContributionLink ? newContributionLink.deletedAt : null + await dbContributionLink.softRemove() + await EVENT_ADMIN_CONTRIBUTION_LINK_DELETE(getUser(context), dbContributionLink) + + return true } @Authorized([RIGHTS.ADMIN_UPDATE_CONTRIBUTION_LINK]) @@ -118,6 +129,7 @@ export class ContributionLinkResolver { maxPerCycle, }: ContributionLinkArgs, @Arg('id', () => Int) id: number, + @Ctx() context: Context, ): Promise { const dbContributionLink = await DbContributionLink.findOne(id) if (!dbContributionLink) { @@ -133,6 +145,9 @@ export class ContributionLinkResolver { dbContributionLink.maxPerCycle = maxPerCycle await dbContributionLink.save() logger.debug(`updateContributionLink successful!`) + + await EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE(getUser(context), dbContributionLink, amount) + return new ContributionLink(dbContributionLink) } } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 1ddcc942a..d89e1c498 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -290,7 +290,7 @@ export class UserResolver { if (contributionLink) { dbUser.contributionLinkId = contributionLink.id // TODO this is so wrong - eventRegisterRedeem.involvedContribution = { id: contributionLink.id } as DbContribution + eventRegisterRedeem.involvedContributionLink = contributionLink } } else { const transactionLink = await DbTransactionLink.findOne({ code: redeemCode }) @@ -298,7 +298,7 @@ export class UserResolver { if (transactionLink) { dbUser.referrerId = transactionLink.userId // TODO this is so wrong - eventRegisterRedeem.involvedTransaction = { id: transactionLink.id } as DbTransaction + eventRegisterRedeem.involvedTransactionLink = transactionLink } } }