1
|
import { SortOptions } from "../types/general"
|
2
|
import { Item } from "../types/item";
|
3
|
import { Note } from "../types/note"
|
4
|
import { axiosInstance } from "./api"
|
5
|
|
6
|
|
7
|
export const getItemNotesRequest = async (item : Item, relatedComments : boolean) => {
|
8
|
|
9
|
let url = `/notes/?item_id[]=${item.id}`;
|
10
|
|
11
|
if(relatedComments && item.concordances && item.concordances.length > 0){
|
12
|
for(let i = 0; i < item.concordances.length; i++){
|
13
|
url += `&item_id[]=${item.concordances[i].id}`
|
14
|
}
|
15
|
}
|
16
|
console.log(url);
|
17
|
return await axiosInstance.get(
|
18
|
url
|
19
|
)
|
20
|
}
|
21
|
|
22
|
export const updateNoteRequest = async (note : Note) => {
|
23
|
return await axiosInstance.put(`/note`, note);
|
24
|
}
|
25
|
|
26
|
export const createNoteRequest = async (note : Note) => {
|
27
|
return await axiosInstance.post(`/note`, note);
|
28
|
}
|
29
|
|
30
|
export const deleteNoteRequest = async (noteId : string) => {
|
31
|
return await axiosInstance.delete(
|
32
|
`/note/${noteId}`
|
33
|
)
|
34
|
}
|
35
|
|
36
|
export const getAllNotesRequest = async (myComments : boolean, generalComments : boolean, sortOptions: { items: SortOptions, date: SortOptions }) => {
|
37
|
let url = `/notes/?my_notes=${myComments}&general_notes=${generalComments}`;
|
38
|
|
39
|
if(sortOptions.date != SortOptions.None){
|
40
|
url += "&order_by=date&order_dir="+sortOptions.date;
|
41
|
}
|
42
|
if(sortOptions.items != SortOptions.None){
|
43
|
url += "&order_by=items&order_dir="+sortOptions.items;
|
44
|
}
|
45
|
|
46
|
return await axiosInstance.get(
|
47
|
url
|
48
|
)
|
49
|
}
|
50
|
|
51
|
|
52
|
|