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,
|
currentPage: 1,
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
filterConfirmed: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')])
|
expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')])
|
||||||
@ -1014,7 +1013,7 @@ describe('ContributionResolver', () => {
|
|||||||
resetToken()
|
resetToken()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('filter confirmed is false', () => {
|
describe('no status filter', () => {
|
||||||
it('returns creations', async () => {
|
it('returns creations', async () => {
|
||||||
const {
|
const {
|
||||||
data: { listContributions: contributionListResult },
|
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 () => {
|
it('returns only unconfirmed creations', async () => {
|
||||||
const {
|
const {
|
||||||
data: { listContributions: contributionListResult },
|
data: { listContributions: contributionListResult },
|
||||||
@ -1076,7 +1075,7 @@ describe('ContributionResolver', () => {
|
|||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 25,
|
pageSize: 25,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
filterConfirmed: true,
|
statusFilter: ['PENDING', 'IN_PROGRESS', 'DENIED', 'DELETED'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(contributionListResult).toMatchObject({
|
expect(contributionListResult).toMatchObject({
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import Decimal from 'decimal.js-light'
|
import Decimal from 'decimal.js-light'
|
||||||
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, getConnection } from '@dbTools/typeorm'
|
import { IsNull, getConnection } from '@dbTools/typeorm'
|
||||||
|
|
||||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||||
import { ContributionMessage } from '@entity/ContributionMessage'
|
import { ContributionMessage } from '@entity/ContributionMessage'
|
||||||
@ -127,35 +127,26 @@ export class ContributionResolver {
|
|||||||
@Authorized([RIGHTS.LIST_CONTRIBUTIONS])
|
@Authorized([RIGHTS.LIST_CONTRIBUTIONS])
|
||||||
@Query(() => ContributionListResult)
|
@Query(() => ContributionListResult)
|
||||||
async listContributions(
|
async listContributions(
|
||||||
|
@Ctx() context: Context,
|
||||||
@Args()
|
@Args()
|
||||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
||||||
@Arg('filterConfirmed', () => Boolean)
|
@Arg('statusFilter', () => [ContributionStatus], { nullable: true })
|
||||||
filterConfirmed: boolean | null,
|
statusFilter?: ContributionStatus[],
|
||||||
@Ctx() context: Context,
|
|
||||||
): Promise<ContributionListResult> {
|
): Promise<ContributionListResult> {
|
||||||
const user = getUser(context)
|
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(
|
return new ContributionListResult(
|
||||||
count,
|
count,
|
||||||
contributions.map((contribution) => new Contribution(contribution, user)),
|
dbContributions.map((contribution) => new Contribution(contribution, user)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +163,8 @@ export class ContributionResolver {
|
|||||||
currentPage,
|
currentPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
false,
|
false,
|
||||||
|
['user'],
|
||||||
|
undefined,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -398,6 +391,8 @@ export class ContributionResolver {
|
|||||||
currentPage,
|
currentPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
true,
|
true,
|
||||||
|
['user'],
|
||||||
|
undefined,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -8,18 +8,21 @@ export const findContributions = async (
|
|||||||
currentPage: number,
|
currentPage: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
withDeleted: boolean,
|
withDeleted: boolean,
|
||||||
|
relations: string[],
|
||||||
|
userId?: number,
|
||||||
statusFilter?: ContributionStatus[],
|
statusFilter?: ContributionStatus[],
|
||||||
): Promise<[DbContribution[], number]> =>
|
): Promise<[DbContribution[], number]> =>
|
||||||
DbContribution.findAndCount({
|
DbContribution.findAndCount({
|
||||||
where: {
|
where: {
|
||||||
...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }),
|
...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }),
|
||||||
|
...(userId && { userId }),
|
||||||
},
|
},
|
||||||
withDeleted: withDeleted,
|
withDeleted: withDeleted,
|
||||||
order: {
|
order: {
|
||||||
createdAt: order,
|
createdAt: order,
|
||||||
id: order,
|
id: order,
|
||||||
},
|
},
|
||||||
relations: ['user'],
|
relations,
|
||||||
skip: (currentPage - 1) * pageSize,
|
skip: (currentPage - 1) * pageSize,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -153,13 +153,13 @@ export const listContributions = gql`
|
|||||||
$currentPage: Int = 1
|
$currentPage: Int = 1
|
||||||
$pageSize: Int = 5
|
$pageSize: Int = 5
|
||||||
$order: Order
|
$order: Order
|
||||||
$filterConfirmed: Boolean = false
|
$statusFilter: [ContributionStatus!]
|
||||||
) {
|
) {
|
||||||
listContributions(
|
listContributions(
|
||||||
currentPage: $currentPage
|
currentPage: $currentPage
|
||||||
pageSize: $pageSize
|
pageSize: $pageSize
|
||||||
order: $order
|
order: $order
|
||||||
filterConfirmed: $filterConfirmed
|
statusFilter: $statusFilter
|
||||||
) {
|
) {
|
||||||
contributionCount
|
contributionCount
|
||||||
contributionList {
|
contributionList {
|
||||||
|
|||||||
@ -165,13 +165,13 @@ export const listContributions = gql`
|
|||||||
$currentPage: Int = 1
|
$currentPage: Int = 1
|
||||||
$pageSize: Int = 25
|
$pageSize: Int = 25
|
||||||
$order: Order = DESC
|
$order: Order = DESC
|
||||||
$filterConfirmed: Boolean = false
|
$statusFilter: [ContributionStatus!]
|
||||||
) {
|
) {
|
||||||
listContributions(
|
listContributions(
|
||||||
currentPage: $currentPage
|
currentPage: $currentPage
|
||||||
pageSize: $pageSize
|
pageSize: $pageSize
|
||||||
order: $order
|
order: $order
|
||||||
filterConfirmed: $filterConfirmed
|
statusFilter: $statusFilter
|
||||||
) {
|
) {
|
||||||
contributionCount
|
contributionCount
|
||||||
contributionList {
|
contributionList {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user