@infrab4a/connect 3.9.0-beta.4 → 3.9.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1762,8 +1762,7 @@
1762
1762
  method: 'GET',
1763
1763
  responseType: 'json',
1764
1764
  headers: {
1765
- Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
1766
- 'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
1765
+ 'Content-Type': 'application/json',
1767
1766
  Authorization: "ApiKey " + this.config.credential,
1768
1767
  },
1769
1768
  })];
@@ -1809,7 +1808,24 @@
1809
1808
  return __generator(this, function (_a) {
1810
1809
  switch (_a.label) {
1811
1810
  case 0: return [4 /*yield*/, axios__default["default"]({
1812
- url: this.config.url + "/" + index,
1811
+ url: this.config.url + "/" + index + "/_doc",
1812
+ method: 'POST',
1813
+ headers: { Authorization: "ApiKey " + this.config.credential },
1814
+ data: data,
1815
+ })];
1816
+ case 1:
1817
+ _a.sent();
1818
+ return [2 /*return*/];
1819
+ }
1820
+ });
1821
+ });
1822
+ };
1823
+ AxiosAdapter.prototype.update = function (index, id, data) {
1824
+ return __awaiter(this, void 0, void 0, function () {
1825
+ return __generator(this, function (_a) {
1826
+ switch (_a.label) {
1827
+ case 0: return [4 /*yield*/, axios__default["default"]({
1828
+ url: this.config.url + "/" + index + "/_update/" + id,
1813
1829
  method: 'PUT',
1814
1830
  headers: { Authorization: "ApiKey " + this.config.credential },
1815
1831
  data: data,
@@ -1821,12 +1837,12 @@
1821
1837
  });
1822
1838
  });
1823
1839
  };
1824
- AxiosAdapter.prototype.delete = function (index) {
1840
+ AxiosAdapter.prototype.delete = function (index, id) {
1825
1841
  return __awaiter(this, void 0, void 0, function () {
1826
1842
  return __generator(this, function (_a) {
1827
1843
  switch (_a.label) {
1828
1844
  case 0: return [4 /*yield*/, axios__default["default"]({
1829
- url: this.config.url + "/" + index,
1845
+ url: this.config.url + "/" + index + "/_doc/" + id,
1830
1846
  method: 'DELETE',
1831
1847
  headers: { Authorization: "ApiKey " + this.config.credential },
1832
1848
  })];
@@ -1845,13 +1861,14 @@
1845
1861
  var ProductsIndex = /** @class */ (function () {
1846
1862
  function ProductsIndex(adapter) {
1847
1863
  this.adapter = adapter;
1864
+ this.index = "products";
1848
1865
  }
1849
- ProductsIndex.prototype.get = function (id) {
1866
+ ProductsIndex.prototype.getById = function (id) {
1850
1867
  return __awaiter(this, void 0, void 0, function () {
1851
1868
  var data;
1852
1869
  return __generator(this, function (_a) {
1853
1870
  switch (_a.label) {
1854
- case 0: return [4 /*yield*/, this.adapter.get('products', id)];
1871
+ case 0: return [4 /*yield*/, this.adapter.get(this.index, id)];
1855
1872
  case 1:
1856
1873
  data = _a.sent();
1857
1874
  return [2 /*return*/, Product.toInstance(data)];
@@ -1859,12 +1876,35 @@
1859
1876
  });
1860
1877
  });
1861
1878
  };
1879
+ ProductsIndex.prototype.getByAlloyId = function (id) {
1880
+ return __awaiter(this, void 0, void 0, function () {
1881
+ var data;
1882
+ return __generator(this, function (_a) {
1883
+ switch (_a.label) {
1884
+ case 0: return [4 /*yield*/, this.adapter.query(this.index, {
1885
+ query: {
1886
+ bool: {
1887
+ must: {
1888
+ match: {
1889
+ id: id,
1890
+ },
1891
+ },
1892
+ },
1893
+ },
1894
+ })];
1895
+ case 1:
1896
+ data = _a.sent();
1897
+ return [2 /*return*/, Product.toInstance(data.hits[0]._source)];
1898
+ }
1899
+ });
1900
+ });
1901
+ };
1862
1902
  ProductsIndex.prototype.search = function (searchTerm) {
1863
1903
  return __awaiter(this, void 0, void 0, function () {
1864
1904
  var search;
1865
1905
  return __generator(this, function (_a) {
1866
1906
  switch (_a.label) {
1867
- case 0: return [4 /*yield*/, this.adapter.query('products', {
1907
+ case 0: return [4 /*yield*/, this.adapter.query(this.index, {
1868
1908
  query: {
1869
1909
  bool: {
1870
1910
  must: {
@@ -1888,26 +1928,6 @@
1888
1928
  })];
1889
1929
  case 1:
1890
1930
  search = _a.sent();
1891
- // const search = await this.esadapter.search(`products`, {
1892
- // bool: {
1893
- // must: {
1894
- // multi_match: {
1895
- // query: `${searchTerm}`,
1896
- // fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
1897
- // fuzziness: 2,
1898
- // },
1899
- // },
1900
- // should: {
1901
- // match_phrase_prefix: {
1902
- // 'name.search': {
1903
- // query: `${searchTerm}`,
1904
- // slop: 10,
1905
- // },
1906
- // },
1907
- // },
1908
- // filter: [{ term: { published: true } }],
1909
- // },
1910
- // })
1911
1931
  search.hits.forEach(function (row) {
1912
1932
  row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
1913
1933
  });
@@ -1917,110 +1937,58 @@
1917
1937
  });
1918
1938
  });
1919
1939
  };
1920
- // async findById(ids: string[], options?: { hasStock: boolean; size: number; shop: Shops }): Promise<Product[]> {
1921
- // const fields = [
1922
- // 'brand',
1923
- // 'id',
1924
- // 'images',
1925
- // 'miniatures',
1926
- // 'name',
1927
- // 'price',
1928
- // 'sku',
1929
- // 'stock',
1930
- // 'slug',
1931
- // 'reviews',
1932
- // 'pricePaid',
1933
- // 'isGift',
1934
- // 'stock',
1935
- // 'weight',
1936
- // 'tags',
1937
- // 'filters',
1938
- // 'hasVariants',
1939
- // 'type',
1940
- // ]
1941
- // const { hits } = await this.adapter.query('products/_search', {
1942
- // _source: fields,
1943
- // query: {
1944
- // bool: {
1945
- // filter: [
1946
- // {
1947
- // terms: {
1948
- // _id: ids,
1949
- // },
1950
- // },
1951
- // {
1952
- // term: {
1953
- // published: true,
1954
- // },
1955
- // },
1956
- // ...(options.hasStock
1957
- // ? [
1958
- // {
1959
- // range: {
1960
- // 'stock.quantity': {
1961
- // gt: 0,
1962
- // },
1963
- // },
1964
- // },
1965
- // ]
1966
- // : []),
1967
- // ],
1968
- // },
1969
- // },
1970
- // ...(options.size ? { size: options.size } : {}),
1971
- // })
1972
- // return hits.map((hit) => Product.toInstance(hit._source))
1973
- // }
1974
1940
  ProductsIndex.prototype.save = function (product) {
1941
+ return __awaiter(this, void 0, void 0, function () {
1942
+ var createdAt, updatedAt, kitProducts, data;
1943
+ return __generator(this, function (_a) {
1944
+ try {
1945
+ createdAt = product.createdAt, updatedAt = product.updatedAt, kitProducts = product.kitProducts, data = __rest(product, ["createdAt", "updatedAt", "kitProducts"]);
1946
+ this.adapter.save(this.index, data);
1947
+ }
1948
+ catch (error) {
1949
+ console.error(error);
1950
+ }
1951
+ return [2 /*return*/];
1952
+ });
1953
+ });
1954
+ };
1955
+ ProductsIndex.prototype.update = function (product) {
1975
1956
  return __awaiter(this, void 0, void 0, function () {
1976
1957
  var error_1;
1977
1958
  return __generator(this, function (_a) {
1978
1959
  switch (_a.label) {
1979
1960
  case 0:
1980
- // try {
1981
- // const { createdAt, updatedAt, kitProducts, ...data } = product
1982
- // this.esadapter.save(`product`, data)
1983
- // } catch (error) {
1984
- // console.error(error)
1985
- // }
1986
- delete product.createdAt;
1987
- delete product.updatedAt;
1988
- delete product.kitProducts;
1989
- _a.label = 1;
1961
+ _a.trys.push([0, 2, , 3]);
1962
+ return [4 /*yield*/, this.adapter.update(this.index, product.id, product)];
1990
1963
  case 1:
1991
- _a.trys.push([1, 4, , 6]);
1992
- if (!product.firestoreId)
1993
- throw new Error('Is not a product from firestore');
1994
- return [4 /*yield*/, this.get(product.firestoreId)];
1995
- case 2:
1996
1964
  _a.sent();
1997
- return [4 /*yield*/, this.adapter.save("products/_doc/" + product.firestoreId, product.toPlain())];
1998
- case 3:
1999
- _a.sent();
2000
- return [3 /*break*/, 6];
2001
- case 4:
1965
+ return [3 /*break*/, 3];
1966
+ case 2:
2002
1967
  error_1 = _a.sent();
2003
- console.error(error_1.message);
2004
- return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
2005
- case 5:
2006
- _a.sent();
2007
- return [3 /*break*/, 6];
2008
- case 6: return [2 /*return*/];
1968
+ console.error(error_1);
1969
+ return [3 /*break*/, 3];
1970
+ case 3: return [2 /*return*/];
2009
1971
  }
2010
1972
  });
2011
1973
  });
2012
1974
  };
2013
- ProductsIndex.prototype.update = function (product) {
2014
- // try {
2015
- // this.esadapter.update(`products`, product.id, product)
2016
- // } catch (error) {
2017
- // console.error(error)
2018
- // }
2019
- };
2020
1975
  ProductsIndex.prototype.delete = function (id) {
2021
1976
  return __awaiter(this, void 0, void 0, function () {
1977
+ var error_2;
2022
1978
  return __generator(this, function (_a) {
2023
- return [2 /*return*/];
1979
+ switch (_a.label) {
1980
+ case 0:
1981
+ _a.trys.push([0, 2, , 3]);
1982
+ return [4 /*yield*/, this.adapter.delete(this.index, id)];
1983
+ case 1:
1984
+ _a.sent();
1985
+ return [3 /*break*/, 3];
1986
+ case 2:
1987
+ error_2 = _a.sent();
1988
+ console.error(error_2);
1989
+ return [3 /*break*/, 3];
1990
+ case 3: return [2 /*return*/];
1991
+ }
2024
1992
  });
2025
1993
  });
2026
1994
  };