From f8b0d52afd9b68be757e609bd215fa2c35e3c912 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 30 Jun 2022 13:57:30 +0200 Subject: [PATCH 01/16] Add ROLES and RIGHTS for users to query listContributions. --- backend/src/auth/RIGHTS.ts | 1 + backend/src/auth/ROLES.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index c10fc96de..6a6f8b7c0 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -26,6 +26,7 @@ export enum RIGHTS { LIST_TRANSACTION_LINKS = 'LIST_TRANSACTION_LINKS', GDT_BALANCE = 'GDT_BALANCE', CREATE_CONTRIBUTION = 'CREATE_CONTRIBUTION', + LIST_CONTRIBUTIONS = 'LIST_CONTRIBUTIONS', // Admin SEARCH_USERS = 'SEARCH_USERS', SET_USER_ROLE = 'SET_USER_ROLE', diff --git a/backend/src/auth/ROLES.ts b/backend/src/auth/ROLES.ts index 2d9ac2deb..f56106664 100644 --- a/backend/src/auth/ROLES.ts +++ b/backend/src/auth/ROLES.ts @@ -24,6 +24,7 @@ export const ROLE_USER = new Role('user', [ RIGHTS.LIST_TRANSACTION_LINKS, RIGHTS.GDT_BALANCE, RIGHTS.CREATE_CONTRIBUTION, + RIGHTS.LIST_CONTRIBUTIONS, ]) export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights From f19a6f1d15a14331711305e83e7a0df848c98923 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 30 Jun 2022 13:58:21 +0200 Subject: [PATCH 02/16] Create model for Contribution and create function to query listContributions. --- backend/src/graphql/model/Contribution.ts | 44 ++++++++++++++++ .../graphql/resolver/ContributionResolver.ts | 51 +++++++++++++++++-- 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 backend/src/graphql/model/Contribution.ts diff --git a/backend/src/graphql/model/Contribution.ts b/backend/src/graphql/model/Contribution.ts new file mode 100644 index 000000000..cd8c94d74 --- /dev/null +++ b/backend/src/graphql/model/Contribution.ts @@ -0,0 +1,44 @@ +import { ObjectType, Field, Int } from 'type-graphql' +import Decimal from 'decimal.js-light' +import { Contribution as dbContribution } from '@entity/Contribution' +import { User } from './User' +import CONFIG from '@/config' + +@ObjectType() +export class Contribution { + constructor(contribution: dbContribution, user: User) { + this.id = contribution.id + this.user = user + this.amount = contribution.amount + this.memo = contribution.memo + this.createdAt = contribution.createdAt + this.deletedAt = contribution.deletedAt + } + + @Field(() => Number) + id: number + + @Field(() => User) + user: User + + @Field(() => Decimal) + amount: Decimal + + @Field(() => String) + memo: string + + @Field(() => Date) + createdAt: Date + + @Field(() => Date, { nullable: true }) + deletedAt: Date | null +} + +@ObjectType() +export class ContributionListResult { + @Field(() => Int) + linkCount: number + + @Field(() => [Contribution]) + linkList: Contribution[] +} diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 924108f87..c3b4c2127 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -1,10 +1,15 @@ import { RIGHTS } from '@/auth/RIGHTS' import { Context, getUser } from '@/server/context' import { backendLogger as logger } from '@/server/logger' -import { Contribution } from '@entity/Contribution' -import { Args, Authorized, Ctx, Mutation, Resolver } from 'type-graphql' +import { Contribution as dbContribution } from '@entity/Contribution' +import { Arg, Args, Authorized, Ctx, Mutation, Query, Resolver } from 'type-graphql' +import { IsNull, Not } from '../../../../database/node_modules/typeorm' import ContributionArgs from '../arg/ContributionArgs' +import Paginated from '../arg/Paginated' +import { Order } from '../enum/Order' +import { Contribution } from '../model/Contribution' import { UnconfirmedContribution } from '../model/UnconfirmedContribution' +import { User } from '../model/User' import { isContributionValid, getUserCreation } from './util/isContributionValid' @Resolver() @@ -21,7 +26,7 @@ export class ContributionResolver { const creationDateObj = new Date(creationDate) isContributionValid(creations, amount, creationDateObj) - const contribution = Contribution.create() + const contribution = dbContribution.create() contribution.userId = user.id contribution.amount = amount contribution.createdAt = new Date() @@ -29,7 +34,45 @@ export class ContributionResolver { contribution.memo = memo logger.trace('contribution to save', contribution) - await Contribution.save(contribution) + await dbContribution.save(contribution) return new UnconfirmedContribution(contribution, user, creations) } + + @Authorized([RIGHTS.LIST_CONTRIBUTIONS]) + @Query(() => [Contribution]) + async listContributions( + @Args() + { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, + @Arg('filterConfirmed', () => Boolean) + filterConfirmed: boolean | null, + @Ctx() context: Context, + ): Promise { + const user = getUser(context) + let contribution + if (filterConfirmed) { + contribution = await dbContribution.find({ + where: { + userId: user.id, + confirmedBy: IsNull(), + }, + order: { + createdAt: order, + }, + skip: (currentPage - 1) * pageSize, + take: pageSize, + }) + } else { + contribution = await dbContribution.find({ + where: { + userId: user.id, + }, + order: { + createdAt: order, + }, + skip: (currentPage - 1) * pageSize, + take: pageSize, + }) + } + return contribution.map((contr) => new Contribution(contr, new User(user))) + } } From 3ce80fc081101df68d6ecb92287c6fd19e921517 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 30 Jun 2022 16:47:44 +0200 Subject: [PATCH 03/16] Remove unused imports. --- backend/src/graphql/model/Contribution.ts | 1 - backend/src/graphql/resolver/ContributionResolver.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/graphql/model/Contribution.ts b/backend/src/graphql/model/Contribution.ts index cd8c94d74..dc1dd39e9 100644 --- a/backend/src/graphql/model/Contribution.ts +++ b/backend/src/graphql/model/Contribution.ts @@ -2,7 +2,6 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' import { Contribution as dbContribution } from '@entity/Contribution' import { User } from './User' -import CONFIG from '@/config' @ObjectType() export class Contribution { diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index c3b4c2127..6669ef20d 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -3,7 +3,7 @@ import { Context, getUser } from '@/server/context' import { backendLogger as logger } from '@/server/logger' import { Contribution as dbContribution } from '@entity/Contribution' import { Arg, Args, Authorized, Ctx, Mutation, Query, Resolver } from 'type-graphql' -import { IsNull, Not } from '../../../../database/node_modules/typeorm' +import { IsNull } from '../../../../database/node_modules/typeorm' import ContributionArgs from '../arg/ContributionArgs' import Paginated from '../arg/Paginated' import { Order } from '../enum/Order' From 7d23be6901ce1859aeebb81965ef2b38090f6fed Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 1 Jul 2022 12:54:04 +0200 Subject: [PATCH 04/16] Add query for listContributions. --- backend/src/seeds/graphql/queries.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 531aebf0f..cf0fd09bd 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -172,6 +172,24 @@ export const queryTransactionLink = gql` } ` +export const listContributions = gql` + query ( + $currentPage: Int = 1 + $pageSize: Int = 5 + $order: Order + $filterConfirmed: Boolean = false + ) { + listContributions( + currentPage: $currentPage + pageSize: $pageSize + order: $order + filterConfirmed: $filterConfirmed + ) { + amount + memo + } + } +` // from admin interface export const listUnconfirmedContributions = gql` From 58a350155bfd8dc2183ac775cfac4b09ce87fcdb Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 1 Jul 2022 12:54:46 +0200 Subject: [PATCH 05/16] Add tests that confirmed contribution are found and no unconfirmed contributions are found. --- .../resolver/ContributionResolver.test.ts | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 01e9b123e..2308cd4e7 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -3,10 +3,13 @@ import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { createContribution } from '@/seeds/graphql/mutations' -import { login } from '@/seeds/graphql/queries' +import { listContributions, login } from '@/seeds/graphql/queries' import { cleanDB, resetToken, testEnvironment } from '@test/helpers' import { GraphQLError } from 'graphql' import { userFactory } from '@/seeds/factory/user' +import { creationFactory } from '@/seeds/factory/creation' +import { creations } from '@/seeds/creation/index' +import { peterLustig } from '@/seeds/users/peter-lustig' let mutate: any, query: any, con: any let testEnv: any @@ -121,4 +124,92 @@ describe('ContributionResolver', () => { }) }) }) + + describe('listContributions', () => { + describe('unauthenticated', () => { + it('returns an error', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + + describe('authenticated', () => { + beforeAll(async () => { + await userFactory(testEnv, peterLustig) + await userFactory(testEnv, bibiBloxberg) + // bibi needs GDDs + const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + await creationFactory(testEnv, bibisCreation!) + // await userFactory(testEnv, bibiBloxberg) + await query({ + query: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + await cleanDB() + resetToken() + }) + + it('returns an empty array for unconfirmed creation filter', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: true, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + listContributions: [], + }, + }), + ) + }) + + it('returns confirmed creation', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + listContributions: expect.arrayContaining([ + expect.objectContaining({ + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + ]), + }, + }), + ) + }) + }) + }) }) From 3718f0dc56ef3d0363c2911bca6c4da9891f3959 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 11:42:24 +0200 Subject: [PATCH 06/16] Change the test so that we can test if the contribution list finds only created but not confirmed contribution --- .../resolver/ContributionResolver.test.ts | 91 ++++++++++++------- backend/src/seeds/graphql/mutations.ts | 1 + backend/src/seeds/graphql/queries.ts | 1 + 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 2308cd4e7..01ece7440 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -13,6 +13,7 @@ import { peterLustig } from '@/seeds/users/peter-lustig' let mutate: any, query: any, con: any let testEnv: any +let result: any beforeAll(async () => { testEnv = await testEnvironment() @@ -114,6 +115,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { createContribution: { + id: expect.any(Number), amount: '100', memo: 'Test env contribution', }, @@ -148,25 +150,22 @@ describe('ContributionResolver', () => { describe('authenticated', () => { beforeAll(async () => { - await userFactory(testEnv, peterLustig) await userFactory(testEnv, bibiBloxberg) - // bibi needs GDDs - const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await creationFactory(testEnv, bibisCreation!) - // await userFactory(testEnv, bibiBloxberg) await query({ query: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) + await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) }) - afterAll(async () => { - await cleanDB() - resetToken() - }) - - it('returns an empty array for unconfirmed creation filter', async () => { + it('returns only unconfirmed creations', async () => { await expect( query({ query: listContributions, @@ -177,39 +176,63 @@ describe('ContributionResolver', () => { filterConfirmed: true, }, }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listContributions: [], - }, - }), - ) - }) - - it('returns confirmed creation', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: false, - }, - }), ).resolves.toEqual( expect.objectContaining({ data: { listContributions: expect.arrayContaining([ expect.objectContaining({ - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', + id: expect.any(Number), + memo: 'Test env contribution', + amount: '100', }), ]), }, }), ) }) + + describe('Adding confirmed creations', () => { + beforeAll(async () => { + await userFactory(testEnv, peterLustig) + const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') + await creationFactory(testEnv, bibisCreation!) + await query({ + query: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + it('returns confirmed and unconfirmed creation', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + listContributions: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(Number), + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test env contribution', + amount: '100', + }), + ]), + }, + }), + ) + }) + }) }) }) }) diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 4926f706f..185485f2c 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -234,6 +234,7 @@ export const deleteContributionLink = gql` export const createContribution = gql` mutation ($amount: Decimal!, $memo: String!, $creationDate: String!) { createContribution(amount: $amount, memo: $memo, creationDate: $creationDate) { + id amount memo } diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index cf0fd09bd..c27ecdd66 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -185,6 +185,7 @@ export const listContributions = gql` order: $order filterConfirmed: $filterConfirmed ) { + id amount memo } From a2eccb12ed5b2e421d3ee8fd328afcc94c4def13 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 11:42:39 +0200 Subject: [PATCH 07/16] Change the variable name contribution to contributions. --- backend/src/graphql/resolver/ContributionResolver.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 59f1f359f..0925fac9c 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -48,9 +48,9 @@ export class ContributionResolver { @Ctx() context: Context, ): Promise { const user = getUser(context) - let contribution + let contributions if (filterConfirmed) { - contribution = await dbContribution.find({ + contributions = await dbContribution.find({ where: { userId: user.id, confirmedBy: IsNull(), @@ -62,7 +62,7 @@ export class ContributionResolver { take: pageSize, }) } else { - contribution = await dbContribution.find({ + contributions = await dbContribution.find({ where: { userId: user.id, }, @@ -73,6 +73,6 @@ export class ContributionResolver { take: pageSize, }) } - return contribution.map((contr) => new Contribution(contr, new User(user))) + return contributions.map((contribution) => new Contribution(contribution, new User(user))) } } From ae52b520dd0288e08f1fff35d461687bf3b96446 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 12:04:46 +0200 Subject: [PATCH 08/16] 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))) } } From 9239f93096afe579bc1f2a0cc0b44bed1d730d7f Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 12:21:51 +0200 Subject: [PATCH 09/16] Add no non nullable assertion to admin Creation. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 01ece7440..fcaaca11a 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -13,7 +13,6 @@ import { peterLustig } from '@/seeds/users/peter-lustig' let mutate: any, query: any, con: any let testEnv: any -let result: any beforeAll(async () => { testEnv = await testEnvironment() @@ -195,6 +194,7 @@ describe('ContributionResolver', () => { beforeAll(async () => { await userFactory(testEnv, peterLustig) const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await creationFactory(testEnv, bibisCreation!) await query({ query: login, From caf4e9ae3e627cc6440636edf720cedd51fa51ec Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 14:04:38 +0200 Subject: [PATCH 10/16] Change the test name to filterConfirmed is false. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index fcaaca11a..1e3034b59 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -202,7 +202,7 @@ describe('ContributionResolver', () => { }) }) - it('returns confirmed and unconfirmed creation', async () => { + it('filter confirmed is false', async () => { await expect( query({ query: listContributions, From 2113061629310c0eee75049f300af42ba79bdaa1 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 14:05:57 +0200 Subject: [PATCH 11/16] Change the imports to the standard. --- .../src/graphql/resolver/ContributionResolver.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index acf1b4cb0..a54a5e6bf 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -3,13 +3,13 @@ import { Context, getUser } from '@/server/context' import { backendLogger as logger } from '@/server/logger' import { Contribution as dbContribution } from '@entity/Contribution' import { Arg, Args, Authorized, Ctx, Mutation, Query, Resolver } from 'type-graphql' -import { IsNull } from '../../../../database/node_modules/typeorm' -import ContributionArgs from '../arg/ContributionArgs' -import Paginated from '../arg/Paginated' -import { Order } from '../enum/Order' -import { Contribution } from '../model/Contribution' -import { UnconfirmedContribution } from '../model/UnconfirmedContribution' -import { User } from '../model/User' +import { IsNull } from '@dbTools/typeorm' +import ContributionArgs from '@arg/ContributionArgs' +import Paginated from '@arg/Paginated' +import { Order } from '@enum/Order' +import { Contribution } from '@model/Contribution' +import { UnconfirmedContribution } from '@model/UnconfirmedContribution' +import { User } from '@model/User' import { validateContribution, getUserCreation } from './util/creations' @Resolver() From f8cdad7e58bfb232d7780543974a6f39787fadfd Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 14:07:57 +0200 Subject: [PATCH 12/16] Change the where clause to a defined object. --- .../src/graphql/resolver/ContributionResolver.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index a54a5e6bf..3e13c404c 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -3,7 +3,7 @@ import { Context, getUser } from '@/server/context' import { backendLogger as logger } from '@/server/logger' import { Contribution as dbContribution } from '@entity/Contribution' import { Arg, Args, Authorized, Ctx, Mutation, Query, Resolver } from 'type-graphql' -import { IsNull } from '@dbTools/typeorm' +import { FindOperator, IsNull } from '@dbTools/typeorm' import ContributionArgs from '@arg/ContributionArgs' import Paginated from '@arg/Paginated' import { Order } from '@enum/Order' @@ -48,14 +48,11 @@ export class ContributionResolver { @Ctx() context: Context, ): Promise { const user = getUser(context) - const where = filterConfirmed - ? { - userId: user.id, - confirmedBy: IsNull(), - } - : { - userId: user.id, - } + const where: { + userId: number + confirmedBy?: FindOperator | null + } = { userId: user.id } + if (filterConfirmed) where.confirmedBy = IsNull() const contributions = await dbContribution.find({ where, order: { From 70db65044cfd5bf3bb42cce63968257616f1f1ed Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 14:09:40 +0200 Subject: [PATCH 13/16] Fix linting. --- backend/src/graphql/resolver/ContributionResolver.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 3e13c404c..41f6c9cd4 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -50,6 +50,7 @@ export class ContributionResolver { const user = getUser(context) const where: { userId: number + // eslint-disable-next-line @typescript-eslint/no-explicit-any confirmedBy?: FindOperator | null } = { userId: user.id } if (filterConfirmed) where.confirmedBy = IsNull() From 339b32a02f76d41eb10d49934c16d7c8cb31a94f Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 11 Jul 2022 17:16:31 +0200 Subject: [PATCH 14/16] Change FindOperator to --- backend/src/graphql/resolver/ContributionResolver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 41f6c9cd4..4424b40d0 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -50,8 +50,7 @@ export class ContributionResolver { const user = getUser(context) const where: { userId: number - // eslint-disable-next-line @typescript-eslint/no-explicit-any - confirmedBy?: FindOperator | null + confirmedBy?: FindOperator | null } = { userId: user.id } if (filterConfirmed) where.confirmedBy = IsNull() const contributions = await dbContribution.find({ From b6f1b0730a51dcfc6c8a97a84b021cadd0644bbf Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Jul 2022 08:44:36 +0200 Subject: [PATCH 15/16] Change the orders and structure from the tests for listContributions. --- .../resolver/ContributionResolver.test.ts | 75 +++++++++---------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 1e3034b59..b3d6aeb3c 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -150,6 +150,10 @@ describe('ContributionResolver', () => { describe('authenticated', () => { beforeAll(async () => { await userFactory(testEnv, bibiBloxberg) + await userFactory(testEnv, peterLustig) + const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + await creationFactory(testEnv, bibisCreation!) await query({ query: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, @@ -163,46 +167,9 @@ describe('ContributionResolver', () => { }, }) }) - - it('returns only unconfirmed creations', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: true, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listContributions: expect.arrayContaining([ - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test env contribution', - amount: '100', - }), - ]), - }, - }), - ) - }) - - describe('Adding confirmed creations', () => { - beforeAll(async () => { - await userFactory(testEnv, peterLustig) - const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await creationFactory(testEnv, bibisCreation!) - await query({ - query: login, - variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, - }) - }) - - it('filter confirmed is false', async () => { + + describe('filter confirmed is false', () => { + it('returns creations', async () => { await expect( query({ query: listContributions, @@ -233,6 +200,34 @@ describe('ContributionResolver', () => { ) }) }) + + describe('filter confirmed is true', () => { + it('returns only unconfirmed creations', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: true, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + listContributions: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test env contribution', + amount: '100', + }), + ]), + }, + }), + ) + }) + }) }) }) }) From 0e13c7c2e12a66e6cbd41c1e6a167e6f5d32046c Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 12 Jul 2022 08:47:15 +0200 Subject: [PATCH 16/16] Remove spaces. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b3d6aeb3c..9b0f6a3bc 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -167,7 +167,7 @@ describe('ContributionResolver', () => { }, }) }) - + describe('filter confirmed is false', () => { it('returns creations', async () => { await expect(