Built motion from commit (unavailable).|2.5.30
[motion2.git] / server / api / cmContact / cmContact.controller.js
index af32d50..a0e15d9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x814b=['JscriptySessionReport','create','join','bulkCreate','each','duplicates','$or','findOrCreate','show','get','ListId','omit','cf_%d','pickBy','format','table','id\x20=\x20?','toParam','values','phone','getTags','rawAttributes','options','nolimit','setTags','ids','getHoppers','rows','getHopperHistories','ContactId','CmHopperHistory','includeAll','getHopperFinals','include','getJscriptySessions','binding_keys','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Incorrect\x20binding\x20parameters\x20passed!','zipObject','No\x20phone\x20column\x20specified','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','0777','fork','pid','send','upload','createReadStream','parse','import','No\x20ListId\x20specified','binding','firstName','child_process','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','getJourney','mail','chat','sms','openchannel','fax','whatsapp','voice','-createdAt','channel','includes','Invalid\x20channel','toLowerCase','range','Invalid\x20date\x20for\x20range\x20from\x20filter','isValid','Invalid\x20date\x20for\x20range\x20to\x20filter','source','destination','endtime','duration','createdAt','userDisposition','userThirdDisposition','fullname','VoiceCallReport','findAndCountAll','startCase','Website','Account','closed','closedAt','note','secondDisposition','UserId','key','Owner','color','browserName','customerIp','customerPort','deviceModel','osName','ratingMessage','ratingType','referer','subject','substatus','externalUrl','Interaction','sortBy','reverse','slice','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','register','sendStatus','status','end','json','offset','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','index','describe','keys','startsWith','CmCustomField','findOne','cf_','all','length','fieldType','type','query','filters','model','intersection','fields','attributes','hasOwnProperty','limit','order','sort','where','pick','select','field','tools_tags','cm_contacts','left_join','cm_user_has_contacts','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','ct.CmContactId\x20=\x20c.id','t.id\x20=\x20ct.TagId','expr','search','sqlOperator','conditions','find','Tag','value','split','map','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','and','uc.UserId\x20=\x20?','dateOfBirth','datetime','DATE','buildExpression','text','start','filter','isNil','Contact','isEmpty','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','replace','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.lastName\x20LIKE\x20?','group','c.id','QueryTypes','clone','DESC','having','t.id\x20IN\x20?','resolve','user','agent','some','User','c.ListId\x20IS\x20NULL','c.ListId\x20IN\x20?','role','count','sequelize','keyBy','merge','c.firstName','c.lastName','c.phone','c.mobile','c.fax','c.email','c.ListId','c.CompanyId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','push','CmContact','params','catch','tags','findAll','displayName','alias','custom','columnName','body','from','mergeWith','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','ChatInteraction','update','ChatOfflineMessage','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelInteraction','OpenchannelMessage','CmHopperFinal','ChatQueueReport','FaxQueueReport','MailQueueReport','SmsQueueReport'];(function(_0x21f337,_0x3de878){var _0xa34f0b=function(_0x2be72c){while(--_0x2be72c){_0x21f337['push'](_0x21f337['shift']());}};_0xa34f0b(++_0x3de878);}(_0x814b,0x1a2));var _0xb814=function(_0x242c29,_0x168f0a){_0x242c29=_0x242c29-0x0;var _0x3f4d1c=_0x814b[_0x242c29];return _0x3f4d1c;};'use strict';var pdf=require(_0xb814('0x0'));var emlformat=require(_0xb814('0x1'));var rimraf=require(_0xb814('0x2'));var zipdir=require(_0xb814('0x3'));var jsonpatch=require(_0xb814('0x4'));var rp=require(_0xb814('0x5'));var moment=require('moment');var BPromise=require(_0xb814('0x6'));var Mustache=require(_0xb814('0x7'));var util=require(_0xb814('0x8'));var path=require(_0xb814('0x9'));var sox=require(_0xb814('0xa'));var csv=require(_0xb814('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xb814('0xc'));var squel=require(_0xb814('0xd'));var crypto=require('crypto');var jsforce=require(_0xb814('0xe'));var deskjs=require(_0xb814('0xf'));var toCsv=require(_0xb814('0xb'));var querystring=require(_0xb814('0x10'));var Papa=require(_0xb814('0x11'));var Redis=require(_0xb814('0x12'));var authService=require(_0xb814('0x13'));var qs=require(_0xb814('0x14'));var as=require(_0xb814('0x15'));var hardwareService=require(_0xb814('0x16'));var logger=require(_0xb814('0x17'))('api');var utils=require(_0xb814('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0xb814('0x19'));var db=require(_0xb814('0x1a'))['db'];config[_0xb814('0x1b')]=_[_0xb814('0x1c')](config[_0xb814('0x1b')],{'host':_0xb814('0x1d'),'port':0x18eb});var socket=require(_0xb814('0x1e'))(new Redis(config[_0xb814('0x1b')]));require(_0xb814('0x1f'))[_0xb814('0x20')](socket);function respondWithStatusCode(_0x3f4881,_0x44fb96){_0x44fb96=_0x44fb96||0xcc;return function(_0x17f5bd){if(_0x17f5bd){return _0x3f4881[_0xb814('0x21')](_0x44fb96);}return _0x3f4881[_0xb814('0x22')](_0x44fb96)[_0xb814('0x23')]();};}function respondWithResult(_0x45e0d0,_0x265a83){_0x265a83=_0x265a83||0xc8;return function(_0x125ce2){if(_0x125ce2){return _0x45e0d0[_0xb814('0x22')](_0x265a83)[_0xb814('0x24')](_0x125ce2);}};}function respondWithFilteredResult(_0x48c9df,_0x168a48){return function(_0x55ba16){if(_0x55ba16){var _0x270598=_0x55ba16['count'],_0xfac75b=_0x168a48[_0xb814('0x25')],_0x4c3007=_0x168a48['offset']+_0x168a48['limit'],_0x4b55a7;if(_0x4c3007>=_0x270598){_0x4c3007=_0x270598;_0x4b55a7=0xc8;}else{_0x4b55a7=0xce;}_0x48c9df[_0xb814('0x22')](_0x4b55a7);return _0x48c9df[_0xb814('0x26')](_0xb814('0x27'),_0xfac75b+'-'+_0x4c3007+'/'+_0x270598)['json'](_0x55ba16);}return null;};}function patchUpdates(_0xf5b8aa){return function(_0x531032){try{jsonpatch[_0xb814('0x28')](_0x531032,_0xf5b8aa,!![]);}catch(_0x1808a3){return BPromise[_0xb814('0x29')](_0x1808a3);}return _0x531032[_0xb814('0x2a')]();};}function saveUpdates(_0x27352e,_0x2bd039){return function(_0x1f5d40){if(_0x1f5d40){return _0x1f5d40['update'](_0x27352e)[_0xb814('0x2b')](function(_0x52b7a3){return _0x52b7a3;});}return null;};}function removeEntity(_0x3f81d0,_0x457dac){return function(_0x31c7ec){if(_0x31c7ec){return _0x31c7ec[_0xb814('0x2c')]()[_0xb814('0x2b')](function(){_0x3f81d0[_0xb814('0x22')](0xcc)[_0xb814('0x23')]();});}};}function handleEntityNotFound(_0x5755ea,_0x392222){return function(_0xc0ef66){if(!_0xc0ef66){_0x5755ea[_0xb814('0x21')](0x194);}return _0xc0ef66;};}function handleError(_0x349394,_0x32ed56){_0x32ed56=_0x32ed56||0x1f4;return function(_0x1d5965){logger[_0xb814('0x2d')](_0x1d5965[_0xb814('0x2e')]);if(_0x1d5965['name']){delete _0x1d5965[_0xb814('0x2f')];}_0x349394[_0xb814('0x22')](_0x32ed56)['send'](_0x1d5965);};}exports[_0xb814('0x30')]=function(_0x37d24d,_0x530744){var _0x499f22={},_0x20577b={},_0x2051d0={'count':0x0,'rows':[]};return db['CmContact'][_0xb814('0x31')]()['then'](function(_0x6efe9a){var _0x5f3e9b=[];for(var _0x4cfc58=0x0;_0x4cfc58<Object[_0xb814('0x32')](_0x6efe9a)['length'];_0x4cfc58++){var _0x2431e2=Object[_0xb814('0x32')](_0x6efe9a)[_0x4cfc58];if(_[_0xb814('0x33')](_0x2431e2,'cf_')){_0x5f3e9b['push'](db[_0xb814('0x34')][_0xb814('0x35')]({'where':{'id':_['trimStart'](_0x2431e2,_0xb814('0x36'))},'raw':!![]}));}}return BPromise[_0xb814('0x37')](_0x5f3e9b)[_0xb814('0x2b')](function(_0x217b7e){for(var _0x1b78de=0x0;_0x1b78de<_0x217b7e[_0xb814('0x38')];_0x1b78de++){if(_0x217b7e[_0x1b78de]){var _0x3672f3='cf_'+_0x217b7e[_0x1b78de]['id'];var _0x3207ec=_0x6efe9a[_0x3672f3];_0x3207ec[_0xb814('0x39')]=_0x217b7e[_0x1b78de][_0xb814('0x3a')];}}return _0x6efe9a;});})[_0xb814('0x2b')](function(_0x14100d){_0x20577b['model']=_[_0xb814('0x32')](_0x14100d);_0x20577b['query']=_[_0xb814('0x32')](_0x37d24d[_0xb814('0x3b')]);_0x20577b[_0xb814('0x3c')]=_['intersection'](_0x20577b[_0xb814('0x3d')],_0x20577b[_0xb814('0x3b')]);_0x499f22['attributes']=_[_0xb814('0x3e')](_0x20577b[_0xb814('0x3d')],qs[_0xb814('0x3f')](_0x37d24d[_0xb814('0x3b')][_0xb814('0x3f')]));_0x499f22[_0xb814('0x40')]=_0x499f22['attributes'][_0xb814('0x38')]?_0x499f22['attributes']:_0x20577b[_0xb814('0x3d')];if(!_0x37d24d['query'][_0xb814('0x41')]('nolimit')){_0x499f22[_0xb814('0x42')]=qs[_0xb814('0x42')](_0x37d24d['query']['limit']);_0x499f22['offset']=qs['offset'](_0x37d24d[_0xb814('0x3b')][_0xb814('0x25')]);}_0x499f22[_0xb814('0x43')]=qs[_0xb814('0x44')](_0x37d24d['query']['sort']);_0x499f22[_0xb814('0x45')]=qs['filters'](_[_0xb814('0x46')](_0x37d24d[_0xb814('0x3b')],_0x20577b[_0xb814('0x3c')]),_0x14100d);var _0x3063bf=[];var _0x42653f=squel[_0xb814('0x47')]()[_0xb814('0x48')]('id')[_0xb814('0x48')](_0xb814('0x2f'))['field']('color')['from'](_0xb814('0x49'));var _0x5ba0bc=squel[_0xb814('0x47')]()['from'](_0xb814('0x4a'),'c')[_0xb814('0x4b')](_0xb814('0x4c'),'uc',_0xb814('0x4d'))['left_join'](_0xb814('0x4e'),'ct',_0xb814('0x4f'))[_0xb814('0x4b')](_0xb814('0x49'),'t',_0xb814('0x50'))[_0xb814('0x45')]('c.deletedAt\x20IS\x20NULL');var _0x69f060=squel[_0xb814('0x51')]();var _0x9ffd73=[];var _0x365f9e=squel[_0xb814('0x51')]();var _0x144d37;if(_0x37d24d[_0xb814('0x3b')]['search']){_0x144d37=as['parseSearch'](_0x37d24d[_0xb814('0x3b')][_0xb814('0x52')]);var _0x4c08d6=_0x144d37[_0xb814('0x53')];for(var _0x43f1b=0x0;_0x43f1b<_0x144d37[_0xb814('0x54')][_0xb814('0x38')];_0x43f1b++){var _0x40af85=_0x144d37[_0xb814('0x54')][_0x43f1b];var _0x344198='c';var _0xe73300=_(_0x14100d)['keys']()[_0xb814('0x55')](function(_0x17510c){return _0x17510c===_0x40af85['field'];});if(_0xe73300)_0xe73300=_0x14100d[_0x40af85[_0xb814('0x48')]];if(!_0xe73300){if(_0x40af85['field']===_0xb814('0x56')){var _0x37866f=_0x40af85[_0xb814('0x57')][_0xb814('0x58')](',')[_0xb814('0x59')](function(_0x4096d4){return Number(_0x4096d4);});_0x37866f[_0xb814('0x5a')](function(_0x45480e){_0x365f9e['or'](_0xb814('0x5b'),'%,'+_0x45480e+',%');});_0x9ffd73=_[_0xb814('0x5c')](_0x9ffd73,_0x37866f);}else if(_0x40af85['field']==='User'){_0x69f060[_0xb814('0x5d')](_0xb814('0x5e'),_0x40af85[_0xb814('0x57')]);}}else{if(_0x40af85[_0xb814('0x48')]===_0xb814('0x5f')||_0xe73300[_0xb814('0x39')]===_0xb814('0x60'))_0x40af85['castTo']=_0xb814('0x61');var _0x388324=as[_0xb814('0x62')](_0x344198,_0xe73300['type'],_0x40af85);_0x69f060[_0x4c08d6](_0x388324[_0xb814('0x63')],_0x388324['value'][_0xb814('0x64')],_0x388324['value'][_0xb814('0x23')]);}}}else{var _0x3cf8f8=_(Object['keys'](_0x37d24d[_0xb814('0x3b')]))[_0xb814('0x59')](function(_0x148151){return _0x14100d['hasOwnProperty'](_0x148151)?_0x148151:undefined;})[_0xb814('0x65')](function(_0x5f0e58){return!_[_0xb814('0x66')](_0x5f0e58);})[_0xb814('0x57')]();if(_0x37d24d['query'][_0xb814('0x67')])_0x3cf8f8['push']('Contact');if(!_[_0xb814('0x68')](_0x3cf8f8)){_0x3cf8f8[_0xb814('0x5a')](function(_0x34935b){if(_0x34935b==='ListId'){_0x5ba0bc[_0xb814('0x45')]('c.ListId\x20IN\x20?',[][_0xb814('0x69')](_0x37d24d[_0xb814('0x3b')][_0x34935b]));}else if(_0x34935b==='Contact'){var _0x2db5a6='%'+_0x37d24d['query'][_0x34935b]+'%';_0x5ba0bc[_0xb814('0x45')](_0xb814('0x6a'),_0x2db5a6);}else{_0x5ba0bc[_0xb814('0x45')]('c.'+_0x34935b+_0xb814('0x6b'),_0x37d24d[_0xb814('0x3b')][_0x34935b]);}});}if(_0x37d24d[_0xb814('0x3b')][_0xb814('0x6c')]){_0x9ffd73=_[_0xb814('0x6d')](_0x37d24d['query'][_0xb814('0x6c')])?_0x37d24d[_0xb814('0x3b')]['tag']:new Array(_0x37d24d[_0xb814('0x3b')][_0xb814('0x6c')]);_0x9ffd73['forEach'](function(_0x371000){_0x365f9e['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x371000+',%');});}if(_0x37d24d['query'][_0xb814('0x65')]){var _0x5257be=_0x37d24d[_0xb814('0x3b')][_0xb814('0x65')][_0xb814('0x6e')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(_0x5257be[_0xb814('0x58')]('\x20')['length']>0x1){_0x69f060['or'](_0xb814('0x6f'),qs[_0xb814('0x70')](_0x5257be),null);}else{if(qs[_0xb814('0x71')](_0x5257be)){_0x69f060['or'](_0xb814('0x72'),_0x5257be+'%');_0x69f060['or'](_0xb814('0x73'),_0x5257be+'%');_0x69f060['or'](_0xb814('0x74'),_0x5257be+'%');_0x69f060['or'](_0xb814('0x75'),_0x5257be+'%');}else if(qs[_0xb814('0x76')](_0x5257be)){_0x69f060['or'](_0xb814('0x77'),_0x5257be+'%');}else{_0x69f060['or']('c.firstName\x20LIKE\x20?','%'+_0x5257be+'%');_0x69f060['or'](_0xb814('0x78'),'%'+_0x5257be+'%');_0x69f060['or'](_0xb814('0x77'),'%'+_0x5257be+'%');}}}}_0x5ba0bc[_0xb814('0x45')](_0x69f060);_0x5ba0bc[_0xb814('0x79')](_0xb814('0x7a'));var _0x3d4843={'type':db['Sequelize'][_0xb814('0x7b')]['SELECT'],'raw':!![]};var _0x3cd4f7=_0x5ba0bc[_0xb814('0x7c')]()[_0xb814('0x48')]('c.id');if(_0x499f22[_0xb814('0x43')]){_0x499f22['order'][_0xb814('0x5a')](function(_0x4a65d0){_0x5ba0bc[_0xb814('0x43')]('c.'+_0x4a65d0[0x0],_0x4a65d0[0x1]===_0xb814('0x7d')?![]:!![]);});}if(!_[_0xb814('0x68')](_0x9ffd73)){_0x5ba0bc[_0xb814('0x7e')](_0x365f9e);_0x3cd4f7[_0xb814('0x45')](_0xb814('0x7f'),_0x9ffd73);}BPromise[_0xb814('0x80')]()['then'](function(){if(!_0x144d37)return;if(_0x37d24d[_0xb814('0x81')]['role']!==_0xb814('0x82'))return;if(!_[_0xb814('0x83')](_0x144d37[_0xb814('0x54')],[_0xb814('0x48'),_0xb814('0x84')])){return _0x37d24d[_0xb814('0x81')]['getLists']({'attributes':['id'],'raw':!![]})[_0xb814('0x2b')](function(_0x1a2603){if(_['isEmpty'](_0x1a2603)){_0x3cd4f7[_0xb814('0x45')](_0xb814('0x85'));_0x5ba0bc[_0xb814('0x45')](_0xb814('0x85'));}else{_0x3cd4f7[_0xb814('0x45')]('c.ListId\x20IN\x20?',_[_0xb814('0x59')](_0x1a2603,'id'));_0x5ba0bc['where'](_0xb814('0x86'),_[_0xb814('0x59')](_0x1a2603,'id'));}});}})[_0xb814('0x2b')](function(){if(_0x37d24d[_0xb814('0x81')][_0xb814('0x87')]===_0xb814('0x82')&&!_0x144d37&&!_0x37d24d['query']['ListId'])return[];return db['sequelize'][_0xb814('0x3b')](_0x3cd4f7['toString'](),_0x3d4843);})[_0xb814('0x2b')](function(_0x1d3954){_0x2051d0[_0xb814('0x88')]=_0x1d3954['length'];if(_0x2051d0[_0xb814('0x88')]===0x0)return[];return db[_0xb814('0x89')][_0xb814('0x3b')](_0x42653f['toString'](),_0x3d4843)[_0xb814('0x2b')](function(_0x1bf0b7){_0x3063bf=_[_0xb814('0x8a')](_0x1bf0b7,'id');_0x3d4843=_[_0xb814('0x8b')](_0x3d4843,{'model':db['CmContact'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x37d24d['query'][_0xb814('0x3f')]){_0x499f22[_0xb814('0x40')][_0xb814('0x5a')](function(_0x408870){_0x5ba0bc[_0xb814('0x48')]('c.'+_0x408870);});}else{_0x5ba0bc[_0xb814('0x48')](_0xb814('0x7a'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x8c'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x8d'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x8e'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x8f'));_0x5ba0bc['field'](_0xb814('0x90'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x91'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x92'));_0x5ba0bc[_0xb814('0x48')]('c.createdAt');_0x5ba0bc[_0xb814('0x48')]('c.deletedAt');_0x5ba0bc[_0xb814('0x48')](_0xb814('0x93'));_0x5ba0bc[_0xb814('0x48')](_0xb814('0x94'),_0xb814('0x95'));}if(_0x499f22['limit'])_0x5ba0bc['limit'](_0x499f22[_0xb814('0x42')]);if(_0x499f22[_0xb814('0x25')])_0x5ba0bc[_0xb814('0x25')](_0x499f22[_0xb814('0x25')]);return db['sequelize'][_0xb814('0x3b')](_0x5ba0bc['toString'](),_0x3d4843);});})[_0xb814('0x2b')](function(_0x227cbd){_0x227cbd['forEach'](function(_0x58b016){if(_0x58b016[_0xb814('0x95')]){_0x58b016['Tags']=[];_0x58b016[_0xb814('0x95')][_0xb814('0x58')](',')[_0xb814('0x5a')](function(_0x1afe14){_0x58b016[_0xb814('0x96')][_0xb814('0x97')](_0x3063bf[_0x1afe14]);});}delete _0x58b016[_0xb814('0x95')];});_0x2051d0['rows']=_0x227cbd;return _0x2051d0;})[_0xb814('0x2b')](respondWithFilteredResult(_0x530744,_0x499f22));})['catch'](handleError(_0x530744,null));};exports[_0xb814('0x2c')]=function(_0x590145,_0x2838cb){return db[_0xb814('0x98')]['find']({'where':{'id':_0x590145[_0xb814('0x99')]['id']}})['then'](handleEntityNotFound(_0x2838cb,null))[_0xb814('0x2b')](removeEntity(_0x2838cb,null))[_0xb814('0x9a')](handleError(_0x2838cb,null));};exports['describe']=function(_0x5a0c4a,_0x9e2e16){return db[_0xb814('0x98')][_0xb814('0x31')]()[_0xb814('0x2b')](function(_0x220f8b){delete _0x220f8b[_0xb814('0x9b')];for(var _0x2b12a9=0x0;_0x2b12a9<Object[_0xb814('0x32')](_0x220f8b)[_0xb814('0x38')];_0x2b12a9++){var _0x34f49c=Object['keys'](_0x220f8b)[_0x2b12a9];if(!_['startsWith'](_0x34f49c,'cf_')){_0x220f8b[_0x34f49c]['columnName']=_0x34f49c;_0x220f8b[_0x34f49c]['displayName']=_0x34f49c;}}return _0x220f8b;})[_0xb814('0x2b')](function(_0x75a33){var _0x3d87d2={'where':{'$or':[{'ListId':_0x5a0c4a['query']['id']},{'ListId':null}]},'raw':!![]};return db[_0xb814('0x34')][_0xb814('0x9c')](_0x3d87d2)[_0xb814('0x2b')](function(_0x26ce5b){for(var _0x161658=0x0;_0x161658<_0x26ce5b[_0xb814('0x38')];_0x161658++){var _0x3367b8=_0xb814('0x36')+_0x26ce5b[_0x161658]['id'];_0x75a33[_0x3367b8]['columnName']=_0x3367b8;_0x75a33[_0x3367b8][_0xb814('0x9d')]=_0x26ce5b[_0x161658][_0xb814('0x9e')];_0x75a33[_0x3367b8][_0xb814('0x9f')]={'type':_0x26ce5b[_0x161658][_0xb814('0x3a')],'values':_0x26ce5b[_0x161658]['values']};}Object[_0xb814('0x32')](_0x75a33)[_0xb814('0x5a')](function(_0x3f4b23){if(!_0x75a33[_0x3f4b23][_0xb814('0x41')](_0xb814('0xa0'))){delete _0x75a33[_0x3f4b23];}});return _0x75a33;});})['then'](respondWithResult(_0x9e2e16,null))['catch'](handleError(_0x9e2e16,null));};exports[_0xb814('0x8b')]=function(_0x57b3f2,_0x15bf14){var _0x3882f8;var _0x592aae;var _0xc8f730;if(_0x57b3f2['body']['id']){delete _0x57b3f2[_0xb814('0xa1')]['id'];}return db['CmContact'][_0xb814('0x9c')]({'where':{'id':[_0x57b3f2[_0xb814('0xa1')]['to'],_0x57b3f2[_0xb814('0xa1')][_0xb814('0xa2')]]}})[_0xb814('0x2b')](function(_0x1ae812){if(_0x1ae812){if(_0x1ae812[_0xb814('0x38')]!==0x2){return null;}_0x1ae812[0x0]=_0x1ae812[0x0]['get']({'plain':!![]});_0x1ae812[0x1]=_0x1ae812[0x1]['get']({'plain':!![]});delete _0x1ae812[0x0]['id'];delete _0x1ae812[0x1]['id'];return _[_0xb814('0xa3')](_0x1ae812[0x0],_0x1ae812[0x1],function(_0x50ed93,_0x511e03){if(Array[_0xb814('0x6d')](_0x511e03)&&!_0x511e03[_0xb814('0x38')]){return _0x50ed93;}else if(!_0x511e03){return _0x50ed93;}});}})[_0xb814('0x2b')](handleEntityNotFound(_0x15bf14,null))['then'](function(_0x2a7cde){if(_0x2a7cde){if(_0x2a7cde['tags']&&_[_0xb814('0x6d')](_0x2a7cde[_0xb814('0x9b')])){_0x2a7cde[_0xb814('0x9b')]=_0x2a7cde[_0xb814('0x9b')]['join']();}logger[_0xb814('0xa4')](_0xb814('0xa5'),_0x57b3f2[_0xb814('0xa1')]['to'],_0x57b3f2['body'][_0xb814('0xa2')]);return db[_0xb814('0xa6')][_0xb814('0x2c')]({'where':{'ContactId':[_0x57b3f2['body']['to'],_0x57b3f2[_0xb814('0xa1')][_0xb814('0xa2')]]}})[_0xb814('0x2b')](function(_0x216d67){logger[_0xb814('0xa4')](_0xb814('0xa7'),_0x216d67);return db[_0xb814('0xa8')][_0xb814('0x2c')]({'where':{'ContactId':[_0x57b3f2[_0xb814('0xa1')]['to'],_0x57b3f2[_0xb814('0xa1')][_0xb814('0xa2')]]}})[_0xb814('0x2b')](function(_0x2a13fb){logger['info']('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x2a13fb);return db[_0xb814('0x98')]['create'](_0x2a7cde);});});}})[_0xb814('0x2b')](function(_0x3949fd){if(_0x3949fd){_0x3882f8=_0x3949fd;_0x592aae={'ContactId':_0x3882f8['id']};_0xc8f730={'where':{'ContactId':[_0x57b3f2[_0xb814('0xa1')]['to'],_0x57b3f2[_0xb814('0xa1')][_0xb814('0xa2')]]}};return db[_0xb814('0xa9')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})['then'](function(){if(_0x3882f8){return db['ChatMessage'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})['then'](function(){if(_0x3882f8){return db[_0xb814('0xab')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db['MailInteraction'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xac')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db['MailInteraction'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db['MailMessage'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xad')]['update'](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xae')]['update'](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xaf')]['update'](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb0')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb1')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb2')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb3')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})['then'](function(){if(_0x3882f8){return db['CmHopperHistory'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})['then'](function(){if(_0x3882f8){return db['ReportAgentPreview'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})['then'](function(){if(_0x3882f8){return db['VoiceCallReport']['update'](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb4')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})['then'](function(){if(_0x3882f8){return db[_0xb814('0xb5')]['update'](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb6')]['update'](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db['OpenchannelQueueReport'][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb7')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0xb8')][_0xb814('0xaa')](_0x592aae,_0xc8f730);}})[_0xb814('0x2b')](function(){if(_0x3882f8){return db[_0xb814('0x98')][_0xb814('0x2c')]({'where':{'id':[_0x57b3f2[_0xb814('0xa1')]['to'],_0x57b3f2[_0xb814('0xa1')][_0xb814('0xa2')]]}});}})[_0xb814('0x2b')](function(){if(_0x3882f8){return _0x3882f8;}})[_0xb814('0x2b')](respondWithResult(_0x15bf14,null))['catch'](handleError(_0x15bf14,null));};exports[_0xb814('0xb9')]=function(_0xfc4469,_0x4e840a){return db[_0xb814('0x98')][_0xb814('0x31')]()[_0xb814('0x2b')](function(_0x570191){if(_0xfc4469['body'][_0xb814('0x9b')]&&_['isArray'](_0xfc4469[_0xb814('0xa1')]['tags'])){if(_0xfc4469[_0xb814('0xa1')]['tags']['length']){_0xfc4469[_0xb814('0xa1')][_0xb814('0x9b')]=_0xfc4469[_0xb814('0xa1')][_0xb814('0x9b')][_0xb814('0xba')](';')+';';}else{_0xfc4469[_0xb814('0xa1')][_0xb814('0x9b')]=null;}}else{_0xfc4469[_0xb814('0xa1')][_0xb814('0x9b')]=null;}return db[_0xb814('0x98')][_0xb814('0xb9')](_0xfc4469['body'],{'fields':_[_0xb814('0x32')](_0x570191),'raw':!![]});})['then'](respondWithResult(_0x4e840a,0xc9))[_0xb814('0x9a')](handleError(_0x4e840a,null));};exports[_0xb814('0xbb')]=function(_0x3c5dbf,_0x4fde6a){var _0x6e5486=[];var _0x18fb74=0x0;var _0x371e92=0x0;var _0x2fbea5=0x0;return db[_0xb814('0x98')][_0xb814('0x31')]()[_0xb814('0x2b')](function(_0x44588a){return BPromise[_0xb814('0xbc')](_0x3c5dbf[_0xb814('0xa1')],function(_0x3b65c0){var _0x11e0c3={'where':{'$or':[]},'defaults':_0x3b65c0,'fields':_[_0xb814('0x32')](_0x44588a),'raw':!![]};if(_0x3b65c0[_0xb814('0xbd')]){for(var _0x2a3e8b=0x0;_0x2a3e8b<_0x3b65c0['duplicates'][_0xb814('0x38')];_0x2a3e8b++){var _0x3fb2af={};_0x3fb2af[_0x3b65c0[_0xb814('0xbd')][_0x2a3e8b]]=_0x3b65c0[_0x3b65c0['duplicates'][_0x2a3e8b]];_0x11e0c3['where'][_0xb814('0xbe')]['push'](_0x3fb2af);}_0x11e0c3['where']['ListId']=_0x3b65c0['ListId'];}return db[_0xb814('0x98')][_0xb814('0xbf')](_0x11e0c3)['spread'](function(_0x559d84,_0x3ba2a0){if(_0x3ba2a0){_0x18fb74++;}else{_0x2fbea5++;}})[_0xb814('0x9a')](function(_0x3d24c3){console[_0xb814('0x2d')](_0x3d24c3);_0x371e92++;});});})[_0xb814('0x2b')](function(_0x20e608){if(_0x20e608){return{'success':_0x18fb74,'failure':_0x371e92,'duplicates':_0x2fbea5};}})[_0xb814('0x2b')](respondWithResult(_0x4fde6a,0xc9))[_0xb814('0x9a')](handleError(_0x4fde6a,null));};exports[_0xb814('0xc0')]=function(_0x2b82c6,_0x4c4724,_0x2a5dff){var _0x553635;return db[_0xb814('0x98')][_0xb814('0x31')]()[_0xb814('0x2b')](function(_0xa7ff62){return db[_0xb814('0x98')][_0xb814('0x55')]({'where':{'id':_0x2b82c6[_0xb814('0x99')]['id']},'include':[{'model':db[_0xb814('0x56')],'as':'Tags','attributes':['id','name','color'],'required':_0x2b82c6[_0xb814('0x3b')][_0xb814('0x6c')]?!![]:![]}],'attributes':_[_0xb814('0x32')](_0xa7ff62)});})[_0xb814('0x2b')](function(_0x2ab60d){_0x553635=_0x2ab60d[_0xb814('0xc1')]({'plain':!![]});var _0x42c0cd={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2ab60d&&_0x2ab60d[_0xb814('0xc2')]){if(_0x2ab60d[_0xb814('0xc2')]){_0x42c0cd[_0xb814('0x45')]['$and']['push']({'ListId':{'$ne':_0x2ab60d[_0xb814('0xc2')]}});}}return db[_0xb814('0x34')][_0xb814('0x9c')](_0x42c0cd);})[_0xb814('0x2b')](function(_0x3f0c9c){return _[_0xb814('0xc3')](_0x553635,_['map'](_0x3f0c9c,function(_0x463765){return util['format'](_0xb814('0xc4'),_0x463765['id']);}));})[_0xb814('0x2b')](handleEntityNotFound(_0x4c4724,null))[_0xb814('0x2b')](respondWithResult(_0x4c4724,null))[_0xb814('0x9a')](handleError(_0x4c4724,null));};exports[_0xb814('0xaa')]=function(_0x2c2238,_0x29ccad){var _0x4deb51;if(_0x2c2238[_0xb814('0xa1')]['id']){delete _0x2c2238[_0xb814('0xa1')]['id'];}return db[_0xb814('0x98')][_0xb814('0x55')]({'where':{'id':_0x2c2238['params']['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x29ccad,null))[_0xb814('0x2b')](saveUpdates(_0x2c2238[_0xb814('0xa1')],null))[_0xb814('0x2b')](function(_0xa66ca3){_0x4deb51=_0xa66ca3;var _0x4a2aa5={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0xa66ca3&&_0xa66ca3[_0xb814('0xc2')]){if(_0xa66ca3[_0xb814('0xc2')]){_0x4a2aa5[_0xb814('0x45')]['$and'][_0xb814('0x97')]({'ListId':{'$ne':_0xa66ca3['ListId']}});}}return db[_0xb814('0x34')]['findAll'](_0x4a2aa5);})[_0xb814('0x2b')](function(_0x3467bd){if(_0x3467bd){return _[_0xb814('0xc3')](_[_0xb814('0xc5')](_0x2c2238['body'],function(_0xe5cf2,_0x228226){return _[_0xb814('0x33')](_0x228226,_0xb814('0x36'));}),_[_0xb814('0x59')](_0x3467bd,function(_0x32c9ca){return util[_0xb814('0xc6')](_0xb814('0xc4'),_0x32c9ca['id']);}));}})[_0xb814('0x2b')](function(_0x152260){if(_0x152260&&!_[_0xb814('0x68')](_0x152260)){var _0x368696=squel[_0xb814('0xaa')]()[_0xb814('0xc7')](_0xb814('0x4a'))['setFields'](_0x152260)[_0xb814('0x45')](_0xb814('0xc8'),_0x2c2238[_0xb814('0x99')]['id'])[_0xb814('0xc9')]();return db[_0xb814('0x89')][_0xb814('0x3b')](_0x368696['text'],{'replacements':_0x368696[_0xb814('0xca')]});}})[_0xb814('0x2b')](function(){if(_0x2c2238[_0xb814('0xa1')][_0xb814('0xcb')]&&_0x4deb51){return db['CmHopper']['update']({'phone':_0x2c2238[_0xb814('0xa1')][_0xb814('0xcb')]},{'where':{'ContactId':_0x4deb51['id']}});}})[_0xb814('0x2b')](function(){return _0x4deb51;})[_0xb814('0x2b')](respondWithResult(_0x29ccad,null))[_0xb814('0x9a')](handleError(_0x29ccad,null));};exports[_0xb814('0xcc')]=function(_0x5bc8d0,_0x36af5c,_0x366151){var _0x1c6ec1={};var _0x3e8156={};var _0x5e2fc8;var _0x412ae7;return db[_0xb814('0x98')][_0xb814('0x35')]({'where':{'id':_0x5bc8d0[_0xb814('0x99')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x36af5c,null))['then'](function(_0x7bb40b){if(_0x7bb40b){_0x5e2fc8=_0x7bb40b;_0x3e8156[_0xb814('0x3d')]=_[_0xb814('0x32')](db[_0xb814('0x56')][_0xb814('0xcd')]);_0x3e8156[_0xb814('0x3b')]=_[_0xb814('0x32')](_0x5bc8d0[_0xb814('0x3b')]);_0x3e8156[_0xb814('0x3c')]=_[_0xb814('0x3e')](_0x3e8156[_0xb814('0x3d')],_0x3e8156[_0xb814('0x3b')]);_0x1c6ec1[_0xb814('0x40')]=_['intersection'](_0x3e8156['model'],qs[_0xb814('0x3f')](_0x5bc8d0[_0xb814('0x3b')][_0xb814('0x3f')]));_0x1c6ec1['attributes']=_0x1c6ec1[_0xb814('0x40')][_0xb814('0x38')]?_0x1c6ec1[_0xb814('0x40')]:_0x3e8156['model'];_0x1c6ec1[_0xb814('0x43')]=qs[_0xb814('0x44')](_0x5bc8d0[_0xb814('0x3b')][_0xb814('0x44')]);_0x1c6ec1[_0xb814('0x45')]=qs[_0xb814('0x3c')](_['pick'](_0x5bc8d0[_0xb814('0x3b')],_0x3e8156['filters']));if(_0x5bc8d0[_0xb814('0x3b')]['filter']){_0x1c6ec1[_0xb814('0x45')]=_[_0xb814('0x8b')](_0x1c6ec1[_0xb814('0x45')],{'$or':_['map'](_0x1c6ec1[_0xb814('0x40')],function(_0x2114c2){var _0x164304={};_0x164304[_0x2114c2]={'$like':'%'+_0x5bc8d0['query'][_0xb814('0x65')]+'%'};return _0x164304;})});}_0x1c6ec1=_['merge']({},_0x1c6ec1,_0x5bc8d0[_0xb814('0xce')]);return _0x5e2fc8[_0xb814('0xcc')](_0x1c6ec1);}})[_0xb814('0x2b')](function(_0x5a5b0f){if(_0x5a5b0f){_0x412ae7=_0x5a5b0f[_0xb814('0x38')];if(!_0x5bc8d0[_0xb814('0x3b')][_0xb814('0x41')](_0xb814('0xcf'))){_0x1c6ec1['limit']=qs[_0xb814('0x42')](_0x5bc8d0[_0xb814('0x3b')][_0xb814('0x42')]);_0x1c6ec1[_0xb814('0x25')]=qs[_0xb814('0x25')](_0x5bc8d0[_0xb814('0x3b')][_0xb814('0x25')]);}return _0x5e2fc8[_0xb814('0xcc')](_0x1c6ec1);}})[_0xb814('0x2b')](function(_0x5a9536){if(_0x5a9536){return _0x5a9536?{'count':_0x412ae7,'rows':_0x5a9536}:null;}})[_0xb814('0x2b')](respondWithResult(_0x36af5c,null))[_0xb814('0x9a')](handleError(_0x36af5c,null));};exports[_0xb814('0xd0')]=function(_0x4bd78e,_0xecdaf4,_0x54f6c1){if(_0x4bd78e['body']['id']){delete _0x4bd78e['body']['id'];}return db[_0xb814('0x98')]['findOne']({'where':{'id':_0x4bd78e[_0xb814('0x99')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0xecdaf4,null))['then'](function(_0x5b6325){if(_0x5b6325){return _0x5b6325[_0xb814('0xd0')](_0x4bd78e['body'][_0xb814('0xd1')]||[]);}return null;})['then'](respondWithResult(_0xecdaf4,null))[_0xb814('0x9a')](handleError(_0xecdaf4,null));};exports[_0xb814('0xd2')]=function(_0x57c5bd,_0x4ff3f3,_0x5b19e7){var _0x54ab1a={'raw':![],'where':{}};var _0x10c136={};var _0x5018ea={'count':0x0,'rows':[]};return db['CmContact'][_0xb814('0x35')]({'where':{'id':_0x57c5bd['params']['id']}})['then'](handleEntityNotFound(_0x4ff3f3,null))['then'](function(_0xb1db37){if(_0xb1db37){_0x10c136[_0xb814('0x3d')]=_[_0xb814('0x32')](db['CmHopper'][_0xb814('0xcd')]);_0x10c136[_0xb814('0x3b')]=_[_0xb814('0x32')](_0x57c5bd[_0xb814('0x3b')]);_0x10c136[_0xb814('0x3c')]=_[_0xb814('0x3e')](_0x10c136['model'],_0x10c136[_0xb814('0x3b')]);_0x54ab1a[_0xb814('0x40')]=_[_0xb814('0x3e')](_0x10c136[_0xb814('0x3d')],qs['fields'](_0x57c5bd[_0xb814('0x3b')][_0xb814('0x3f')]));_0x54ab1a[_0xb814('0x40')]=_0x54ab1a[_0xb814('0x40')][_0xb814('0x38')]?_0x54ab1a[_0xb814('0x40')]:_0x10c136[_0xb814('0x3d')];if(!_0x57c5bd[_0xb814('0x3b')][_0xb814('0x41')](_0xb814('0xcf'))){_0x54ab1a['limit']=qs[_0xb814('0x42')](_0x57c5bd[_0xb814('0x3b')]['limit']);_0x54ab1a[_0xb814('0x25')]=qs['offset'](_0x57c5bd[_0xb814('0x3b')][_0xb814('0x25')]);}_0x54ab1a['order']=qs[_0xb814('0x44')](_0x57c5bd['query'][_0xb814('0x44')]);_0x54ab1a[_0xb814('0x45')]=qs[_0xb814('0x3c')](_[_0xb814('0x46')](_0x57c5bd[_0xb814('0x3b')],_0x10c136['filters']));_0x54ab1a[_0xb814('0x45')]['ContactId']=_0xb1db37['id'];if(_0x57c5bd[_0xb814('0x3b')][_0xb814('0x65')]){_0x54ab1a[_0xb814('0x45')]=_[_0xb814('0x8b')](_0x54ab1a[_0xb814('0x45')],{'$or':_[_0xb814('0x59')](_0x54ab1a[_0xb814('0x40')],function(_0xca1f74){var _0x18d39c={};_0x18d39c[_0xca1f74]={'$like':'%'+_0x57c5bd['query'][_0xb814('0x65')]+'%'};return _0x18d39c;})});}_0x54ab1a=_[_0xb814('0x8b')]({},_0x54ab1a,_0x57c5bd[_0xb814('0xce')]);return db[_0xb814('0xa6')]['count']({'where':_0x54ab1a[_0xb814('0x45')]})[_0xb814('0x2b')](function(_0x4e9063){_0x5018ea[_0xb814('0x88')]=_0x4e9063;if(_0x57c5bd['query']['includeAll']){_0x54ab1a['include']=[{'all':!![]}];}return db[_0xb814('0xa6')][_0xb814('0x9c')](_0x54ab1a);})[_0xb814('0x2b')](function(_0x41aa3e){_0x5018ea[_0xb814('0xd3')]=_0x41aa3e;return _0x5018ea;});}})['then'](respondWithFilteredResult(_0x4ff3f3,_0x54ab1a))[_0xb814('0x9a')](handleError(_0x4ff3f3,null));};exports[_0xb814('0xd4')]=function(_0x53b02d,_0xb3dac5,_0x4897ef){var _0x3c7640={'raw':!![],'where':{}};var _0xbadfa={};var _0x3ae679={'count':0x0,'rows':[]};return db[_0xb814('0x98')][_0xb814('0x35')]({'where':{'id':_0x53b02d[_0xb814('0x99')]['id']}})['then'](handleEntityNotFound(_0xb3dac5,null))['then'](function(_0xc71bf6){if(_0xc71bf6){_0xbadfa['model']=_[_0xb814('0x32')](db['CmHopperHistory'][_0xb814('0xcd')]);_0xbadfa[_0xb814('0x3b')]=_[_0xb814('0x32')](_0x53b02d[_0xb814('0x3b')]);_0xbadfa['filters']=_[_0xb814('0x3e')](_0xbadfa['model'],_0xbadfa['query']);_0x3c7640[_0xb814('0x40')]=_[_0xb814('0x3e')](_0xbadfa['model'],qs[_0xb814('0x3f')](_0x53b02d[_0xb814('0x3b')][_0xb814('0x3f')]));_0x3c7640[_0xb814('0x40')]=_0x3c7640['attributes'][_0xb814('0x38')]?_0x3c7640[_0xb814('0x40')]:_0xbadfa[_0xb814('0x3d')];if(!_0x53b02d[_0xb814('0x3b')][_0xb814('0x41')](_0xb814('0xcf'))){_0x3c7640[_0xb814('0x42')]=qs[_0xb814('0x42')](_0x53b02d[_0xb814('0x3b')][_0xb814('0x42')]);_0x3c7640[_0xb814('0x25')]=qs[_0xb814('0x25')](_0x53b02d[_0xb814('0x3b')]['offset']);}_0x3c7640[_0xb814('0x43')]=qs[_0xb814('0x44')](_0x53b02d[_0xb814('0x3b')][_0xb814('0x44')]);_0x3c7640[_0xb814('0x45')]=qs[_0xb814('0x3c')](_[_0xb814('0x46')](_0x53b02d[_0xb814('0x3b')],_0xbadfa['filters']));_0x3c7640[_0xb814('0x45')][_0xb814('0xd5')]=_0xc71bf6['id'];if(_0x53b02d[_0xb814('0x3b')][_0xb814('0x65')]){_0x3c7640[_0xb814('0x45')]=_[_0xb814('0x8b')](_0x3c7640[_0xb814('0x45')],{'$or':_[_0xb814('0x59')](_0x3c7640['attributes'],function(_0x12366a){var _0x5d9685={};_0x5d9685[_0x12366a]={'$like':'%'+_0x53b02d['query'][_0xb814('0x65')]+'%'};return _0x5d9685;})});}_0x3c7640=_['merge']({},_0x3c7640,_0x53b02d[_0xb814('0xce')]);return db[_0xb814('0xd6')][_0xb814('0x88')]({'where':_0x3c7640['where']})[_0xb814('0x2b')](function(_0xb238bc){_0x3ae679[_0xb814('0x88')]=_0xb238bc;if(_0x53b02d[_0xb814('0x3b')][_0xb814('0xd7')]){_0x3c7640['include']=[{'all':!![]}];}return db[_0xb814('0xd6')][_0xb814('0x9c')](_0x3c7640);})[_0xb814('0x2b')](function(_0x50ef97){_0x3ae679[_0xb814('0xd3')]=_0x50ef97;return _0x3ae679;});}})[_0xb814('0x2b')](respondWithFilteredResult(_0xb3dac5,_0x3c7640))[_0xb814('0x9a')](handleError(_0xb3dac5,null));};exports[_0xb814('0xd8')]=function(_0x1f0823,_0x1271ce,_0x4c1805){var _0x117d26={'raw':!![],'where':{}};var _0xb11bea={};var _0x40ae50={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x1f0823[_0xb814('0x99')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x1271ce,null))[_0xb814('0x2b')](function(_0x40bdd0){if(_0x40bdd0){_0xb11bea['model']=_[_0xb814('0x32')](db['CmHopperFinal']['rawAttributes']);_0xb11bea['query']=_[_0xb814('0x32')](_0x1f0823[_0xb814('0x3b')]);_0xb11bea[_0xb814('0x3c')]=_[_0xb814('0x3e')](_0xb11bea[_0xb814('0x3d')],_0xb11bea['query']);_0x117d26[_0xb814('0x40')]=_[_0xb814('0x3e')](_0xb11bea[_0xb814('0x3d')],qs[_0xb814('0x3f')](_0x1f0823[_0xb814('0x3b')][_0xb814('0x3f')]));_0x117d26[_0xb814('0x40')]=_0x117d26['attributes']['length']?_0x117d26['attributes']:_0xb11bea[_0xb814('0x3d')];if(!_0x1f0823['query'][_0xb814('0x41')](_0xb814('0xcf'))){_0x117d26[_0xb814('0x42')]=qs['limit'](_0x1f0823[_0xb814('0x3b')][_0xb814('0x42')]);_0x117d26['offset']=qs[_0xb814('0x25')](_0x1f0823[_0xb814('0x3b')][_0xb814('0x25')]);}_0x117d26[_0xb814('0x43')]=qs[_0xb814('0x44')](_0x1f0823[_0xb814('0x3b')][_0xb814('0x44')]);_0x117d26[_0xb814('0x45')]=qs[_0xb814('0x3c')](_[_0xb814('0x46')](_0x1f0823['query'],_0xb11bea[_0xb814('0x3c')]));_0x117d26['where'][_0xb814('0xd5')]=_0x40bdd0['id'];if(_0x1f0823[_0xb814('0x3b')][_0xb814('0x65')]){_0x117d26[_0xb814('0x45')]=_[_0xb814('0x8b')](_0x117d26['where'],{'$or':_[_0xb814('0x59')](_0x117d26[_0xb814('0x40')],function(_0x3a21af){var _0x4827f4={};_0x4827f4[_0x3a21af]={'$like':'%'+_0x1f0823[_0xb814('0x3b')][_0xb814('0x65')]+'%'};return _0x4827f4;})});}_0x117d26=_[_0xb814('0x8b')]({},_0x117d26,_0x1f0823[_0xb814('0xce')]);return db[_0xb814('0xb3')][_0xb814('0x88')]({'where':_0x117d26[_0xb814('0x45')]})[_0xb814('0x2b')](function(_0x23ea5d){_0x40ae50[_0xb814('0x88')]=_0x23ea5d;if(_0x1f0823[_0xb814('0x3b')][_0xb814('0xd7')]){_0x117d26[_0xb814('0xd9')]=[{'all':!![]}];}return db[_0xb814('0xb3')][_0xb814('0x9c')](_0x117d26);})[_0xb814('0x2b')](function(_0x5c040f){_0x40ae50[_0xb814('0xd3')]=_0x5c040f;return _0x40ae50;});}})[_0xb814('0x2b')](respondWithFilteredResult(_0x1271ce,_0x117d26))[_0xb814('0x9a')](handleError(_0x1271ce,null));};exports[_0xb814('0xda')]=function(_0x92b160,_0xbff80c,_0x5cdcfa){var _0x19eb95={'raw':!![],'where':{}};var _0x321606={};var _0x1fab17={'count':0x0,'rows':[]};return db[_0xb814('0x98')][_0xb814('0x35')]({'where':{'id':_0x92b160[_0xb814('0x99')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0xbff80c,null))[_0xb814('0x2b')](function(_0x364003){if(_0x364003){_0x321606[_0xb814('0x3d')]=_[_0xb814('0x32')](db[_0xb814('0xb8')][_0xb814('0xcd')]);_0x321606[_0xb814('0x3b')]=_['keys'](_0x92b160[_0xb814('0x3b')]);_0x321606[_0xb814('0x3c')]=_[_0xb814('0x3e')](_0x321606[_0xb814('0x3d')],_0x321606[_0xb814('0x3b')]);_0x19eb95[_0xb814('0x40')]=_[_0xb814('0x3e')](_0x321606[_0xb814('0x3d')],qs['fields'](_0x92b160['query'][_0xb814('0x3f')]));_0x19eb95[_0xb814('0x40')]=_0x19eb95[_0xb814('0x40')][_0xb814('0x38')]?_0x19eb95[_0xb814('0x40')]:_0x321606['model'];if(!_0x92b160[_0xb814('0x3b')][_0xb814('0x41')](_0xb814('0xcf'))){_0x19eb95[_0xb814('0x42')]=qs['limit'](_0x92b160['query'][_0xb814('0x42')]);_0x19eb95[_0xb814('0x25')]=qs[_0xb814('0x25')](_0x92b160['query'][_0xb814('0x25')]);}_0x19eb95[_0xb814('0x43')]=qs[_0xb814('0x44')](_0x92b160[_0xb814('0x3b')]['sort']);_0x19eb95['where']=qs[_0xb814('0x3c')](_[_0xb814('0x46')](_0x92b160[_0xb814('0x3b')],_0x321606['filters']));_0x19eb95['where']['ContactId']=_0x364003['id'];if(_0x92b160['query'][_0xb814('0x65')]){_0x19eb95[_0xb814('0x45')]=_['merge'](_0x19eb95[_0xb814('0x45')],{'$or':_[_0xb814('0x59')](_0x19eb95[_0xb814('0x40')],function(_0x39e6ae){var _0x197937={};_0x197937[_0x39e6ae]={'$like':'%'+_0x92b160[_0xb814('0x3b')][_0xb814('0x65')]+'%'};return _0x197937;})});}_0x19eb95=_['merge']({},_0x19eb95,_0x92b160[_0xb814('0xce')]);return db[_0xb814('0xb8')][_0xb814('0x88')]({'where':_0x19eb95[_0xb814('0x45')]})[_0xb814('0x2b')](function(_0x38eea0){_0x1fab17[_0xb814('0x88')]=_0x38eea0;if(_0x92b160[_0xb814('0x3b')][_0xb814('0xd7')]){_0x19eb95[_0xb814('0xd9')]=[{'all':!![]}];}return db['JscriptySessionReport'][_0xb814('0x9c')](_0x19eb95);})['then'](function(_0x44f144){_0x1fab17['rows']=_0x44f144;return _0x1fab17;});}})['then'](respondWithFilteredResult(_0xbff80c,_0x19eb95))[_0xb814('0x9a')](handleError(_0xbff80c,null));};exports['uploadCsv']=function(_0x5bb365,_0x189200,_0x43d49b){try{if(!_0x5bb365[_0xb814('0xa1')]['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x5bb365[_0xb814('0xa1')][_0xb814('0xdb')]){throw new Error('No\x20association\x20keys\x20specified!');}if(!_0x5bb365[_0xb814('0xa1')][_0xb814('0xdc')]){throw new Error(_0xb814('0xdd'));}if(!_0x5bb365[_0xb814('0xa1')][_0xb814('0xde')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x1d9f8d=_0x5bb365['body'][_0xb814('0xdb')][_0xb814('0x58')](',');var _0x19ad31=_0x5bb365[_0xb814('0xa1')][_0xb814('0xdc')][_0xb814('0x58')](',');if(!_0x1d9f8d[_0xb814('0x38')]||!_0x19ad31[_0xb814('0x38')]||_0x1d9f8d[_0xb814('0x38')]!==_0x19ad31[_0xb814('0x38')]){throw new Error(_0xb814('0xdf'));}_0x5bb365['body'][_0xb814('0x3f')]=_[_0xb814('0xe0')](_0x1d9f8d,_0x19ad31);if(!_0x5bb365[_0xb814('0xa1')][_0xb814('0x3f')][_0xb814('0xcb')]){throw new Error(_0xb814('0xe1'));}if(!_0x5bb365['body'][_0xb814('0x3f')]['firstName']){throw new Error(_0xb814('0xe2'));}var _0x20d49b=path[_0xb814('0xba')](config[_0xb814('0xe3')],_0xb814('0xe4'),_0x5bb365[_0xb814('0xe5')]['filename']);fs['chmodSync'](_0x20d49b,parseInt(_0xb814('0xe6'),0x8));var _0xbb6002=require('child_process')[_0xb814('0xe7')](path[_0xb814('0xba')](__dirname,'../../components/import/cm/csv'),[_0x20d49b,_0x5bb365[_0xb814('0xa1')][_0xb814('0xdb')],_0x5bb365['body'][_0xb814('0xdc')],_0x5bb365[_0xb814('0xa1')][_0xb814('0xc2')],_0x5bb365[_0xb814('0xa1')]['CompanyId'],_0x5bb365[_0xb814('0xa1')]['duplicates'],_0x5bb365['body'][_0xb814('0xde')]]);return _0x189200[_0xb814('0x22')](0xc8)[_0xb814('0x24')]({'message':'File\x20uploaded\x20correctly!','pid':_0xbb6002[_0xb814('0xe8')]});}catch(_0x257426){return _0x189200[_0xb814('0x22')](0x1f4)[_0xb814('0xe9')](_0x257426);}};exports[_0xb814('0xea')]=function(_0x49dfe2,_0xd7438f,_0x48e8f9){var _0x30c930=fs[_0xb814('0xeb')](_0x49dfe2['file'][_0xb814('0x9')]);Papa[_0xb814('0xec')](_0x30c930,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x591823){return _0xd7438f[_0xb814('0x22')](0xc8)['json']({'file':_0x49dfe2[_0xb814('0xe5')],'fields':_0x591823['meta']['fields']});}});};exports[_0xb814('0xed')]=function(_0x60b176,_0x35ebde,_0x43c470){return db[_0xb814('0x84')][_0xb814('0x9c')]({'raw':!![],'attributes':['id'],'where':{'role':'agent'}})[_0xb814('0x2b')](function(_0x2eabbd){var _0xcec6da=![];if(!_0x60b176['body'][_0xb814('0xc2')]){throw new Error(_0xb814('0xee'));}if(!_0x60b176['body']['binding'][_0xb814('0xcb')]){throw new Error(_0xb814('0xe1'));}if(!_0x60b176[_0xb814('0xa1')][_0xb814('0xef')][_0xb814('0xf0')]){throw new Error('No\x20firstName\x20column\x20specified');}if(!_0x60b176['body'][_0xb814('0xde')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x4d2f97=require(_0xb814('0xf1'))[_0xb814('0xe7')](path[_0xb814('0xba')](__dirname,_0xb814('0xf2')),[_0x60b176[_0xb814('0x99')]['id'],JSON['stringify'](_0x60b176[_0xb814('0xa1')]),JSON[_0xb814('0xf3')](_0x2eabbd)]);_0x4d2f97['on'](_0xb814('0xf4'),function(_0xf543d2){_0xcec6da=!![];return _0x35ebde[_0xb814('0x22')](0xc8)[_0xb814('0x24')]({'message':_0xb814('0xf5'),'pid':_0x4d2f97[_0xb814('0xe8')]});});_0x4d2f97['on'](_0xb814('0xf6'),function(_0x4877cf){if(_0x4877cf&&!_0xcec6da){return _0x35ebde[_0xb814('0x22')](0x1f4)[_0xb814('0x24')]({'message':_0xb814('0xf7'),'pid':_0x4d2f97['pid']});}});})['catch'](handleError(_0x35ebde,null));};exports[_0xb814('0xf8')]=function(_0x17e8ea,_0x37b42c){var _0x58b74a=[_0xb814('0xf9'),_0xb814('0xfa'),_0xb814('0xfb'),_0xb814('0xfc'),_0xb814('0xfd'),_0xb814('0xfe'),_0xb814('0xff')];var _0x140fde={'offset':0x0,'order':qs[_0xb814('0x44')](_0xb814('0x100'))},_0x50a4da={'count':0x0,'rows':[]};Promise[_0xb814('0x80')]()[_0xb814('0x2b')](function(){if(_0x17e8ea[_0xb814('0x3b')][_0xb814('0x101')]){if(!_[_0xb814('0x102')](_0x58b74a,_0x17e8ea['query'][_0xb814('0x101')]['toLowerCase']())){throw new Error(_0xb814('0x103'));}_0x58b74a=[_0x17e8ea[_0xb814('0x3b')][_0xb814('0x101')][_0xb814('0x104')]()];}if(_0x17e8ea[_0xb814('0x3b')]['range']){try{var _0x59d24f=JSON['parse'](_0x17e8ea[_0xb814('0x3b')][_0xb814('0x105')]);if(!moment(_0x59d24f[_0xb814('0xa2')])['isValid']()){throw new Error(_0xb814('0x106'));}if(!moment(_0x59d24f['to'])[_0xb814('0x107')]()){throw new Error(_0xb814('0x108'));}}catch(_0x2d51e0){throw new Error('Invalid\x20createdAt\x20filter');}}if(!_0x17e8ea[_0xb814('0x3b')][_0xb814('0x41')](_0xb814('0xcf'))){_0x140fde['limit']=qs[_0xb814('0x42')](_0x17e8ea[_0xb814('0x3b')]['limit']||0xa);_0x140fde[_0xb814('0x25')]=qs['offset'](_0x17e8ea[_0xb814('0x3b')][_0xb814('0x25')]);}var _0x13c9fd=_0x58b74a[_0xb814('0x59')](function(_0x22c416){if(_0x22c416===_0xb814('0xff')){var _0x36b0d0={'attributes':['id','uniqueid',_0xb814('0x3a'),_0xb814('0x109'),_0xb814('0x10a'),'callerid','starttime',_0xb814('0x10b'),_0xb814('0x10c'),'note',_0xb814('0x10d'),_0xb814('0x10e'),'userSecondDisposition',_0xb814('0x10f')],'where':{'ContactId':_0x17e8ea[_0xb814('0x99')]['id']},'include':[{'model':db['User'],'as':_0xb814('0x84'),'attributes':['id',_0xb814('0x2f'),_0xb814('0x110'),'alias']}],'order':[[_0xb814('0x10d'),'DESC']]};if(_0x17e8ea[_0xb814('0x3b')][_0xb814('0x105')]){_0x36b0d0[_0xb814('0x45')][_0xb814('0x10d')]={'$gte':_0x59d24f[_0xb814('0xa2')],'$lte':_0x59d24f['to']};}return db[_0xb814('0x111')][_0xb814('0x112')](_0x36b0d0)[_0xb814('0x2b')](function(_0x590238){_0x50a4da[_0xb814('0x88')]+=_0x590238[_0xb814('0x88')];return _[_0xb814('0x59')](_0x590238[_0xb814('0xd3')],function(_0x47e4a1){var _0x1768e7=_0x47e4a1[_0xb814('0xc1')]({'plain':!![]});_0x1768e7[_0xb814('0x101')]=_0x22c416;if(_0x1768e7['User']){_0x1768e7[_0xb814('0x84')]={'id':_0x1768e7['User']['id'],'name':_0x1768e7[_0xb814('0x84')][_0xb814('0x2f')],'fullname':_0x1768e7[_0xb814('0x84')]['fullname'],'alias':_0x1768e7['User'][_0xb814('0x9e')]};}return _0x1768e7;});});}else{var _0xd03fe4=_[_0xb814('0x113')](_0x22c416)+(_0x22c416===_0xb814('0xfa')?_0xb814('0x114'):_0xb814('0x115'));var _0x1f558e={'attributes':['id',_0xb814('0x116'),_0xb814('0x117'),'createdAt',_0xb814('0x118'),'disposition',_0xb814('0x119'),'thirdDisposition',_0xb814('0x11a'),_0xd03fe4+'Id'],'where':{'ContactId':_0x17e8ea[_0xb814('0x99')]['id']},'include':[{'model':db[_0xd03fe4],'as':'Account','attributes':['id',_0xb814('0x2f'),_0xb814('0x11b')]},{'model':db['User'],'as':_0xb814('0x11c'),'attributes':['id','name',_0xb814('0x110')]},{'model':db[_0xb814('0x56')],'as':_0xb814('0x96'),'attributes':['id','name',_0xb814('0x11d')],'through':{'attributes':[]}}],'order':[['createdAt','DESC']]};if(_0x17e8ea[_0xb814('0x3b')][_0xb814('0x105')]){_0x1f558e['where'][_0xb814('0x10d')]={'$gte':_0x59d24f[_0xb814('0xa2')],'$lte':_0x59d24f['to']};}switch(_0x22c416){case _0xb814('0xfa'):_0x1f558e[_0xb814('0x40')][_0xb814('0x97')](_0xb814('0x11e'),_0xb814('0x11f'),_0xb814('0x120'),_0xb814('0x121'),_0xb814('0x122'),_0xb814('0x123'),_0xb814('0x124'),'ratingValue',_0xb814('0x125'));break;case _0xb814('0xf9'):_0x1f558e['attributes']['push'](_0xb814('0x126'),_0xb814('0x127'));break;case _0xb814('0xfc'):_0x1f558e['attributes'][_0xb814('0x97')](_0xb814('0x128'),'threadId');break;}return db[_[_0xb814('0x113')](_0x22c416)+_0xb814('0x129')][_0xb814('0x112')](_0x1f558e)['then'](function(_0x383ded){_0x50a4da['count']+=_0x383ded[_0xb814('0x88')];return _['map'](_0x383ded[_0xb814('0xd3')],function(_0x5bc0ab){var _0x4b0d12=_0x5bc0ab['get']({'plain':!![]});_0x4b0d12['channel']=_0x22c416;if(_0x4b0d12[_0xb814('0x11c')]){_0x4b0d12['Owner']={'id':_0x4b0d12[_0xb814('0x11c')]['id'],'name':_0x4b0d12[_0xb814('0x11c')]['name'],'fullname':_0x4b0d12[_0xb814('0x11c')][_0xb814('0x110')]};}return _0x4b0d12;});});}});return Promise[_0xb814('0x37')](_0x13c9fd);})['then'](function(_0x17aa4e){return _(_0x17aa4e)['flatten']()[_0xb814('0x12a')](_0xb814('0x10d'))[_0xb814('0x12b')]()['value']();})[_0xb814('0x2b')](function(_0x644abf){_0x50a4da[_0xb814('0xd3')]=_0x140fde['limit']?_0x644abf[_0xb814('0x12c')](_0x140fde[_0xb814('0x25')],_0x140fde[_0xb814('0x25')]+_0x140fde[_0xb814('0x42')]):_0x644abf;return _0x50a4da;})[_0xb814('0x2b')](respondWithFilteredResult(_0x37b42c,_0x140fde))[_0xb814('0x9a')](handleError(_0x37b42c,null));};
\ No newline at end of file
+var _0x74e6=['values','body','findAll','get','mergeWith','join','info','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','ChatInteraction','ChatMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxMessage','OpenchannelInteraction','OpenchannelMessage','CmHopperFinal','CmHopperHistory','ReportAgentPreview','VoiceCallReport','FaxQueueReport','MailQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','create','bulkCreate','duplicates','spread','error','show','name','color','$and','omit','cf_%d','pickBy','format','table','setFields','id\x20=\x20?','toParam','text','phone','options','getTags','setTags','getHoppers','rawAttributes','ContactId','rows','getHopperFinals','includeAll','include','getJscriptySessions','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','server/files/tmp','file','chmodSync','0777','child_process','fork','../../components/import/cm/csv','File\x20uploaded\x20correctly!','pid','upload','createReadStream','parse','meta','import','binding','../../components/import/cm/csv2','stringify','start\x20child\x20process\x20correctly!','error\x20child\x20process','mail','chat','sms','openchannel','fax','whatsapp','voice','channel','toLowerCase','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','uniqueid','source','destination','callerid','duration','note','createdAt','userSecondDisposition','UserId','fullname','findAndCountAll','alias','startCase','Website','Account','closed','closedAt','disposition','secondDisposition','key','Owner','browserName','customerIp','customerPort','deviceModel','osName','ratingMessage','ratingType','ratingValue','referer','substatus','externalUrl','Interaction','flatten','sortBy','reverse','slice','eml-format','zip-dir','fast-json-patch','moment','path','sox','ejs','fs-extra','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./cmContact.socket','sendStatus','status','end','undefined','limit','offset','set','json','apply','reject','save','update','then','stack','send','index','CmContact','keys','length','startsWith','cf_','push','CmCustomField','findOne','all','fieldType','type','model','query','intersection','fields','attributes','nolimit','order','sort','where','filters','pick','select','field','from','tools_tags','cm_contacts','left_join','cm_user_has_contacts','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','ct.CmContactId\x20=\x20c.id','c.deletedAt\x20IS\x20NULL','expr','parseSearch','conditions','find','Tag','value','split','forEach','union','User','and','uc.UserId\x20=\x20?','dateOfBirth','castTo','DATE','start','hasOwnProperty','filter','isNil','Contact','isEmpty','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','replace','getFullTextValue','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','group','c.id','QueryTypes','SELECT','clone','DESC','having','t.id\x20IN\x20?','resolve','user','role','some','getLists','c.ListId\x20IS\x20NULL','map','agent','toString','count','sequelize','keyBy','merge','c.firstName','c.lastName','c.phone','c.mobile','c.email','c.ListId','c.CompanyId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','destroy','params','catch','describe','tags','columnName','displayName','custom'];(function(_0x359627,_0x27788b){var _0x4a6e73=function(_0x17af52){while(--_0x17af52){_0x359627['push'](_0x359627['shift']());}};_0x4a6e73(++_0x27788b);}(_0x74e6,0x8d));var _0x674e=function(_0x37b3df,_0x2e1535){_0x37b3df=_0x37b3df-0x0;var _0x398bd4=_0x74e6[_0x37b3df];return _0x398bd4;};'use strict';var emlformat=require(_0x674e('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x674e('0x1'));var jsonpatch=require(_0x674e('0x2'));var rp=require('request-promise');var moment=require(_0x674e('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x674e('0x4'));var sox=require(_0x674e('0x5'));var csv=require('to-csv');var ejs=require(_0x674e('0x6'));var fs=require('fs');var fs_extra=require(_0x674e('0x7'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x674e('0x8'));var deskjs=require('desk.js');var toCsv=require(_0x674e('0x9'));var querystring=require(_0x674e('0xa'));var Papa=require(_0x674e('0xb'));var Redis=require(_0x674e('0xc'));var authService=require(_0x674e('0xd'));var qs=require(_0x674e('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x674e('0xf'));var logger=require(_0x674e('0x10'))(_0x674e('0x11'));var utils=require(_0x674e('0x12'));var config=require(_0x674e('0x13'));var licenseUtil=require(_0x674e('0x14'));var db=require(_0x674e('0x15'))['db'];config['redis']=_[_0x674e('0x16')](config[_0x674e('0x17')],{'host':_0x674e('0x18'),'port':0x18eb});var socket=require(_0x674e('0x19'))(new Redis(config[_0x674e('0x17')]));require(_0x674e('0x1a'))['register'](socket);function respondWithStatusCode(_0x173761,_0x466d57){_0x466d57=_0x466d57||0xcc;return function(_0xc465a4){if(_0xc465a4){return _0x173761[_0x674e('0x1b')](_0x466d57);}return _0x173761[_0x674e('0x1c')](_0x466d57)[_0x674e('0x1d')]();};}function respondWithResult(_0x14ff6e,_0x4e404e){_0x4e404e=_0x4e404e||0xc8;return function(_0x4f9a7c){if(_0x4f9a7c){return _0x14ff6e[_0x674e('0x1c')](_0x4e404e)['json'](_0x4f9a7c);}};}function respondWithFilteredResult(_0x1f982f,_0x309ed7){return function(_0xf4c4d8){if(_0xf4c4d8){var _0x4d0b28=typeof _0x309ed7['offset']===_0x674e('0x1e')&&typeof _0x309ed7[_0x674e('0x1f')]===_0x674e('0x1e');var _0x435017=_0xf4c4d8['count'];var _0x2f7624=_0x4d0b28?0x0:_0x309ed7[_0x674e('0x20')];var _0x474b63=_0x4d0b28?_0xf4c4d8['count']:_0x309ed7[_0x674e('0x20')]+_0x309ed7[_0x674e('0x1f')];var _0x4a6cca;if(_0x474b63>=_0x435017){_0x474b63=_0x435017;_0x4a6cca=0xc8;}else{_0x4a6cca=0xce;}_0x1f982f[_0x674e('0x1c')](_0x4a6cca);return _0x1f982f[_0x674e('0x21')]('Content-Range',_0x2f7624+'-'+_0x474b63+'/'+_0x435017)[_0x674e('0x22')](_0xf4c4d8);}return null;};}function patchUpdates(_0x528373){return function(_0x596a1a){try{jsonpatch[_0x674e('0x23')](_0x596a1a,_0x528373,!![]);}catch(_0x3721cf){return BPromise[_0x674e('0x24')](_0x3721cf);}return _0x596a1a[_0x674e('0x25')]();};}function saveUpdates(_0x263a7e,_0x101ccd){return function(_0x462042){if(_0x462042){return _0x462042[_0x674e('0x26')](_0x263a7e)[_0x674e('0x27')](function(_0x5d5b42){return _0x5d5b42;});}return null;};}function removeEntity(_0x1eb9ed,_0x375881){return function(_0x12d177){if(_0x12d177){return _0x12d177['destroy']()[_0x674e('0x27')](function(){_0x1eb9ed[_0x674e('0x1c')](0xcc)[_0x674e('0x1d')]();});}};}function handleEntityNotFound(_0x5e12f2,_0x516ed3){return function(_0x46e1a0){if(!_0x46e1a0){_0x5e12f2[_0x674e('0x1b')](0x194);}return _0x46e1a0;};}function handleError(_0x4b0c21,_0xa43748){_0xa43748=_0xa43748||0x1f4;return function(_0x388ee8){logger['error'](_0x388ee8[_0x674e('0x28')]);if(_0x388ee8['name']){delete _0x388ee8['name'];}_0x4b0c21[_0x674e('0x1c')](_0xa43748)[_0x674e('0x29')](_0x388ee8);};}exports[_0x674e('0x2a')]=function(_0x5205ba,_0x18a4d4){var _0x58db18={},_0x2e510a={},_0x326e72={'count':0x0,'rows':[]};return db[_0x674e('0x2b')]['describe']()[_0x674e('0x27')](function(_0x1b64f6){var _0x17ec73=[];for(var _0x1160b9=0x0;_0x1160b9<Object[_0x674e('0x2c')](_0x1b64f6)[_0x674e('0x2d')];_0x1160b9++){var _0x160751=Object[_0x674e('0x2c')](_0x1b64f6)[_0x1160b9];if(_[_0x674e('0x2e')](_0x160751,_0x674e('0x2f'))){_0x17ec73[_0x674e('0x30')](db[_0x674e('0x31')][_0x674e('0x32')]({'where':{'id':_['trimStart'](_0x160751,_0x674e('0x2f'))},'raw':!![]}));}}return BPromise[_0x674e('0x33')](_0x17ec73)[_0x674e('0x27')](function(_0x4f9526){for(var _0x1ef635=0x0;_0x1ef635<_0x4f9526[_0x674e('0x2d')];_0x1ef635++){if(_0x4f9526[_0x1ef635]){var _0x1b9b86='cf_'+_0x4f9526[_0x1ef635]['id'];var _0x19de19=_0x1b64f6[_0x1b9b86];_0x19de19[_0x674e('0x34')]=_0x4f9526[_0x1ef635][_0x674e('0x35')];}}return _0x1b64f6;});})[_0x674e('0x27')](function(_0x589601){_0x2e510a[_0x674e('0x36')]=_['keys'](_0x589601);_0x2e510a[_0x674e('0x37')]=_[_0x674e('0x2c')](_0x5205ba['query']);_0x2e510a['filters']=_[_0x674e('0x38')](_0x2e510a[_0x674e('0x36')],_0x2e510a['query']);_0x58db18['attributes']=_[_0x674e('0x38')](_0x2e510a['model'],qs[_0x674e('0x39')](_0x5205ba[_0x674e('0x37')][_0x674e('0x39')]));_0x58db18['attributes']=_0x58db18['attributes']['length']?_0x58db18[_0x674e('0x3a')]:_0x2e510a[_0x674e('0x36')];if(!_0x5205ba[_0x674e('0x37')]['hasOwnProperty'](_0x674e('0x3b'))){_0x58db18[_0x674e('0x1f')]=qs[_0x674e('0x1f')](_0x5205ba[_0x674e('0x37')][_0x674e('0x1f')]);_0x58db18[_0x674e('0x20')]=qs[_0x674e('0x20')](_0x5205ba[_0x674e('0x37')]['offset']);}_0x58db18[_0x674e('0x3c')]=qs[_0x674e('0x3d')](_0x5205ba[_0x674e('0x37')][_0x674e('0x3d')]);_0x58db18[_0x674e('0x3e')]=qs[_0x674e('0x3f')](_[_0x674e('0x40')](_0x5205ba[_0x674e('0x37')],_0x2e510a[_0x674e('0x3f')]),_0x589601);var _0x3623b4=[];var _0x26d191=squel[_0x674e('0x41')]()['field']('id')[_0x674e('0x42')]('name')[_0x674e('0x42')]('color')[_0x674e('0x43')](_0x674e('0x44'));var _0x492632=squel[_0x674e('0x41')]()[_0x674e('0x43')](_0x674e('0x45'),'c')[_0x674e('0x46')](_0x674e('0x47'),'uc',_0x674e('0x48'))[_0x674e('0x46')](_0x674e('0x49'),'ct',_0x674e('0x4a'))['left_join']('tools_tags','t','t.id\x20=\x20ct.TagId')[_0x674e('0x3e')](_0x674e('0x4b'));var _0x1bdf03=squel[_0x674e('0x4c')]();var _0xc97db4=[];var _0x966b2e=squel[_0x674e('0x4c')]();var _0x3e0d25;if(_0x5205ba[_0x674e('0x37')]['search']){_0x3e0d25=as[_0x674e('0x4d')](_0x5205ba[_0x674e('0x37')]['search']);var _0x5d9430=_0x3e0d25['sqlOperator'];for(var _0x46e7fa=0x0;_0x46e7fa<_0x3e0d25[_0x674e('0x4e')][_0x674e('0x2d')];_0x46e7fa++){var _0x2398d4=_0x3e0d25['conditions'][_0x46e7fa];var _0x4da3f4='c';var _0x5b9c5d=_(_0x589601)['keys']()[_0x674e('0x4f')](function(_0x307c99){return _0x307c99===_0x2398d4[_0x674e('0x42')];});if(_0x5b9c5d)_0x5b9c5d=_0x589601[_0x2398d4[_0x674e('0x42')]];if(!_0x5b9c5d){if(_0x2398d4['field']===_0x674e('0x50')){var _0x19c063=_0x2398d4[_0x674e('0x51')][_0x674e('0x52')](',')['map'](function(_0x42404f){return Number(_0x42404f);});_0x19c063[_0x674e('0x53')](function(_0x10206c){_0x966b2e['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x10206c+',%');});_0xc97db4=_[_0x674e('0x54')](_0xc97db4,_0x19c063);}else if(_0x2398d4['field']===_0x674e('0x55')){_0x1bdf03[_0x674e('0x56')](_0x674e('0x57'),_0x2398d4[_0x674e('0x51')]);}}else{if(_0x2398d4[_0x674e('0x42')]===_0x674e('0x58')||_0x5b9c5d[_0x674e('0x34')]==='datetime')_0x2398d4[_0x674e('0x59')]=_0x674e('0x5a');var _0x6355ef=as['buildExpression'](_0x4da3f4,_0x5b9c5d['type'],_0x2398d4);_0x1bdf03[_0x5d9430](_0x6355ef['text'],_0x6355ef[_0x674e('0x51')][_0x674e('0x5b')],_0x6355ef[_0x674e('0x51')][_0x674e('0x1d')]);}}}else{var _0x1fd114=_(Object[_0x674e('0x2c')](_0x5205ba[_0x674e('0x37')]))['map'](function(_0x443d43){return _0x589601[_0x674e('0x5c')](_0x443d43)?_0x443d43:undefined;})[_0x674e('0x5d')](function(_0x20272c){return!_[_0x674e('0x5e')](_0x20272c);})['value']();if(_0x5205ba[_0x674e('0x37')][_0x674e('0x5f')])_0x1fd114[_0x674e('0x30')](_0x674e('0x5f'));if(!_[_0x674e('0x60')](_0x1fd114)){_0x1fd114[_0x674e('0x53')](function(_0x5a3235){if(_0x5a3235===_0x674e('0x61')){_0x492632[_0x674e('0x3e')](_0x674e('0x62'),[][_0x674e('0x63')](_0x5205ba['query'][_0x5a3235]));}else if(_0x5a3235===_0x674e('0x5f')){var _0xd7b6cb='%'+_0x5205ba['query'][_0x5a3235]+'%';_0x492632[_0x674e('0x3e')](_0x674e('0x64'),_0xd7b6cb);}else{_0x492632['where']('c.'+_0x5a3235+_0x674e('0x65'),_0x5205ba[_0x674e('0x37')][_0x5a3235]);}});}if(_0x5205ba['query'][_0x674e('0x66')]){_0xc97db4=_[_0x674e('0x67')](_0x5205ba['query']['tag'])?_0x5205ba[_0x674e('0x37')][_0x674e('0x66')]:new Array(_0x5205ba[_0x674e('0x37')][_0x674e('0x66')]);_0xc97db4[_0x674e('0x53')](function(_0x1a158e){_0x966b2e['or'](_0x674e('0x68'),'%,'+_0x1a158e+',%');});}if(_0x5205ba[_0x674e('0x37')]['filter']){var _0x31f2f6=_0x5205ba[_0x674e('0x37')][_0x674e('0x5d')][_0x674e('0x69')]('\x5c','\x5c\x5c')[_0x674e('0x69')](/'/g,'\x27\x27');if(_0x31f2f6[_0x674e('0x52')]('\x20')[_0x674e('0x2d')]>0x1){_0x1bdf03['or']('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x674e('0x6a')](_0x31f2f6),null);}else{if(qs['isNumeric'](_0x31f2f6)){_0x1bdf03['or'](_0x674e('0x6b'),_0x31f2f6+'%');_0x1bdf03['or'](_0x674e('0x6c'),_0x31f2f6+'%');_0x1bdf03['or'](_0x674e('0x6d'),_0x31f2f6+'%');_0x1bdf03['or'](_0x674e('0x6e'),_0x31f2f6+'%');}else if(qs[_0x674e('0x6f')](_0x31f2f6)){_0x1bdf03['or'](_0x674e('0x70'),_0x31f2f6+'%');}else{_0x1bdf03['or'](_0x674e('0x71'),'%'+_0x31f2f6+'%');_0x1bdf03['or'](_0x674e('0x72'),'%'+_0x31f2f6+'%');_0x1bdf03['or']('c.email\x20LIKE\x20?','%'+_0x31f2f6+'%');}}}}_0x492632[_0x674e('0x3e')](_0x1bdf03);_0x492632[_0x674e('0x73')](_0x674e('0x74'));var _0x87b33e={'type':db['Sequelize'][_0x674e('0x75')][_0x674e('0x76')],'raw':!![]};var _0x270c67=_0x492632[_0x674e('0x77')]()[_0x674e('0x42')](_0x674e('0x74'));if(_0x58db18[_0x674e('0x3c')]){_0x58db18[_0x674e('0x3c')][_0x674e('0x53')](function(_0xe0cdf6){_0x492632[_0x674e('0x3c')]('c.'+_0xe0cdf6[0x0],_0xe0cdf6[0x1]===_0x674e('0x78')?![]:!![]);});}if(!_['isEmpty'](_0xc97db4)){_0x492632[_0x674e('0x79')](_0x966b2e);_0x270c67[_0x674e('0x3e')](_0x674e('0x7a'),_0xc97db4);}BPromise[_0x674e('0x7b')]()[_0x674e('0x27')](function(){if(!_0x3e0d25)return;if(_0x5205ba[_0x674e('0x7c')][_0x674e('0x7d')]!=='agent')return;if(!_[_0x674e('0x7e')](_0x3e0d25[_0x674e('0x4e')],['field','User'])){return _0x5205ba[_0x674e('0x7c')][_0x674e('0x7f')]({'attributes':['id'],'raw':!![]})[_0x674e('0x27')](function(_0x1979ad){if(_[_0x674e('0x60')](_0x1979ad)){_0x270c67[_0x674e('0x3e')](_0x674e('0x80'));_0x492632[_0x674e('0x3e')](_0x674e('0x80'));}else{_0x270c67[_0x674e('0x3e')]('c.ListId\x20IN\x20?',_[_0x674e('0x81')](_0x1979ad,'id'));_0x492632[_0x674e('0x3e')](_0x674e('0x62'),_[_0x674e('0x81')](_0x1979ad,'id'));}});}})[_0x674e('0x27')](function(){if(_0x5205ba[_0x674e('0x7c')][_0x674e('0x7d')]===_0x674e('0x82')&&!_0x3e0d25&&!_0x5205ba['query'][_0x674e('0x61')])return[];return db['sequelize'][_0x674e('0x37')](_0x270c67[_0x674e('0x83')](),_0x87b33e);})[_0x674e('0x27')](function(_0x1b14ed){_0x326e72['count']=_0x1b14ed[_0x674e('0x2d')];if(_0x326e72[_0x674e('0x84')]===0x0)return[];return db[_0x674e('0x85')][_0x674e('0x37')](_0x26d191[_0x674e('0x83')](),_0x87b33e)[_0x674e('0x27')](function(_0x31b572){_0x3623b4=_[_0x674e('0x86')](_0x31b572,'id');_0x87b33e=_[_0x674e('0x87')](_0x87b33e,{'model':db['CmContact'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x5205ba[_0x674e('0x37')][_0x674e('0x39')]){_0x58db18[_0x674e('0x3a')][_0x674e('0x53')](function(_0x72d561){_0x492632[_0x674e('0x42')]('c.'+_0x72d561);});}else{_0x492632[_0x674e('0x42')](_0x674e('0x74'));_0x492632[_0x674e('0x42')](_0x674e('0x88'));_0x492632[_0x674e('0x42')](_0x674e('0x89'));_0x492632[_0x674e('0x42')](_0x674e('0x8a'));_0x492632[_0x674e('0x42')](_0x674e('0x8b'));_0x492632['field']('c.fax');_0x492632[_0x674e('0x42')](_0x674e('0x8c'));_0x492632[_0x674e('0x42')](_0x674e('0x8d'));_0x492632[_0x674e('0x42')]('c.createdAt');_0x492632[_0x674e('0x42')]('c.deletedAt');_0x492632[_0x674e('0x42')](_0x674e('0x8e'));_0x492632[_0x674e('0x42')](_0x674e('0x8f'),'TagIds');}if(_0x58db18[_0x674e('0x1f')])_0x492632[_0x674e('0x1f')](_0x58db18['limit']);if(_0x58db18[_0x674e('0x20')])_0x492632[_0x674e('0x20')](_0x58db18[_0x674e('0x20')]);return db[_0x674e('0x85')][_0x674e('0x37')](_0x492632[_0x674e('0x83')](),_0x87b33e);});})['then'](function(_0x56f01f){_0x56f01f[_0x674e('0x53')](function(_0x32acc3){if(_0x32acc3[_0x674e('0x90')]){_0x32acc3[_0x674e('0x91')]=[];_0x32acc3[_0x674e('0x90')][_0x674e('0x52')](',')[_0x674e('0x53')](function(_0x480ab2){_0x32acc3[_0x674e('0x91')][_0x674e('0x30')](_0x3623b4[_0x480ab2]);});}delete _0x32acc3[_0x674e('0x90')];});_0x326e72['rows']=_0x56f01f;return _0x326e72;})['then'](respondWithFilteredResult(_0x18a4d4,_0x58db18));})['catch'](handleError(_0x18a4d4,null));};exports[_0x674e('0x92')]=function(_0x2b262a,_0x2456fd){return db[_0x674e('0x2b')]['find']({'where':{'id':_0x2b262a[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x2456fd,null))[_0x674e('0x27')](removeEntity(_0x2456fd,null))[_0x674e('0x94')](handleError(_0x2456fd,null));};exports[_0x674e('0x95')]=function(_0x4c50eb,_0x4cc98e){return db[_0x674e('0x2b')][_0x674e('0x95')]()[_0x674e('0x27')](function(_0x95c778){delete _0x95c778[_0x674e('0x96')];for(var _0x188564=0x0;_0x188564<Object[_0x674e('0x2c')](_0x95c778)[_0x674e('0x2d')];_0x188564++){var _0x1a78ed=Object[_0x674e('0x2c')](_0x95c778)[_0x188564];if(!_[_0x674e('0x2e')](_0x1a78ed,_0x674e('0x2f'))){_0x95c778[_0x1a78ed][_0x674e('0x97')]=_0x1a78ed;_0x95c778[_0x1a78ed][_0x674e('0x98')]=_0x1a78ed;}}return _0x95c778;})[_0x674e('0x27')](function(_0x3e3dde){var _0x5bfe2d={'where':{'$or':[{'ListId':_0x4c50eb['query']['id']},{'ListId':null}]},'raw':!![]};return db[_0x674e('0x31')]['findAll'](_0x5bfe2d)[_0x674e('0x27')](function(_0x1131c6){for(var _0x114a7e=0x0;_0x114a7e<_0x1131c6[_0x674e('0x2d')];_0x114a7e++){var _0x20b1fb='cf_'+_0x1131c6[_0x114a7e]['id'];_0x3e3dde[_0x20b1fb][_0x674e('0x97')]=_0x20b1fb;_0x3e3dde[_0x20b1fb][_0x674e('0x98')]=_0x1131c6[_0x114a7e]['alias'];_0x3e3dde[_0x20b1fb][_0x674e('0x99')]={'type':_0x1131c6[_0x114a7e][_0x674e('0x35')],'values':_0x1131c6[_0x114a7e][_0x674e('0x9a')]};}Object['keys'](_0x3e3dde)['forEach'](function(_0x10e2b7){if(!_0x3e3dde[_0x10e2b7]['hasOwnProperty'](_0x674e('0x97'))){delete _0x3e3dde[_0x10e2b7];}});return _0x3e3dde;});})[_0x674e('0x27')](respondWithResult(_0x4cc98e,null))['catch'](handleError(_0x4cc98e,null));};exports[_0x674e('0x87')]=function(_0x4123d6,_0xcec1fb){var _0x2b3970;var _0x52196c;var _0x3b1fe3;if(_0x4123d6[_0x674e('0x9b')]['id']){delete _0x4123d6[_0x674e('0x9b')]['id'];}return db[_0x674e('0x2b')][_0x674e('0x9c')]({'where':{'id':[_0x4123d6['body']['to'],_0x4123d6['body'][_0x674e('0x43')]]}})[_0x674e('0x27')](function(_0x2a5bb8){if(_0x2a5bb8){if(_0x2a5bb8[_0x674e('0x2d')]!==0x2){return null;}_0x2a5bb8[0x0]=_0x2a5bb8[0x0][_0x674e('0x9d')]({'plain':!![]});_0x2a5bb8[0x1]=_0x2a5bb8[0x1][_0x674e('0x9d')]({'plain':!![]});delete _0x2a5bb8[0x0]['id'];delete _0x2a5bb8[0x1]['id'];return _[_0x674e('0x9e')](_0x2a5bb8[0x0],_0x2a5bb8[0x1],function(_0x1b98c8,_0x561cb7){if(Array[_0x674e('0x67')](_0x561cb7)&&!_0x561cb7[_0x674e('0x2d')]){return _0x1b98c8;}else if(!_0x561cb7){return _0x1b98c8;}});}})['then'](handleEntityNotFound(_0xcec1fb,null))[_0x674e('0x27')](function(_0x59fb63){if(_0x59fb63){if(_0x59fb63[_0x674e('0x96')]&&_[_0x674e('0x67')](_0x59fb63[_0x674e('0x96')])){_0x59fb63[_0x674e('0x96')]=_0x59fb63[_0x674e('0x96')][_0x674e('0x9f')]();}logger[_0x674e('0xa0')]('[CmContact][merge]\x20to\x20%s\x20from\x20%s',_0x4123d6['body']['to'],_0x4123d6['body'][_0x674e('0x43')]);return db[_0x674e('0xa1')]['destroy']({'where':{'ContactId':[_0x4123d6[_0x674e('0x9b')]['to'],_0x4123d6[_0x674e('0x9b')][_0x674e('0x43')]]}})[_0x674e('0x27')](function(_0x3f82a2){logger[_0x674e('0xa0')](_0x674e('0xa2'),_0x3f82a2);return db[_0x674e('0xa3')]['destroy']({'where':{'ContactId':[_0x4123d6['body']['to'],_0x4123d6[_0x674e('0x9b')][_0x674e('0x43')]]}})[_0x674e('0x27')](function(_0x34a94d){logger[_0x674e('0xa0')](_0x674e('0xa4'),_0x34a94d);return db['CmContact']['create'](_0x59fb63);});});}})['then'](function(_0x116f86){if(_0x116f86){_0x2b3970=_0x116f86;_0x52196c={'ContactId':_0x2b3970['id']};_0x3b1fe3={'where':{'ContactId':[_0x4123d6[_0x674e('0x9b')]['to'],_0x4123d6[_0x674e('0x9b')][_0x674e('0x43')]]}};return db[_0x674e('0xa5')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xa6')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db['ChatOfflineMessage']['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xa7')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db['MailMessage'][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xa7')]['update'](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db[_0x674e('0xa8')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xa9')]['update'](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db[_0x674e('0xaa')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db['FaxInteraction'][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xab')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xac')]['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xad')]['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xae')]['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xaf')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xb0')]['update'](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db[_0x674e('0xb1')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db['ChatQueueReport'][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db[_0x674e('0xb2')]['update'](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db[_0x674e('0xb3')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db['OpenchannelQueueReport'][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xb4')][_0x674e('0x26')](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xb5')]['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xb6')]['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0xb7')]['update'](_0x52196c,_0x3b1fe3);}})['then'](function(){if(_0x2b3970){return db[_0x674e('0xb8')]['update'](_0x52196c,_0x3b1fe3);}})[_0x674e('0x27')](function(){if(_0x2b3970){return db[_0x674e('0x2b')][_0x674e('0x92')]({'where':{'id':[_0x4123d6[_0x674e('0x9b')]['to'],_0x4123d6[_0x674e('0x9b')][_0x674e('0x43')]]}});}})[_0x674e('0x27')](function(){if(_0x2b3970){return _0x2b3970;}})[_0x674e('0x27')](respondWithResult(_0xcec1fb,null))['catch'](handleError(_0xcec1fb,null));};exports[_0x674e('0xb9')]=function(_0x448f16,_0x133969){return db['CmContact'][_0x674e('0x95')]()[_0x674e('0x27')](function(_0x53dffe){if(_0x448f16[_0x674e('0x9b')][_0x674e('0x96')]&&_[_0x674e('0x67')](_0x448f16[_0x674e('0x9b')][_0x674e('0x96')])){if(_0x448f16[_0x674e('0x9b')][_0x674e('0x96')][_0x674e('0x2d')]){_0x448f16[_0x674e('0x9b')][_0x674e('0x96')]=_0x448f16[_0x674e('0x9b')]['tags'][_0x674e('0x9f')](';')+';';}else{_0x448f16[_0x674e('0x9b')][_0x674e('0x96')]=null;}}else{_0x448f16[_0x674e('0x9b')][_0x674e('0x96')]=null;}return db[_0x674e('0x2b')][_0x674e('0xb9')](_0x448f16[_0x674e('0x9b')],{'fields':_[_0x674e('0x2c')](_0x53dffe),'raw':!![]});})[_0x674e('0x27')](respondWithResult(_0x133969,0xc9))[_0x674e('0x94')](handleError(_0x133969,null));};exports[_0x674e('0xba')]=function(_0x4a1c31,_0x147e63){var _0x244cff=[];var _0x42e65d=0x0;var _0x3dbfbe=0x0;var _0x24842a=0x0;return db[_0x674e('0x2b')]['describe']()[_0x674e('0x27')](function(_0x1ac848){return BPromise['each'](_0x4a1c31[_0x674e('0x9b')],function(_0x43724d){var _0x288bf9={'where':{'$or':[]},'defaults':_0x43724d,'fields':_[_0x674e('0x2c')](_0x1ac848),'raw':!![]};if(_0x43724d[_0x674e('0xbb')]){for(var _0x2330df=0x0;_0x2330df<_0x43724d[_0x674e('0xbb')]['length'];_0x2330df++){var _0x3f97b2={};_0x3f97b2[_0x43724d[_0x674e('0xbb')][_0x2330df]]=_0x43724d[_0x43724d[_0x674e('0xbb')][_0x2330df]];_0x288bf9[_0x674e('0x3e')]['$or'][_0x674e('0x30')](_0x3f97b2);}_0x288bf9[_0x674e('0x3e')][_0x674e('0x61')]=_0x43724d[_0x674e('0x61')];}return db[_0x674e('0x2b')]['findOrCreate'](_0x288bf9)[_0x674e('0xbc')](function(_0x24e3ca,_0x16b9f2){if(_0x16b9f2){_0x42e65d++;}else{_0x24842a++;}})[_0x674e('0x94')](function(_0x301f5d){console[_0x674e('0xbd')](_0x301f5d);_0x3dbfbe++;});});})[_0x674e('0x27')](function(_0x10521e){if(_0x10521e){return{'success':_0x42e65d,'failure':_0x3dbfbe,'duplicates':_0x24842a};}})[_0x674e('0x27')](respondWithResult(_0x147e63,0xc9))['catch'](handleError(_0x147e63,null));};exports[_0x674e('0xbe')]=function(_0x5a7ae2,_0x50031a,_0x941221){var _0x45bc33;return db[_0x674e('0x2b')][_0x674e('0x95')]()[_0x674e('0x27')](function(_0x4f5e20){return db['CmContact'][_0x674e('0x4f')]({'where':{'id':_0x5a7ae2[_0x674e('0x93')]['id']},'include':[{'model':db['Tag'],'as':'Tags','attributes':['id',_0x674e('0xbf'),_0x674e('0xc0')],'required':_0x5a7ae2[_0x674e('0x37')][_0x674e('0x66')]?!![]:![]}],'attributes':_['keys'](_0x4f5e20)});})[_0x674e('0x27')](function(_0x5de03c){_0x45bc33=_0x5de03c[_0x674e('0x9d')]({'plain':!![]});var _0x1c7969={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x5de03c&&_0x5de03c[_0x674e('0x61')]){if(_0x5de03c[_0x674e('0x61')]){_0x1c7969['where'][_0x674e('0xc1')][_0x674e('0x30')]({'ListId':{'$ne':_0x5de03c[_0x674e('0x61')]}});}}return db['CmCustomField'][_0x674e('0x9c')](_0x1c7969);})[_0x674e('0x27')](function(_0xa10d45){return _[_0x674e('0xc2')](_0x45bc33,_['map'](_0xa10d45,function(_0x1585ed){return util['format'](_0x674e('0xc3'),_0x1585ed['id']);}));})[_0x674e('0x27')](handleEntityNotFound(_0x50031a,null))[_0x674e('0x27')](respondWithResult(_0x50031a,null))[_0x674e('0x94')](handleError(_0x50031a,null));};exports[_0x674e('0x26')]=function(_0x4db8e8,_0x262d47){var _0x117f98;if(_0x4db8e8[_0x674e('0x9b')]['id']){delete _0x4db8e8[_0x674e('0x9b')]['id'];}return db['CmContact'][_0x674e('0x4f')]({'where':{'id':_0x4db8e8[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x262d47,null))[_0x674e('0x27')](saveUpdates(_0x4db8e8['body'],null))[_0x674e('0x27')](function(_0x3b75cf){_0x117f98=_0x3b75cf;var _0x95fbd6={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x3b75cf&&_0x3b75cf[_0x674e('0x61')]){if(_0x3b75cf['ListId']){_0x95fbd6['where'][_0x674e('0xc1')]['push']({'ListId':{'$ne':_0x3b75cf[_0x674e('0x61')]}});}}return db[_0x674e('0x31')]['findAll'](_0x95fbd6);})['then'](function(_0x2fdad4){if(_0x2fdad4){return _[_0x674e('0xc2')](_[_0x674e('0xc4')](_0x4db8e8['body'],function(_0x4ff67f,_0xb867b5){return _[_0x674e('0x2e')](_0xb867b5,_0x674e('0x2f'));}),_[_0x674e('0x81')](_0x2fdad4,function(_0x3ded07){return util[_0x674e('0xc5')](_0x674e('0xc3'),_0x3ded07['id']);}));}})[_0x674e('0x27')](function(_0x1d0e0b){if(_0x1d0e0b&&!_[_0x674e('0x60')](_0x1d0e0b)){var _0x46ca35=squel[_0x674e('0x26')]()[_0x674e('0xc6')](_0x674e('0x45'))[_0x674e('0xc7')](_0x1d0e0b)['where'](_0x674e('0xc8'),_0x4db8e8[_0x674e('0x93')]['id'])[_0x674e('0xc9')]();return db[_0x674e('0x85')][_0x674e('0x37')](_0x46ca35[_0x674e('0xca')],{'replacements':_0x46ca35[_0x674e('0x9a')]});}})['then'](function(){if(_0x4db8e8[_0x674e('0x9b')][_0x674e('0xcb')]&&_0x117f98){return db['CmHopper'][_0x674e('0x26')]({'phone':_0x4db8e8[_0x674e('0x9b')][_0x674e('0xcb')]},{'where':{'ContactId':_0x117f98['id']}});}})['then'](function(){return _0x117f98;})[_0x674e('0x27')](respondWithResult(_0x262d47,null))['catch'](handleError(_0x262d47,null));};exports['getTags']=function(_0x4ca20a,_0x2c0db3,_0x187698){var _0x34f351={};var _0x41f681={};var _0x2a046c;var _0x51b126;return db[_0x674e('0x2b')][_0x674e('0x32')]({'where':{'id':_0x4ca20a[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x2c0db3,null))[_0x674e('0x27')](function(_0x15dd45){if(_0x15dd45){_0x2a046c=_0x15dd45;_0x41f681['model']=_[_0x674e('0x2c')](db[_0x674e('0x50')]['rawAttributes']);_0x41f681['query']=_[_0x674e('0x2c')](_0x4ca20a['query']);_0x41f681[_0x674e('0x3f')]=_[_0x674e('0x38')](_0x41f681[_0x674e('0x36')],_0x41f681[_0x674e('0x37')]);_0x34f351[_0x674e('0x3a')]=_[_0x674e('0x38')](_0x41f681[_0x674e('0x36')],qs[_0x674e('0x39')](_0x4ca20a[_0x674e('0x37')]['fields']));_0x34f351[_0x674e('0x3a')]=_0x34f351['attributes']['length']?_0x34f351['attributes']:_0x41f681[_0x674e('0x36')];_0x34f351[_0x674e('0x3c')]=qs['sort'](_0x4ca20a['query']['sort']);_0x34f351[_0x674e('0x3e')]=qs[_0x674e('0x3f')](_[_0x674e('0x40')](_0x4ca20a[_0x674e('0x37')],_0x41f681[_0x674e('0x3f')]));if(_0x4ca20a[_0x674e('0x37')][_0x674e('0x5d')]){_0x34f351[_0x674e('0x3e')]=_[_0x674e('0x87')](_0x34f351[_0x674e('0x3e')],{'$or':_[_0x674e('0x81')](_0x34f351['attributes'],function(_0x20ca18){var _0x533d91={};_0x533d91[_0x20ca18]={'$like':'%'+_0x4ca20a['query']['filter']+'%'};return _0x533d91;})});}_0x34f351=_['merge']({},_0x34f351,_0x4ca20a[_0x674e('0xcc')]);return _0x2a046c[_0x674e('0xcd')](_0x34f351);}})[_0x674e('0x27')](function(_0x48e709){if(_0x48e709){_0x51b126=_0x48e709[_0x674e('0x2d')];if(!_0x4ca20a[_0x674e('0x37')][_0x674e('0x5c')](_0x674e('0x3b'))){_0x34f351[_0x674e('0x1f')]=qs[_0x674e('0x1f')](_0x4ca20a[_0x674e('0x37')][_0x674e('0x1f')]);_0x34f351[_0x674e('0x20')]=qs[_0x674e('0x20')](_0x4ca20a['query'][_0x674e('0x20')]);}return _0x2a046c[_0x674e('0xcd')](_0x34f351);}})[_0x674e('0x27')](function(_0x9869ea){if(_0x9869ea){return _0x9869ea?{'count':_0x51b126,'rows':_0x9869ea}:null;}})[_0x674e('0x27')](respondWithResult(_0x2c0db3,null))[_0x674e('0x94')](handleError(_0x2c0db3,null));};exports[_0x674e('0xce')]=function(_0x1d5592,_0x37ddac,_0x1142d6){if(_0x1d5592[_0x674e('0x9b')]['id']){delete _0x1d5592[_0x674e('0x9b')]['id'];}return db[_0x674e('0x2b')][_0x674e('0x32')]({'where':{'id':_0x1d5592[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x37ddac,null))[_0x674e('0x27')](function(_0x24408a){if(_0x24408a){return _0x24408a[_0x674e('0xce')](_0x1d5592[_0x674e('0x9b')]['ids']||[]);}return null;})[_0x674e('0x27')](respondWithResult(_0x37ddac,null))[_0x674e('0x94')](handleError(_0x37ddac,null));};exports[_0x674e('0xcf')]=function(_0x132078,_0x5e1fcc,_0x4aeaf5){var _0x3da23e={'raw':![],'where':{}};var _0x1ec645={};var _0x227913={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x132078[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x5e1fcc,null))['then'](function(_0x302010){if(_0x302010){_0x1ec645[_0x674e('0x36')]=_[_0x674e('0x2c')](db[_0x674e('0xa1')][_0x674e('0xd0')]);_0x1ec645[_0x674e('0x37')]=_['keys'](_0x132078[_0x674e('0x37')]);_0x1ec645[_0x674e('0x3f')]=_[_0x674e('0x38')](_0x1ec645[_0x674e('0x36')],_0x1ec645[_0x674e('0x37')]);_0x3da23e[_0x674e('0x3a')]=_[_0x674e('0x38')](_0x1ec645[_0x674e('0x36')],qs['fields'](_0x132078[_0x674e('0x37')]['fields']));_0x3da23e[_0x674e('0x3a')]=_0x3da23e[_0x674e('0x3a')][_0x674e('0x2d')]?_0x3da23e[_0x674e('0x3a')]:_0x1ec645['model'];if(!_0x132078[_0x674e('0x37')][_0x674e('0x5c')](_0x674e('0x3b'))){_0x3da23e['limit']=qs[_0x674e('0x1f')](_0x132078[_0x674e('0x37')]['limit']);_0x3da23e[_0x674e('0x20')]=qs['offset'](_0x132078[_0x674e('0x37')]['offset']);}_0x3da23e[_0x674e('0x3c')]=qs[_0x674e('0x3d')](_0x132078[_0x674e('0x37')][_0x674e('0x3d')]);_0x3da23e[_0x674e('0x3e')]=qs[_0x674e('0x3f')](_['pick'](_0x132078['query'],_0x1ec645['filters']));_0x3da23e[_0x674e('0x3e')][_0x674e('0xd1')]=_0x302010['id'];if(_0x132078['query']['filter']){_0x3da23e[_0x674e('0x3e')]=_[_0x674e('0x87')](_0x3da23e['where'],{'$or':_[_0x674e('0x81')](_0x3da23e[_0x674e('0x3a')],function(_0x5beadb){var _0x42c567={};_0x42c567[_0x5beadb]={'$like':'%'+_0x132078[_0x674e('0x37')][_0x674e('0x5d')]+'%'};return _0x42c567;})});}_0x3da23e=_['merge']({},_0x3da23e,_0x132078[_0x674e('0xcc')]);return db[_0x674e('0xa1')]['count']({'where':_0x3da23e[_0x674e('0x3e')]})['then'](function(_0xa4110a){_0x227913[_0x674e('0x84')]=_0xa4110a;if(_0x132078[_0x674e('0x37')]['includeAll']){_0x3da23e['include']=[{'all':!![]}];}return db[_0x674e('0xa1')][_0x674e('0x9c')](_0x3da23e);})['then'](function(_0x542099){_0x227913[_0x674e('0xd2')]=_0x542099;return _0x227913;});}})[_0x674e('0x27')](respondWithFilteredResult(_0x5e1fcc,_0x3da23e))[_0x674e('0x94')](handleError(_0x5e1fcc,null));};exports['getHopperHistories']=function(_0x52f33c,_0x23c62a,_0x18408a){var _0x52f632={'raw':!![],'where':{}};var _0x3aac9a={};var _0x6f0102={'count':0x0,'rows':[]};return db[_0x674e('0x2b')][_0x674e('0x32')]({'where':{'id':_0x52f33c[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x23c62a,null))[_0x674e('0x27')](function(_0x412b4){if(_0x412b4){_0x3aac9a['model']=_['keys'](db['CmHopperHistory'][_0x674e('0xd0')]);_0x3aac9a['query']=_[_0x674e('0x2c')](_0x52f33c[_0x674e('0x37')]);_0x3aac9a[_0x674e('0x3f')]=_[_0x674e('0x38')](_0x3aac9a[_0x674e('0x36')],_0x3aac9a[_0x674e('0x37')]);_0x52f632[_0x674e('0x3a')]=_[_0x674e('0x38')](_0x3aac9a[_0x674e('0x36')],qs[_0x674e('0x39')](_0x52f33c[_0x674e('0x37')][_0x674e('0x39')]));_0x52f632['attributes']=_0x52f632[_0x674e('0x3a')]['length']?_0x52f632[_0x674e('0x3a')]:_0x3aac9a['model'];if(!_0x52f33c[_0x674e('0x37')][_0x674e('0x5c')]('nolimit')){_0x52f632['limit']=qs['limit'](_0x52f33c[_0x674e('0x37')][_0x674e('0x1f')]);_0x52f632[_0x674e('0x20')]=qs['offset'](_0x52f33c[_0x674e('0x37')]['offset']);}_0x52f632[_0x674e('0x3c')]=qs[_0x674e('0x3d')](_0x52f33c[_0x674e('0x37')][_0x674e('0x3d')]);_0x52f632[_0x674e('0x3e')]=qs[_0x674e('0x3f')](_[_0x674e('0x40')](_0x52f33c['query'],_0x3aac9a[_0x674e('0x3f')]));_0x52f632[_0x674e('0x3e')][_0x674e('0xd1')]=_0x412b4['id'];if(_0x52f33c[_0x674e('0x37')][_0x674e('0x5d')]){_0x52f632[_0x674e('0x3e')]=_[_0x674e('0x87')](_0x52f632[_0x674e('0x3e')],{'$or':_[_0x674e('0x81')](_0x52f632[_0x674e('0x3a')],function(_0x12ca47){var _0x336e1c={};_0x336e1c[_0x12ca47]={'$like':'%'+_0x52f33c['query'][_0x674e('0x5d')]+'%'};return _0x336e1c;})});}_0x52f632=_[_0x674e('0x87')]({},_0x52f632,_0x52f33c[_0x674e('0xcc')]);return db[_0x674e('0xaf')]['count']({'where':_0x52f632[_0x674e('0x3e')]})[_0x674e('0x27')](function(_0x1ae39c){_0x6f0102[_0x674e('0x84')]=_0x1ae39c;if(_0x52f33c[_0x674e('0x37')]['includeAll']){_0x52f632['include']=[{'all':!![]}];}return db[_0x674e('0xaf')][_0x674e('0x9c')](_0x52f632);})[_0x674e('0x27')](function(_0x3c8fab){_0x6f0102[_0x674e('0xd2')]=_0x3c8fab;return _0x6f0102;});}})[_0x674e('0x27')](respondWithFilteredResult(_0x23c62a,_0x52f632))[_0x674e('0x94')](handleError(_0x23c62a,null));};exports[_0x674e('0xd3')]=function(_0x2aa016,_0x53f67b,_0x40d9eb){var _0xa5e953={'raw':!![],'where':{}};var _0xda11cc={};var _0x2c0d4e={'count':0x0,'rows':[]};return db[_0x674e('0x2b')]['findOne']({'where':{'id':_0x2aa016['params']['id']}})['then'](handleEntityNotFound(_0x53f67b,null))[_0x674e('0x27')](function(_0x4e97aa){if(_0x4e97aa){_0xda11cc[_0x674e('0x36')]=_[_0x674e('0x2c')](db['CmHopperFinal'][_0x674e('0xd0')]);_0xda11cc[_0x674e('0x37')]=_[_0x674e('0x2c')](_0x2aa016[_0x674e('0x37')]);_0xda11cc['filters']=_['intersection'](_0xda11cc['model'],_0xda11cc[_0x674e('0x37')]);_0xa5e953[_0x674e('0x3a')]=_[_0x674e('0x38')](_0xda11cc[_0x674e('0x36')],qs[_0x674e('0x39')](_0x2aa016[_0x674e('0x37')][_0x674e('0x39')]));_0xa5e953[_0x674e('0x3a')]=_0xa5e953[_0x674e('0x3a')]['length']?_0xa5e953[_0x674e('0x3a')]:_0xda11cc[_0x674e('0x36')];if(!_0x2aa016['query']['hasOwnProperty']('nolimit')){_0xa5e953[_0x674e('0x1f')]=qs[_0x674e('0x1f')](_0x2aa016['query']['limit']);_0xa5e953[_0x674e('0x20')]=qs[_0x674e('0x20')](_0x2aa016[_0x674e('0x37')][_0x674e('0x20')]);}_0xa5e953['order']=qs['sort'](_0x2aa016[_0x674e('0x37')][_0x674e('0x3d')]);_0xa5e953[_0x674e('0x3e')]=qs[_0x674e('0x3f')](_[_0x674e('0x40')](_0x2aa016[_0x674e('0x37')],_0xda11cc[_0x674e('0x3f')]));_0xa5e953[_0x674e('0x3e')][_0x674e('0xd1')]=_0x4e97aa['id'];if(_0x2aa016[_0x674e('0x37')][_0x674e('0x5d')]){_0xa5e953['where']=_['merge'](_0xa5e953[_0x674e('0x3e')],{'$or':_[_0x674e('0x81')](_0xa5e953[_0x674e('0x3a')],function(_0x24069e){var _0x6de505={};_0x6de505[_0x24069e]={'$like':'%'+_0x2aa016[_0x674e('0x37')]['filter']+'%'};return _0x6de505;})});}_0xa5e953=_[_0x674e('0x87')]({},_0xa5e953,_0x2aa016[_0x674e('0xcc')]);return db['CmHopperFinal'][_0x674e('0x84')]({'where':_0xa5e953[_0x674e('0x3e')]})[_0x674e('0x27')](function(_0x423281){_0x2c0d4e[_0x674e('0x84')]=_0x423281;if(_0x2aa016[_0x674e('0x37')][_0x674e('0xd4')]){_0xa5e953[_0x674e('0xd5')]=[{'all':!![]}];}return db[_0x674e('0xae')][_0x674e('0x9c')](_0xa5e953);})['then'](function(_0x55d408){_0x2c0d4e[_0x674e('0xd2')]=_0x55d408;return _0x2c0d4e;});}})[_0x674e('0x27')](respondWithFilteredResult(_0x53f67b,_0xa5e953))[_0x674e('0x94')](handleError(_0x53f67b,null));};exports[_0x674e('0xd6')]=function(_0x144f88,_0x149a57,_0x4a758a){var _0xb564c6={'raw':!![],'where':{}};var _0x2f2392={};var _0x5ce578={'count':0x0,'rows':[]};return db[_0x674e('0x2b')][_0x674e('0x32')]({'where':{'id':_0x144f88[_0x674e('0x93')]['id']}})[_0x674e('0x27')](handleEntityNotFound(_0x149a57,null))[_0x674e('0x27')](function(_0x19d39d){if(_0x19d39d){_0x2f2392[_0x674e('0x36')]=_[_0x674e('0x2c')](db['JscriptySessionReport']['rawAttributes']);_0x2f2392[_0x674e('0x37')]=_[_0x674e('0x2c')](_0x144f88[_0x674e('0x37')]);_0x2f2392[_0x674e('0x3f')]=_[_0x674e('0x38')](_0x2f2392[_0x674e('0x36')],_0x2f2392[_0x674e('0x37')]);_0xb564c6[_0x674e('0x3a')]=_[_0x674e('0x38')](_0x2f2392[_0x674e('0x36')],qs['fields'](_0x144f88[_0x674e('0x37')]['fields']));_0xb564c6[_0x674e('0x3a')]=_0xb564c6[_0x674e('0x3a')][_0x674e('0x2d')]?_0xb564c6[_0x674e('0x3a')]:_0x2f2392[_0x674e('0x36')];if(!_0x144f88[_0x674e('0x37')][_0x674e('0x5c')](_0x674e('0x3b'))){_0xb564c6[_0x674e('0x1f')]=qs['limit'](_0x144f88['query'][_0x674e('0x1f')]);_0xb564c6[_0x674e('0x20')]=qs['offset'](_0x144f88[_0x674e('0x37')]['offset']);}_0xb564c6[_0x674e('0x3c')]=qs[_0x674e('0x3d')](_0x144f88['query'][_0x674e('0x3d')]);_0xb564c6['where']=qs[_0x674e('0x3f')](_['pick'](_0x144f88[_0x674e('0x37')],_0x2f2392[_0x674e('0x3f')]));_0xb564c6[_0x674e('0x3e')]['ContactId']=_0x19d39d['id'];if(_0x144f88[_0x674e('0x37')][_0x674e('0x5d')]){_0xb564c6[_0x674e('0x3e')]=_['merge'](_0xb564c6['where'],{'$or':_[_0x674e('0x81')](_0xb564c6[_0x674e('0x3a')],function(_0x40effb){var _0xefc6cc={};_0xefc6cc[_0x40effb]={'$like':'%'+_0x144f88['query']['filter']+'%'};return _0xefc6cc;})});}_0xb564c6=_[_0x674e('0x87')]({},_0xb564c6,_0x144f88['options']);return db[_0x674e('0xb5')][_0x674e('0x84')]({'where':_0xb564c6[_0x674e('0x3e')]})['then'](function(_0x3f6e9b){_0x5ce578[_0x674e('0x84')]=_0x3f6e9b;if(_0x144f88[_0x674e('0x37')][_0x674e('0xd4')]){_0xb564c6[_0x674e('0xd5')]=[{'all':!![]}];}return db[_0x674e('0xb5')][_0x674e('0x9c')](_0xb564c6);})['then'](function(_0x150d81){_0x5ce578[_0x674e('0xd2')]=_0x150d81;return _0x5ce578;});}})[_0x674e('0x27')](respondWithFilteredResult(_0x149a57,_0xb564c6))[_0x674e('0x94')](handleError(_0x149a57,null));};exports[_0x674e('0xd7')]=function(_0x471076,_0x403935,_0x121d33){try{if(!_0x471076[_0x674e('0x9b')]['ListId']){throw new Error(_0x674e('0xd8'));}if(!_0x471076[_0x674e('0x9b')][_0x674e('0xd9')]){throw new Error(_0x674e('0xda'));}if(!_0x471076[_0x674e('0x9b')][_0x674e('0xdb')]){throw new Error(_0x674e('0xdc'));}if(!_0x471076['body'][_0x674e('0xdd')]){throw new Error(_0x674e('0xde'));}var _0x236bb2=_0x471076[_0x674e('0x9b')][_0x674e('0xd9')][_0x674e('0x52')](',');var _0x32fe80=_0x471076[_0x674e('0x9b')][_0x674e('0xdb')][_0x674e('0x52')](',');if(!_0x236bb2[_0x674e('0x2d')]||!_0x32fe80[_0x674e('0x2d')]||_0x236bb2[_0x674e('0x2d')]!==_0x32fe80[_0x674e('0x2d')]){throw new Error('Incorrect\x20binding\x20parameters\x20passed!');}_0x471076[_0x674e('0x9b')]['fields']=_['zipObject'](_0x236bb2,_0x32fe80);if(!_0x471076[_0x674e('0x9b')][_0x674e('0x39')][_0x674e('0xcb')]){throw new Error(_0x674e('0xdf'));}if(!_0x471076[_0x674e('0x9b')]['fields'][_0x674e('0xe0')]){throw new Error(_0x674e('0xe1'));}var _0x4ba38a=path[_0x674e('0x9f')](config['root'],_0x674e('0xe2'),_0x471076[_0x674e('0xe3')]['filename']);fs[_0x674e('0xe4')](_0x4ba38a,parseInt(_0x674e('0xe5'),0x8));var _0x15ef08=require(_0x674e('0xe6'))[_0x674e('0xe7')](path[_0x674e('0x9f')](__dirname,_0x674e('0xe8')),[_0x4ba38a,_0x471076[_0x674e('0x9b')]['binding_keys'],_0x471076['body'][_0x674e('0xdb')],_0x471076[_0x674e('0x9b')][_0x674e('0x61')],_0x471076['body']['CompanyId'],_0x471076[_0x674e('0x9b')][_0x674e('0xbb')],_0x471076[_0x674e('0x9b')][_0x674e('0xdd')]]);return _0x403935[_0x674e('0x1c')](0xc8)[_0x674e('0x22')]({'message':_0x674e('0xe9'),'pid':_0x15ef08[_0x674e('0xea')]});}catch(_0x4d394c){return _0x403935[_0x674e('0x1c')](0x1f4)[_0x674e('0x29')](_0x4d394c);}};exports[_0x674e('0xeb')]=function(_0x3372be,_0x2a9667,_0x18522f){var _0x26c993=fs[_0x674e('0xec')](_0x3372be[_0x674e('0xe3')]['path']);Papa[_0x674e('0xed')](_0x26c993,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x44cc37){return _0x2a9667[_0x674e('0x1c')](0xc8)[_0x674e('0x22')]({'file':_0x3372be[_0x674e('0xe3')],'fields':_0x44cc37[_0x674e('0xee')][_0x674e('0x39')]});}});};exports[_0x674e('0xef')]=function(_0x13f903,_0x34867f,_0x36844d){return db['User'][_0x674e('0x9c')]({'raw':!![],'attributes':['id'],'where':{'role':_0x674e('0x82')}})[_0x674e('0x27')](function(_0x17f74f){var _0x4082f3=![];if(!_0x13f903[_0x674e('0x9b')]['ListId']){throw new Error(_0x674e('0xd8'));}if(!_0x13f903[_0x674e('0x9b')][_0x674e('0xf0')][_0x674e('0xcb')]){throw new Error(_0x674e('0xdf'));}if(!_0x13f903['body']['binding'][_0x674e('0xe0')]){throw new Error(_0x674e('0xe1'));}if(!_0x13f903['body'][_0x674e('0xdd')]){throw new Error(_0x674e('0xde'));}var _0x579969=require(_0x674e('0xe6'))[_0x674e('0xe7')](path[_0x674e('0x9f')](__dirname,_0x674e('0xf1')),[_0x13f903[_0x674e('0x93')]['id'],JSON[_0x674e('0xf2')](_0x13f903[_0x674e('0x9b')]),JSON[_0x674e('0xf2')](_0x17f74f)]);_0x579969['on']('message',function(_0x2087ae){_0x4082f3=!![];return _0x34867f[_0x674e('0x1c')](0xc8)['json']({'message':_0x674e('0xf3'),'pid':_0x579969[_0x674e('0xea')]});});_0x579969['on']('exit',function(_0x2c9dfb){if(_0x2c9dfb&&!_0x4082f3){return _0x34867f[_0x674e('0x1c')](0x1f4)[_0x674e('0x22')]({'message':_0x674e('0xf4'),'pid':_0x579969[_0x674e('0xea')]});}});})[_0x674e('0x94')](handleError(_0x34867f,null));};exports['getJourney']=function(_0x167f94,_0xeb2455){var _0x3da6ef=[_0x674e('0xf5'),_0x674e('0xf6'),_0x674e('0xf7'),_0x674e('0xf8'),_0x674e('0xf9'),_0x674e('0xfa'),_0x674e('0xfb')];var _0x4d6c3f={'offset':0x0,'order':qs[_0x674e('0x3d')]('-createdAt')},_0x55dcea={'count':0x0,'rows':[]};Promise[_0x674e('0x7b')]()[_0x674e('0x27')](function(){if(_0x167f94[_0x674e('0x37')]['channel']){if(!_['includes'](_0x3da6ef,_0x167f94[_0x674e('0x37')][_0x674e('0xfc')][_0x674e('0xfd')]())){throw new Error('Invalid\x20channel');}_0x3da6ef=[_0x167f94[_0x674e('0x37')][_0x674e('0xfc')][_0x674e('0xfd')]()];}if(_0x167f94['query'][_0x674e('0xfe')]){try{var _0x1fec9b=JSON[_0x674e('0xed')](_0x167f94[_0x674e('0x37')][_0x674e('0xfe')]);if(!moment(_0x1fec9b[_0x674e('0x43')])[_0x674e('0xff')]()){throw new Error(_0x674e('0x100'));}if(!moment(_0x1fec9b['to'])[_0x674e('0xff')]()){throw new Error(_0x674e('0x101'));}}catch(_0x3c87d1){throw new Error('Invalid\x20createdAt\x20filter');}}if(!_0x167f94[_0x674e('0x37')][_0x674e('0x5c')](_0x674e('0x3b'))){_0x4d6c3f[_0x674e('0x1f')]=qs[_0x674e('0x1f')](_0x167f94[_0x674e('0x37')][_0x674e('0x1f')]||0xa);_0x4d6c3f[_0x674e('0x20')]=qs['offset'](_0x167f94[_0x674e('0x37')][_0x674e('0x20')]);}var _0x504286=_0x3da6ef[_0x674e('0x81')](function(_0x349315){if(_0x349315===_0x674e('0xfb')){var _0xccb090={'attributes':['id',_0x674e('0x102'),_0x674e('0x35'),_0x674e('0x103'),_0x674e('0x104'),_0x674e('0x105'),'starttime','endtime',_0x674e('0x106'),_0x674e('0x107'),_0x674e('0x108'),'userDisposition',_0x674e('0x109'),'userThirdDisposition',_0x674e('0x10a')],'where':{'ContactId':_0x167f94[_0x674e('0x93')]['id']},'include':[{'model':db[_0x674e('0x55')],'as':_0x674e('0x55'),'attributes':['id',_0x674e('0xbf'),_0x674e('0x10b'),'alias']}],'order':[['createdAt',_0x674e('0x78')]]};if(_0x167f94['query']['range']){_0xccb090['where'][_0x674e('0x108')]={'$gte':_0x1fec9b['from'],'$lte':_0x1fec9b['to']};}return db[_0x674e('0xb1')][_0x674e('0x10c')](_0xccb090)['then'](function(_0x418259){_0x55dcea[_0x674e('0x84')]+=_0x418259[_0x674e('0x84')];return _[_0x674e('0x81')](_0x418259[_0x674e('0xd2')],function(_0x87125){var _0x16ebc4=_0x87125['get']({'plain':!![]});_0x16ebc4[_0x674e('0xfc')]=_0x349315;if(_0x16ebc4[_0x674e('0x55')]){_0x16ebc4[_0x674e('0x55')]={'id':_0x16ebc4[_0x674e('0x55')]['id'],'name':_0x16ebc4[_0x674e('0x55')][_0x674e('0xbf')],'fullname':_0x16ebc4['User']['fullname'],'alias':_0x16ebc4[_0x674e('0x55')][_0x674e('0x10d')]};}return _0x16ebc4;});});}else{var _0x10daec=_[_0x674e('0x10e')](_0x349315)+(_0x349315===_0x674e('0xf6')?_0x674e('0x10f'):_0x674e('0x110'));var _0x22348b={'attributes':['id',_0x674e('0x111'),_0x674e('0x112'),_0x674e('0x108'),'note',_0x674e('0x113'),_0x674e('0x114'),'thirdDisposition',_0x674e('0x10a'),_0x10daec+'Id'],'where':{'ContactId':_0x167f94[_0x674e('0x93')]['id']},'include':[{'model':db[_0x10daec],'as':_0x674e('0x110'),'attributes':['id',_0x674e('0xbf'),_0x674e('0x115')]},{'model':db['User'],'as':_0x674e('0x116'),'attributes':['id',_0x674e('0xbf'),_0x674e('0x10b')]},{'model':db[_0x674e('0x50')],'as':'Tags','attributes':['id',_0x674e('0xbf'),'color'],'through':{'attributes':[]}}],'order':[[_0x674e('0x108'),'DESC']]};if(_0x167f94['query'][_0x674e('0xfe')]){_0x22348b[_0x674e('0x3e')][_0x674e('0x108')]={'$gte':_0x1fec9b[_0x674e('0x43')],'$lte':_0x1fec9b['to']};}switch(_0x349315){case _0x674e('0xf6'):_0x22348b[_0x674e('0x3a')][_0x674e('0x30')](_0x674e('0x117'),_0x674e('0x118'),_0x674e('0x119'),_0x674e('0x11a'),_0x674e('0x11b'),_0x674e('0x11c'),_0x674e('0x11d'),_0x674e('0x11e'),_0x674e('0x11f'));break;case _0x674e('0xf5'):_0x22348b['attributes']['push']('subject',_0x674e('0x120'));break;case'openchannel':_0x22348b['attributes']['push'](_0x674e('0x121'),'threadId');break;}return db[_[_0x674e('0x10e')](_0x349315)+_0x674e('0x122')][_0x674e('0x10c')](_0x22348b)[_0x674e('0x27')](function(_0x4070fd){_0x55dcea[_0x674e('0x84')]+=_0x4070fd[_0x674e('0x84')];return _[_0x674e('0x81')](_0x4070fd[_0x674e('0xd2')],function(_0x14ed41){var _0x1fdb2c=_0x14ed41[_0x674e('0x9d')]({'plain':!![]});_0x1fdb2c[_0x674e('0xfc')]=_0x349315;if(_0x1fdb2c[_0x674e('0x116')]){_0x1fdb2c[_0x674e('0x116')]={'id':_0x1fdb2c[_0x674e('0x116')]['id'],'name':_0x1fdb2c[_0x674e('0x116')][_0x674e('0xbf')],'fullname':_0x1fdb2c[_0x674e('0x116')][_0x674e('0x10b')]};}return _0x1fdb2c;});});}});return Promise[_0x674e('0x33')](_0x504286);})['then'](function(_0x5bc640){return _(_0x5bc640)[_0x674e('0x123')]()[_0x674e('0x124')](_0x674e('0x108'))[_0x674e('0x125')]()[_0x674e('0x51')]();})[_0x674e('0x27')](function(_0x102239){_0x55dcea['rows']=_0x4d6c3f[_0x674e('0x1f')]?_0x102239[_0x674e('0x126')](_0x4d6c3f[_0x674e('0x20')],_0x4d6c3f[_0x674e('0x20')]+_0x4d6c3f[_0x674e('0x1f')]):_0x102239;return _0x55dcea;})['then'](respondWithFilteredResult(_0xeb2455,_0x4d6c3f))[_0x674e('0x94')](handleError(_0xeb2455,null));};
\ No newline at end of file