Skip to content

Commit 7a0d4cc

Browse files
Merge branch 'v4-beta/next' of github.com:contentstack/contentstack-javascript into v4-beta/next
2 parents 748808a + 080df94 commit 7a0d4cc

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/lib/query.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,22 @@ export class Query extends BaseQuery {
200200
this._parameters[key] = { '$nin': value };
201201
return this;
202202
}
203+
204+
/**
205+
* @method notExists
206+
* @memberof Query
207+
* @description Returns the raw (JSON) query based on the filters applied on Query object.
208+
* @example
209+
* import contentstack from '@contentstack/delivery-sdk'
210+
*
211+
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
212+
* const query = stack.contentType("contentTypeUid").Query();
213+
* const result = notExists('fieldUid').find()
214+
*
215+
* @returns {Query}
216+
*/
217+
notExists(key: string): Query {
218+
this._parameters[key] = { '$exists': false };
219+
return this;
220+
}
203221
}

test/api/contenttype.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ describe('ContentType Query API test cases', () => {
4646
expect(query.entries[0].created_at).toBeDefined();
4747
}
4848
});
49+
50+
it('should get entries which does not match the fieldUid - notExists', async () => {
51+
const query = await makeContentType('contenttype_uid').Query().notExists('multi_line').find<TEntry>()
52+
if (query.entries) {
53+
expect(query.entries[0]._version).toBeDefined();
54+
expect(query.entries[0].title).toBeDefined();
55+
expect(query.entries[0].uid).toBeDefined();
56+
expect(query.entries[0].created_at).toBeDefined();
57+
expect((query.entries[0] as any).multi_line).not.toBeDefined()
58+
}
59+
});
4960
});
5061
function makeContentType(uid = ''): ContentType {
5162
const contentType = stack.ContentType(uid);

test/unit/contenttype.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ describe('ContentType Query class', () => {
5858
});
5959
it('should get entries which matches the fieldUid and values', () => {
6060
const query = contentType.Query().containedIn('fieldUID', ['value']);
61-
expect(query._queryParams).toStrictEqual({'fieldUID': {'$in': ['value']}});
61+
expect(query._parameters).toStrictEqual({'fieldUID': {'$in': ['value']}});
6262
});
6363
it('should get entries which does not match the fieldUid and values', () => {
6464
const query = contentType.Query().notContainedIn('fieldUID', ['value', 'value2']);
65-
expect(query._queryParams).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}});
65+
expect(query._parameters).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}});
66+
});
67+
it('should get entries which does not match the fieldUid - notExists', () => {
68+
const query = contentType.Query().notExists('fieldUID');
69+
expect(query._parameters).toStrictEqual({'fieldUID': {'$exists': false}});
6670
});
6771
});

0 commit comments

Comments
 (0)