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

fix: Dept w/o any BH do not adhere to the default BH rules. (#29549)

parent 7f78a294
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
"@rocket.chat/model-typings": patch
---
fix: Dept w/o any BH config do not adhere to the default BH rules.
......@@ -21,9 +21,31 @@ const getAllAgentIdsWithoutDepartment = async (): Promise<string[]> => {
return agentIdsWithoutDepartment;
};
const getAllAgentIdsWithDepartmentNotConnectedToBusinessHour = async (): Promise<string[]> => {
const activeDepartmentsWithoutBusinessHour = (
await LivechatDepartment.findActiveDepartmentsWithoutBusinessHour({
projection: { _id: 1 },
}).toArray()
).map((dept) => dept._id);
const agentIdsWithDepartmentNotConnectedToBusinessHour = await LivechatDepartmentAgents.findAllAgentsConnectedToListOfDepartments(
activeDepartmentsWithoutBusinessHour,
);
return agentIdsWithDepartmentNotConnectedToBusinessHour;
};
const getAllAgentIdsForDefaultBusinessHour = async (): Promise<string[]> => {
const [withoutDepartment, withDepartmentNotConnectedToBusinessHour] = await Promise.all([
getAllAgentIdsWithoutDepartment(),
getAllAgentIdsWithDepartmentNotConnectedToBusinessHour(),
]);
return [...new Set([...withoutDepartment, ...withDepartmentNotConnectedToBusinessHour])];
};
const getAgentIdsToHandle = async (businessHour: Record<string, any>): Promise<string[]> => {
if (businessHour.type === LivechatBusinessHourTypes.DEFAULT) {
return getAllAgentIdsWithoutDepartment();
return getAllAgentIdsForDefaultBusinessHour();
}
const departmentIds = (
await LivechatDepartment.findEnabledByBusinessHourId(businessHour._id, {
......
......@@ -128,6 +128,14 @@ export class LivechatDepartmentRaw extends BaseRaw<ILivechatDepartment> implemen
return this.find(query, options);
}
findActiveDepartmentsWithoutBusinessHour(options: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment> {
const query = {
enabled: true,
businessHourId: { $exists: false },
};
return this.find(query, options);
}
findEnabledByListOfBusinessHourIdsAndDepartmentIds(
businessHourIds: string[],
departmentIds: string[],
......
......@@ -356,6 +356,10 @@ export class LivechatDepartmentAgentsRaw extends BaseRaw<ILivechatDepartmentAgen
countByDepartmentId(departmentId: string): Promise<number> {
return this.col.countDocuments({ departmentId });
}
findAllAgentsConnectedToListOfDepartments(departmentIds: string[]): Promise<string[]> {
return this.col.distinct('agentId', { departmentId: { $in: departmentIds } });
}
}
const isStringValue = (value: any): value is string => typeof value === 'string';
......@@ -87,4 +87,5 @@ export interface ILivechatDepartmentAgentsModel extends IBaseModel<ILivechatDepa
getNextBotForDepartment(departmentId: string, ignoreAgentId?: string): Promise<{ agentId: string; username: string } | undefined>;
replaceUsernameOfAgentByUserId(userId: string, username: string): Promise<UpdateResult | Document>;
countByDepartmentId(departmentId: string): Promise<number>;
findAllAgentsConnectedToListOfDepartments(departmentIds: string[]): Promise<string[]>;
}
......@@ -23,6 +23,8 @@ export interface ILivechatDepartmentModel extends IBaseModel<ILivechatDepartment
options: FindOptions<ILivechatDepartment>,
): FindCursor<ILivechatDepartment>;
findActiveDepartmentsWithoutBusinessHour(options: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment>;
addBusinessHourToDepartmentsByIds(ids: string[], businessHourId: string): Promise<Document | UpdateResult>;
removeBusinessHourFromDepartmentsByIdsAndBusinessHourId(ids: string[], businessHourId: string): Promise<Document | UpdateResult>;
......
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