mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Change the listContribution query to give back ContributionListResult object with linkCount.
This commit is contained in:
parent
6e0db93591
commit
93c2d6814a
@ -2,6 +2,7 @@ import { RIGHTS } from '@/auth/RIGHTS'
|
|||||||
import { Context, getUser } from '@/server/context'
|
import { Context, getUser } from '@/server/context'
|
||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { Contribution as dbContribution } from '@entity/Contribution'
|
import { Contribution as dbContribution } from '@entity/Contribution'
|
||||||
|
import { User as dbUser } from '@entity/User'
|
||||||
import { Arg, Args, Authorized, Ctx, Int, Mutation, Query, Resolver } from 'type-graphql'
|
import { Arg, Args, Authorized, Ctx, Int, Mutation, Query, Resolver } from 'type-graphql'
|
||||||
import { FindOperator, IsNull } from '@dbTools/typeorm'
|
import { FindOperator, IsNull } from '@dbTools/typeorm'
|
||||||
import ContributionArgs from '@arg/ContributionArgs'
|
import ContributionArgs from '@arg/ContributionArgs'
|
||||||
@ -39,21 +40,21 @@ export class ContributionResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.LIST_CONTRIBUTIONS])
|
@Authorized([RIGHTS.LIST_CONTRIBUTIONS])
|
||||||
@Query(() => [Contribution])
|
@Query(() => ContributionListResult)
|
||||||
async listContributions(
|
async listContributions(
|
||||||
@Args()
|
@Args()
|
||||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
||||||
@Arg('filterConfirmed', () => Boolean)
|
@Arg('filterConfirmed', () => Boolean)
|
||||||
filterConfirmed: boolean | null,
|
filterConfirmed: boolean | null,
|
||||||
@Ctx() context: Context,
|
@Ctx() context: Context,
|
||||||
): Promise<Contribution[]> {
|
): Promise<ContributionListResult> {
|
||||||
const user = getUser(context)
|
const user = getUser(context)
|
||||||
const where: {
|
const where: {
|
||||||
userId: number
|
userId: number
|
||||||
confirmedBy?: FindOperator<number> | null
|
confirmedBy?: FindOperator<number> | null
|
||||||
} = { userId: user.id }
|
} = { userId: user.id }
|
||||||
if (filterConfirmed) where.confirmedBy = IsNull()
|
if (filterConfirmed) where.confirmedBy = IsNull()
|
||||||
const contributions = await dbContribution.find({
|
const [contributions, count] = await dbContribution.findAndCount({
|
||||||
where,
|
where,
|
||||||
order: {
|
order: {
|
||||||
createdAt: order,
|
createdAt: order,
|
||||||
@ -62,7 +63,10 @@ export class ContributionResolver {
|
|||||||
skip: (currentPage - 1) * pageSize,
|
skip: (currentPage - 1) * pageSize,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
})
|
})
|
||||||
return contributions.map((contribution) => new Contribution(contribution, new User(user)))
|
return new ContributionListResult(
|
||||||
|
count,
|
||||||
|
contributions.map((contribution) => new Contribution(contribution, new User(user))),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.LIST_ALL_CONTRIBUTIONS])
|
@Authorized([RIGHTS.LIST_ALL_CONTRIBUTIONS])
|
||||||
|
|||||||
@ -185,9 +185,12 @@ export const listContributions = gql`
|
|||||||
order: $order
|
order: $order
|
||||||
filterConfirmed: $filterConfirmed
|
filterConfirmed: $filterConfirmed
|
||||||
) {
|
) {
|
||||||
id
|
linkCount
|
||||||
amount
|
linkList {
|
||||||
memo
|
id
|
||||||
|
amount
|
||||||
|
memo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user