Skip to content
Snippets Groups Projects
Unverified Commit dc549a50 authored by Martin Schoeler's avatar Martin Schoeler Committed by GitHub
Browse files

[IMPROVE] Add agentId parameter to changeLivechatStatus method (#18571)


* Add agentId parameter to changeLivechatStatus method

* Fix reviews

* fix problems

* return if the same as before

* Update app/livechat/server/methods/changeLivechatStatus.js

Co-authored-by: default avatarRenato Becker <renato.augusto.becker@gmail.com>

* Fix review

Co-authored-by: default avatarGuilherme Gazzo <guilhermegazzo@gmail.com>
Co-authored-by: default avatarRenato Becker <renato.augusto.becker@gmail.com>
Co-authored-by: default avatarGuilherme Gazzo <guilherme@gazzo.xyz>
parent fdda1426
No related merge requests found
import { Meteor } from 'meteor/meteor';
import { Livechat } from '../lib/Livechat';
import { hasPermission } from '../../../authorization';
import Users from '../../../models/server/models/Users';
Meteor.methods({
'livechat:changeLivechatStatus'() {
if (!Meteor.userId()) {
'livechat:changeLivechatStatus'({ status, agentId = Meteor.userId() } = {}) {
const uid = Meteor.userId();
if (!uid || !agentId) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:changeLivechatStatus' });
}
const user = Meteor.user();
const agent = Users.findOneAgentById(agentId, {
fields: {
status: 1,
statusLivechat: 1,
},
});
if (!agent) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveAgentInfo' });
}
const newStatus = status || (agent.statusLivechat === 'available' ? 'not-available' : 'available');
if (newStatus === agent.statusLivechat) {
return;
}
if (agentId !== uid) {
if (!hasPermission(uid, 'manage-livechat-agents')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveAgentInfo' });
}
return Livechat.setUserStatusLivechat(agentId, newStatus);
}
const newStatus = user.statusLivechat === 'available' ? 'not-available' : 'available';
if (!Livechat.allowAgentChangeServiceStatus(newStatus, user._id)) {
if (!Livechat.allowAgentChangeServiceStatus(newStatus, agentId)) {
throw new Meteor.Error('error-business-hours-are-closed', 'Not allowed', { method: 'livechat:changeLivechatStatus' });
}
return Livechat.setUserStatusLivechat(user._id, newStatus);
return Livechat.setUserStatusLivechat(agentId, newStatus);
},
});
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