mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2340 from gradido/2272-send-email-for-rejected-contributions
feat(backend): 🍰 Send email for rejected contributions
This commit is contained in:
commit
d4d68b0748
@ -63,6 +63,7 @@ import ContributionMessageArgs from '@arg/ContributionMessageArgs'
|
|||||||
import { ContributionMessageType } from '@enum/MessageType'
|
import { ContributionMessageType } from '@enum/MessageType'
|
||||||
import { ContributionMessage } from '@model/ContributionMessage'
|
import { ContributionMessage } from '@model/ContributionMessage'
|
||||||
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
import { sendContributionConfirmedEmail } from '@/mailer/sendContributionConfirmedEmail'
|
||||||
|
import { sendContributionRejectedEmail } from '@/mailer/sendContributionRejectedEmail'
|
||||||
import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributionMessageEmail'
|
import { sendAddedContributionMessageEmail } from '@/mailer/sendAddedContributionMessageEmail'
|
||||||
import { eventProtocol } from '@/event/EventProtocolEmitter'
|
import { eventProtocol } from '@/event/EventProtocolEmitter'
|
||||||
import {
|
import {
|
||||||
@ -455,6 +456,10 @@ export class AdminResolver {
|
|||||||
) {
|
) {
|
||||||
throw new Error('Own contribution can not be deleted as admin')
|
throw new Error('Own contribution can not be deleted as admin')
|
||||||
}
|
}
|
||||||
|
const user = await dbUser.findOneOrFail(
|
||||||
|
{ id: contribution.userId },
|
||||||
|
{ relations: ['emailContact'] },
|
||||||
|
)
|
||||||
contribution.contributionStatus = ContributionStatus.DELETED
|
contribution.contributionStatus = ContributionStatus.DELETED
|
||||||
contribution.deletedBy = moderator.id
|
contribution.deletedBy = moderator.id
|
||||||
await contribution.save()
|
await contribution.save()
|
||||||
@ -468,6 +473,16 @@ export class AdminResolver {
|
|||||||
await eventProtocol.writeEvent(
|
await eventProtocol.writeEvent(
|
||||||
event.setEventAdminContributionDelete(eventAdminContributionDelete),
|
event.setEventAdminContributionDelete(eventAdminContributionDelete),
|
||||||
)
|
)
|
||||||
|
sendContributionRejectedEmail({
|
||||||
|
senderFirstName: moderator.firstName,
|
||||||
|
senderLastName: moderator.lastName,
|
||||||
|
recipientEmail: user.emailContact.email,
|
||||||
|
recipientFirstName: user.firstName,
|
||||||
|
recipientLastName: user.lastName,
|
||||||
|
contributionMemo: contribution.memo,
|
||||||
|
contributionAmount: contribution.amount,
|
||||||
|
overviewURL: CONFIG.EMAIL_LINK_OVERVIEW,
|
||||||
|
})
|
||||||
|
|
||||||
return !!res
|
return !!res
|
||||||
}
|
}
|
||||||
|
|||||||
38
backend/src/mailer/sendContributionRejectedEmail.test.ts
Normal file
38
backend/src/mailer/sendContributionRejectedEmail.test.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import Decimal from 'decimal.js-light'
|
||||||
|
import { sendContributionRejectedEmail } from './sendContributionRejectedEmail'
|
||||||
|
import { sendEMail } from './sendEMail'
|
||||||
|
|
||||||
|
jest.mock('./sendEMail', () => {
|
||||||
|
return {
|
||||||
|
__esModule: true,
|
||||||
|
sendEMail: jest.fn(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('sendContributionConfirmedEmail', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await sendContributionRejectedEmail({
|
||||||
|
senderFirstName: 'Peter',
|
||||||
|
senderLastName: 'Lustig',
|
||||||
|
recipientFirstName: 'Bibi',
|
||||||
|
recipientLastName: 'Bloxberg',
|
||||||
|
recipientEmail: 'bibi@bloxberg.de',
|
||||||
|
contributionMemo: 'Vielen herzlichen Dank für den neuen Hexenbesen!',
|
||||||
|
contributionAmount: new Decimal(200.0),
|
||||||
|
overviewURL: 'http://localhost/overview',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls sendEMail', () => {
|
||||||
|
expect(sendEMail).toBeCalledWith({
|
||||||
|
to: 'Bibi Bloxberg <bibi@bloxberg.de>',
|
||||||
|
subject: 'Schöpfung wurde abgelehnt',
|
||||||
|
text:
|
||||||
|
expect.stringContaining('Hallo Bibi Bloxberg') &&
|
||||||
|
expect.stringContaining(
|
||||||
|
'Dein Gradido Schöpfungsantrag "Vielen herzlichen Dank für den neuen Hexenbesen!" wurde soeben von Peter Lustig abgelehnt.',
|
||||||
|
) &&
|
||||||
|
expect.stringContaining('Link zu deinem Konto: http://localhost/overview'),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
26
backend/src/mailer/sendContributionRejectedEmail.ts
Normal file
26
backend/src/mailer/sendContributionRejectedEmail.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
|
import Decimal from 'decimal.js-light'
|
||||||
|
import { sendEMail } from './sendEMail'
|
||||||
|
import { contributionRejected } from './text/contributionRejected'
|
||||||
|
|
||||||
|
export const sendContributionRejectedEmail = (data: {
|
||||||
|
senderFirstName: string
|
||||||
|
senderLastName: string
|
||||||
|
recipientFirstName: string
|
||||||
|
recipientLastName: string
|
||||||
|
recipientEmail: string
|
||||||
|
contributionMemo: string
|
||||||
|
contributionAmount: Decimal
|
||||||
|
overviewURL: string
|
||||||
|
}): Promise<boolean> => {
|
||||||
|
logger.info(
|
||||||
|
`sendEmail(): to=${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>,
|
||||||
|
subject=${contributionRejected.de.subject},
|
||||||
|
text=${contributionRejected.de.text(data)}`,
|
||||||
|
)
|
||||||
|
return sendEMail({
|
||||||
|
to: `${data.recipientFirstName} ${data.recipientLastName} <${data.recipientEmail}>`,
|
||||||
|
subject: contributionRejected.de.subject,
|
||||||
|
text: contributionRejected.de.text(data),
|
||||||
|
})
|
||||||
|
}
|
||||||
27
backend/src/mailer/text/contributionRejected.ts
Normal file
27
backend/src/mailer/text/contributionRejected.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import Decimal from 'decimal.js-light'
|
||||||
|
|
||||||
|
export const contributionRejected = {
|
||||||
|
de: {
|
||||||
|
subject: 'Schöpfung wurde abgelehnt',
|
||||||
|
text: (data: {
|
||||||
|
senderFirstName: string
|
||||||
|
senderLastName: string
|
||||||
|
recipientFirstName: string
|
||||||
|
recipientLastName: string
|
||||||
|
contributionMemo: string
|
||||||
|
contributionAmount: Decimal
|
||||||
|
overviewURL: string
|
||||||
|
}): string =>
|
||||||
|
`Hallo ${data.recipientFirstName} ${data.recipientLastName},
|
||||||
|
|
||||||
|
Dein eingereichter Gemeinwohl-Beitrag "${data.contributionMemo}" wurde soeben von ${data.senderFirstName} ${data.senderLastName} abgelehnt.
|
||||||
|
|
||||||
|
Bitte antworte nicht auf diese E-Mail!
|
||||||
|
|
||||||
|
Mit freundlichen Grüßen,
|
||||||
|
dein Gradido-Team
|
||||||
|
|
||||||
|
|
||||||
|
Link zu deinem Konto: ${data.overviewURL}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user