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

pull/29612/head^2
Murtaza Patrawala 3 years ago committed by GitHub
parent 7f78a29469
commit ee5993625b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .changeset/little-ligers-hug.md
  2. 24
      apps/meteor/ee/app/livechat-enterprise/server/business-hour/Helper.ts
  3. 8
      apps/meteor/server/models/raw/LivechatDepartment.ts
  4. 4
      apps/meteor/server/models/raw/LivechatDepartmentAgents.ts
  5. 1
      packages/model-typings/src/models/ILivechatDepartmentAgentsModel.ts
  6. 2
      packages/model-typings/src/models/ILivechatDepartmentModel.ts

@ -0,0 +1,6 @@
---
"@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>;

Loading…
Cancel
Save