Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / components / interaction / utils.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x14e5=['capitalize','chat','Website','InteractionId','upperFirst','unknown','websites','_interactions','_interaction_has_tags','_messages','user_has_','isArray','toUpperCase','name','role','stringify','null','Interaction','then','info','exports','../../config/logger','openchannel-interactions','mail-interactions','sms-interactions','chat-interactions','whatsapp-interactions'];(function(_0x327352,_0x2dbf17){var _0x58e9ba=function(_0x3eb94b){while(--_0x3eb94b){_0x327352['push'](_0x327352['shift']());}};_0x58e9ba(++_0x2dbf17);}(_0x14e5,0x174));var _0x514e=function(_0x32bb6b,_0x1a5fbe){_0x32bb6b=_0x32bb6b-0x0;var _0x58dcb4=_0x14e5[_0x32bb6b];return _0x58dcb4;};'use strict';var _=require('lodash');var db=require('../../mysqldb')['db'];var loggers={'openchannel':require(_0x514e('0x0'))(_0x514e('0x1')),'mail':require(_0x514e('0x0'))(_0x514e('0x2')),'fax':require('../../config/logger')('fax-interactions'),'sms':require(_0x514e('0x0'))(_0x514e('0x3')),'chat':require('../../config/logger')(_0x514e('0x4')),'whatsapp':require(_0x514e('0x0'))(_0x514e('0x5'))};function getAccountFK(_0x1b4b5c){return _[_0x514e('0x6')](_0x1b4b5c)+(_0x1b4b5c===_0x514e('0x7')?_0x514e('0x8'):'Account')+'Id';}function getInteractionFK(_0x16fb21){return _[_0x514e('0x6')](_0x16fb21)+_0x514e('0x9');}function getInteractionId(_0x2edaca,_0xd90a59,_0x452265){if(_0x2edaca&&_0x2edaca[_[_0x514e('0xa')](_0x452265)+'InteractionId']){return _0x2edaca[_[_0x514e('0xa')](_0x452265)+_0x514e('0x9')];}else if(_0x2edaca&&_0x2edaca['id']){return _0x2edaca['id'];}else if(_0xd90a59&&_0xd90a59['id']){return _0xd90a59['id'];}else{return _0x514e('0xb');}}function getInteractionsTables(_0x5f7140){return{'accounts':_0x5f7140+'_'+(_0x5f7140===_0x514e('0x7')?_0x514e('0xc'):'accounts'),'interactions':_0x5f7140+_0x514e('0xd'),'interactionsTags':_0x5f7140+_0x514e('0xe'),'messages':_0x5f7140+_0x514e('0xf'),'userInteractions':_0x514e('0x10')+_0x5f7140+_0x514e('0xd')};}function getSelectedTags(_0x5f440){var _0x2a5f64=[];if(_0x5f440){_0x2a5f64=Array[_0x514e('0x11')](_0x5f440)?_0x5f440:[_0x5f440];}return _0x2a5f64;}function log(_0x3bd4a6,_0x3d4f98,_0x235e2b,_0x23f6a,_0x5b529f,_0x7fc8e2){loggers[_0x5b529f['toLowerCase']()][_0x3bd4a6]('[%s]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x7fc8e2[_0x514e('0x12')](),_0x3d4f98?_0x3d4f98['id']:null,_0x3d4f98?_0x3d4f98[_0x514e('0x13')]:null,_0x3d4f98?_0x3d4f98[_0x514e('0x14')]:null,getInteractionId(_0x235e2b,_0x23f6a,_0x5b529f),_0x235e2b?JSON[_0x514e('0x15')](_0x235e2b):_0x514e('0x16'));}function updateUser(_0x32d4ef,_0x1847bb,_0x279391,_0x4892d5,_0xa69a1c){db[_[_0x514e('0xa')](_0x4892d5)+_0x514e('0x17')]['findOne']({'where':{'id':getInteractionId(_0x1847bb,_0x279391,_0x4892d5)}})['then'](function(_0x1b9464){if(_0x1b9464){return _0x1b9464['update']({'UserId':_0x32d4ef?_0x32d4ef['id']:null});}})[_0x514e('0x18')](function(_0x1314d1){if(_0x1314d1){log(_0x514e('0x19'),_0x32d4ef,_0x1847bb,_0x279391,_0x4892d5,_0xa69a1c);}})['catch'](function(){log('error',_0x32d4ef,_0x1847bb,_0x279391,_0x4892d5,_0xa69a1c);});}module[_0x514e('0x1a')]={'getAccountFK':getAccountFK,'getInteractionFK':getInteractionFK,'getInteractionsTables':getInteractionsTables,'getSelectedTags':getSelectedTags,'updateUser':updateUser};