Skip to content

Commit

Permalink
fix: closes #1943 (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
datasalaryman authored Jul 18, 2024
1 parent 300ce09 commit 9eea9fb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-onions-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

resolve client error during getLatest trpc call
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export const postRouter = createTRPCRouter({
}),

getLatest: publicProcedure.query(({ ctx }) => {
return ctx.db.query.posts.findFirst({
const post = ctx.db.query.posts.findFirst({
orderBy: (posts, { desc }) => [desc(posts.createdAt)],
});

return post ?? null;
}),

getSecretMessage: protectedProcedure.query(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ export const postRouter = createTRPCRouter({
}),

getLatest: protectedProcedure.query(({ ctx }) => {
return ctx.db.post.findFirst({
const post = 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 @@ -24,8 +24,10 @@ export const postRouter = createTRPCRouter({
}),

getLatest: publicProcedure.query(({ ctx }) => {
return ctx.db.query.posts.findFirst({
const post = ctx.db.query.posts.findFirst({
orderBy: (posts, { desc }) => [desc(posts.createdAt)],
});

return post ?? null;
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const postRouter = createTRPCRouter({
}),

getLatest: publicProcedure.query(({ ctx }) => {
return ctx.db.post.findFirst({
const post = ctx.db.post.findFirst({
orderBy: { createdAt: "desc" },
});

return post ?? null;
}),
});

0 comments on commit 9eea9fb

Please sign in to comment.