fix: remove empty custom fields

pull/15840/head
Anton Kazarinov 6 years ago
parent 293f7d32a0
commit 9e7705a1cd
  1. 10
      app/livechat/server/lib/Livechat.js
  2. 9
      app/models/server/models/LivechatRooms.js
  3. 7
      app/models/server/models/LivechatVisitors.js

@ -296,10 +296,7 @@ export const Livechat = {
return;
}
const value = s.trim(livechatData[field._id]);
if (value === '') {
return;
}
if (field.regexp !== undefined && field.regexp !== '') {
if (value !== '' && field.regexp !== undefined && field.regexp !== '') {
const regexp = new RegExp(field.regexp);
if (!regexp.test(value)) {
throw new Meteor.Error(TAPi18n.__('error-invalid-custom-field-value', { field: field.label }));
@ -450,10 +447,7 @@ export const Livechat = {
return;
}
const value = s.trim(livechatData[field._id]);
if (value === '') {
return;
}
if (field.regexp !== undefined && field.regexp !== '') {
if (value !== '' && field.regexp !== undefined && field.regexp !== '') {
const regexp = new RegExp(field.regexp);
if (!regexp.test(value)) {
throw new Meteor.Error(TAPi18n.__('error-invalid-custom-field-value', { field: field.label }));

@ -86,9 +86,14 @@ export class LivechatRooms extends Base {
unsetData.tags = 1;
}
if (livechatData != null) {
if (livechatData) {
Object.keys(livechatData).forEach((key) => {
setData[`livechatData.${ key }`] = s.trim(livechatData[key]);
const value = s.trim(livechatData[key]);
if (value) {
setData[`livechatData.${ key }`] = value;
} else {
unsetData[`livechatData.${ key }`] = 1;
}
});
}

@ -162,7 +162,12 @@ export class LivechatVisitors extends Base {
if (data.livechatData) {
Object.keys(data.livechatData).forEach((key) => {
setData[`livechatData.${ key }`] = s.trim(data.livechatData[key]);
const value = s.trim(data.livechatData[key]);
if (value) {
setData[`livechatData.${ key }`] = value;
} else {
unsetData[`livechatData.${ key }`] = 1;
}
});
}

Loading…
Cancel
Save