|
|
|
@ -196,11 +196,11 @@ export class UsersRaw extends BaseRaw { |
|
|
|
|
return result.value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getAgentAndAmountOngoingChats(userId) { |
|
|
|
|
async getAgentAndAmountOngoingChats(userId, department) { |
|
|
|
|
const aggregate = [ |
|
|
|
|
{ $match: { _id: userId, status: { $exists: true, $ne: 'offline' }, statusLivechat: 'available', roles: 'livechat-agent' } }, |
|
|
|
|
{ $lookup: { from: 'rocketchat_subscription', localField: '_id', foreignField: 'u._id', as: 'subs' } }, |
|
|
|
|
{ $project: { agentId: '$_id', username: 1, lastAssignTime: 1, lastRoutingTime: 1, 'queueInfo.chats': { $size: { $filter: { input: '$subs', as: 'sub', cond: { $and: [{ $eq: ['$$sub.t', 'l'] }, { $eq: ['$$sub.open', true] }, { $ne: ['$$sub.onHold', true] }] } } } } } }, |
|
|
|
|
{ $project: { agentId: '$_id', username: 1, lastAssignTime: 1, lastRoutingTime: 1, 'queueInfo.chats': { $size: { $filter: { input: '$subs', as: 'sub', cond: { $and: [{ $eq: ['$$sub.t', 'l'] }, { $eq: ['$$sub.open', true] }, { $ne: ['$$sub.onHold', true] }, { ...department && { $eq: ['$$sub.department', department] } }] } } } } } }, |
|
|
|
|
{ $sort: { 'queueInfo.chats': 1, lastAssignTime: 1, lastRoutingTime: 1, username: 1 } }, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|