diff --git a/backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts b/backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts new file mode 100644 index 000000000..755cc8fe2 --- /dev/null +++ b/backend/src/event/EVENT_ACTIVATE_ACCOUNT.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => + Event(EventType.ACTIVATE_ACCOUNT, user, user).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts new file mode 100644 index 000000000..52fd2264f --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CONFIRM.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_CONFIRM = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.CONTRIBUTION_CONFIRM, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts new file mode 100644 index 000000000..c95ba5b9b --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_CREATE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_CREATE, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts new file mode 100644 index 000000000..30cfd8b93 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DELETE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_DELETE, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts new file mode 100644 index 000000000..d84467f4f --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_DENY.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_DENY, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts new file mode 100644 index 000000000..3fc17f7d2 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_CONTRIBUTION_UPDATE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( + user: DbUser, + moderator: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event( + EventType.ADMIN_CONTRIBUTION_UPDATE, + user, + moderator, + null, + null, + contribution, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts b/backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts new file mode 100644 index 000000000..da4907930 --- /dev/null +++ b/backend/src/event/EVENT_ADMIN_SEND_CONFIRMATION_EMAIL.ts @@ -0,0 +1,8 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( + user: DbUser, + moderator: DbUser, +): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts new file mode 100644 index 000000000..cbc514dc8 --- /dev/null +++ b/backend/src/event/EVENT_CONTRIBUTION_CREATE.ts @@ -0,0 +1,12 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_CONTRIBUTION_CREATE = async ( + user: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts new file mode 100644 index 000000000..b15e57ea8 --- /dev/null +++ b/backend/src/event/EVENT_CONTRIBUTION_DELETE.ts @@ -0,0 +1,12 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_CONTRIBUTION_DELETE = async ( + user: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() diff --git a/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts new file mode 100644 index 000000000..2fb56dc77 --- /dev/null +++ b/backend/src/event/EVENT_CONTRIBUTION_UPDATE.ts @@ -0,0 +1,12 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Contribution as DbContribution } from '@entity/Contribution' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_CONTRIBUTION_UPDATE = async ( + user: DbUser, + contribution: DbContribution, + amount: Decimal, +): Promise => + Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() diff --git a/backend/src/event/EVENT_LOGIN.ts b/backend/src/event/EVENT_LOGIN.ts new file mode 100644 index 000000000..2c1e763ec --- /dev/null +++ b/backend/src/event/EVENT_LOGIN.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_LOGIN = async (user: DbUser): Promise => + Event(EventType.LOGIN, user, user).save() diff --git a/backend/src/event/EVENT_REGISTER.ts b/backend/src/event/EVENT_REGISTER.ts new file mode 100644 index 000000000..73c6bf4f9 --- /dev/null +++ b/backend/src/event/EVENT_REGISTER.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_REGISTER = async (user: DbUser): Promise => + Event(EventType.REGISTER, user, user).save() diff --git a/backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts b/backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts new file mode 100644 index 000000000..3110ece1f --- /dev/null +++ b/backend/src/event/EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => + Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() diff --git a/backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts b/backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts new file mode 100644 index 000000000..b387c0e60 --- /dev/null +++ b/backend/src/event/EVENT_SEND_CONFIRMATION_EMAIL.ts @@ -0,0 +1,6 @@ +import { User as DbUser } from '@entity/User' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => + Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() diff --git a/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts new file mode 100644 index 000000000..78f561148 --- /dev/null +++ b/backend/src/event/EVENT_TRANSACTION_RECEIVE.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Transaction as DbTransaction } from '@entity/Transaction' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_TRANSACTION_RECEIVE = async ( + user: DbUser, + involvedUser: DbUser, + transaction: DbTransaction, + amount: Decimal, +): Promise => + Event( + EventType.TRANSACTION_RECEIVE, + user, + involvedUser, + involvedUser, + transaction, + null, + null, + amount, + ).save() diff --git a/backend/src/event/EVENT_TRANSACTION_SEND.ts b/backend/src/event/EVENT_TRANSACTION_SEND.ts new file mode 100644 index 000000000..e281b0d30 --- /dev/null +++ b/backend/src/event/EVENT_TRANSACTION_SEND.ts @@ -0,0 +1,22 @@ +import Decimal from 'decimal.js-light' +import { User as DbUser } from '@entity/User' +import { Transaction as DbTransaction } from '@entity/Transaction' +import { Event as DbEvent } from '@entity/Event' +import { Event, EventType } from './Event' + +export const EVENT_TRANSACTION_SEND = async ( + user: DbUser, + involvedUser: DbUser, + transaction: DbTransaction, + amount: Decimal, +): Promise => + Event( + EventType.TRANSACTION_SEND, + user, + user, + involvedUser, + transaction, + null, + null, + amount, + ).save() diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 720cb2799..163b0b646 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -4,7 +4,7 @@ import { ContributionMessage as DbContributionMessage } from '@entity/Contributi import { Contribution as DbContribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import Decimal from 'decimal.js-light' -import { EventType } from './EventType' +import { EventType } from './Event' export const Event = ( type: EventType, @@ -28,162 +28,21 @@ export const Event = ( return event } -export const EVENT_CONTRIBUTION_CREATE = async ( - user: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() +export { EventType } from './EventType' -export const EVENT_CONTRIBUTION_DELETE = async ( - user: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() - -export const EVENT_CONTRIBUTION_UPDATE = async ( - user: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() - -export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_CREATE, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_UPDATE, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_DELETE, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_CONTRIBUTION_CONFIRM = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.CONTRIBUTION_CONFIRM, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( - user: DbUser, - moderator: DbUser, - contribution: DbContribution, - amount: Decimal, -): Promise => - Event( - EventType.ADMIN_CONTRIBUTION_DENY, - user, - moderator, - null, - null, - contribution, - null, - amount, - ).save() - -export const EVENT_TRANSACTION_SEND = async ( - user: DbUser, - involvedUser: DbUser, - transaction: DbTransaction, - amount: Decimal, -): Promise => - Event( - EventType.TRANSACTION_SEND, - user, - user, - involvedUser, - transaction, - null, - null, - amount, - ).save() - -export const EVENT_TRANSACTION_RECEIVE = async ( - user: DbUser, - involvedUser: DbUser, - transaction: DbTransaction, - amount: Decimal, -): Promise => - Event( - EventType.TRANSACTION_RECEIVE, - user, - involvedUser, - involvedUser, - transaction, - null, - null, - amount, - ).save() - -export const EVENT_LOGIN = async (user: DbUser): Promise => - Event(EventType.LOGIN, user, user).save() - -export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => - Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() - -export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => - Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() - -export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( - user: DbUser, - moderator: DbUser, -): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() - -export const EVENT_REGISTER = async (user: DbUser): Promise => - Event(EventType.REGISTER, user, user).save() - -export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => - Event(EventType.ACTIVATE_ACCOUNT, user, user).save() +export { EVENT_ACTIVATE_ACCOUNT } from './EVENT_ACTIVATE_ACCOUNT' +export { EVENT_ADMIN_CONTRIBUTION_CONFIRM } from './EVENT_ADMIN_CONTRIBUTION_CONFIRM' +export { EVENT_ADMIN_CONTRIBUTION_CREATE } from './EVENT_ADMIN_CONTRIBUTION_CREATE' +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_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' +export { EVENT_CONTRIBUTION_UPDATE } from './EVENT_CONTRIBUTION_UPDATE' +export { EVENT_LOGIN } from './EVENT_LOGIN' +export { EVENT_REGISTER } from './EVENT_REGISTER' +export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL' +export { EVENT_SEND_CONFIRMATION_EMAIL } from './EVENT_SEND_CONFIRMATION_EMAIL' +export { EVENT_TRANSACTION_SEND } from './EVENT_TRANSACTION_SEND' +export { EVENT_TRANSACTION_RECEIVE } from './EVENT_TRANSACTION_RECEIVE' diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index cc2115f3f..ac177c228 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -45,7 +45,7 @@ import { Event as DbEvent } from '@entity/Event' import { Contribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' -import { EventType } from '@/event/EventType' +import { EventType } from '@/event/Event' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 0d27739f9..62c53d993 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -41,7 +41,7 @@ import { EVENT_ADMIN_CONTRIBUTION_CREATE, EVENT_ADMIN_CONTRIBUTION_UPDATE, EVENT_ADMIN_CONTRIBUTION_DELETE, - EVENT_CONTRIBUTION_CONFIRM, + EVENT_ADMIN_CONTRIBUTION_CONFIRM, EVENT_ADMIN_CONTRIBUTION_DENY, } from '@/event/Event' import { calculateDecay } from '@/util/decay' @@ -559,7 +559,7 @@ export class ContributionResolver { await queryRunner.release() } - await EVENT_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount) + await EVENT_ADMIN_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount) } finally { releaseLock() } diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 590a1fca3..d8f249e05 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import Decimal from 'decimal.js-light' -import { EventType } from '@/event/EventType' +import { EventType } from '@/event/Event' import { userFactory } from '@/seeds/factory/user' import { confirmContribution, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 36a591a49..3bcc229b1 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -34,7 +34,7 @@ import { contributionLinkFactory } from '@/seeds/factory/contributionLink' import { transactionLinkFactory } from '@/seeds/factory/transactionLink' import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' -import { EventType } from '@/event/EventType' +import { EventType } from '@/event/Event' import { Event as DbEvent } from '@entity/Event' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 67f263709..1ddcc942a 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -52,6 +52,7 @@ import { RIGHTS } from '@/auth/RIGHTS' import { hasElopageBuys } from '@/util/hasElopageBuys' import { Event, + EventType, EVENT_LOGIN, EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, EVENT_SEND_CONFIRMATION_EMAIL, @@ -65,7 +66,6 @@ import { FULL_CREATION_AVAILABLE } from './const/const' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { PasswordEncryptionType } from '../enum/PasswordEncryptionType' import LogError from '@/server/LogError' -import { EventType } from '@/event/EventType' // eslint-disable-next-line @typescript-eslint/no-var-requires const sodium = require('sodium-native')