mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
WIP add elements to get contribution denying working in backend
This commit is contained in:
parent
5c42ec828a
commit
2fc2ecf5af
@ -298,6 +298,13 @@ export class Event {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setEventAdminContributionDeny(ev: EventAdminContributionDeny): Event {
|
||||||
|
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
||||||
|
this.type = EventProtocolType.ADMIN_CONTRIBUTION_DENY
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
public setEventAdminContributionUpdate(ev: EventAdminContributionUpdate): Event {
|
public setEventAdminContributionUpdate(ev: EventAdminContributionUpdate): Event {
|
||||||
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
||||||
this.type = EventProtocolType.ADMIN_CONTRIBUTION_UPDATE
|
this.type = EventProtocolType.ADMIN_CONTRIBUTION_UPDATE
|
||||||
|
|||||||
@ -44,6 +44,7 @@ import {
|
|||||||
EventContributionConfirm,
|
EventContributionConfirm,
|
||||||
EventAdminContributionCreate,
|
EventAdminContributionCreate,
|
||||||
EventAdminContributionDelete,
|
EventAdminContributionDelete,
|
||||||
|
EventAdminContributionDeny,
|
||||||
EventAdminContributionUpdate,
|
EventAdminContributionUpdate,
|
||||||
} from '@/event/Event'
|
} from '@/event/Event'
|
||||||
import { writeEvent } from '@/event/EventProtocolEmitter'
|
import { writeEvent } from '@/event/EventProtocolEmitter'
|
||||||
@ -559,6 +560,56 @@ export class ContributionResolver {
|
|||||||
return !!res
|
return !!res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.ADMIN_DENY_CONTRIBUTION])
|
||||||
|
@Mutation(() => Boolean)
|
||||||
|
async adminDenyContribution(
|
||||||
|
@Arg('id', () => Int) id: number,
|
||||||
|
@Ctx() context: Context,
|
||||||
|
): Promise<boolean> {
|
||||||
|
const contribution = await DbContribution.findOne(id)
|
||||||
|
if (!contribution) {
|
||||||
|
logger.error(`Contribution not found for given id: ${id}`)
|
||||||
|
throw new Error('Contribution not found for given id.')
|
||||||
|
}
|
||||||
|
if (contribution.confirmedAt) {
|
||||||
|
logger.error('A confirmed contribution can not be denied')
|
||||||
|
throw new Error('A confirmed contribution can not be denied')
|
||||||
|
}
|
||||||
|
const moderator = getUser(context)
|
||||||
|
if (
|
||||||
|
contribution.contributionType === ContributionType.USER &&
|
||||||
|
contribution.userId === moderator.id
|
||||||
|
) {
|
||||||
|
throw new Error('Own contribution can not be denied as admin')
|
||||||
|
}
|
||||||
|
const user = await DbUser.findOneOrFail(
|
||||||
|
{ id: contribution.userId },
|
||||||
|
{ relations: ['emailContact'] },
|
||||||
|
)
|
||||||
|
contribution.contributionStatus = ContributionStatus.DENIED
|
||||||
|
contribution.deniedBy = moderator.id
|
||||||
|
await contribution.save()
|
||||||
|
const res = await contribution.softRemove()
|
||||||
|
|
||||||
|
const event = new Event()
|
||||||
|
const eventAdminContributionDeny = new EventAdminContributionDeny()
|
||||||
|
eventAdminContributionDeny.userId = contribution.userId
|
||||||
|
eventAdminContributionDeny.amount = contribution.amount
|
||||||
|
eventAdminContributionDeny.contributionId = contribution.id
|
||||||
|
await writeEvent(event.setEventAdminContributionDeny(eventAdminContributionDeny))
|
||||||
|
sendContributionDeniedEmail({
|
||||||
|
firstName: user.firstName,
|
||||||
|
lastName: user.lastName,
|
||||||
|
email: user.emailContact.email,
|
||||||
|
language: user.language,
|
||||||
|
senderFirstName: moderator.firstName,
|
||||||
|
senderLastName: moderator.lastName,
|
||||||
|
contributionMemo: contribution.memo,
|
||||||
|
})
|
||||||
|
|
||||||
|
return !!res
|
||||||
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.CONFIRM_CONTRIBUTION])
|
@Authorized([RIGHTS.CONFIRM_CONTRIBUTION])
|
||||||
@Mutation(() => Boolean)
|
@Mutation(() => Boolean)
|
||||||
async confirmContribution(
|
async confirmContribution(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user