From a7ef990d3f499f00be439797cbb8ad43292f08cc Mon Sep 17 00:00:00 2001 From: joshuawenata Date: Sat, 20 May 2023 11:01:59 +0700 Subject: [PATCH 1/2] creating api editMerchantProfile that change email, storeName, phone, and address --- src/server/api/routers/merchant.ts | 28 ++++++++++++++++++++++++++++ src/server/api/routers/user.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/server/api/routers/merchant.ts b/src/server/api/routers/merchant.ts index 2688f0e..55582f8 100644 --- a/src/server/api/routers/merchant.ts +++ b/src/server/api/routers/merchant.ts @@ -40,4 +40,32 @@ export const merchantRouter = createTRPCRouter({ } return merchant; }), + editMerchantProfile: protectedProcedure + .input( + z.object({ + merchantId: z.string(), + }) + ) + .mutation(async ({ input: { merchantId }, ctx }) => { + const merchant = await ctx.prisma.merchant.findUnique({ + where: { + id: merchantId, + }, + }); + const email = merchant?.email; + const storeName = merchant?.name; + const phone = merchant?.phone; + const address = merchant?.address; + await ctx.prisma.merchant.update({ + where: { + id: merchantId, + }, + data: { + email: email, + name: storeName, + phone: phone, + address: address, + }, + }); + }), }); diff --git a/src/server/api/routers/user.ts b/src/server/api/routers/user.ts index f917604..69951f7 100644 --- a/src/server/api/routers/user.ts +++ b/src/server/api/routers/user.ts @@ -42,4 +42,32 @@ export const userRouter = createTRPCRouter({ } return user; }), + editUserProfile: protectedProcedure + .input( + z.object({ + userId: z.string(), + }) + ) + .mutation(async ({ input: { userId }, ctx }) => { + const user = await ctx.prisma.user.findUnique({ + where: { + id: userId, + }, + }); + const email = user?.email; + const name = user?.name; + const phone = user?.phone; + const address = user?.address; + await ctx.prisma.user.update({ + where: { + id: userId, + }, + data: { + email: email, + name: name, + phone: phone, + address: address, + }, + }); + }), }); From 8ac1d47b8f7393bef87e8ad4e35eec8954c2767e Mon Sep 17 00:00:00 2001 From: joshuawenata Date: Sat, 20 May 2023 19:48:11 +0700 Subject: [PATCH 2/2] update api from input --- src/pages/app/history/details/[ticketId].tsx | 2 +- src/server/api/routers/merchant.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/app/history/details/[ticketId].tsx b/src/pages/app/history/details/[ticketId].tsx index b1a8852..f877301 100644 --- a/src/pages/app/history/details/[ticketId].tsx +++ b/src/pages/app/history/details/[ticketId].tsx @@ -11,7 +11,7 @@ const TicketDetailsPage: AuthNextPage = () => { -
+
{ + .mutation(async ({ input: { merchantId, email, storeName, phone, address }, ctx }) => { const merchant = await ctx.prisma.merchant.findUnique({ where: { id: merchantId, }, }); - const email = merchant?.email; - const storeName = merchant?.name; - const phone = merchant?.phone; - const address = merchant?.address; await ctx.prisma.merchant.update({ where: { id: merchantId,