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) } }