new contribution related admin events implemented and working

This commit is contained in:
joseji 2022-10-07 12:47:07 +02:00
parent 088e30daae
commit a50871185f
2 changed files with 58 additions and 8 deletions

View File

@ -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( await expect(EventProtocol.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.CONTRIBUTION_CREATE, type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE,
userId: admin.id, 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', () => { 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,
}),
)
})
}) })
}) })

View File

@ -69,8 +69,10 @@ import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributio
import { eventProtocol } from '@/event/EventProtocolEmitter' import { eventProtocol } from '@/event/EventProtocolEmitter'
import { import {
Event, Event,
EventAdminContributionCreate,
EventAdminContributionDelete,
EventAdminContributionUpdate,
EventContributionConfirm, EventContributionConfirm,
EventContributionCreate,
EventSendConfirmationEmail, EventSendConfirmationEmail,
} from '@/event/Event' } from '@/event/Event'
@ -278,11 +280,13 @@ export class AdminResolver {
logger.trace('contribution to save', contribution) logger.trace('contribution to save', contribution)
await Contribution.save(contribution) await Contribution.save(contribution)
const eventCreateContribution = new EventContributionCreate() const eventAdminCreateContribution = new EventAdminContributionCreate()
eventCreateContribution.userId = moderator.id eventAdminCreateContribution.userId = moderator.id
eventCreateContribution.amount = amount eventAdminCreateContribution.amount = amount
eventCreateContribution.contributionId = contribution.id eventAdminCreateContribution.contributionId = contribution.id
await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution)) await eventProtocol.writeEvent(
event.setEventAdminContributionCreate(eventAdminCreateContribution),
)
return getUserCreation(emailContact.userId) return getUserCreation(emailContact.userId)
} }
@ -382,6 +386,15 @@ export class AdminResolver {
result.creation = await getUserCreation(user.id) 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 return result
} }
@ -431,6 +444,16 @@ export class AdminResolver {
contribution.contributionStatus = ContributionStatus.DELETED contribution.contributionStatus = ContributionStatus.DELETED
await contribution.save() await contribution.save()
const res = await contribution.softRemove() 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 return !!res
} }