Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / permissions_by_term / js / src / async-function / fetch-from-backend.js
diff --git a/web/modules/contrib/permissions_by_term/js/src/async-function/fetch-from-backend.js b/web/modules/contrib/permissions_by_term/js/src/async-function/fetch-from-backend.js
new file mode 100644 (file)
index 0000000..717a3c4
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * @returns array
+ */
+const fetchFromBackend = async () => {
+  let contentType = null;
+  if (window.location.href.indexOf('/node/add') !== -1) {
+    contentType = window.location.href.split("/").pop();
+  }
+
+  let url = '/admin/permissions-by-term/access-info-by-url?url=' + window.location.pathname;
+  if (contentType !== null) {
+    url = '/admin/permissions-by-term/access-info-by-content-type/' + contentType;
+  }
+
+  return await fetch(url, { credentials:'include' })
+      .then(function(response) {
+        return response.json();
+      }).then(function(data) {
+        return data;
+      });
+};
+
+export default fetchFromBackend;
\ No newline at end of file