Skip to content

Commit fbf0d7a

Browse files
Merge pull request #147 from contentstack/feat/cs-43911-notContainedInd-implementation
Feat/cs 43911 not contained ind implementation
2 parents fd5ace8 + c2a4dcd commit fbf0d7a

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

CHANGELOG.md

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

3+
### Version: 4.0.0-beta.4
4+
#### Date: March-04-2024
5+
##### New Features:
6+
- Query implementation for containedIn and notContainedIn
7+
8+
### Version: 4.0.0-beta.3
9+
#### Date: February-13-2024
10+
- Live preview support 1.0 and 2.0
11+
12+
### Version: v4.0.0-beta.2
13+
#### Date: February-02-2024
14+
- Includes adding of prepare script to build package
15+
316
### Version: 4.0.0-beta
417
#### Date: January-15-2024
518
- Beta release of Typescript SDK

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.0.0-beta.3",
3+
"version": "4.0.0-beta.4",
44
"type": "commonjs",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/types/src/index.d.ts",

src/lib/query.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseQuery } from './base-query';
33
import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation } from './types';
44
export class Query extends BaseQuery {
55
private _contentTypeUid?: string;
6-
override _queryParams: { [key: string]: any} = {};
6+
77
constructor(client: AxiosInstance, uid: string, queryObj?: { [key: string]: any }) {
88
super();
99
this._client = client;
@@ -173,13 +173,31 @@ export class Query extends BaseQuery {
173173
* import contentstack from '@contentstack/delivery-sdk'
174174
*
175175
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
176-
* const query = stack.contentType("contentTypeUid").Query;
176+
* const query = stack.contentType("contentTypeUid").Query();
177177
* const result = containedIn('fieldUid', ['value1', 'value2']).find()
178178
*
179179
* @returns {Query}
180180
*/
181181
containedIn(key: string, value: (string | number | boolean)[]): Query {
182-
this._queryParams[key] = value;
182+
this._parameters[key] = { '$in': value };
183+
return this;
184+
}
185+
186+
/**
187+
* @method NoContainedIn
188+
* @memberof Query
189+
* @description Returns the raw (JSON) query based on the filters applied on Query object.
190+
* @example
191+
* import contentstack from '@contentstack/delivery-sdk'
192+
*
193+
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
194+
* const query = stack.contentType("contentTypeUid").Query();
195+
* const result = notContainedIn('fieldUid', ['value1', 'value2']).find()
196+
*
197+
* @returns {Query}
198+
*/
199+
notContainedIn(key: string, value: (string | number | boolean)[]): Query {
200+
this._parameters[key] = { '$nin': value };
183201
return this;
184202
}
185203
}

test/api/contenttype.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { BaseContentType, BaseEntry, FindResponse } from 'src';
44
import { ContentType } from '../../src/lib/content-type';
55
import { stackInstance } from '../utils/stack-instance';
6-
import { TContentType, TEntry } from './types';
6+
import { TContentType, TEntries, TEntry } from './types';
77
import dotenv from 'dotenv';
88

99
dotenv.config()
@@ -27,7 +27,7 @@ describe('ContentType API test cases', () => {
2727
});
2828
});
2929
describe('ContentType Query API test cases', () => {
30-
it('should test for contained In', async () => {
30+
it('should get entries which matches the fieldUid and values', async () => {
3131
const query = await makeContentType('contenttype_uid').Query().containedIn('title', ['value']).find<TEntry>()
3232
if (query.entries) {
3333
expect(query.entries[0]._version).toBeDefined();
@@ -36,6 +36,16 @@ describe('ContentType Query API test cases', () => {
3636
expect(query.entries[0].created_at).toBeDefined();
3737
}
3838
});
39+
40+
it('should get entries which does not match the fieldUid and values', async () => {
41+
const query = await makeContentType('contenttype_uid').Query().notContainedIn('title', ['test', 'test2']).find<TEntry>()
42+
if (query.entries) {
43+
expect(query.entries[0]._version).toBeDefined();
44+
expect(query.entries[0].title).toBeDefined();
45+
expect(query.entries[0].uid).toBeDefined();
46+
expect(query.entries[0].created_at).toBeDefined();
47+
}
48+
});
3949
});
4050
function makeContentType(uid = ''): ContentType {
4151
const contentType = stack.ContentType(uid);

test/unit/contenttype.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ describe('ContentType Query class', () => {
5656
beforeEach(() => {
5757
contentType = new ContentType(client, 'contentTypeUid');
5858
});
59-
it('should test for contained In', () => {
59+
it('should get entries which matches the fieldUid and values', () => {
6060
const query = contentType.Query().containedIn('fieldUID', ['value']);
61-
expect(query._queryParams).toStrictEqual({'fieldUID': ['value']});
61+
expect(query._queryParams).toStrictEqual({'fieldUID': {'$in': ['value']}});
62+
});
63+
it('should get entries which does not match the fieldUid and values', () => {
64+
const query = contentType.Query().notContainedIn('fieldUID', ['value', 'value2']);
65+
expect(query._queryParams).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}});
6266
});
6367
});

0 commit comments

Comments
 (0)