@q2devel/q2-core 1.0.101 → 1.0.102
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.
- package/dist/api/getTerms.d.ts.map +1 -1
- package/dist/api/getTerms.js +40 -29
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTerms.d.ts","sourceRoot":"","sources":["../../api/getTerms.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTerms.d.ts","sourceRoot":"","sources":["../../api/getTerms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAIpC,KAAK,aAAa,GAAG;IACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,IAAI,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;KAAE,CAAC,CAAA;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,CAAA;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,QAAQ,GACjB,KAAK,WAAW,EAChB,8DAaG,aAAa,KACjB,OAAO,CAAC,IAAI,EAAE,CAiHhB,CAAA"}
|
package/dist/api/getTerms.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// api/getTerms.ts
|
|
2
1
|
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
3
2
|
import mapIncludedResources from '../utils/mapIncludedResources';
|
|
4
3
|
export const getTerms = async (ctx, { categoryId, include = [
|
|
@@ -20,47 +19,59 @@ export const getTerms = async (ctx, { categoryId, include = [
|
|
|
20
19
|
const baseUrl = ctx.locale === ctx.defaultLocale
|
|
21
20
|
? `/jsonapi/taxonomy_term/produktykategorie`
|
|
22
21
|
: `/${ctx.locale}/jsonapi/taxonomy_term/produktykategorie`;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
params.
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
// Build params for a given offset. Each page builds fresh params so we
|
|
23
|
+
// never carry over Drupal's `next` link cursor (which would explode the
|
|
24
|
+
// URL with all already-seen drupal_internal__tid values and cause
|
|
25
|
+
// 414/431 once the term count grows).
|
|
26
|
+
const buildParams = (offset) => {
|
|
27
|
+
const params = new DrupalJsonApiParams()
|
|
28
|
+
.addInclude(include)
|
|
29
|
+
.addFilter('langcode', ctx.locale)
|
|
30
|
+
.addPageLimit(pageLimit)
|
|
31
|
+
.addPageOffset(offset);
|
|
32
|
+
if (sort && sort.length > 0) {
|
|
33
|
+
sort.forEach(({ field, direction = 'DESC' }) => {
|
|
34
|
+
params.addSort(field, direction);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else if (sortField) {
|
|
38
|
+
// Deprecated: support old sortField for backward compatibility
|
|
39
|
+
params.addSort(sortField);
|
|
40
|
+
}
|
|
41
|
+
if (filter && filter.length > 0) {
|
|
42
|
+
filter.forEach(({ field, value }) => {
|
|
43
|
+
params.addFilter(field, String(value));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (categoryId) {
|
|
47
|
+
params.addFilter('drupal_internal__tid', categoryId, 'IN');
|
|
48
|
+
}
|
|
49
|
+
return params;
|
|
50
|
+
};
|
|
46
51
|
// Pole pro akumulaci všech stránek dat
|
|
47
52
|
const allData = [];
|
|
48
53
|
const allIncluded = [];
|
|
49
|
-
let
|
|
54
|
+
let offset = 0;
|
|
50
55
|
let pageCounter = 0;
|
|
51
|
-
while (
|
|
52
|
-
const
|
|
56
|
+
while (pageCounter < 50) {
|
|
57
|
+
const params = buildParams(offset);
|
|
58
|
+
const url = `${baseUrl}?${params.getQueryString()}`;
|
|
59
|
+
const response = await ctx.axios.get(url);
|
|
53
60
|
const data = response.data;
|
|
54
61
|
if (Array.isArray(data.data)) {
|
|
55
62
|
allData.push(...data.data);
|
|
56
63
|
}
|
|
57
|
-
else {
|
|
64
|
+
else if (data.data) {
|
|
58
65
|
allData.push(data.data);
|
|
59
66
|
}
|
|
60
67
|
if (Array.isArray(data.included)) {
|
|
61
68
|
allIncluded.push(...data.included);
|
|
62
69
|
}
|
|
63
|
-
|
|
70
|
+
// Drupal still tells us whether more pages exist via links.next —
|
|
71
|
+
// we just don't follow its href, we compute our own offset URL.
|
|
72
|
+
if (!data.links?.next?.href)
|
|
73
|
+
break;
|
|
74
|
+
offset += pageLimit;
|
|
64
75
|
pageCounter++;
|
|
65
76
|
}
|
|
66
77
|
const combinedResponse = {
|