From 3cfa29b5b5f45155d44b8a6d64eb3c822635b325 Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Tue, 6 Jun 2023 02:20:45 -0500 Subject: [PATCH] add basic resource editing on backend --- src/pages/resources/[id]/edit.tsx | 1 - src/server/api/routers/auditoryResources.ts | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pages/resources/[id]/edit.tsx b/src/pages/resources/[id]/edit.tsx index d1d09e7..2be936b 100644 --- a/src/pages/resources/[id]/edit.tsx +++ b/src/pages/resources/[id]/edit.tsx @@ -59,7 +59,6 @@ const EditResourcePage = ( }); const onSubmit: SubmitHandler = (data) => { - console.log("mutating"); mutate(data); }; diff --git a/src/server/api/routers/auditoryResources.ts b/src/server/api/routers/auditoryResources.ts index 293bd76..fa6c614 100644 --- a/src/server/api/routers/auditoryResources.ts +++ b/src/server/api/routers/auditoryResources.ts @@ -60,14 +60,17 @@ export const auditoryResourceRouter = createTRPCRouter({ .optional(), }) ) - .mutation(({ input, ctx }) => { - console.log(input); - // return await ctx.prisma.auditoryResource.update({ - // where: { - // id: input.id, - // }, - // data: { ...input }, - // }); + .mutation(async ({ input, ctx }) => { + return await ctx.prisma.auditoryResource.update({ + where: { + id: input.id, + }, + data: Object.fromEntries( + Object.entries(input).filter(([key, _value]) => { + return key !== "id"; + }) + ), + }); }), search: publicProcedure