From e6b5a089f1f90254e275f5d7d1e3d596530589e9 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 11 Oct 2023 12:42:39 -0600 Subject: [PATCH 1/2] paginate --- apps/meteor/app/api/server/lib/users.ts | 7 ++++++- apps/meteor/app/api/server/v1/users.ts | 3 +++ .../src/v1/users/UsersAutocompleteParamsGET.ts | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/api/server/lib/users.ts b/apps/meteor/app/api/server/lib/users.ts index 990fda0a0209..798e398f38d9 100644 --- a/apps/meteor/app/api/server/lib/users.ts +++ b/apps/meteor/app/api/server/lib/users.ts @@ -12,9 +12,13 @@ type UserAutoComplete = Required['username'][]; conditions: Filter; term: string }; + offset: number; + count: number; }): Promise<{ items: UserAutoComplete[]; }> { @@ -32,7 +36,8 @@ export async function findUsersToAutocomplete({ sort: { username: 1, }, - limit: 10, + limit: count, + skip: offset, }; // Search on DMs first, to list known users before others. diff --git a/apps/meteor/app/api/server/v1/users.ts b/apps/meteor/app/api/server/v1/users.ts index b23d41255c3b..c550d6fcf155 100644 --- a/apps/meteor/app/api/server/v1/users.ts +++ b/apps/meteor/app/api/server/v1/users.ts @@ -965,6 +965,7 @@ API.v1.addRoute( { async get() { const { selector: selectorRaw } = this.queryParams; + const { offset, count } = await getPaginationItems(this.queryParams); const selector: { exceptions: Required['username'][]; conditions: Filter; term: string } = JSON.parse(selectorRaw); @@ -980,6 +981,8 @@ API.v1.addRoute( await findUsersToAutocomplete({ uid: this.userId, selector, + offset, + count, }), ); }, diff --git a/packages/rest-typings/src/v1/users/UsersAutocompleteParamsGET.ts b/packages/rest-typings/src/v1/users/UsersAutocompleteParamsGET.ts index bdb6578db24d..82964fc015f6 100644 --- a/packages/rest-typings/src/v1/users/UsersAutocompleteParamsGET.ts +++ b/packages/rest-typings/src/v1/users/UsersAutocompleteParamsGET.ts @@ -1,10 +1,12 @@ import Ajv from 'ajv'; +import type { PaginatedRequest } from '../../helpers/PaginatedRequest'; + const ajv = new Ajv({ coerceTypes: true, }); -export type UsersAutocompleteParamsGET = { selector: string }; +export type UsersAutocompleteParamsGET = PaginatedRequest<{ selector: string }>; const UsersAutocompleteParamsGetSchema = { type: 'object', @@ -12,6 +14,18 @@ const UsersAutocompleteParamsGetSchema = { selector: { type: 'string', }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, }, required: ['selector'], additionalProperties: false, From 492967802ce5e82ef6df0893a5ad1c4f462176e6 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 11 Oct 2023 13:16:24 -0600 Subject: [PATCH 2/2] Create tidy-tables-eat.md --- .changeset/tidy-tables-eat.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/tidy-tables-eat.md diff --git a/.changeset/tidy-tables-eat.md b/.changeset/tidy-tables-eat.md new file mode 100644 index 000000000000..9db17b8be69e --- /dev/null +++ b/.changeset/tidy-tables-eat.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/rest-typings": patch +--- + +chore: Add pagination to `users.autocomplete` endpoint