Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / cmContact / cmContact.controller.js
index abbc185..aa13b2d 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 _0x7557=['item_types','ItemTypeId','description','OrderBy','contact\x20phone\x20exists','PHONE','item','ItemType','`ItemType`.OrderBy','ItemType.OrderBy','getAdditionalPhones','duplicateAdditionalPhones','CmContactId','toContactId','rescheduleAdditionalPhones','hopperId','intersection','nolimit','pick','ContactId','includeAll','include','rows','getHopperHistories','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','split','Incorrect\x20binding\x20parameters\x20passed!','zipObject','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','file','filename','chmodSync','0777','child_process','CompanyId','upload','createReadStream','meta','import','agent','binding','fork','../../components/import/cm/csv2','stringify','start\x20child\x20process\x20correctly!','pid','exit','error\x20child\x20process','importUpdates','User','message','getJourney','mail','chat','sms','fax','whatsapp','voice','-createdAt','resolve','includes','channel','Invalid\x20channel','toLowerCase','range','parse','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20createdAt\x20filter','source','destination','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','UserId','fullname','DESC','findAndCountAll','alias','startCase','Website','Account','closed','disposition','secondDisposition','Owner','browserName','customerIp','customerPort','deviceModel','osName','ratingMessage','ratingType','ratingValue','referer','subject','substatus','Interaction','sortBy','reverse','slice','moment','bluebird','util','squel','papaparse','ioredis','../../components/contacts','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','defaults','localhost','redis','./cmContact.socket','register','json','undefined','limit','count','offset','status','set','Content-Range','update','then','destroy','end','error','stack','name','send','index','describe','getOptions','findAll','user','catch','CmContact','find','params','tags','keys','startsWith','cf_','columnName','displayName','query','analytics','CmCustomField','type','values','info','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','forEach','hasOwnProperty','merge','body','from','get','mergeWith','length','isArray','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperFinal','CmHopperHistory','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappInteraction','create','join','isNil','dialTimezone','timezones','utcOffset','additionalPhones','bulkCreate','each','duplicates','$or','push','where','ListId','findOrCreate','spread','all','show','Tag','Tags','color','tag','Phones','ContactItemType','sequelize','literal','$and','omit','map','format','cf_%d','pickBy','isEmpty','table','cm_contacts','setFields','toParam','text','phone','getTags','findOne','model','rawAttributes','filters','fields','attributes','order','sort','filter','options','setTags','ids','items'];(function(_0x3b991c,_0x36b129){var _0x52a642=function(_0x59b627){while(--_0x59b627){_0x3b991c['push'](_0x3b991c['shift']());}};_0x52a642(++_0x36b129);}(_0x7557,0x74));var _0x7755=function(_0x2e4c2e,_0x1df99e){_0x2e4c2e=_0x2e4c2e-0x0;var _0xf5d858=_0x7557[_0x2e4c2e];return _0xf5d858;};'use strict';var moment=require(_0x7755('0x0'));var BPromise=require(_0x7755('0x1'));var util=require(_0x7755('0x2'));var path=require('path');var fs=require('fs');var _=require('lodash');var squel=require(_0x7755('0x3'));var Papa=require(_0x7755('0x4'));var Redis=require(_0x7755('0x5'));var contacts=require(_0x7755('0x6'));var qs=require(_0x7755('0x7'));var logger=require(_0x7755('0x8'))(_0x7755('0x9'));var config=require(_0x7755('0xa'));var shared=require('../../config/environment/shared');var db=require(_0x7755('0xb'))['db'];config['redis']=_[_0x7755('0xc')](config['redis'],{'host':_0x7755('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x7755('0xe')]));require(_0x7755('0xf'))[_0x7755('0x10')](socket);function respondWithResult(_0x4dcda4,_0x473789){_0x473789=_0x473789||0xc8;return function(_0x554ae4){if(_0x554ae4){return _0x4dcda4['status'](_0x473789)[_0x7755('0x11')](_0x554ae4);}};}function respondWithFilteredResult(_0x27742a,_0x50e450){return function(_0x17dcfc){if(_0x17dcfc){var _0x17f765=typeof _0x50e450['offset']===_0x7755('0x12')&&typeof _0x50e450[_0x7755('0x13')]===_0x7755('0x12');var _0x414da7=_0x17dcfc[_0x7755('0x14')];var _0x27e0a8=_0x17f765?0x0:_0x50e450[_0x7755('0x15')];var _0x53aea1=_0x17f765?_0x17dcfc[_0x7755('0x14')]:_0x50e450[_0x7755('0x15')]+_0x50e450['limit'];var _0x476e08;if(_0x53aea1>=_0x414da7){_0x53aea1=_0x414da7;_0x476e08=0xc8;}else{_0x476e08=0xce;}_0x27742a[_0x7755('0x16')](_0x476e08);return _0x27742a[_0x7755('0x17')](_0x7755('0x18'),_0x27e0a8+'-'+_0x53aea1+'/'+_0x414da7)[_0x7755('0x11')](_0x17dcfc);}return null;};}function saveUpdates(_0x26bc32){return function(_0x23436a){if(_0x23436a){return _0x23436a[_0x7755('0x19')](_0x26bc32)[_0x7755('0x1a')](function(_0x12684f){return _0x12684f;});}return null;};}function removeEntity(_0x36dbe5){return function(_0x24eaf8){if(_0x24eaf8){return _0x24eaf8[_0x7755('0x1b')]()[_0x7755('0x1a')](function(){_0x36dbe5[_0x7755('0x16')](0xcc)[_0x7755('0x1c')]();});}};}function handleEntityNotFound(_0x259483){return function(_0x1d3708){if(!_0x1d3708){_0x259483['sendStatus'](0x194);}return _0x1d3708;};}function handleError(_0x4925b8,_0x4cbc3c){_0x4cbc3c=_0x4cbc3c||0x1f4;return function(_0x1c2959){logger[_0x7755('0x1d')](_0x1c2959[_0x7755('0x1e')]);if(_0x1c2959[_0x7755('0x1f')]){delete _0x1c2959[_0x7755('0x1f')];}_0x4925b8[_0x7755('0x16')](_0x4cbc3c)[_0x7755('0x20')](_0x1c2959);};}exports[_0x7755('0x21')]=function(_0x44a34c,_0x2f4eef){var _0x556631={};return contacts[_0x7755('0x22')]()[_0x7755('0x1a')](function(_0x55fbe1){_0x556631=qs[_0x7755('0x23')](_0x55fbe1,_0x44a34c);return contacts[_0x7755('0x24')](_0x44a34c['query'],_0x44a34c[_0x7755('0x25')],_0x556631,_0x55fbe1);})['then'](respondWithFilteredResult(_0x2f4eef,_0x556631))[_0x7755('0x26')](handleError(_0x2f4eef,null));};exports[_0x7755('0x1b')]=function(_0x2fa23c,_0x29400d){return db[_0x7755('0x27')][_0x7755('0x28')]({'where':{'id':_0x2fa23c[_0x7755('0x29')]['id']}})['then'](handleEntityNotFound(_0x29400d,null))[_0x7755('0x1a')](removeEntity(_0x29400d,null))[_0x7755('0x26')](handleError(_0x29400d,null));};exports[_0x7755('0x22')]=function(_0x54e66e,_0x2713b4){return db[_0x7755('0x27')][_0x7755('0x22')]()[_0x7755('0x1a')](function(_0xbf9735){delete _0xbf9735[_0x7755('0x2a')];for(var _0x339697=0x0;_0x339697<Object['keys'](_0xbf9735)['length'];_0x339697++){var _0x33b56e=Object[_0x7755('0x2b')](_0xbf9735)[_0x339697];if(!_[_0x7755('0x2c')](_0x33b56e,_0x7755('0x2d'))){_0xbf9735[_0x33b56e][_0x7755('0x2e')]=_0x33b56e;_0xbf9735[_0x33b56e][_0x7755('0x2f')]=_0x33b56e;}}return _0xbf9735;})[_0x7755('0x1a')](function(_0x5a77e0){var _0x147706={'where':Boolean(_0x54e66e[_0x7755('0x30')][_0x7755('0x31')])===!![]?undefined:{'$or':[{'ListId':_0x54e66e[_0x7755('0x30')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x7755('0x32')][_0x7755('0x24')](_0x147706)[_0x7755('0x1a')](function(_0x5a3dd8){for(var _0x3a37f5=0x0;_0x3a37f5<_0x5a3dd8['length'];_0x3a37f5++){var _0x162c60=_0x7755('0x2d')+_0x5a3dd8[_0x3a37f5]['id'];if(_0x5a77e0[_0x162c60]){_0x5a77e0[_0x162c60][_0x7755('0x2e')]=_0x162c60;_0x5a77e0[_0x162c60][_0x7755('0x2f')]=_0x5a3dd8[_0x3a37f5]['alias'];_0x5a77e0[_0x162c60]['custom']={'type':_0x5a3dd8[_0x3a37f5][_0x7755('0x33')],'values':_0x5a3dd8[_0x3a37f5][_0x7755('0x34')]};}else{logger[_0x7755('0x35')](_0x7755('0x36'),_0x162c60);}}Object[_0x7755('0x2b')](_0x5a77e0)[_0x7755('0x37')](function(_0x9c15d4){if(!_0x5a77e0[_0x9c15d4][_0x7755('0x38')](_0x7755('0x2e'))){delete _0x5a77e0[_0x9c15d4];}});return _0x5a77e0;});})['then'](respondWithResult(_0x2713b4,null))[_0x7755('0x26')](handleError(_0x2713b4,null));};exports[_0x7755('0x39')]=function(_0x36d093,_0x36a679){var _0xb6c7c2;var _0x1ec0c9;var _0x3a4d99;if(_0x36d093['body']['id']){delete _0x36d093[_0x7755('0x3a')]['id'];}return db[_0x7755('0x27')]['findAll']({'where':{'id':[_0x36d093[_0x7755('0x3a')]['to'],_0x36d093[_0x7755('0x3a')][_0x7755('0x3b')]]}})['then'](function(_0x59c7c5){if(_0x59c7c5){if(_0x59c7c5['length']!==0x2){return null;}_0x59c7c5[0x0]=_0x59c7c5[0x0][_0x7755('0x3c')]({'plain':!![]});_0x59c7c5[0x1]=_0x59c7c5[0x1][_0x7755('0x3c')]({'plain':!![]});delete _0x59c7c5[0x0]['id'];delete _0x59c7c5[0x1]['id'];return _[_0x7755('0x3d')](_0x59c7c5[0x0],_0x59c7c5[0x1],function(_0x4786fe,_0x4c39cd){if(Array['isArray'](_0x4c39cd)&&!_0x4c39cd[_0x7755('0x3e')]){return _0x4786fe;}else if(!_0x4c39cd){return _0x4786fe;}});}})[_0x7755('0x1a')](handleEntityNotFound(_0x36a679,null))[_0x7755('0x1a')](function(_0x1d7268){if(_0x1d7268){if(_0x1d7268[_0x7755('0x2a')]&&_[_0x7755('0x3f')](_0x1d7268[_0x7755('0x2a')])){_0x1d7268[_0x7755('0x2a')]=_0x1d7268['tags']['join']();}logger['info'](_0x7755('0x40'),_0x36d093['body']['to'],_0x36d093[_0x7755('0x3a')]['from']);return db[_0x7755('0x41')]['destroy']({'where':{'ContactId':[_0x36d093[_0x7755('0x3a')]['to'],_0x36d093[_0x7755('0x3a')][_0x7755('0x3b')]]}})[_0x7755('0x1a')](function(_0xff29ea){logger[_0x7755('0x35')](_0x7755('0x42'),_0xff29ea);return db[_0x7755('0x43')][_0x7755('0x1b')]({'where':{'ContactId':[_0x36d093[_0x7755('0x3a')]['to'],_0x36d093['body'][_0x7755('0x3b')]]}})[_0x7755('0x1a')](function(_0x5096d3){logger['info'](_0x7755('0x44'),_0x5096d3);return db[_0x7755('0x27')]['create'](_0x1d7268);});});}})['then'](function(_0x419d74){if(_0x419d74){_0xb6c7c2=_0x419d74;_0x1ec0c9={'ContactId':_0xb6c7c2['id']};_0x3a4d99={'where':{'ContactId':[_0x36d093['body']['to'],_0x36d093['body'][_0x7755('0x3b')]]}};return db[_0x7755('0x45')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x46')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db[_0x7755('0x47')]['update'](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x48')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db[_0x7755('0x49')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x48')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x49')]['update'](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x4a')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x4b')]['update'](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db['FaxInteraction'][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db['FaxMessage'][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x4c')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db[_0x7755('0x4d')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x4e')][_0x7755('0x19')]({'CmContactId':_0xb6c7c2['id']},{'where':{'CmContactId':[_0x36d093[_0x7755('0x3a')]['to'],_0x36d093[_0x7755('0x3a')][_0x7755('0x3b')]]}});}})['then'](function(){if(_0xb6c7c2){return db[_0x7755('0x4f')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x50')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db['ReportAgentPreview']['update'](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x51')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x52')]['update'](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x53')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x54')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x55')]['update'](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x56')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db[_0x7755('0x57')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db[_0x7755('0x58')][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return db['WhatsappMessage']['update'](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db['WhatsappQueueReport'][_0x7755('0x19')](_0x1ec0c9,_0x3a4d99);}})['then'](function(){if(_0xb6c7c2){return db['CmContact'][_0x7755('0x1b')]({'where':{'id':[_0x36d093[_0x7755('0x3a')]['to'],_0x36d093[_0x7755('0x3a')][_0x7755('0x3b')]]}});}})[_0x7755('0x1a')](function(){if(_0xb6c7c2){return _0xb6c7c2;}})[_0x7755('0x1a')](respondWithResult(_0x36a679,null))[_0x7755('0x26')](handleError(_0x36a679,null));};exports[_0x7755('0x59')]=function(_0x22237e,_0x168879){return db[_0x7755('0x27')][_0x7755('0x22')]()['then'](function(_0x3810b3){if(_0x22237e[_0x7755('0x3a')][_0x7755('0x2a')]&&_[_0x7755('0x3f')](_0x22237e[_0x7755('0x3a')]['tags'])){if(_0x22237e['body'][_0x7755('0x2a')]['length']){_0x22237e['body'][_0x7755('0x2a')]=_0x22237e[_0x7755('0x3a')][_0x7755('0x2a')][_0x7755('0x5a')](';')+';';}else{_0x22237e['body'][_0x7755('0x2a')]=null;}}else{_0x22237e['body'][_0x7755('0x2a')]=null;}if(!_[_0x7755('0x5b')](_0x22237e[_0x7755('0x3a')][_0x7755('0x5c')])){var _0x3c307f=_0x22237e[_0x7755('0x3a')][_0x7755('0x5c')];if(!_[_0x7755('0x5b')](shared[_0x7755('0x5d')][_0x3c307f]))_0x22237e[_0x7755('0x3a')][_0x7755('0x5e')]=shared[_0x7755('0x5d')][_0x3c307f]['utcOffset'];}return db[_0x7755('0x27')][_0x7755('0x59')](_0x22237e['body'],{'fields':_[_0x7755('0x2b')](_0x3810b3),'raw':!![]});})['then'](function(_0x1555bb){if(_0x22237e[_0x7755('0x3a')][_0x7755('0x5f')]){return insertAdditionalPhones(_0x1555bb,_0x22237e[_0x7755('0x3a')][_0x7755('0x5f')]);}else{return _0x1555bb;}})[_0x7755('0x1a')](respondWithResult(_0x168879,0xc9))[_0x7755('0x26')](handleError(_0x168879,null));};exports[_0x7755('0x60')]=function(_0x184ce1,_0x4ea5c8){var _0x590ea9=0x0;var _0x316130=0x0;var _0x1f31c4=0x0;var _0x5afc44=[];return db[_0x7755('0x27')][_0x7755('0x22')]()[_0x7755('0x1a')](function(_0x23248d){return BPromise[_0x7755('0x61')](_0x184ce1[_0x7755('0x3a')],function(_0x5ba33c){var _0x3e7c70={'where':{'$or':[]},'defaults':_0x5ba33c,'fields':_[_0x7755('0x2b')](_0x23248d),'raw':!![]};if(_0x5ba33c[_0x7755('0x62')]){for(var _0x1190eb=0x0;_0x1190eb<_0x5ba33c[_0x7755('0x62')][_0x7755('0x3e')];_0x1190eb++){var _0x30b3a2={};_0x30b3a2[_0x5ba33c[_0x7755('0x62')][_0x1190eb]]=_0x5ba33c[_0x5ba33c[_0x7755('0x62')][_0x1190eb]];_0x3e7c70['where'][_0x7755('0x63')][_0x7755('0x64')](_0x30b3a2);}_0x3e7c70[_0x7755('0x65')][_0x7755('0x66')]=_0x5ba33c[_0x7755('0x66')];}return db[_0x7755('0x27')][_0x7755('0x67')](_0x3e7c70)[_0x7755('0x68')](function(_0x35fb9d,_0x21bd98){if(_0x21bd98){if(_0x5ba33c[_0x7755('0x38')](_0x7755('0x5f'))){_0x5afc44[_0x7755('0x64')]({'contact':_0x35fb9d,'additionalPhones':_0x5ba33c[_0x7755('0x5f')]});}_0x590ea9++;}else{_0x1f31c4++;}})['catch'](function(){_0x316130++;});});})[_0x7755('0x1a')](function(_0x5e8591){if(_0x5e8591){if(_0x5afc44[_0x7755('0x3e')]>0x0){return new Promise(function(_0x21bf9f){var _0x3fcffa=[];for(var _0x6c950c=0x0;_0x6c950c<_0x5afc44[_0x7755('0x3e')];_0x6c950c++){_0x3fcffa[_0x7755('0x64')](insertAdditionalPhones(_0x5afc44[_0x6c950c]['contact'],_0x5afc44[_0x6c950c]['additionalPhones']));}Promise[_0x7755('0x69')](_0x3fcffa)['then'](function(){_0x21bf9f(0x1);});})[_0x7755('0x1a')](function(){return{'success':_0x590ea9,'failure':_0x316130,'duplicates':_0x1f31c4};});}else{return{'success':_0x590ea9,'failure':_0x316130,'duplicates':_0x1f31c4};}}})['then'](respondWithResult(_0x4ea5c8,0xc9))[_0x7755('0x26')](handleError(_0x4ea5c8,null));};exports[_0x7755('0x6a')]=function(_0x10cd57,_0x30c1fc){var _0xf3d204;return db[_0x7755('0x27')][_0x7755('0x22')]()[_0x7755('0x1a')](function(_0x3fd951){return db[_0x7755('0x27')]['find']({'where':{'id':_0x10cd57[_0x7755('0x29')]['id']},'include':[{'model':db[_0x7755('0x6b')],'as':_0x7755('0x6c'),'attributes':['id','name',_0x7755('0x6d')],'required':_0x10cd57['query'][_0x7755('0x6e')]?!![]:![]},{'model':db[_0x7755('0x4e')],'as':_0x7755('0x6f'),'where':{'CmContactId':_0x10cd57[_0x7755('0x29')]['id']},'required':![],'include':[{'model':db[_0x7755('0x70')],'as':'ItemType'}]}],'order':[db[_0x7755('0x71')][_0x7755('0x72')]('Phones.OrderBy')],'attributes':_[_0x7755('0x2b')](_0x3fd951)});})[_0x7755('0x1a')](function(_0x302345){if(!_[_0x7755('0x5b')](_0x302345)){_0xf3d204=_0x302345[_0x7755('0x3c')]({'plain':!![]});var _0x265afd={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x302345&&_0x302345['ListId']){if(_0x302345[_0x7755('0x66')]){_0x265afd[_0x7755('0x65')][_0x7755('0x73')]['push']({'ListId':{'$ne':_0x302345[_0x7755('0x66')]}});}}return db['CmCustomField']['findAll'](_0x265afd);}})[_0x7755('0x1a')](function(_0x4b38ca){if(!_[_0x7755('0x5b')](_0x4b38ca)){return _[_0x7755('0x74')](_0xf3d204,_[_0x7755('0x75')](_0x4b38ca,function(_0x1f037a){return util[_0x7755('0x76')](_0x7755('0x77'),_0x1f037a['id']);}));}})[_0x7755('0x1a')](handleEntityNotFound(_0x30c1fc,null))['then'](respondWithResult(_0x30c1fc,null))[_0x7755('0x26')](handleError(_0x30c1fc,null));};exports[_0x7755('0x19')]=function(_0x10e753,_0x4abbb8){var _0x1f6d90;if(_0x10e753[_0x7755('0x3a')]['id']){delete _0x10e753[_0x7755('0x3a')]['id'];}if(!_[_0x7755('0x5b')](_0x10e753['body'][_0x7755('0x5c')])){var _0x7b6b06=_0x10e753['body'][_0x7755('0x5c')];if(!_[_0x7755('0x5b')](shared[_0x7755('0x5d')][_0x7b6b06]))_0x10e753[_0x7755('0x3a')][_0x7755('0x5e')]=shared[_0x7755('0x5d')][_0x7b6b06][_0x7755('0x5e')];}return db['CmContact'][_0x7755('0x28')]({'where':{'id':_0x10e753['params']['id']}})[_0x7755('0x1a')](handleEntityNotFound(_0x4abbb8,null))[_0x7755('0x1a')](saveUpdates(_0x10e753[_0x7755('0x3a')],null))[_0x7755('0x1a')](function(_0x49aaa){_0x1f6d90=_0x49aaa;var _0xbfd76={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x49aaa&&_0x49aaa[_0x7755('0x66')]){if(_0x49aaa[_0x7755('0x66')]){_0xbfd76[_0x7755('0x65')]['$and'][_0x7755('0x64')]({'ListId':{'$ne':_0x49aaa[_0x7755('0x66')]}});}}return db[_0x7755('0x32')][_0x7755('0x24')](_0xbfd76);})['then'](function(_0x1c91e7){if(_0x1c91e7){return _[_0x7755('0x74')](_[_0x7755('0x78')](_0x10e753[_0x7755('0x3a')],function(_0xb57851,_0x1681b7){return _[_0x7755('0x2c')](_0x1681b7,_0x7755('0x2d'));}),_['map'](_0x1c91e7,function(_0x4d3c03){return util[_0x7755('0x76')]('cf_%d',_0x4d3c03['id']);}));}})[_0x7755('0x1a')](function(_0x49d5fb){if(_0x49d5fb&&!_[_0x7755('0x79')](_0x49d5fb)){var _0x142a0f=squel[_0x7755('0x19')]()[_0x7755('0x7a')](_0x7755('0x7b'))[_0x7755('0x7c')](_0x49d5fb)[_0x7755('0x65')]('id\x20=\x20?',_0x10e753[_0x7755('0x29')]['id'])[_0x7755('0x7d')]();return db[_0x7755('0x71')][_0x7755('0x30')](_0x142a0f[_0x7755('0x7e')],{'replacements':_0x142a0f[_0x7755('0x34')]});}})['then'](function(){if(_0x10e753[_0x7755('0x3a')]['phone']&&_0x1f6d90){return db[_0x7755('0x41')][_0x7755('0x19')]({'phone':_0x10e753[_0x7755('0x3a')][_0x7755('0x7f')],'OrderBy':0x0},{'where':{'ContactId':_0x1f6d90['id']}});}})[_0x7755('0x1a')](function(){return _0x1f6d90;})['then'](respondWithResult(_0x4abbb8,null))[_0x7755('0x26')](handleError(_0x4abbb8,null));};exports[_0x7755('0x80')]=function(_0x6adfd4,_0x161e80){var _0x204635={};var _0x45b684={};var _0x1aa4ef;var _0x44f30d;return db[_0x7755('0x27')][_0x7755('0x81')]({'where':{'id':_0x6adfd4[_0x7755('0x29')]['id']}})[_0x7755('0x1a')](handleEntityNotFound(_0x161e80,null))['then'](function(_0x3ad569){if(_0x3ad569){_0x1aa4ef=_0x3ad569;_0x45b684[_0x7755('0x82')]=_[_0x7755('0x2b')](db[_0x7755('0x6b')][_0x7755('0x83')]);_0x45b684[_0x7755('0x30')]=_[_0x7755('0x2b')](_0x6adfd4['query']);_0x45b684[_0x7755('0x84')]=_['intersection'](_0x45b684['model'],_0x45b684['query']);_0x204635['attributes']=_['intersection'](_0x45b684['model'],qs[_0x7755('0x85')](_0x6adfd4[_0x7755('0x30')][_0x7755('0x85')]));_0x204635[_0x7755('0x86')]=_0x204635[_0x7755('0x86')][_0x7755('0x3e')]?_0x204635[_0x7755('0x86')]:_0x45b684[_0x7755('0x82')];_0x204635[_0x7755('0x87')]=qs[_0x7755('0x88')](_0x6adfd4['query']['sort']);_0x204635[_0x7755('0x65')]=qs[_0x7755('0x84')](_['pick'](_0x6adfd4['query'],_0x45b684['filters']));if(_0x6adfd4[_0x7755('0x30')][_0x7755('0x89')]){_0x204635[_0x7755('0x65')]=_[_0x7755('0x39')](_0x204635['where'],{'$or':_[_0x7755('0x75')](_0x204635[_0x7755('0x86')],function(_0xd6e5b7){var _0x590de4={};_0x590de4[_0xd6e5b7]={'$like':'%'+_0x6adfd4[_0x7755('0x30')][_0x7755('0x89')]+'%'};return _0x590de4;})});}_0x204635=_['merge']({},_0x204635,_0x6adfd4[_0x7755('0x8a')]);return _0x1aa4ef[_0x7755('0x80')](_0x204635);}})[_0x7755('0x1a')](function(_0x4f0d61){if(_0x4f0d61){_0x44f30d=_0x4f0d61['length'];if(!_0x6adfd4['query'][_0x7755('0x38')]('nolimit')){_0x204635[_0x7755('0x13')]=qs[_0x7755('0x13')](_0x6adfd4[_0x7755('0x30')][_0x7755('0x13')]);_0x204635[_0x7755('0x15')]=qs['offset'](_0x6adfd4[_0x7755('0x30')][_0x7755('0x15')]);}return _0x1aa4ef[_0x7755('0x80')](_0x204635);}})['then'](function(_0x19d0bb){if(_0x19d0bb){return _0x19d0bb?{'count':_0x44f30d,'rows':_0x19d0bb}:null;}})['then'](respondWithResult(_0x161e80,null))[_0x7755('0x26')](handleError(_0x161e80,null));};exports[_0x7755('0x8b')]=function(_0x440541,_0xa90124){if(_0x440541['body']['id']){delete _0x440541['body']['id'];}return db['CmContact'][_0x7755('0x81')]({'where':{'id':_0x440541['params']['id']}})['then'](handleEntityNotFound(_0xa90124,null))[_0x7755('0x1a')](function(_0x5881a6){if(_0x5881a6){return _0x5881a6[_0x7755('0x8b')](_0x440541[_0x7755('0x3a')][_0x7755('0x8c')]||[]);}return null;})[_0x7755('0x1a')](respondWithResult(_0xa90124,null))[_0x7755('0x26')](handleError(_0xa90124,null));};exports['setAdditionalPhones']=function(_0x1981b6,_0xa3d617){var _0x528397=[];_0x528397[_0x7755('0x64')](addAdditionalPhones(_0x1981b6[_0x7755('0x3a')]));Promise['all'](_0x528397)[_0x7755('0x1a')](function(){_0x528397=[];_0x528397[_0x7755('0x64')](deleteCmHopperPhones(_0x1981b6[_0x7755('0x3a')]['id']));_0x528397[_0x7755('0x64')](addCmHopperPhones(_0x1981b6['body']['id']));Promise[_0x7755('0x69')](_0x528397)[_0x7755('0x1a')](function(){return[0x1];})[_0x7755('0x1a')](respondWithResult(_0xa3d617,null));});};function addAdditionalPhones(_0x36e10a){var _0xf2d2a8;return new Promise(function(_0x2c3699){return db[_0x7755('0x4e')][_0x7755('0x1b')]({'where':{'CmContactId':_0x36e10a['id']}})[_0x7755('0x1a')](function(){db[_0x7755('0x70')]['findAll']({'raw':!![],'attributes':['id','OrderBy']})[_0x7755('0x1a')](function(_0x1dd18e){var _0x204c84=[];for(var _0x17b817=0x0;_0x17b817<_0x36e10a[_0x7755('0x8d')]['length'];_0x17b817++){var _0x1cd8fc=_0x36e10a[_0x7755('0x8e')]?_[_0x7755('0x5b')](_0x36e10a[_0x7755('0x8e')][_0x17b817])?'':_0x36e10a[_0x7755('0x8e')][_0x17b817]:_0x36e10a[_0x7755('0x8d')][_0x17b817][_0x7755('0x8f')]?_0x36e10a[_0x7755('0x8d')][_0x17b817]['ItemTypeId']:'';var _0x267ddd=_['isNil'](_0x36e10a[_0x7755('0x8d')][_0x17b817][_0x7755('0x90')])?'':_0x36e10a[_0x7755('0x8d')][_0x17b817]['description'];var _0x5eec0c=_0x1cd8fc+':'+_0x36e10a[_0x7755('0x8d')][_0x17b817][_0x7755('0x7f')]+'ยง'+_0x267ddd;if(_[_0x7755('0x5b')](_0xf2d2a8))_0xf2d2a8=_0x5eec0c;else _0xf2d2a8+=';'+_0x5eec0c;var _0x2f5b09=null;var _0x7cc8b2=null;if(_0x36e10a[_0x7755('0x8e')]){if(!_[_0x7755('0x5b')](_0x36e10a['item_types'][_0x17b817])){_0x7cc8b2=_[_0x7755('0x28')](_0x1dd18e,function(_0x15223f){return _0x15223f['id']===_0x36e10a[_0x7755('0x8e')][_0x17b817];});if(!_[_0x7755('0x5b')](_0x7cc8b2)){_0x2f5b09=_0x7cc8b2[_0x7755('0x91')];}}}else{if(!_['isNil'](_0x36e10a['items'][_0x17b817])){_0x7cc8b2=_[_0x7755('0x28')](_0x1dd18e,function(_0x26237b){return _0x26237b['id']===_0x36e10a[_0x7755('0x8d')][_0x17b817]['ItemTypeId'];});if(!_['isNil'](_0x7cc8b2)){_0x2f5b09=_0x17b817;}}}if(_[_0x7755('0x5b')](_0x2f5b09)){_0x2f5b09=0x64;}_0x204c84['push'](addAdditionalPhone(_0x36e10a['id'],_0x36e10a[_0x7755('0x8d')][_0x17b817]['phone'],_0x36e10a['item_types']?_[_0x7755('0x5b')](_0x36e10a[_0x7755('0x8e')][_0x17b817])?null:_0x36e10a[_0x7755('0x8e')][_0x17b817]:_0x36e10a[_0x7755('0x8d')][_0x17b817]['ItemTypeId']?_0x36e10a[_0x7755('0x8d')][_0x17b817][_0x7755('0x8f')]:null,_0x2f5b09,_0x267ddd));}Promise['all'](_0x204c84)[_0x7755('0x1a')](function(){db[_0x7755('0x27')]['update']({'AdditionalPhones':_0xf2d2a8},{'where':{'id':_0x36e10a['id']}})[_0x7755('0x1a')](function(){_0x2c3699(0x1);});});});});});}function addAdditionalPhone(_0x4c89da,_0x59ec48,_0x71e2e7,_0x4fccc3,_0x5da147){return db[_0x7755('0x4e')][_0x7755('0x28')]({'where':{'CmContactId':_0x4c89da,'item':_0x59ec48}})[_0x7755('0x1a')](function(_0x910775){if(_0x910775)logger[_0x7755('0x35')](_0x7755('0x92'),_0x910775);else{db[_0x7755('0x4e')]['create']({'CmContactId':_0x4c89da,'item':_0x59ec48,'ItemTypeId':_0x71e2e7,'OrderBy':_0x4fccc3,'ItemClass':_0x7755('0x93'),'description':_0x5da147});}});}function deleteCmHopperPhones(_0x28b312){return new Promise(function(_0x1d3fe3){return db[_0x7755('0x41')][_0x7755('0x24')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x28b312}})[_0x7755('0x1a')](function(_0x2acf25){db['CmHopperAdditionalPhone'][_0x7755('0x1b')]({'where':{'CmHopperId':{'$in':_[_0x7755('0x75')](_0x2acf25,'id')}}});})['then'](function(){_0x1d3fe3(0x1);});});}function addCmHopperPhones(_0x5dc3b4){return new Promise(function(_0x3a5078){return db[_0x7755('0x41')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x5dc3b4}})['then'](function(_0x3978f1){var _0x3dfa57=[];_['map'](_0x3978f1,function(_0x453c55){_0x3dfa57['push'](createCmHopperPhone(_0x5dc3b4,_0x453c55['id']));});Promise[_0x7755('0x69')](_0x3dfa57)[_0x7755('0x1a')](function(){_0x3a5078(0x1);});});});}function createCmHopperPhone(_0x5debac,_0x57a67f){return new Promise(function(_0x15bb78){db[_0x7755('0x4e')][_0x7755('0x24')]({'raw':!![],'attributes':[_0x7755('0x94'),_0x7755('0x91')],'where':{'CmContactId':_0x5debac,'ItemClass':'PHONE'},'include':[{'model':db[_0x7755('0x70')],'attributes':[_0x7755('0x91')],'as':_0x7755('0x95')}],'order':['OrderBy',db[_0x7755('0x71')][_0x7755('0x72')](_0x7755('0x96'))]})[_0x7755('0x1a')](function(_0x14d465){var _0xb551c6=0x1;var _0xc32d02=_['map'](_0x14d465,function(_0xf0f9c8){_0xf0f9c8['CmHopperId']=_0x57a67f;_0xf0f9c8['phone']=_0xf0f9c8['item'];_0xf0f9c8[_0x7755('0x91')]=_0xb551c6;delete _0xf0f9c8[_0x7755('0x97')];_0xb551c6=_0xb551c6+0x1;return _0xf0f9c8;});return db['CmHopperAdditionalPhone'][_0x7755('0x60')](_0xc32d02,{});})[_0x7755('0x1a')](function(){_0x15bb78(0x1);});});}function insertAdditionalPhones(_0x29c1d6,_0x550414){return new Promise(function(_0xad953a){var _0x27c074=[];for(var _0x593792=0x0;_0x593792<_0x550414[_0x7755('0x3e')];_0x593792++){var _0x44fe80=_0x550414[_0x593792];_0x27c074[_0x7755('0x64')](parseContactItemType(_0x44fe80));}Promise[_0x7755('0x69')](_0x27c074)[_0x7755('0x1a')](function(){var _0x3ba1fe={'id':_0x29c1d6['id'],'items':_0x550414};return addAdditionalPhones(_0x3ba1fe)[_0x7755('0x1a')](function(){return addCmHopperPhones(_0x29c1d6['id']);});})['then'](function(){_0xad953a(_0x29c1d6);});});}function parseContactItemType(_0x914386){return new Promise(function(_0xe4221d){if(_0x914386[_0x7755('0x38')](_0x7755('0x8f'))){_0xe4221d(_0x914386);}else{return db[_0x7755('0x70')][_0x7755('0x28')]({'where':{'name':_0x914386[_0x7755('0x95')]}})[_0x7755('0x1a')](function(_0x18c9ca){if(_[_0x7755('0x5b')](_0x18c9ca))_0x914386[_0x7755('0x8f')]=null;else _0x914386['ItemTypeId']=_0x18c9ca['id'];_0xe4221d(_0x914386);});}});}exports[_0x7755('0x98')]=function(_0x1dad5a,_0x5cda83){return db[_0x7755('0x4e')]['findAll']({'raw':!![],'where':{'CmContactId':_0x1dad5a[_0x7755('0x29')]['id'],'ItemClass':_0x7755('0x93')},'include':[{'model':db['ContactItemType'],'as':_0x7755('0x95')}],'order':[[_0x7755('0x91')],[db[_0x7755('0x71')][_0x7755('0x72')](_0x7755('0x96'))]]})[_0x7755('0x1a')](function(_0xf251bf){return _0xf251bf;})['then'](respondWithResult(_0x5cda83,null))[_0x7755('0x26')](handleError(_0x5cda83,null));};exports[_0x7755('0x99')]=function(_0x24570b,_0x5aadd1){return db['CmContactHasItem'][_0x7755('0x24')]({'raw':!![],'where':{'CmContactId':_0x24570b[_0x7755('0x3a')]['fromContactId']}})['then'](function(_0x47a558){var _0x114591=_[_0x7755('0x75')](_0x47a558,function(_0x560bf2){_0x560bf2[_0x7755('0x9a')]=_0x24570b[_0x7755('0x3a')]['toContactId'];return _0x560bf2;});return db[_0x7755('0x4e')][_0x7755('0x60')](_0x114591,{});})[_0x7755('0x1a')](function(){return addCmHopperPhones(_0x24570b[_0x7755('0x3a')][_0x7755('0x9b')]);})['then'](function(){return['ok'];})[_0x7755('0x1a')](respondWithResult(_0x5aadd1,null))['catch'](handleError(_0x5aadd1,null));};exports[_0x7755('0x9c')]=function(_0x30d307,_0x9b3ae9){var _0x241bf5=[];_0x241bf5[_0x7755('0x64')](createCmHopperPhone(_0x30d307[_0x7755('0x3a')]['id'],_0x30d307[_0x7755('0x3a')][_0x7755('0x9d')]));Promise[_0x7755('0x69')](_0x241bf5)[_0x7755('0x1a')](function(){return[0x1];})['then'](respondWithResult(_0x9b3ae9,null));};exports['getHoppers']=function(_0x19883f,_0x3e32ef){var _0x14a127={'raw':![],'where':{}};var _0x36eee3={};var _0xae7d61={'count':0x0,'rows':[]};return db['CmContact'][_0x7755('0x81')]({'where':{'id':_0x19883f[_0x7755('0x29')]['id']}})[_0x7755('0x1a')](handleEntityNotFound(_0x3e32ef,null))[_0x7755('0x1a')](function(_0x23734f){if(_0x23734f){_0x36eee3[_0x7755('0x82')]=_[_0x7755('0x2b')](db['CmHopper']['rawAttributes']);_0x36eee3[_0x7755('0x30')]=_[_0x7755('0x2b')](_0x19883f['query']);_0x36eee3[_0x7755('0x84')]=_[_0x7755('0x9e')](_0x36eee3['model'],_0x36eee3['query']);_0x14a127[_0x7755('0x86')]=_[_0x7755('0x9e')](_0x36eee3[_0x7755('0x82')],qs[_0x7755('0x85')](_0x19883f[_0x7755('0x30')][_0x7755('0x85')]));_0x14a127['attributes']=_0x14a127[_0x7755('0x86')][_0x7755('0x3e')]?_0x14a127[_0x7755('0x86')]:_0x36eee3['model'];if(!_0x19883f[_0x7755('0x30')][_0x7755('0x38')](_0x7755('0x9f'))){_0x14a127['limit']=qs[_0x7755('0x13')](_0x19883f[_0x7755('0x30')]['limit']);_0x14a127[_0x7755('0x15')]=qs[_0x7755('0x15')](_0x19883f['query'][_0x7755('0x15')]);}_0x14a127['order']=qs['sort'](_0x19883f[_0x7755('0x30')]['sort']);_0x14a127['where']=qs[_0x7755('0x84')](_[_0x7755('0xa0')](_0x19883f[_0x7755('0x30')],_0x36eee3[_0x7755('0x84')]));_0x14a127[_0x7755('0x65')][_0x7755('0xa1')]=_0x23734f['id'];if(_0x19883f[_0x7755('0x30')][_0x7755('0x89')]){_0x14a127[_0x7755('0x65')]=_[_0x7755('0x39')](_0x14a127[_0x7755('0x65')],{'$or':_['map'](_0x14a127['attributes'],function(_0x30b1e3){var _0x17df73={};_0x17df73[_0x30b1e3]={'$like':'%'+_0x19883f[_0x7755('0x30')][_0x7755('0x89')]+'%'};return _0x17df73;})});}_0x14a127=_[_0x7755('0x39')]({},_0x14a127,_0x19883f[_0x7755('0x8a')]);return db[_0x7755('0x41')][_0x7755('0x14')]({'where':_0x14a127['where']})[_0x7755('0x1a')](function(_0x26fa57){_0xae7d61[_0x7755('0x14')]=_0x26fa57;if(_0x19883f[_0x7755('0x30')][_0x7755('0xa2')]){_0x14a127[_0x7755('0xa3')]=[{'all':!![]}];}return db[_0x7755('0x41')][_0x7755('0x24')](_0x14a127);})[_0x7755('0x1a')](function(_0x53265a){_0xae7d61[_0x7755('0xa4')]=_0x53265a;return _0xae7d61;});}})[_0x7755('0x1a')](respondWithFilteredResult(_0x3e32ef,_0x14a127))[_0x7755('0x26')](handleError(_0x3e32ef,null));};exports[_0x7755('0xa5')]=function(_0x1ba126,_0x38dd57){var _0x16cda9={'raw':!![],'where':{}};var _0x5808ea={};var _0x5d1cad={'count':0x0,'rows':[]};return db[_0x7755('0x27')][_0x7755('0x81')]({'where':{'id':_0x1ba126[_0x7755('0x29')]['id']}})['then'](handleEntityNotFound(_0x38dd57,null))[_0x7755('0x1a')](function(_0x7be795){if(_0x7be795){_0x5808ea[_0x7755('0x82')]=_[_0x7755('0x2b')](db[_0x7755('0x50')][_0x7755('0x83')]);_0x5808ea[_0x7755('0x30')]=_[_0x7755('0x2b')](_0x1ba126[_0x7755('0x30')]);_0x5808ea[_0x7755('0x84')]=_['intersection'](_0x5808ea[_0x7755('0x82')],_0x5808ea[_0x7755('0x30')]);_0x16cda9[_0x7755('0x86')]=_[_0x7755('0x9e')](_0x5808ea[_0x7755('0x82')],qs[_0x7755('0x85')](_0x1ba126[_0x7755('0x30')][_0x7755('0x85')]));_0x16cda9['attributes']=_0x16cda9[_0x7755('0x86')]['length']?_0x16cda9['attributes']:_0x5808ea[_0x7755('0x82')];if(!_0x1ba126[_0x7755('0x30')]['hasOwnProperty'](_0x7755('0x9f'))){_0x16cda9['limit']=qs[_0x7755('0x13')](_0x1ba126[_0x7755('0x30')]['limit']);_0x16cda9[_0x7755('0x15')]=qs[_0x7755('0x15')](_0x1ba126['query'][_0x7755('0x15')]);}_0x16cda9[_0x7755('0x87')]=qs['sort'](_0x1ba126['query'][_0x7755('0x88')]);_0x16cda9[_0x7755('0x65')]=qs[_0x7755('0x84')](_[_0x7755('0xa0')](_0x1ba126[_0x7755('0x30')],_0x5808ea[_0x7755('0x84')]));_0x16cda9[_0x7755('0x65')][_0x7755('0xa1')]=_0x7be795['id'];if(_0x1ba126[_0x7755('0x30')][_0x7755('0x89')]){_0x16cda9[_0x7755('0x65')]=_[_0x7755('0x39')](_0x16cda9['where'],{'$or':_[_0x7755('0x75')](_0x16cda9['attributes'],function(_0x27cce1){var _0x8c8f8d={};_0x8c8f8d[_0x27cce1]={'$like':'%'+_0x1ba126[_0x7755('0x30')]['filter']+'%'};return _0x8c8f8d;})});}_0x16cda9=_[_0x7755('0x39')]({},_0x16cda9,_0x1ba126['options']);return db[_0x7755('0x50')]['count']({'where':_0x16cda9[_0x7755('0x65')]})[_0x7755('0x1a')](function(_0x539326){_0x5d1cad[_0x7755('0x14')]=_0x539326;if(_0x1ba126[_0x7755('0x30')]['includeAll']){_0x16cda9[_0x7755('0xa3')]=[{'all':!![]}];}return db[_0x7755('0x50')][_0x7755('0x24')](_0x16cda9);})[_0x7755('0x1a')](function(_0x438c14){_0x5d1cad[_0x7755('0xa4')]=_0x438c14;return _0x5d1cad;});}})[_0x7755('0x1a')](respondWithFilteredResult(_0x38dd57,_0x16cda9))[_0x7755('0x26')](handleError(_0x38dd57,null));};exports['getHopperFinals']=function(_0x256684,_0x37af2a){var _0x21b248={'raw':!![],'where':{}};var _0x1a8c48={};var _0x2b2af2={'count':0x0,'rows':[]};return db['CmContact'][_0x7755('0x81')]({'where':{'id':_0x256684[_0x7755('0x29')]['id']}})[_0x7755('0x1a')](handleEntityNotFound(_0x37af2a,null))[_0x7755('0x1a')](function(_0x469c11){if(_0x469c11){_0x1a8c48[_0x7755('0x82')]=_[_0x7755('0x2b')](db['CmHopperFinal']['rawAttributes']);_0x1a8c48[_0x7755('0x30')]=_[_0x7755('0x2b')](_0x256684[_0x7755('0x30')]);_0x1a8c48[_0x7755('0x84')]=_[_0x7755('0x9e')](_0x1a8c48[_0x7755('0x82')],_0x1a8c48[_0x7755('0x30')]);_0x21b248[_0x7755('0x86')]=_['intersection'](_0x1a8c48[_0x7755('0x82')],qs[_0x7755('0x85')](_0x256684['query'][_0x7755('0x85')]));_0x21b248[_0x7755('0x86')]=_0x21b248[_0x7755('0x86')][_0x7755('0x3e')]?_0x21b248[_0x7755('0x86')]:_0x1a8c48[_0x7755('0x82')];if(!_0x256684[_0x7755('0x30')]['hasOwnProperty'](_0x7755('0x9f'))){_0x21b248['limit']=qs[_0x7755('0x13')](_0x256684[_0x7755('0x30')]['limit']);_0x21b248[_0x7755('0x15')]=qs[_0x7755('0x15')](_0x256684[_0x7755('0x30')][_0x7755('0x15')]);}_0x21b248[_0x7755('0x87')]=qs[_0x7755('0x88')](_0x256684['query']['sort']);_0x21b248[_0x7755('0x65')]=qs[_0x7755('0x84')](_['pick'](_0x256684['query'],_0x1a8c48[_0x7755('0x84')]));_0x21b248[_0x7755('0x65')][_0x7755('0xa1')]=_0x469c11['id'];if(_0x256684[_0x7755('0x30')][_0x7755('0x89')]){_0x21b248[_0x7755('0x65')]=_[_0x7755('0x39')](_0x21b248['where'],{'$or':_[_0x7755('0x75')](_0x21b248['attributes'],function(_0x1c67c2){var _0x4da814={};_0x4da814[_0x1c67c2]={'$like':'%'+_0x256684['query'][_0x7755('0x89')]+'%'};return _0x4da814;})});}_0x21b248=_[_0x7755('0x39')]({},_0x21b248,_0x256684[_0x7755('0x8a')]);return db[_0x7755('0x4f')][_0x7755('0x14')]({'where':_0x21b248['where']})['then'](function(_0x276d03){_0x2b2af2['count']=_0x276d03;if(_0x256684[_0x7755('0x30')][_0x7755('0xa2')]){_0x21b248['include']=[{'all':!![]}];}return db[_0x7755('0x4f')][_0x7755('0x24')](_0x21b248);})[_0x7755('0x1a')](function(_0x21be10){_0x2b2af2[_0x7755('0xa4')]=_0x21be10;return _0x2b2af2;});}})[_0x7755('0x1a')](respondWithFilteredResult(_0x37af2a,_0x21b248))[_0x7755('0x26')](handleError(_0x37af2a,null));};exports['getJscriptySessions']=function(_0x2f0cd3,_0x58a403){var _0x42cf0d={'raw':!![],'where':{}};var _0x53471d={};var _0xcd9d6c={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x2f0cd3[_0x7755('0x29')]['id']}})[_0x7755('0x1a')](handleEntityNotFound(_0x58a403,null))[_0x7755('0x1a')](function(_0x31626d){if(_0x31626d){_0x53471d[_0x7755('0x82')]=_['keys'](db[_0x7755('0x57')][_0x7755('0x83')]);_0x53471d['query']=_['keys'](_0x2f0cd3[_0x7755('0x30')]);_0x53471d['filters']=_[_0x7755('0x9e')](_0x53471d[_0x7755('0x82')],_0x53471d[_0x7755('0x30')]);_0x42cf0d['attributes']=_[_0x7755('0x9e')](_0x53471d['model'],qs[_0x7755('0x85')](_0x2f0cd3[_0x7755('0x30')][_0x7755('0x85')]));_0x42cf0d[_0x7755('0x86')]=_0x42cf0d[_0x7755('0x86')][_0x7755('0x3e')]?_0x42cf0d[_0x7755('0x86')]:_0x53471d[_0x7755('0x82')];if(!_0x2f0cd3[_0x7755('0x30')][_0x7755('0x38')]('nolimit')){_0x42cf0d[_0x7755('0x13')]=qs[_0x7755('0x13')](_0x2f0cd3[_0x7755('0x30')][_0x7755('0x13')]);_0x42cf0d['offset']=qs[_0x7755('0x15')](_0x2f0cd3[_0x7755('0x30')]['offset']);}_0x42cf0d['order']=qs[_0x7755('0x88')](_0x2f0cd3['query']['sort']);_0x42cf0d[_0x7755('0x65')]=qs[_0x7755('0x84')](_[_0x7755('0xa0')](_0x2f0cd3[_0x7755('0x30')],_0x53471d[_0x7755('0x84')]));_0x42cf0d[_0x7755('0x65')][_0x7755('0xa1')]=_0x31626d['id'];if(_0x2f0cd3['query'][_0x7755('0x89')]){_0x42cf0d[_0x7755('0x65')]=_[_0x7755('0x39')](_0x42cf0d[_0x7755('0x65')],{'$or':_[_0x7755('0x75')](_0x42cf0d[_0x7755('0x86')],function(_0x3fab7e){var _0x593781={};_0x593781[_0x3fab7e]={'$like':'%'+_0x2f0cd3[_0x7755('0x30')][_0x7755('0x89')]+'%'};return _0x593781;})});}_0x42cf0d=_['merge']({},_0x42cf0d,_0x2f0cd3[_0x7755('0x8a')]);return db[_0x7755('0x57')][_0x7755('0x14')]({'where':_0x42cf0d[_0x7755('0x65')]})['then'](function(_0x91c549){_0xcd9d6c['count']=_0x91c549;if(_0x2f0cd3['query'][_0x7755('0xa2')]){_0x42cf0d['include']=[{'all':!![]}];}return db['JscriptySessionReport'][_0x7755('0x24')](_0x42cf0d);})['then'](function(_0x145d18){_0xcd9d6c[_0x7755('0xa4')]=_0x145d18;return _0xcd9d6c;});}})[_0x7755('0x1a')](respondWithFilteredResult(_0x58a403,_0x42cf0d))[_0x7755('0x26')](handleError(_0x58a403,null));};exports[_0x7755('0xa6')]=function(_0x22a494,_0x51c417){try{if(!_0x22a494['body'][_0x7755('0x66')]){throw new Error(_0x7755('0xa7'));}if(!_0x22a494[_0x7755('0x3a')][_0x7755('0xa8')]){throw new Error(_0x7755('0xa9'));}if(!_0x22a494['body'][_0x7755('0xaa')]){throw new Error(_0x7755('0xab'));}if(!_0x22a494['body'][_0x7755('0xac')]){throw new Error(_0x7755('0xad'));}var _0xe16f96=_0x22a494[_0x7755('0x3a')][_0x7755('0xa8')][_0x7755('0xae')](',');var _0x4b9fe4=_0x22a494[_0x7755('0x3a')][_0x7755('0xaa')]['split'](',');if(!_0xe16f96[_0x7755('0x3e')]||!_0x4b9fe4[_0x7755('0x3e')]||_0xe16f96[_0x7755('0x3e')]!==_0x4b9fe4[_0x7755('0x3e')]){throw new Error(_0x7755('0xaf'));}_0x22a494[_0x7755('0x3a')][_0x7755('0x85')]=_[_0x7755('0xb0')](_0xe16f96,_0x4b9fe4);if(!_0x22a494['body'][_0x7755('0x85')][_0x7755('0x7f')]){throw new Error(_0x7755('0xb1'));}if(!_0x22a494[_0x7755('0x3a')][_0x7755('0x85')][_0x7755('0xb2')]){throw new Error(_0x7755('0xb3'));}var _0x361013=path['join'](config['root'],'server/files/tmp',_0x22a494[_0x7755('0xb4')][_0x7755('0xb5')]);fs[_0x7755('0xb6')](_0x361013,parseInt(_0x7755('0xb7'),0x8));var _0x4020cc=require(_0x7755('0xb8'))['fork'](path['join'](__dirname,'../../components/import/cm/csv'),[_0x361013,_0x22a494[_0x7755('0x3a')][_0x7755('0xa8')],_0x22a494[_0x7755('0x3a')][_0x7755('0xaa')],_0x22a494[_0x7755('0x3a')][_0x7755('0x66')],_0x22a494[_0x7755('0x3a')][_0x7755('0xb9')],_0x22a494[_0x7755('0x3a')]['duplicates'],_0x22a494[_0x7755('0x3a')][_0x7755('0xac')]]);return _0x51c417[_0x7755('0x16')](0xc8)[_0x7755('0x11')]({'message':'File\x20uploaded\x20correctly!','pid':_0x4020cc['pid']});}catch(_0x20f804){return _0x51c417['status'](0x1f4)[_0x7755('0x20')](_0x20f804);}};exports[_0x7755('0xba')]=function(_0x5e4372,_0x379a16){var _0x482743=fs[_0x7755('0xbb')](_0x5e4372[_0x7755('0xb4')]['path']);Papa['parse'](_0x482743,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x9395f3){return _0x379a16[_0x7755('0x16')](0xc8)['json']({'file':_0x5e4372['file'],'fields':_0x9395f3[_0x7755('0xbc')][_0x7755('0x85')]});}});};exports[_0x7755('0xbd')]=function(_0xb8b901,_0x3826b9){return db['User']['findAll']({'raw':!![],'attributes':['id'],'where':{'role':_0x7755('0xbe')}})[_0x7755('0x1a')](function(_0x51aaf3){var _0x4db804=![];if(!_0xb8b901[_0x7755('0x3a')][_0x7755('0x66')]){throw new Error(_0x7755('0xa7'));}if(!_0xb8b901[_0x7755('0x3a')][_0x7755('0xbf')][_0x7755('0x7f')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0xb8b901['body']['binding'][_0x7755('0xb2')]){throw new Error(_0x7755('0xb3'));}if(!_0xb8b901['body']['socket_timestamp']){throw new Error(_0x7755('0xad'));}var _0x151faf=require(_0x7755('0xb8'))[_0x7755('0xc0')](path[_0x7755('0x5a')](__dirname,_0x7755('0xc1')),[_0xb8b901['params']['id'],JSON[_0x7755('0xc2')](_0xb8b901['body']),JSON['stringify'](_0x51aaf3)]);_0x151faf['on']('message',function(){_0x4db804=!![];return _0x3826b9[_0x7755('0x16')](0xc8)[_0x7755('0x11')]({'message':_0x7755('0xc3'),'pid':_0x151faf[_0x7755('0xc4')]});});_0x151faf['on'](_0x7755('0xc5'),function(_0x4fefe6){if(_0x4fefe6&&!_0x4db804){return _0x3826b9[_0x7755('0x16')](0x1f4)[_0x7755('0x11')]({'message':_0x7755('0xc6'),'pid':_0x151faf[_0x7755('0xc4')]});}});})['catch'](handleError(_0x3826b9,null));};exports[_0x7755('0xc7')]=function(_0x40ba4c,_0x309578){return db[_0x7755('0xc8')][_0x7755('0x24')]({'raw':!![],'attributes':['id'],'where':{'role':_0x7755('0xbe')}})['then'](function(_0x14f772){var _0x216734=![];if(!_0x40ba4c['body'][_0x7755('0x66')]){throw new Error(_0x7755('0xa7'));}if(!_0x40ba4c[_0x7755('0x3a')][_0x7755('0xbf')]['phone']){throw new Error(_0x7755('0xb1'));}if(!_0x40ba4c[_0x7755('0x3a')]['binding'][_0x7755('0xb2')]){throw new Error(_0x7755('0xb3'));}if(!_0x40ba4c[_0x7755('0x3a')][_0x7755('0xac')]){throw new Error(_0x7755('0xad'));}var _0x362e89=require('child_process')['fork'](path[_0x7755('0x5a')](__dirname,'../../components/import/cm/csvUpdates'),[_0x40ba4c['params']['id'],JSON[_0x7755('0xc2')](_0x40ba4c[_0x7755('0x3a')]),JSON[_0x7755('0xc2')](_0x14f772)]);_0x362e89['on'](_0x7755('0xc9'),function(){_0x216734=!![];return _0x309578['status'](0xc8)[_0x7755('0x11')]({'message':_0x7755('0xc3'),'pid':_0x362e89[_0x7755('0xc4')]});});_0x362e89['on'](_0x7755('0xc5'),function(_0x33cb29){if(_0x33cb29&&!_0x216734){return _0x309578[_0x7755('0x16')](0x1f4)['json']({'message':_0x7755('0xc6'),'pid':_0x362e89['pid']});}});})[_0x7755('0x26')](handleError(_0x309578,null));};exports[_0x7755('0xca')]=function(_0x15c184,_0x3080c8){var _0x131a9e=[_0x7755('0xcb'),_0x7755('0xcc'),_0x7755('0xcd'),'openchannel',_0x7755('0xce'),_0x7755('0xcf'),_0x7755('0xd0')];var _0x39e734={'offset':0x0,'order':qs['sort'](_0x7755('0xd1'))},_0x2cf145={'count':0x0,'rows':[]};Promise[_0x7755('0xd2')]()[_0x7755('0x1a')](function(){if(_0x15c184[_0x7755('0x30')]['channel']){if(!_[_0x7755('0xd3')](_0x131a9e,_0x15c184[_0x7755('0x30')][_0x7755('0xd4')]['toLowerCase']())){throw new Error(_0x7755('0xd5'));}_0x131a9e=[_0x15c184[_0x7755('0x30')][_0x7755('0xd4')][_0x7755('0xd6')]()];}if(_0x15c184[_0x7755('0x30')][_0x7755('0xd7')]){try{var _0xc3f35b=JSON[_0x7755('0xd8')](_0x15c184[_0x7755('0x30')][_0x7755('0xd7')]);if(!moment(_0xc3f35b[_0x7755('0x3b')])[_0x7755('0xd9')]()){throw new Error(_0x7755('0xda'));}if(!moment(_0xc3f35b['to'])[_0x7755('0xd9')]()){throw new Error('Invalid\x20date\x20for\x20range\x20to\x20filter');}}catch(_0x450038){throw new Error(_0x7755('0xdb'));}}if(!_0x15c184[_0x7755('0x30')]['hasOwnProperty'](_0x7755('0x9f'))){_0x39e734['limit']=qs[_0x7755('0x13')](_0x15c184[_0x7755('0x30')]['limit']||0xa);_0x39e734['offset']=qs[_0x7755('0x15')](_0x15c184[_0x7755('0x30')][_0x7755('0x15')]);}var _0x4d075c=_0x131a9e[_0x7755('0x75')](function(_0xa1b7a7){if(_0xa1b7a7===_0x7755('0xd0')){var _0x2f1fc1={'attributes':['id','uniqueid','type',_0x7755('0xdc'),_0x7755('0xdd'),_0x7755('0xde'),_0x7755('0xdf'),_0x7755('0xe0'),_0x7755('0xe1'),_0x7755('0xe2'),_0x7755('0xe3'),_0x7755('0xe4'),_0x7755('0xe5'),_0x7755('0xe6'),_0x7755('0xe7')],'where':{'ContactId':_0x15c184[_0x7755('0x29')]['id']},'include':[{'model':db['User'],'as':_0x7755('0xc8'),'attributes':['id',_0x7755('0x1f'),_0x7755('0xe8'),'alias']}],'order':[['createdAt',_0x7755('0xe9')]]};if(_0x15c184[_0x7755('0x30')][_0x7755('0xd7')]){_0x2f1fc1['where'][_0x7755('0xe3')]={'$gte':_0xc3f35b[_0x7755('0x3b')],'$lte':_0xc3f35b['to']};}return db[_0x7755('0x51')][_0x7755('0xea')](_0x2f1fc1)['then'](function(_0xbcc6be){_0x2cf145[_0x7755('0x14')]+=_0xbcc6be['count'];return _[_0x7755('0x75')](_0xbcc6be[_0x7755('0xa4')],function(_0x145961){var _0x103d72=_0x145961['get']({'plain':!![]});_0x103d72['channel']=_0xa1b7a7;if(_0x103d72[_0x7755('0xc8')]){_0x103d72[_0x7755('0xc8')]={'id':_0x103d72[_0x7755('0xc8')]['id'],'name':_0x103d72[_0x7755('0xc8')][_0x7755('0x1f')],'fullname':_0x103d72[_0x7755('0xc8')][_0x7755('0xe8')],'alias':_0x103d72[_0x7755('0xc8')][_0x7755('0xeb')]};}return _0x103d72;});});}else{var _0x4a17b8=_[_0x7755('0xec')](_0xa1b7a7)+(_0xa1b7a7===_0x7755('0xcc')?_0x7755('0xed'):_0x7755('0xee'));var _0x502f23={'attributes':['id',_0x7755('0xef'),'closedAt',_0x7755('0xe3'),_0x7755('0xe2'),_0x7755('0xf0'),_0x7755('0xf1'),'thirdDisposition',_0x7755('0xe7'),_0x4a17b8+'Id'],'where':{'ContactId':_0x15c184[_0x7755('0x29')]['id']},'include':[{'model':db[_0x4a17b8],'as':_0x7755('0xee'),'attributes':['id',_0x7755('0x1f'),'key']},{'model':db['User'],'as':_0x7755('0xf2'),'attributes':['id','name',_0x7755('0xe8')]},{'model':db[_0x7755('0x6b')],'as':_0x7755('0x6c'),'attributes':['id',_0x7755('0x1f'),_0x7755('0x6d')],'through':{'attributes':[]}}],'order':[['createdAt',_0x7755('0xe9')]]};if(_0x15c184[_0x7755('0x30')][_0x7755('0xd7')]){_0x502f23['where'][_0x7755('0xe3')]={'$gte':_0xc3f35b[_0x7755('0x3b')],'$lte':_0xc3f35b['to']};}switch(_0xa1b7a7){case _0x7755('0xcc'):_0x502f23[_0x7755('0x86')][_0x7755('0x64')](_0x7755('0xf3'),_0x7755('0xf4'),_0x7755('0xf5'),_0x7755('0xf6'),_0x7755('0xf7'),_0x7755('0xf8'),_0x7755('0xf9'),_0x7755('0xfa'),_0x7755('0xfb'));break;case'mail':_0x502f23['attributes'][_0x7755('0x64')](_0x7755('0xfc'),_0x7755('0xfd'));break;case'openchannel':_0x502f23[_0x7755('0x86')][_0x7755('0x64')]('externalUrl','threadId');break;}return db[_['startCase'](_0xa1b7a7)+_0x7755('0xfe')]['findAndCountAll'](_0x502f23)[_0x7755('0x1a')](function(_0x114969){_0x2cf145[_0x7755('0x14')]+=_0x114969[_0x7755('0x14')];return _['map'](_0x114969[_0x7755('0xa4')],function(_0x32ae2a){var _0x43739e=_0x32ae2a[_0x7755('0x3c')]({'plain':!![]});_0x43739e[_0x7755('0xd4')]=_0xa1b7a7;if(_0x43739e[_0x7755('0xf2')]){_0x43739e[_0x7755('0xf2')]={'id':_0x43739e['Owner']['id'],'name':_0x43739e['Owner'][_0x7755('0x1f')],'fullname':_0x43739e[_0x7755('0xf2')][_0x7755('0xe8')]};}return _0x43739e;});});}});return Promise[_0x7755('0x69')](_0x4d075c);})[_0x7755('0x1a')](function(_0x2855d5){return _(_0x2855d5)['flatten']()[_0x7755('0xff')](_0x7755('0xe3'))[_0x7755('0x100')]()['value']();})[_0x7755('0x1a')](function(_0x297513){_0x2cf145[_0x7755('0xa4')]=_0x39e734['limit']?_0x297513[_0x7755('0x101')](_0x39e734[_0x7755('0x15')],_0x39e734['offset']+_0x39e734[_0x7755('0x13')]):_0x297513;return _0x2cf145;})[_0x7755('0x1a')](respondWithFilteredResult(_0x3080c8,_0x39e734))['catch'](handleError(_0x3080c8,null));};
\ No newline at end of file