Skip to content

Commit

Permalink
fix(cli/template): add code attempting to resolve #1943
Browse files Browse the repository at this point in the history
  • Loading branch information
datasalaryman committed Jul 15, 2024
1 parent 300ce09 commit f7fcb4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ 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)],
});
if (post === undefined) {
return null;
}
return post;
}),

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

getLatest: protectedProcedure.query(({ ctx }) => {
return ctx.db.post.findFirst({
getLatest: publicProcedure.query(async ({ ctx }) => {
const post = ctx.db.post.findFirst({
orderBy: { createdAt: "desc" },
where: { createdBy: { id: ctx.session.user.id } },
});
if (post === undefined) {
return null;
}
return post;
}),

getSecretMessage: protectedProcedure.query(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ 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)],
});
if (post === undefined) {
return null;
}
return post;
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ export const postRouter = createTRPCRouter({
}),

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

if (post === undefined) {
return null;
}

return post;
}),
});

0 comments on commit f7fcb4d

Please sign in to comment.