Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit d51dfbb

Browse files
authored
feat(sdk): add count method
Added a method to get count of users
2 parents dc4e560 + 4b70df2 commit d51dfbb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/lib/sdk.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ test('Create an instance', t => {
3131
'getProviderAuthenticationUrl',
3232
'authenticateProvider',
3333
'getEntries',
34+
'getEntryCount',
3435
'getEntry',
3536
'createEntry',
3637
'updateEntry',
@@ -349,6 +350,22 @@ test('Get entries', async t => {
349350
);
350351
});
351352

353+
test('Get entry count', async t => {
354+
await t.context.strapi.getEntryCount('user', {
355+
name_contains: 'jack'
356+
});
357+
358+
t.true(
359+
t.context.axiosRequest.calledWithExactly({
360+
method: 'get',
361+
params: {
362+
name_contains: 'jack'
363+
},
364+
url: '/user/count'
365+
})
366+
);
367+
});
368+
352369
test('Get entry', async t => {
353370
await t.context.strapi.getEntry('user', 'ID');
354371

src/lib/sdk.ts

+14
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ export default class Strapi {
241241
});
242242
}
243243

244+
/**
245+
* Get the total count of entries with the provided criteria
246+
* @param contentType
247+
* @param params Filter and order queries.
248+
*/
249+
public getEntryCount(
250+
contentType: string,
251+
params?: AxiosRequestConfig['params']
252+
): Promise<object[]> {
253+
return this.request('get', `/${contentType}/count`, {
254+
params
255+
});
256+
}
257+
244258
/**
245259
* Get a specific entry
246260
* @param contentType Type of entry

0 commit comments

Comments
 (0)