Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getLatest procedure has unresolved promise before null coalescing #1949

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-garlics-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

Fix unresolved promise before null coalescing
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
});
Loading