|
Line 0
Link Here
|
|
|
1 |
export class DisplayAPIClient { |
| 2 |
constructor(HttpClient) { |
| 3 |
this.httpClientDisplaysConfig = new HttpClient({ |
| 4 |
baseURL: "/api/v1/displays/config/", |
| 5 |
}); |
| 6 |
|
| 7 |
this.httpClientDisplays = new HttpClient({ |
| 8 |
baseURL: "/api/v1/displays/", |
| 9 |
}); |
| 10 |
|
| 11 |
this.httpClientDisplayItems = new HttpClient({ |
| 12 |
baseURL: "/api/v1/display/items/", |
| 13 |
}); |
| 14 |
} |
| 15 |
|
| 16 |
get config() { |
| 17 |
return { |
| 18 |
get: () => |
| 19 |
this.httpClientDisplaysConfig.get({ |
| 20 |
endpoint: "", |
| 21 |
}), |
| 22 |
}; |
| 23 |
} |
| 24 |
|
| 25 |
get displays() { |
| 26 |
return { |
| 27 |
create: display => |
| 28 |
this.httpClientDisplays.post({ |
| 29 |
endpoint: "", |
| 30 |
body: display, |
| 31 |
}), |
| 32 |
get: id => |
| 33 |
this.httpClientDisplays.get({ |
| 34 |
endpoint: "" + id, |
| 35 |
headers: { |
| 36 |
"x-koha-embed": "display_items,library,item_type,+strings", |
| 37 |
}, |
| 38 |
}), |
| 39 |
getAll: (query, params) => |
| 40 |
this.httpClientDisplays.getAll({ |
| 41 |
endpoint: "", |
| 42 |
headers: { |
| 43 |
"x-koha-embed": "display_items,library,item_type,+strings", |
| 44 |
}, |
| 45 |
params, |
| 46 |
query, |
| 47 |
}), |
| 48 |
update: (display, id) => |
| 49 |
this.httpClientDisplays.put({ |
| 50 |
endpoint: "" + id, |
| 51 |
body: display, |
| 52 |
}), |
| 53 |
delete: id => |
| 54 |
this.httpClientDisplays.delete({ |
| 55 |
endpoint: "" + id, |
| 56 |
}), |
| 57 |
count: (query = {}) => |
| 58 |
this.httpClientDisplays.count({ |
| 59 |
endpoint: |
| 60 |
"?" + |
| 61 |
new URLSearchParams({ |
| 62 |
_page: 1, |
| 63 |
_per_page: 1, |
| 64 |
...(query && { q: JSON.stringify(query) }), |
| 65 |
}), |
| 66 |
}), |
| 67 |
}; |
| 68 |
} |
| 69 |
|
| 70 |
get displayItems() { |
| 71 |
return { |
| 72 |
create: displayItem => |
| 73 |
this.httpClientDisplayItems.post({ |
| 74 |
endpoint: "", |
| 75 |
body: displayItem, |
| 76 |
}), |
| 77 |
get: (display_id, itemnumber) => |
| 78 |
this.httpClientDisplayItems.get({ |
| 79 |
endpoint: "" + display_id + "/" + itemnumber, |
| 80 |
}), |
| 81 |
getAll: (query, params) => |
| 82 |
this.httpClientDisplayItems.getAll({ |
| 83 |
endpoint: "", |
| 84 |
query, |
| 85 |
params, |
| 86 |
}), |
| 87 |
update: (displayItem, display_id, itemnumber) => |
| 88 |
this.httpClientDisplayItems.put({ |
| 89 |
endpoint: "" + display_id + "/" + itemnumber, |
| 90 |
body: displayItem, |
| 91 |
}), |
| 92 |
delete: (display_id, itemnumber) => |
| 93 |
this.httpClientDisplayItems.delete({ |
| 94 |
endpoint: "" + display_id + "/" + itemnumber, |
| 95 |
}), |
| 96 |
batchAdd: displayItems => |
| 97 |
this.httpClientDisplayItems.post({ |
| 98 |
endpoint: "batch", |
| 99 |
body: displayItems, |
| 100 |
}), |
| 101 |
batchDelete: displayItems => |
| 102 |
this.httpClientDisplayItems.delete({ |
| 103 |
endpoint: "batch", |
| 104 |
body: displayItems, |
| 105 |
parseResponse: true, |
| 106 |
}), |
| 107 |
count: (query = {}) => |
| 108 |
this.httpClientDisplayItems.count({ |
| 109 |
endpoint: |
| 110 |
"?" + |
| 111 |
new URLSearchParams({ |
| 112 |
_page: 1, |
| 113 |
_per_page: 1, |
| 114 |
...(query && { q: JSON.stringify(query) }), |
| 115 |
}), |
| 116 |
}), |
| 117 |
}; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
export default DisplayAPIClient; |