From 2ef07fd37a3daa2bb2910f1cf6762b97e1f53b5b Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Tue, 5 Sep 2023 20:38:05 -0500 Subject: [PATCH] add delete function --- src/pages/resources/[id]/index.tsx | 14 ++++++++++++-- src/server/api/routers/auditoryResources.ts | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pages/resources/[id]/index.tsx b/src/pages/resources/[id]/index.tsx index 9770b1c..d40e43c 100644 --- a/src/pages/resources/[id]/index.tsx +++ b/src/pages/resources/[id]/index.tsx @@ -95,6 +95,15 @@ const ResourceViewPage = () => { } ); + const { mutate: mutateDelete } = api.auditoryResource.delete.useMutation({ + onSuccess: async () => { + await router.push(`/resources`); + }, + onError: (error) => { + console.error(error); + }, + }); + const ConditionalView = (data: AuditoryResource) => { return (
@@ -138,8 +147,9 @@ const ResourceViewPage = () => { label="Delete" symbol={} onConfirm={() => { - // todo - console.log("deleting"); + mutateDelete({ + id, + }); }} />, ]} diff --git a/src/server/api/routers/auditoryResources.ts b/src/server/api/routers/auditoryResources.ts index a88bf5d..9fb4728 100644 --- a/src/server/api/routers/auditoryResources.ts +++ b/src/server/api/routers/auditoryResources.ts @@ -89,6 +89,20 @@ export const auditoryResourceRouter = createTRPCRouter({ }); }), + delete: protectedProcedure + .input( + z.object({ + id: z.string(), + }) + ) + .mutation(async ({ input, ctx }) => { + return await ctx.prisma.auditoryResource.delete({ + where: { + id: input.id, + }, + }); + }), + update: protectedProcedure .input(AuditoryResourceSchema.partial().extend({ id: z.string() })) .mutation(async ({ input, ctx }) => {