From 9312662e14033d6f4df5cd19d400e00ec5b3756b Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Thu, 14 Apr 2022 21:03:22 +0200 Subject: [PATCH] fix: update edit mutation in viewer.apiKeys --- apps/web/server/routers/viewer/apiKeys.tsx | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/web/server/routers/viewer/apiKeys.tsx b/apps/web/server/routers/viewer/apiKeys.tsx index 6959980153..0b95986ff6 100644 --- a/apps/web/server/routers/viewer/apiKeys.tsx +++ b/apps/web/server/routers/viewer/apiKeys.tsx @@ -49,22 +49,31 @@ export const apiKeysRouter = createProtectedRouter() }), async resolve({ ctx, input }) { const { id, ...data } = input; - const apiKey = await ctx.prisma.apiKey.findFirst({ + const { + apiKeys: [updatedApiKey], + } = await ctx.prisma.user.update({ where: { - userId: ctx.user.id, - id, + id: ctx.user.id, + }, + data: { + apiKeys: { + update: { + where: { + id, + }, + data, + }, + }, + }, + select: { + apiKeys: { + where: { + id, + }, + }, }, }); - if (!apiKey) { - // user does not own this apiKey - return null; - } - return await ctx.prisma.apiKey.update({ - where: { - id, - }, - data, - }); + return updatedApiKey; }, }) .mutation("delete", {