mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
remove email from admin update contribution
This commit is contained in:
parent
774f9e6b81
commit
ac2ce5e6b1
@ -6,9 +6,6 @@ export default class AdminUpdateContributionArgs {
|
||||
@Field(() => Int)
|
||||
id: number
|
||||
|
||||
@Field(() => String)
|
||||
email: string
|
||||
|
||||
@Field(() => Decimal)
|
||||
amount: Decimal
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ export class Contribution {
|
||||
this.deletedAt = contribution.deletedAt
|
||||
this.deletedBy = contribution.deletedBy
|
||||
this.moderatorId = contribution.moderatorId
|
||||
this.userId = contribution.userId
|
||||
}
|
||||
|
||||
@Field(() => Number)
|
||||
@ -69,8 +70,11 @@ export class Contribution {
|
||||
@Field(() => String)
|
||||
state: string
|
||||
|
||||
@Field(() => Number, { nullable: true })
|
||||
@Field(() => Int, { nullable: true })
|
||||
moderatorId: number | null
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
userId: number | null
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
|
||||
@ -313,41 +313,27 @@ export class ContributionResolver {
|
||||
@Authorized([RIGHTS.ADMIN_UPDATE_CONTRIBUTION])
|
||||
@Mutation(() => AdminUpdateContribution)
|
||||
async adminUpdateContribution(
|
||||
@Args() { id, email, amount, memo, creationDate }: AdminUpdateContributionArgs,
|
||||
@Args() { id, amount, memo, creationDate }: AdminUpdateContributionArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<AdminUpdateContribution> {
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
const emailContact = await UserContact.findOne({
|
||||
where: { email },
|
||||
withDeleted: true,
|
||||
relations: ['user'],
|
||||
})
|
||||
if (!emailContact || !emailContact.user) {
|
||||
throw new LogError('Could not find User', email)
|
||||
}
|
||||
if (emailContact.deletedAt || emailContact.user.deletedAt) {
|
||||
throw new LogError('User was deleted', email)
|
||||
}
|
||||
|
||||
const moderator = getUser(context)
|
||||
|
||||
const contributionToUpdate = await DbContribution.findOne({
|
||||
where: { id, confirmedAt: IsNull(), deniedAt: IsNull() },
|
||||
})
|
||||
|
||||
if (!contributionToUpdate) {
|
||||
throw new LogError('Contribution not found', id)
|
||||
}
|
||||
|
||||
if (contributionToUpdate.userId !== emailContact.user.id) {
|
||||
throw new LogError('User of the pending contribution and send user does not correspond')
|
||||
}
|
||||
|
||||
if (contributionToUpdate.moderatorId === null) {
|
||||
throw new LogError('An admin is not allowed to update an user contribution')
|
||||
}
|
||||
|
||||
const creationDateObj = new Date(creationDate)
|
||||
let creations = await getUserCreation(emailContact.user.id, clientTimezoneOffset)
|
||||
let creations = await getUserCreation(contributionToUpdate.userId, clientTimezoneOffset)
|
||||
|
||||
// TODO: remove this restriction
|
||||
if (contributionToUpdate.contributionDate.getMonth() === creationDateObj.getMonth()) {
|
||||
@ -371,9 +357,13 @@ export class ContributionResolver {
|
||||
result.memo = contributionToUpdate.memo
|
||||
result.date = contributionToUpdate.contributionDate
|
||||
|
||||
result.creation = await getUserCreation(emailContact.user.id, clientTimezoneOffset)
|
||||
result.creation = await getUserCreation(contributionToUpdate.userId, clientTimezoneOffset)
|
||||
|
||||
await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount)
|
||||
await EVENT_ADMIN_CONTRIBUTION_UPDATE(
|
||||
contributionToUpdate.userId,
|
||||
contributionToUpdate.id,
|
||||
amount,
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user