timeline db and react query
This commit is contained in:
20
apps/web/src/functions/get-timelines.ts
Normal file
20
apps/web/src/functions/get-timelines.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@zendegi/db";
|
||||
import { createServerFn } from "@tanstack/react-start";
|
||||
import { timeline } from "@zendegi/db/schema/timeline";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
export const getTimelines = createServerFn({ method: "GET" }).handler(
|
||||
async () => {
|
||||
return db.query.timeline.findMany({
|
||||
where: eq(timeline.visibility, "public"),
|
||||
orderBy: (t, { desc }) => [desc(t.createdAt)],
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const timelinesQueryOptions = () =>
|
||||
queryOptions({
|
||||
queryKey: ["timelines"],
|
||||
queryFn: () => getTimelines(),
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import { createServerFn } from "@tanstack/react-start";
|
||||
|
||||
import { authMiddleware } from "@/middleware/auth";
|
||||
|
||||
export const getUser = createServerFn({ method: "GET" })
|
||||
|
||||
Reference in New Issue
Block a user