mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2061 from gradido/add_count_to_list_contributions
Fix: Add count to list contributions
This commit is contained in:
commit
298f76de0f
@ -48,13 +48,13 @@ export class Contribution {
|
|||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class ContributionListResult {
|
export class ContributionListResult {
|
||||||
constructor(count: number, list: Contribution[]) {
|
constructor(count: number, list: Contribution[]) {
|
||||||
this.linkCount = count
|
this.contributionCount = count
|
||||||
this.linkList = list
|
this.contributionList = list
|
||||||
}
|
}
|
||||||
|
|
||||||
@Field(() => Int)
|
@Field(() => Int)
|
||||||
linkCount: number
|
contributionCount: number
|
||||||
|
|
||||||
@Field(() => [Contribution])
|
@Field(() => [Contribution])
|
||||||
linkList: Contribution[]
|
contributionList: Contribution[]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -193,7 +193,9 @@ describe('ContributionResolver', () => {
|
|||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listContributions: expect.arrayContaining([
|
listContributions: {
|
||||||
|
contributionCount: 2,
|
||||||
|
contributionList: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(Number),
|
id: expect.any(Number),
|
||||||
memo: 'Herzlich Willkommen bei Gradido!',
|
memo: 'Herzlich Willkommen bei Gradido!',
|
||||||
@ -206,6 +208,7 @@ describe('ContributionResolver', () => {
|
|||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -226,7 +229,9 @@ describe('ContributionResolver', () => {
|
|||||||
).resolves.toEqual(
|
).resolves.toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listContributions: expect.arrayContaining([
|
listContributions: {
|
||||||
|
contributionCount: 1,
|
||||||
|
contributionList: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(Number),
|
id: expect.any(Number),
|
||||||
memo: 'Test env contribution',
|
memo: 'Test env contribution',
|
||||||
@ -234,6 +239,7 @@ describe('ContributionResolver', () => {
|
|||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -496,8 +502,8 @@ describe('ContributionResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listAllContributions: {
|
listAllContributions: {
|
||||||
linkCount: 2,
|
contributionCount: 2,
|
||||||
linkList: expect.arrayContaining([
|
contributionList: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(Number),
|
id: expect.any(Number),
|
||||||
memo: 'Herzlich Willkommen bei Gradido!',
|
memo: 'Herzlich Willkommen bei Gradido!',
|
||||||
|
|||||||
@ -39,21 +39,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 +62,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,18 +185,21 @@ export const listContributions = gql`
|
|||||||
order: $order
|
order: $order
|
||||||
filterConfirmed: $filterConfirmed
|
filterConfirmed: $filterConfirmed
|
||||||
) {
|
) {
|
||||||
|
contributionCount
|
||||||
|
contributionList {
|
||||||
id
|
id
|
||||||
amount
|
amount
|
||||||
memo
|
memo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export const listAllContributions = `
|
export const listAllContributions = `
|
||||||
query ($currentPage: Int = 1, $pageSize: Int = 5, $order: Order = DESC) {
|
query ($currentPage: Int = 1, $pageSize: Int = 5, $order: Order = DESC) {
|
||||||
listAllContributions(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
|
listAllContributions(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
|
||||||
linkCount
|
contributionCount
|
||||||
linkList {
|
contributionList {
|
||||||
id
|
id
|
||||||
firstName
|
firstName
|
||||||
lastName
|
lastName
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user