From a50871185f19909e7f7019621edd2c253ba4e030 Mon Sep 17 00:00:00 2001 From: joseji Date: Fri, 7 Oct 2022 12:47:07 +0200 Subject: [PATCH] new contribution related admin events implemented and working --- .../graphql/resolver/AdminResolver.test.ts | 31 ++++++++++++++-- backend/src/graphql/resolver/AdminResolver.ts | 35 +++++++++++++++---- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 53097abbe..ad847bde1 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1121,10 +1121,10 @@ describe('AdminResolver', () => { ) }) - it('stores the create contribution event in the database', async () => { + it('stores the admin create contribution event in the database', async () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CREATE, + type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, userId: admin.id, }), ) @@ -1376,6 +1376,15 @@ describe('AdminResolver', () => { }), ) }) + + it('stores the admin update contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + userId: admin.id, + }), + ) + }) }) describe('creation update is successful without changing month', () => { @@ -1404,6 +1413,15 @@ describe('AdminResolver', () => { }), ) }) + + it('stores the admin update contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + userId: admin.id, + }), + ) + }) }) }) @@ -1505,6 +1523,15 @@ describe('AdminResolver', () => { }), ) }) + + it('stores the admin delete contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + userId: admin.id, + }), + ) + }) }) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index b03da9dc4..f228c01e3 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -69,8 +69,10 @@ import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributio import { eventProtocol } from '@/event/EventProtocolEmitter' import { Event, + EventAdminContributionCreate, + EventAdminContributionDelete, + EventAdminContributionUpdate, EventContributionConfirm, - EventContributionCreate, EventSendConfirmationEmail, } from '@/event/Event' @@ -278,11 +280,13 @@ export class AdminResolver { logger.trace('contribution to save', contribution) await Contribution.save(contribution) - const eventCreateContribution = new EventContributionCreate() - eventCreateContribution.userId = moderator.id - eventCreateContribution.amount = amount - eventCreateContribution.contributionId = contribution.id - await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) + const eventAdminCreateContribution = new EventAdminContributionCreate() + eventAdminCreateContribution.userId = moderator.id + eventAdminCreateContribution.amount = amount + eventAdminCreateContribution.contributionId = contribution.id + await eventProtocol.writeEvent( + event.setEventAdminContributionCreate(eventAdminCreateContribution), + ) return getUserCreation(emailContact.userId) } @@ -382,6 +386,15 @@ export class AdminResolver { result.creation = await getUserCreation(user.id) + const event = new Event() + const eventAdminContributionUpdate = new EventAdminContributionUpdate() + eventAdminContributionUpdate.userId = user.id + eventAdminContributionUpdate.amount = amount + eventAdminContributionUpdate.contributionId = contributionToUpdate.id + await eventProtocol.writeEvent( + event.setEventAdminContributionUpdate(eventAdminContributionUpdate), + ) + return result } @@ -431,6 +444,16 @@ export class AdminResolver { contribution.contributionStatus = ContributionStatus.DELETED await contribution.save() const res = await contribution.softRemove() + + const event = new Event() + const eventAdminContributionDelete = new EventAdminContributionDelete() + eventAdminContributionDelete.userId = contribution.userId + eventAdminContributionDelete.amount = contribution.amount + eventAdminContributionDelete.contributionId = contribution.id + await eventProtocol.writeEvent( + event.setEventAdminContributionDelete(eventAdminContributionDelete), + ) + return !!res }