@q2devel/q2-core 1.0.16 → 1.0.18
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CoreContext } from '../../context';
|
|
2
2
|
import { Product } from '../../types/products/Product';
|
|
3
3
|
type GetProductsParams = {
|
|
4
|
+
locale?: string;
|
|
4
5
|
categoryId?: string[];
|
|
5
6
|
productId?: string;
|
|
6
7
|
searchTerm?: string;
|
|
@@ -17,12 +18,12 @@ type GetProductsParams = {
|
|
|
17
18
|
cache?: boolean;
|
|
18
19
|
mapFnVariations?: (base: Product, raw: any) => Product | Promise<Product>;
|
|
19
20
|
};
|
|
20
|
-
export declare const getProducts: (ctx: CoreContext, { categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, mapFnVariations, }: GetProductsParams) => Promise<Product[]>;
|
|
21
|
+
export declare const getProducts: (ctx: CoreContext, { locale, categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, mapFnVariations, }: GetProductsParams) => Promise<Product[]>;
|
|
21
22
|
type GetProductCountParams = {
|
|
22
23
|
categoryId?: string[];
|
|
23
24
|
tag?: string;
|
|
24
25
|
cache?: boolean;
|
|
25
26
|
};
|
|
26
|
-
export declare const getProductCount: (ctx: CoreContext, { categoryId, tag, cache
|
|
27
|
+
export declare const getProductCount: (ctx: CoreContext, { categoryId, tag, cache }: GetProductCountParams) => Promise<number>;
|
|
27
28
|
export {};
|
|
28
29
|
//# sourceMappingURL=getProducts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProducts.d.ts","sourceRoot":"","sources":["../../../api/products/getProducts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getProducts.d.ts","sourceRoot":"","sources":["../../../api/products/getProducts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAKtD,KAAK,iBAAiB,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;QAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC5E,CAAA;AAED,eAAO,MAAM,WAAW,GACpB,KAAK,WAAW,EAChB,oHAmBG,iBAAiB,KACrB,OAAO,CAAC,OAAO,EAAE,CA8DnB,CAAA;AAED,KAAK,qBAAqB,GAAG;IACzB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,eAAe,GACxB,KAAK,WAAW,EAChB,4BAA6C,qBAAqB,KACnE,OAAO,CAAC,MAAM,CAqChB,CAAA"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
|
-
import mapIncludedResources from '../../utils/mapIncludedResources';
|
|
3
2
|
import { handleSortChange } from '../../utils/generalHelper';
|
|
3
|
+
import mapIncludedResources from '../../utils/mapIncludedResources';
|
|
4
4
|
import { mapProduct } from '../../utils/mapProducts';
|
|
5
|
-
export const getProducts = async (ctx, { categoryId, productId, searchTerm, limit, offset, filters = [], sort = '', tag = '', include = [
|
|
5
|
+
export const getProducts = async (ctx, { locale, categoryId, productId, searchTerm, limit, offset, filters = [], sort = '', tag = '', include = [
|
|
6
6
|
'product_id',
|
|
7
7
|
'product_id.field_category',
|
|
8
8
|
'product_id.field_image',
|
|
9
9
|
'product_id.field_image.field_media_image',
|
|
10
10
|
'field_image.field_media_image',
|
|
11
11
|
], cache = true, mapFnVariations, }) => {
|
|
12
|
-
const
|
|
12
|
+
const currentLocale = locale || ctx.locale;
|
|
13
|
+
const cacheKey = [
|
|
14
|
+
'products',
|
|
15
|
+
currentLocale,
|
|
13
16
|
categoryId?.length ? `cat:${categoryId.join(',')}` : '',
|
|
14
17
|
productId ? `id:${productId}` : '',
|
|
15
18
|
searchTerm ? `search:${searchTerm}` : '',
|
|
@@ -17,8 +20,10 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
17
20
|
offset ? `offset:${offset}` : '',
|
|
18
21
|
filters.length ? `filters:${JSON.stringify(filters)}` : '',
|
|
19
22
|
sort ? `sort:${sort}` : '',
|
|
20
|
-
|
|
21
|
-
]
|
|
23
|
+
tag ? `tag:${tag}` : '',
|
|
24
|
+
]
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(':');
|
|
22
27
|
if (cache && ctx.getCache) {
|
|
23
28
|
const cached = await ctx.getCache(cacheKey);
|
|
24
29
|
if (cached)
|
|
@@ -26,7 +31,7 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
26
31
|
}
|
|
27
32
|
const params = new DrupalJsonApiParams()
|
|
28
33
|
.addInclude(include)
|
|
29
|
-
.addFilter('langcode',
|
|
34
|
+
.addFilter('langcode', currentLocale);
|
|
30
35
|
if (tag)
|
|
31
36
|
params.addFilter(`product_id.${tag}`, '1');
|
|
32
37
|
if (categoryId)
|
|
@@ -45,9 +50,9 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
45
50
|
params.addSort(sortData.title, sortData.direction);
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
|
-
const url =
|
|
53
|
+
const url = currentLocale === ctx.defaultLocale
|
|
49
54
|
? `/jsonapi/index/variation`
|
|
50
|
-
: `/${
|
|
55
|
+
: `/${currentLocale}/jsonapi/index/variation`;
|
|
51
56
|
const { data } = await ctx.axios.get(`${url}?${params.getQueryString()}`);
|
|
52
57
|
const resolvedProducts = mapIncludedResources(data, 5);
|
|
53
58
|
const mappedProducts = await Promise.all(resolvedProducts.map(async (item) => {
|
|
@@ -62,11 +67,15 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
62
67
|
}
|
|
63
68
|
return mappedProducts;
|
|
64
69
|
};
|
|
65
|
-
export const getProductCount = async (ctx, { categoryId = [], tag = '', cache = true
|
|
66
|
-
const cacheKey = [
|
|
70
|
+
export const getProductCount = async (ctx, { categoryId = [], tag = '', cache = true }) => {
|
|
71
|
+
const cacheKey = [
|
|
72
|
+
'productCount',
|
|
73
|
+
ctx.locale,
|
|
67
74
|
categoryId?.length ? `cat:${categoryId.join(',')}` : '',
|
|
68
75
|
tag ? `tag:${tag}` : '',
|
|
69
|
-
]
|
|
76
|
+
]
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join(':');
|
|
70
79
|
// if (cache && ctx.getCache) {
|
|
71
80
|
// const cached = await ctx.getCache<number>(cacheKey);
|
|
72
81
|
// if (cached !== null) return cached;
|
|
@@ -78,9 +87,7 @@ export const getProductCount = async (ctx, { categoryId = [], tag = '', cache =
|
|
|
78
87
|
if (tag) {
|
|
79
88
|
params.addFilter(`product_id.${tag}`, '1');
|
|
80
89
|
}
|
|
81
|
-
params
|
|
82
|
-
.addFilter('langcode', ctx.locale)
|
|
83
|
-
.addPageLimit(1);
|
|
90
|
+
params.addFilter('langcode', ctx.locale).addPageLimit(1);
|
|
84
91
|
const url = ctx.locale === ctx.defaultLocale
|
|
85
92
|
? `/jsonapi/index/variation`
|
|
86
93
|
: `/${ctx.locale}/jsonapi/index/variation`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetProducts.d.ts","sourceRoot":"","sources":["../../../hooks/products/useGetProducts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,KAAK,qBAAqB,GAAG;IACzB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;QAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,GAAG,CAAA;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,cAAc,GACvB,KAAK,WAAW,EAChB,QAAQ,MAAM,EACd,UAAU,qBAAqB,
|
|
1
|
+
{"version":3,"file":"useGetProducts.d.ts","sourceRoot":"","sources":["../../../hooks/products/useGetProducts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;A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