From 66a5175dc1abff1477bedc3fd655ecd0ff44faa1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Feb 2023 21:28:58 +0100 Subject: [PATCH 01/17] combine logic for both listTransactionLinks and listTransactionLinksAdmin --- backend/src/graphql/model/TransactionLink.ts | 4 +- .../resolver/TransactionLinkResolver.test.ts | 20 ++-- .../resolver/TransactionLinkResolver.ts | 108 +++++++++--------- backend/src/seeds/graphql/queries.ts | 4 +- frontend/src/graphql/queries.js | 18 +-- 5 files changed, 78 insertions(+), 76 deletions(-) diff --git a/backend/src/graphql/model/TransactionLink.ts b/backend/src/graphql/model/TransactionLink.ts index 18a601948..416527ec9 100644 --- a/backend/src/graphql/model/TransactionLink.ts +++ b/backend/src/graphql/model/TransactionLink.ts @@ -61,8 +61,8 @@ export class TransactionLink { @ObjectType() export class TransactionLinkResult { @Field(() => Int) - linkCount: number + count: number @Field(() => [TransactionLink]) - linkList: TransactionLink[] + links: TransactionLink[] } diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index 09f2f9a02..03f412a43 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -611,8 +611,8 @@ describe('TransactionLinkResolver', () => { expect.objectContaining({ data: { listTransactionLinksAdmin: { - linkCount: 6, - linkList: expect.not.arrayContaining([ + count: 6, + links: expect.not.arrayContaining([ expect.objectContaining({ memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(', createdAt: expect.any(String), @@ -647,8 +647,8 @@ describe('TransactionLinkResolver', () => { expect.objectContaining({ data: { listTransactionLinksAdmin: { - linkCount: 6, - linkList: expect.not.arrayContaining([ + count: 6, + links: expect.not.arrayContaining([ expect.objectContaining({ memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(', createdAt: expect.any(String), @@ -681,8 +681,8 @@ describe('TransactionLinkResolver', () => { expect.objectContaining({ data: { listTransactionLinksAdmin: { - linkCount: 7, - linkList: expect.arrayContaining([ + count: 7, + links: expect.arrayContaining([ expect.not.objectContaining({ memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(', createdAt: expect.any(String), @@ -715,8 +715,8 @@ describe('TransactionLinkResolver', () => { expect.objectContaining({ data: { listTransactionLinksAdmin: { - linkCount: 7, - linkList: expect.arrayContaining([ + count: 7, + links: expect.arrayContaining([ expect.objectContaining({ memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(', createdAt: expect.any(String), @@ -752,8 +752,8 @@ describe('TransactionLinkResolver', () => { expect.objectContaining({ data: { listTransactionLinksAdmin: { - linkCount: 6, - linkList: expect.arrayContaining([ + count: 6, + links: expect.arrayContaining([ expect.not.objectContaining({ memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(', createdAt: expect.any(String), diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 4647dde60..945ef766c 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -35,6 +35,7 @@ import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK' import LogError from '@/server/LogError' import { getLastTransaction } from './util/getLastTransaction' +import { filter } from 'lodash' // TODO: do not export, test it inside the resolver export const transactionLinkCode = (date: Date): string => { @@ -141,30 +142,6 @@ export class TransactionLinkResolver { } } - @Authorized([RIGHTS.LIST_TRANSACTION_LINKS]) - @Query(() => [TransactionLink]) - async listTransactionLinks( - @Args() - { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, - @Ctx() context: Context, - ): Promise { - const user = getUser(context) - // const now = new Date() - const transactionLinks = await DbTransactionLink.find({ - where: { - userId: user.id, - redeemedBy: null, - // validUntil: MoreThan(now), - }, - order: { - createdAt: order, - }, - skip: (currentPage - 1) * pageSize, - take: pageSize, - }) - return transactionLinks.map((tl) => new TransactionLink(tl, new User(user))) - } - @Authorized([RIGHTS.REDEEM_TRANSACTION_LINK]) @Mutation(() => Boolean) async redeemTransactionLink( @@ -338,43 +315,66 @@ export class TransactionLinkResolver { } } + @Authorized([RIGHTS.LIST_TRANSACTION_LINKS]) + @Query(() => [TransactionLink]) + async listTransactionLinks( + @Args() + paginated: Paginated, + @Ctx() context: Context, + ): Promise { + const user = getUser(context) + return transactionLinkList( + paginated, + { + withDeleted: false, + withExpired: true, + withRedeemed: false, + }, + user.id, + ) + } + @Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN]) @Query(() => TransactionLinkResult) async listTransactionLinksAdmin( @Args() - { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, + paginated: Paginated, @Arg('filters', () => TransactionLinkFilters, { nullable: true }) - filters: TransactionLinkFilters, + filters: TransactionLinkFilters | null, @Arg('userId', () => Int) userId: number, ): Promise { - const user = await DbUser.findOneOrFail({ id: userId }) - const where: { - userId: number - redeemedBy?: number | null - validUntil?: FindOperator | null - } = { - userId, - redeemedBy: null, - validUntil: MoreThan(new Date()), - } - if (filters) { - if (filters.withRedeemed) delete where.redeemedBy - if (filters.withExpired) delete where.validUntil - } - const [transactionLinks, count] = await DbTransactionLink.findAndCount({ - where, - withDeleted: filters ? filters.withDeleted : false, - order: { - createdAt: order, - }, - skip: (currentPage - 1) * pageSize, - take: pageSize, - }) - - return { - linkCount: count, - linkList: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))), - } + return transactionLinkList(paginated, filters, userId) + } +} + +const transactionLinkList = async ( + { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, + filters: TransactionLinkFilters | null, + userId: number, +): Promise => { + const user = await DbUser.findOneOrFail({ id: userId }) + const { withDeleted, withExpired, withRedeemed } = filters || { + withDeleted: false, + withExpired: false, + withRedeemed: false, + } + const [transactionLinks, count] = await DbTransactionLink.findAndCount({ + where: { + userId, + ...(!withRedeemed && { redeemedBy: null }), + ...(!withExpired && { validUntil: MoreThan(new Date()) }), + }, + withDeleted, + order: { + createdAt: order, + }, + skip: (currentPage - 1) * pageSize, + take: pageSize, + }) + + return { + count, + links: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))), } } diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 385a69479..2c4473ab5 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -224,8 +224,8 @@ export const listTransactionLinksAdmin = gql` currentPage: $currentPage pageSize: $pageSize ) { - linkCount - linkList { + count + links { id amount holdAvailableAmount diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index e199a3730..6e8d420b8 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -126,14 +126,16 @@ export const queryTransactionLink = gql` export const listTransactionLinks = gql` query($currentPage: Int = 1, $pageSize: Int = 5) { listTransactionLinks(currentPage: $currentPage, pageSize: $pageSize) { - id - amount - holdAvailableAmount - memo - link - createdAt - validUntil - redeemedAt + links { + id + amount + holdAvailableAmount + memo + link + createdAt + validUntil + redeemedAt + } } } ` From 5bba531769b7da7006f8f5b73a99e474f1f7a7ed Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Feb 2023 21:29:14 +0100 Subject: [PATCH 02/17] missing graphql changes --- admin/src/components/TransactionLinkList.spec.js | 4 ++-- admin/src/components/TransactionLinkList.vue | 4 ++-- admin/src/graphql/listTransactionLinksAdmin.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/admin/src/components/TransactionLinkList.spec.js b/admin/src/components/TransactionLinkList.spec.js index 094e515b2..09a7872ca 100644 --- a/admin/src/components/TransactionLinkList.spec.js +++ b/admin/src/components/TransactionLinkList.spec.js @@ -9,8 +9,8 @@ const apolloQueryMock = jest.fn() apolloQueryMock.mockResolvedValue({ data: { listTransactionLinksAdmin: { - linkCount: 8, - linkList: [ + count: 8, + links: [ { amount: '19.99', code: '62ef8236ace7217fbd066c5a', diff --git a/admin/src/components/TransactionLinkList.vue b/admin/src/components/TransactionLinkList.vue index 564865440..eb58903c6 100644 --- a/admin/src/components/TransactionLinkList.vue +++ b/admin/src/components/TransactionLinkList.vue @@ -42,8 +42,8 @@ export default { }, }) .then((result) => { - this.rows = result.data.listTransactionLinksAdmin.linkCount - this.items = result.data.listTransactionLinksAdmin.linkList + this.rows = result.data.listTransactionLinksAdmin.count + this.items = result.data.listTransactionLinksAdmin.links }) .catch((error) => { this.toastError(error.message) diff --git a/admin/src/graphql/listTransactionLinksAdmin.js b/admin/src/graphql/listTransactionLinksAdmin.js index 2e4171f02..c069bafd9 100644 --- a/admin/src/graphql/listTransactionLinksAdmin.js +++ b/admin/src/graphql/listTransactionLinksAdmin.js @@ -8,8 +8,8 @@ export const listTransactionLinksAdmin = gql` userId: $userId filters: { withRedeemed: true, withExpired: true, withDeleted: true } ) { - linkCount - linkList { + count + links { id amount holdAvailableAmount From ae940b509abee4b7d302261bfdbf8b40d69705bf Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 14 Feb 2023 21:33:24 +0100 Subject: [PATCH 03/17] removed unused imports --- backend/src/graphql/resolver/TransactionLinkResolver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 945ef766c..fb028ca2a 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -1,7 +1,7 @@ import { randomBytes } from 'crypto' import Decimal from 'decimal.js-light' -import { getConnection, MoreThan, FindOperator } from '@dbTools/typeorm' +import { getConnection, MoreThan } from '@dbTools/typeorm' import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' import { User as DbUser } from '@entity/User' @@ -35,7 +35,6 @@ import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK' import LogError from '@/server/LogError' import { getLastTransaction } from './util/getLastTransaction' -import { filter } from 'lodash' // TODO: do not export, test it inside the resolver export const transactionLinkCode = (date: Date): string => { From 12c128e0729b9782854ed269e26f1b4d87c88248 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:03:38 +0100 Subject: [PATCH 04/17] do not requqery the user --- .../src/graphql/resolver/TransactionLinkResolver.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 4bc6721bf..174134aa6 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -333,7 +333,7 @@ export class TransactionLinkResolver { withExpired: true, withRedeemed: false, }, - user.id, + user, ) } @@ -347,16 +347,15 @@ export class TransactionLinkResolver { @Arg('userId', () => Int) userId: number, ): Promise { - return transactionLinkList(paginated, filters, userId) + return transactionLinkList(paginated, filters, await DbUser.findOneOrFail({ id: userId })) } } const transactionLinkList = async ( { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, filters: TransactionLinkFilters | null, - userId: number, + user: DbUser, ): Promise => { - const user = await DbUser.findOneOrFail({ id: userId }) const { withDeleted, withExpired, withRedeemed } = filters || { withDeleted: false, withExpired: false, @@ -364,7 +363,7 @@ const transactionLinkList = async ( } const [transactionLinks, count] = await DbTransactionLink.findAndCount({ where: { - userId, + user: user.id, ...(!withRedeemed && { redeemedBy: null }), ...(!withExpired && { validUntil: MoreThan(new Date()) }), }, @@ -378,6 +377,6 @@ const transactionLinkList = async ( return { count, - links: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))), + links: transactionLinks.map((tl) => new TransactionLink(tl, user)), } } From d21996a045853deea3e29b5ba48a7c67bc1ddf6f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:10:31 +0100 Subject: [PATCH 05/17] externalize transactionLinkList function into utils folder --- .../resolver/TransactionLinkResolver.ts | 34 +---------------- .../resolver/util/transactionLinkList.ts | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 backend/src/graphql/resolver/util/transactionLinkList.ts diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 174134aa6..e0c12d7a7 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -1,7 +1,7 @@ import { randomBytes } from 'crypto' import Decimal from 'decimal.js-light' -import { getConnection, MoreThan } from '@dbTools/typeorm' +import { getConnection } from '@dbTools/typeorm' import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' import { User as DbUser } from '@entity/User' @@ -13,7 +13,6 @@ import { User } from '@model/User' import { ContributionLink } from '@model/ContributionLink' import { Decay } from '@model/Decay' import { TransactionLink, TransactionLinkResult } from '@model/TransactionLink' -import { Order } from '@enum/Order' import { ContributionType } from '@enum/ContributionType' import { ContributionStatus } from '@enum/ContributionStatus' import { TransactionTypeId } from '@enum/TransactionTypeId' @@ -35,6 +34,7 @@ import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK' import LogError from '@/server/LogError' import { getLastTransaction } from './util/getLastTransaction' +import transactionLinkList from './util/transactionLinkList' // TODO: do not export, test it inside the resolver export const transactionLinkCode = (date: Date): string => { @@ -350,33 +350,3 @@ export class TransactionLinkResolver { return transactionLinkList(paginated, filters, await DbUser.findOneOrFail({ id: userId })) } } - -const transactionLinkList = async ( - { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, - filters: TransactionLinkFilters | null, - user: DbUser, -): Promise => { - const { withDeleted, withExpired, withRedeemed } = filters || { - withDeleted: false, - withExpired: false, - withRedeemed: false, - } - const [transactionLinks, count] = await DbTransactionLink.findAndCount({ - where: { - user: user.id, - ...(!withRedeemed && { redeemedBy: null }), - ...(!withExpired && { validUntil: MoreThan(new Date()) }), - }, - withDeleted, - order: { - createdAt: order, - }, - skip: (currentPage - 1) * pageSize, - take: pageSize, - }) - - return { - count, - links: transactionLinks.map((tl) => new TransactionLink(tl, user)), - } -} diff --git a/backend/src/graphql/resolver/util/transactionLinkList.ts b/backend/src/graphql/resolver/util/transactionLinkList.ts new file mode 100644 index 000000000..48a91920d --- /dev/null +++ b/backend/src/graphql/resolver/util/transactionLinkList.ts @@ -0,0 +1,37 @@ +import { MoreThan } from '@dbTools/typeorm' +import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' +import { User as DbUser } from '@entity/User' +import { Order } from '@enum/Order' +import Paginated from '@arg/Paginated' +import TransactionLinkFilters from '@arg/TransactionLinkFilters' +import { TransactionLink, TransactionLinkResult } from '@model/TransactionLink' + +export default async function transactionLinkList( + { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, + filters: TransactionLinkFilters | null, + user: DbUser, +): Promise { + const { withDeleted, withExpired, withRedeemed } = filters || { + withDeleted: false, + withExpired: false, + withRedeemed: false, + } + const [transactionLinks, count] = await DbTransactionLink.findAndCount({ + where: { + user: user.id, + ...(!withRedeemed && { redeemedBy: null }), + ...(!withExpired && { validUntil: MoreThan(new Date()) }), + }, + withDeleted, + order: { + createdAt: order, + }, + skip: (currentPage - 1) * pageSize, + take: pageSize, + }) + + return { + count, + links: transactionLinks.map((tl) => new TransactionLink(tl, user)), + } +} From b8870682265d9758013a3beb1716a261360d8fd9 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:12:11 +0100 Subject: [PATCH 06/17] remove user constant, not required --- backend/src/graphql/resolver/TransactionLinkResolver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index e0c12d7a7..186a9bf1d 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -325,7 +325,6 @@ export class TransactionLinkResolver { paginated: Paginated, @Ctx() context: Context, ): Promise { - const user = getUser(context) return transactionLinkList( paginated, { @@ -333,7 +332,7 @@ export class TransactionLinkResolver { withExpired: true, withRedeemed: false, }, - user, + getUser(context), ) } From 16c3ba399e8881f01715ecf0f9dd0f14d1d39df3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:21:37 +0100 Subject: [PATCH 07/17] some misssing changes --- backend/src/graphql/resolver/util/transactionLinkList.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/util/transactionLinkList.ts b/backend/src/graphql/resolver/util/transactionLinkList.ts index 48a91920d..2d151b94a 100644 --- a/backend/src/graphql/resolver/util/transactionLinkList.ts +++ b/backend/src/graphql/resolver/util/transactionLinkList.ts @@ -5,6 +5,7 @@ import { Order } from '@enum/Order' import Paginated from '@arg/Paginated' import TransactionLinkFilters from '@arg/TransactionLinkFilters' import { TransactionLink, TransactionLinkResult } from '@model/TransactionLink' +import { User } from '@/graphql/model/User' export default async function transactionLinkList( { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, @@ -18,7 +19,7 @@ export default async function transactionLinkList( } const [transactionLinks, count] = await DbTransactionLink.findAndCount({ where: { - user: user.id, + userId: user.id, ...(!withRedeemed && { redeemedBy: null }), ...(!withExpired && { validUntil: MoreThan(new Date()) }), }, @@ -32,6 +33,6 @@ export default async function transactionLinkList( return { count, - links: transactionLinks.map((tl) => new TransactionLink(tl, user)), + links: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))), } } From c01a94aa248f7660c3d25eb4e9a2dbf3b41db6f8 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:25:09 +0100 Subject: [PATCH 08/17] potential frontend fix --- .../src/components/Transactions/TransactionLinkSummary.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Transactions/TransactionLinkSummary.vue b/frontend/src/components/Transactions/TransactionLinkSummary.vue index b54c0e687..f90d6da85 100644 --- a/frontend/src/components/Transactions/TransactionLinkSummary.vue +++ b/frontend/src/components/Transactions/TransactionLinkSummary.vue @@ -90,7 +90,10 @@ export default { fetchPolicy: 'network-only', }) .then((result) => { - this.transactionLinks = [...this.transactionLinks, ...result.data.listTransactionLinks] + this.transactionLinks.links = [ + ...this.transactionLinks, + ...result.data.listTransactionLinks.links, + ] this.$emit('update-transactions') this.pending = false }) From cb058adde64df26b94aaece5a872f7e7db30a22c Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:29:09 +0100 Subject: [PATCH 09/17] fix tests --- .../TransactionLinkSummary.spec.js | 184 +++++++++--------- 1 file changed, 94 insertions(+), 90 deletions(-) diff --git a/frontend/src/components/Transactions/TransactionLinkSummary.spec.js b/frontend/src/components/Transactions/TransactionLinkSummary.spec.js index d0086ceab..46041f87f 100644 --- a/frontend/src/components/Transactions/TransactionLinkSummary.spec.js +++ b/frontend/src/components/Transactions/TransactionLinkSummary.spec.js @@ -47,51 +47,53 @@ describe('TransactionLinkSummary', () => { beforeEach(() => { apolloQueryMock.mockResolvedValue({ data: { - listTransactionLinks: [ - { - amount: '75', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 86, - memo: - 'Hokuspokus Haselnuss, Vogelbein und Fliegenfuß, damit der Trick gelingen muss!', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - { - amount: '85', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 107, - memo: 'Mäusespeck und Katzenbuckel, Tricks und Tracks und Zauberkugel!', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - { - amount: '95', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 92, - memo: - 'Abrakadabra 1,2,3, die Sonne kommt herbei. Schweinepups und Spuckebrei, der Regen ist vorbei.', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - { - amount: '150', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 16, - memo: - 'Abrakadabra 1,2,3 was verschwunden ist komme herbei.Wieseldreck und Schweinemist, zaubern das ist keine List.', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - ], + listTransactionLinks: { + links: [ + { + amount: '75', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 86, + memo: + 'Hokuspokus Haselnuss, Vogelbein und Fliegenfuß, damit der Trick gelingen muss!', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + { + amount: '85', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 107, + memo: 'Mäusespeck und Katzenbuckel, Tricks und Tracks und Zauberkugel!', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + { + amount: '95', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 92, + memo: + 'Abrakadabra 1,2,3, die Sonne kommt herbei. Schweinepups und Spuckebrei, der Regen ist vorbei.', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + { + amount: '150', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 16, + memo: + 'Abrakadabra 1,2,3 was verschwunden ist komme herbei.Wieseldreck und Schweinemist, zaubern das ist keine List.', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + ], + }, }, }) @@ -166,51 +168,53 @@ describe('TransactionLinkSummary', () => { jest.clearAllMocks() apolloQueryMock.mockResolvedValue({ data: { - listTransactionLinks: [ - { - amount: '76', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 87, - memo: - 'Hat jemand die Nummer von der Hexe aus Schneewittchen? Ich bräuchte mal ein paar Äpfel.', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - { - amount: '86', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 108, - memo: - 'Die Windfahn´ krächzt am Dach, Der Uhu im Geklüfte; Was wispert wie ein Ach Verhallend in die Lüfte?', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - { - amount: '96', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 93, - memo: - 'Verschlafen kräht der Hahn, Ein Blitz noch, und ein trüber, Umwölbter Tag bricht an – Walpurgisnacht vorüber!', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - { - amount: '150', - link: 'http://localhost/redeem/ce28664b5308c17f931c0367', - createdAt: '2022-03-16T14:22:40.000Z', - holdAvailableAmount: '5.13109484759482747111', - id: 17, - memo: 'Eene meene Flaschenschrank, fertig ist der Hexentrank!', - redeemedAt: null, - validUntil: '2022-03-30T14:22:40.000Z', - }, - ], + listTransactionLinks: { + links: [ + { + amount: '76', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 87, + memo: + 'Hat jemand die Nummer von der Hexe aus Schneewittchen? Ich bräuchte mal ein paar Äpfel.', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + { + amount: '86', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 108, + memo: + 'Die Windfahn´ krächzt am Dach, Der Uhu im Geklüfte; Was wispert wie ein Ach Verhallend in die Lüfte?', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + { + amount: '96', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 93, + memo: + 'Verschlafen kräht der Hahn, Ein Blitz noch, und ein trüber, Umwölbter Tag bricht an – Walpurgisnacht vorüber!', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + { + amount: '150', + link: 'http://localhost/redeem/ce28664b5308c17f931c0367', + createdAt: '2022-03-16T14:22:40.000Z', + holdAvailableAmount: '5.13109484759482747111', + id: 17, + memo: 'Eene meene Flaschenschrank, fertig ist der Hexentrank!', + redeemedAt: null, + validUntil: '2022-03-30T14:22:40.000Z', + }, + ], + }, }, }) await wrapper.setData({ From 214970dde186063e48ccae54e0189b8d77e7c37a Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 17 Feb 2023 23:38:06 +0100 Subject: [PATCH 10/17] typo --- frontend/src/components/Transactions/TransactionLinkSummary.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Transactions/TransactionLinkSummary.vue b/frontend/src/components/Transactions/TransactionLinkSummary.vue index f90d6da85..c3a62357b 100644 --- a/frontend/src/components/Transactions/TransactionLinkSummary.vue +++ b/frontend/src/components/Transactions/TransactionLinkSummary.vue @@ -90,7 +90,7 @@ export default { fetchPolicy: 'network-only', }) .then((result) => { - this.transactionLinks.links = [ + this.transactionLinks = [ ...this.transactionLinks, ...result.data.listTransactionLinks.links, ] From 75d23c5dafea30967d0a5bbf498c014beab86ee3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 23 Feb 2023 21:36:59 +0100 Subject: [PATCH 11/17] corrected return type of listTransactionLinks --- backend/src/graphql/resolver/TransactionLinkResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 186a9bf1d..2c8450bd6 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -319,7 +319,7 @@ export class TransactionLinkResolver { } @Authorized([RIGHTS.LIST_TRANSACTION_LINKS]) - @Query(() => [TransactionLink]) + @Query(() => TransactionLinkResult) async listTransactionLinks( @Args() paginated: Paginated, From 93735ad3f7d1ee24f9219a94fe4268917239ba41 Mon Sep 17 00:00:00 2001 From: mahula Date: Fri, 24 Feb 2023 17:57:00 +0100 Subject: [PATCH 12/17] rename dht node workflow jobs for github settings --- .github/workflows/test_dht-node.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_dht-node.yml b/.github/workflows/test_dht-node.yml index 5b3a65a70..f0dc3848e 100644 --- a/.github/workflows/test_dht-node.yml +++ b/.github/workflows/test_dht-node.yml @@ -1,4 +1,4 @@ -name: gradido test_dht-node CI +name: Gradido DHT Node Test CI on: push @@ -7,7 +7,7 @@ jobs: # JOB: DOCKER BUILD TEST ##################################################### ############################################################################## build: - name: Docker Build Test + name: Docker Build Test - DHT Node runs-on: ubuntu-latest steps: - name: Checkout code @@ -28,7 +28,7 @@ jobs: # JOB: LINT ################################################################## ############################################################################## lint: - name: Lint + name: Lint - DHT Node runs-on: ubuntu-latest needs: [build] steps: @@ -50,7 +50,7 @@ jobs: # JOB: UNIT TEST ############################################################# ############################################################################## unit_test: - name: Unit tests + name: Unit Tests - DHT Node runs-on: ubuntu-latest needs: [build] steps: From 1f16ae89caa9cd38851f05af8b927884acb51516 Mon Sep 17 00:00:00 2001 From: mahula Date: Fri, 24 Feb 2023 21:34:51 +0100 Subject: [PATCH 13/17] rename federation workflow jobs for github settings --- .github/workflows/test_federation.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_federation.yml b/.github/workflows/test_federation.yml index 2da78758e..650fc7347 100644 --- a/.github/workflows/test_federation.yml +++ b/.github/workflows/test_federation.yml @@ -1,4 +1,4 @@ -name: gradido test_federation CI +name: Gradido Federation Test CI on: push @@ -7,7 +7,7 @@ jobs: # JOB: DOCKER BUILD TEST ##################################################### ############################################################################## build: - name: Docker Build Test + name: Docker Build Test - Federation runs-on: ubuntu-latest steps: - name: Checkout code @@ -28,7 +28,7 @@ jobs: # JOB: LINT ################################################################## ############################################################################## lint: - name: Lint + name: Lint - Federation runs-on: ubuntu-latest needs: [build] steps: @@ -50,7 +50,7 @@ jobs: # JOB: UNIT TEST ############################################################# ############################################################################## unit_test: - name: Unit tests + name: Unit Tests - Federation runs-on: ubuntu-latest needs: [build] steps: From eb53e5ff166202b38b5f78a795a579e2416404ab Mon Sep 17 00:00:00 2001 From: mahula Date: Fri, 24 Feb 2023 22:40:07 +0100 Subject: [PATCH 14/17] rename report names in federation and dht workflow --- .github/workflows/test_dht-node.yml | 2 +- .github/workflows/test_federation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dht-node.yml b/.github/workflows/test_dht-node.yml index f0dc3848e..4ac475351 100644 --- a/.github/workflows/test_dht-node.yml +++ b/.github/workflows/test_dht-node.yml @@ -90,7 +90,7 @@ jobs: - name: Coverage check uses: webcraftmedia/coverage-check-action@master with: - report_name: Coverage dht-node + report_name: Coverage DHT Node type: lcov #result_path: ./dht-node/coverage/lcov.info result_path: ./coverage/lcov.info diff --git a/.github/workflows/test_federation.yml b/.github/workflows/test_federation.yml index 650fc7347..ab943eedd 100644 --- a/.github/workflows/test_federation.yml +++ b/.github/workflows/test_federation.yml @@ -90,7 +90,7 @@ jobs: - name: Coverage check uses: webcraftmedia/coverage-check-action@master with: - report_name: Coverage federation + report_name: Coverage Federation type: lcov #result_path: ./federation/coverage/lcov.info result_path: ./coverage/lcov.info From 5f8702c3c4c7010bc3d94ab7642b219cd9d2743c Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 27 Feb 2023 15:44:14 +0100 Subject: [PATCH 15/17] catch error for not existing users and test this --- .../resolver/TransactionLinkResolver.test.ts | 20 +++++++++++++++++++ .../resolver/TransactionLinkResolver.ts | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index 2bbca26d3..60b4551be 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -600,6 +600,26 @@ describe('TransactionLinkResolver', () => { resetToken() }) + describe('', () => { + it('throws error when user does not exists', async () => { + jest.clearAllMocks() + await expect( + mutate({ + mutation: listTransactionLinksAdmin, + variables: { + userId: -1, + }, + }), + ).resolves.toMatchObject({ + errors: [new GraphQLError('Could not find requested User')], + }) + }) + + it('logs the error thrown', () => { + expect(logger.error).toBeCalledWith('Could not find requested User', -1) + }) + }) + describe('without any filters', () => { it('finds 6 open transaction links and no deleted or redeemed', async () => { await expect( diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 2c8450bd6..ab5b52bad 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -346,6 +346,10 @@ export class TransactionLinkResolver { @Arg('userId', () => Int) userId: number, ): Promise { - return transactionLinkList(paginated, filters, await DbUser.findOneOrFail({ id: userId })) + const user = await DbUser.findOne({ id: userId }) + if (!user) { + throw new LogError('Could not find requested User', userId) + } + return transactionLinkList(paginated, filters, user) } } From 1055396d20d9bb1530e948fa1822287b959f7a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 28 Feb 2023 14:37:41 +0100 Subject: [PATCH 16/17] Change menu and tab titles in email to the new design --- backend/src/locales/de.json | 6 +++--- backend/src/locales/en.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/locales/de.json b/backend/src/locales/de.json index 530e8db10..4dc90def2 100644 --- a/backend/src/locales/de.json +++ b/backend/src/locales/de.json @@ -17,7 +17,7 @@ "addedContributionMessage": { "commonGoodContributionMessage": "du hast zu deinem Gemeinwohl-Beitrag „{contributionMemo}“ eine Nachricht von {senderFirstName} {senderLastName} erhalten.", "subject": "Gradido: Nachricht zu deinem Gemeinwohl-Beitrag", - "toSeeAndAnswerMessage": "Um die Nachricht zu sehen und darauf zu antworten, gehe in deinem Gradido-Konto ins Menü „Gemeinschaft“ auf den Tab „Meine Beiträge zum Gemeinwohl“!" + "toSeeAndAnswerMessage": "Um die Nachricht zu sehen und darauf zu antworten, gehe in deinem Gradido-Konto ins Menü „Schöpfen“ auf den Tab „Meine Beiträge“!" }, "contributionConfirmed": { "commonGoodContributionConfirmed": "dein Gemeinwohl-Beitrag „{contributionMemo}“ wurde soeben von {senderFirstName} {senderLastName} bestätigt und in deinem Gradido-Konto gutgeschrieben.", @@ -26,12 +26,12 @@ "contributionDeleted": { "commonGoodContributionDeleted": "dein Gemeinwohl-Beitrag „{contributionMemo}“ wurde von {senderFirstName} {senderLastName} gelöscht.", "subject": "Gradido: Dein Gemeinwohl-Beitrag wurde gelöscht", - "toSeeContributionsAndMessages": "Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü „Gemeinschaft“ auf den Tab „Meine Beiträge zum Gemeinwohl“!" + "toSeeContributionsAndMessages": "Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü „Schöpfen“ auf den Tab „Meine Beiträge“!" }, "contributionDenied": { "commonGoodContributionDenied": "dein Gemeinwohl-Beitrag „{contributionMemo}“ wurde von {senderFirstName} {senderLastName} abgelehnt.", "subject": "Gradido: Dein Gemeinwohl-Beitrag wurde abgelehnt", - "toSeeContributionsAndMessages": "Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü „Gemeinschaft“ auf den Tab „Meine Beiträge zum Gemeinwohl“!" + "toSeeContributionsAndMessages": "Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü „Schöpfen“ auf den Tab „Meine Beiträge“!" }, "general": { "amountGDD": "Betrag: {amountGDD} GDD", diff --git a/backend/src/locales/en.json b/backend/src/locales/en.json index 269c38629..74c5739bc 100644 --- a/backend/src/locales/en.json +++ b/backend/src/locales/en.json @@ -17,7 +17,7 @@ "addedContributionMessage": { "commonGoodContributionMessage": "you have received a message from {senderFirstName} {senderLastName} regarding your common good contribution “{contributionMemo}”.", "subject": "Gradido: Message about your common good contribution", - "toSeeAndAnswerMessage": "To view and reply to the message, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!" + "toSeeAndAnswerMessage": "To view and reply to the message, go to the “Creation” menu in your Gradido account and click on the “My contributions” tab!" }, "contributionConfirmed": { "commonGoodContributionConfirmed": "Your public good contribution “{contributionMemo}” has just been confirmed by {senderFirstName} {senderLastName} and credited to your Gradido account.", @@ -26,12 +26,12 @@ "contributionDeleted": { "commonGoodContributionDeleted": "Your public good contribution “{contributionMemo}” was deleted by {senderFirstName} {senderLastName}.", "subject": "Gradido: Your common good contribution was deleted", - "toSeeContributionsAndMessages": "To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!" + "toSeeContributionsAndMessages": "To see your common good contributions and related messages, go to the “Creation” menu in your Gradido account and click on the “My contributions” tab!" }, "contributionDenied": { "commonGoodContributionDenied": "Your public good contribution “{contributionMemo}” was rejected by {senderFirstName} {senderLastName}.", "subject": "Gradido: Your common good contribution was rejected", - "toSeeContributionsAndMessages": "To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!" + "toSeeContributionsAndMessages": "To see your common good contributions and related messages, go to the “Creation” menu in your Gradido account and click on the “My contributions” tab!" }, "general": { "amountGDD": "Amount: {amountGDD} GDD", From a8d382b8d7f608044b2326af3b5b8528288c8dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 28 Feb 2023 14:37:51 +0100 Subject: [PATCH 17/17] Fix tests --- backend/src/emails/sendEmailVariants.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/emails/sendEmailVariants.test.ts b/backend/src/emails/sendEmailVariants.test.ts index 7e499feb9..9f30a8ce1 100644 --- a/backend/src/emails/sendEmailVariants.test.ts +++ b/backend/src/emails/sendEmailVariants.test.ts @@ -106,7 +106,7 @@ describe('sendEmailVariants', () => { 'you have received a message from Bibi Bloxberg regarding your common good contribution “My contribution.”.', ) expect(result.originalMessage.html).toContain( - 'To view and reply to the message, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!', + 'To view and reply to the message, go to the “Creation” menu in your Gradido account and click on the “My contributions” tab!', ) expect(result.originalMessage.html).toContain( `Link to your account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, @@ -424,7 +424,7 @@ describe('sendEmailVariants', () => { 'Your public good contribution “My contribution.” was rejected by Bibi Bloxberg.', ) expect(result.originalMessage.html).toContain( - 'To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!', + 'To see your common good contributions and related messages, go to the “Creation” menu in your Gradido account and click on the “My contributions” tab!', ) expect(result.originalMessage.html).toContain( `Link to your account: ${CONFIG.EMAIL_LINK_OVERVIEW}`, @@ -502,7 +502,7 @@ describe('sendEmailVariants', () => { 'Your public good contribution “My contribution.” was deleted by Bibi Bloxberg.', ) expect(result.originalMessage.html).toContain( - 'To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!', + 'To see your common good contributions and related messages, go to the “Creation” menu in your Gradido account and click on the “My contributions” tab!', ) expect(result.originalMessage.html).toContain( `Link to your account: ${CONFIG.EMAIL_LINK_OVERVIEW}`,