-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
39 lines (38 loc) · 1.12 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import ms from "ms";
import { type ServiceArgs, createQueryService, createService } from "../helpers/createService";
import { jsonFetch } from "../helpers/jsonFetch";
import type { CreateNote, Note, NoteParams, NoteSearchParams, Notes } from "./schema";
export const notesService = {
getAll: createQueryService({
url: "/notes",
tags: ["notes"] as const,
call: (url, args: ServiceArgs<{ searchParams?: NoteSearchParams }>) =>
jsonFetch<Notes>({ url, ...args }),
}),
get: createQueryService({
url: "/notes/:noteId",
tags: ["notes"] as const,
call: (url, args: ServiceArgs<NoteParams>) => jsonFetch<Note>({ url, ...args }),
queryDefaults: { staleTime: ms("5m") },
}),
create: createService({
url: "/notes",
call: (url, args: ServiceArgs<{ body: CreateNote }>) =>
jsonFetch<Note>({
...args,
url,
method: "POST",
body: JSON.stringify(args.body),
}),
}),
edit: createService({
url: "/notes/:noteId",
call: (url, args: ServiceArgs<{ urlParams: NoteParams; body: Partial<CreateNote> }>) =>
jsonFetch<Note>({
...args,
url,
method: "PUT",
body: JSON.stringify(args.body),
}),
}),
};