mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Change return value of createContribution from Boolean to UnconfirmedContribution, add constructor to UnconfirmedContribution.
This commit is contained in:
parent
6a9b4f7b9a
commit
c7ea879e36
@ -1,8 +1,23 @@
|
||||
import { ObjectType, Field, Int } from 'type-graphql'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { Contribution } from '@entity/Contribution'
|
||||
import { User } from '@entity/User'
|
||||
import { FULL_CREATION_AVAILABLE } from '../resolver/const/const'
|
||||
|
||||
@ObjectType()
|
||||
export class UnconfirmedContribution {
|
||||
constructor(contribution: Contribution, user: User, creations: Decimal[]) {
|
||||
this.id = contribution.id
|
||||
this.userId = contribution.userId
|
||||
this.amount = contribution.amount
|
||||
this.memo = contribution.memo
|
||||
this.date = contribution.contributionDate
|
||||
this.firstName = user ? user.firstName : ''
|
||||
this.lastName = user ? user.lastName : ''
|
||||
this.email = user ? user.email : ''
|
||||
this.creation = creations
|
||||
}
|
||||
|
||||
@Field(() => String)
|
||||
firstName: string
|
||||
|
||||
|
||||
@ -4,16 +4,17 @@ import { backendLogger as logger } from '@/server/logger'
|
||||
import { Contribution } from '@entity/Contribution'
|
||||
import { Args, Authorized, Ctx, Mutation, Resolver } from 'type-graphql'
|
||||
import ContributionArgs from '../arg/ContributionArgs'
|
||||
import { UnconfirmedContribution } from '../model/UnconfirmedContribution'
|
||||
import { isContributionValid, getUserCreation } from './util/isContributionValid'
|
||||
|
||||
@Resolver()
|
||||
export class ContributionResolver {
|
||||
@Authorized([RIGHTS.CREATE_CONTRIBUTION])
|
||||
@Mutation(() => Boolean)
|
||||
@Mutation(() => UnconfirmedContribution)
|
||||
async createContribution(
|
||||
@Args() { amount, memo, creationDate }: ContributionArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<boolean> {
|
||||
): Promise<UnconfirmedContribution> {
|
||||
const user = getUser(context)
|
||||
const creations = await getUserCreation(user.id)
|
||||
logger.trace('creations', creations)
|
||||
@ -29,6 +30,6 @@ export class ContributionResolver {
|
||||
|
||||
logger.trace('contribution to save', contribution)
|
||||
await Contribution.save(contribution)
|
||||
return true
|
||||
return new UnconfirmedContribution(contribution, user, creations)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user