Skip to content

Commit 018aa4e

Browse files
authored
Merge pull request #51 from contentstack/next
Added array of values in includereference method
2 parents d88e24f + c0bc3f7 commit 018aa4e

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change log
22

3+
### Version: 4.3.0
4+
#### Date: Septmber-09-2024
5+
Feat: Include refernce accepts array of values
6+
37
### Version: 4.2.0
48
#### Date: Septmber-04-2024
59
Feat: Variants support added

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/delivery-sdk",
3-
"version": "4.2.0",
3+
"version": "4.3.0",
44
"type": "commonjs",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/types/src/index.d.ts",

src/lib/entries.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,17 @@ export class Entries extends EntryQueryable {
111111
* @param {string} referenceFieldUid - UID of the reference field to include.
112112
* @returns {Entries} - Returns the Entries instance for chaining.
113113
*/
114-
includeReference(referenceFieldUid: string): Entries {
115-
this._queryParams['include[]'] = referenceFieldUid;
116-
114+
includeReference(...referenceFieldUid: (string | string[])[]): Entries {
115+
if (referenceFieldUid.length) {
116+
referenceFieldUid.forEach(value => {
117+
if (!Array.isArray(this._queryParams['include[]'])) {
118+
this._queryParams['include[]'] = [];
119+
}
120+
(this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value]));
121+
});
122+
} else {
123+
console.error("Argument should be a String or an Array.");
124+
}
117125
return this;
118126
}
119127

src/lib/entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class Entry {
88
private _contentTypeUid: string;
99
private _entryUid: string;
1010
private _urlPath: string;
11-
_queryParams: { [key: string]: string | number } = {};
11+
_queryParams: { [key: string]: string | number | string[] } = {};
1212

1313
constructor(client: AxiosInstance, contentTypeUid: string, entryUid: string) {
1414
this._client = client;

src/lib/internal-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export type params = {
33
}
44

55
export type queryParams = {
6-
[key: string]: string | boolean | number
6+
[key: string]: string | boolean | number | string[]
77
}

test/unit/entries.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ describe('Entries class', () => {
3535
it('should set the include parameter to the given reference field UID', () => {
3636
const referenceFieldUid = 'referenceFieldUid';
3737
entry.includeReference(referenceFieldUid);
38+
expect(entry._queryParams['include[]']).toContain(referenceFieldUid);
39+
});
3840

39-
expect(entry._queryParams['include[]']).toBe(referenceFieldUid);
40-
});
4141

4242
it('should add "include_fallback" in _queryParams when includeFallback method is called', () => {
4343
const returnedValue = entry.includeFallback();

0 commit comments

Comments
 (0)