Skip to content

Commit

Permalink
Merge pull request #51 from contentstack/next
Browse files Browse the repository at this point in the history
Added array of values in includereference method
  • Loading branch information
cs-raj authored Sep 12, 2024
2 parents d88e24f + c0bc3f7 commit 018aa4e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change log

### Version: 4.3.0
#### Date: Septmber-09-2024
Feat: Include refernce accepts array of values

### Version: 4.2.0
#### Date: Septmber-04-2024
Feat: Variants support added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.2.0",
"version": "4.3.0",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/types/src/index.d.ts",
Expand Down
14 changes: 11 additions & 3 deletions src/lib/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ export class Entries extends EntryQueryable {
* @param {string} referenceFieldUid - UID of the reference field to include.
* @returns {Entries} - Returns the Entries instance for chaining.
*/
includeReference(referenceFieldUid: string): Entries {
this._queryParams['include[]'] = referenceFieldUid;

includeReference(...referenceFieldUid: (string | string[])[]): Entries {
if (referenceFieldUid.length) {
referenceFieldUid.forEach(value => {
if (!Array.isArray(this._queryParams['include[]'])) {
this._queryParams['include[]'] = [];
}
(this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value]));
});
} else {
console.error("Argument should be a String or an Array.");
}
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Entry {
private _contentTypeUid: string;
private _entryUid: string;
private _urlPath: string;
_queryParams: { [key: string]: string | number } = {};
_queryParams: { [key: string]: string | number | string[] } = {};

constructor(client: AxiosInstance, contentTypeUid: string, entryUid: string) {
this._client = client;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/internal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export type params = {
}

export type queryParams = {
[key: string]: string | boolean | number
[key: string]: string | boolean | number | string[]
}
4 changes: 2 additions & 2 deletions test/unit/entries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ describe('Entries class', () => {
it('should set the include parameter to the given reference field UID', () => {
const referenceFieldUid = 'referenceFieldUid';
entry.includeReference(referenceFieldUid);
expect(entry._queryParams['include[]']).toContain(referenceFieldUid);
});

expect(entry._queryParams['include[]']).toBe(referenceFieldUid);
});

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

0 comments on commit 018aa4e

Please sign in to comment.