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 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-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-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); }), }); 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; }), });