Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Error when updating omnichannel department without agents parameter #18428

Merged
merged 2 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/livechat/server/lib/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ export const updateDepartmentAgents = (departmentId, agents) => {
}

upsert.forEach((agent) => {
if (!Users.findOneById(agent.agentId, { fields: { _id: 1 } })) {
return;
}

LivechatDepartmentAgents.saveAgent({
agentId: agent.agentId,
departmentId,
Expand All @@ -400,4 +404,6 @@ export const updateDepartmentAgents = (departmentId, agents) => {
const numAgents = LivechatDepartmentAgents.find({ departmentId }).count();
LivechatDepartment.updateNumAgentsById(departmentId, numAgents);
}

return true;
};
13 changes: 6 additions & 7 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,31 +813,30 @@ export const Livechat = {
saveDepartmentAgents(_id, departmentAgents) {
check(_id, String);
check(departmentAgents, {
upsert: [
upsert: Match.Maybe([
Match.ObjectIncluding({
agentId: String,
username: String,
count: Match.Maybe(Match.Integer),
order: Match.Maybe(Match.Integer),
}),
],
remove: [
]),
remove: Match.Maybe([
Match.ObjectIncluding({
agentId: String,
username: Match.Maybe(String),
count: Match.Maybe(Match.Integer),
order: Match.Maybe(Match.Integer),
}),
],
]),
});

const department = LivechatDepartment.findOneById(_id);
if (!department) {
throw new Meteor.Error('error-department-not-found', 'Department not found', { method: 'livechat:saveDepartmentAgents' });
}

const departmentDB = LivechatDepartment.createOrUpdateDepartment(_id, department);
return departmentDB && updateDepartmentAgents(departmentDB._id, departmentAgents);
return updateDepartmentAgents(_id, departmentAgents);
},

saveDepartment(_id, departmentData, departmentAgents) {
Expand Down Expand Up @@ -880,7 +879,7 @@ export const Livechat = {
}

const departmentDB = LivechatDepartment.createOrUpdateDepartment(_id, departmentData);
if (departmentDB) {
if (departmentDB && departmentAgents) {
updateDepartmentAgents(departmentDB._id, departmentAgents);
}

Expand Down