-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalbumApi.ts
More file actions
71 lines (61 loc) · 1.92 KB
/
albumApi.ts
File metadata and controls
71 lines (61 loc) · 1.92 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { useMutation, useQuery } from "@tanstack/react-query";
import { Album, AlbumsResponse } from "models/Album";
import { IGetObjects } from "types/types";
import axiosClient from "./axios";
export async function addAlbum({
name,
isSystem
}: {
name: string;
isSystem: boolean;
}): Promise<Album> {
const res = await axiosClient.post('album', {
name,
isSystem
});
return res.data;
}
export const getAlbums = () =>
useQuery({
queryKey: ['getAlbums'],
queryFn: async (): Promise<Album[]> => {
const res = await axiosClient.get<AlbumsResponse>('album');
return res.data.albums;
},
});
export const deleteAlbum = () =>
useMutation({
mutationFn: async (id: string) => {
await axiosClient.delete(`album/${id}`);
},
});
export async function addObjectsToAlbum(params: { albumId: string; objectIds: string[] }) {
const { albumId, objectIds } = params;
const { data } = await axiosClient.post(
`album/${encodeURIComponent(albumId)}/objects`, objectIds
);
return data;
}
export const getAlbumItems = async ({ albumId }: { albumId: string; }): Promise<IGetObjects> => {
const res = await axiosClient.get(`/album/${albumId}/100`);
return res.data;
};
export const getAlbumById = async ({ albumId }: { albumId: string; }): Promise<Album> => {
const res = await axiosClient.get(`/album/${albumId}`);
return res.data;
};
export async function updateAlbum({ id, name }: {
id: string
name: string;
}): Promise<void> {
const res = await axiosClient.put('album', { id, name });
return res.data;
}
export async function bulkRemoveObjectsFromAlbum(params: { albumId: string; objectIds: string[] }) {
const { albumId, objectIds } = params;
const { data } = await axiosClient.post(
`/albums/${encodeURIComponent(albumId)}/objects:bulk-delete`,
objectIds
);
return data;
}