Skip to content
Snippets Groups Projects
Unverified Commit d860c348 authored by Murtaza Patrawala's avatar Murtaza Patrawala Committed by GitHub
Browse files

Regression: Empty custom-fields filter on Current Chats causing issues (#26720)

parent 1599a22a
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ API.v1.addRoute(
'livechat/rooms',
{ authRequired: true },
{
get() {
async get() {
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
const { agents, departmentId, open, tags, roomName, onhold } = this.requestParams();
......@@ -32,6 +32,7 @@ API.v1.addRoute(
check(open, Match.Maybe(String));
check(onhold, Match.Maybe(String));
check(tags, Match.Maybe([String]));
check(customFields, Match.Maybe(String));
createdAt = validateDateParams('createdAt', createdAt);
closedAt = validateDateParams('closedAt', closedAt);
......@@ -43,24 +44,29 @@ API.v1.addRoute(
}
if (customFields) {
customFields = JSON.parse(customFields);
try {
const parsedCustomFields = JSON.parse(customFields);
check(parsedCustomFields, Object);
// Model's already checking for the keys, so we don't need to do it here.
customFields = parsedCustomFields;
} catch (e) {
throw new Error('The "customFields" query parameter must be a valid JSON.');
}
}
return API.v1.success(
Promise.await(
findRooms({
agents,
roomName,
departmentId,
open: open && open === 'true',
createdAt,
closedAt,
tags,
customFields,
onhold,
options: { offset, count, sort, fields },
}),
),
await findRooms({
agents,
roomName,
departmentId,
open: open && open === 'true',
createdAt,
closedAt,
tags,
customFields,
onhold,
options: { offset, count, sort, fields },
}),
);
},
},
......
......@@ -1057,7 +1057,7 @@ export class LivechatRoomsRaw extends BaseRaw {
if (tags) {
query.tags = { $in: tags };
}
if (customFields) {
if (customFields && Object.keys(customFields).length) {
query.$and = Object.keys(customFields).map((key) => ({
[`livechatData.${key}`]: new RegExp(customFields[key], 'i'),
}));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment