From ae52b520dd0288e08f1fff35d461687bf3b96446 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 12:04:46 +0200 Subject: [PATCH] Withdrew where clause to an variable with inline condition. --- .../graphql/resolver/ContributionResolver.ts | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 0925fac9c..acf1b4cb0 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -48,31 +48,22 @@ export class ContributionResolver { @Ctx() context: Context, ): Promise { const user = getUser(context) - let contributions - if (filterConfirmed) { - contributions = await dbContribution.find({ - where: { + const where = filterConfirmed + ? { userId: user.id, confirmedBy: IsNull(), - }, - order: { - createdAt: order, - }, - skip: (currentPage - 1) * pageSize, - take: pageSize, - }) - } else { - contributions = await dbContribution.find({ - where: { + } + : { userId: user.id, - }, - order: { - createdAt: order, - }, - skip: (currentPage - 1) * pageSize, - take: pageSize, - }) - } + } + const contributions = await dbContribution.find({ + where, + order: { + createdAt: order, + }, + skip: (currentPage - 1) * pageSize, + take: pageSize, + }) return contributions.map((contribution) => new Contribution(contribution, new User(user))) } }