From 0be67197c08f6fe83b087b644f3a519f2698c493 Mon Sep 17 00:00:00 2001 From: mrevanzak Date: Sun, 12 Nov 2023 20:42:00 +0700 Subject: [PATCH] feat(api): getDefaultAddress service --- packages/api/src/router/user.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/api/src/router/user.ts b/packages/api/src/router/user.ts index e066707..047898c 100644 --- a/packages/api/src/router/user.ts +++ b/packages/api/src/router/user.ts @@ -9,6 +9,12 @@ export const userRouter = createTRPCRouter({ where: (addresses, { eq }) => eq(addresses.userId, ctx.auth.userId), }); }), + getDefaultAddress: protectedProcedure + .query(({ ctx }) => { + return ctx.db.query.addresses.findFirst({ + where: (addresses, { and, eq }) => and(eq(addresses.userId, ctx.auth.userId), eq(addresses.default, true)), + }); + }), createAddress: protectedProcedure .input(insertAddressSchema) .query(({ input, ctx }) => {