mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into 2730-devops-add-federation-modul-to-deployment-scripts
This commit is contained in:
commit
20ca891cc6
@ -995,7 +995,6 @@ describe('ContributionResolver', () => {
|
||||
currentPage: 1,
|
||||
pageSize: 25,
|
||||
order: 'DESC',
|
||||
filterConfirmed: false,
|
||||
},
|
||||
})
|
||||
expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')])
|
||||
@ -1014,7 +1013,7 @@ describe('ContributionResolver', () => {
|
||||
resetToken()
|
||||
})
|
||||
|
||||
describe('filter confirmed is false', () => {
|
||||
describe('no status filter', () => {
|
||||
it('returns creations', async () => {
|
||||
const {
|
||||
data: { listContributions: contributionListResult },
|
||||
@ -1066,7 +1065,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('filter confirmed is true', () => {
|
||||
describe('with status filter [PENDING, IN_PROGRESS, DENIED, DELETED]', () => {
|
||||
it('returns only unconfirmed creations', async () => {
|
||||
const {
|
||||
data: { listContributions: contributionListResult },
|
||||
@ -1076,7 +1075,7 @@ describe('ContributionResolver', () => {
|
||||
currentPage: 1,
|
||||
pageSize: 25,
|
||||
order: 'DESC',
|
||||
filterConfirmed: true,
|
||||
statusFilter: ['PENDING', 'IN_PROGRESS', 'DENIED', 'DELETED'],
|
||||
},
|
||||
})
|
||||
expect(contributionListResult).toMatchObject({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { Arg, Args, Authorized, Ctx, Int, Mutation, Query, Resolver } from 'type-graphql'
|
||||
import { FindOperator, IsNull, getConnection } from '@dbTools/typeorm'
|
||||
import { IsNull, getConnection } from '@dbTools/typeorm'
|
||||
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { ContributionMessage } from '@entity/ContributionMessage'
|
||||
@ -127,35 +127,26 @@ export class ContributionResolver {
|
||||
@Authorized([RIGHTS.LIST_CONTRIBUTIONS])
|
||||
@Query(() => ContributionListResult)
|
||||
async listContributions(
|
||||
@Ctx() context: Context,
|
||||
@Args()
|
||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
||||
@Arg('filterConfirmed', () => Boolean)
|
||||
filterConfirmed: boolean | null,
|
||||
@Ctx() context: Context,
|
||||
@Arg('statusFilter', () => [ContributionStatus], { nullable: true })
|
||||
statusFilter?: ContributionStatus[],
|
||||
): Promise<ContributionListResult> {
|
||||
const user = getUser(context)
|
||||
const where: {
|
||||
userId: number
|
||||
confirmedBy?: FindOperator<number> | null
|
||||
} = { userId: user.id }
|
||||
|
||||
if (filterConfirmed) where.confirmedBy = IsNull()
|
||||
|
||||
const [contributions, count] = await getConnection()
|
||||
.createQueryBuilder()
|
||||
.select('c')
|
||||
.from(DbContribution, 'c')
|
||||
.leftJoinAndSelect('c.messages', 'm')
|
||||
.where(where)
|
||||
.withDeleted()
|
||||
.orderBy('c.createdAt', order)
|
||||
.limit(pageSize)
|
||||
.offset((currentPage - 1) * pageSize)
|
||||
.getManyAndCount()
|
||||
|
||||
const [dbContributions, count] = await findContributions(
|
||||
order,
|
||||
currentPage,
|
||||
pageSize,
|
||||
true,
|
||||
['messages'],
|
||||
user.id,
|
||||
statusFilter,
|
||||
)
|
||||
return new ContributionListResult(
|
||||
count,
|
||||
contributions.map((contribution) => new Contribution(contribution, user)),
|
||||
dbContributions.map((contribution) => new Contribution(contribution, user)),
|
||||
)
|
||||
}
|
||||
|
||||
@ -172,6 +163,8 @@ export class ContributionResolver {
|
||||
currentPage,
|
||||
pageSize,
|
||||
false,
|
||||
['user'],
|
||||
undefined,
|
||||
statusFilter,
|
||||
)
|
||||
|
||||
@ -398,6 +391,8 @@ export class ContributionResolver {
|
||||
currentPage,
|
||||
pageSize,
|
||||
true,
|
||||
['user'],
|
||||
undefined,
|
||||
statusFilter,
|
||||
)
|
||||
|
||||
|
||||
@ -8,18 +8,21 @@ export const findContributions = async (
|
||||
currentPage: number,
|
||||
pageSize: number,
|
||||
withDeleted: boolean,
|
||||
relations: string[],
|
||||
userId?: number,
|
||||
statusFilter?: ContributionStatus[],
|
||||
): Promise<[DbContribution[], number]> =>
|
||||
DbContribution.findAndCount({
|
||||
where: {
|
||||
...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }),
|
||||
...(userId && { userId }),
|
||||
},
|
||||
withDeleted: withDeleted,
|
||||
order: {
|
||||
createdAt: order,
|
||||
id: order,
|
||||
},
|
||||
relations: ['user'],
|
||||
relations,
|
||||
skip: (currentPage - 1) * pageSize,
|
||||
take: pageSize,
|
||||
})
|
||||
|
||||
@ -153,13 +153,13 @@ export const listContributions = gql`
|
||||
$currentPage: Int = 1
|
||||
$pageSize: Int = 5
|
||||
$order: Order
|
||||
$filterConfirmed: Boolean = false
|
||||
$statusFilter: [ContributionStatus!]
|
||||
) {
|
||||
listContributions(
|
||||
currentPage: $currentPage
|
||||
pageSize: $pageSize
|
||||
order: $order
|
||||
filterConfirmed: $filterConfirmed
|
||||
statusFilter: $statusFilter
|
||||
) {
|
||||
contributionCount
|
||||
contributionList {
|
||||
|
||||
@ -165,13 +165,13 @@ export const listContributions = gql`
|
||||
$currentPage: Int = 1
|
||||
$pageSize: Int = 25
|
||||
$order: Order = DESC
|
||||
$filterConfirmed: Boolean = false
|
||||
$statusFilter: [ContributionStatus!]
|
||||
) {
|
||||
listContributions(
|
||||
currentPage: $currentPage
|
||||
pageSize: $pageSize
|
||||
order: $order
|
||||
filterConfirmed: $filterConfirmed
|
||||
statusFilter: $statusFilter
|
||||
) {
|
||||
contributionCount
|
||||
contributionList {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user