Skip to content

Commit 4c351e1

Browse files
Merge pull request #161 from contentstack/feat/cs-43921-search-query-operator
Feat/cs 43921 search query operator
2 parents b5b1366 + 3fdc3e8 commit 4c351e1

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

package-lock.json

Lines changed: 7 additions & 7 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
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"@contentstack/core": "^1.0.1",
27-
"@contentstack/utils": "^1.3.1",
27+
"@contentstack/utils": "^1.3.3",
2828
"@types/humps": "^2.0.6",
2929
"dotenv": "^16.3.1",
3030
"humps": "^2.0.1"

src/lib/query.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export class Query extends BaseQuery {
295295
*
296296
* @returns {Query}
297297
*/
298-
referenceIn(key: string, query: Query) {
298+
referenceIn(key: string, query: Query): Query {
299299
this._parameters[key] = { '$in_query': query._parameters }
300300
return this;
301301
}
@@ -313,7 +313,7 @@ export class Query extends BaseQuery {
313313
*
314314
* @returns {Query}
315315
*/
316-
referenceNotIn(key: string, query: Query) {
316+
referenceNotIn(key: string, query: Query): Query {
317317
this._parameters[key] = { '$nin_query': query._parameters }
318318
return this;
319319
}
@@ -335,4 +335,8 @@ export class Query extends BaseQuery {
335335
this._parameters['tags'] = values;
336336
return this;
337337
}
338+
search(key: string): Query {
339+
this._queryParams['typeahead'] = key
340+
return this
341+
}
338342
}

test/api/entry-queryables.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ describe('Query Operators API test cases', () => {
142142
expect(query.entries[0].title).toBe('value');
143143
}
144144
});
145+
146+
it('should search for the matching key and return the entry', async () => {
147+
const query = await makeEntries('contenttype_uid').query().search('value2').find<TEntry>();
148+
if (query.entries) {
149+
expect(query.entries[0]._version).toBeDefined();
150+
expect(query.entries[0].locale).toBeDefined();
151+
expect(query.entries[0].uid).toBeDefined();
152+
expect(query.entries[0].title).toBe('value2');
153+
}
154+
});
145155
});
146156

147157
function makeEntries(contentTypeUid = ''): Entries {

test/unit/entry-queryable.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,10 @@ describe('Query Operators API test cases', () => {
6767
expect(query._parameters).toEqual({ tags: ['tag1'] });
6868
}
6969
});
70+
it('should search for the matching key and return the entry', async () => {
71+
const query = contentType.Entry().query().search('entry');
72+
if (query) {
73+
expect(query._queryParams).toEqual({ typeahead: 'entry' });
74+
}
75+
});
7076
});

0 commit comments

Comments
 (0)