Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / cmContact / cmContact.controller.js
index abbc185..9db97d9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5bf6=['../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','./cmContact.socket','register','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','then','sendStatus','name','send','index','CmContact','describe','length','startsWith','cf_','push','CmCustomField','findOne','all','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','select','field','from','tools_tags','left_join','cm_user_has_contacts','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','t.id\x20=\x20ct.TagId','c.deletedAt\x20IS\x20NULL','expr','parseSearch','search','sqlOperator','conditions','Tag','value','split','map','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','and','uc.UserId\x20=\x20?','fieldType','datetime','castTo','DATE','buildExpression','type','text','start','filter','Contact','isEmpty','c.ListId\x20IN\x20?','concat','tag','replace','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','Sequelize','QueryTypes','SELECT','clone','c.id','t.id\x20IN\x20?','resolve','user','agent','some','getLists','c.ListId\x20IS\x20NULL','role','ListId','sequelize','toString','count','keyBy','c.firstName','c.lastName','c.phone','c.mobile','c.email','c.ListId','c.deletedAt','c.CompanyId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','rows','catch','destroy','find','tags','displayName','columnName','alias','custom','merge','body','findAll','get','isArray','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','CmHopperHistory','ReportAgentPreview','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','SmsQueueReport','JscriptySessionReport','create','bulkCreate','each','duplicates','$or','findOrCreate','params','color','$and','omit','cf_%d','pickBy','table','setFields','id\x20=\x20?','values','phone','getTags','rawAttributes','options','nolimit','setTags','ids','getHoppers','ContactId','includeAll','include','getHopperHistories','getHopperFinals','CmHopperFinal','getJscriptySessions','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','Incorrect\x20binding\x20parameters\x20passed!','zipObject','firstName','join','root','filename','chmodSync','0777','child_process','fork','File\x20uploaded\x20correctly!','pid','upload','createReadStream','file','parse','meta','import','binding','socket_timestamp','stringify','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','getJourney','mail','fax','whatsapp','voice','channel','includes','Invalid\x20channel','toLowerCase','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','uniqueid','source','callerid','duration','note','userDisposition','userSecondDisposition','userThirdDisposition','fullname','createdAt','DESC','findAndCountAll','startCase','chat','Website','Account','closed','closedAt','disposition','secondDisposition','thirdDisposition','UserId','key','browserName','customerIp','deviceModel','osName','ratingType','ratingValue','referer','subject','substatus','openchannel','externalUrl','threadId','Owner','flatten','sortBy','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch'];(function(_0x33d38e,_0x52ca70){var _0x45712f=function(_0x323f42){while(--_0x323f42){_0x33d38e['push'](_0x33d38e['shift']());}};_0x45712f(++_0x52ca70);}(_0x5bf6,0x10e));var _0x65bf=function(_0x47e549,_0x2e53d6){_0x47e549=_0x47e549-0x0;var _0x251374=_0x5bf6[_0x47e549];return _0x251374;};'use strict';var pdf=require(_0x65bf('0x0'));var emlformat=require(_0x65bf('0x1'));var rimraf=require(_0x65bf('0x2'));var zipdir=require(_0x65bf('0x3'));var jsonpatch=require(_0x65bf('0x4'));var rp=require(_0x65bf('0x5'));var moment=require(_0x65bf('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x65bf('0x7'));var util=require(_0x65bf('0x8'));var path=require(_0x65bf('0x9'));var sox=require(_0x65bf('0xa'));var csv=require(_0x65bf('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x65bf('0xc'));var squel=require(_0x65bf('0xd'));var crypto=require('crypto');var jsforce=require(_0x65bf('0xe'));var deskjs=require(_0x65bf('0xf'));var toCsv=require('to-csv');var querystring=require(_0x65bf('0x10'));var Papa=require(_0x65bf('0x11'));var Redis=require('ioredis');var authService=require(_0x65bf('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x65bf('0x13'));var hardwareService=require(_0x65bf('0x14'));var logger=require(_0x65bf('0x15'))(_0x65bf('0x16'));var utils=require(_0x65bf('0x17'));var config=require(_0x65bf('0x18'));var licenseUtil=require(_0x65bf('0x19'));var db=require(_0x65bf('0x1a'))['db'];config[_0x65bf('0x1b')]=_[_0x65bf('0x1c')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x65bf('0x1d'))(new Redis(config['redis']));require(_0x65bf('0x1e'))[_0x65bf('0x1f')](socket);function respondWithStatusCode(_0x3d0f94,_0x206b36){_0x206b36=_0x206b36||0xcc;return function(_0x2e798b){if(_0x2e798b){return _0x3d0f94['sendStatus'](_0x206b36);}return _0x3d0f94[_0x65bf('0x20')](_0x206b36)[_0x65bf('0x21')]();};}function respondWithResult(_0x1e50c5,_0x66415f){_0x66415f=_0x66415f||0xc8;return function(_0x314f35){if(_0x314f35){return _0x1e50c5['status'](_0x66415f)[_0x65bf('0x22')](_0x314f35);}};}function respondWithFilteredResult(_0x252455,_0x53ed70){return function(_0x147841){if(_0x147841){var _0x4ba745=_0x147841['count'],_0x1c48e9=_0x53ed70[_0x65bf('0x23')],_0x3a0bca=_0x53ed70[_0x65bf('0x23')]+_0x53ed70[_0x65bf('0x24')],_0xe7c358;if(_0x3a0bca>=_0x4ba745){_0x3a0bca=_0x4ba745;_0xe7c358=0xc8;}else{_0xe7c358=0xce;}_0x252455[_0x65bf('0x20')](_0xe7c358);return _0x252455[_0x65bf('0x25')](_0x65bf('0x26'),_0x1c48e9+'-'+_0x3a0bca+'/'+_0x4ba745)[_0x65bf('0x22')](_0x147841);}return null;};}function patchUpdates(_0x44c0ae){return function(_0x17c23b){try{jsonpatch[_0x65bf('0x27')](_0x17c23b,_0x44c0ae,!![]);}catch(_0x2dd960){return BPromise[_0x65bf('0x28')](_0x2dd960);}return _0x17c23b[_0x65bf('0x29')]();};}function saveUpdates(_0xbb6ea3,_0x3fe5f6){return function(_0x3ffe10){if(_0x3ffe10){return _0x3ffe10[_0x65bf('0x2a')](_0xbb6ea3)[_0x65bf('0x2b')](function(_0x156b56){return _0x156b56;});}return null;};}function removeEntity(_0x21b04e,_0x2b4813){return function(_0x4c0dd2){if(_0x4c0dd2){return _0x4c0dd2['destroy']()['then'](function(){_0x21b04e[_0x65bf('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3af5ba,_0x446f1b){return function(_0x408d9e){if(!_0x408d9e){_0x3af5ba[_0x65bf('0x2c')](0x194);}return _0x408d9e;};}function handleError(_0x348160,_0x488aad){_0x488aad=_0x488aad||0x1f4;return function(_0x199313){logger['error'](_0x199313['stack']);if(_0x199313['name']){delete _0x199313[_0x65bf('0x2d')];}_0x348160[_0x65bf('0x20')](_0x488aad)[_0x65bf('0x2e')](_0x199313);};}exports[_0x65bf('0x2f')]=function(_0x32b4b6,_0x2f6167){var _0x493c57={},_0x2ceac0={},_0xd43e29={'count':0x0,'rows':[]};return db[_0x65bf('0x30')][_0x65bf('0x31')]()[_0x65bf('0x2b')](function(_0x2c1db3){var _0x4e7878=[];for(var _0x5a224e=0x0;_0x5a224e<Object['keys'](_0x2c1db3)[_0x65bf('0x32')];_0x5a224e++){var _0x303d44=Object['keys'](_0x2c1db3)[_0x5a224e];if(_[_0x65bf('0x33')](_0x303d44,_0x65bf('0x34'))){_0x4e7878[_0x65bf('0x35')](db[_0x65bf('0x36')][_0x65bf('0x37')]({'where':{'id':_['trimStart'](_0x303d44,_0x65bf('0x34'))},'raw':!![]}));}}return BPromise[_0x65bf('0x38')](_0x4e7878)[_0x65bf('0x2b')](function(_0x5ae71f){for(var _0x1650aa=0x0;_0x1650aa<_0x5ae71f[_0x65bf('0x32')];_0x1650aa++){if(_0x5ae71f[_0x1650aa]){var _0x2b496d=_0x65bf('0x34')+_0x5ae71f[_0x1650aa]['id'];var _0x4f98b1=_0x2c1db3[_0x2b496d];_0x4f98b1['fieldType']=_0x5ae71f[_0x1650aa]['type'];}}return _0x2c1db3;});})['then'](function(_0x2dd670){_0x2ceac0[_0x65bf('0x39')]=_[_0x65bf('0x3a')](_0x2dd670);_0x2ceac0[_0x65bf('0x3b')]=_[_0x65bf('0x3a')](_0x32b4b6[_0x65bf('0x3b')]);_0x2ceac0[_0x65bf('0x3c')]=_[_0x65bf('0x3d')](_0x2ceac0[_0x65bf('0x39')],_0x2ceac0[_0x65bf('0x3b')]);_0x493c57[_0x65bf('0x3e')]=_[_0x65bf('0x3d')](_0x2ceac0[_0x65bf('0x39')],qs['fields'](_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x3f')]));_0x493c57[_0x65bf('0x3e')]=_0x493c57[_0x65bf('0x3e')][_0x65bf('0x32')]?_0x493c57[_0x65bf('0x3e')]:_0x2ceac0[_0x65bf('0x39')];if(!_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x40')]('nolimit')){_0x493c57[_0x65bf('0x24')]=qs[_0x65bf('0x24')](_0x32b4b6[_0x65bf('0x3b')]['limit']);_0x493c57[_0x65bf('0x23')]=qs[_0x65bf('0x23')](_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x23')]);}_0x493c57[_0x65bf('0x41')]=qs[_0x65bf('0x42')](_0x32b4b6['query'][_0x65bf('0x42')]);_0x493c57[_0x65bf('0x43')]=qs[_0x65bf('0x3c')](_[_0x65bf('0x44')](_0x32b4b6[_0x65bf('0x3b')],_0x2ceac0[_0x65bf('0x3c')]),_0x2dd670);var _0x42dfe9=[];var _0x42c9bd=squel[_0x65bf('0x45')]()['field']('id')[_0x65bf('0x46')](_0x65bf('0x2d'))[_0x65bf('0x46')]('color')[_0x65bf('0x47')](_0x65bf('0x48'));var _0x2984f9=squel[_0x65bf('0x45')]()[_0x65bf('0x47')]('cm_contacts','c')[_0x65bf('0x49')](_0x65bf('0x4a'),'uc',_0x65bf('0x4b'))[_0x65bf('0x49')](_0x65bf('0x4c'),'ct','ct.CmContactId\x20=\x20c.id')[_0x65bf('0x49')](_0x65bf('0x48'),'t',_0x65bf('0x4d'))[_0x65bf('0x43')](_0x65bf('0x4e'));var _0x1bad76=squel[_0x65bf('0x4f')]();var _0x3d3317=[];var _0xd18ff0=squel[_0x65bf('0x4f')]();var _0xf78ccd;if(_0x32b4b6[_0x65bf('0x3b')]['search']){_0xf78ccd=as[_0x65bf('0x50')](_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x51')]);var _0x3a3c20=_0xf78ccd[_0x65bf('0x52')];for(var _0x48eb8b=0x0;_0x48eb8b<_0xf78ccd[_0x65bf('0x53')][_0x65bf('0x32')];_0x48eb8b++){var _0x3f1e6f=_0xf78ccd[_0x65bf('0x53')][_0x48eb8b];var _0x5eb9a5='c';var _0x542ec9=_(_0x2dd670)[_0x65bf('0x3a')]()['find'](function(_0x58a6fd){return _0x58a6fd===_0x3f1e6f[_0x65bf('0x46')];});if(_0x542ec9)_0x542ec9=_0x2dd670[_0x3f1e6f['field']];if(!_0x542ec9){if(_0x3f1e6f[_0x65bf('0x46')]===_0x65bf('0x54')){var _0x44becf=_0x3f1e6f[_0x65bf('0x55')][_0x65bf('0x56')](',')[_0x65bf('0x57')](function(_0x216760){return Number(_0x216760);});_0x44becf[_0x65bf('0x58')](function(_0x2b9b05){_0xd18ff0['or'](_0x65bf('0x59'),'%,'+_0x2b9b05+',%');});_0x3d3317=_['union'](_0x3d3317,_0x44becf);}else if(_0x3f1e6f[_0x65bf('0x46')]===_0x65bf('0x5a')){_0x1bad76[_0x65bf('0x5b')](_0x65bf('0x5c'),_0x3f1e6f[_0x65bf('0x55')]);}}else{if(_0x3f1e6f[_0x65bf('0x46')]==='dateOfBirth'||_0x542ec9[_0x65bf('0x5d')]===_0x65bf('0x5e'))_0x3f1e6f[_0x65bf('0x5f')]=_0x65bf('0x60');var _0x2cbccc=as[_0x65bf('0x61')](_0x5eb9a5,_0x542ec9[_0x65bf('0x62')],_0x3f1e6f);_0x1bad76[_0x3a3c20](_0x2cbccc[_0x65bf('0x63')],_0x2cbccc['value'][_0x65bf('0x64')],_0x2cbccc['value'][_0x65bf('0x21')]);}}}else{var _0x574fa2=_(Object[_0x65bf('0x3a')](_0x32b4b6['query']))[_0x65bf('0x57')](function(_0x4922ce){return _0x2dd670[_0x65bf('0x40')](_0x4922ce)?_0x4922ce:undefined;})[_0x65bf('0x65')](function(_0x32f586){return!_['isNil'](_0x32f586);})['value']();if(_0x32b4b6['query'][_0x65bf('0x66')])_0x574fa2[_0x65bf('0x35')](_0x65bf('0x66'));if(!_[_0x65bf('0x67')](_0x574fa2)){_0x574fa2[_0x65bf('0x58')](function(_0x2266a5){if(_0x2266a5==='ListId'){_0x2984f9['where'](_0x65bf('0x68'),[][_0x65bf('0x69')](_0x32b4b6[_0x65bf('0x3b')][_0x2266a5]));}else if(_0x2266a5==='Contact'){var _0x4e5637='%'+_0x32b4b6[_0x65bf('0x3b')][_0x2266a5]+'%';_0x2984f9['where']('CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?',_0x4e5637);}else{_0x2984f9[_0x65bf('0x43')]('c.'+_0x2266a5+'\x20=\x20?',_0x32b4b6['query'][_0x2266a5]);}});}if(_0x32b4b6[_0x65bf('0x3b')]['tag']){_0x3d3317=_['isArray'](_0x32b4b6['query'][_0x65bf('0x6a')])?_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x6a')]:new Array(_0x32b4b6['query'][_0x65bf('0x6a')]);_0x3d3317[_0x65bf('0x58')](function(_0x521039){_0xd18ff0['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x521039+',%');});}if(_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x65')]){var _0xc7dbd1=_0x32b4b6[_0x65bf('0x3b')]['filter'][_0x65bf('0x6b')]('\x5c','\x5c\x5c')[_0x65bf('0x6b')](/'/g,'\x27\x27');if(_0xc7dbd1[_0x65bf('0x56')]('\x20')['length']>0x1){_0x1bad76['or'](_0x65bf('0x6c'),qs['getFullTextValue'](_0xc7dbd1),null);}else{if(qs['isNumeric'](_0xc7dbd1)){_0x1bad76['or'](_0x65bf('0x6d'),_0xc7dbd1+'%');_0x1bad76['or'](_0x65bf('0x6e'),_0xc7dbd1+'%');_0x1bad76['or']('c.mobile\x20LIKE\x20?',_0xc7dbd1+'%');_0x1bad76['or'](_0x65bf('0x6f'),_0xc7dbd1+'%');}else if(qs[_0x65bf('0x70')](_0xc7dbd1)){_0x1bad76['or'](_0x65bf('0x71'),_0xc7dbd1+'%');}else{_0x1bad76['or'](_0x65bf('0x72'),'%'+_0xc7dbd1+'%');_0x1bad76['or'](_0x65bf('0x73'),'%'+_0xc7dbd1+'%');_0x1bad76['or']('c.email\x20LIKE\x20?','%'+_0xc7dbd1+'%');}}}}_0x2984f9[_0x65bf('0x43')](_0x1bad76);_0x2984f9['group']('c.id');var _0x21fe36={'type':db[_0x65bf('0x74')][_0x65bf('0x75')][_0x65bf('0x76')],'raw':!![]};var _0x6aa6d5=_0x2984f9[_0x65bf('0x77')]()[_0x65bf('0x46')](_0x65bf('0x78'));if(_0x493c57[_0x65bf('0x41')]){_0x493c57['order']['forEach'](function(_0x1fd5d9){_0x2984f9[_0x65bf('0x41')]('c.'+_0x1fd5d9[0x0],_0x1fd5d9[0x1]==='DESC'?![]:!![]);});}if(!_[_0x65bf('0x67')](_0x3d3317)){_0x2984f9['having'](_0xd18ff0);_0x6aa6d5['where'](_0x65bf('0x79'),_0x3d3317);}BPromise[_0x65bf('0x7a')]()[_0x65bf('0x2b')](function(){if(!_0xf78ccd)return;if(_0x32b4b6[_0x65bf('0x7b')]['role']!==_0x65bf('0x7c'))return;if(!_[_0x65bf('0x7d')](_0xf78ccd[_0x65bf('0x53')],[_0x65bf('0x46'),_0x65bf('0x5a')])){return _0x32b4b6['user'][_0x65bf('0x7e')]({'attributes':['id'],'raw':!![]})[_0x65bf('0x2b')](function(_0x55ae17){if(_[_0x65bf('0x67')](_0x55ae17)){_0x6aa6d5['where'](_0x65bf('0x7f'));_0x2984f9[_0x65bf('0x43')](_0x65bf('0x7f'));}else{_0x6aa6d5[_0x65bf('0x43')]('c.ListId\x20IN\x20?',_[_0x65bf('0x57')](_0x55ae17,'id'));_0x2984f9['where'](_0x65bf('0x68'),_[_0x65bf('0x57')](_0x55ae17,'id'));}});}})['then'](function(){if(_0x32b4b6[_0x65bf('0x7b')][_0x65bf('0x80')]===_0x65bf('0x7c')&&!_0xf78ccd&&!_0x32b4b6['query'][_0x65bf('0x81')])return[];return db[_0x65bf('0x82')]['query'](_0x6aa6d5[_0x65bf('0x83')](),_0x21fe36);})[_0x65bf('0x2b')](function(_0x332e2b){_0xd43e29[_0x65bf('0x84')]=_0x332e2b['length'];if(_0xd43e29[_0x65bf('0x84')]===0x0)return[];return db[_0x65bf('0x82')]['query'](_0x42c9bd[_0x65bf('0x83')](),_0x21fe36)[_0x65bf('0x2b')](function(_0x591cac){_0x42dfe9=_[_0x65bf('0x85')](_0x591cac,'id');_0x21fe36=_['merge'](_0x21fe36,{'model':db[_0x65bf('0x30')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x32b4b6[_0x65bf('0x3b')][_0x65bf('0x3f')]){_0x493c57[_0x65bf('0x3e')][_0x65bf('0x58')](function(_0x1c9e44){_0x2984f9[_0x65bf('0x46')]('c.'+_0x1c9e44);});}else{_0x2984f9[_0x65bf('0x46')]('c.id');_0x2984f9[_0x65bf('0x46')](_0x65bf('0x86'));_0x2984f9[_0x65bf('0x46')](_0x65bf('0x87'));_0x2984f9[_0x65bf('0x46')](_0x65bf('0x88'));_0x2984f9[_0x65bf('0x46')](_0x65bf('0x89'));_0x2984f9['field']('c.fax');_0x2984f9[_0x65bf('0x46')](_0x65bf('0x8a'));_0x2984f9['field'](_0x65bf('0x8b'));_0x2984f9['field']('c.createdAt');_0x2984f9[_0x65bf('0x46')](_0x65bf('0x8c'));_0x2984f9[_0x65bf('0x46')](_0x65bf('0x8d'));_0x2984f9['field'](_0x65bf('0x8e'),'TagIds');}if(_0x493c57[_0x65bf('0x24')])_0x2984f9[_0x65bf('0x24')](_0x493c57[_0x65bf('0x24')]);if(_0x493c57[_0x65bf('0x23')])_0x2984f9[_0x65bf('0x23')](_0x493c57[_0x65bf('0x23')]);return db[_0x65bf('0x82')]['query'](_0x2984f9[_0x65bf('0x83')](),_0x21fe36);});})[_0x65bf('0x2b')](function(_0x498f70){_0x498f70[_0x65bf('0x58')](function(_0x282211){if(_0x282211[_0x65bf('0x8f')]){_0x282211[_0x65bf('0x90')]=[];_0x282211[_0x65bf('0x8f')]['split'](',')[_0x65bf('0x58')](function(_0x5174ad){_0x282211[_0x65bf('0x90')]['push'](_0x42dfe9[_0x5174ad]);});}delete _0x282211[_0x65bf('0x8f')];});_0xd43e29[_0x65bf('0x91')]=_0x498f70;return _0xd43e29;})['then'](respondWithFilteredResult(_0x2f6167,_0x493c57));})[_0x65bf('0x92')](handleError(_0x2f6167,null));};exports[_0x65bf('0x93')]=function(_0x5125a0,_0x17a2d1){return db[_0x65bf('0x30')][_0x65bf('0x94')]({'where':{'id':_0x5125a0['params']['id']}})['then'](handleEntityNotFound(_0x17a2d1,null))[_0x65bf('0x2b')](removeEntity(_0x17a2d1,null))['catch'](handleError(_0x17a2d1,null));};exports[_0x65bf('0x31')]=function(_0x393e9d,_0x364b55){return db['CmContact'][_0x65bf('0x31')]()['then'](function(_0x38a3a6){delete _0x38a3a6[_0x65bf('0x95')];for(var _0x470994=0x0;_0x470994<Object[_0x65bf('0x3a')](_0x38a3a6)[_0x65bf('0x32')];_0x470994++){var _0x168aef=Object[_0x65bf('0x3a')](_0x38a3a6)[_0x470994];if(!_[_0x65bf('0x33')](_0x168aef,_0x65bf('0x34'))){_0x38a3a6[_0x168aef]['columnName']=_0x168aef;_0x38a3a6[_0x168aef][_0x65bf('0x96')]=_0x168aef;}}return _0x38a3a6;})[_0x65bf('0x2b')](function(_0x24bbd5){var _0x27cc22={'where':{'$or':[{'ListId':_0x393e9d[_0x65bf('0x3b')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x65bf('0x36')]['findAll'](_0x27cc22)['then'](function(_0x1df147){for(var _0xc0d611=0x0;_0xc0d611<_0x1df147[_0x65bf('0x32')];_0xc0d611++){var _0x10b558=_0x65bf('0x34')+_0x1df147[_0xc0d611]['id'];_0x24bbd5[_0x10b558][_0x65bf('0x97')]=_0x10b558;_0x24bbd5[_0x10b558][_0x65bf('0x96')]=_0x1df147[_0xc0d611][_0x65bf('0x98')];_0x24bbd5[_0x10b558][_0x65bf('0x99')]={'type':_0x1df147[_0xc0d611][_0x65bf('0x62')],'values':_0x1df147[_0xc0d611]['values']};}Object[_0x65bf('0x3a')](_0x24bbd5)[_0x65bf('0x58')](function(_0x1be1c1){if(!_0x24bbd5[_0x1be1c1][_0x65bf('0x40')]('columnName')){delete _0x24bbd5[_0x1be1c1];}});return _0x24bbd5;});})[_0x65bf('0x2b')](respondWithResult(_0x364b55,null))[_0x65bf('0x92')](handleError(_0x364b55,null));};exports[_0x65bf('0x9a')]=function(_0x4d2df8,_0x3bc83c){var _0x1fb839;var _0x346a2c;var _0x10a17a;if(_0x4d2df8['body']['id']){delete _0x4d2df8[_0x65bf('0x9b')]['id'];}return db[_0x65bf('0x30')][_0x65bf('0x9c')]({'where':{'id':[_0x4d2df8['body']['to'],_0x4d2df8[_0x65bf('0x9b')]['from']]}})[_0x65bf('0x2b')](function(_0x261a5b){if(_0x261a5b){if(_0x261a5b[_0x65bf('0x32')]!==0x2){return null;}_0x261a5b[0x0]=_0x261a5b[0x0]['get']({'plain':!![]});_0x261a5b[0x1]=_0x261a5b[0x1][_0x65bf('0x9d')]({'plain':!![]});delete _0x261a5b[0x0]['id'];delete _0x261a5b[0x1]['id'];return _['mergeWith'](_0x261a5b[0x0],_0x261a5b[0x1],function(_0x116ac9,_0x3e039e){if(Array[_0x65bf('0x9e')](_0x3e039e)&&!_0x3e039e[_0x65bf('0x32')]){return _0x116ac9;}else if(!_0x3e039e){return _0x116ac9;}});}})['then'](handleEntityNotFound(_0x3bc83c,null))['then'](function(_0x1f90e6){if(_0x1f90e6){if(_0x1f90e6['tags']&&_[_0x65bf('0x9e')](_0x1f90e6[_0x65bf('0x95')])){_0x1f90e6[_0x65bf('0x95')]=_0x1f90e6[_0x65bf('0x95')]['join']();}logger[_0x65bf('0x9f')](_0x65bf('0xa0'),_0x4d2df8[_0x65bf('0x9b')]['to'],_0x4d2df8['body'][_0x65bf('0x47')]);return db[_0x65bf('0xa1')][_0x65bf('0x93')]({'where':{'ContactId':[_0x4d2df8[_0x65bf('0x9b')]['to'],_0x4d2df8[_0x65bf('0x9b')][_0x65bf('0x47')]]}})['then'](function(_0x44deca){logger[_0x65bf('0x9f')](_0x65bf('0xa2'),_0x44deca);return db['CmHopperBlack']['destroy']({'where':{'ContactId':[_0x4d2df8[_0x65bf('0x9b')]['to'],_0x4d2df8['body'][_0x65bf('0x47')]]}})[_0x65bf('0x2b')](function(_0x480360){logger['info']('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x480360);return db[_0x65bf('0x30')]['create'](_0x1f90e6);});});}})[_0x65bf('0x2b')](function(_0x2344d2){if(_0x2344d2){_0x1fb839=_0x2344d2;_0x346a2c={'ContactId':_0x1fb839['id']};_0x10a17a={'where':{'ContactId':[_0x4d2df8['body']['to'],_0x4d2df8[_0x65bf('0x9b')]['from']]}};return db[_0x65bf('0xa3')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})['then'](function(){if(_0x1fb839){return db[_0x65bf('0xa4')]['update'](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xa5')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xa6')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xa7')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db['MailInteraction']['update'](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xa7')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xa8')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xa9')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})['then'](function(){if(_0x1fb839){return db[_0x65bf('0xaa')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db['FaxMessage'][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db['OpenchannelInteraction'][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})['then'](function(){if(_0x1fb839){return db['OpenchannelMessage'][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db['CmHopperFinal'][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xab')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})['then'](function(){if(_0x1fb839){return db[_0x65bf('0xac')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xad')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xae')]['update'](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xaf')]['update'](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xb0')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db['OpenchannelQueueReport'][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return db[_0x65bf('0xb1')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})['then'](function(){if(_0x1fb839){return db[_0x65bf('0xb2')][_0x65bf('0x2a')](_0x346a2c,_0x10a17a);}})['then'](function(){if(_0x1fb839){return db[_0x65bf('0x30')][_0x65bf('0x93')]({'where':{'id':[_0x4d2df8['body']['to'],_0x4d2df8[_0x65bf('0x9b')][_0x65bf('0x47')]]}});}})[_0x65bf('0x2b')](function(){if(_0x1fb839){return _0x1fb839;}})['then'](respondWithResult(_0x3bc83c,null))['catch'](handleError(_0x3bc83c,null));};exports[_0x65bf('0xb3')]=function(_0x351fce,_0x4ccb61){return db[_0x65bf('0x30')]['describe']()[_0x65bf('0x2b')](function(_0x333f30){if(_0x351fce[_0x65bf('0x9b')][_0x65bf('0x95')]&&_[_0x65bf('0x9e')](_0x351fce['body'][_0x65bf('0x95')])){if(_0x351fce[_0x65bf('0x9b')][_0x65bf('0x95')][_0x65bf('0x32')]){_0x351fce[_0x65bf('0x9b')][_0x65bf('0x95')]=_0x351fce['body'][_0x65bf('0x95')]['join'](';')+';';}else{_0x351fce[_0x65bf('0x9b')][_0x65bf('0x95')]=null;}}else{_0x351fce[_0x65bf('0x9b')]['tags']=null;}return db[_0x65bf('0x30')][_0x65bf('0xb3')](_0x351fce[_0x65bf('0x9b')],{'fields':_[_0x65bf('0x3a')](_0x333f30),'raw':!![]});})[_0x65bf('0x2b')](respondWithResult(_0x4ccb61,0xc9))[_0x65bf('0x92')](handleError(_0x4ccb61,null));};exports[_0x65bf('0xb4')]=function(_0x89d875,_0x564a10){var _0xbd91e9=[];var _0x56121b=0x0;var _0x4cbf4a=0x0;var _0x360171=0x0;return db[_0x65bf('0x30')][_0x65bf('0x31')]()[_0x65bf('0x2b')](function(_0x55cc82){return BPromise[_0x65bf('0xb5')](_0x89d875['body'],function(_0x336cd9){var _0x185ddc={'where':{'$or':[]},'defaults':_0x336cd9,'fields':_['keys'](_0x55cc82),'raw':!![]};if(_0x336cd9[_0x65bf('0xb6')]){for(var _0x722d1=0x0;_0x722d1<_0x336cd9['duplicates'][_0x65bf('0x32')];_0x722d1++){var _0x51ff52={};_0x51ff52[_0x336cd9[_0x65bf('0xb6')][_0x722d1]]=_0x336cd9[_0x336cd9[_0x65bf('0xb6')][_0x722d1]];_0x185ddc[_0x65bf('0x43')][_0x65bf('0xb7')][_0x65bf('0x35')](_0x51ff52);}_0x185ddc['where'][_0x65bf('0x81')]=_0x336cd9[_0x65bf('0x81')];}return db[_0x65bf('0x30')][_0x65bf('0xb8')](_0x185ddc)['spread'](function(_0x3199b8,_0xd879a2){if(_0xd879a2){_0x56121b++;}else{_0x360171++;}})[_0x65bf('0x92')](function(_0x4a63a4){console['error'](_0x4a63a4);_0x4cbf4a++;});});})[_0x65bf('0x2b')](function(_0x46c9da){if(_0x46c9da){return{'success':_0x56121b,'failure':_0x4cbf4a,'duplicates':_0x360171};}})[_0x65bf('0x2b')](respondWithResult(_0x564a10,0xc9))['catch'](handleError(_0x564a10,null));};exports['show']=function(_0x38e2a0,_0x51450e,_0x4895d3){var _0x34c85e;return db[_0x65bf('0x30')][_0x65bf('0x31')]()['then'](function(_0x536405){return db[_0x65bf('0x30')][_0x65bf('0x94')]({'where':{'id':_0x38e2a0[_0x65bf('0xb9')]['id']},'include':[{'model':db[_0x65bf('0x54')],'as':_0x65bf('0x90'),'attributes':['id','name',_0x65bf('0xba')],'required':_0x38e2a0[_0x65bf('0x3b')]['tag']?!![]:![]}],'attributes':_[_0x65bf('0x3a')](_0x536405)});})[_0x65bf('0x2b')](function(_0x51f021){_0x34c85e=_0x51f021[_0x65bf('0x9d')]({'plain':!![]});var _0xbe3477={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x51f021&&_0x51f021[_0x65bf('0x81')]){if(_0x51f021[_0x65bf('0x81')]){_0xbe3477[_0x65bf('0x43')][_0x65bf('0xbb')][_0x65bf('0x35')]({'ListId':{'$ne':_0x51f021['ListId']}});}}return db[_0x65bf('0x36')]['findAll'](_0xbe3477);})[_0x65bf('0x2b')](function(_0xeef164){return _[_0x65bf('0xbc')](_0x34c85e,_[_0x65bf('0x57')](_0xeef164,function(_0x797162){return util['format'](_0x65bf('0xbd'),_0x797162['id']);}));})[_0x65bf('0x2b')](handleEntityNotFound(_0x51450e,null))['then'](respondWithResult(_0x51450e,null))[_0x65bf('0x92')](handleError(_0x51450e,null));};exports[_0x65bf('0x2a')]=function(_0x2187f8,_0x1268fc){var _0x46c48b;if(_0x2187f8[_0x65bf('0x9b')]['id']){delete _0x2187f8[_0x65bf('0x9b')]['id'];}return db[_0x65bf('0x30')][_0x65bf('0x94')]({'where':{'id':_0x2187f8[_0x65bf('0xb9')]['id']}})['then'](handleEntityNotFound(_0x1268fc,null))['then'](saveUpdates(_0x2187f8[_0x65bf('0x9b')],null))[_0x65bf('0x2b')](function(_0x4cf97e){_0x46c48b=_0x4cf97e;var _0x251a48={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x4cf97e&&_0x4cf97e[_0x65bf('0x81')]){if(_0x4cf97e[_0x65bf('0x81')]){_0x251a48[_0x65bf('0x43')][_0x65bf('0xbb')][_0x65bf('0x35')]({'ListId':{'$ne':_0x4cf97e[_0x65bf('0x81')]}});}}return db[_0x65bf('0x36')]['findAll'](_0x251a48);})[_0x65bf('0x2b')](function(_0x3e9e15){if(_0x3e9e15){return _[_0x65bf('0xbc')](_[_0x65bf('0xbe')](_0x2187f8[_0x65bf('0x9b')],function(_0x53297d,_0x311925){return _[_0x65bf('0x33')](_0x311925,'cf_');}),_['map'](_0x3e9e15,function(_0x189094){return util['format'](_0x65bf('0xbd'),_0x189094['id']);}));}})['then'](function(_0x3e9e32){if(_0x3e9e32&&!_[_0x65bf('0x67')](_0x3e9e32)){var _0x169166=squel['update']()[_0x65bf('0xbf')]('cm_contacts')[_0x65bf('0xc0')](_0x3e9e32)[_0x65bf('0x43')](_0x65bf('0xc1'),_0x2187f8[_0x65bf('0xb9')]['id'])['toParam']();return db[_0x65bf('0x82')][_0x65bf('0x3b')](_0x169166[_0x65bf('0x63')],{'replacements':_0x169166[_0x65bf('0xc2')]});}})[_0x65bf('0x2b')](function(){if(_0x2187f8[_0x65bf('0x9b')]['phone']&&_0x46c48b){return db[_0x65bf('0xa1')][_0x65bf('0x2a')]({'phone':_0x2187f8[_0x65bf('0x9b')][_0x65bf('0xc3')]},{'where':{'ContactId':_0x46c48b['id']}});}})[_0x65bf('0x2b')](function(){return _0x46c48b;})['then'](respondWithResult(_0x1268fc,null))[_0x65bf('0x92')](handleError(_0x1268fc,null));};exports[_0x65bf('0xc4')]=function(_0x256e12,_0x36d283,_0x55c1e1){var _0x5b4b52={};var _0x429435={};var _0xa81d77;var _0x454ec8;return db[_0x65bf('0x30')][_0x65bf('0x37')]({'where':{'id':_0x256e12[_0x65bf('0xb9')]['id']}})[_0x65bf('0x2b')](handleEntityNotFound(_0x36d283,null))[_0x65bf('0x2b')](function(_0x57849d){if(_0x57849d){_0xa81d77=_0x57849d;_0x429435[_0x65bf('0x39')]=_[_0x65bf('0x3a')](db[_0x65bf('0x54')][_0x65bf('0xc5')]);_0x429435[_0x65bf('0x3b')]=_['keys'](_0x256e12[_0x65bf('0x3b')]);_0x429435[_0x65bf('0x3c')]=_['intersection'](_0x429435[_0x65bf('0x39')],_0x429435['query']);_0x5b4b52[_0x65bf('0x3e')]=_[_0x65bf('0x3d')](_0x429435[_0x65bf('0x39')],qs[_0x65bf('0x3f')](_0x256e12['query']['fields']));_0x5b4b52[_0x65bf('0x3e')]=_0x5b4b52[_0x65bf('0x3e')][_0x65bf('0x32')]?_0x5b4b52['attributes']:_0x429435[_0x65bf('0x39')];_0x5b4b52[_0x65bf('0x41')]=qs[_0x65bf('0x42')](_0x256e12[_0x65bf('0x3b')][_0x65bf('0x42')]);_0x5b4b52[_0x65bf('0x43')]=qs[_0x65bf('0x3c')](_['pick'](_0x256e12[_0x65bf('0x3b')],_0x429435[_0x65bf('0x3c')]));if(_0x256e12[_0x65bf('0x3b')]['filter']){_0x5b4b52[_0x65bf('0x43')]=_[_0x65bf('0x9a')](_0x5b4b52[_0x65bf('0x43')],{'$or':_[_0x65bf('0x57')](_0x5b4b52[_0x65bf('0x3e')],function(_0x22f2fa){var _0x3c27fc={};_0x3c27fc[_0x22f2fa]={'$like':'%'+_0x256e12[_0x65bf('0x3b')][_0x65bf('0x65')]+'%'};return _0x3c27fc;})});}_0x5b4b52=_[_0x65bf('0x9a')]({},_0x5b4b52,_0x256e12[_0x65bf('0xc6')]);return _0xa81d77['getTags'](_0x5b4b52);}})['then'](function(_0x19c952){if(_0x19c952){_0x454ec8=_0x19c952[_0x65bf('0x32')];if(!_0x256e12[_0x65bf('0x3b')]['hasOwnProperty'](_0x65bf('0xc7'))){_0x5b4b52['limit']=qs['limit'](_0x256e12[_0x65bf('0x3b')][_0x65bf('0x24')]);_0x5b4b52['offset']=qs[_0x65bf('0x23')](_0x256e12[_0x65bf('0x3b')][_0x65bf('0x23')]);}return _0xa81d77[_0x65bf('0xc4')](_0x5b4b52);}})[_0x65bf('0x2b')](function(_0x57426a){if(_0x57426a){return _0x57426a?{'count':_0x454ec8,'rows':_0x57426a}:null;}})[_0x65bf('0x2b')](respondWithResult(_0x36d283,null))[_0x65bf('0x92')](handleError(_0x36d283,null));};exports[_0x65bf('0xc8')]=function(_0x22d176,_0x43749f,_0x18bcf0){if(_0x22d176[_0x65bf('0x9b')]['id']){delete _0x22d176[_0x65bf('0x9b')]['id'];}return db[_0x65bf('0x30')][_0x65bf('0x37')]({'where':{'id':_0x22d176[_0x65bf('0xb9')]['id']}})['then'](handleEntityNotFound(_0x43749f,null))['then'](function(_0xbe16fd){if(_0xbe16fd){return _0xbe16fd[_0x65bf('0xc8')](_0x22d176['body'][_0x65bf('0xc9')]||[]);}return null;})['then'](respondWithResult(_0x43749f,null))['catch'](handleError(_0x43749f,null));};exports[_0x65bf('0xca')]=function(_0x31e4e1,_0x2aca88,_0x6a902){var _0x210087={'raw':![],'where':{}};var _0x47b4c0={};var _0x163073={'count':0x0,'rows':[]};return db[_0x65bf('0x30')][_0x65bf('0x37')]({'where':{'id':_0x31e4e1[_0x65bf('0xb9')]['id']}})[_0x65bf('0x2b')](handleEntityNotFound(_0x2aca88,null))['then'](function(_0x189999){if(_0x189999){_0x47b4c0[_0x65bf('0x39')]=_[_0x65bf('0x3a')](db[_0x65bf('0xa1')][_0x65bf('0xc5')]);_0x47b4c0[_0x65bf('0x3b')]=_[_0x65bf('0x3a')](_0x31e4e1[_0x65bf('0x3b')]);_0x47b4c0[_0x65bf('0x3c')]=_['intersection'](_0x47b4c0[_0x65bf('0x39')],_0x47b4c0[_0x65bf('0x3b')]);_0x210087['attributes']=_[_0x65bf('0x3d')](_0x47b4c0[_0x65bf('0x39')],qs['fields'](_0x31e4e1['query'][_0x65bf('0x3f')]));_0x210087[_0x65bf('0x3e')]=_0x210087[_0x65bf('0x3e')]['length']?_0x210087[_0x65bf('0x3e')]:_0x47b4c0[_0x65bf('0x39')];if(!_0x31e4e1[_0x65bf('0x3b')][_0x65bf('0x40')](_0x65bf('0xc7'))){_0x210087[_0x65bf('0x24')]=qs['limit'](_0x31e4e1[_0x65bf('0x3b')][_0x65bf('0x24')]);_0x210087[_0x65bf('0x23')]=qs[_0x65bf('0x23')](_0x31e4e1[_0x65bf('0x3b')][_0x65bf('0x23')]);}_0x210087[_0x65bf('0x41')]=qs['sort'](_0x31e4e1['query']['sort']);_0x210087[_0x65bf('0x43')]=qs['filters'](_['pick'](_0x31e4e1[_0x65bf('0x3b')],_0x47b4c0[_0x65bf('0x3c')]));_0x210087[_0x65bf('0x43')][_0x65bf('0xcb')]=_0x189999['id'];if(_0x31e4e1[_0x65bf('0x3b')][_0x65bf('0x65')]){_0x210087['where']=_[_0x65bf('0x9a')](_0x210087['where'],{'$or':_[_0x65bf('0x57')](_0x210087['attributes'],function(_0x4e109d){var _0xe41260={};_0xe41260[_0x4e109d]={'$like':'%'+_0x31e4e1[_0x65bf('0x3b')][_0x65bf('0x65')]+'%'};return _0xe41260;})});}_0x210087=_[_0x65bf('0x9a')]({},_0x210087,_0x31e4e1[_0x65bf('0xc6')]);return db[_0x65bf('0xa1')][_0x65bf('0x84')]({'where':_0x210087['where']})[_0x65bf('0x2b')](function(_0x5462e5){_0x163073[_0x65bf('0x84')]=_0x5462e5;if(_0x31e4e1[_0x65bf('0x3b')][_0x65bf('0xcc')]){_0x210087[_0x65bf('0xcd')]=[{'all':!![]}];}return db[_0x65bf('0xa1')]['findAll'](_0x210087);})[_0x65bf('0x2b')](function(_0xec28f8){_0x163073[_0x65bf('0x91')]=_0xec28f8;return _0x163073;});}})['then'](respondWithFilteredResult(_0x2aca88,_0x210087))[_0x65bf('0x92')](handleError(_0x2aca88,null));};exports[_0x65bf('0xce')]=function(_0x3e1b91,_0x1978d8,_0x5100c4){var _0x54be73={'raw':!![],'where':{}};var _0x2ad0e1={};var _0x691b71={'count':0x0,'rows':[]};return db['CmContact'][_0x65bf('0x37')]({'where':{'id':_0x3e1b91[_0x65bf('0xb9')]['id']}})[_0x65bf('0x2b')](handleEntityNotFound(_0x1978d8,null))['then'](function(_0x13cc0e){if(_0x13cc0e){_0x2ad0e1[_0x65bf('0x39')]=_[_0x65bf('0x3a')](db[_0x65bf('0xab')][_0x65bf('0xc5')]);_0x2ad0e1[_0x65bf('0x3b')]=_['keys'](_0x3e1b91[_0x65bf('0x3b')]);_0x2ad0e1[_0x65bf('0x3c')]=_[_0x65bf('0x3d')](_0x2ad0e1[_0x65bf('0x39')],_0x2ad0e1[_0x65bf('0x3b')]);_0x54be73[_0x65bf('0x3e')]=_['intersection'](_0x2ad0e1[_0x65bf('0x39')],qs[_0x65bf('0x3f')](_0x3e1b91[_0x65bf('0x3b')][_0x65bf('0x3f')]));_0x54be73['attributes']=_0x54be73['attributes'][_0x65bf('0x32')]?_0x54be73[_0x65bf('0x3e')]:_0x2ad0e1['model'];if(!_0x3e1b91[_0x65bf('0x3b')][_0x65bf('0x40')]('nolimit')){_0x54be73[_0x65bf('0x24')]=qs[_0x65bf('0x24')](_0x3e1b91[_0x65bf('0x3b')][_0x65bf('0x24')]);_0x54be73[_0x65bf('0x23')]=qs['offset'](_0x3e1b91['query'][_0x65bf('0x23')]);}_0x54be73[_0x65bf('0x41')]=qs['sort'](_0x3e1b91['query'][_0x65bf('0x42')]);_0x54be73[_0x65bf('0x43')]=qs[_0x65bf('0x3c')](_[_0x65bf('0x44')](_0x3e1b91['query'],_0x2ad0e1[_0x65bf('0x3c')]));_0x54be73['where'][_0x65bf('0xcb')]=_0x13cc0e['id'];if(_0x3e1b91[_0x65bf('0x3b')][_0x65bf('0x65')]){_0x54be73[_0x65bf('0x43')]=_[_0x65bf('0x9a')](_0x54be73[_0x65bf('0x43')],{'$or':_['map'](_0x54be73[_0x65bf('0x3e')],function(_0x2a8666){var _0x96c27c={};_0x96c27c[_0x2a8666]={'$like':'%'+_0x3e1b91[_0x65bf('0x3b')][_0x65bf('0x65')]+'%'};return _0x96c27c;})});}_0x54be73=_[_0x65bf('0x9a')]({},_0x54be73,_0x3e1b91[_0x65bf('0xc6')]);return db[_0x65bf('0xab')]['count']({'where':_0x54be73[_0x65bf('0x43')]})[_0x65bf('0x2b')](function(_0x1da7d7){_0x691b71['count']=_0x1da7d7;if(_0x3e1b91['query'][_0x65bf('0xcc')]){_0x54be73[_0x65bf('0xcd')]=[{'all':!![]}];}return db[_0x65bf('0xab')][_0x65bf('0x9c')](_0x54be73);})[_0x65bf('0x2b')](function(_0x195d8d){_0x691b71[_0x65bf('0x91')]=_0x195d8d;return _0x691b71;});}})[_0x65bf('0x2b')](respondWithFilteredResult(_0x1978d8,_0x54be73))[_0x65bf('0x92')](handleError(_0x1978d8,null));};exports[_0x65bf('0xcf')]=function(_0xe3e5c1,_0xb9dc81,_0x1edf1c){var _0x26c3c6={'raw':!![],'where':{}};var _0x3125d5={};var _0x3198c0={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0xe3e5c1[_0x65bf('0xb9')]['id']}})[_0x65bf('0x2b')](handleEntityNotFound(_0xb9dc81,null))[_0x65bf('0x2b')](function(_0x3b2606){if(_0x3b2606){_0x3125d5[_0x65bf('0x39')]=_['keys'](db[_0x65bf('0xd0')]['rawAttributes']);_0x3125d5[_0x65bf('0x3b')]=_[_0x65bf('0x3a')](_0xe3e5c1[_0x65bf('0x3b')]);_0x3125d5[_0x65bf('0x3c')]=_['intersection'](_0x3125d5[_0x65bf('0x39')],_0x3125d5[_0x65bf('0x3b')]);_0x26c3c6[_0x65bf('0x3e')]=_[_0x65bf('0x3d')](_0x3125d5[_0x65bf('0x39')],qs[_0x65bf('0x3f')](_0xe3e5c1['query'][_0x65bf('0x3f')]));_0x26c3c6[_0x65bf('0x3e')]=_0x26c3c6[_0x65bf('0x3e')][_0x65bf('0x32')]?_0x26c3c6[_0x65bf('0x3e')]:_0x3125d5[_0x65bf('0x39')];if(!_0xe3e5c1[_0x65bf('0x3b')][_0x65bf('0x40')](_0x65bf('0xc7'))){_0x26c3c6['limit']=qs[_0x65bf('0x24')](_0xe3e5c1[_0x65bf('0x3b')][_0x65bf('0x24')]);_0x26c3c6[_0x65bf('0x23')]=qs[_0x65bf('0x23')](_0xe3e5c1[_0x65bf('0x3b')]['offset']);}_0x26c3c6[_0x65bf('0x41')]=qs['sort'](_0xe3e5c1[_0x65bf('0x3b')][_0x65bf('0x42')]);_0x26c3c6['where']=qs['filters'](_[_0x65bf('0x44')](_0xe3e5c1[_0x65bf('0x3b')],_0x3125d5[_0x65bf('0x3c')]));_0x26c3c6[_0x65bf('0x43')]['ContactId']=_0x3b2606['id'];if(_0xe3e5c1['query'][_0x65bf('0x65')]){_0x26c3c6['where']=_[_0x65bf('0x9a')](_0x26c3c6[_0x65bf('0x43')],{'$or':_[_0x65bf('0x57')](_0x26c3c6[_0x65bf('0x3e')],function(_0x5f651a){var _0x174ac0={};_0x174ac0[_0x5f651a]={'$like':'%'+_0xe3e5c1[_0x65bf('0x3b')]['filter']+'%'};return _0x174ac0;})});}_0x26c3c6=_[_0x65bf('0x9a')]({},_0x26c3c6,_0xe3e5c1[_0x65bf('0xc6')]);return db['CmHopperFinal'][_0x65bf('0x84')]({'where':_0x26c3c6[_0x65bf('0x43')]})[_0x65bf('0x2b')](function(_0x1337fa){_0x3198c0['count']=_0x1337fa;if(_0xe3e5c1[_0x65bf('0x3b')]['includeAll']){_0x26c3c6[_0x65bf('0xcd')]=[{'all':!![]}];}return db[_0x65bf('0xd0')][_0x65bf('0x9c')](_0x26c3c6);})[_0x65bf('0x2b')](function(_0x5dc409){_0x3198c0[_0x65bf('0x91')]=_0x5dc409;return _0x3198c0;});}})[_0x65bf('0x2b')](respondWithFilteredResult(_0xb9dc81,_0x26c3c6))[_0x65bf('0x92')](handleError(_0xb9dc81,null));};exports[_0x65bf('0xd1')]=function(_0x494aec,_0x44b1c5,_0x29d9c4){var _0x19dc32={'raw':!![],'where':{}};var _0x321fb7={};var _0x5a79cf={'count':0x0,'rows':[]};return db[_0x65bf('0x30')][_0x65bf('0x37')]({'where':{'id':_0x494aec[_0x65bf('0xb9')]['id']}})[_0x65bf('0x2b')](handleEntityNotFound(_0x44b1c5,null))[_0x65bf('0x2b')](function(_0x371b3e){if(_0x371b3e){_0x321fb7['model']=_[_0x65bf('0x3a')](db[_0x65bf('0xb2')][_0x65bf('0xc5')]);_0x321fb7[_0x65bf('0x3b')]=_[_0x65bf('0x3a')](_0x494aec['query']);_0x321fb7[_0x65bf('0x3c')]=_[_0x65bf('0x3d')](_0x321fb7['model'],_0x321fb7[_0x65bf('0x3b')]);_0x19dc32[_0x65bf('0x3e')]=_[_0x65bf('0x3d')](_0x321fb7[_0x65bf('0x39')],qs['fields'](_0x494aec[_0x65bf('0x3b')][_0x65bf('0x3f')]));_0x19dc32['attributes']=_0x19dc32[_0x65bf('0x3e')][_0x65bf('0x32')]?_0x19dc32['attributes']:_0x321fb7[_0x65bf('0x39')];if(!_0x494aec['query'][_0x65bf('0x40')](_0x65bf('0xc7'))){_0x19dc32['limit']=qs[_0x65bf('0x24')](_0x494aec[_0x65bf('0x3b')][_0x65bf('0x24')]);_0x19dc32['offset']=qs[_0x65bf('0x23')](_0x494aec['query']['offset']);}_0x19dc32[_0x65bf('0x41')]=qs[_0x65bf('0x42')](_0x494aec[_0x65bf('0x3b')][_0x65bf('0x42')]);_0x19dc32['where']=qs['filters'](_['pick'](_0x494aec[_0x65bf('0x3b')],_0x321fb7[_0x65bf('0x3c')]));_0x19dc32[_0x65bf('0x43')][_0x65bf('0xcb')]=_0x371b3e['id'];if(_0x494aec[_0x65bf('0x3b')][_0x65bf('0x65')]){_0x19dc32[_0x65bf('0x43')]=_[_0x65bf('0x9a')](_0x19dc32['where'],{'$or':_[_0x65bf('0x57')](_0x19dc32[_0x65bf('0x3e')],function(_0x480acb){var _0x1780f3={};_0x1780f3[_0x480acb]={'$like':'%'+_0x494aec[_0x65bf('0x3b')][_0x65bf('0x65')]+'%'};return _0x1780f3;})});}_0x19dc32=_['merge']({},_0x19dc32,_0x494aec[_0x65bf('0xc6')]);return db[_0x65bf('0xb2')][_0x65bf('0x84')]({'where':_0x19dc32[_0x65bf('0x43')]})['then'](function(_0x5d5a04){_0x5a79cf[_0x65bf('0x84')]=_0x5d5a04;if(_0x494aec['query'][_0x65bf('0xcc')]){_0x19dc32[_0x65bf('0xcd')]=[{'all':!![]}];}return db[_0x65bf('0xb2')][_0x65bf('0x9c')](_0x19dc32);})[_0x65bf('0x2b')](function(_0x519b77){_0x5a79cf[_0x65bf('0x91')]=_0x519b77;return _0x5a79cf;});}})[_0x65bf('0x2b')](respondWithFilteredResult(_0x44b1c5,_0x19dc32))[_0x65bf('0x92')](handleError(_0x44b1c5,null));};exports['uploadCsv']=function(_0x1523d2,_0x654635,_0x15cd52){try{if(!_0x1523d2[_0x65bf('0x9b')][_0x65bf('0x81')]){throw new Error(_0x65bf('0xd2'));}if(!_0x1523d2[_0x65bf('0x9b')][_0x65bf('0xd3')]){throw new Error(_0x65bf('0xd4'));}if(!_0x1523d2[_0x65bf('0x9b')][_0x65bf('0xd5')]){throw new Error(_0x65bf('0xd6'));}if(!_0x1523d2[_0x65bf('0x9b')]['socket_timestamp']){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x451e80=_0x1523d2[_0x65bf('0x9b')][_0x65bf('0xd3')]['split'](',');var _0xabf929=_0x1523d2[_0x65bf('0x9b')][_0x65bf('0xd5')][_0x65bf('0x56')](',');if(!_0x451e80['length']||!_0xabf929['length']||_0x451e80[_0x65bf('0x32')]!==_0xabf929[_0x65bf('0x32')]){throw new Error(_0x65bf('0xd7'));}_0x1523d2['body']['fields']=_[_0x65bf('0xd8')](_0x451e80,_0xabf929);if(!_0x1523d2[_0x65bf('0x9b')][_0x65bf('0x3f')]['phone']){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x1523d2[_0x65bf('0x9b')][_0x65bf('0x3f')][_0x65bf('0xd9')]){throw new Error('No\x20firstName\x20column\x20specified');}var _0x56cba6=path[_0x65bf('0xda')](config[_0x65bf('0xdb')],'server/files/tmp',_0x1523d2['file'][_0x65bf('0xdc')]);fs[_0x65bf('0xdd')](_0x56cba6,parseInt(_0x65bf('0xde'),0x8));var _0x454a78=require(_0x65bf('0xdf'))[_0x65bf('0xe0')](path['join'](__dirname,'../../components/import/cm/csv'),[_0x56cba6,_0x1523d2[_0x65bf('0x9b')]['binding_keys'],_0x1523d2[_0x65bf('0x9b')][_0x65bf('0xd5')],_0x1523d2['body'][_0x65bf('0x81')],_0x1523d2['body']['CompanyId'],_0x1523d2[_0x65bf('0x9b')][_0x65bf('0xb6')],_0x1523d2['body']['socket_timestamp']]);return _0x654635[_0x65bf('0x20')](0xc8)['json']({'message':_0x65bf('0xe1'),'pid':_0x454a78[_0x65bf('0xe2')]});}catch(_0x43ab6d){return _0x654635[_0x65bf('0x20')](0x1f4)['send'](_0x43ab6d);}};exports[_0x65bf('0xe3')]=function(_0x473c37,_0x123d0d,_0x23ac6f){var _0x54bfac=fs[_0x65bf('0xe4')](_0x473c37[_0x65bf('0xe5')][_0x65bf('0x9')]);Papa[_0x65bf('0xe6')](_0x54bfac,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x13cb48){return _0x123d0d[_0x65bf('0x20')](0xc8)[_0x65bf('0x22')]({'file':_0x473c37[_0x65bf('0xe5')],'fields':_0x13cb48[_0x65bf('0xe7')][_0x65bf('0x3f')]});}});};exports[_0x65bf('0xe8')]=function(_0x389cb9,_0x30ee1a,_0x2e8803){return db[_0x65bf('0x5a')][_0x65bf('0x9c')]({'raw':!![],'attributes':['id'],'where':{'role':_0x65bf('0x7c')}})['then'](function(_0x57eda5){var _0x48f1cb=![];if(!_0x389cb9[_0x65bf('0x9b')][_0x65bf('0x81')]){throw new Error(_0x65bf('0xd2'));}if(!_0x389cb9[_0x65bf('0x9b')][_0x65bf('0xe9')][_0x65bf('0xc3')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x389cb9['body'][_0x65bf('0xe9')][_0x65bf('0xd9')]){throw new Error('No\x20firstName\x20column\x20specified');}if(!_0x389cb9[_0x65bf('0x9b')][_0x65bf('0xea')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x2a5c8f=require(_0x65bf('0xdf'))[_0x65bf('0xe0')](path['join'](__dirname,'../../components/import/cm/csv2'),[_0x389cb9[_0x65bf('0xb9')]['id'],JSON[_0x65bf('0xeb')](_0x389cb9['body']),JSON[_0x65bf('0xeb')](_0x57eda5)]);_0x2a5c8f['on']('message',function(_0x127059){_0x48f1cb=!![];return _0x30ee1a['status'](0xc8)[_0x65bf('0x22')]({'message':_0x65bf('0xec'),'pid':_0x2a5c8f[_0x65bf('0xe2')]});});_0x2a5c8f['on'](_0x65bf('0xed'),function(_0x3d37a2){if(_0x3d37a2&&!_0x48f1cb){return _0x30ee1a['status'](0x1f4)[_0x65bf('0x22')]({'message':_0x65bf('0xee'),'pid':_0x2a5c8f[_0x65bf('0xe2')]});}});})['catch'](handleError(_0x30ee1a,null));};exports[_0x65bf('0xef')]=function(_0x7e8795,_0x44a337){var _0x1ca473=[_0x65bf('0xf0'),'chat','sms','openchannel',_0x65bf('0xf1'),_0x65bf('0xf2'),_0x65bf('0xf3')];var _0x4e404={'offset':0x0,'order':qs[_0x65bf('0x42')]('-createdAt')},_0x428886={'count':0x0,'rows':[]};Promise[_0x65bf('0x7a')]()[_0x65bf('0x2b')](function(){if(_0x7e8795[_0x65bf('0x3b')][_0x65bf('0xf4')]){if(!_[_0x65bf('0xf5')](_0x1ca473,_0x7e8795[_0x65bf('0x3b')][_0x65bf('0xf4')]['toLowerCase']())){throw new Error(_0x65bf('0xf6'));}_0x1ca473=[_0x7e8795['query'][_0x65bf('0xf4')][_0x65bf('0xf7')]()];}if(_0x7e8795[_0x65bf('0x3b')][_0x65bf('0xf8')]){try{var _0x5debb7=JSON[_0x65bf('0xe6')](_0x7e8795['query'][_0x65bf('0xf8')]);if(!moment(_0x5debb7[_0x65bf('0x47')])[_0x65bf('0xf9')]()){throw new Error(_0x65bf('0xfa'));}if(!moment(_0x5debb7['to'])['isValid']()){throw new Error(_0x65bf('0xfb'));}}catch(_0x175694){throw new Error('Invalid\x20createdAt\x20filter');}}if(!_0x7e8795[_0x65bf('0x3b')]['hasOwnProperty'](_0x65bf('0xc7'))){_0x4e404[_0x65bf('0x24')]=qs[_0x65bf('0x24')](_0x7e8795[_0x65bf('0x3b')]['limit']||0xa);_0x4e404[_0x65bf('0x23')]=qs[_0x65bf('0x23')](_0x7e8795[_0x65bf('0x3b')][_0x65bf('0x23')]);}var _0x1e45e3=_0x1ca473['map'](function(_0x133c3b){if(_0x133c3b==='voice'){var _0x5ba23f={'attributes':['id',_0x65bf('0xfc'),_0x65bf('0x62'),_0x65bf('0xfd'),'destination',_0x65bf('0xfe'),'starttime','endtime',_0x65bf('0xff'),_0x65bf('0x100'),'createdAt',_0x65bf('0x101'),_0x65bf('0x102'),_0x65bf('0x103')],'where':{'ContactId':_0x7e8795[_0x65bf('0xb9')]['id']},'include':[{'model':db['User'],'as':'User','attributes':['id',_0x65bf('0x2d'),_0x65bf('0x104'),'alias']}],'order':[[_0x65bf('0x105'),_0x65bf('0x106')]]};if(_0x7e8795[_0x65bf('0x3b')]['range']){_0x5ba23f[_0x65bf('0x43')][_0x65bf('0x105')]={'$gte':_0x5debb7[_0x65bf('0x47')],'$lte':_0x5debb7['to']};}return db['VoiceCallReport'][_0x65bf('0x107')](_0x5ba23f)['then'](function(_0x2e4eaf){_0x428886[_0x65bf('0x84')]+=_0x2e4eaf['count'];return _['map'](_0x2e4eaf[_0x65bf('0x91')],function(_0x774bc6){var _0x74cdbf=_0x774bc6[_0x65bf('0x9d')]({'plain':!![]});_0x74cdbf[_0x65bf('0xf4')]=_0x133c3b;if(_0x74cdbf[_0x65bf('0x5a')]){_0x74cdbf[_0x65bf('0x5a')]={'id':_0x74cdbf[_0x65bf('0x5a')]['id'],'name':_0x74cdbf['User'][_0x65bf('0x2d')],'fullname':_0x74cdbf['User']['fullname'],'alias':_0x74cdbf['User']['alias']};}return _0x74cdbf;});});}else{var _0x43e6c1=_[_0x65bf('0x108')](_0x133c3b)+(_0x133c3b===_0x65bf('0x109')?_0x65bf('0x10a'):_0x65bf('0x10b'));var _0x593a64={'attributes':['id',_0x65bf('0x10c'),_0x65bf('0x10d'),_0x65bf('0x105'),_0x65bf('0x100'),_0x65bf('0x10e'),_0x65bf('0x10f'),_0x65bf('0x110'),_0x65bf('0x111'),_0x43e6c1+'Id'],'where':{'ContactId':_0x7e8795[_0x65bf('0xb9')]['id']},'include':[{'model':db[_0x43e6c1],'as':_0x65bf('0x10b'),'attributes':['id',_0x65bf('0x2d'),_0x65bf('0x112')]},{'model':db['User'],'as':'Owner','attributes':['id',_0x65bf('0x2d'),_0x65bf('0x104')]},{'model':db[_0x65bf('0x54')],'as':_0x65bf('0x90'),'attributes':['id',_0x65bf('0x2d'),_0x65bf('0xba')],'through':{'attributes':[]}}],'order':[[_0x65bf('0x105'),_0x65bf('0x106')]]};if(_0x7e8795['query']['range']){_0x593a64['where'][_0x65bf('0x105')]={'$gte':_0x5debb7[_0x65bf('0x47')],'$lte':_0x5debb7['to']};}switch(_0x133c3b){case _0x65bf('0x109'):_0x593a64[_0x65bf('0x3e')][_0x65bf('0x35')](_0x65bf('0x113'),_0x65bf('0x114'),'customerPort',_0x65bf('0x115'),_0x65bf('0x116'),'ratingMessage',_0x65bf('0x117'),_0x65bf('0x118'),_0x65bf('0x119'));break;case _0x65bf('0xf0'):_0x593a64['attributes'][_0x65bf('0x35')](_0x65bf('0x11a'),_0x65bf('0x11b'));break;case _0x65bf('0x11c'):_0x593a64[_0x65bf('0x3e')][_0x65bf('0x35')](_0x65bf('0x11d'),_0x65bf('0x11e'));break;}return db[_[_0x65bf('0x108')](_0x133c3b)+'Interaction']['findAndCountAll'](_0x593a64)[_0x65bf('0x2b')](function(_0x241096){_0x428886[_0x65bf('0x84')]+=_0x241096[_0x65bf('0x84')];return _[_0x65bf('0x57')](_0x241096[_0x65bf('0x91')],function(_0x142fbf){var _0x2e97f4=_0x142fbf['get']({'plain':!![]});_0x2e97f4[_0x65bf('0xf4')]=_0x133c3b;if(_0x2e97f4[_0x65bf('0x11f')]){_0x2e97f4['Owner']={'id':_0x2e97f4[_0x65bf('0x11f')]['id'],'name':_0x2e97f4[_0x65bf('0x11f')][_0x65bf('0x2d')],'fullname':_0x2e97f4[_0x65bf('0x11f')][_0x65bf('0x104')]};}return _0x2e97f4;});});}});return Promise['all'](_0x1e45e3);})[_0x65bf('0x2b')](function(_0x40509b){return _(_0x40509b)[_0x65bf('0x120')]()[_0x65bf('0x121')](_0x65bf('0x105'))['reverse']()['value']();})[_0x65bf('0x2b')](function(_0x46b9a8){_0x428886[_0x65bf('0x91')]=_0x4e404['limit']?_0x46b9a8['slice'](_0x4e404[_0x65bf('0x23')],_0x4e404['offset']+_0x4e404[_0x65bf('0x24')]):_0x46b9a8;return _0x428886;})[_0x65bf('0x2b')](respondWithFilteredResult(_0x44a337,_0x4e404))['catch'](handleError(_0x44a337,null));};
\ No newline at end of file
+var _0xdaea=['threadId','Interaction','Owner','flatten','sortBy','reverse','value','slice','util','path','squel','ioredis','../../components/contacts','../../config/logger','../../config/environment','../../config/environment/shared','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','status','json','offset','undefined','count','update','then','end','sendStatus','error','stack','name','send','describe','getOptions','query','user','catch','CmContact','find','tags','keys','length','startsWith','cf_','analytics','findAll','displayName','alias','type','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','hasOwnProperty','merge','body','from','get','mergeWith','isArray','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','destroy','[CmContact][merge][destroy][CmHopper],\x20%s','create','ChatInteraction','ChatMessage','MailMessage','MailInteraction','SmsInteraction','SmsMessage','FaxInteraction','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperFinal','CmHopperHistory','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','JscriptySessionReport','WhatsappMessage','WhatsappQueueReport','join','isNil','dialTimezone','timezones','utcOffset','additionalPhones','bulkCreate','each','duplicates','where','push','ListId','findOrCreate','contact','all','params','Tag','Tags','color','Phones','ContactItemType','ItemType','sequelize','literal','Phones.OrderBy','CmCustomField','omit','map','format','cf_%d','$and','pickBy','isEmpty','table','setFields','text','values','getTags','findOne','rawAttributes','filters','intersection','model','attributes','fields','order','sort','pick','filter','nolimit','limit','setTags','OrderBy','items','item_types','ItemTypeId','description','contact\x20phone\x20exists','PHONE','CmHopperAdditionalPhone','item','`ItemType`.OrderBy','CmHopperId','phone','ItemType.OrderBy','duplicateAdditionalPhones','CmContactId','toContactId','rescheduleAdditionalPhones','hopperId','ContactId','options','include','getHopperHistories','rows','includeAll','getJscriptySessions','No\x20ListId\x20specified','binding_keys','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','binding_values','Incorrect\x20binding\x20parameters\x20passed!','zipObject','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','filename','chmodSync','0777','fork','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','upload','createReadStream','meta','User','agent','binding','child_process','../../components/import/cm/csv2','stringify','message','error\x20child\x20process','../../components/import/cm/csvUpdates','start\x20child\x20process\x20correctly!','getJourney','mail','chat','sms','openchannel','fax','whatsapp','-createdAt','channel','includes','toLowerCase','Invalid\x20channel','range','parse','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','Invalid\x20createdAt\x20filter','voice','uniqueid','source','destination','callerid','endtime','note','userDisposition','userSecondDisposition','UserId','fullname','DESC','createdAt','findAndCountAll','startCase','Website','Account','closed','closedAt','disposition','secondDisposition','thirdDisposition','key','deviceModel','osName','ratingMessage','ratingType','referer','subject','externalUrl'];(function(_0x108d5f,_0x33f82d){var _0x456ea3=function(_0x228200){while(--_0x228200){_0x108d5f['push'](_0x108d5f['shift']());}};_0x456ea3(++_0x33f82d);}(_0xdaea,0xfe));var _0xadae=function(_0x2cc0b3,_0x120bf1){_0x2cc0b3=_0x2cc0b3-0x0;var _0x1667ef=_0xdaea[_0x2cc0b3];return _0x1667ef;};'use strict';var moment=require('moment');var BPromise=require('bluebird');var util=require(_0xadae('0x0'));var path=require(_0xadae('0x1'));var fs=require('fs');var _=require('lodash');var squel=require(_0xadae('0x2'));var Papa=require('papaparse');var Redis=require(_0xadae('0x3'));var contacts=require(_0xadae('0x4'));var qs=require('../../components/parsers/qs');var logger=require(_0xadae('0x5'))('api');var config=require(_0xadae('0x6'));var shared=require(_0xadae('0x7'));var db=require(_0xadae('0x8'))['db'];config[_0xadae('0x9')]=_[_0xadae('0xa')](config[_0xadae('0x9')],{'host':_0xadae('0xb'),'port':0x18eb});var socket=require(_0xadae('0xc'))(new Redis(config[_0xadae('0x9')]));require(_0xadae('0xd'))['register'](socket);function respondWithResult(_0x140cfa,_0x16123a){_0x16123a=_0x16123a||0xc8;return function(_0x5052de){if(_0x5052de){return _0x140cfa[_0xadae('0xe')](_0x16123a)[_0xadae('0xf')](_0x5052de);}};}function respondWithFilteredResult(_0x22ded7,_0x534e4f){return function(_0x3b668d){if(_0x3b668d){var _0x44b7cd=typeof _0x534e4f[_0xadae('0x10')]===_0xadae('0x11')&&typeof _0x534e4f['limit']===_0xadae('0x11');var _0x5a03e0=_0x3b668d[_0xadae('0x12')];var _0x248a83=_0x44b7cd?0x0:_0x534e4f[_0xadae('0x10')];var _0x4b4e73=_0x44b7cd?_0x3b668d[_0xadae('0x12')]:_0x534e4f[_0xadae('0x10')]+_0x534e4f['limit'];var _0x4fafaa;if(_0x4b4e73>=_0x5a03e0){_0x4b4e73=_0x5a03e0;_0x4fafaa=0xc8;}else{_0x4fafaa=0xce;}_0x22ded7['status'](_0x4fafaa);return _0x22ded7['set']('Content-Range',_0x248a83+'-'+_0x4b4e73+'/'+_0x5a03e0)[_0xadae('0xf')](_0x3b668d);}return null;};}function saveUpdates(_0x510baf){return function(_0x5d92aa){if(_0x5d92aa){return _0x5d92aa[_0xadae('0x13')](_0x510baf)['then'](function(_0x29971d){return _0x29971d;});}return null;};}function removeEntity(_0xf81e21){return function(_0x2cb6cf){if(_0x2cb6cf){return _0x2cb6cf['destroy']()[_0xadae('0x14')](function(){_0xf81e21['status'](0xcc)[_0xadae('0x15')]();});}};}function handleEntityNotFound(_0x2cb213){return function(_0x554068){if(!_0x554068){_0x2cb213[_0xadae('0x16')](0x194);}return _0x554068;};}function handleError(_0x3a2603,_0x4c09d9){_0x4c09d9=_0x4c09d9||0x1f4;return function(_0x58ecbe){logger[_0xadae('0x17')](_0x58ecbe[_0xadae('0x18')]);if(_0x58ecbe[_0xadae('0x19')]){delete _0x58ecbe[_0xadae('0x19')];}_0x3a2603[_0xadae('0xe')](_0x4c09d9)[_0xadae('0x1a')](_0x58ecbe);};}exports['index']=function(_0x2f6234,_0xb064b1){var _0x5c30ca={};return contacts[_0xadae('0x1b')]()[_0xadae('0x14')](function(_0x4d428c){_0x5c30ca=qs[_0xadae('0x1c')](_0x4d428c,_0x2f6234);return contacts['findAll'](_0x2f6234[_0xadae('0x1d')],_0x2f6234[_0xadae('0x1e')],_0x5c30ca,_0x4d428c);})[_0xadae('0x14')](respondWithFilteredResult(_0xb064b1,_0x5c30ca))[_0xadae('0x1f')](handleError(_0xb064b1,null));};exports['destroy']=function(_0x79f8b3,_0x2620f0){return db[_0xadae('0x20')][_0xadae('0x21')]({'where':{'id':_0x79f8b3['params']['id']}})['then'](handleEntityNotFound(_0x2620f0,null))[_0xadae('0x14')](removeEntity(_0x2620f0,null))[_0xadae('0x1f')](handleError(_0x2620f0,null));};exports[_0xadae('0x1b')]=function(_0x54691c,_0x2d5438){return db[_0xadae('0x20')][_0xadae('0x1b')]()['then'](function(_0x565b33){delete _0x565b33[_0xadae('0x22')];for(var _0x264266=0x0;_0x264266<Object[_0xadae('0x23')](_0x565b33)[_0xadae('0x24')];_0x264266++){var _0x413d8a=Object['keys'](_0x565b33)[_0x264266];if(!_[_0xadae('0x25')](_0x413d8a,_0xadae('0x26'))){_0x565b33[_0x413d8a]['columnName']=_0x413d8a;_0x565b33[_0x413d8a]['displayName']=_0x413d8a;}}return _0x565b33;})['then'](function(_0x484a05){var _0x502097={'where':Boolean(_0x54691c['query'][_0xadae('0x27')])===!![]?undefined:{'$or':[{'ListId':_0x54691c[_0xadae('0x1d')]['id']},{'ListId':null}]},'raw':!![]};return db['CmCustomField'][_0xadae('0x28')](_0x502097)[_0xadae('0x14')](function(_0xc48e0){for(var _0x2f19e8=0x0;_0x2f19e8<_0xc48e0['length'];_0x2f19e8++){var _0x3ee189=_0xadae('0x26')+_0xc48e0[_0x2f19e8]['id'];if(_0x484a05[_0x3ee189]){_0x484a05[_0x3ee189]['columnName']=_0x3ee189;_0x484a05[_0x3ee189][_0xadae('0x29')]=_0xc48e0[_0x2f19e8][_0xadae('0x2a')];_0x484a05[_0x3ee189]['custom']={'type':_0xc48e0[_0x2f19e8][_0xadae('0x2b')],'values':_0xc48e0[_0x2f19e8]['values']};}else{logger['info'](_0xadae('0x2c'),_0x3ee189);}}Object[_0xadae('0x23')](_0x484a05)['forEach'](function(_0x1c821d){if(!_0x484a05[_0x1c821d][_0xadae('0x2d')]('columnName')){delete _0x484a05[_0x1c821d];}});return _0x484a05;});})[_0xadae('0x14')](respondWithResult(_0x2d5438,null))[_0xadae('0x1f')](handleError(_0x2d5438,null));};exports[_0xadae('0x2e')]=function(_0x42787b,_0x274fb4){var _0x1069c2;var _0x4ed8b5;var _0x24726a;if(_0x42787b[_0xadae('0x2f')]['id']){delete _0x42787b[_0xadae('0x2f')]['id'];}return db['CmContact'][_0xadae('0x28')]({'where':{'id':[_0x42787b[_0xadae('0x2f')]['to'],_0x42787b[_0xadae('0x2f')][_0xadae('0x30')]]}})[_0xadae('0x14')](function(_0x124160){if(_0x124160){if(_0x124160[_0xadae('0x24')]!==0x2){return null;}_0x124160[0x0]=_0x124160[0x0][_0xadae('0x31')]({'plain':!![]});_0x124160[0x1]=_0x124160[0x1]['get']({'plain':!![]});delete _0x124160[0x0]['id'];delete _0x124160[0x1]['id'];return _[_0xadae('0x32')](_0x124160[0x0],_0x124160[0x1],function(_0x16a7e8,_0x4a61a1){if(Array[_0xadae('0x33')](_0x4a61a1)&&!_0x4a61a1['length']){return _0x16a7e8;}else if(!_0x4a61a1){return _0x16a7e8;}});}})['then'](handleEntityNotFound(_0x274fb4,null))[_0xadae('0x14')](function(_0x168ddd){if(_0x168ddd){if(_0x168ddd[_0xadae('0x22')]&&_['isArray'](_0x168ddd[_0xadae('0x22')])){_0x168ddd['tags']=_0x168ddd[_0xadae('0x22')]['join']();}logger[_0xadae('0x34')](_0xadae('0x35'),_0x42787b[_0xadae('0x2f')]['to'],_0x42787b[_0xadae('0x2f')][_0xadae('0x30')]);return db[_0xadae('0x36')][_0xadae('0x37')]({'where':{'ContactId':[_0x42787b[_0xadae('0x2f')]['to'],_0x42787b['body'][_0xadae('0x30')]]}})[_0xadae('0x14')](function(_0x3149e2){logger[_0xadae('0x34')](_0xadae('0x38'),_0x3149e2);return db['CmHopperBlack'][_0xadae('0x37')]({'where':{'ContactId':[_0x42787b[_0xadae('0x2f')]['to'],_0x42787b[_0xadae('0x2f')][_0xadae('0x30')]]}})[_0xadae('0x14')](function(_0x2189f6){logger[_0xadae('0x34')]('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x2189f6);return db[_0xadae('0x20')][_0xadae('0x39')](_0x168ddd);});});}})[_0xadae('0x14')](function(_0x35dc40){if(_0x35dc40){_0x1069c2=_0x35dc40;_0x4ed8b5={'ContactId':_0x1069c2['id']};_0x24726a={'where':{'ContactId':[_0x42787b[_0xadae('0x2f')]['to'],_0x42787b['body'][_0xadae('0x30')]]}};return db[_0xadae('0x3a')]['update'](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x3b')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})['then'](function(){if(_0x1069c2){return db['ChatOfflineMessage'][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})['then'](function(){if(_0x1069c2){return db['MailInteraction'][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})['then'](function(){if(_0x1069c2){return db[_0xadae('0x3c')]['update'](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x3d')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})['then'](function(){if(_0x1069c2){return db[_0xadae('0x3c')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x3e')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x3f')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x40')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db['FaxMessage'][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x41')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x42')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x43')][_0xadae('0x13')]({'CmContactId':_0x1069c2['id']},{'where':{'CmContactId':[_0x42787b[_0xadae('0x2f')]['to'],_0x42787b[_0xadae('0x2f')][_0xadae('0x30')]]}});}})['then'](function(){if(_0x1069c2){return db[_0xadae('0x44')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x45')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})['then'](function(){if(_0x1069c2){return db['ReportAgentPreview'][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x46')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x47')]['update'](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x48')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x49')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x4a')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db['SmsQueueReport'][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x4b')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db['WhatsappInteraction']['update'](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x4c')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x4d')][_0xadae('0x13')](_0x4ed8b5,_0x24726a);}})[_0xadae('0x14')](function(){if(_0x1069c2){return db[_0xadae('0x20')]['destroy']({'where':{'id':[_0x42787b['body']['to'],_0x42787b[_0xadae('0x2f')][_0xadae('0x30')]]}});}})[_0xadae('0x14')](function(){if(_0x1069c2){return _0x1069c2;}})[_0xadae('0x14')](respondWithResult(_0x274fb4,null))[_0xadae('0x1f')](handleError(_0x274fb4,null));};exports[_0xadae('0x39')]=function(_0x3d7ad1,_0x1174b1){return db['CmContact'][_0xadae('0x1b')]()[_0xadae('0x14')](function(_0x4d1797){if(_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x22')]&&_[_0xadae('0x33')](_0x3d7ad1[_0xadae('0x2f')]['tags'])){if(_0x3d7ad1['body']['tags'][_0xadae('0x24')]){_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x22')]=_0x3d7ad1['body']['tags'][_0xadae('0x4e')](';')+';';}else{_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x22')]=null;}}else{_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x22')]=null;}if(!_[_0xadae('0x4f')](_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x50')])){var _0x3d86dc=_0x3d7ad1[_0xadae('0x2f')]['dialTimezone'];if(!_[_0xadae('0x4f')](shared[_0xadae('0x51')][_0x3d86dc]))_0x3d7ad1['body']['utcOffset']=shared[_0xadae('0x51')][_0x3d86dc][_0xadae('0x52')];}return db[_0xadae('0x20')][_0xadae('0x39')](_0x3d7ad1[_0xadae('0x2f')],{'fields':_[_0xadae('0x23')](_0x4d1797),'raw':!![]});})[_0xadae('0x14')](function(_0xcc9ab3){if(_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x53')]){return insertAdditionalPhones(_0xcc9ab3,_0x3d7ad1[_0xadae('0x2f')][_0xadae('0x53')]);}else{return _0xcc9ab3;}})[_0xadae('0x14')](respondWithResult(_0x1174b1,0xc9))[_0xadae('0x1f')](handleError(_0x1174b1,null));};exports[_0xadae('0x54')]=function(_0x227575,_0x18173b){var _0x3a5092=0x0;var _0x4a51ba=0x0;var _0x3bce7a=0x0;var _0x5426e7=[];return db[_0xadae('0x20')][_0xadae('0x1b')]()[_0xadae('0x14')](function(_0x4ee379){return BPromise[_0xadae('0x55')](_0x227575[_0xadae('0x2f')],function(_0x29fac6){var _0x56d7f0={'where':{'$or':[]},'defaults':_0x29fac6,'fields':_[_0xadae('0x23')](_0x4ee379),'raw':!![]};if(_0x29fac6['duplicates']){for(var _0x20f1de=0x0;_0x20f1de<_0x29fac6[_0xadae('0x56')][_0xadae('0x24')];_0x20f1de++){var _0x3d7ca1={};_0x3d7ca1[_0x29fac6[_0xadae('0x56')][_0x20f1de]]=_0x29fac6[_0x29fac6[_0xadae('0x56')][_0x20f1de]];_0x56d7f0[_0xadae('0x57')]['$or'][_0xadae('0x58')](_0x3d7ca1);}_0x56d7f0[_0xadae('0x57')][_0xadae('0x59')]=_0x29fac6[_0xadae('0x59')];}return db['CmContact'][_0xadae('0x5a')](_0x56d7f0)['spread'](function(_0x7a02fa,_0x35e44f){if(_0x35e44f){if(_0x29fac6[_0xadae('0x2d')]('additionalPhones')){_0x5426e7[_0xadae('0x58')]({'contact':_0x7a02fa,'additionalPhones':_0x29fac6[_0xadae('0x53')]});}_0x3a5092++;}else{_0x3bce7a++;}})[_0xadae('0x1f')](function(){_0x4a51ba++;});});})['then'](function(_0x396297){if(_0x396297){if(_0x5426e7[_0xadae('0x24')]>0x0){return new Promise(function(_0x5ef385){var _0x553fc7=[];for(var _0x118a73=0x0;_0x118a73<_0x5426e7[_0xadae('0x24')];_0x118a73++){_0x553fc7[_0xadae('0x58')](insertAdditionalPhones(_0x5426e7[_0x118a73][_0xadae('0x5b')],_0x5426e7[_0x118a73][_0xadae('0x53')]));}Promise[_0xadae('0x5c')](_0x553fc7)[_0xadae('0x14')](function(){_0x5ef385(0x1);});})['then'](function(){return{'success':_0x3a5092,'failure':_0x4a51ba,'duplicates':_0x3bce7a};});}else{return{'success':_0x3a5092,'failure':_0x4a51ba,'duplicates':_0x3bce7a};}}})['then'](respondWithResult(_0x18173b,0xc9))[_0xadae('0x1f')](handleError(_0x18173b,null));};exports['show']=function(_0x171a5c,_0x1f2c0d){var _0x3824c4;return db[_0xadae('0x20')][_0xadae('0x1b')]()[_0xadae('0x14')](function(_0x43179a){return db[_0xadae('0x20')][_0xadae('0x21')]({'where':{'id':_0x171a5c[_0xadae('0x5d')]['id']},'include':[{'model':db[_0xadae('0x5e')],'as':_0xadae('0x5f'),'attributes':['id',_0xadae('0x19'),_0xadae('0x60')],'required':_0x171a5c[_0xadae('0x1d')]['tag']?!![]:![]},{'model':db['CmContactHasItem'],'as':_0xadae('0x61'),'where':{'CmContactId':_0x171a5c[_0xadae('0x5d')]['id']},'required':![],'include':[{'model':db[_0xadae('0x62')],'as':_0xadae('0x63')}]}],'order':[db[_0xadae('0x64')][_0xadae('0x65')](_0xadae('0x66'))],'attributes':_[_0xadae('0x23')](_0x43179a)});})[_0xadae('0x14')](function(_0x470eaf){if(!_[_0xadae('0x4f')](_0x470eaf)){_0x3824c4=_0x470eaf[_0xadae('0x31')]({'plain':!![]});var _0x26d23a={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x470eaf&&_0x470eaf[_0xadae('0x59')]){if(_0x470eaf[_0xadae('0x59')]){_0x26d23a[_0xadae('0x57')]['$and']['push']({'ListId':{'$ne':_0x470eaf[_0xadae('0x59')]}});}}return db[_0xadae('0x67')][_0xadae('0x28')](_0x26d23a);}})['then'](function(_0xd2b53e){if(!_[_0xadae('0x4f')](_0xd2b53e)){return _[_0xadae('0x68')](_0x3824c4,_[_0xadae('0x69')](_0xd2b53e,function(_0x5a344a){return util[_0xadae('0x6a')](_0xadae('0x6b'),_0x5a344a['id']);}));}})[_0xadae('0x14')](handleEntityNotFound(_0x1f2c0d,null))[_0xadae('0x14')](respondWithResult(_0x1f2c0d,null))[_0xadae('0x1f')](handleError(_0x1f2c0d,null));};exports['update']=function(_0x1d9211,_0x45039a){var _0x1941e9;if(_0x1d9211[_0xadae('0x2f')]['id']){delete _0x1d9211[_0xadae('0x2f')]['id'];}if(!_[_0xadae('0x4f')](_0x1d9211['body']['dialTimezone'])){var _0x51f046=_0x1d9211[_0xadae('0x2f')]['dialTimezone'];if(!_['isNil'](shared[_0xadae('0x51')][_0x51f046]))_0x1d9211[_0xadae('0x2f')][_0xadae('0x52')]=shared[_0xadae('0x51')][_0x51f046]['utcOffset'];}return db[_0xadae('0x20')][_0xadae('0x21')]({'where':{'id':_0x1d9211[_0xadae('0x5d')]['id']}})[_0xadae('0x14')](handleEntityNotFound(_0x45039a,null))[_0xadae('0x14')](saveUpdates(_0x1d9211[_0xadae('0x2f')],null))[_0xadae('0x14')](function(_0x26c7cf){_0x1941e9=_0x26c7cf;var _0x3e14ba={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x26c7cf&&_0x26c7cf[_0xadae('0x59')]){if(_0x26c7cf[_0xadae('0x59')]){_0x3e14ba[_0xadae('0x57')][_0xadae('0x6c')][_0xadae('0x58')]({'ListId':{'$ne':_0x26c7cf[_0xadae('0x59')]}});}}return db['CmCustomField']['findAll'](_0x3e14ba);})[_0xadae('0x14')](function(_0x417a18){if(_0x417a18){return _[_0xadae('0x68')](_[_0xadae('0x6d')](_0x1d9211[_0xadae('0x2f')],function(_0x17e3ee,_0x196b6e){return _[_0xadae('0x25')](_0x196b6e,'cf_');}),_[_0xadae('0x69')](_0x417a18,function(_0x8c12ad){return util['format'](_0xadae('0x6b'),_0x8c12ad['id']);}));}})[_0xadae('0x14')](function(_0x1cc4f8){if(_0x1cc4f8&&!_[_0xadae('0x6e')](_0x1cc4f8)){var _0x2ce668=squel['update']()[_0xadae('0x6f')]('cm_contacts')[_0xadae('0x70')](_0x1cc4f8)[_0xadae('0x57')]('id\x20=\x20?',_0x1d9211[_0xadae('0x5d')]['id'])['toParam']();return db[_0xadae('0x64')][_0xadae('0x1d')](_0x2ce668[_0xadae('0x71')],{'replacements':_0x2ce668[_0xadae('0x72')]});}})[_0xadae('0x14')](function(){if(_0x1d9211[_0xadae('0x2f')]['phone']&&_0x1941e9){return db[_0xadae('0x36')][_0xadae('0x13')]({'phone':_0x1d9211[_0xadae('0x2f')]['phone'],'OrderBy':0x0},{'where':{'ContactId':_0x1941e9['id']}});}})[_0xadae('0x14')](function(){return _0x1941e9;})[_0xadae('0x14')](respondWithResult(_0x45039a,null))[_0xadae('0x1f')](handleError(_0x45039a,null));};exports[_0xadae('0x73')]=function(_0x1649ca,_0x3c8fa6){var _0x2cd694={};var _0x175350={};var _0x46ff15;var _0x1bc7b2;return db[_0xadae('0x20')][_0xadae('0x74')]({'where':{'id':_0x1649ca[_0xadae('0x5d')]['id']}})[_0xadae('0x14')](handleEntityNotFound(_0x3c8fa6,null))[_0xadae('0x14')](function(_0x4a0b4e){if(_0x4a0b4e){_0x46ff15=_0x4a0b4e;_0x175350['model']=_[_0xadae('0x23')](db[_0xadae('0x5e')][_0xadae('0x75')]);_0x175350['query']=_[_0xadae('0x23')](_0x1649ca[_0xadae('0x1d')]);_0x175350[_0xadae('0x76')]=_[_0xadae('0x77')](_0x175350[_0xadae('0x78')],_0x175350[_0xadae('0x1d')]);_0x2cd694[_0xadae('0x79')]=_['intersection'](_0x175350[_0xadae('0x78')],qs[_0xadae('0x7a')](_0x1649ca[_0xadae('0x1d')][_0xadae('0x7a')]));_0x2cd694[_0xadae('0x79')]=_0x2cd694[_0xadae('0x79')][_0xadae('0x24')]?_0x2cd694[_0xadae('0x79')]:_0x175350[_0xadae('0x78')];_0x2cd694[_0xadae('0x7b')]=qs[_0xadae('0x7c')](_0x1649ca['query'][_0xadae('0x7c')]);_0x2cd694['where']=qs[_0xadae('0x76')](_[_0xadae('0x7d')](_0x1649ca[_0xadae('0x1d')],_0x175350['filters']));if(_0x1649ca[_0xadae('0x1d')][_0xadae('0x7e')]){_0x2cd694['where']=_[_0xadae('0x2e')](_0x2cd694[_0xadae('0x57')],{'$or':_[_0xadae('0x69')](_0x2cd694[_0xadae('0x79')],function(_0x1aed26){var _0x201977={};_0x201977[_0x1aed26]={'$like':'%'+_0x1649ca[_0xadae('0x1d')][_0xadae('0x7e')]+'%'};return _0x201977;})});}_0x2cd694=_[_0xadae('0x2e')]({},_0x2cd694,_0x1649ca['options']);return _0x46ff15[_0xadae('0x73')](_0x2cd694);}})[_0xadae('0x14')](function(_0xf3fba7){if(_0xf3fba7){_0x1bc7b2=_0xf3fba7[_0xadae('0x24')];if(!_0x1649ca[_0xadae('0x1d')][_0xadae('0x2d')](_0xadae('0x7f'))){_0x2cd694['limit']=qs[_0xadae('0x80')](_0x1649ca[_0xadae('0x1d')][_0xadae('0x80')]);_0x2cd694[_0xadae('0x10')]=qs[_0xadae('0x10')](_0x1649ca[_0xadae('0x1d')]['offset']);}return _0x46ff15[_0xadae('0x73')](_0x2cd694);}})[_0xadae('0x14')](function(_0x2e924f){if(_0x2e924f){return _0x2e924f?{'count':_0x1bc7b2,'rows':_0x2e924f}:null;}})['then'](respondWithResult(_0x3c8fa6,null))[_0xadae('0x1f')](handleError(_0x3c8fa6,null));};exports[_0xadae('0x81')]=function(_0xe7af06,_0xde2f60){if(_0xe7af06[_0xadae('0x2f')]['id']){delete _0xe7af06[_0xadae('0x2f')]['id'];}return db[_0xadae('0x20')][_0xadae('0x74')]({'where':{'id':_0xe7af06[_0xadae('0x5d')]['id']}})[_0xadae('0x14')](handleEntityNotFound(_0xde2f60,null))[_0xadae('0x14')](function(_0x48e692){if(_0x48e692){return _0x48e692[_0xadae('0x81')](_0xe7af06['body']['ids']||[]);}return null;})['then'](respondWithResult(_0xde2f60,null))['catch'](handleError(_0xde2f60,null));};exports['setAdditionalPhones']=function(_0x1c4ddd,_0x7b1b67){var _0x3886f4=[];_0x3886f4[_0xadae('0x58')](addAdditionalPhones(_0x1c4ddd['body']));Promise[_0xadae('0x5c')](_0x3886f4)[_0xadae('0x14')](function(){_0x3886f4=[];_0x3886f4[_0xadae('0x58')](deleteCmHopperPhones(_0x1c4ddd[_0xadae('0x2f')]['id']));_0x3886f4[_0xadae('0x58')](addCmHopperPhones(_0x1c4ddd['body']['id']));Promise[_0xadae('0x5c')](_0x3886f4)[_0xadae('0x14')](function(){return[0x1];})[_0xadae('0x14')](respondWithResult(_0x7b1b67,null));});};function addAdditionalPhones(_0x182b80){var _0x13e75c;return new Promise(function(_0x66ecb1){return db['CmContactHasItem'][_0xadae('0x37')]({'where':{'CmContactId':_0x182b80['id']}})[_0xadae('0x14')](function(){db[_0xadae('0x62')]['findAll']({'raw':!![],'attributes':['id',_0xadae('0x82')]})[_0xadae('0x14')](function(_0x19b606){var _0x5f1619=[];for(var _0x20389f=0x0;_0x20389f<_0x182b80[_0xadae('0x83')][_0xadae('0x24')];_0x20389f++){var _0x530b0c=_0x182b80[_0xadae('0x84')]?_[_0xadae('0x4f')](_0x182b80[_0xadae('0x84')][_0x20389f])?'':_0x182b80[_0xadae('0x84')][_0x20389f]:_0x182b80['items'][_0x20389f][_0xadae('0x85')]?_0x182b80[_0xadae('0x83')][_0x20389f][_0xadae('0x85')]:'';var _0x24828a=_[_0xadae('0x4f')](_0x182b80[_0xadae('0x83')][_0x20389f]['description'])?'':_0x182b80[_0xadae('0x83')][_0x20389f][_0xadae('0x86')];var _0xf82bcb=_0x530b0c+':'+_0x182b80[_0xadae('0x83')][_0x20389f]['phone']+'ยง'+_0x24828a;if(_[_0xadae('0x4f')](_0x13e75c))_0x13e75c=_0xf82bcb;else _0x13e75c+=';'+_0xf82bcb;var _0xfa01b6=null;var _0x4ca0b1=null;if(_0x182b80[_0xadae('0x84')]){if(!_[_0xadae('0x4f')](_0x182b80[_0xadae('0x84')][_0x20389f])){_0x4ca0b1=_[_0xadae('0x21')](_0x19b606,function(_0x4fc208){return _0x4fc208['id']===_0x182b80[_0xadae('0x84')][_0x20389f];});if(!_[_0xadae('0x4f')](_0x4ca0b1)){_0xfa01b6=_0x4ca0b1['OrderBy'];}}}else{if(!_[_0xadae('0x4f')](_0x182b80[_0xadae('0x83')][_0x20389f])){_0x4ca0b1=_['find'](_0x19b606,function(_0x21b55a){return _0x21b55a['id']===_0x182b80[_0xadae('0x83')][_0x20389f][_0xadae('0x85')];});if(!_[_0xadae('0x4f')](_0x4ca0b1)){_0xfa01b6=_0x20389f;}}}if(_[_0xadae('0x4f')](_0xfa01b6)){_0xfa01b6=0x64;}_0x5f1619[_0xadae('0x58')](addAdditionalPhone(_0x182b80['id'],_0x182b80[_0xadae('0x83')][_0x20389f]['phone'],_0x182b80[_0xadae('0x84')]?_[_0xadae('0x4f')](_0x182b80[_0xadae('0x84')][_0x20389f])?null:_0x182b80[_0xadae('0x84')][_0x20389f]:_0x182b80[_0xadae('0x83')][_0x20389f][_0xadae('0x85')]?_0x182b80[_0xadae('0x83')][_0x20389f]['ItemTypeId']:null,_0xfa01b6,_0x24828a));}Promise[_0xadae('0x5c')](_0x5f1619)[_0xadae('0x14')](function(){db['CmContact'][_0xadae('0x13')]({'AdditionalPhones':_0x13e75c},{'where':{'id':_0x182b80['id']}})[_0xadae('0x14')](function(){_0x66ecb1(0x1);});});});});});}function addAdditionalPhone(_0x402fec,_0xc2a668,_0xdbc80e,_0x1f0744,_0x460a48){return db[_0xadae('0x43')][_0xadae('0x21')]({'where':{'CmContactId':_0x402fec,'item':_0xc2a668}})[_0xadae('0x14')](function(_0x3c3231){if(_0x3c3231)logger[_0xadae('0x34')](_0xadae('0x87'),_0x3c3231);else{db[_0xadae('0x43')][_0xadae('0x39')]({'CmContactId':_0x402fec,'item':_0xc2a668,'ItemTypeId':_0xdbc80e,'OrderBy':_0x1f0744,'ItemClass':_0xadae('0x88'),'description':_0x460a48});}});}function deleteCmHopperPhones(_0x2d01dd){return new Promise(function(_0x35cea2){return db['CmHopper']['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x2d01dd}})['then'](function(_0x44b05d){db[_0xadae('0x89')][_0xadae('0x37')]({'where':{'CmHopperId':{'$in':_[_0xadae('0x69')](_0x44b05d,'id')}}});})[_0xadae('0x14')](function(){_0x35cea2(0x1);});});}function addCmHopperPhones(_0x470612){return new Promise(function(_0x596d4d){return db[_0xadae('0x36')][_0xadae('0x28')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x470612}})[_0xadae('0x14')](function(_0x1b2479){var _0x1b3b79=[];_[_0xadae('0x69')](_0x1b2479,function(_0x348d0d){_0x1b3b79[_0xadae('0x58')](createCmHopperPhone(_0x470612,_0x348d0d['id']));});Promise[_0xadae('0x5c')](_0x1b3b79)[_0xadae('0x14')](function(){_0x596d4d(0x1);});});});}function createCmHopperPhone(_0x4fdbd0,_0x49108e){return new Promise(function(_0x10de56){db[_0xadae('0x43')][_0xadae('0x28')]({'raw':!![],'attributes':[_0xadae('0x8a'),'OrderBy'],'where':{'CmContactId':_0x4fdbd0,'ItemClass':_0xadae('0x88')},'include':[{'model':db[_0xadae('0x62')],'attributes':[_0xadae('0x82')],'as':_0xadae('0x63')}],'order':['OrderBy',db['sequelize'][_0xadae('0x65')](_0xadae('0x8b'))]})[_0xadae('0x14')](function(_0x5cf982){var _0xb8ed3c=0x1;var _0x555937=_[_0xadae('0x69')](_0x5cf982,function(_0x42ba87){_0x42ba87[_0xadae('0x8c')]=_0x49108e;_0x42ba87[_0xadae('0x8d')]=_0x42ba87[_0xadae('0x8a')];_0x42ba87['OrderBy']=_0xb8ed3c;delete _0x42ba87[_0xadae('0x8e')];_0xb8ed3c=_0xb8ed3c+0x1;return _0x42ba87;});return db['CmHopperAdditionalPhone']['bulkCreate'](_0x555937,{});})[_0xadae('0x14')](function(){_0x10de56(0x1);});});}function insertAdditionalPhones(_0x37ff7d,_0x382610){return new Promise(function(_0x5d9f09){var _0x217ec2=[];for(var _0x29bb14=0x0;_0x29bb14<_0x382610['length'];_0x29bb14++){var _0x330504=_0x382610[_0x29bb14];_0x217ec2[_0xadae('0x58')](parseContactItemType(_0x330504));}Promise['all'](_0x217ec2)['then'](function(){var _0x5201d1={'id':_0x37ff7d['id'],'items':_0x382610};return addAdditionalPhones(_0x5201d1)[_0xadae('0x14')](function(){return addCmHopperPhones(_0x37ff7d['id']);});})[_0xadae('0x14')](function(){_0x5d9f09(_0x37ff7d);});});}function parseContactItemType(_0x2480ba){return new Promise(function(_0x3ed86c){if(_0x2480ba[_0xadae('0x2d')](_0xadae('0x85'))){_0x3ed86c(_0x2480ba);}else{return db[_0xadae('0x62')][_0xadae('0x21')]({'where':{'name':_0x2480ba[_0xadae('0x63')]}})[_0xadae('0x14')](function(_0x513f2e){if(_[_0xadae('0x4f')](_0x513f2e))_0x2480ba['ItemTypeId']=null;else _0x2480ba[_0xadae('0x85')]=_0x513f2e['id'];_0x3ed86c(_0x2480ba);});}});}exports['getAdditionalPhones']=function(_0x1c6694,_0x15fac1){return db['CmContactHasItem'][_0xadae('0x28')]({'raw':!![],'where':{'CmContactId':_0x1c6694[_0xadae('0x5d')]['id'],'ItemClass':'PHONE'},'include':[{'model':db[_0xadae('0x62')],'as':_0xadae('0x63')}],'order':[[_0xadae('0x82')],[db[_0xadae('0x64')][_0xadae('0x65')](_0xadae('0x8b'))]]})[_0xadae('0x14')](function(_0x1a9532){return _0x1a9532;})['then'](respondWithResult(_0x15fac1,null))[_0xadae('0x1f')](handleError(_0x15fac1,null));};exports[_0xadae('0x8f')]=function(_0x39fc7e,_0x2e0af3){return db[_0xadae('0x43')][_0xadae('0x28')]({'raw':!![],'where':{'CmContactId':_0x39fc7e[_0xadae('0x2f')]['fromContactId']}})[_0xadae('0x14')](function(_0xfcfe8){var _0x2cee3c=_[_0xadae('0x69')](_0xfcfe8,function(_0x570b1a){_0x570b1a[_0xadae('0x90')]=_0x39fc7e[_0xadae('0x2f')][_0xadae('0x91')];return _0x570b1a;});return db['CmContactHasItem'][_0xadae('0x54')](_0x2cee3c,{});})[_0xadae('0x14')](function(){return addCmHopperPhones(_0x39fc7e['body'][_0xadae('0x91')]);})[_0xadae('0x14')](function(){return['ok'];})['then'](respondWithResult(_0x2e0af3,null))['catch'](handleError(_0x2e0af3,null));};exports[_0xadae('0x92')]=function(_0x48bf27,_0x5022e9){var _0x36df16=[];_0x36df16[_0xadae('0x58')](createCmHopperPhone(_0x48bf27['body']['id'],_0x48bf27[_0xadae('0x2f')][_0xadae('0x93')]));Promise['all'](_0x36df16)[_0xadae('0x14')](function(){return[0x1];})['then'](respondWithResult(_0x5022e9,null));};exports['getHoppers']=function(_0x187485,_0x20c8ee){var _0x4dcdb1={'raw':![],'where':{}};var _0x356b44={};var _0x4add9a={'count':0x0,'rows':[]};return db[_0xadae('0x20')][_0xadae('0x74')]({'where':{'id':_0x187485['params']['id']}})[_0xadae('0x14')](handleEntityNotFound(_0x20c8ee,null))[_0xadae('0x14')](function(_0x4bd822){if(_0x4bd822){_0x356b44[_0xadae('0x78')]=_[_0xadae('0x23')](db[_0xadae('0x36')][_0xadae('0x75')]);_0x356b44['query']=_[_0xadae('0x23')](_0x187485[_0xadae('0x1d')]);_0x356b44['filters']=_[_0xadae('0x77')](_0x356b44[_0xadae('0x78')],_0x356b44[_0xadae('0x1d')]);_0x4dcdb1[_0xadae('0x79')]=_[_0xadae('0x77')](_0x356b44[_0xadae('0x78')],qs[_0xadae('0x7a')](_0x187485[_0xadae('0x1d')][_0xadae('0x7a')]));_0x4dcdb1['attributes']=_0x4dcdb1[_0xadae('0x79')][_0xadae('0x24')]?_0x4dcdb1[_0xadae('0x79')]:_0x356b44[_0xadae('0x78')];if(!_0x187485[_0xadae('0x1d')][_0xadae('0x2d')](_0xadae('0x7f'))){_0x4dcdb1[_0xadae('0x80')]=qs[_0xadae('0x80')](_0x187485['query'][_0xadae('0x80')]);_0x4dcdb1[_0xadae('0x10')]=qs[_0xadae('0x10')](_0x187485[_0xadae('0x1d')]['offset']);}_0x4dcdb1[_0xadae('0x7b')]=qs[_0xadae('0x7c')](_0x187485[_0xadae('0x1d')][_0xadae('0x7c')]);_0x4dcdb1[_0xadae('0x57')]=qs['filters'](_['pick'](_0x187485['query'],_0x356b44[_0xadae('0x76')]));_0x4dcdb1[_0xadae('0x57')][_0xadae('0x94')]=_0x4bd822['id'];if(_0x187485[_0xadae('0x1d')][_0xadae('0x7e')]){_0x4dcdb1['where']=_['merge'](_0x4dcdb1[_0xadae('0x57')],{'$or':_[_0xadae('0x69')](_0x4dcdb1[_0xadae('0x79')],function(_0x49f287){var _0x50679d={};_0x50679d[_0x49f287]={'$like':'%'+_0x187485[_0xadae('0x1d')]['filter']+'%'};return _0x50679d;})});}_0x4dcdb1=_[_0xadae('0x2e')]({},_0x4dcdb1,_0x187485[_0xadae('0x95')]);return db[_0xadae('0x36')][_0xadae('0x12')]({'where':_0x4dcdb1[_0xadae('0x57')]})[_0xadae('0x14')](function(_0x4315ed){_0x4add9a[_0xadae('0x12')]=_0x4315ed;if(_0x187485[_0xadae('0x1d')]['includeAll']){_0x4dcdb1[_0xadae('0x96')]=[{'all':!![]}];}return db[_0xadae('0x36')][_0xadae('0x28')](_0x4dcdb1);})[_0xadae('0x14')](function(_0x55c2c4){_0x4add9a['rows']=_0x55c2c4;return _0x4add9a;});}})[_0xadae('0x14')](respondWithFilteredResult(_0x20c8ee,_0x4dcdb1))[_0xadae('0x1f')](handleError(_0x20c8ee,null));};exports[_0xadae('0x97')]=function(_0xaff9e6,_0x4f5471){var _0x20890f={'raw':!![],'where':{}};var _0x3ae0db={};var _0x4f52a6={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0xaff9e6[_0xadae('0x5d')]['id']}})[_0xadae('0x14')](handleEntityNotFound(_0x4f5471,null))[_0xadae('0x14')](function(_0x3a2242){if(_0x3a2242){_0x3ae0db['model']=_['keys'](db[_0xadae('0x45')][_0xadae('0x75')]);_0x3ae0db[_0xadae('0x1d')]=_['keys'](_0xaff9e6['query']);_0x3ae0db[_0xadae('0x76')]=_[_0xadae('0x77')](_0x3ae0db[_0xadae('0x78')],_0x3ae0db[_0xadae('0x1d')]);_0x20890f[_0xadae('0x79')]=_[_0xadae('0x77')](_0x3ae0db[_0xadae('0x78')],qs[_0xadae('0x7a')](_0xaff9e6[_0xadae('0x1d')][_0xadae('0x7a')]));_0x20890f[_0xadae('0x79')]=_0x20890f['attributes'][_0xadae('0x24')]?_0x20890f[_0xadae('0x79')]:_0x3ae0db['model'];if(!_0xaff9e6[_0xadae('0x1d')][_0xadae('0x2d')](_0xadae('0x7f'))){_0x20890f['limit']=qs[_0xadae('0x80')](_0xaff9e6['query'][_0xadae('0x80')]);_0x20890f[_0xadae('0x10')]=qs[_0xadae('0x10')](_0xaff9e6[_0xadae('0x1d')][_0xadae('0x10')]);}_0x20890f['order']=qs['sort'](_0xaff9e6[_0xadae('0x1d')]['sort']);_0x20890f[_0xadae('0x57')]=qs[_0xadae('0x76')](_[_0xadae('0x7d')](_0xaff9e6['query'],_0x3ae0db[_0xadae('0x76')]));_0x20890f[_0xadae('0x57')][_0xadae('0x94')]=_0x3a2242['id'];if(_0xaff9e6[_0xadae('0x1d')][_0xadae('0x7e')]){_0x20890f['where']=_[_0xadae('0x2e')](_0x20890f[_0xadae('0x57')],{'$or':_[_0xadae('0x69')](_0x20890f[_0xadae('0x79')],function(_0xb6184f){var _0x7746dc={};_0x7746dc[_0xb6184f]={'$like':'%'+_0xaff9e6[_0xadae('0x1d')][_0xadae('0x7e')]+'%'};return _0x7746dc;})});}_0x20890f=_['merge']({},_0x20890f,_0xaff9e6[_0xadae('0x95')]);return db[_0xadae('0x45')][_0xadae('0x12')]({'where':_0x20890f['where']})[_0xadae('0x14')](function(_0x55395c){_0x4f52a6[_0xadae('0x12')]=_0x55395c;if(_0xaff9e6['query']['includeAll']){_0x20890f[_0xadae('0x96')]=[{'all':!![]}];}return db[_0xadae('0x45')][_0xadae('0x28')](_0x20890f);})[_0xadae('0x14')](function(_0x26e6dc){_0x4f52a6[_0xadae('0x98')]=_0x26e6dc;return _0x4f52a6;});}})[_0xadae('0x14')](respondWithFilteredResult(_0x4f5471,_0x20890f))[_0xadae('0x1f')](handleError(_0x4f5471,null));};exports['getHopperFinals']=function(_0x11c108,_0x19b273){var _0x4512fe={'raw':!![],'where':{}};var _0x43de0a={};var _0x47d4a2={'count':0x0,'rows':[]};return db[_0xadae('0x20')][_0xadae('0x74')]({'where':{'id':_0x11c108[_0xadae('0x5d')]['id']}})['then'](handleEntityNotFound(_0x19b273,null))['then'](function(_0x3a7162){if(_0x3a7162){_0x43de0a[_0xadae('0x78')]=_['keys'](db[_0xadae('0x44')][_0xadae('0x75')]);_0x43de0a[_0xadae('0x1d')]=_['keys'](_0x11c108['query']);_0x43de0a[_0xadae('0x76')]=_[_0xadae('0x77')](_0x43de0a['model'],_0x43de0a[_0xadae('0x1d')]);_0x4512fe['attributes']=_[_0xadae('0x77')](_0x43de0a[_0xadae('0x78')],qs[_0xadae('0x7a')](_0x11c108[_0xadae('0x1d')][_0xadae('0x7a')]));_0x4512fe[_0xadae('0x79')]=_0x4512fe[_0xadae('0x79')][_0xadae('0x24')]?_0x4512fe['attributes']:_0x43de0a[_0xadae('0x78')];if(!_0x11c108[_0xadae('0x1d')][_0xadae('0x2d')](_0xadae('0x7f'))){_0x4512fe[_0xadae('0x80')]=qs[_0xadae('0x80')](_0x11c108['query'][_0xadae('0x80')]);_0x4512fe[_0xadae('0x10')]=qs[_0xadae('0x10')](_0x11c108['query'][_0xadae('0x10')]);}_0x4512fe[_0xadae('0x7b')]=qs[_0xadae('0x7c')](_0x11c108[_0xadae('0x1d')][_0xadae('0x7c')]);_0x4512fe['where']=qs[_0xadae('0x76')](_[_0xadae('0x7d')](_0x11c108[_0xadae('0x1d')],_0x43de0a[_0xadae('0x76')]));_0x4512fe[_0xadae('0x57')][_0xadae('0x94')]=_0x3a7162['id'];if(_0x11c108[_0xadae('0x1d')][_0xadae('0x7e')]){_0x4512fe[_0xadae('0x57')]=_['merge'](_0x4512fe[_0xadae('0x57')],{'$or':_[_0xadae('0x69')](_0x4512fe[_0xadae('0x79')],function(_0x12d060){var _0x487e6a={};_0x487e6a[_0x12d060]={'$like':'%'+_0x11c108[_0xadae('0x1d')][_0xadae('0x7e')]+'%'};return _0x487e6a;})});}_0x4512fe=_['merge']({},_0x4512fe,_0x11c108[_0xadae('0x95')]);return db['CmHopperFinal'][_0xadae('0x12')]({'where':_0x4512fe[_0xadae('0x57')]})[_0xadae('0x14')](function(_0x1b1782){_0x47d4a2[_0xadae('0x12')]=_0x1b1782;if(_0x11c108['query'][_0xadae('0x99')]){_0x4512fe[_0xadae('0x96')]=[{'all':!![]}];}return db[_0xadae('0x44')][_0xadae('0x28')](_0x4512fe);})[_0xadae('0x14')](function(_0x5f2db0){_0x47d4a2['rows']=_0x5f2db0;return _0x47d4a2;});}})[_0xadae('0x14')](respondWithFilteredResult(_0x19b273,_0x4512fe))[_0xadae('0x1f')](handleError(_0x19b273,null));};exports[_0xadae('0x9a')]=function(_0x1e14a5,_0x1fe72b){var _0x4c5327={'raw':!![],'where':{}};var _0x4c9b21={};var _0x27abf1={'count':0x0,'rows':[]};return db['CmContact'][_0xadae('0x74')]({'where':{'id':_0x1e14a5[_0xadae('0x5d')]['id']}})[_0xadae('0x14')](handleEntityNotFound(_0x1fe72b,null))['then'](function(_0x537666){if(_0x537666){_0x4c9b21[_0xadae('0x78')]=_['keys'](db['JscriptySessionReport']['rawAttributes']);_0x4c9b21[_0xadae('0x1d')]=_['keys'](_0x1e14a5[_0xadae('0x1d')]);_0x4c9b21['filters']=_[_0xadae('0x77')](_0x4c9b21[_0xadae('0x78')],_0x4c9b21['query']);_0x4c5327[_0xadae('0x79')]=_[_0xadae('0x77')](_0x4c9b21['model'],qs[_0xadae('0x7a')](_0x1e14a5[_0xadae('0x1d')][_0xadae('0x7a')]));_0x4c5327['attributes']=_0x4c5327[_0xadae('0x79')]['length']?_0x4c5327[_0xadae('0x79')]:_0x4c9b21['model'];if(!_0x1e14a5['query'][_0xadae('0x2d')](_0xadae('0x7f'))){_0x4c5327[_0xadae('0x80')]=qs[_0xadae('0x80')](_0x1e14a5[_0xadae('0x1d')][_0xadae('0x80')]);_0x4c5327[_0xadae('0x10')]=qs[_0xadae('0x10')](_0x1e14a5[_0xadae('0x1d')][_0xadae('0x10')]);}_0x4c5327[_0xadae('0x7b')]=qs[_0xadae('0x7c')](_0x1e14a5[_0xadae('0x1d')][_0xadae('0x7c')]);_0x4c5327[_0xadae('0x57')]=qs['filters'](_[_0xadae('0x7d')](_0x1e14a5[_0xadae('0x1d')],_0x4c9b21['filters']));_0x4c5327[_0xadae('0x57')]['ContactId']=_0x537666['id'];if(_0x1e14a5[_0xadae('0x1d')]['filter']){_0x4c5327['where']=_[_0xadae('0x2e')](_0x4c5327['where'],{'$or':_[_0xadae('0x69')](_0x4c5327[_0xadae('0x79')],function(_0x438ca1){var _0x4d0b66={};_0x4d0b66[_0x438ca1]={'$like':'%'+_0x1e14a5['query'][_0xadae('0x7e')]+'%'};return _0x4d0b66;})});}_0x4c5327=_[_0xadae('0x2e')]({},_0x4c5327,_0x1e14a5['options']);return db[_0xadae('0x4b')][_0xadae('0x12')]({'where':_0x4c5327[_0xadae('0x57')]})[_0xadae('0x14')](function(_0xf69475){_0x27abf1['count']=_0xf69475;if(_0x1e14a5[_0xadae('0x1d')][_0xadae('0x99')]){_0x4c5327[_0xadae('0x96')]=[{'all':!![]}];}return db[_0xadae('0x4b')]['findAll'](_0x4c5327);})[_0xadae('0x14')](function(_0x137a3d){_0x27abf1[_0xadae('0x98')]=_0x137a3d;return _0x27abf1;});}})[_0xadae('0x14')](respondWithFilteredResult(_0x1fe72b,_0x4c5327))['catch'](handleError(_0x1fe72b,null));};exports['uploadCsv']=function(_0x5378e3,_0x1d9471){try{if(!_0x5378e3[_0xadae('0x2f')][_0xadae('0x59')]){throw new Error(_0xadae('0x9b'));}if(!_0x5378e3[_0xadae('0x2f')][_0xadae('0x9c')]){throw new Error('No\x20association\x20keys\x20specified!');}if(!_0x5378e3['body']['binding_values']){throw new Error(_0xadae('0x9d'));}if(!_0x5378e3[_0xadae('0x2f')][_0xadae('0x9e')]){throw new Error(_0xadae('0x9f'));}var _0x6e78f1=_0x5378e3[_0xadae('0x2f')]['binding_keys']['split'](',');var _0x396fed=_0x5378e3['body'][_0xadae('0xa0')]['split'](',');if(!_0x6e78f1[_0xadae('0x24')]||!_0x396fed[_0xadae('0x24')]||_0x6e78f1[_0xadae('0x24')]!==_0x396fed['length']){throw new Error(_0xadae('0xa1'));}_0x5378e3[_0xadae('0x2f')][_0xadae('0x7a')]=_[_0xadae('0xa2')](_0x6e78f1,_0x396fed);if(!_0x5378e3[_0xadae('0x2f')]['fields'][_0xadae('0x8d')]){throw new Error(_0xadae('0xa3'));}if(!_0x5378e3[_0xadae('0x2f')][_0xadae('0x7a')][_0xadae('0xa4')]){throw new Error(_0xadae('0xa5'));}var _0x15114e=path[_0xadae('0x4e')](config[_0xadae('0xa6')],_0xadae('0xa7'),_0x5378e3[_0xadae('0xa8')][_0xadae('0xa9')]);fs[_0xadae('0xaa')](_0x15114e,parseInt(_0xadae('0xab'),0x8));var _0x4104f3=require('child_process')[_0xadae('0xac')](path[_0xadae('0x4e')](__dirname,_0xadae('0xad')),[_0x15114e,_0x5378e3['body'][_0xadae('0x9c')],_0x5378e3[_0xadae('0x2f')][_0xadae('0xa0')],_0x5378e3[_0xadae('0x2f')][_0xadae('0x59')],_0x5378e3['body'][_0xadae('0xae')],_0x5378e3[_0xadae('0x2f')][_0xadae('0x56')],_0x5378e3['body']['socket_timestamp']]);return _0x1d9471[_0xadae('0xe')](0xc8)['json']({'message':_0xadae('0xaf'),'pid':_0x4104f3[_0xadae('0xb0')]});}catch(_0x1e442f){return _0x1d9471[_0xadae('0xe')](0x1f4)['send'](_0x1e442f);}};exports[_0xadae('0xb1')]=function(_0xfa0f,_0x53711c){var _0xd17f4b=fs[_0xadae('0xb2')](_0xfa0f['file'][_0xadae('0x1')]);Papa['parse'](_0xd17f4b,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x1c8277){return _0x53711c[_0xadae('0xe')](0xc8)['json']({'file':_0xfa0f[_0xadae('0xa8')],'fields':_0x1c8277[_0xadae('0xb3')]['fields']});}});};exports['import']=function(_0x46df16,_0x374ef2){return db[_0xadae('0xb4')]['findAll']({'raw':!![],'attributes':['id'],'where':{'role':_0xadae('0xb5')}})[_0xadae('0x14')](function(_0x472756){var _0x3acee7=![];if(!_0x46df16[_0xadae('0x2f')][_0xadae('0x59')]){throw new Error(_0xadae('0x9b'));}if(!_0x46df16[_0xadae('0x2f')][_0xadae('0xb6')][_0xadae('0x8d')]){throw new Error(_0xadae('0xa3'));}if(!_0x46df16[_0xadae('0x2f')]['binding'][_0xadae('0xa4')]){throw new Error(_0xadae('0xa5'));}if(!_0x46df16[_0xadae('0x2f')][_0xadae('0x9e')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x482197=require(_0xadae('0xb7'))[_0xadae('0xac')](path['join'](__dirname,_0xadae('0xb8')),[_0x46df16[_0xadae('0x5d')]['id'],JSON[_0xadae('0xb9')](_0x46df16[_0xadae('0x2f')]),JSON[_0xadae('0xb9')](_0x472756)]);_0x482197['on'](_0xadae('0xba'),function(){_0x3acee7=!![];return _0x374ef2[_0xadae('0xe')](0xc8)['json']({'message':'start\x20child\x20process\x20correctly!','pid':_0x482197[_0xadae('0xb0')]});});_0x482197['on']('exit',function(_0x481fd9){if(_0x481fd9&&!_0x3acee7){return _0x374ef2[_0xadae('0xe')](0x1f4)[_0xadae('0xf')]({'message':_0xadae('0xbb'),'pid':_0x482197[_0xadae('0xb0')]});}});})['catch'](handleError(_0x374ef2,null));};exports['importUpdates']=function(_0x3e5539,_0x487fd9){return db[_0xadae('0xb4')][_0xadae('0x28')]({'raw':!![],'attributes':['id'],'where':{'role':_0xadae('0xb5')}})[_0xadae('0x14')](function(_0x341425){var _0x1b298f=![];if(!_0x3e5539[_0xadae('0x2f')][_0xadae('0x59')]){throw new Error(_0xadae('0x9b'));}if(!_0x3e5539[_0xadae('0x2f')]['binding']['phone']){throw new Error(_0xadae('0xa3'));}if(!_0x3e5539[_0xadae('0x2f')][_0xadae('0xb6')][_0xadae('0xa4')]){throw new Error(_0xadae('0xa5'));}if(!_0x3e5539['body'][_0xadae('0x9e')]){throw new Error(_0xadae('0x9f'));}var _0x33d6fa=require(_0xadae('0xb7'))[_0xadae('0xac')](path[_0xadae('0x4e')](__dirname,_0xadae('0xbc')),[_0x3e5539['params']['id'],JSON[_0xadae('0xb9')](_0x3e5539[_0xadae('0x2f')]),JSON[_0xadae('0xb9')](_0x341425)]);_0x33d6fa['on']('message',function(){_0x1b298f=!![];return _0x487fd9[_0xadae('0xe')](0xc8)[_0xadae('0xf')]({'message':_0xadae('0xbd'),'pid':_0x33d6fa[_0xadae('0xb0')]});});_0x33d6fa['on']('exit',function(_0x4f5e41){if(_0x4f5e41&&!_0x1b298f){return _0x487fd9['status'](0x1f4)[_0xadae('0xf')]({'message':'error\x20child\x20process','pid':_0x33d6fa['pid']});}});})['catch'](handleError(_0x487fd9,null));};exports[_0xadae('0xbe')]=function(_0x2ff949,_0x72e61f){var _0x49ca62=[_0xadae('0xbf'),_0xadae('0xc0'),_0xadae('0xc1'),_0xadae('0xc2'),_0xadae('0xc3'),_0xadae('0xc4'),'voice'];var _0x1fbfcb={'offset':0x0,'order':qs['sort'](_0xadae('0xc5'))},_0x786280={'count':0x0,'rows':[]};Promise['resolve']()[_0xadae('0x14')](function(){if(_0x2ff949['query'][_0xadae('0xc6')]){if(!_[_0xadae('0xc7')](_0x49ca62,_0x2ff949[_0xadae('0x1d')][_0xadae('0xc6')][_0xadae('0xc8')]())){throw new Error(_0xadae('0xc9'));}_0x49ca62=[_0x2ff949[_0xadae('0x1d')]['channel'][_0xadae('0xc8')]()];}if(_0x2ff949[_0xadae('0x1d')][_0xadae('0xca')]){try{var _0x579033=JSON[_0xadae('0xcb')](_0x2ff949[_0xadae('0x1d')][_0xadae('0xca')]);if(!moment(_0x579033['from'])[_0xadae('0xcc')]()){throw new Error(_0xadae('0xcd'));}if(!moment(_0x579033['to'])[_0xadae('0xcc')]()){throw new Error(_0xadae('0xce'));}}catch(_0x4593a9){throw new Error(_0xadae('0xcf'));}}if(!_0x2ff949[_0xadae('0x1d')][_0xadae('0x2d')](_0xadae('0x7f'))){_0x1fbfcb[_0xadae('0x80')]=qs[_0xadae('0x80')](_0x2ff949['query'][_0xadae('0x80')]||0xa);_0x1fbfcb['offset']=qs[_0xadae('0x10')](_0x2ff949[_0xadae('0x1d')][_0xadae('0x10')]);}var _0x2713cb=_0x49ca62[_0xadae('0x69')](function(_0x3a8251){if(_0x3a8251===_0xadae('0xd0')){var _0x4f103f={'attributes':['id',_0xadae('0xd1'),_0xadae('0x2b'),_0xadae('0xd2'),_0xadae('0xd3'),_0xadae('0xd4'),'starttime',_0xadae('0xd5'),'duration',_0xadae('0xd6'),'createdAt',_0xadae('0xd7'),_0xadae('0xd8'),'userThirdDisposition',_0xadae('0xd9')],'where':{'ContactId':_0x2ff949[_0xadae('0x5d')]['id']},'include':[{'model':db[_0xadae('0xb4')],'as':_0xadae('0xb4'),'attributes':['id',_0xadae('0x19'),_0xadae('0xda'),'alias']}],'order':[['createdAt',_0xadae('0xdb')]]};if(_0x2ff949[_0xadae('0x1d')][_0xadae('0xca')]){_0x4f103f[_0xadae('0x57')][_0xadae('0xdc')]={'$gte':_0x579033[_0xadae('0x30')],'$lte':_0x579033['to']};}return db[_0xadae('0x46')][_0xadae('0xdd')](_0x4f103f)[_0xadae('0x14')](function(_0x191e71){_0x786280[_0xadae('0x12')]+=_0x191e71[_0xadae('0x12')];return _[_0xadae('0x69')](_0x191e71['rows'],function(_0x12a92c){var _0x536ef9=_0x12a92c[_0xadae('0x31')]({'plain':!![]});_0x536ef9[_0xadae('0xc6')]=_0x3a8251;if(_0x536ef9[_0xadae('0xb4')]){_0x536ef9[_0xadae('0xb4')]={'id':_0x536ef9[_0xadae('0xb4')]['id'],'name':_0x536ef9['User'][_0xadae('0x19')],'fullname':_0x536ef9[_0xadae('0xb4')][_0xadae('0xda')],'alias':_0x536ef9[_0xadae('0xb4')][_0xadae('0x2a')]};}return _0x536ef9;});});}else{var _0x1620e1=_[_0xadae('0xde')](_0x3a8251)+(_0x3a8251===_0xadae('0xc0')?_0xadae('0xdf'):_0xadae('0xe0'));var _0x401d10={'attributes':['id',_0xadae('0xe1'),_0xadae('0xe2'),_0xadae('0xdc'),_0xadae('0xd6'),_0xadae('0xe3'),_0xadae('0xe4'),_0xadae('0xe5'),'UserId',_0x1620e1+'Id'],'where':{'ContactId':_0x2ff949[_0xadae('0x5d')]['id']},'include':[{'model':db[_0x1620e1],'as':'Account','attributes':['id',_0xadae('0x19'),_0xadae('0xe6')]},{'model':db[_0xadae('0xb4')],'as':'Owner','attributes':['id',_0xadae('0x19'),_0xadae('0xda')]},{'model':db[_0xadae('0x5e')],'as':_0xadae('0x5f'),'attributes':['id','name',_0xadae('0x60')],'through':{'attributes':[]}}],'order':[['createdAt',_0xadae('0xdb')]]};if(_0x2ff949[_0xadae('0x1d')]['range']){_0x401d10[_0xadae('0x57')][_0xadae('0xdc')]={'$gte':_0x579033[_0xadae('0x30')],'$lte':_0x579033['to']};}switch(_0x3a8251){case _0xadae('0xc0'):_0x401d10[_0xadae('0x79')][_0xadae('0x58')]('browserName','customerIp','customerPort',_0xadae('0xe7'),_0xadae('0xe8'),_0xadae('0xe9'),_0xadae('0xea'),'ratingValue',_0xadae('0xeb'));break;case _0xadae('0xbf'):_0x401d10[_0xadae('0x79')][_0xadae('0x58')](_0xadae('0xec'),'substatus');break;case _0xadae('0xc2'):_0x401d10[_0xadae('0x79')][_0xadae('0x58')](_0xadae('0xed'),_0xadae('0xee'));break;}return db[_[_0xadae('0xde')](_0x3a8251)+_0xadae('0xef')][_0xadae('0xdd')](_0x401d10)[_0xadae('0x14')](function(_0x24b116){_0x786280[_0xadae('0x12')]+=_0x24b116[_0xadae('0x12')];return _['map'](_0x24b116[_0xadae('0x98')],function(_0x81826d){var _0x197d28=_0x81826d['get']({'plain':!![]});_0x197d28['channel']=_0x3a8251;if(_0x197d28[_0xadae('0xf0')]){_0x197d28[_0xadae('0xf0')]={'id':_0x197d28[_0xadae('0xf0')]['id'],'name':_0x197d28[_0xadae('0xf0')][_0xadae('0x19')],'fullname':_0x197d28[_0xadae('0xf0')]['fullname']};}return _0x197d28;});});}});return Promise[_0xadae('0x5c')](_0x2713cb);})['then'](function(_0x1c7603){return _(_0x1c7603)[_0xadae('0xf1')]()[_0xadae('0xf2')](_0xadae('0xdc'))[_0xadae('0xf3')]()[_0xadae('0xf4')]();})[_0xadae('0x14')](function(_0x40ecbf){_0x786280[_0xadae('0x98')]=_0x1fbfcb['limit']?_0x40ecbf[_0xadae('0xf5')](_0x1fbfcb[_0xadae('0x10')],_0x1fbfcb[_0xadae('0x10')]+_0x1fbfcb[_0xadae('0x80')]):_0x40ecbf;return _0x786280;})[_0xadae('0x14')](respondWithFilteredResult(_0x72e61f,_0x1fbfcb))[_0xadae('0x1f')](handleError(_0x72e61f,null));};
\ No newline at end of file