Skip to content

Commit

Permalink
onlyavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 12, 2023
1 parent e04128c commit 5edfd7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/meteor/app/livechat/imports/server/rest/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ API.v1.addRoute(
return API.v1.unauthorized();
}

const { onlyAvailable } = this.queryParams;
return API.v1.success(
await findAgents({
text,
onlyAvailable,
pagination: {
offset,
count,
Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/app/livechat/server/api/lib/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { escapeRegExp } from '@rocket.chat/string-helpers';
async function findUsers({
role,
text,
onlyAvailable = false,
pagination: { offset, count, sort },
}: {
role: IRole['_id'];
text?: string;
onlyAvailable?: boolean;
pagination: { offset: number; count: number; sort: any };
}): Promise<{ users: ILivechatAgent[]; count: number; offset: number; total: number }> {
const query = {};
Expand All @@ -24,6 +26,12 @@ async function findUsers({
});
}

if (onlyAvailable) {
Object.assign(query, {
statusLivechat: 'available',
});
}

const [
{
sortedResults,
Expand Down Expand Up @@ -52,14 +60,17 @@ async function findUsers({
}
export async function findAgents({
text,
onlyAvailable = false,
pagination: { offset, count, sort },
}: {
text?: string;
onlyAvailable: boolean;
pagination: { offset: number; count: number; sort: any };
}): Promise<ReturnType<typeof findUsers>> {
return findUsers({
role: 'livechat-agent',
text,
onlyAvailable,
pagination: {
offset,
count,
Expand Down
8 changes: 6 additions & 2 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ const LivechatDepartmentsByUnitIdSchema = {

export const isLivechatDepartmentsByUnitIdProps = ajv.compile<LivechatDepartmentsByUnitIdProps>(LivechatDepartmentsByUnitIdSchema);

type LivechatUsersManagerGETProps = PaginatedRequest<{ text?: string; fields?: string }>;
type LivechatUsersManagerGETProps = PaginatedRequest<{ text?: string; fields?: string; onlyAvailable?: boolean }>;

const LivechatUsersManagerGETSchema = {
type: 'object',
Expand All @@ -758,6 +758,10 @@ const LivechatUsersManagerGETSchema = {
type: 'string',
nullable: true,
},
onlyAvailable: {
type: 'string',
nullable: true,
},
count: {
type: 'number',
nullable: true,
Expand Down Expand Up @@ -3386,7 +3390,7 @@ export type OmnichannelEndpoints = {
};

'/v1/livechat/users/agent': {
GET: (params: PaginatedRequest<{ text?: string }>) => PaginatedResult<{
GET: (params: PaginatedRequest<{ text?: string; onlyAvailable?: boolean }>) => PaginatedResult<{
users: (ILivechatAgent & { departments: string[] })[];
}>;
POST: (params: LivechatUsersManagerPOSTProps) => { success: boolean };
Expand Down

0 comments on commit 5edfd7d

Please sign in to comment.