2c1c551ba2c27cc9ccc7cbb82bfb3cf8ee187ef4
[srvgit] / koha-tmpl / intranet-tmpl / prog / js / vue / fetch.js
1 import { setError } from "./messages";
2
3 export const fetchAgreement = async function (agreement_id) {
4     if (!agreement_id) return;
5     const apiUrl = "/api/v1/erm/agreements/" + agreement_id;
6     let agreement;
7     await fetch(apiUrl, {
8         headers: {
9             "x-koha-embed":
10                 "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement,documents",
11         },
12     })
13         .then((res) => res.json())
14         .then(
15             (result) => {
16                 agreement = result;
17             },
18             (error) => {
19                 setError(error);
20             }
21         );
22     return agreement;
23 };
24
25 export const fetchAgreements = async function () {
26     const apiUrl = "/api/v1/erm/agreements";
27     let agreements;
28     await fetch(apiUrl)
29         .then((res) => res.json())
30         .then(
31             (result) => {
32                 agreements = result;
33             },
34             (error) => {
35                 setError(error);
36             }
37         );
38     return agreements;
39 };
40
41 export const fetchLicense = async function (license_id) {
42     if (!license_id) return;
43     const apiUrl = "/api/v1/erm/licenses/" + license_id;
44     let license;
45     await fetch(apiUrl)
46         .then((res) => res.json())
47         .then(
48             (result) => {
49                 license = result;
50             },
51             (error) => {
52                 setError(error);
53             }
54         );
55     return license;
56 };
57
58 export const fetchLicenses = async function () {
59     const apiUrl = "/api/v1/erm/licenses";
60     let licenses;
61     await fetch(apiUrl)
62         .then((res) => res.json())
63         .then(
64             (result) => {
65                 licenses = result;
66             },
67             (error) => {
68                 setError(error);
69             }
70         );
71     return licenses;
72 };
73
74 export const fetchPatron = async function (patron_id) {
75     if (!patron_id) return;
76     const apiUrl = "/api/v1/patrons/" + patron_id;
77     let patron;
78     await fetch(apiUrl)
79         .then((res) => res.json())
80         .then(
81             (result) => {
82                 patron = result;
83             },
84             (error) => {
85                 setError(error);
86             }
87         );
88     return patron;
89 };
90
91 export const fetchVendors = async function () {
92     const apiUrl = "/api/v1/acquisitions/vendors";
93     let vendors;
94     await fetch(apiUrl)
95         .then((res) => res.json())
96         .then(
97             (result) => {
98                 vendors = result;
99             },
100             (error) => {
101                 setError(error);
102             }
103         );
104     return vendors;
105 };