Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / cmContact / cmContact.controller.js
index 3fed0d6..93df52f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x202f=['bluebird','mustache','path','sox','to-csv','ejs','lodash','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../mysqldb','redis','localhost','socket.io-emitter','register','end','status','json','offset','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','index','describe','keys','length','startsWith','cf_','findOne','trimStart','fieldType','type','model','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','limit','sort','pick','select','field','color','from','tools_tags','cm_contacts','left_join','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','ct.CmContactId\x20=\x20c.id','t.id\x20=\x20ct.TagId','where','c.deletedAt\x20IS\x20NULL','expr','search','parseSearch','sqlOperator','conditions','find','Tag','value','split','map','forEach','User','and','datetime','castTo','DATE','text','start','filter','Contact','push','isEmpty','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','\x27\x27\x27\x27','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','c.id','Sequelize','QueryTypes','SELECT','clone','order','resolve','getLists','c.ListId\x20IS\x20NULL','sequelize','toString','count','CmContact','c.lastName','c.phone','c.mobile','c.fax','c.email','c.ListId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','rows','params','catch','tags','columnName','findAll','displayName','alias','custom','merge','body','get','mergeWith','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','create','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','OpenchannelInteraction','OpenchannelMessage','CmHopperFinal','CmHopperHistory','ReportAgentPreview','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','JscriptySessionReport','join','bulkCreate','each','duplicates','$or','findOrCreate','spread','show','$and','CmCustomField','omit','cf_%d','pickBy','format','table','setFields','id\x20=\x20?','values','rawAttributes','options','getTags','setTags','ids','getHoppers','ContactId','includeAll','include','getHopperFinals','getJscriptySessions','uploadCsv','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','Incorrect\x20binding\x20parameters\x20passed!','phone','No\x20phone\x20column\x20specified','root','server/files/tmp','file','filename','child_process','fork','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','send','upload','createReadStream','parse','meta','No\x20ListId\x20specified','binding','firstName','../../components/import/cm/csv2','stringify','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment'];(function(_0x230e8c,_0x3a1038){var _0x377068=function(_0x364402){while(--_0x364402){_0x230e8c['push'](_0x230e8c['shift']());}};_0x377068(++_0x3a1038);}(_0x202f,0xe7));var _0xf202=function(_0x40677e,_0x1684e6){_0x40677e=_0x40677e-0x0;var _0x2ac00e=_0x202f[_0x40677e];return _0x2ac00e;};'use strict';var pdf=require(_0xf202('0x0'));var emlformat=require(_0xf202('0x1'));var rimraf=require(_0xf202('0x2'));var zipdir=require(_0xf202('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf202('0x4'));var moment=require(_0xf202('0x5'));var BPromise=require(_0xf202('0x6'));var Mustache=require(_0xf202('0x7'));var util=require('util');var path=require(_0xf202('0x8'));var sox=require(_0xf202('0x9'));var csv=require(_0xf202('0xa'));var ejs=require(_0xf202('0xb'));var fs=require('fs');var _=require(_0xf202('0xc'));var squel=require('squel');var crypto=require(_0xf202('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xf202('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf202('0xf'));var Redis=require(_0xf202('0x10'));var authService=require(_0xf202('0x11'));var qs=require(_0xf202('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf202('0x13'));var logger=require(_0xf202('0x14'))(_0xf202('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0xf202('0x16'))['db'];config[_0xf202('0x17')]=_['defaults'](config[_0xf202('0x17')],{'host':_0xf202('0x18'),'port':0x18eb});var socket=require(_0xf202('0x19'))(new Redis(config['redis']));require('./cmContact.socket')[_0xf202('0x1a')](socket);function respondWithStatusCode(_0x3fe549,_0x1d91b7){_0x1d91b7=_0x1d91b7||0xcc;return function(_0x97a429){if(_0x97a429){return _0x3fe549['sendStatus'](_0x1d91b7);}return _0x3fe549['status'](_0x1d91b7)[_0xf202('0x1b')]();};}function respondWithResult(_0x3d5119,_0x3f29aa){_0x3f29aa=_0x3f29aa||0xc8;return function(_0x44b7b0){if(_0x44b7b0){return _0x3d5119[_0xf202('0x1c')](_0x3f29aa)[_0xf202('0x1d')](_0x44b7b0);}};}function respondWithFilteredResult(_0x4e9355,_0x448fc1){return function(_0x50fa3f){if(_0x50fa3f){var _0x1843fd=_0x50fa3f['count'],_0xf2a99b=_0x448fc1[_0xf202('0x1e')],_0x38bf17=_0x448fc1[_0xf202('0x1e')]+_0x448fc1['limit'],_0x5769ae;if(_0x38bf17>=_0x1843fd){_0x38bf17=_0x1843fd;_0x5769ae=0xc8;}else{_0x5769ae=0xce;}_0x4e9355[_0xf202('0x1c')](_0x5769ae);return _0x4e9355[_0xf202('0x1f')](_0xf202('0x20'),_0xf2a99b+'-'+_0x38bf17+'/'+_0x1843fd)[_0xf202('0x1d')](_0x50fa3f);}return null;};}function patchUpdates(_0x53a99b){return function(_0x30fb1b){try{jsonpatch[_0xf202('0x21')](_0x30fb1b,_0x53a99b,!![]);}catch(_0x445c2a){return BPromise[_0xf202('0x22')](_0x445c2a);}return _0x30fb1b[_0xf202('0x23')]();};}function saveUpdates(_0x387ce2,_0x4d3b46){return function(_0x5f19fe){if(_0x5f19fe){return _0x5f19fe[_0xf202('0x24')](_0x387ce2)[_0xf202('0x25')](function(_0xc6d116){return _0xc6d116;});}return null;};}function removeEntity(_0x198057,_0x2debda){return function(_0xd5a218){if(_0xd5a218){return _0xd5a218[_0xf202('0x26')]()[_0xf202('0x25')](function(){_0x198057[_0xf202('0x1c')](0xcc)[_0xf202('0x1b')]();});}};}function handleEntityNotFound(_0x20c9c7,_0x2394cd){return function(_0xa3f1f){if(!_0xa3f1f){_0x20c9c7[_0xf202('0x27')](0x194);}return _0xa3f1f;};}function handleError(_0x51d674,_0x1447f1){_0x1447f1=_0x1447f1||0x1f4;return function(_0x3d484d){logger[_0xf202('0x28')](_0x3d484d[_0xf202('0x29')]);if(_0x3d484d[_0xf202('0x2a')]){delete _0x3d484d[_0xf202('0x2a')];}_0x51d674['status'](_0x1447f1)['send'](_0x3d484d);};}exports[_0xf202('0x2b')]=function(_0x524998,_0x1be4f4){var _0x4c3f76={},_0xe19347={},_0x191054={'count':0x0,'rows':[]};return db['CmContact'][_0xf202('0x2c')]()[_0xf202('0x25')](function(_0x58d8c1){var _0x292b62=[];for(var _0x5b98f8=0x0;_0x5b98f8<Object[_0xf202('0x2d')](_0x58d8c1)[_0xf202('0x2e')];_0x5b98f8++){var _0x4bd990=Object['keys'](_0x58d8c1)[_0x5b98f8];if(_[_0xf202('0x2f')](_0x4bd990,_0xf202('0x30'))){_0x292b62['push'](db['CmCustomField'][_0xf202('0x31')]({'where':{'id':_[_0xf202('0x32')](_0x4bd990,_0xf202('0x30'))},'raw':!![]}));}}return BPromise['all'](_0x292b62)['then'](function(_0x49ceb2){for(var _0x4fbc42=0x0;_0x4fbc42<_0x49ceb2[_0xf202('0x2e')];_0x4fbc42++){if(_0x49ceb2[_0x4fbc42]){var _0x258bcd='cf_'+_0x49ceb2[_0x4fbc42]['id'];var _0x4ad345=_0x58d8c1[_0x258bcd];_0x4ad345[_0xf202('0x33')]=_0x49ceb2[_0x4fbc42][_0xf202('0x34')];}}return _0x58d8c1;});})[_0xf202('0x25')](function(_0x58bdfa){_0xe19347[_0xf202('0x35')]=_[_0xf202('0x2d')](_0x58bdfa);_0xe19347[_0xf202('0x36')]=_[_0xf202('0x2d')](_0x524998[_0xf202('0x36')]);_0xe19347[_0xf202('0x37')]=_['intersection'](_0xe19347[_0xf202('0x35')],_0xe19347[_0xf202('0x36')]);_0x4c3f76['attributes']=_[_0xf202('0x38')](_0xe19347[_0xf202('0x35')],qs[_0xf202('0x39')](_0x524998[_0xf202('0x36')]['fields']));_0x4c3f76[_0xf202('0x3a')]=_0x4c3f76[_0xf202('0x3a')][_0xf202('0x2e')]?_0x4c3f76[_0xf202('0x3a')]:_0xe19347[_0xf202('0x35')];if(!_0x524998[_0xf202('0x36')][_0xf202('0x3b')](_0xf202('0x3c'))){_0x4c3f76[_0xf202('0x3d')]=qs[_0xf202('0x3d')](_0x524998[_0xf202('0x36')][_0xf202('0x3d')]);_0x4c3f76[_0xf202('0x1e')]=qs['offset'](_0x524998['query']['offset']);}_0x4c3f76['order']=qs[_0xf202('0x3e')](_0x524998[_0xf202('0x36')]['sort']);_0x4c3f76['where']=qs['filters'](_[_0xf202('0x3f')](_0x524998[_0xf202('0x36')],_0xe19347[_0xf202('0x37')]),_0x58bdfa);var _0x34f8cf=[];var _0x426ddd=squel[_0xf202('0x40')]()[_0xf202('0x41')]('id')[_0xf202('0x41')](_0xf202('0x2a'))[_0xf202('0x41')](_0xf202('0x42'))[_0xf202('0x43')](_0xf202('0x44'));var _0x3bf95c=squel[_0xf202('0x40')]()[_0xf202('0x43')](_0xf202('0x45'),'c')[_0xf202('0x46')]('cm_user_has_contacts','uc',_0xf202('0x47'))[_0xf202('0x46')](_0xf202('0x48'),'ct',_0xf202('0x49'))[_0xf202('0x46')](_0xf202('0x44'),'t',_0xf202('0x4a'))[_0xf202('0x4b')](_0xf202('0x4c'));var _0xf8b74b=squel[_0xf202('0x4d')]();var _0x461193=[];var _0x126b94=squel['expr']();var _0x30fe87;if(_0x524998[_0xf202('0x36')][_0xf202('0x4e')]){_0x30fe87=as[_0xf202('0x4f')](_0x524998[_0xf202('0x36')][_0xf202('0x4e')]);var _0x2c8b0e=_0x30fe87[_0xf202('0x50')];for(var _0xacbfbf=0x0;_0xacbfbf<_0x30fe87[_0xf202('0x51')]['length'];_0xacbfbf++){var _0x2bcebe=_0x30fe87[_0xf202('0x51')][_0xacbfbf];var _0x296ba3='c';var _0x34513a=_(_0x58bdfa)['keys']()[_0xf202('0x52')](function(_0x16dabe){return _0x16dabe===_0x2bcebe[_0xf202('0x41')];});if(_0x34513a)_0x34513a=_0x58bdfa[_0x2bcebe['field']];if(!_0x34513a){if(_0x2bcebe[_0xf202('0x41')]===_0xf202('0x53')){var _0x5a5bee=_0x2bcebe[_0xf202('0x54')][_0xf202('0x55')](',')[_0xf202('0x56')](function(_0xebace){return Number(_0xebace);});_0x5a5bee[_0xf202('0x57')](function(_0x5555ff){_0x126b94['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x5555ff+',%');});_0x461193=_['union'](_0x461193,_0x5a5bee);}else if(_0x2bcebe[_0xf202('0x41')]===_0xf202('0x58')){_0xf8b74b[_0xf202('0x59')]('uc.UserId\x20=\x20?',_0x2bcebe[_0xf202('0x54')]);}}else{if(_0x2bcebe[_0xf202('0x41')]==='dateOfBirth'||_0x34513a[_0xf202('0x33')]===_0xf202('0x5a'))_0x2bcebe[_0xf202('0x5b')]=_0xf202('0x5c');var _0x5c6ab4=as['buildExpression'](_0x296ba3,_0x34513a['type'],_0x2bcebe);_0xf8b74b[_0x2c8b0e](_0x5c6ab4[_0xf202('0x5d')],_0x5c6ab4[_0xf202('0x54')][_0xf202('0x5e')],_0x5c6ab4[_0xf202('0x54')][_0xf202('0x1b')]);}}}else{var _0x10d82e=_(Object[_0xf202('0x2d')](_0x524998['query']))['map'](function(_0x5f045d){return _0x58bdfa['hasOwnProperty'](_0x5f045d)?_0x5f045d:undefined;})[_0xf202('0x5f')](function(_0x340bda){return!_['isNil'](_0x340bda);})['value']();if(_0x524998[_0xf202('0x36')][_0xf202('0x60')])_0x10d82e[_0xf202('0x61')](_0xf202('0x60'));if(!_[_0xf202('0x62')](_0x10d82e)){_0x10d82e['forEach'](function(_0x32ec08){if(_0x32ec08===_0xf202('0x63')){_0x3bf95c[_0xf202('0x4b')](_0xf202('0x64'),[][_0xf202('0x65')](_0x524998[_0xf202('0x36')][_0x32ec08]));}else if(_0x32ec08===_0xf202('0x60')){var _0x3d6e9f='%'+_0x524998['query'][_0x32ec08]+'%';_0x3bf95c[_0xf202('0x4b')](_0xf202('0x66'),_0x3d6e9f);}else{_0x3bf95c[_0xf202('0x4b')]('c.'+_0x32ec08+_0xf202('0x67'),_0x524998[_0xf202('0x36')][_0x32ec08]);}});}if(_0x524998[_0xf202('0x36')][_0xf202('0x68')]){_0x461193=_[_0xf202('0x69')](_0x524998[_0xf202('0x36')][_0xf202('0x68')])?_0x524998[_0xf202('0x36')][_0xf202('0x68')]:new Array(_0x524998[_0xf202('0x36')][_0xf202('0x68')]);_0x461193[_0xf202('0x57')](function(_0x5951dc){_0x126b94['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x5951dc+',%');});}if(_0x524998[_0xf202('0x36')]['filter']){var _0x45ea24=_0x524998[_0xf202('0x36')][_0xf202('0x5f')]['replace']('\x5c','\x5c\x5c')['replace']('\x27\x27',_0xf202('0x6a'));if(_0x45ea24[_0xf202('0x55')]('\x20')['length']>0x1){_0xf8b74b['or'](_0xf202('0x6b'),qs['getFullTextValue'](_0x45ea24),null);}else{if(qs[_0xf202('0x6c')](_0x45ea24)){_0xf8b74b['or'](_0xf202('0x6d'),_0x45ea24+'%');_0xf8b74b['or'](_0xf202('0x6e'),_0x45ea24+'%');_0xf8b74b['or'](_0xf202('0x6f'),_0x45ea24+'%');_0xf8b74b['or'](_0xf202('0x70'),_0x45ea24+'%');}else if(qs['isEmail'](_0x45ea24)){_0xf8b74b['or'](_0xf202('0x71'),_0x45ea24+'%');}else{_0xf8b74b['or'](_0xf202('0x72'),'%'+_0x45ea24+'%');_0xf8b74b['or'](_0xf202('0x73'),'%'+_0x45ea24+'%');_0xf8b74b['or'](_0xf202('0x71'),'%'+_0x45ea24+'%');}}}}_0x3bf95c[_0xf202('0x4b')](_0xf8b74b);_0x3bf95c['group'](_0xf202('0x74'));var _0x40347f={'type':db[_0xf202('0x75')][_0xf202('0x76')][_0xf202('0x77')],'raw':!![]};var _0x3ff521=_0x3bf95c[_0xf202('0x78')]()[_0xf202('0x41')](_0xf202('0x74'));if(_0x4c3f76[_0xf202('0x79')]){_0x4c3f76[_0xf202('0x79')][_0xf202('0x57')](function(_0x4ab8d0){_0x3bf95c[_0xf202('0x79')]('c.'+_0x4ab8d0[0x0],_0x4ab8d0[0x1]==='DESC'?![]:!![]);});}if(!_[_0xf202('0x62')](_0x461193)){_0x3bf95c['having'](_0x126b94);_0x3ff521[_0xf202('0x4b')]('t.id\x20IN\x20?',_0x461193);}BPromise[_0xf202('0x7a')]()['then'](function(){if(_0x30fe87&&!_['some'](_0x30fe87[_0xf202('0x51')],['field',_0xf202('0x58')])){return _0x524998['user'][_0xf202('0x7b')]({'attributes':['id'],'raw':!![]})['then'](function(_0x4a2e63){if(_['isEmpty'](_0x4a2e63)){_0x3ff521[_0xf202('0x4b')](_0xf202('0x7c'));_0x3bf95c[_0xf202('0x4b')](_0xf202('0x7c'));}else{_0x3ff521['where'](_0xf202('0x64'),_[_0xf202('0x56')](_0x4a2e63,'id'));_0x3bf95c[_0xf202('0x4b')](_0xf202('0x64'),_[_0xf202('0x56')](_0x4a2e63,'id'));}});}else{return;}})[_0xf202('0x25')](function(){db[_0xf202('0x7d')][_0xf202('0x36')](_0x3ff521[_0xf202('0x7e')](),_0x40347f)[_0xf202('0x25')](function(_0x3907ef){_0x191054[_0xf202('0x7f')]=_0x3907ef['length'];if(_0x191054[_0xf202('0x7f')]===0x0)return[];return db[_0xf202('0x7d')]['query'](_0x426ddd[_0xf202('0x7e')](),_0x40347f);})['then'](function(_0x4afd59){_0x34f8cf=_['keyBy'](_0x4afd59,'id');_0x40347f=_['merge'](_0x40347f,{'model':db[_0xf202('0x80')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x524998[_0xf202('0x36')]['fields']){_0x4c3f76[_0xf202('0x3a')][_0xf202('0x57')](function(_0x19de2f){_0x3bf95c['field']('c.'+_0x19de2f);});}else{_0x3bf95c[_0xf202('0x41')]('c.id');_0x3bf95c[_0xf202('0x41')]('c.firstName');_0x3bf95c[_0xf202('0x41')](_0xf202('0x81'));_0x3bf95c[_0xf202('0x41')](_0xf202('0x82'));_0x3bf95c[_0xf202('0x41')](_0xf202('0x83'));_0x3bf95c[_0xf202('0x41')](_0xf202('0x84'));_0x3bf95c['field'](_0xf202('0x85'));_0x3bf95c[_0xf202('0x41')](_0xf202('0x86'));_0x3bf95c[_0xf202('0x41')]('c.deletedAt');_0x3bf95c['field'](_0xf202('0x87'),_0xf202('0x88'));}if(_0x4c3f76[_0xf202('0x3d')])_0x3bf95c['limit'](_0x4c3f76['limit']);if(_0x4c3f76[_0xf202('0x1e')])_0x3bf95c[_0xf202('0x1e')](_0x4c3f76['offset']);return db[_0xf202('0x7d')][_0xf202('0x36')](_0x3bf95c[_0xf202('0x7e')](),_0x40347f);})[_0xf202('0x25')](function(_0x41fb19){_0x41fb19[_0xf202('0x57')](function(_0x38fd55){if(_0x38fd55['TagIds']){_0x38fd55[_0xf202('0x89')]=[];_0x38fd55[_0xf202('0x88')][_0xf202('0x55')](',')[_0xf202('0x57')](function(_0x4c0fc9){_0x38fd55[_0xf202('0x89')]['push'](_0x34f8cf[_0x4c0fc9]);});}delete _0x38fd55[_0xf202('0x88')];});_0x191054[_0xf202('0x8a')]=_0x41fb19;return _0x191054;})[_0xf202('0x25')](respondWithFilteredResult(_0x1be4f4,_0x4c3f76));});})['catch'](handleError(_0x1be4f4,null));};exports['destroy']=function(_0x1007be,_0x72a4c8){return db['CmContact']['find']({'where':{'id':_0x1007be[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0x72a4c8,null))[_0xf202('0x25')](removeEntity(_0x72a4c8,null))[_0xf202('0x8c')](handleError(_0x72a4c8,null));};exports[_0xf202('0x2c')]=function(_0x407930,_0x9ff4ab){return db[_0xf202('0x80')][_0xf202('0x2c')]()[_0xf202('0x25')](function(_0x120c56){delete _0x120c56[_0xf202('0x8d')];for(var _0x2fe2a0=0x0;_0x2fe2a0<Object[_0xf202('0x2d')](_0x120c56)['length'];_0x2fe2a0++){var _0x45fa7d=Object[_0xf202('0x2d')](_0x120c56)[_0x2fe2a0];if(!_[_0xf202('0x2f')](_0x45fa7d,_0xf202('0x30'))){_0x120c56[_0x45fa7d][_0xf202('0x8e')]=_0x45fa7d;_0x120c56[_0x45fa7d]['displayName']=_0x45fa7d;}}return _0x120c56;})[_0xf202('0x25')](function(_0x1842bb){var _0x39ba6e={'where':{'$or':[{'ListId':_0x407930[_0xf202('0x36')]['id']},{'ListId':null}]},'raw':!![]};return db['CmCustomField'][_0xf202('0x8f')](_0x39ba6e)[_0xf202('0x25')](function(_0x26aba3){for(var _0x2265d2=0x0;_0x2265d2<_0x26aba3[_0xf202('0x2e')];_0x2265d2++){var _0x54243a=_0xf202('0x30')+_0x26aba3[_0x2265d2]['id'];_0x1842bb[_0x54243a][_0xf202('0x8e')]=_0x54243a;_0x1842bb[_0x54243a][_0xf202('0x90')]=_0x26aba3[_0x2265d2][_0xf202('0x91')];_0x1842bb[_0x54243a][_0xf202('0x92')]={'type':_0x26aba3[_0x2265d2][_0xf202('0x34')],'values':_0x26aba3[_0x2265d2]['values']};}Object['keys'](_0x1842bb)[_0xf202('0x57')](function(_0x22e1aa){if(!_0x1842bb[_0x22e1aa]['hasOwnProperty']('columnName')){delete _0x1842bb[_0x22e1aa];}});return _0x1842bb;});})['then'](respondWithResult(_0x9ff4ab,null))['catch'](handleError(_0x9ff4ab,null));};exports[_0xf202('0x93')]=function(_0x39d703,_0x176f28){var _0x7e1043;var _0x53378f;var _0x462170;if(_0x39d703[_0xf202('0x94')]['id']){delete _0x39d703[_0xf202('0x94')]['id'];}return db[_0xf202('0x80')][_0xf202('0x8f')]({'where':{'id':[_0x39d703[_0xf202('0x94')]['to'],_0x39d703['body']['from']]}})[_0xf202('0x25')](function(_0x1cecd8){if(_0x1cecd8){if(_0x1cecd8[_0xf202('0x2e')]!==0x2){return null;}_0x1cecd8[0x0]=_0x1cecd8[0x0]['get']({'plain':!![]});_0x1cecd8[0x1]=_0x1cecd8[0x1][_0xf202('0x95')]({'plain':!![]});delete _0x1cecd8[0x0]['id'];delete _0x1cecd8[0x1]['id'];return _[_0xf202('0x96')](_0x1cecd8[0x0],_0x1cecd8[0x1],function(_0x5d64cb,_0x5dc661){if(Array[_0xf202('0x69')](_0x5dc661)&&!_0x5dc661['length']){return _0x5d64cb;}else if(!_0x5dc661){return _0x5d64cb;}});}})[_0xf202('0x25')](handleEntityNotFound(_0x176f28,null))[_0xf202('0x25')](function(_0x18946b){if(_0x18946b){if(_0x18946b['tags']&&_['isArray'](_0x18946b[_0xf202('0x8d')])){_0x18946b[_0xf202('0x8d')]=_0x18946b['tags']['join']();}logger[_0xf202('0x97')](_0xf202('0x98'),_0x39d703[_0xf202('0x94')]['to'],_0x39d703[_0xf202('0x94')]['from']);return db[_0xf202('0x99')][_0xf202('0x26')]({'where':{'ContactId':[_0x39d703[_0xf202('0x94')]['to'],_0x39d703['body'][_0xf202('0x43')]]}})[_0xf202('0x25')](function(_0x5d0402){logger[_0xf202('0x97')](_0xf202('0x9a'),_0x5d0402);return db[_0xf202('0x9b')][_0xf202('0x26')]({'where':{'ContactId':[_0x39d703['body']['to'],_0x39d703[_0xf202('0x94')]['from']]}})[_0xf202('0x25')](function(_0x58191){logger[_0xf202('0x97')]('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x58191);return db[_0xf202('0x80')][_0xf202('0x9c')](_0x18946b);});});}})[_0xf202('0x25')](function(_0x26832a){if(_0x26832a){_0x7e1043=_0x26832a;_0x53378f={'ContactId':_0x7e1043['id']};_0x462170={'where':{'ContactId':[_0x39d703[_0xf202('0x94')]['to'],_0x39d703['body']['from']]}};return db['ChatInteraction'][_0xf202('0x24')](_0x53378f,_0x462170);}})['then'](function(){if(_0x7e1043){return db[_0xf202('0x9d')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0x9e')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0x9f')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa0')]['update'](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db['MailInteraction'][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa0')]['update'](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa1')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa2')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa3')]['update'](_0x53378f,_0x462170);}})['then'](function(){if(_0x7e1043){return db['FaxMessage'][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa4')]['update'](_0x53378f,_0x462170);}})['then'](function(){if(_0x7e1043){return db[_0xf202('0xa5')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa6')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa7')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa8')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xa9')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xaa')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xab')]['update'](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xac')]['update'](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xad')]['update'](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db['SmsQueueReport'][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0xae')][_0xf202('0x24')](_0x53378f,_0x462170);}})[_0xf202('0x25')](function(){if(_0x7e1043){return db[_0xf202('0x80')][_0xf202('0x26')]({'where':{'id':[_0x39d703['body']['to'],_0x39d703['body'][_0xf202('0x43')]]}});}})[_0xf202('0x25')](function(){if(_0x7e1043){return _0x7e1043;}})['then'](respondWithResult(_0x176f28,null))[_0xf202('0x8c')](handleError(_0x176f28,null));};exports[_0xf202('0x9c')]=function(_0x587644,_0x2569d5){return db['CmContact'][_0xf202('0x2c')]()[_0xf202('0x25')](function(_0x4d0a6c){if(_0x587644[_0xf202('0x94')][_0xf202('0x8d')]&&_['isArray'](_0x587644['body']['tags'])){if(_0x587644[_0xf202('0x94')][_0xf202('0x8d')]['length']){_0x587644[_0xf202('0x94')][_0xf202('0x8d')]=_0x587644[_0xf202('0x94')][_0xf202('0x8d')][_0xf202('0xaf')](';')+';';}else{_0x587644[_0xf202('0x94')][_0xf202('0x8d')]=null;}}else{_0x587644[_0xf202('0x94')]['tags']=null;}return db[_0xf202('0x80')][_0xf202('0x9c')](_0x587644[_0xf202('0x94')],{'fields':_[_0xf202('0x2d')](_0x4d0a6c),'raw':!![]});})[_0xf202('0x25')](respondWithResult(_0x2569d5,0xc9))['catch'](handleError(_0x2569d5,null));};exports[_0xf202('0xb0')]=function(_0x168a26,_0x9dcaef){var _0x2cdc63=[];var _0x46a4b3=0x0;var _0x474a33=0x0;var _0x41acaf=0x0;return db['CmContact'][_0xf202('0x2c')]()[_0xf202('0x25')](function(_0x242085){return BPromise[_0xf202('0xb1')](_0x168a26[_0xf202('0x94')],function(_0x309592){var _0x454aa9={'where':{'$or':[]},'defaults':_0x309592,'fields':_[_0xf202('0x2d')](_0x242085),'raw':!![]};if(_0x309592['duplicates']){for(var _0xa64b1=0x0;_0xa64b1<_0x309592[_0xf202('0xb2')][_0xf202('0x2e')];_0xa64b1++){var _0x1e43b2={};_0x1e43b2[_0x309592[_0xf202('0xb2')][_0xa64b1]]=_0x309592[_0x309592['duplicates'][_0xa64b1]];_0x454aa9[_0xf202('0x4b')][_0xf202('0xb3')][_0xf202('0x61')](_0x1e43b2);}_0x454aa9[_0xf202('0x4b')]['ListId']=_0x309592[_0xf202('0x63')];}return db['CmContact'][_0xf202('0xb4')](_0x454aa9)[_0xf202('0xb5')](function(_0x2757cf,_0x4b19ff){if(_0x4b19ff){_0x46a4b3++;}else{_0x41acaf++;}})[_0xf202('0x8c')](function(_0x3ffcdb){console[_0xf202('0x28')](_0x3ffcdb);_0x474a33++;});});})[_0xf202('0x25')](function(_0x29174d){if(_0x29174d){return{'success':_0x46a4b3,'failure':_0x474a33,'duplicates':_0x41acaf};}})['then'](respondWithResult(_0x9dcaef,0xc9))[_0xf202('0x8c')](handleError(_0x9dcaef,null));};exports[_0xf202('0xb6')]=function(_0x495ad4,_0x2386a0,_0x366cbd){var _0xc4ab02;return db[_0xf202('0x80')][_0xf202('0x2c')]()[_0xf202('0x25')](function(_0x47e11c){return db[_0xf202('0x80')][_0xf202('0x52')]({'where':{'id':_0x495ad4[_0xf202('0x8b')]['id']},'include':[{'model':db[_0xf202('0x53')],'as':_0xf202('0x89'),'attributes':['id','name',_0xf202('0x42')],'required':_0x495ad4[_0xf202('0x36')][_0xf202('0x68')]?!![]:![]}],'attributes':_[_0xf202('0x2d')](_0x47e11c)});})[_0xf202('0x25')](function(_0x2c87b5){_0xc4ab02=_0x2c87b5[_0xf202('0x95')]({'plain':!![]});var _0x4bf716={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2c87b5&&_0x2c87b5[_0xf202('0x63')]){if(_0x2c87b5[_0xf202('0x63')]){_0x4bf716['where'][_0xf202('0xb7')][_0xf202('0x61')]({'ListId':{'$ne':_0x2c87b5[_0xf202('0x63')]}});}}return db[_0xf202('0xb8')]['findAll'](_0x4bf716);})[_0xf202('0x25')](function(_0x9392ae){return _[_0xf202('0xb9')](_0xc4ab02,_[_0xf202('0x56')](_0x9392ae,function(_0x4f679a){return util['format'](_0xf202('0xba'),_0x4f679a['id']);}));})[_0xf202('0x25')](handleEntityNotFound(_0x2386a0,null))[_0xf202('0x25')](respondWithResult(_0x2386a0,null))[_0xf202('0x8c')](handleError(_0x2386a0,null));};exports['update']=function(_0x56da37,_0xa85c39){var _0x2b9d4c;if(_0x56da37[_0xf202('0x94')]['id']){delete _0x56da37[_0xf202('0x94')]['id'];}return db[_0xf202('0x80')][_0xf202('0x52')]({'where':{'id':_0x56da37[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0xa85c39,null))['then'](saveUpdates(_0x56da37[_0xf202('0x94')],null))[_0xf202('0x25')](function(_0x575d83){_0x2b9d4c=_0x575d83;var _0x5ea0cb={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x575d83&&_0x575d83[_0xf202('0x63')]){if(_0x575d83[_0xf202('0x63')]){_0x5ea0cb['where']['$and'][_0xf202('0x61')]({'ListId':{'$ne':_0x575d83['ListId']}});}}return db['CmCustomField'][_0xf202('0x8f')](_0x5ea0cb);})[_0xf202('0x25')](function(_0x1d6123){if(_0x1d6123){return _['omit'](_[_0xf202('0xbb')](_0x56da37[_0xf202('0x94')],function(_0x55dfa2,_0x2b28e9){return _[_0xf202('0x2f')](_0x2b28e9,'cf_');}),_[_0xf202('0x56')](_0x1d6123,function(_0x28bef0){return util[_0xf202('0xbc')](_0xf202('0xba'),_0x28bef0['id']);}));}})[_0xf202('0x25')](function(_0x1407f3){if(_0x1407f3&&!_[_0xf202('0x62')](_0x1407f3)){var _0x25cbc1=squel[_0xf202('0x24')]()[_0xf202('0xbd')](_0xf202('0x45'))[_0xf202('0xbe')](_0x1407f3)[_0xf202('0x4b')](_0xf202('0xbf'),_0x56da37[_0xf202('0x8b')]['id'])['toParam']();return db[_0xf202('0x7d')][_0xf202('0x36')](_0x25cbc1['text'],{'replacements':_0x25cbc1[_0xf202('0xc0')]});}})['then'](function(){if(_0x56da37[_0xf202('0x94')]['phone']&&_0x2b9d4c){return db['CmHopper'][_0xf202('0x24')]({'phone':_0x56da37[_0xf202('0x94')]['phone']},{'where':{'ContactId':_0x2b9d4c['id']}});}})[_0xf202('0x25')](function(){return _0x2b9d4c;})[_0xf202('0x25')](respondWithResult(_0xa85c39,null))[_0xf202('0x8c')](handleError(_0xa85c39,null));};exports['getTags']=function(_0x2668aa,_0x2a5836,_0x44b86b){var _0x1f07f7={};var _0x48d6ca={};var _0x1b79cf;var _0x4a0e00;return db[_0xf202('0x80')][_0xf202('0x31')]({'where':{'id':_0x2668aa[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0x2a5836,null))[_0xf202('0x25')](function(_0x367c28){if(_0x367c28){_0x1b79cf=_0x367c28;_0x48d6ca[_0xf202('0x35')]=_['keys'](db[_0xf202('0x53')][_0xf202('0xc1')]);_0x48d6ca['query']=_[_0xf202('0x2d')](_0x2668aa[_0xf202('0x36')]);_0x48d6ca[_0xf202('0x37')]=_[_0xf202('0x38')](_0x48d6ca[_0xf202('0x35')],_0x48d6ca[_0xf202('0x36')]);_0x1f07f7[_0xf202('0x3a')]=_[_0xf202('0x38')](_0x48d6ca[_0xf202('0x35')],qs[_0xf202('0x39')](_0x2668aa['query'][_0xf202('0x39')]));_0x1f07f7[_0xf202('0x3a')]=_0x1f07f7[_0xf202('0x3a')][_0xf202('0x2e')]?_0x1f07f7[_0xf202('0x3a')]:_0x48d6ca[_0xf202('0x35')];_0x1f07f7[_0xf202('0x79')]=qs[_0xf202('0x3e')](_0x2668aa[_0xf202('0x36')][_0xf202('0x3e')]);_0x1f07f7[_0xf202('0x4b')]=qs[_0xf202('0x37')](_[_0xf202('0x3f')](_0x2668aa[_0xf202('0x36')],_0x48d6ca[_0xf202('0x37')]));if(_0x2668aa['query'][_0xf202('0x5f')]){_0x1f07f7[_0xf202('0x4b')]=_[_0xf202('0x93')](_0x1f07f7['where'],{'$or':_['map'](_0x1f07f7[_0xf202('0x3a')],function(_0x441fca){var _0x590431={};_0x590431[_0x441fca]={'$like':'%'+_0x2668aa[_0xf202('0x36')]['filter']+'%'};return _0x590431;})});}_0x1f07f7=_[_0xf202('0x93')]({},_0x1f07f7,_0x2668aa[_0xf202('0xc2')]);return _0x1b79cf[_0xf202('0xc3')](_0x1f07f7);}})[_0xf202('0x25')](function(_0x28f972){if(_0x28f972){_0x4a0e00=_0x28f972[_0xf202('0x2e')];if(!_0x2668aa[_0xf202('0x36')][_0xf202('0x3b')](_0xf202('0x3c'))){_0x1f07f7[_0xf202('0x3d')]=qs['limit'](_0x2668aa[_0xf202('0x36')][_0xf202('0x3d')]);_0x1f07f7[_0xf202('0x1e')]=qs[_0xf202('0x1e')](_0x2668aa[_0xf202('0x36')][_0xf202('0x1e')]);}return _0x1b79cf[_0xf202('0xc3')](_0x1f07f7);}})[_0xf202('0x25')](function(_0x467ca9){if(_0x467ca9){return _0x467ca9?{'count':_0x4a0e00,'rows':_0x467ca9}:null;}})[_0xf202('0x25')](respondWithResult(_0x2a5836,null))[_0xf202('0x8c')](handleError(_0x2a5836,null));};exports[_0xf202('0xc4')]=function(_0x948a03,_0x825918,_0x228e2f){if(_0x948a03[_0xf202('0x94')]['id']){delete _0x948a03['body']['id'];}return db[_0xf202('0x80')][_0xf202('0x31')]({'where':{'id':_0x948a03['params']['id']}})[_0xf202('0x25')](handleEntityNotFound(_0x825918,null))[_0xf202('0x25')](function(_0x34fa54){if(_0x34fa54){return _0x34fa54[_0xf202('0xc4')](_0x948a03[_0xf202('0x94')][_0xf202('0xc5')]||[]);}return null;})[_0xf202('0x25')](respondWithResult(_0x825918,null))[_0xf202('0x8c')](handleError(_0x825918,null));};exports[_0xf202('0xc6')]=function(_0xb1a79d,_0xb0b871,_0x3de93d){var _0x54e780={'raw':![],'where':{}};var _0x1e9b2d={};var _0x11fa6a={'count':0x0,'rows':[]};return db[_0xf202('0x80')][_0xf202('0x31')]({'where':{'id':_0xb1a79d[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0xb0b871,null))[_0xf202('0x25')](function(_0x16d27d){if(_0x16d27d){_0x1e9b2d[_0xf202('0x35')]=_[_0xf202('0x2d')](db[_0xf202('0x99')]['rawAttributes']);_0x1e9b2d[_0xf202('0x36')]=_[_0xf202('0x2d')](_0xb1a79d[_0xf202('0x36')]);_0x1e9b2d[_0xf202('0x37')]=_[_0xf202('0x38')](_0x1e9b2d['model'],_0x1e9b2d[_0xf202('0x36')]);_0x54e780[_0xf202('0x3a')]=_[_0xf202('0x38')](_0x1e9b2d['model'],qs[_0xf202('0x39')](_0xb1a79d[_0xf202('0x36')][_0xf202('0x39')]));_0x54e780['attributes']=_0x54e780['attributes'][_0xf202('0x2e')]?_0x54e780['attributes']:_0x1e9b2d[_0xf202('0x35')];if(!_0xb1a79d[_0xf202('0x36')]['hasOwnProperty'](_0xf202('0x3c'))){_0x54e780[_0xf202('0x3d')]=qs['limit'](_0xb1a79d[_0xf202('0x36')][_0xf202('0x3d')]);_0x54e780[_0xf202('0x1e')]=qs[_0xf202('0x1e')](_0xb1a79d['query'][_0xf202('0x1e')]);}_0x54e780['order']=qs[_0xf202('0x3e')](_0xb1a79d['query'][_0xf202('0x3e')]);_0x54e780['where']=qs[_0xf202('0x37')](_[_0xf202('0x3f')](_0xb1a79d['query'],_0x1e9b2d[_0xf202('0x37')]));_0x54e780['where'][_0xf202('0xc7')]=_0x16d27d['id'];if(_0xb1a79d[_0xf202('0x36')][_0xf202('0x5f')]){_0x54e780[_0xf202('0x4b')]=_[_0xf202('0x93')](_0x54e780[_0xf202('0x4b')],{'$or':_[_0xf202('0x56')](_0x54e780['attributes'],function(_0x2e5d0b){var _0x2e549c={};_0x2e549c[_0x2e5d0b]={'$like':'%'+_0xb1a79d[_0xf202('0x36')]['filter']+'%'};return _0x2e549c;})});}_0x54e780=_[_0xf202('0x93')]({},_0x54e780,_0xb1a79d[_0xf202('0xc2')]);return db[_0xf202('0x99')][_0xf202('0x7f')]({'where':_0x54e780[_0xf202('0x4b')]})[_0xf202('0x25')](function(_0x580441){_0x11fa6a[_0xf202('0x7f')]=_0x580441;if(_0xb1a79d[_0xf202('0x36')][_0xf202('0xc8')]){_0x54e780['include']=[{'all':!![]}];}return db[_0xf202('0x99')][_0xf202('0x8f')](_0x54e780);})[_0xf202('0x25')](function(_0x2d9092){_0x11fa6a[_0xf202('0x8a')]=_0x2d9092;return _0x11fa6a;});}})[_0xf202('0x25')](respondWithFilteredResult(_0xb0b871,_0x54e780))[_0xf202('0x8c')](handleError(_0xb0b871,null));};exports['getHopperHistories']=function(_0x3072e6,_0x15c120,_0x50efc8){var _0x449785={'raw':!![],'where':{}};var _0x3d2ab9={};var _0xe0bd3c={'count':0x0,'rows':[]};return db[_0xf202('0x80')][_0xf202('0x31')]({'where':{'id':_0x3072e6[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0x15c120,null))[_0xf202('0x25')](function(_0xd2ef3e){if(_0xd2ef3e){_0x3d2ab9[_0xf202('0x35')]=_['keys'](db[_0xf202('0xa7')][_0xf202('0xc1')]);_0x3d2ab9[_0xf202('0x36')]=_[_0xf202('0x2d')](_0x3072e6[_0xf202('0x36')]);_0x3d2ab9[_0xf202('0x37')]=_[_0xf202('0x38')](_0x3d2ab9[_0xf202('0x35')],_0x3d2ab9[_0xf202('0x36')]);_0x449785[_0xf202('0x3a')]=_[_0xf202('0x38')](_0x3d2ab9[_0xf202('0x35')],qs['fields'](_0x3072e6[_0xf202('0x36')][_0xf202('0x39')]));_0x449785[_0xf202('0x3a')]=_0x449785[_0xf202('0x3a')][_0xf202('0x2e')]?_0x449785[_0xf202('0x3a')]:_0x3d2ab9['model'];if(!_0x3072e6[_0xf202('0x36')]['hasOwnProperty'](_0xf202('0x3c'))){_0x449785[_0xf202('0x3d')]=qs[_0xf202('0x3d')](_0x3072e6[_0xf202('0x36')]['limit']);_0x449785[_0xf202('0x1e')]=qs[_0xf202('0x1e')](_0x3072e6[_0xf202('0x36')][_0xf202('0x1e')]);}_0x449785[_0xf202('0x79')]=qs['sort'](_0x3072e6[_0xf202('0x36')][_0xf202('0x3e')]);_0x449785[_0xf202('0x4b')]=qs[_0xf202('0x37')](_[_0xf202('0x3f')](_0x3072e6['query'],_0x3d2ab9[_0xf202('0x37')]));_0x449785[_0xf202('0x4b')]['ContactId']=_0xd2ef3e['id'];if(_0x3072e6[_0xf202('0x36')][_0xf202('0x5f')]){_0x449785[_0xf202('0x4b')]=_['merge'](_0x449785['where'],{'$or':_[_0xf202('0x56')](_0x449785[_0xf202('0x3a')],function(_0x5abb45){var _0x48fce7={};_0x48fce7[_0x5abb45]={'$like':'%'+_0x3072e6[_0xf202('0x36')]['filter']+'%'};return _0x48fce7;})});}_0x449785=_['merge']({},_0x449785,_0x3072e6[_0xf202('0xc2')]);return db[_0xf202('0xa7')][_0xf202('0x7f')]({'where':_0x449785[_0xf202('0x4b')]})[_0xf202('0x25')](function(_0x20773c){_0xe0bd3c[_0xf202('0x7f')]=_0x20773c;if(_0x3072e6[_0xf202('0x36')][_0xf202('0xc8')]){_0x449785[_0xf202('0xc9')]=[{'all':!![]}];}return db['CmHopperHistory'][_0xf202('0x8f')](_0x449785);})['then'](function(_0xa604bd){_0xe0bd3c['rows']=_0xa604bd;return _0xe0bd3c;});}})['then'](respondWithFilteredResult(_0x15c120,_0x449785))[_0xf202('0x8c')](handleError(_0x15c120,null));};exports[_0xf202('0xca')]=function(_0x9c0f38,_0x4b7e09,_0x44d08a){var _0x577d5f={'raw':!![],'where':{}};var _0x1cbf51={};var _0x581e0f={'count':0x0,'rows':[]};return db['CmContact'][_0xf202('0x31')]({'where':{'id':_0x9c0f38[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0x4b7e09,null))[_0xf202('0x25')](function(_0x19e896){if(_0x19e896){_0x1cbf51[_0xf202('0x35')]=_[_0xf202('0x2d')](db[_0xf202('0xa6')][_0xf202('0xc1')]);_0x1cbf51[_0xf202('0x36')]=_[_0xf202('0x2d')](_0x9c0f38['query']);_0x1cbf51['filters']=_[_0xf202('0x38')](_0x1cbf51[_0xf202('0x35')],_0x1cbf51[_0xf202('0x36')]);_0x577d5f[_0xf202('0x3a')]=_[_0xf202('0x38')](_0x1cbf51[_0xf202('0x35')],qs['fields'](_0x9c0f38['query']['fields']));_0x577d5f[_0xf202('0x3a')]=_0x577d5f[_0xf202('0x3a')][_0xf202('0x2e')]?_0x577d5f[_0xf202('0x3a')]:_0x1cbf51['model'];if(!_0x9c0f38[_0xf202('0x36')][_0xf202('0x3b')]('nolimit')){_0x577d5f['limit']=qs['limit'](_0x9c0f38[_0xf202('0x36')][_0xf202('0x3d')]);_0x577d5f[_0xf202('0x1e')]=qs['offset'](_0x9c0f38[_0xf202('0x36')][_0xf202('0x1e')]);}_0x577d5f[_0xf202('0x79')]=qs[_0xf202('0x3e')](_0x9c0f38['query'][_0xf202('0x3e')]);_0x577d5f[_0xf202('0x4b')]=qs[_0xf202('0x37')](_[_0xf202('0x3f')](_0x9c0f38[_0xf202('0x36')],_0x1cbf51[_0xf202('0x37')]));_0x577d5f[_0xf202('0x4b')][_0xf202('0xc7')]=_0x19e896['id'];if(_0x9c0f38['query'][_0xf202('0x5f')]){_0x577d5f[_0xf202('0x4b')]=_[_0xf202('0x93')](_0x577d5f[_0xf202('0x4b')],{'$or':_[_0xf202('0x56')](_0x577d5f[_0xf202('0x3a')],function(_0x4692cd){var _0x46451a={};_0x46451a[_0x4692cd]={'$like':'%'+_0x9c0f38[_0xf202('0x36')][_0xf202('0x5f')]+'%'};return _0x46451a;})});}_0x577d5f=_[_0xf202('0x93')]({},_0x577d5f,_0x9c0f38[_0xf202('0xc2')]);return db['CmHopperFinal'][_0xf202('0x7f')]({'where':_0x577d5f[_0xf202('0x4b')]})[_0xf202('0x25')](function(_0x52e73a){_0x581e0f['count']=_0x52e73a;if(_0x9c0f38[_0xf202('0x36')][_0xf202('0xc8')]){_0x577d5f[_0xf202('0xc9')]=[{'all':!![]}];}return db['CmHopperFinal'][_0xf202('0x8f')](_0x577d5f);})[_0xf202('0x25')](function(_0x208e7f){_0x581e0f[_0xf202('0x8a')]=_0x208e7f;return _0x581e0f;});}})[_0xf202('0x25')](respondWithFilteredResult(_0x4b7e09,_0x577d5f))[_0xf202('0x8c')](handleError(_0x4b7e09,null));};exports[_0xf202('0xcb')]=function(_0x96cede,_0x15abee,_0x1c321c){var _0x34e8ec={'raw':!![],'where':{}};var _0xb3706b={};var _0x418589={'count':0x0,'rows':[]};return db[_0xf202('0x80')][_0xf202('0x31')]({'where':{'id':_0x96cede[_0xf202('0x8b')]['id']}})[_0xf202('0x25')](handleEntityNotFound(_0x15abee,null))[_0xf202('0x25')](function(_0x572494){if(_0x572494){_0xb3706b[_0xf202('0x35')]=_[_0xf202('0x2d')](db[_0xf202('0xae')][_0xf202('0xc1')]);_0xb3706b['query']=_['keys'](_0x96cede[_0xf202('0x36')]);_0xb3706b[_0xf202('0x37')]=_[_0xf202('0x38')](_0xb3706b[_0xf202('0x35')],_0xb3706b['query']);_0x34e8ec[_0xf202('0x3a')]=_['intersection'](_0xb3706b[_0xf202('0x35')],qs[_0xf202('0x39')](_0x96cede[_0xf202('0x36')][_0xf202('0x39')]));_0x34e8ec[_0xf202('0x3a')]=_0x34e8ec['attributes'][_0xf202('0x2e')]?_0x34e8ec[_0xf202('0x3a')]:_0xb3706b['model'];if(!_0x96cede[_0xf202('0x36')][_0xf202('0x3b')](_0xf202('0x3c'))){_0x34e8ec[_0xf202('0x3d')]=qs[_0xf202('0x3d')](_0x96cede[_0xf202('0x36')][_0xf202('0x3d')]);_0x34e8ec[_0xf202('0x1e')]=qs[_0xf202('0x1e')](_0x96cede[_0xf202('0x36')][_0xf202('0x1e')]);}_0x34e8ec[_0xf202('0x79')]=qs[_0xf202('0x3e')](_0x96cede['query']['sort']);_0x34e8ec[_0xf202('0x4b')]=qs[_0xf202('0x37')](_[_0xf202('0x3f')](_0x96cede[_0xf202('0x36')],_0xb3706b[_0xf202('0x37')]));_0x34e8ec['where'][_0xf202('0xc7')]=_0x572494['id'];if(_0x96cede['query']['filter']){_0x34e8ec[_0xf202('0x4b')]=_[_0xf202('0x93')](_0x34e8ec['where'],{'$or':_[_0xf202('0x56')](_0x34e8ec['attributes'],function(_0x361cce){var _0x21f35f={};_0x21f35f[_0x361cce]={'$like':'%'+_0x96cede[_0xf202('0x36')][_0xf202('0x5f')]+'%'};return _0x21f35f;})});}_0x34e8ec=_[_0xf202('0x93')]({},_0x34e8ec,_0x96cede[_0xf202('0xc2')]);return db[_0xf202('0xae')]['count']({'where':_0x34e8ec[_0xf202('0x4b')]})['then'](function(_0xc1d1fb){_0x418589[_0xf202('0x7f')]=_0xc1d1fb;if(_0x96cede['query'][_0xf202('0xc8')]){_0x34e8ec[_0xf202('0xc9')]=[{'all':!![]}];}return db[_0xf202('0xae')]['findAll'](_0x34e8ec);})['then'](function(_0x2f3c3e){_0x418589[_0xf202('0x8a')]=_0x2f3c3e;return _0x418589;});}})[_0xf202('0x25')](respondWithFilteredResult(_0x15abee,_0x34e8ec))[_0xf202('0x8c')](handleError(_0x15abee,null));};exports[_0xf202('0xcc')]=function(_0x551897,_0x4e057e,_0x3b18db){try{if(!_0x551897[_0xf202('0x94')]['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x551897['body'][_0xf202('0xcd')]){throw new Error(_0xf202('0xce'));}if(!_0x551897[_0xf202('0x94')][_0xf202('0xcf')]){throw new Error(_0xf202('0xd0'));}if(!_0x551897[_0xf202('0x94')][_0xf202('0xd1')]){throw new Error(_0xf202('0xd2'));}var _0x1397de=_0x551897['body'][_0xf202('0xcd')][_0xf202('0x55')](',');var _0x87b86c=_0x551897[_0xf202('0x94')]['binding_values'][_0xf202('0x55')](',');if(!_0x1397de['length']||!_0x87b86c['length']||_0x1397de[_0xf202('0x2e')]!==_0x87b86c['length']){throw new Error(_0xf202('0xd3'));}_0x551897[_0xf202('0x94')][_0xf202('0x39')]=_['zipObject'](_0x1397de,_0x87b86c);if(!_0x551897[_0xf202('0x94')][_0xf202('0x39')][_0xf202('0xd4')]){throw new Error(_0xf202('0xd5'));}if(!_0x551897[_0xf202('0x94')]['fields']['firstName']){throw new Error('No\x20firstName\x20column\x20specified');}var _0xf8347c=path['join'](config[_0xf202('0xd6')],_0xf202('0xd7'),_0x551897[_0xf202('0xd8')][_0xf202('0xd9')]);fs['chmodSync'](_0xf8347c,parseInt('0777',0x8));var _0xc647d6=require(_0xf202('0xda'))[_0xf202('0xdb')](path['join'](__dirname,_0xf202('0xdc')),[_0xf8347c,_0x551897[_0xf202('0x94')][_0xf202('0xcd')],_0x551897[_0xf202('0x94')][_0xf202('0xcf')],_0x551897[_0xf202('0x94')][_0xf202('0x63')],_0x551897[_0xf202('0x94')][_0xf202('0xdd')],_0x551897[_0xf202('0x94')]['duplicates'],_0x551897[_0xf202('0x94')][_0xf202('0xd1')]]);return _0x4e057e[_0xf202('0x1c')](0xc8)[_0xf202('0x1d')]({'message':_0xf202('0xde'),'pid':_0xc647d6[_0xf202('0xdf')]});}catch(_0x26b0bb){return _0x4e057e[_0xf202('0x1c')](0x1f4)[_0xf202('0xe0')](_0x26b0bb);}};exports[_0xf202('0xe1')]=function(_0x2fe1fd,_0x27dabf,_0x125d13){var _0x9abe91=fs[_0xf202('0xe2')](_0x2fe1fd[_0xf202('0xd8')]['path']);Papa[_0xf202('0xe3')](_0x9abe91,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x2665b6){return _0x27dabf[_0xf202('0x1c')](0xc8)[_0xf202('0x1d')]({'file':_0x2fe1fd[_0xf202('0xd8')],'fields':_0x2665b6[_0xf202('0xe4')][_0xf202('0x39')]});}});};exports['import']=function(_0x16bb2f,_0x414239,_0x283802){return db[_0xf202('0x58')][_0xf202('0x8f')]({'raw':!![],'attributes':['id'],'where':{'role':'agent'}})['then'](function(_0x34cc0d){var _0x3a09db=![];if(!_0x16bb2f[_0xf202('0x94')][_0xf202('0x63')]){throw new Error(_0xf202('0xe5'));}if(!_0x16bb2f[_0xf202('0x94')][_0xf202('0xe6')][_0xf202('0xd4')]){throw new Error(_0xf202('0xd5'));}if(!_0x16bb2f[_0xf202('0x94')][_0xf202('0xe6')][_0xf202('0xe7')]){throw new Error('No\x20firstName\x20column\x20specified');}if(!_0x16bb2f[_0xf202('0x94')]['socket_timestamp']){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x1b87ce=require(_0xf202('0xda'))['fork'](path['join'](__dirname,_0xf202('0xe8')),[_0x16bb2f['params']['id'],JSON[_0xf202('0xe9')](_0x16bb2f[_0xf202('0x94')]),JSON[_0xf202('0xe9')](_0x34cc0d)]);_0x1b87ce['on']('message',function(_0x5c7e9a){_0x3a09db=!![];return _0x414239['status'](0xc8)[_0xf202('0x1d')]({'message':_0xf202('0xea'),'pid':_0x1b87ce[_0xf202('0xdf')]});});_0x1b87ce['on'](_0xf202('0xeb'),function(_0x4e0be5){if(_0x4e0be5&&!_0x3a09db){return _0x414239[_0xf202('0x1c')](0x1f4)[_0xf202('0x1d')]({'message':_0xf202('0xec'),'pid':_0x1b87ce[_0xf202('0xdf')]});}});})[_0xf202('0x8c')](handleError(_0x414239,null));};
\ No newline at end of file
+var _0xb94d=['where','$or','push','ListId','findOrCreate','spread','contact','all','show','find','Tags','name','ContactItemType','ItemType','sequelize','literal','Phones.OrderBy','isNil','$and','omit','map','format','cf_%d','pickBy','cf_','isEmpty','table','cm_contacts','setFields','id\x20=\x20?','text','phone','getTags','findOne','model','Tag','rawAttributes','filters','attributes','intersection','fields','order','sort','filter','nolimit','setTags','setAdditionalPhones','OrderBy','items','item_types','description','ItemTypeId','contact\x20phone\x20exists','PHONE','CmHopper','CmHopperAdditionalPhone','item','`ItemType`.OrderBy','CmHopperId','ItemType.OrderBy','getAdditionalPhones','duplicateAdditionalPhones','fromContactId','CmContactId','toContactId','hopperId','getHoppers','pick','ContactId','options','include','rows','getHopperHistories','includeAll','getHopperFinals','uploadCsv','binding_keys','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','split','Incorrect\x20binding\x20parameters\x20passed!','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','child_process','fork','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','upload','meta','import','User','agent','No\x20ListId\x20specified','binding','../../components/import/cm/csv2','stringify','message','exit','error\x20child\x20process','importUpdates','../../components/import/cm/csvUpdates','getJourney','chat','openchannel','fax','voice','-createdAt','resolve','includes','channel','toLowerCase','Invalid\x20channel','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20createdAt\x20filter','uniqueid','source','destination','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','VoiceCallReport','findAndCountAll','startCase','Website','closed','closedAt','disposition','secondDisposition','thirdDisposition','UserId','Account','key','Owner','color','DESC','browserName','customerIp','customerPort','deviceModel','ratingMessage','ratingType','mail','subject','externalUrl','threadId','fullname','flatten','sortBy','value','slice','moment','lodash','squel','ioredis','../../components/contacts','../../components/parsers/qs','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','register','status','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','sendStatus','error','send','index','findAll','query','catch','params','describe','CmContact','tags','keys','length','startsWith','columnName','analytics','CmCustomField','displayName','alias','type','values','info','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','forEach','hasOwnProperty','merge','body','get','mergeWith','isArray','join','from','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperFinal','CmHopperHistory','FaxQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','create','dialTimezone','utcOffset','timezones','additionalPhones','bulkCreate','duplicates'];(function(_0x2576d7,_0x167624){var _0x16a08c=function(_0x19de1e){while(--_0x19de1e){_0x2576d7['push'](_0x2576d7['shift']());}};_0x16a08c(++_0x167624);}(_0xb94d,0xa6));var _0xdb94=function(_0x152121,_0x120c53){_0x152121=_0x152121-0x0;var _0x592a85=_0xb94d[_0x152121];return _0x592a85;};'use strict';var moment=require(_0xdb94('0x0'));var BPromise=require('bluebird');var util=require('util');var path=require('path');var fs=require('fs');var _=require(_0xdb94('0x1'));var squel=require(_0xdb94('0x2'));var Papa=require('papaparse');var Redis=require(_0xdb94('0x3'));var contacts=require(_0xdb94('0x4'));var qs=require(_0xdb94('0x5'));var logger=require(_0xdb94('0x6'))('api');var config=require(_0xdb94('0x7'));var shared=require('../../config/environment/shared');var db=require(_0xdb94('0x8'))['db'];config[_0xdb94('0x9')]=_[_0xdb94('0xa')](config[_0xdb94('0x9')],{'host':_0xdb94('0xb'),'port':0x18eb});var socket=require(_0xdb94('0xc'))(new Redis(config[_0xdb94('0x9')]));require(_0xdb94('0xd'))[_0xdb94('0xe')](socket);function respondWithResult(_0x3ffc6e,_0x2d7f4c){_0x2d7f4c=_0x2d7f4c||0xc8;return function(_0x31daeb){if(_0x31daeb){return _0x3ffc6e[_0xdb94('0xf')](_0x2d7f4c)[_0xdb94('0x10')](_0x31daeb);}};}function respondWithFilteredResult(_0x23b044,_0x329646){return function(_0x4650a9){if(_0x4650a9){var _0x34310c=typeof _0x329646[_0xdb94('0x11')]===_0xdb94('0x12')&&typeof _0x329646[_0xdb94('0x13')]===_0xdb94('0x12');var _0x59cbb3=_0x4650a9[_0xdb94('0x14')];var _0x4db975=_0x34310c?0x0:_0x329646[_0xdb94('0x11')];var _0x307725=_0x34310c?_0x4650a9[_0xdb94('0x14')]:_0x329646[_0xdb94('0x11')]+_0x329646[_0xdb94('0x13')];var _0x341c8c;if(_0x307725>=_0x59cbb3){_0x307725=_0x59cbb3;_0x341c8c=0xc8;}else{_0x341c8c=0xce;}_0x23b044[_0xdb94('0xf')](_0x341c8c);return _0x23b044[_0xdb94('0x15')](_0xdb94('0x16'),_0x4db975+'-'+_0x307725+'/'+_0x59cbb3)[_0xdb94('0x10')](_0x4650a9);}return null;};}function saveUpdates(_0x37e716){return function(_0x1dd952){if(_0x1dd952){return _0x1dd952[_0xdb94('0x17')](_0x37e716)[_0xdb94('0x18')](function(_0x4c5994){return _0x4c5994;});}return null;};}function removeEntity(_0x38fa25){return function(_0x512ccd){if(_0x512ccd){return _0x512ccd[_0xdb94('0x19')]()[_0xdb94('0x18')](function(){_0x38fa25[_0xdb94('0xf')](0xcc)['end']();});}};}function handleEntityNotFound(_0x39695c){return function(_0x5b12d5){if(!_0x5b12d5){_0x39695c[_0xdb94('0x1a')](0x194);}return _0x5b12d5;};}function handleError(_0xd074be,_0x3d7285){_0x3d7285=_0x3d7285||0x1f4;return function(_0x2be650){logger[_0xdb94('0x1b')](_0x2be650['stack']);if(_0x2be650['name']){delete _0x2be650['name'];}_0xd074be[_0xdb94('0xf')](_0x3d7285)[_0xdb94('0x1c')](_0x2be650);};}exports[_0xdb94('0x1d')]=function(_0x37ae65,_0x2ca1a9){var _0x5e4b61={};return contacts['describe']()['then'](function(_0xdab26){_0x5e4b61=qs['getOptions'](_0xdab26,_0x37ae65);return contacts[_0xdb94('0x1e')](_0x37ae65[_0xdb94('0x1f')],_0x37ae65['user'],_0x5e4b61,_0xdab26);})[_0xdb94('0x18')](respondWithFilteredResult(_0x2ca1a9,_0x5e4b61))[_0xdb94('0x20')](handleError(_0x2ca1a9,null));};exports[_0xdb94('0x19')]=function(_0x594b82,_0xb549aa){return db['CmContact']['find']({'where':{'id':_0x594b82[_0xdb94('0x21')]['id']}})['then'](handleEntityNotFound(_0xb549aa,null))[_0xdb94('0x18')](removeEntity(_0xb549aa,null))['catch'](handleError(_0xb549aa,null));};exports[_0xdb94('0x22')]=function(_0x34c70b,_0x5d4f28){return db[_0xdb94('0x23')][_0xdb94('0x22')]()[_0xdb94('0x18')](function(_0x5d9a22){delete _0x5d9a22[_0xdb94('0x24')];for(var _0xbc39a9=0x0;_0xbc39a9<Object[_0xdb94('0x25')](_0x5d9a22)[_0xdb94('0x26')];_0xbc39a9++){var _0x929d96=Object['keys'](_0x5d9a22)[_0xbc39a9];if(!_[_0xdb94('0x27')](_0x929d96,'cf_')){_0x5d9a22[_0x929d96][_0xdb94('0x28')]=_0x929d96;_0x5d9a22[_0x929d96]['displayName']=_0x929d96;}}return _0x5d9a22;})['then'](function(_0xffcbc3){var _0x1c6922={'where':Boolean(_0x34c70b[_0xdb94('0x1f')][_0xdb94('0x29')])===!![]?undefined:{'$or':[{'ListId':_0x34c70b[_0xdb94('0x1f')]['id']},{'ListId':null}]},'raw':!![]};return db[_0xdb94('0x2a')][_0xdb94('0x1e')](_0x1c6922)[_0xdb94('0x18')](function(_0x3d4895){for(var _0x35ea2f=0x0;_0x35ea2f<_0x3d4895['length'];_0x35ea2f++){var _0x3eacb4='cf_'+_0x3d4895[_0x35ea2f]['id'];if(_0xffcbc3[_0x3eacb4]){_0xffcbc3[_0x3eacb4][_0xdb94('0x28')]=_0x3eacb4;_0xffcbc3[_0x3eacb4][_0xdb94('0x2b')]=_0x3d4895[_0x35ea2f][_0xdb94('0x2c')];_0xffcbc3[_0x3eacb4]['custom']={'type':_0x3d4895[_0x35ea2f][_0xdb94('0x2d')],'values':_0x3d4895[_0x35ea2f][_0xdb94('0x2e')]};}else{logger[_0xdb94('0x2f')](_0xdb94('0x30'),_0x3eacb4);}}Object['keys'](_0xffcbc3)[_0xdb94('0x31')](function(_0x1549e3){if(!_0xffcbc3[_0x1549e3][_0xdb94('0x32')](_0xdb94('0x28'))){delete _0xffcbc3[_0x1549e3];}});return _0xffcbc3;});})[_0xdb94('0x18')](respondWithResult(_0x5d4f28,null))[_0xdb94('0x20')](handleError(_0x5d4f28,null));};exports[_0xdb94('0x33')]=function(_0x40998c,_0x5cb9d6){var _0x37fe6d;var _0x2e7ea9;var _0x236c55;if(_0x40998c[_0xdb94('0x34')]['id']){delete _0x40998c[_0xdb94('0x34')]['id'];}return db[_0xdb94('0x23')][_0xdb94('0x1e')]({'where':{'id':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')]['from']]}})[_0xdb94('0x18')](function(_0x5988d1){if(_0x5988d1){if(_0x5988d1[_0xdb94('0x26')]!==0x2){return null;}_0x5988d1[0x0]=_0x5988d1[0x0][_0xdb94('0x35')]({'plain':!![]});_0x5988d1[0x1]=_0x5988d1[0x1][_0xdb94('0x35')]({'plain':!![]});delete _0x5988d1[0x0]['id'];delete _0x5988d1[0x1]['id'];return _[_0xdb94('0x36')](_0x5988d1[0x0],_0x5988d1[0x1],function(_0x5a1196,_0x2dce74){if(Array['isArray'](_0x2dce74)&&!_0x2dce74[_0xdb94('0x26')]){return _0x5a1196;}else if(!_0x2dce74){return _0x5a1196;}});}})[_0xdb94('0x18')](handleEntityNotFound(_0x5cb9d6,null))[_0xdb94('0x18')](function(_0x1593de){if(_0x1593de){if(_0x1593de[_0xdb94('0x24')]&&_[_0xdb94('0x37')](_0x1593de['tags'])){_0x1593de[_0xdb94('0x24')]=_0x1593de['tags'][_0xdb94('0x38')]();}logger[_0xdb94('0x2f')]('[CmContact][merge]\x20to\x20%s\x20from\x20%s',_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')][_0xdb94('0x39')]);return db['CmHopper'][_0xdb94('0x19')]({'where':{'ContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')][_0xdb94('0x39')]]}})[_0xdb94('0x18')](function(_0x4d789d){logger[_0xdb94('0x2f')](_0xdb94('0x3a'),_0x4d789d);return db[_0xdb94('0x3b')][_0xdb94('0x19')]({'where':{'ContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')]['from']]}})[_0xdb94('0x18')](function(_0x1c46a7){logger[_0xdb94('0x2f')]('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x1c46a7);return db[_0xdb94('0x23')]['create'](_0x1593de);});});}})[_0xdb94('0x18')](function(_0x4def80){if(_0x4def80){_0x37fe6d=_0x4def80;_0x2e7ea9={'ContactId':_0x37fe6d['id']};_0x236c55={'where':{'ContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')][_0xdb94('0x39')]]}};return db['ChatInteraction'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['ChatMessage'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3c')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3d')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['MailMessage'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3d')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3e')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3f')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x40')]['update'](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x41')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['FaxMessage']['update'](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x42')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x43')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x44')][_0xdb94('0x17')]({'CmContactId':_0x37fe6d['id']},{'where':{'CmContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')]['from']]}});}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x45')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x46')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['ReportAgentPreview'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db['VoiceCallReport'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['ChatQueueReport'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x47')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['MailQueueReport']['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x48')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x49')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x4a')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x4b')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x4c')]['update'](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x4d')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x23')][_0xdb94('0x19')]({'where':{'id':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c['body']['from']]}});}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return _0x37fe6d;}})[_0xdb94('0x18')](respondWithResult(_0x5cb9d6,null))[_0xdb94('0x20')](handleError(_0x5cb9d6,null));};exports[_0xdb94('0x4e')]=function(_0x5f5d6e,_0x53d900){return db[_0xdb94('0x23')][_0xdb94('0x22')]()[_0xdb94('0x18')](function(_0x1d54e3){if(_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x24')]&&_[_0xdb94('0x37')](_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x24')])){if(_0x5f5d6e[_0xdb94('0x34')]['tags'][_0xdb94('0x26')]){_0x5f5d6e['body'][_0xdb94('0x24')]=_0x5f5d6e['body'][_0xdb94('0x24')]['join'](';')+';';}else{_0x5f5d6e[_0xdb94('0x34')]['tags']=null;}}else{_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x24')]=null;}if(!_['isNil'](_0x5f5d6e['body']['dialTimezone'])){var _0x5d6baf=_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x4f')];if(!_['isNil'](shared['timezones'][_0x5d6baf]))_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x50')]=shared[_0xdb94('0x51')][_0x5d6baf][_0xdb94('0x50')];}return db[_0xdb94('0x23')][_0xdb94('0x4e')](_0x5f5d6e['body'],{'fields':_[_0xdb94('0x25')](_0x1d54e3),'raw':!![]});})[_0xdb94('0x18')](function(_0x472d97){if(_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x52')]){return insertAdditionalPhones(_0x472d97,_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x52')]);}else{return _0x472d97;}})['then'](respondWithResult(_0x53d900,0xc9))[_0xdb94('0x20')](handleError(_0x53d900,null));};exports[_0xdb94('0x53')]=function(_0x5894d4,_0x4cf70b){var _0x26dfda=0x0;var _0x20c72d=0x0;var _0x3656b2=0x0;var _0xe78a79=[];return db[_0xdb94('0x23')][_0xdb94('0x22')]()[_0xdb94('0x18')](function(_0x1700e0){return BPromise['each'](_0x5894d4[_0xdb94('0x34')],function(_0x3f6c70){var _0x322161={'where':{'$or':[]},'defaults':_0x3f6c70,'fields':_[_0xdb94('0x25')](_0x1700e0),'raw':!![]};if(_0x3f6c70[_0xdb94('0x54')]){for(var _0x15ef26=0x0;_0x15ef26<_0x3f6c70[_0xdb94('0x54')][_0xdb94('0x26')];_0x15ef26++){var _0x392ddb={};_0x392ddb[_0x3f6c70['duplicates'][_0x15ef26]]=_0x3f6c70[_0x3f6c70[_0xdb94('0x54')][_0x15ef26]];_0x322161[_0xdb94('0x55')][_0xdb94('0x56')][_0xdb94('0x57')](_0x392ddb);}_0x322161[_0xdb94('0x55')][_0xdb94('0x58')]=_0x3f6c70['ListId'];}return db['CmContact'][_0xdb94('0x59')](_0x322161)[_0xdb94('0x5a')](function(_0x192174,_0x25f195){if(_0x25f195){if(_0x3f6c70[_0xdb94('0x32')](_0xdb94('0x52'))){_0xe78a79[_0xdb94('0x57')]({'contact':_0x192174,'additionalPhones':_0x3f6c70['additionalPhones']});}_0x26dfda++;}else{_0x3656b2++;}})['catch'](function(){_0x20c72d++;});});})['then'](function(_0x4cfb39){if(_0x4cfb39){if(_0xe78a79[_0xdb94('0x26')]>0x0){return new Promise(function(_0x248bf3){var _0x22cd79=[];for(var _0x1ec6f9=0x0;_0x1ec6f9<_0xe78a79[_0xdb94('0x26')];_0x1ec6f9++){_0x22cd79[_0xdb94('0x57')](insertAdditionalPhones(_0xe78a79[_0x1ec6f9][_0xdb94('0x5b')],_0xe78a79[_0x1ec6f9][_0xdb94('0x52')]));}Promise[_0xdb94('0x5c')](_0x22cd79)[_0xdb94('0x18')](function(){_0x248bf3(0x1);});})['then'](function(){return{'success':_0x26dfda,'failure':_0x20c72d,'duplicates':_0x3656b2};});}else{return{'success':_0x26dfda,'failure':_0x20c72d,'duplicates':_0x3656b2};}}})['then'](respondWithResult(_0x4cf70b,0xc9))['catch'](handleError(_0x4cf70b,null));};exports[_0xdb94('0x5d')]=function(_0x371055,_0x32e173){var _0x3a6ee6;return db[_0xdb94('0x23')][_0xdb94('0x22')]()['then'](function(_0x228fb6){return db[_0xdb94('0x23')][_0xdb94('0x5e')]({'where':{'id':_0x371055['params']['id']},'include':[{'model':db['Tag'],'as':_0xdb94('0x5f'),'attributes':['id',_0xdb94('0x60'),'color'],'required':_0x371055[_0xdb94('0x1f')]['tag']?!![]:![]},{'model':db[_0xdb94('0x44')],'as':'Phones','where':{'CmContactId':_0x371055[_0xdb94('0x21')]['id']},'required':![],'include':[{'model':db[_0xdb94('0x61')],'as':_0xdb94('0x62')}]}],'order':[db[_0xdb94('0x63')][_0xdb94('0x64')](_0xdb94('0x65'))],'attributes':_['keys'](_0x228fb6)});})[_0xdb94('0x18')](function(_0x551e5a){if(!_[_0xdb94('0x66')](_0x551e5a)){_0x3a6ee6=_0x551e5a[_0xdb94('0x35')]({'plain':!![]});var _0x5f0291={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x551e5a&&_0x551e5a[_0xdb94('0x58')]){if(_0x551e5a[_0xdb94('0x58')]){_0x5f0291[_0xdb94('0x55')][_0xdb94('0x67')]['push']({'ListId':{'$ne':_0x551e5a['ListId']}});}}return db[_0xdb94('0x2a')][_0xdb94('0x1e')](_0x5f0291);}})[_0xdb94('0x18')](function(_0x3ffd48){if(!_[_0xdb94('0x66')](_0x3ffd48)){return _[_0xdb94('0x68')](_0x3a6ee6,_[_0xdb94('0x69')](_0x3ffd48,function(_0x683597){return util[_0xdb94('0x6a')](_0xdb94('0x6b'),_0x683597['id']);}));}})[_0xdb94('0x18')](handleEntityNotFound(_0x32e173,null))[_0xdb94('0x18')](respondWithResult(_0x32e173,null))[_0xdb94('0x20')](handleError(_0x32e173,null));};exports[_0xdb94('0x17')]=function(_0x31f2c1,_0x3bbe09){var _0x3e1df4;if(_0x31f2c1[_0xdb94('0x34')]['id']){delete _0x31f2c1[_0xdb94('0x34')]['id'];}if(!_[_0xdb94('0x66')](_0x31f2c1['body'][_0xdb94('0x4f')])){var _0x5a7e1f=_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x4f')];if(!_[_0xdb94('0x66')](shared['timezones'][_0x5a7e1f]))_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x50')]=shared['timezones'][_0x5a7e1f][_0xdb94('0x50')];}return db[_0xdb94('0x23')][_0xdb94('0x5e')]({'where':{'id':_0x31f2c1[_0xdb94('0x21')]['id']}})['then'](handleEntityNotFound(_0x3bbe09,null))['then'](saveUpdates(_0x31f2c1[_0xdb94('0x34')],null))[_0xdb94('0x18')](function(_0x2a3279){_0x3e1df4=_0x2a3279;var _0x333dac={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2a3279&&_0x2a3279[_0xdb94('0x58')]){if(_0x2a3279[_0xdb94('0x58')]){_0x333dac[_0xdb94('0x55')]['$and']['push']({'ListId':{'$ne':_0x2a3279['ListId']}});}}return db[_0xdb94('0x2a')]['findAll'](_0x333dac);})[_0xdb94('0x18')](function(_0x1d1b4b){if(_0x1d1b4b){return _[_0xdb94('0x68')](_[_0xdb94('0x6c')](_0x31f2c1[_0xdb94('0x34')],function(_0xbf088c,_0x43f245){return _[_0xdb94('0x27')](_0x43f245,_0xdb94('0x6d'));}),_[_0xdb94('0x69')](_0x1d1b4b,function(_0x38a2ab){return util['format']('cf_%d',_0x38a2ab['id']);}));}})['then'](function(_0x1f9bf0){if(_0x1f9bf0&&!_[_0xdb94('0x6e')](_0x1f9bf0)){var _0x563559=squel[_0xdb94('0x17')]()[_0xdb94('0x6f')](_0xdb94('0x70'))[_0xdb94('0x71')](_0x1f9bf0)['where'](_0xdb94('0x72'),_0x31f2c1['params']['id'])['toParam']();return db[_0xdb94('0x63')][_0xdb94('0x1f')](_0x563559[_0xdb94('0x73')],{'replacements':_0x563559[_0xdb94('0x2e')]});}})['then'](function(){if(_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x74')]&&_0x3e1df4){return db['CmHopper']['update']({'phone':_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x74')],'OrderBy':0x0},{'where':{'ContactId':_0x3e1df4['id']}});}})[_0xdb94('0x18')](function(){return _0x3e1df4;})[_0xdb94('0x18')](respondWithResult(_0x3bbe09,null))[_0xdb94('0x20')](handleError(_0x3bbe09,null));};exports[_0xdb94('0x75')]=function(_0x416769,_0x3bca46){var _0xc8f95e={};var _0x58b06b={};var _0x8fc959;var _0x996f22;return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x416769[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x3bca46,null))[_0xdb94('0x18')](function(_0x1da82d){if(_0x1da82d){_0x8fc959=_0x1da82d;_0x58b06b[_0xdb94('0x77')]=_[_0xdb94('0x25')](db[_0xdb94('0x78')][_0xdb94('0x79')]);_0x58b06b[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x416769[_0xdb94('0x1f')]);_0x58b06b[_0xdb94('0x7a')]=_['intersection'](_0x58b06b['model'],_0x58b06b[_0xdb94('0x1f')]);_0xc8f95e[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x58b06b[_0xdb94('0x77')],qs[_0xdb94('0x7d')](_0x416769[_0xdb94('0x1f')]['fields']));_0xc8f95e[_0xdb94('0x7b')]=_0xc8f95e[_0xdb94('0x7b')][_0xdb94('0x26')]?_0xc8f95e[_0xdb94('0x7b')]:_0x58b06b['model'];_0xc8f95e[_0xdb94('0x7e')]=qs[_0xdb94('0x7f')](_0x416769[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0xc8f95e[_0xdb94('0x55')]=qs['filters'](_['pick'](_0x416769['query'],_0x58b06b[_0xdb94('0x7a')]));if(_0x416769[_0xdb94('0x1f')][_0xdb94('0x80')]){_0xc8f95e['where']=_[_0xdb94('0x33')](_0xc8f95e['where'],{'$or':_[_0xdb94('0x69')](_0xc8f95e[_0xdb94('0x7b')],function(_0x2674b1){var _0x46bb58={};_0x46bb58[_0x2674b1]={'$like':'%'+_0x416769[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x46bb58;})});}_0xc8f95e=_[_0xdb94('0x33')]({},_0xc8f95e,_0x416769['options']);return _0x8fc959[_0xdb94('0x75')](_0xc8f95e);}})[_0xdb94('0x18')](function(_0x44858c){if(_0x44858c){_0x996f22=_0x44858c[_0xdb94('0x26')];if(!_0x416769[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0xc8f95e[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x416769[_0xdb94('0x1f')][_0xdb94('0x13')]);_0xc8f95e[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x416769[_0xdb94('0x1f')]['offset']);}return _0x8fc959['getTags'](_0xc8f95e);}})[_0xdb94('0x18')](function(_0x3ba98d){if(_0x3ba98d){return _0x3ba98d?{'count':_0x996f22,'rows':_0x3ba98d}:null;}})[_0xdb94('0x18')](respondWithResult(_0x3bca46,null))[_0xdb94('0x20')](handleError(_0x3bca46,null));};exports['setTags']=function(_0x38a3c3,_0x128863){if(_0x38a3c3[_0xdb94('0x34')]['id']){delete _0x38a3c3['body']['id'];}return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x38a3c3[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x128863,null))[_0xdb94('0x18')](function(_0x1fab19){if(_0x1fab19){return _0x1fab19[_0xdb94('0x82')](_0x38a3c3[_0xdb94('0x34')]['ids']||[]);}return null;})[_0xdb94('0x18')](respondWithResult(_0x128863,null))['catch'](handleError(_0x128863,null));};exports[_0xdb94('0x83')]=function(_0x50f76f,_0x36e191){var _0x21a825=[];_0x21a825[_0xdb94('0x57')](addAdditionalPhones(_0x50f76f[_0xdb94('0x34')]));Promise['all'](_0x21a825)[_0xdb94('0x18')](function(){_0x21a825=[];_0x21a825[_0xdb94('0x57')](deleteCmHopperPhones(_0x50f76f[_0xdb94('0x34')]['id']));_0x21a825[_0xdb94('0x57')](addCmHopperPhones(_0x50f76f[_0xdb94('0x34')]['id']));Promise['all'](_0x21a825)[_0xdb94('0x18')](function(){return[0x1];})['then'](respondWithResult(_0x36e191,null));});};function addAdditionalPhones(_0x10b9db){var _0x4faecf;return new Promise(function(_0x3169a3){return db['CmContactHasItem'][_0xdb94('0x19')]({'where':{'CmContactId':_0x10b9db['id']}})[_0xdb94('0x18')](function(){db[_0xdb94('0x61')][_0xdb94('0x1e')]({'raw':!![],'attributes':['id',_0xdb94('0x84')]})['then'](function(_0x21b693){var _0x1e5bd3=[];for(var _0x21c234=0x0;_0x21c234<_0x10b9db[_0xdb94('0x85')][_0xdb94('0x26')];_0x21c234++){var _0x44d35c=_0x10b9db['item_types']?_['isNil'](_0x10b9db['item_types'][_0x21c234])?'':_0x10b9db[_0xdb94('0x86')][_0x21c234]:_0x10b9db[_0xdb94('0x85')][_0x21c234]['ItemTypeId']?_0x10b9db[_0xdb94('0x85')][_0x21c234]['ItemTypeId']:'';var _0x45747b=_['isNil'](_0x10b9db[_0xdb94('0x85')][_0x21c234]['description'])?'':_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x87')];var _0x43359e=_0x44d35c+':'+_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x74')]+'ยง'+_0x45747b;if(_[_0xdb94('0x66')](_0x4faecf))_0x4faecf=_0x43359e;else _0x4faecf+=';'+_0x43359e;var _0x24525a=null;var _0x196af6=null;if(_0x10b9db[_0xdb94('0x86')]){if(!_[_0xdb94('0x66')](_0x10b9db[_0xdb94('0x86')][_0x21c234])){_0x196af6=_[_0xdb94('0x5e')](_0x21b693,function(_0x9d863b){return _0x9d863b['id']===_0x10b9db['item_types'][_0x21c234];});if(!_[_0xdb94('0x66')](_0x196af6)){_0x24525a=_0x196af6['OrderBy'];}}}else{if(!_[_0xdb94('0x66')](_0x10b9db['items'][_0x21c234])){_0x196af6=_[_0xdb94('0x5e')](_0x21b693,function(_0x1b2071){return _0x1b2071['id']===_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x88')];});if(!_[_0xdb94('0x66')](_0x196af6)){_0x24525a=_0x21c234;}}}if(_[_0xdb94('0x66')](_0x24525a)){_0x24525a=0x64;}_0x1e5bd3[_0xdb94('0x57')](addAdditionalPhone(_0x10b9db['id'],_0x10b9db[_0xdb94('0x85')][_0x21c234]['phone'],_0x10b9db[_0xdb94('0x86')]?_[_0xdb94('0x66')](_0x10b9db['item_types'][_0x21c234])?null:_0x10b9db[_0xdb94('0x86')][_0x21c234]:_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x88')]?_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x88')]:null,_0x24525a,_0x45747b));}Promise['all'](_0x1e5bd3)['then'](function(){db[_0xdb94('0x23')]['update']({'AdditionalPhones':_0x4faecf},{'where':{'id':_0x10b9db['id']}})[_0xdb94('0x18')](function(){_0x3169a3(0x1);});});});});});}function addAdditionalPhone(_0x4bd1cc,_0x549da3,_0x2c7920,_0x49ad0f,_0x4cc783){return db[_0xdb94('0x44')][_0xdb94('0x5e')]({'where':{'CmContactId':_0x4bd1cc,'item':_0x549da3}})[_0xdb94('0x18')](function(_0x1feae0){if(_0x1feae0)logger[_0xdb94('0x2f')](_0xdb94('0x89'),_0x1feae0);else{db[_0xdb94('0x44')][_0xdb94('0x4e')]({'CmContactId':_0x4bd1cc,'item':_0x549da3,'ItemTypeId':_0x2c7920,'OrderBy':_0x49ad0f,'ItemClass':_0xdb94('0x8a'),'description':_0x4cc783});}});}function deleteCmHopperPhones(_0x249924){return new Promise(function(_0x2de5fe){return db[_0xdb94('0x8b')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x249924}})[_0xdb94('0x18')](function(_0x5d683c){db[_0xdb94('0x8c')][_0xdb94('0x19')]({'where':{'CmHopperId':{'$in':_[_0xdb94('0x69')](_0x5d683c,'id')}}});})[_0xdb94('0x18')](function(){_0x2de5fe(0x1);});});}function addCmHopperPhones(_0xbcfeb6){return new Promise(function(_0x357d29){return db['CmHopper'][_0xdb94('0x1e')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0xbcfeb6}})[_0xdb94('0x18')](function(_0x359cf1){var _0x1f4771=[];_[_0xdb94('0x69')](_0x359cf1,function(_0x543185){_0x1f4771[_0xdb94('0x57')](createCmHopperPhone(_0xbcfeb6,_0x543185['id']));});Promise['all'](_0x1f4771)['then'](function(){_0x357d29(0x1);});});});}function createCmHopperPhone(_0x1c821b,_0x3f32ac){return new Promise(function(_0x101355){db[_0xdb94('0x44')]['findAll']({'raw':!![],'attributes':[_0xdb94('0x8d'),_0xdb94('0x84')],'where':{'CmContactId':_0x1c821b,'ItemClass':_0xdb94('0x8a')},'include':[{'model':db[_0xdb94('0x61')],'attributes':[_0xdb94('0x84')],'as':_0xdb94('0x62')}],'order':[_0xdb94('0x84'),db[_0xdb94('0x63')]['literal'](_0xdb94('0x8e'))]})['then'](function(_0x1ce70b){var _0x3c8dd8=0x1;var _0x1e5711=_[_0xdb94('0x69')](_0x1ce70b,function(_0x3324f4){_0x3324f4[_0xdb94('0x8f')]=_0x3f32ac;_0x3324f4['phone']=_0x3324f4[_0xdb94('0x8d')];_0x3324f4[_0xdb94('0x84')]=_0x3c8dd8;delete _0x3324f4[_0xdb94('0x90')];_0x3c8dd8=_0x3c8dd8+0x1;return _0x3324f4;});return db[_0xdb94('0x8c')]['bulkCreate'](_0x1e5711,{});})['then'](function(){_0x101355(0x1);});});}function insertAdditionalPhones(_0x5266a2,_0x448417){return new Promise(function(_0xf6465d){var _0xcb545=[];for(var _0x4c9e36=0x0;_0x4c9e36<_0x448417[_0xdb94('0x26')];_0x4c9e36++){var _0x5cbf1a=_0x448417[_0x4c9e36];_0xcb545['push'](parseContactItemType(_0x5cbf1a));}Promise['all'](_0xcb545)[_0xdb94('0x18')](function(){var _0x22169c={'id':_0x5266a2['id'],'items':_0x448417};return addAdditionalPhones(_0x22169c)['then'](function(){return addCmHopperPhones(_0x5266a2['id']);});})[_0xdb94('0x18')](function(){_0xf6465d(_0x5266a2);});});}function parseContactItemType(_0xcd661){return new Promise(function(_0x5b1069){if(_0xcd661['hasOwnProperty'](_0xdb94('0x88'))){_0x5b1069(_0xcd661);}else{return db[_0xdb94('0x61')][_0xdb94('0x5e')]({'where':{'name':_0xcd661[_0xdb94('0x62')]}})['then'](function(_0x6b6190){if(_[_0xdb94('0x66')](_0x6b6190))_0xcd661[_0xdb94('0x88')]=null;else _0xcd661['ItemTypeId']=_0x6b6190['id'];_0x5b1069(_0xcd661);});}});}exports[_0xdb94('0x91')]=function(_0x22ff73,_0x3218b7){return db[_0xdb94('0x44')][_0xdb94('0x1e')]({'raw':!![],'where':{'CmContactId':_0x22ff73[_0xdb94('0x21')]['id'],'ItemClass':_0xdb94('0x8a')},'include':[{'model':db[_0xdb94('0x61')],'as':'ItemType'}],'order':[['OrderBy'],[db['sequelize'][_0xdb94('0x64')](_0xdb94('0x8e'))]]})[_0xdb94('0x18')](function(_0x54ee3d){return _0x54ee3d;})[_0xdb94('0x18')](respondWithResult(_0x3218b7,null))['catch'](handleError(_0x3218b7,null));};exports[_0xdb94('0x92')]=function(_0x454bae,_0x5d3f66){return db['CmContactHasItem']['findAll']({'raw':!![],'where':{'CmContactId':_0x454bae[_0xdb94('0x34')][_0xdb94('0x93')]}})[_0xdb94('0x18')](function(_0x173f98){var _0x3487ce=_['map'](_0x173f98,function(_0x28742e){_0x28742e[_0xdb94('0x94')]=_0x454bae[_0xdb94('0x34')][_0xdb94('0x95')];return _0x28742e;});return db[_0xdb94('0x44')][_0xdb94('0x53')](_0x3487ce,{});})[_0xdb94('0x18')](function(){return addCmHopperPhones(_0x454bae[_0xdb94('0x34')][_0xdb94('0x95')]);})[_0xdb94('0x18')](function(){return['ok'];})[_0xdb94('0x18')](respondWithResult(_0x5d3f66,null))[_0xdb94('0x20')](handleError(_0x5d3f66,null));};exports['rescheduleAdditionalPhones']=function(_0x404fb6,_0x11ec5f){var _0x15f845=[];_0x15f845[_0xdb94('0x57')](createCmHopperPhone(_0x404fb6[_0xdb94('0x34')]['id'],_0x404fb6['body'][_0xdb94('0x96')]));Promise[_0xdb94('0x5c')](_0x15f845)[_0xdb94('0x18')](function(){return[0x1];})[_0xdb94('0x18')](respondWithResult(_0x11ec5f,null));};exports[_0xdb94('0x97')]=function(_0x39b8ba,_0x210343){var _0x215997={'raw':![],'where':{}};var _0x269cd4={};var _0x48c9da={'count':0x0,'rows':[]};return db[_0xdb94('0x23')]['findOne']({'where':{'id':_0x39b8ba[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x210343,null))['then'](function(_0x23f35e){if(_0x23f35e){_0x269cd4[_0xdb94('0x77')]=_[_0xdb94('0x25')](db['CmHopper'][_0xdb94('0x79')]);_0x269cd4[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x39b8ba[_0xdb94('0x1f')]);_0x269cd4[_0xdb94('0x7a')]=_[_0xdb94('0x7c')](_0x269cd4[_0xdb94('0x77')],_0x269cd4['query']);_0x215997[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x269cd4['model'],qs[_0xdb94('0x7d')](_0x39b8ba['query'][_0xdb94('0x7d')]));_0x215997[_0xdb94('0x7b')]=_0x215997[_0xdb94('0x7b')][_0xdb94('0x26')]?_0x215997[_0xdb94('0x7b')]:_0x269cd4[_0xdb94('0x77')];if(!_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0x215997['limit']=qs[_0xdb94('0x13')](_0x39b8ba['query'][_0xdb94('0x13')]);_0x215997['offset']=qs[_0xdb94('0x11')](_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x215997[_0xdb94('0x7e')]=qs[_0xdb94('0x7f')](_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0x215997[_0xdb94('0x55')]=qs[_0xdb94('0x7a')](_[_0xdb94('0x98')](_0x39b8ba['query'],_0x269cd4[_0xdb94('0x7a')]));_0x215997[_0xdb94('0x55')][_0xdb94('0x99')]=_0x23f35e['id'];if(_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x215997[_0xdb94('0x55')]=_[_0xdb94('0x33')](_0x215997[_0xdb94('0x55')],{'$or':_[_0xdb94('0x69')](_0x215997[_0xdb94('0x7b')],function(_0x350bf8){var _0x45821f={};_0x45821f[_0x350bf8]={'$like':'%'+_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x45821f;})});}_0x215997=_[_0xdb94('0x33')]({},_0x215997,_0x39b8ba[_0xdb94('0x9a')]);return db[_0xdb94('0x8b')][_0xdb94('0x14')]({'where':_0x215997['where']})[_0xdb94('0x18')](function(_0x5015f){_0x48c9da[_0xdb94('0x14')]=_0x5015f;if(_0x39b8ba[_0xdb94('0x1f')]['includeAll']){_0x215997[_0xdb94('0x9b')]=[{'all':!![]}];}return db[_0xdb94('0x8b')][_0xdb94('0x1e')](_0x215997);})[_0xdb94('0x18')](function(_0xc08a68){_0x48c9da[_0xdb94('0x9c')]=_0xc08a68;return _0x48c9da;});}})['then'](respondWithFilteredResult(_0x210343,_0x215997))[_0xdb94('0x20')](handleError(_0x210343,null));};exports[_0xdb94('0x9d')]=function(_0x2e04e3,_0xbe8234){var _0x350761={'raw':!![],'where':{}};var _0x4081a1={};var _0x195c90={'count':0x0,'rows':[]};return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x2e04e3[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0xbe8234,null))['then'](function(_0x1a13b9){if(_0x1a13b9){_0x4081a1['model']=_['keys'](db[_0xdb94('0x46')][_0xdb94('0x79')]);_0x4081a1[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x2e04e3[_0xdb94('0x1f')]);_0x4081a1[_0xdb94('0x7a')]=_['intersection'](_0x4081a1[_0xdb94('0x77')],_0x4081a1[_0xdb94('0x1f')]);_0x350761[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x4081a1[_0xdb94('0x77')],qs[_0xdb94('0x7d')](_0x2e04e3['query'][_0xdb94('0x7d')]));_0x350761[_0xdb94('0x7b')]=_0x350761[_0xdb94('0x7b')][_0xdb94('0x26')]?_0x350761[_0xdb94('0x7b')]:_0x4081a1[_0xdb94('0x77')];if(!_0x2e04e3[_0xdb94('0x1f')]['hasOwnProperty'](_0xdb94('0x81'))){_0x350761[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x13')]);_0x350761[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x350761['order']=qs[_0xdb94('0x7f')](_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0x350761[_0xdb94('0x55')]=qs[_0xdb94('0x7a')](_['pick'](_0x2e04e3[_0xdb94('0x1f')],_0x4081a1['filters']));_0x350761[_0xdb94('0x55')]['ContactId']=_0x1a13b9['id'];if(_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x350761['where']=_['merge'](_0x350761[_0xdb94('0x55')],{'$or':_[_0xdb94('0x69')](_0x350761[_0xdb94('0x7b')],function(_0x13b8fa){var _0x477a63={};_0x477a63[_0x13b8fa]={'$like':'%'+_0x2e04e3[_0xdb94('0x1f')]['filter']+'%'};return _0x477a63;})});}_0x350761=_[_0xdb94('0x33')]({},_0x350761,_0x2e04e3['options']);return db[_0xdb94('0x46')][_0xdb94('0x14')]({'where':_0x350761[_0xdb94('0x55')]})[_0xdb94('0x18')](function(_0x4f4109){_0x195c90[_0xdb94('0x14')]=_0x4f4109;if(_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x9e')]){_0x350761[_0xdb94('0x9b')]=[{'all':!![]}];}return db[_0xdb94('0x46')][_0xdb94('0x1e')](_0x350761);})[_0xdb94('0x18')](function(_0x791e36){_0x195c90[_0xdb94('0x9c')]=_0x791e36;return _0x195c90;});}})[_0xdb94('0x18')](respondWithFilteredResult(_0xbe8234,_0x350761))[_0xdb94('0x20')](handleError(_0xbe8234,null));};exports[_0xdb94('0x9f')]=function(_0x243de5,_0x14d124){var _0x40d014={'raw':!![],'where':{}};var _0x4ece04={};var _0x40054e={'count':0x0,'rows':[]};return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x243de5[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x14d124,null))[_0xdb94('0x18')](function(_0x4818f7){if(_0x4818f7){_0x4ece04[_0xdb94('0x77')]=_[_0xdb94('0x25')](db[_0xdb94('0x45')][_0xdb94('0x79')]);_0x4ece04['query']=_[_0xdb94('0x25')](_0x243de5[_0xdb94('0x1f')]);_0x4ece04[_0xdb94('0x7a')]=_[_0xdb94('0x7c')](_0x4ece04[_0xdb94('0x77')],_0x4ece04['query']);_0x40d014[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x4ece04[_0xdb94('0x77')],qs['fields'](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x7d')]));_0x40d014[_0xdb94('0x7b')]=_0x40d014['attributes']['length']?_0x40d014['attributes']:_0x4ece04[_0xdb94('0x77')];if(!_0x243de5['query'][_0xdb94('0x32')](_0xdb94('0x81'))){_0x40d014['limit']=qs[_0xdb94('0x13')](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x13')]);_0x40d014['offset']=qs['offset'](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x40d014[_0xdb94('0x7e')]=qs['sort'](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0x40d014['where']=qs[_0xdb94('0x7a')](_[_0xdb94('0x98')](_0x243de5[_0xdb94('0x1f')],_0x4ece04['filters']));_0x40d014[_0xdb94('0x55')][_0xdb94('0x99')]=_0x4818f7['id'];if(_0x243de5[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x40d014[_0xdb94('0x55')]=_[_0xdb94('0x33')](_0x40d014['where'],{'$or':_[_0xdb94('0x69')](_0x40d014[_0xdb94('0x7b')],function(_0x1f5328){var _0x5be65c={};_0x5be65c[_0x1f5328]={'$like':'%'+_0x243de5[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x5be65c;})});}_0x40d014=_[_0xdb94('0x33')]({},_0x40d014,_0x243de5[_0xdb94('0x9a')]);return db[_0xdb94('0x45')][_0xdb94('0x14')]({'where':_0x40d014[_0xdb94('0x55')]})['then'](function(_0x2f53d3){_0x40054e[_0xdb94('0x14')]=_0x2f53d3;if(_0x243de5['query']['includeAll']){_0x40d014['include']=[{'all':!![]}];}return db[_0xdb94('0x45')][_0xdb94('0x1e')](_0x40d014);})[_0xdb94('0x18')](function(_0x564abf){_0x40054e[_0xdb94('0x9c')]=_0x564abf;return _0x40054e;});}})[_0xdb94('0x18')](respondWithFilteredResult(_0x14d124,_0x40d014))[_0xdb94('0x20')](handleError(_0x14d124,null));};exports['getJscriptySessions']=function(_0x117e9f,_0xfb2007){var _0x2fea6d={'raw':!![],'where':{}};var _0x480790={};var _0x3c48f4={'count':0x0,'rows':[]};return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x117e9f['params']['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0xfb2007,null))['then'](function(_0x51d1ed){if(_0x51d1ed){_0x480790['model']=_['keys'](db[_0xdb94('0x4a')][_0xdb94('0x79')]);_0x480790[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x117e9f[_0xdb94('0x1f')]);_0x480790[_0xdb94('0x7a')]=_[_0xdb94('0x7c')](_0x480790[_0xdb94('0x77')],_0x480790[_0xdb94('0x1f')]);_0x2fea6d['attributes']=_[_0xdb94('0x7c')](_0x480790['model'],qs[_0xdb94('0x7d')](_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x7d')]));_0x2fea6d[_0xdb94('0x7b')]=_0x2fea6d[_0xdb94('0x7b')][_0xdb94('0x26')]?_0x2fea6d['attributes']:_0x480790['model'];if(!_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0x2fea6d[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x117e9f[_0xdb94('0x1f')]['limit']);_0x2fea6d[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x2fea6d[_0xdb94('0x7e')]=qs[_0xdb94('0x7f')](_0x117e9f['query'][_0xdb94('0x7f')]);_0x2fea6d[_0xdb94('0x55')]=qs[_0xdb94('0x7a')](_[_0xdb94('0x98')](_0x117e9f[_0xdb94('0x1f')],_0x480790[_0xdb94('0x7a')]));_0x2fea6d['where'][_0xdb94('0x99')]=_0x51d1ed['id'];if(_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x2fea6d[_0xdb94('0x55')]=_[_0xdb94('0x33')](_0x2fea6d[_0xdb94('0x55')],{'$or':_[_0xdb94('0x69')](_0x2fea6d['attributes'],function(_0x17f28c){var _0x32e32a={};_0x32e32a[_0x17f28c]={'$like':'%'+_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x32e32a;})});}_0x2fea6d=_[_0xdb94('0x33')]({},_0x2fea6d,_0x117e9f[_0xdb94('0x9a')]);return db[_0xdb94('0x4a')][_0xdb94('0x14')]({'where':_0x2fea6d[_0xdb94('0x55')]})[_0xdb94('0x18')](function(_0x55d3ab){_0x3c48f4[_0xdb94('0x14')]=_0x55d3ab;if(_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x9e')]){_0x2fea6d[_0xdb94('0x9b')]=[{'all':!![]}];}return db['JscriptySessionReport'][_0xdb94('0x1e')](_0x2fea6d);})['then'](function(_0x160178){_0x3c48f4['rows']=_0x160178;return _0x3c48f4;});}})[_0xdb94('0x18')](respondWithFilteredResult(_0xfb2007,_0x2fea6d))[_0xdb94('0x20')](handleError(_0xfb2007,null));};exports[_0xdb94('0xa0')]=function(_0x46661c,_0x30f04c){try{if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0x58')]){throw new Error('No\x20ListId\x20specified');}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0xa1')]){throw new Error('No\x20association\x20keys\x20specified!');}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0xa2')]){throw new Error(_0xdb94('0xa3'));}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0xa4')]){throw new Error(_0xdb94('0xa5'));}var _0x20d0b0=_0x46661c['body'][_0xdb94('0xa1')][_0xdb94('0xa6')](',');var _0x4ce05e=_0x46661c[_0xdb94('0x34')][_0xdb94('0xa2')][_0xdb94('0xa6')](',');if(!_0x20d0b0[_0xdb94('0x26')]||!_0x4ce05e['length']||_0x20d0b0[_0xdb94('0x26')]!==_0x4ce05e[_0xdb94('0x26')]){throw new Error(_0xdb94('0xa7'));}_0x46661c[_0xdb94('0x34')]['fields']=_['zipObject'](_0x20d0b0,_0x4ce05e);if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0x7d')][_0xdb94('0x74')]){throw new Error(_0xdb94('0xa8'));}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0x7d')][_0xdb94('0xa9')]){throw new Error(_0xdb94('0xaa'));}var _0x3c5db9=path[_0xdb94('0x38')](config[_0xdb94('0xab')],_0xdb94('0xac'),_0x46661c[_0xdb94('0xad')]['filename']);fs['chmodSync'](_0x3c5db9,parseInt('0777',0x8));var _0xe04dea=require(_0xdb94('0xae'))[_0xdb94('0xaf')](path['join'](__dirname,_0xdb94('0xb0')),[_0x3c5db9,_0x46661c[_0xdb94('0x34')][_0xdb94('0xa1')],_0x46661c[_0xdb94('0x34')][_0xdb94('0xa2')],_0x46661c['body'][_0xdb94('0x58')],_0x46661c['body'][_0xdb94('0xb1')],_0x46661c['body'][_0xdb94('0x54')],_0x46661c[_0xdb94('0x34')][_0xdb94('0xa4')]]);return _0x30f04c[_0xdb94('0xf')](0xc8)['json']({'message':_0xdb94('0xb2'),'pid':_0xe04dea[_0xdb94('0xb3')]});}catch(_0x40d6fd){return _0x30f04c[_0xdb94('0xf')](0x1f4)['send'](_0x40d6fd);}};exports[_0xdb94('0xb4')]=function(_0x357a12,_0x2b3d3f){var _0x1b8197=fs['createReadStream'](_0x357a12[_0xdb94('0xad')]['path']);Papa['parse'](_0x1b8197,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x5824cc){return _0x2b3d3f['status'](0xc8)[_0xdb94('0x10')]({'file':_0x357a12[_0xdb94('0xad')],'fields':_0x5824cc[_0xdb94('0xb5')]['fields']});}});};exports[_0xdb94('0xb6')]=function(_0x2cfab7,_0x497cf6){return db[_0xdb94('0xb7')][_0xdb94('0x1e')]({'raw':!![],'attributes':['id'],'where':{'role':_0xdb94('0xb8')}})[_0xdb94('0x18')](function(_0x2bb0d8){var _0x431f29=![];if(!_0x2cfab7[_0xdb94('0x34')][_0xdb94('0x58')]){throw new Error(_0xdb94('0xb9'));}if(!_0x2cfab7[_0xdb94('0x34')]['binding'][_0xdb94('0x74')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x2cfab7[_0xdb94('0x34')][_0xdb94('0xba')][_0xdb94('0xa9')]){throw new Error(_0xdb94('0xaa'));}if(!_0x2cfab7['body'][_0xdb94('0xa4')]){throw new Error(_0xdb94('0xa5'));}var _0x3676ba=require(_0xdb94('0xae'))[_0xdb94('0xaf')](path[_0xdb94('0x38')](__dirname,_0xdb94('0xbb')),[_0x2cfab7[_0xdb94('0x21')]['id'],JSON['stringify'](_0x2cfab7[_0xdb94('0x34')]),JSON[_0xdb94('0xbc')](_0x2bb0d8)]);_0x3676ba['on'](_0xdb94('0xbd'),function(){_0x431f29=!![];return _0x497cf6[_0xdb94('0xf')](0xc8)[_0xdb94('0x10')]({'message':'start\x20child\x20process\x20correctly!','pid':_0x3676ba[_0xdb94('0xb3')]});});_0x3676ba['on'](_0xdb94('0xbe'),function(_0x2fb36c){if(_0x2fb36c&&!_0x431f29){return _0x497cf6[_0xdb94('0xf')](0x1f4)[_0xdb94('0x10')]({'message':_0xdb94('0xbf'),'pid':_0x3676ba['pid']});}});})[_0xdb94('0x20')](handleError(_0x497cf6,null));};exports[_0xdb94('0xc0')]=function(_0x39f7f6,_0x1ae6f4){return db['User']['findAll']({'raw':!![],'attributes':['id'],'where':{'role':_0xdb94('0xb8')}})[_0xdb94('0x18')](function(_0x30363f){var _0x5545cd=![];if(!_0x39f7f6['body'][_0xdb94('0x58')]){throw new Error(_0xdb94('0xb9'));}if(!_0x39f7f6[_0xdb94('0x34')][_0xdb94('0xba')][_0xdb94('0x74')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x39f7f6[_0xdb94('0x34')][_0xdb94('0xba')][_0xdb94('0xa9')]){throw new Error(_0xdb94('0xaa'));}if(!_0x39f7f6[_0xdb94('0x34')][_0xdb94('0xa4')]){throw new Error(_0xdb94('0xa5'));}var _0x44bbf2=require(_0xdb94('0xae'))[_0xdb94('0xaf')](path[_0xdb94('0x38')](__dirname,_0xdb94('0xc1')),[_0x39f7f6[_0xdb94('0x21')]['id'],JSON[_0xdb94('0xbc')](_0x39f7f6[_0xdb94('0x34')]),JSON['stringify'](_0x30363f)]);_0x44bbf2['on'](_0xdb94('0xbd'),function(){_0x5545cd=!![];return _0x1ae6f4['status'](0xc8)[_0xdb94('0x10')]({'message':'start\x20child\x20process\x20correctly!','pid':_0x44bbf2[_0xdb94('0xb3')]});});_0x44bbf2['on'](_0xdb94('0xbe'),function(_0x4dc8a8){if(_0x4dc8a8&&!_0x5545cd){return _0x1ae6f4[_0xdb94('0xf')](0x1f4)[_0xdb94('0x10')]({'message':_0xdb94('0xbf'),'pid':_0x44bbf2[_0xdb94('0xb3')]});}});})[_0xdb94('0x20')](handleError(_0x1ae6f4,null));};exports[_0xdb94('0xc2')]=function(_0x1f1ea3,_0x2128f6){var _0x13e689=['mail',_0xdb94('0xc3'),'sms',_0xdb94('0xc4'),_0xdb94('0xc5'),'whatsapp',_0xdb94('0xc6')];var _0x6e0474={'offset':0x0,'order':qs['sort'](_0xdb94('0xc7'))},_0x265782={'count':0x0,'rows':[]};Promise[_0xdb94('0xc8')]()[_0xdb94('0x18')](function(){if(_0x1f1ea3[_0xdb94('0x1f')]['channel']){if(!_[_0xdb94('0xc9')](_0x13e689,_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0xca')][_0xdb94('0xcb')]())){throw new Error(_0xdb94('0xcc'));}_0x13e689=[_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0xca')][_0xdb94('0xcb')]()];}if(_0x1f1ea3[_0xdb94('0x1f')]['range']){try{var _0x4042e2=JSON['parse'](_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0xcd')]);if(!moment(_0x4042e2['from'])[_0xdb94('0xce')]()){throw new Error(_0xdb94('0xcf'));}if(!moment(_0x4042e2['to'])['isValid']()){throw new Error('Invalid\x20date\x20for\x20range\x20to\x20filter');}}catch(_0x5f599f){throw new Error(_0xdb94('0xd0'));}}if(!_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0x6e0474[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0x13')]||0xa);_0x6e0474[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0x11')]);}var _0x254fb0=_0x13e689[_0xdb94('0x69')](function(_0x28c17c){if(_0x28c17c===_0xdb94('0xc6')){var _0x2b5eb1={'attributes':['id',_0xdb94('0xd1'),_0xdb94('0x2d'),_0xdb94('0xd2'),_0xdb94('0xd3'),_0xdb94('0xd4'),_0xdb94('0xd5'),_0xdb94('0xd6'),_0xdb94('0xd7'),_0xdb94('0xd8'),_0xdb94('0xd9'),_0xdb94('0xda'),_0xdb94('0xdb'),_0xdb94('0xdc'),'UserId'],'where':{'ContactId':_0x1f1ea3[_0xdb94('0x21')]['id']},'include':[{'model':db[_0xdb94('0xb7')],'as':'User','attributes':['id','name','fullname',_0xdb94('0x2c')]}],'order':[[_0xdb94('0xd9'),'DESC']]};if(_0x1f1ea3[_0xdb94('0x1f')]['range']){_0x2b5eb1['where'][_0xdb94('0xd9')]={'$gte':_0x4042e2['from'],'$lte':_0x4042e2['to']};}return db[_0xdb94('0xdd')][_0xdb94('0xde')](_0x2b5eb1)[_0xdb94('0x18')](function(_0x3aee7c){_0x265782['count']+=_0x3aee7c[_0xdb94('0x14')];return _[_0xdb94('0x69')](_0x3aee7c['rows'],function(_0x336902){var _0x4c8e62=_0x336902[_0xdb94('0x35')]({'plain':!![]});_0x4c8e62['channel']=_0x28c17c;if(_0x4c8e62[_0xdb94('0xb7')]){_0x4c8e62[_0xdb94('0xb7')]={'id':_0x4c8e62[_0xdb94('0xb7')]['id'],'name':_0x4c8e62[_0xdb94('0xb7')]['name'],'fullname':_0x4c8e62[_0xdb94('0xb7')]['fullname'],'alias':_0x4c8e62['User'][_0xdb94('0x2c')]};}return _0x4c8e62;});});}else{var _0x2fd3cf=_[_0xdb94('0xdf')](_0x28c17c)+(_0x28c17c===_0xdb94('0xc3')?_0xdb94('0xe0'):'Account');var _0x597af9={'attributes':['id',_0xdb94('0xe1'),_0xdb94('0xe2'),_0xdb94('0xd9'),_0xdb94('0xd8'),_0xdb94('0xe3'),_0xdb94('0xe4'),_0xdb94('0xe5'),_0xdb94('0xe6'),_0x2fd3cf+'Id'],'where':{'ContactId':_0x1f1ea3[_0xdb94('0x21')]['id']},'include':[{'model':db[_0x2fd3cf],'as':_0xdb94('0xe7'),'attributes':['id',_0xdb94('0x60'),_0xdb94('0xe8')]},{'model':db[_0xdb94('0xb7')],'as':_0xdb94('0xe9'),'attributes':['id','name','fullname']},{'model':db['Tag'],'as':'Tags','attributes':['id','name',_0xdb94('0xea')],'through':{'attributes':[]}}],'order':[[_0xdb94('0xd9'),_0xdb94('0xeb')]]};if(_0x1f1ea3[_0xdb94('0x1f')]['range']){_0x597af9[_0xdb94('0x55')][_0xdb94('0xd9')]={'$gte':_0x4042e2[_0xdb94('0x39')],'$lte':_0x4042e2['to']};}switch(_0x28c17c){case _0xdb94('0xc3'):_0x597af9[_0xdb94('0x7b')]['push'](_0xdb94('0xec'),_0xdb94('0xed'),_0xdb94('0xee'),_0xdb94('0xef'),'osName',_0xdb94('0xf0'),_0xdb94('0xf1'),'ratingValue','referer');break;case _0xdb94('0xf2'):_0x597af9[_0xdb94('0x7b')][_0xdb94('0x57')](_0xdb94('0xf3'),'substatus');break;case'openchannel':_0x597af9[_0xdb94('0x7b')]['push'](_0xdb94('0xf4'),_0xdb94('0xf5'));break;}return db[_[_0xdb94('0xdf')](_0x28c17c)+'Interaction'][_0xdb94('0xde')](_0x597af9)[_0xdb94('0x18')](function(_0x4ef47e){_0x265782['count']+=_0x4ef47e[_0xdb94('0x14')];return _[_0xdb94('0x69')](_0x4ef47e[_0xdb94('0x9c')],function(_0x303e39){var _0x114c1a=_0x303e39[_0xdb94('0x35')]({'plain':!![]});_0x114c1a[_0xdb94('0xca')]=_0x28c17c;if(_0x114c1a[_0xdb94('0xe9')]){_0x114c1a[_0xdb94('0xe9')]={'id':_0x114c1a[_0xdb94('0xe9')]['id'],'name':_0x114c1a[_0xdb94('0xe9')][_0xdb94('0x60')],'fullname':_0x114c1a[_0xdb94('0xe9')][_0xdb94('0xf6')]};}return _0x114c1a;});});}});return Promise['all'](_0x254fb0);})[_0xdb94('0x18')](function(_0x5220f8){return _(_0x5220f8)[_0xdb94('0xf7')]()[_0xdb94('0xf8')]('createdAt')['reverse']()[_0xdb94('0xf9')]();})[_0xdb94('0x18')](function(_0x19e647){_0x265782['rows']=_0x6e0474[_0xdb94('0x13')]?_0x19e647[_0xdb94('0xfa')](_0x6e0474[_0xdb94('0x11')],_0x6e0474[_0xdb94('0x11')]+_0x6e0474[_0xdb94('0x13')]):_0x19e647;return _0x265782;})[_0xdb94('0x18')](respondWithFilteredResult(_0x2128f6,_0x6e0474))[_0xdb94('0x20')](handleError(_0x2128f6,null));};
\ No newline at end of file