diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 7ed75fd45..720cb2799 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -4,10 +4,10 @@ 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 { EventProtocolType } from './EventProtocolType' +import { EventType } from './EventType' export const Event = ( - type: EventProtocolType, + type: EventType, affectedUser: DbUser, actingUser: DbUser, involvedUser: DbUser | null = null, @@ -33,48 +33,21 @@ export const EVENT_CONTRIBUTION_CREATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_CREATE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() export const EVENT_CONTRIBUTION_DELETE = async ( user: DbUser, contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_DELETE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + 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( - EventProtocolType.CONTRIBUTION_UPDATE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( user: DbUser, @@ -83,7 +56,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_CREATE, + EventType.ADMIN_CONTRIBUTION_CREATE, user, moderator, null, @@ -100,7 +73,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + EventType.ADMIN_CONTRIBUTION_UPDATE, user, moderator, null, @@ -117,7 +90,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + EventType.ADMIN_CONTRIBUTION_DELETE, user, moderator, null, @@ -134,7 +107,7 @@ export const EVENT_CONTRIBUTION_CONFIRM = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.CONTRIBUTION_CONFIRM, + EventType.CONTRIBUTION_CONFIRM, user, moderator, null, @@ -151,7 +124,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_DENY, + EventType.ADMIN_CONTRIBUTION_DENY, user, moderator, null, @@ -168,7 +141,7 @@ export const EVENT_TRANSACTION_SEND = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.TRANSACTION_SEND, + EventType.TRANSACTION_SEND, user, user, involvedUser, @@ -185,7 +158,7 @@ export const EVENT_TRANSACTION_RECEIVE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.TRANSACTION_RECEIVE, + EventType.TRANSACTION_RECEIVE, user, involvedUser, involvedUser, @@ -196,22 +169,21 @@ export const EVENT_TRANSACTION_RECEIVE = async ( ).save() export const EVENT_LOGIN = async (user: DbUser): Promise => - Event(EventProtocolType.LOGIN, user, user).save() + Event(EventType.LOGIN, user, user).save() export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => - Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() + Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => - Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, user, user).save() + Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( user: DbUser, moderator: DbUser, -): Promise => - Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() +): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() export const EVENT_REGISTER = async (user: DbUser): Promise => - Event(EventProtocolType.REGISTER, user, user).save() + Event(EventType.REGISTER, user, user).save() export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => - Event(EventProtocolType.ACTIVATE_ACCOUNT, user, user).save() + Event(EventType.ACTIVATE_ACCOUNT, user, user).save() diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventType.ts similarity index 98% rename from backend/src/event/EventProtocolType.ts rename to backend/src/event/EventType.ts index 3a4c914c1..360d5efb4 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventType.ts @@ -1,4 +1,4 @@ -export enum EventProtocolType { +export enum EventType { // VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index def4fdf96..cc2115f3f 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 { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' @@ -276,7 +276,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CREATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CREATE, + type: EventType.CONTRIBUTION_CREATE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: pendingContribution.data.createContribution.id, @@ -582,7 +582,7 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_UPDATE, + type: EventType.CONTRIBUTION_UPDATE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: pendingContribution.data.createContribution.id, @@ -813,7 +813,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, + type: EventType.ADMIN_CONTRIBUTION_DENY, affectedUserId: bibi.id, actingUserId: admin.id, involvedContributionId: contributionToDeny.data.createContribution.id, @@ -941,7 +941,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_DELETE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_DELETE, + type: EventType.CONTRIBUTION_DELETE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: contributionToDelete.data.createContribution.id, @@ -2032,7 +2032,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_CREATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, + type: EventType.ADMIN_CONTRIBUTION_CREATE, affectedUserId: bibi.id, actingUserId: admin.id, amount: expect.decimalEqual(200), @@ -2258,7 +2258,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + type: EventType.ADMIN_CONTRIBUTION_UPDATE, affectedUserId: creation?.userId, actingUserId: admin.id, amount: 300, @@ -2300,7 +2300,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + type: EventType.ADMIN_CONTRIBUTION_UPDATE, affectedUserId: creation?.userId, actingUserId: admin.id, amount: expect.decimalEqual(200), @@ -2386,7 +2386,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_DELETE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + type: EventType.ADMIN_CONTRIBUTION_DELETE, affectedUserId: creation?.userId, actingUserId: admin.id, involvedContributionId: creation?.id, @@ -2544,7 +2544,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CONFIRM event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CONFIRM, + type: EventType.CONTRIBUTION_CONFIRM, }), ) }) @@ -2576,7 +2576,7 @@ describe('ContributionResolver', () => { it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_CONFIRMATION_EMAIL, + type: EventType.SEND_CONFIRMATION_EMAIL, }), ) }) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 6ddbb8191..590a1fca3 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 { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { userFactory } from '@/seeds/factory/user' import { confirmContribution, @@ -339,7 +339,7 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.TRANSACTION_SEND, + type: EventType.TRANSACTION_SEND, affectedUserId: user[1].id, actingUserId: user[1].id, involvedUserId: user[0].id, @@ -357,7 +357,7 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.TRANSACTION_RECEIVE, + type: EventType.TRANSACTION_RECEIVE, affectedUserId: user[0].id, actingUserId: user[1].id, involvedUserId: user[1].id, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index e627f4f0f..36a591a49 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 { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { Event as DbEvent } from '@entity/Event' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' @@ -184,7 +184,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REGISTER, + type: EventType.REGISTER, affectedUserId: userConatct.user.id, actingUserId: userConatct.user.id, }), @@ -214,7 +214,7 @@ describe('UserResolver', () => { it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_CONFIRMATION_EMAIL, + type: EventType.SEND_CONFIRMATION_EMAIL, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -260,7 +260,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, + type: EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, affectedUserId: userConatct.user.id, actingUserId: 0, }), @@ -361,7 +361,7 @@ describe('UserResolver', () => { it('stores the ACTIVATE_ACCOUNT event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ACTIVATE_ACCOUNT, + type: EventType.ACTIVATE_ACCOUNT, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -371,7 +371,7 @@ describe('UserResolver', () => { it('stores the REDEEM_REGISTER event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REDEEM_REGISTER, + type: EventType.REDEEM_REGISTER, affectedUserId: result.data.createUser.id, actingUserId: result.data.createUser.id, involvedContributionId: link.id, @@ -456,7 +456,7 @@ describe('UserResolver', () => { it('stores the REDEEM_REGISTER event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REDEEM_REGISTER, + type: EventType.REDEEM_REGISTER, affectedUserId: newUser.data.createUser.id, actingUserId: newUser.data.createUser.id, involvedTransactionId: transactionLink.id, @@ -689,7 +689,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.LOGIN, + type: EventType.LOGIN, affectedUserId: userConatct.user.id, actingUserId: userConatct.user.id, }), @@ -938,7 +938,7 @@ describe('UserResolver', () => { it('stores the LOGIN event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.LOGIN, + type: EventType.LOGIN, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -1858,7 +1858,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, + type: EventType.ADMIN_SEND_CONFIRMATION_EMAIL, affectedUserId: userConatct.user.id, actingUserId: admin.id, }), diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index d79b0444e..67f263709 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -65,7 +65,7 @@ import { FULL_CREATION_AVAILABLE } from './const/const' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { PasswordEncryptionType } from '../enum/PasswordEncryptionType' import LogError from '@/server/LogError' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' // eslint-disable-next-line @typescript-eslint/no-var-requires const sodium = require('sodium-native') @@ -269,7 +269,7 @@ export class UserResolver { const gradidoID = await newGradidoID() const eventRegisterRedeem = Event( - EventProtocolType.REDEEM_REGISTER, + EventType.REDEEM_REGISTER, { id: 0 } as DbUser, { id: 0 } as DbUser, )