From 12b7f94d59bdcd175ec420026d3d3e20e1bab9c4 Mon Sep 17 00:00:00 2001 From: ictx Date: Mon, 22 Jul 2024 01:09:33 -0500 Subject: [PATCH 1/3] fix: remove redundant null coalescing for prisma --- .../extras/src/server/api/routers/post/with-auth-prisma.ts | 4 +--- .../extras/src/server/api/routers/post/with-prisma.ts | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cli/template/extras/src/server/api/routers/post/with-auth-prisma.ts b/cli/template/extras/src/server/api/routers/post/with-auth-prisma.ts index 12aa34ba03..3994691ed1 100644 --- a/cli/template/extras/src/server/api/routers/post/with-auth-prisma.ts +++ b/cli/template/extras/src/server/api/routers/post/with-auth-prisma.ts @@ -30,12 +30,10 @@ export const postRouter = createTRPCRouter({ }), getLatest: protectedProcedure.query(({ ctx }) => { - const post = ctx.db.post.findFirst({ + return ctx.db.post.findFirst({ orderBy: { createdAt: "desc" }, where: { createdBy: { id: ctx.session.user.id } }, }); - - return post ?? null; }), getSecretMessage: protectedProcedure.query(() => { diff --git a/cli/template/extras/src/server/api/routers/post/with-prisma.ts b/cli/template/extras/src/server/api/routers/post/with-prisma.ts index 8337e2f1f8..68367a35b6 100644 --- a/cli/template/extras/src/server/api/routers/post/with-prisma.ts +++ b/cli/template/extras/src/server/api/routers/post/with-prisma.ts @@ -25,10 +25,8 @@ export const postRouter = createTRPCRouter({ }), getLatest: publicProcedure.query(({ ctx }) => { - const post = ctx.db.post.findFirst({ + return ctx.db.post.findFirst({ orderBy: { createdAt: "desc" }, }); - - return post ?? null; }), }); From 7ccef3b8ae1a2af015ab4e1c32be4fbfbc98a71b Mon Sep 17 00:00:00 2001 From: ictx Date: Mon, 22 Jul 2024 01:12:18 -0500 Subject: [PATCH 2/3] fix: resolve promise with `.then` before null coalescing for drizzle --- .../src/server/api/routers/post/with-auth-drizzle.ts | 12 ++++++------ .../src/server/api/routers/post/with-drizzle.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts b/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts index 885f2fd143..a06242cafb 100644 --- a/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts +++ b/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts @@ -28,12 +28,12 @@ export const postRouter = createTRPCRouter({ }); }), - getLatest: publicProcedure.query(({ ctx }) => { - const post = ctx.db.query.posts.findFirst({ - orderBy: (posts, { desc }) => [desc(posts.createdAt)], - }); - - return post ?? null; + getLatest: publicProcedure.query(async ({ ctx }) => { + return ctx.db.query.posts + .findFirst({ + orderBy: (posts, { desc }) => [desc(posts.createdAt)], + }) + .then((post) => post ?? null); }), getSecretMessage: protectedProcedure.query(() => { diff --git a/cli/template/extras/src/server/api/routers/post/with-drizzle.ts b/cli/template/extras/src/server/api/routers/post/with-drizzle.ts index 8c8ac78396..b740bd188d 100644 --- a/cli/template/extras/src/server/api/routers/post/with-drizzle.ts +++ b/cli/template/extras/src/server/api/routers/post/with-drizzle.ts @@ -23,11 +23,11 @@ export const postRouter = createTRPCRouter({ }); }), - getLatest: publicProcedure.query(({ ctx }) => { - const post = ctx.db.query.posts.findFirst({ - orderBy: (posts, { desc }) => [desc(posts.createdAt)], - }); - - return post ?? null; + getLatest: publicProcedure.query(async ({ ctx }) => { + return ctx.db.query.posts + .findFirst({ + orderBy: (posts, { desc }) => [desc(posts.createdAt)], + }) + .then((post) => post ?? null); }), }); From 6fb647669dbef63e81176f529be7fbaa99b78765 Mon Sep 17 00:00:00 2001 From: ictx Date: Mon, 22 Jul 2024 01:43:17 -0500 Subject: [PATCH 3/3] chore: add changeset --- .changeset/soft-garlics-rush.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/soft-garlics-rush.md diff --git a/.changeset/soft-garlics-rush.md b/.changeset/soft-garlics-rush.md new file mode 100644 index 0000000000..3fa326f940 --- /dev/null +++ b/.changeset/soft-garlics-rush.md @@ -0,0 +1,5 @@ +--- +"create-t3-app": patch +--- + +Fix unresolved promise before null coalescing