tRPC - fetch params

Hello, how can i pass parameters to the query? I have tasks that need to be filled directly by an ID coming from a URL address. const params = useParams() as { id: string }; const tasks = await api.tasks.getProjectTasks.fetch(); export const tasksRouter = createTRPCRouter({ getProjectTasks: protectedProcedure.query(({ ctx: { auth, db } }) => { const data = db .select() .from(tasks) .where(eq(project.id......)) .limit(5) .orderBy(desc(tasks.createdAt)); return data; }),
Solution:
Hello, how can i pass parameters to the query? I have tasks that need to be filled directly by an ID coming from a URL address. ...
Jump to solution
2 Replies
Neto
Neto2y ago
const params = useParams() as { id: string };
const tasks = await api.tasks.getProjectTasks.fetch(params.id);

export const tasksRouter = createTRPCRouter({
getProjectTasks: protectedProcedure
.input(z.string()) // this thing here
.query(({ input, ctx: { auth, db } }) => {
// input is of the value from .input(...)
const data = db
.select()
.from(tasks)
.where(eq(project.id, input))
.limit(5)
.orderBy(desc(tasks.createdAt));
return data;
}),
const params = useParams() as { id: string };
const tasks = await api.tasks.getProjectTasks.fetch(params.id);

export const tasksRouter = createTRPCRouter({
getProjectTasks: protectedProcedure
.input(z.string()) // this thing here
.query(({ input, ctx: { auth, db } }) => {
// input is of the value from .input(...)
const data = db
.select()
.from(tasks)
.where(eq(project.id, input))
.limit(5)
.orderBy(desc(tasks.createdAt));
return data;
}),
slavi_lns
slavi_lnsOP2y ago
@nyx (Rustular DevRel) Thank you soo much.
Want results from more Discord servers?
Add your server