|
Lines 2-41
import { setError } from "../messages";
Link Here
|
| 2 |
|
2 |
|
| 3 |
//TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient |
3 |
//TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient |
| 4 |
|
4 |
|
| 5 |
const _createEditPackage = function (method, erm_package) { |
|
|
| 6 |
let apiUrl = "/api/v1/erm/eholdings/local/packages"; |
| 7 |
|
| 8 |
if (method == "PUT") { |
| 9 |
apiUrl += "/" + erm_package.package_id; |
| 10 |
} |
| 11 |
delete erm_package.package_id; |
| 12 |
delete erm_package.resources; |
| 13 |
delete erm_package.vendor; |
| 14 |
delete erm_package.resources_count; |
| 15 |
delete erm_package.is_selected; |
| 16 |
|
| 17 |
erm_package.package_agreements = erm_package.package_agreements.map( |
| 18 |
({ package_id, agreement, ...keepAttrs }) => keepAttrs |
| 19 |
); |
| 20 |
|
| 21 |
const options = { |
| 22 |
method: method, |
| 23 |
body: JSON.stringify(erm_package), |
| 24 |
headers: { |
| 25 |
"Content-Type": "application/json;charset=utf-8", |
| 26 |
}, |
| 27 |
}; |
| 28 |
|
| 29 |
return myFetch(apiUrl, options, 1); |
| 30 |
}; |
| 31 |
|
| 32 |
export const createPackage = function (erm_package) { |
| 33 |
return _createEditPackage("POST", erm_package); |
| 34 |
}; |
| 35 |
export const editPackage = function (erm_package) { |
| 36 |
return _createEditPackage("PUT", erm_package); |
| 37 |
}; |
| 38 |
|
| 39 |
const _fetchPackage = function (apiUrl, package_id) { |
5 |
const _fetchPackage = function (apiUrl, package_id) { |
| 40 |
if (!package_id) return; |
6 |
if (!package_id) return; |
| 41 |
return myFetch(apiUrl, { |
7 |
return myFetch(apiUrl, { |
|
Lines 45-54
const _fetchPackage = function (apiUrl, package_id) {
Link Here
|
| 45 |
}, |
11 |
}, |
| 46 |
}); |
12 |
}); |
| 47 |
}; |
13 |
}; |
| 48 |
export const fetchLocalPackage = function (package_id) { |
|
|
| 49 |
const apiUrl = "/api/v1/erm/eholdings/local/packages/" + package_id; |
| 50 |
return _fetchPackage(apiUrl, package_id); |
| 51 |
}; |
| 52 |
export const fetchEBSCOPackage = function (package_id) { |
14 |
export const fetchEBSCOPackage = function (package_id) { |
| 53 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/packages/" + package_id; |
15 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/packages/" + package_id; |
| 54 |
return _fetchPackage(apiUrl, package_id); |
16 |
return _fetchPackage(apiUrl, package_id); |
|
Lines 61-94
export const _fetchPackages = function (apiUrl) {
Link Here
|
| 61 |
}, |
23 |
}, |
| 62 |
}); |
24 |
}); |
| 63 |
}; |
25 |
}; |
| 64 |
export const fetchLocalPackages = function () { |
|
|
| 65 |
const apiUrl = "/api/v1/erm/eholdings/local/packages?_per_page=-1"; |
| 66 |
return _fetchPackages(apiUrl); |
| 67 |
}; |
| 68 |
export const fetchEBSCOPackages = function () { |
26 |
export const fetchEBSCOPackages = function () { |
| 69 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/packages"; |
27 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/packages"; |
| 70 |
return _fetchPackages(apiUrl); |
28 |
return _fetchPackages(apiUrl); |
| 71 |
}; |
29 |
}; |
| 72 |
|
30 |
|
| 73 |
export const fetchLocalPackageCount = function (filters) { |
|
|
| 74 |
const q = filters |
| 75 |
? { |
| 76 |
"me.name": { like: "%" + filters.package_name + "%" }, |
| 77 |
...(filters.content_type |
| 78 |
? { "me.content_type": filters.content_type } |
| 79 |
: {}), |
| 80 |
} |
| 81 |
: {}; |
| 82 |
|
| 83 |
const params = { |
| 84 |
_page: 1, |
| 85 |
_per_page: 1, |
| 86 |
q: JSON.stringify(q), |
| 87 |
}; |
| 88 |
var apiUrl = "/api/v1/erm/eholdings/local/packages"; |
| 89 |
return myFetchTotal(apiUrl + "?" + new URLSearchParams(params)); |
| 90 |
}; |
| 91 |
|
| 92 |
export const _fetchTitle = function (apiUrl, title_id) { |
31 |
export const _fetchTitle = function (apiUrl, title_id) { |
| 93 |
if (!title_id) return; |
32 |
if (!title_id) return; |
| 94 |
return myFetch(apiUrl, { |
33 |
return myFetch(apiUrl, { |
|
Lines 97-135
export const _fetchTitle = function (apiUrl, title_id) {
Link Here
|
| 97 |
}, |
36 |
}, |
| 98 |
}); |
37 |
}); |
| 99 |
}; |
38 |
}; |
| 100 |
export const fetchLocalTitle = function (title_id) { |
|
|
| 101 |
const apiUrl = "/api/v1/erm/eholdings/local/titles/" + title_id; |
| 102 |
return _fetchTitle(apiUrl, title_id); |
| 103 |
}; |
| 104 |
export const fetchEBSCOTitle = function (title_id) { |
39 |
export const fetchEBSCOTitle = function (title_id) { |
| 105 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/titles/" + title_id; |
40 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/titles/" + title_id; |
| 106 |
return _fetchTitle(apiUrl, title_id); |
41 |
return _fetchTitle(apiUrl, title_id); |
| 107 |
}; |
42 |
}; |
| 108 |
|
43 |
|
| 109 |
export const fetchLocalTitleCount = function (filters) { |
|
|
| 110 |
const q = filters |
| 111 |
? { |
| 112 |
...(filters.publication_title |
| 113 |
? { |
| 114 |
"me.publication_title": { |
| 115 |
like: "%" + filters.publication_title + "%", |
| 116 |
}, |
| 117 |
} |
| 118 |
: {}), |
| 119 |
...(filters.publication_type |
| 120 |
? { "me.publication_type": filters.publication_type } |
| 121 |
: {}), |
| 122 |
} |
| 123 |
: undefined; |
| 124 |
const params = { |
| 125 |
_page: 1, |
| 126 |
_per_page: 1, |
| 127 |
...(q ? { q: JSON.stringify(q) } : {}), |
| 128 |
}; |
| 129 |
var apiUrl = "/api/v1/erm/eholdings/local/titles"; |
| 130 |
return myFetchTotal(apiUrl + "?" + new URLSearchParams(params)); |
| 131 |
}; |
| 132 |
|
| 133 |
export const _fetchResource = function (apiUrl, resource_id) { |
44 |
export const _fetchResource = function (apiUrl, resource_id) { |
| 134 |
if (!resource_id) return; |
45 |
if (!resource_id) return; |
| 135 |
return myFetch(apiUrl, { |
46 |
return myFetch(apiUrl, { |
|
Lines 138-147
export const _fetchResource = function (apiUrl, resource_id) {
Link Here
|
| 138 |
}, |
49 |
}, |
| 139 |
}); |
50 |
}); |
| 140 |
}; |
51 |
}; |
| 141 |
export const fetchLocalResource = function (resource_id) { |
|
|
| 142 |
const apiUrl = "/api/v1/erm/eholdings/local/resources/" + resource_id; |
| 143 |
return _fetchResource(apiUrl, resource_id); |
| 144 |
}; |
| 145 |
export const fetchEBSCOResource = function (resource_id) { |
52 |
export const fetchEBSCOResource = function (resource_id) { |
| 146 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/resources/" + resource_id; |
53 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/resources/" + resource_id; |
| 147 |
return _fetchResource(apiUrl, resource_id); |
54 |
return _fetchResource(apiUrl, resource_id); |
|
Lines 151-160
export const _fetchResources = async function (apiUrl) {
Link Here
|
| 151 |
return await myFetch(apiUrl); |
58 |
return await myFetch(apiUrl); |
| 152 |
}; |
59 |
}; |
| 153 |
|
60 |
|
| 154 |
export const fetchLocalResources = function () { |
|
|
| 155 |
const apiUrl = "/api/v1/erm/eholdings/local/resources"; |
| 156 |
return _fetchResources(apiUrl); |
| 157 |
}; |
| 158 |
export const fetchEBSCOResources = function () { |
61 |
export const fetchEBSCOResources = function () { |
| 159 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/resources"; |
62 |
const apiUrl = "/api/v1/erm/eholdings/ebsco/resources"; |
| 160 |
return _fetchResources(apiUrl); |
63 |
return _fetchResources(apiUrl); |