Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / cmContact / cmContact.controller.js
index 50f9220..a3de24d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe1d1=['fork','../../components/import/cm/csv','CompanyId','socket_timestamp','File\x20uploaded\x20correctly!','pid','upload','createReadStream','parse','meta','import','User','agent','binding','No\x20firstName\x20column\x20specified','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','./cmContact.socket','register','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','CmContact','describe','keys','length','cf_','CmCustomField','findOne','trimStart','all','fieldType','type','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','where','field','color','from','tools_tags','cm_contacts','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','search','parseSearch','sqlOperator','conditions','Tag','value','split','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','uc.UserId\x20=\x20?','datetime','castTo','buildExpression','text','start','map','isNil','Contact','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','filter','replace','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.id\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','group','c.id','Sequelize','QueryTypes','SELECT','clone','order','having','t.id\x20IN\x20?','resolve','some','user','getLists','c.ListId\x20IS\x20NULL','sequelize','toString','keyBy','merge','c.firstName','c.lastName','c.phone','c.mobile','c.email','c.deletedAt','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','rows','catch','find','params','tags','startsWith','columnName','findAll','displayName','alias','custom','values','body','get','join','info','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelInteraction','OpenchannelMessage','CmHopperFinal','CmHopperHistory','ReportAgentPreview','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','bulkCreate','each','duplicates','$or','push','findOrCreate','spread','$and','omit','format','cf_%d','isEmpty','table','setFields','id\x20=\x20?','toParam','phone','getTags','rawAttributes','sort','pick','options','setTags','ids','getHoppers','ContactId','includeAll','include','getJscriptySessions','uploadCsv','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','Incorrect\x20binding\x20parameters\x20passed!','zipObject','firstName','root','server/files/tmp','file','filename','chmodSync','child_process'];(function(_0x263a2f,_0x1e81e3){var _0x8020e8=function(_0x39f91a){while(--_0x39f91a){_0x263a2f['push'](_0x263a2f['shift']());}};_0x8020e8(++_0x1e81e3);}(_0xe1d1,0x10f));var _0x1e1d=function(_0x1b6186,_0x1ec7f2){_0x1b6186=_0x1b6186-0x0;var _0x186121=_0xe1d1[_0x1b6186];return _0x186121;};'use strict';var pdf=require(_0x1e1d('0x0'));var emlformat=require(_0x1e1d('0x1'));var rimraf=require(_0x1e1d('0x2'));var zipdir=require(_0x1e1d('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x1e1d('0x4'));var moment=require(_0x1e1d('0x5'));var BPromise=require(_0x1e1d('0x6'));var Mustache=require(_0x1e1d('0x7'));var util=require('util');var path=require(_0x1e1d('0x8'));var sox=require('sox');var csv=require(_0x1e1d('0x9'));var ejs=require(_0x1e1d('0xa'));var fs=require('fs');var _=require(_0x1e1d('0xb'));var squel=require('squel');var crypto=require(_0x1e1d('0xc'));var jsforce=require(_0x1e1d('0xd'));var deskjs=require(_0x1e1d('0xe'));var toCsv=require(_0x1e1d('0x9'));var querystring=require(_0x1e1d('0xf'));var Papa=require(_0x1e1d('0x10'));var Redis=require(_0x1e1d('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x1e1d('0x12'));var as=require(_0x1e1d('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x1e1d('0x14'))(_0x1e1d('0x15'));var utils=require(_0x1e1d('0x16'));var config=require(_0x1e1d('0x17'));var licenseUtil=require(_0x1e1d('0x18'));var db=require(_0x1e1d('0x19'))['db'];config['redis']=_[_0x1e1d('0x1a')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x1e1d('0x1b')]));require(_0x1e1d('0x1c'))[_0x1e1d('0x1d')](socket);function respondWithStatusCode(_0x207808,_0x650034){_0x650034=_0x650034||0xcc;return function(_0x3e6fb1){if(_0x3e6fb1){return _0x207808[_0x1e1d('0x1e')](_0x650034);}return _0x207808[_0x1e1d('0x1f')](_0x650034)[_0x1e1d('0x20')]();};}function respondWithResult(_0x5c1e28,_0x381fc2){_0x381fc2=_0x381fc2||0xc8;return function(_0x47c3d5){if(_0x47c3d5){return _0x5c1e28[_0x1e1d('0x1f')](_0x381fc2)[_0x1e1d('0x21')](_0x47c3d5);}};}function respondWithFilteredResult(_0x5c9a04,_0x42d785){return function(_0xab31a9){if(_0xab31a9){var _0x22ed47=_0xab31a9[_0x1e1d('0x22')],_0x3c16d9=_0x42d785[_0x1e1d('0x23')],_0x34cde2=_0x42d785['offset']+_0x42d785[_0x1e1d('0x24')],_0x375a07;if(_0x34cde2>=_0x22ed47){_0x34cde2=_0x22ed47;_0x375a07=0xc8;}else{_0x375a07=0xce;}_0x5c9a04[_0x1e1d('0x1f')](_0x375a07);return _0x5c9a04[_0x1e1d('0x25')](_0x1e1d('0x26'),_0x3c16d9+'-'+_0x34cde2+'/'+_0x22ed47)[_0x1e1d('0x21')](_0xab31a9);}return null;};}function patchUpdates(_0x1dd8c5){return function(_0x138fe1){try{jsonpatch[_0x1e1d('0x27')](_0x138fe1,_0x1dd8c5,!![]);}catch(_0x59fa42){return BPromise[_0x1e1d('0x28')](_0x59fa42);}return _0x138fe1[_0x1e1d('0x29')]();};}function saveUpdates(_0x4681a1,_0x54215e){return function(_0x3682cb){if(_0x3682cb){return _0x3682cb[_0x1e1d('0x2a')](_0x4681a1)[_0x1e1d('0x2b')](function(_0x474999){return _0x474999;});}return null;};}function removeEntity(_0x4c9780,_0x206d5a){return function(_0x35f9df){if(_0x35f9df){return _0x35f9df[_0x1e1d('0x2c')]()[_0x1e1d('0x2b')](function(){_0x4c9780['status'](0xcc)[_0x1e1d('0x20')]();});}};}function handleEntityNotFound(_0x182048,_0x5cab21){return function(_0x79b54d){if(!_0x79b54d){_0x182048[_0x1e1d('0x1e')](0x194);}return _0x79b54d;};}function handleError(_0xd67ea4,_0x5452b0){_0x5452b0=_0x5452b0||0x1f4;return function(_0x18ffa4){logger[_0x1e1d('0x2d')](_0x18ffa4['stack']);if(_0x18ffa4['name']){delete _0x18ffa4[_0x1e1d('0x2e')];}_0xd67ea4[_0x1e1d('0x1f')](_0x5452b0)[_0x1e1d('0x2f')](_0x18ffa4);};}exports['index']=function(_0x4c268d,_0x43f8d6){var _0x5ed3b0={},_0x50a31f={},_0x166dc3={'count':0x0,'rows':[]};return db[_0x1e1d('0x30')][_0x1e1d('0x31')]()['then'](function(_0x4bce08){var _0xa895d5=[];for(var _0x244eb0=0x0;_0x244eb0<Object[_0x1e1d('0x32')](_0x4bce08)[_0x1e1d('0x33')];_0x244eb0++){var _0x4940a2=Object[_0x1e1d('0x32')](_0x4bce08)[_0x244eb0];if(_['startsWith'](_0x4940a2,_0x1e1d('0x34'))){_0xa895d5['push'](db[_0x1e1d('0x35')][_0x1e1d('0x36')]({'where':{'id':_[_0x1e1d('0x37')](_0x4940a2,_0x1e1d('0x34'))},'raw':!![]}));}}return BPromise[_0x1e1d('0x38')](_0xa895d5)[_0x1e1d('0x2b')](function(_0x1446c3){for(var _0x34ab1e=0x0;_0x34ab1e<_0x1446c3['length'];_0x34ab1e++){if(_0x1446c3[_0x34ab1e]){var _0x6e2ff8=_0x1e1d('0x34')+_0x1446c3[_0x34ab1e]['id'];var _0x243bfe=_0x4bce08[_0x6e2ff8];_0x243bfe[_0x1e1d('0x39')]=_0x1446c3[_0x34ab1e][_0x1e1d('0x3a')];}}return _0x4bce08;});})['then'](function(_0x1f2c8c){_0x50a31f[_0x1e1d('0x3b')]=_[_0x1e1d('0x32')](_0x1f2c8c);_0x50a31f[_0x1e1d('0x3c')]=_[_0x1e1d('0x32')](_0x4c268d[_0x1e1d('0x3c')]);_0x50a31f[_0x1e1d('0x3d')]=_[_0x1e1d('0x3e')](_0x50a31f[_0x1e1d('0x3b')],_0x50a31f[_0x1e1d('0x3c')]);_0x5ed3b0[_0x1e1d('0x3f')]=_[_0x1e1d('0x3e')](_0x50a31f['model'],qs['fields'](_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x40')]));_0x5ed3b0[_0x1e1d('0x3f')]=_0x5ed3b0[_0x1e1d('0x3f')][_0x1e1d('0x33')]?_0x5ed3b0[_0x1e1d('0x3f')]:_0x50a31f[_0x1e1d('0x3b')];if(!_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x41')](_0x1e1d('0x42'))){_0x5ed3b0['limit']=qs[_0x1e1d('0x24')](_0x4c268d['query']['limit']);_0x5ed3b0[_0x1e1d('0x23')]=qs[_0x1e1d('0x23')](_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x23')]);}_0x5ed3b0['order']=qs['sort'](_0x4c268d[_0x1e1d('0x3c')]['sort']);_0x5ed3b0[_0x1e1d('0x43')]=qs[_0x1e1d('0x3d')](_['pick'](_0x4c268d[_0x1e1d('0x3c')],_0x50a31f[_0x1e1d('0x3d')]),_0x1f2c8c);var _0x2decbd=[];var _0x31355f=squel['select']()['field']('id')[_0x1e1d('0x44')](_0x1e1d('0x2e'))[_0x1e1d('0x44')](_0x1e1d('0x45'))[_0x1e1d('0x46')](_0x1e1d('0x47'));var _0x4ff187=squel['select']()[_0x1e1d('0x46')](_0x1e1d('0x48'),'c')[_0x1e1d('0x49')](_0x1e1d('0x4a'),'uc',_0x1e1d('0x4b'))[_0x1e1d('0x49')](_0x1e1d('0x4c'),'ct','ct.CmContactId\x20=\x20c.id')[_0x1e1d('0x49')](_0x1e1d('0x47'),'t',_0x1e1d('0x4d'))[_0x1e1d('0x43')](_0x1e1d('0x4e'));var _0x912c61=squel[_0x1e1d('0x4f')]();var _0x58a67c=[];var _0x8c89eb=squel[_0x1e1d('0x4f')]();var _0x6e6b7e;if(_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x50')]){_0x6e6b7e=as[_0x1e1d('0x51')](_0x4c268d['query'][_0x1e1d('0x50')]);var _0x55adb7=_0x6e6b7e[_0x1e1d('0x52')];for(var _0x35e825=0x0;_0x35e825<_0x6e6b7e[_0x1e1d('0x53')][_0x1e1d('0x33')];_0x35e825++){var _0x2cd759=_0x6e6b7e[_0x1e1d('0x53')][_0x35e825];var _0x1f7190='c';var _0x1e2199=_(_0x1f2c8c)[_0x1e1d('0x32')]()['find'](function(_0x1bc5f9){return _0x1bc5f9===_0x2cd759[_0x1e1d('0x44')];});if(_0x1e2199)_0x1e2199=_0x1f2c8c[_0x2cd759['field']];if(!_0x1e2199){if(_0x2cd759[_0x1e1d('0x44')]===_0x1e1d('0x54')){var _0x1a03e9=_0x2cd759[_0x1e1d('0x55')][_0x1e1d('0x56')](',')['map'](function(_0x4ecea5){return Number(_0x4ecea5);});_0x1a03e9[_0x1e1d('0x57')](function(_0x34cba2){_0x8c89eb['or'](_0x1e1d('0x58'),'%,'+_0x34cba2+',%');});_0x58a67c=_['union'](_0x58a67c,_0x1a03e9);}else if(_0x2cd759[_0x1e1d('0x44')]==='User'){_0x912c61['and'](_0x1e1d('0x59'),_0x2cd759[_0x1e1d('0x55')]);}}else{if(_0x2cd759['field']==='dateOfBirth'||_0x1e2199['fieldType']===_0x1e1d('0x5a'))_0x2cd759[_0x1e1d('0x5b')]='DATE';var _0x151909=as[_0x1e1d('0x5c')](_0x1f7190,_0x1e2199[_0x1e1d('0x3a')],_0x2cd759);_0x912c61[_0x55adb7](_0x151909[_0x1e1d('0x5d')],_0x151909[_0x1e1d('0x55')][_0x1e1d('0x5e')],_0x151909['value']['end']);}}}else{var _0x216327=_(Object['keys'](_0x4c268d['query']))[_0x1e1d('0x5f')](function(_0x57ace2){return _0x1f2c8c[_0x1e1d('0x41')](_0x57ace2)?_0x57ace2:undefined;})['filter'](function(_0x446348){return!_[_0x1e1d('0x60')](_0x446348);})[_0x1e1d('0x55')]();if(_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x61')])_0x216327['push'](_0x1e1d('0x61'));if(!_['isEmpty'](_0x216327)){_0x216327[_0x1e1d('0x57')](function(_0x4088b7){if(_0x4088b7===_0x1e1d('0x62')){_0x4ff187[_0x1e1d('0x43')](_0x1e1d('0x63'),[][_0x1e1d('0x64')](_0x4c268d['query'][_0x4088b7]));}else if(_0x4088b7===_0x1e1d('0x61')){var _0x2de141='%'+_0x4c268d['query'][_0x4088b7]+'%';_0x4ff187[_0x1e1d('0x43')](_0x1e1d('0x65'),_0x2de141);}else{_0x4ff187[_0x1e1d('0x43')]('c.'+_0x4088b7+_0x1e1d('0x66'),_0x4c268d[_0x1e1d('0x3c')][_0x4088b7]);}});}if(_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x67')]){_0x58a67c=_[_0x1e1d('0x68')](_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x67')])?_0x4c268d[_0x1e1d('0x3c')][_0x1e1d('0x67')]:new Array(_0x4c268d['query'][_0x1e1d('0x67')]);_0x58a67c[_0x1e1d('0x57')](function(_0x499801){_0x8c89eb['or'](_0x1e1d('0x58'),'%,'+_0x499801+',%');});}if(_0x4c268d['query'][_0x1e1d('0x69')]){var _0x20bf0e=_0x4c268d[_0x1e1d('0x3c')]['filter'][_0x1e1d('0x6a')]('\x5c','\x5c\x5c')[_0x1e1d('0x6a')](/'/g,'\x27\x27');if(_0x20bf0e[_0x1e1d('0x56')]('\x20')['length']>0x1){_0x912c61['or'](_0x1e1d('0x6b'),qs[_0x1e1d('0x6c')](_0x20bf0e),null);}else{if(qs['isNumeric'](_0x20bf0e)){_0x912c61['or'](_0x1e1d('0x6d'),_0x20bf0e+'%');_0x912c61['or']('c.phone\x20LIKE\x20?',_0x20bf0e+'%');_0x912c61['or'](_0x1e1d('0x6e'),_0x20bf0e+'%');_0x912c61['or'](_0x1e1d('0x6f'),_0x20bf0e+'%');}else if(qs[_0x1e1d('0x70')](_0x20bf0e)){_0x912c61['or'](_0x1e1d('0x71'),_0x20bf0e+'%');}else{_0x912c61['or'](_0x1e1d('0x72'),'%'+_0x20bf0e+'%');_0x912c61['or'](_0x1e1d('0x73'),'%'+_0x20bf0e+'%');_0x912c61['or'](_0x1e1d('0x71'),'%'+_0x20bf0e+'%');}}}}_0x4ff187[_0x1e1d('0x43')](_0x912c61);_0x4ff187[_0x1e1d('0x74')](_0x1e1d('0x75'));var _0x9b8f86={'type':db[_0x1e1d('0x76')][_0x1e1d('0x77')][_0x1e1d('0x78')],'raw':!![]};var _0x185050=_0x4ff187[_0x1e1d('0x79')]()['field'](_0x1e1d('0x75'));if(_0x5ed3b0[_0x1e1d('0x7a')]){_0x5ed3b0[_0x1e1d('0x7a')]['forEach'](function(_0x386e18){_0x4ff187[_0x1e1d('0x7a')]('c.'+_0x386e18[0x0],_0x386e18[0x1]==='DESC'?![]:!![]);});}if(!_['isEmpty'](_0x58a67c)){_0x4ff187[_0x1e1d('0x7b')](_0x8c89eb);_0x185050['where'](_0x1e1d('0x7c'),_0x58a67c);}BPromise[_0x1e1d('0x7d')]()['then'](function(){if(_0x6e6b7e&&!_[_0x1e1d('0x7e')](_0x6e6b7e[_0x1e1d('0x53')],[_0x1e1d('0x44'),'User'])){return _0x4c268d[_0x1e1d('0x7f')][_0x1e1d('0x80')]({'attributes':['id'],'raw':!![]})[_0x1e1d('0x2b')](function(_0x5f1885){if(_['isEmpty'](_0x5f1885)){_0x185050['where'](_0x1e1d('0x81'));_0x4ff187[_0x1e1d('0x43')](_0x1e1d('0x81'));}else{_0x185050[_0x1e1d('0x43')](_0x1e1d('0x63'),_['map'](_0x5f1885,'id'));_0x4ff187['where'](_0x1e1d('0x63'),_[_0x1e1d('0x5f')](_0x5f1885,'id'));}});}else{return;}})[_0x1e1d('0x2b')](function(){db[_0x1e1d('0x82')][_0x1e1d('0x3c')](_0x185050[_0x1e1d('0x83')](),_0x9b8f86)['then'](function(_0x382d22){_0x166dc3[_0x1e1d('0x22')]=_0x382d22['length'];if(_0x166dc3[_0x1e1d('0x22')]===0x0)return[];return db[_0x1e1d('0x82')][_0x1e1d('0x3c')](_0x31355f[_0x1e1d('0x83')](),_0x9b8f86);})[_0x1e1d('0x2b')](function(_0x2626e1){_0x2decbd=_[_0x1e1d('0x84')](_0x2626e1,'id');_0x9b8f86=_[_0x1e1d('0x85')](_0x9b8f86,{'model':db[_0x1e1d('0x30')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4c268d[_0x1e1d('0x3c')]['fields']){_0x5ed3b0[_0x1e1d('0x3f')][_0x1e1d('0x57')](function(_0x445d57){_0x4ff187[_0x1e1d('0x44')]('c.'+_0x445d57);});}else{_0x4ff187['field']('c.id');_0x4ff187[_0x1e1d('0x44')](_0x1e1d('0x86'));_0x4ff187[_0x1e1d('0x44')](_0x1e1d('0x87'));_0x4ff187[_0x1e1d('0x44')](_0x1e1d('0x88'));_0x4ff187['field'](_0x1e1d('0x89'));_0x4ff187[_0x1e1d('0x44')]('c.fax');_0x4ff187[_0x1e1d('0x44')](_0x1e1d('0x8a'));_0x4ff187[_0x1e1d('0x44')]('c.ListId');_0x4ff187['field'](_0x1e1d('0x8b'));_0x4ff187[_0x1e1d('0x44')](_0x1e1d('0x8c'),_0x1e1d('0x8d'));}if(_0x5ed3b0[_0x1e1d('0x24')])_0x4ff187[_0x1e1d('0x24')](_0x5ed3b0[_0x1e1d('0x24')]);if(_0x5ed3b0[_0x1e1d('0x23')])_0x4ff187[_0x1e1d('0x23')](_0x5ed3b0['offset']);return db[_0x1e1d('0x82')]['query'](_0x4ff187[_0x1e1d('0x83')](),_0x9b8f86);})[_0x1e1d('0x2b')](function(_0x373532){_0x373532['forEach'](function(_0x49a857){if(_0x49a857['TagIds']){_0x49a857['Tags']=[];_0x49a857['TagIds'][_0x1e1d('0x56')](',')[_0x1e1d('0x57')](function(_0x54d4cc){_0x49a857[_0x1e1d('0x8e')]['push'](_0x2decbd[_0x54d4cc]);});}delete _0x49a857['TagIds'];});_0x166dc3[_0x1e1d('0x8f')]=_0x373532;return _0x166dc3;})[_0x1e1d('0x2b')](respondWithFilteredResult(_0x43f8d6,_0x5ed3b0));});})[_0x1e1d('0x90')](handleError(_0x43f8d6,null));};exports[_0x1e1d('0x2c')]=function(_0x495e2f,_0x47b748){return db[_0x1e1d('0x30')][_0x1e1d('0x91')]({'where':{'id':_0x495e2f[_0x1e1d('0x92')]['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x47b748,null))[_0x1e1d('0x2b')](removeEntity(_0x47b748,null))[_0x1e1d('0x90')](handleError(_0x47b748,null));};exports['describe']=function(_0x128dee,_0x3da4ba){return db[_0x1e1d('0x30')][_0x1e1d('0x31')]()[_0x1e1d('0x2b')](function(_0xb6bb6c){delete _0xb6bb6c[_0x1e1d('0x93')];for(var _0x147ea1=0x0;_0x147ea1<Object[_0x1e1d('0x32')](_0xb6bb6c)[_0x1e1d('0x33')];_0x147ea1++){var _0x2f5877=Object[_0x1e1d('0x32')](_0xb6bb6c)[_0x147ea1];if(!_[_0x1e1d('0x94')](_0x2f5877,'cf_')){_0xb6bb6c[_0x2f5877][_0x1e1d('0x95')]=_0x2f5877;_0xb6bb6c[_0x2f5877]['displayName']=_0x2f5877;}}return _0xb6bb6c;})[_0x1e1d('0x2b')](function(_0x522b2b){var _0x50a473={'where':{'$or':[{'ListId':_0x128dee[_0x1e1d('0x3c')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x1e1d('0x35')][_0x1e1d('0x96')](_0x50a473)[_0x1e1d('0x2b')](function(_0x206b88){for(var _0x50d7da=0x0;_0x50d7da<_0x206b88['length'];_0x50d7da++){var _0x3eeb55=_0x1e1d('0x34')+_0x206b88[_0x50d7da]['id'];_0x522b2b[_0x3eeb55]['columnName']=_0x3eeb55;_0x522b2b[_0x3eeb55][_0x1e1d('0x97')]=_0x206b88[_0x50d7da][_0x1e1d('0x98')];_0x522b2b[_0x3eeb55][_0x1e1d('0x99')]={'type':_0x206b88[_0x50d7da]['type'],'values':_0x206b88[_0x50d7da][_0x1e1d('0x9a')]};}Object[_0x1e1d('0x32')](_0x522b2b)[_0x1e1d('0x57')](function(_0x40c658){if(!_0x522b2b[_0x40c658]['hasOwnProperty'](_0x1e1d('0x95'))){delete _0x522b2b[_0x40c658];}});return _0x522b2b;});})[_0x1e1d('0x2b')](respondWithResult(_0x3da4ba,null))[_0x1e1d('0x90')](handleError(_0x3da4ba,null));};exports[_0x1e1d('0x85')]=function(_0x13051d,_0x22b59a){var _0x1dcaec;var _0x3f5ee6;var _0x199ab7;if(_0x13051d[_0x1e1d('0x9b')]['id']){delete _0x13051d[_0x1e1d('0x9b')]['id'];}return db[_0x1e1d('0x30')]['findAll']({'where':{'id':[_0x13051d[_0x1e1d('0x9b')]['to'],_0x13051d['body']['from']]}})[_0x1e1d('0x2b')](function(_0x98819d){if(_0x98819d){if(_0x98819d['length']!==0x2){return null;}_0x98819d[0x0]=_0x98819d[0x0][_0x1e1d('0x9c')]({'plain':!![]});_0x98819d[0x1]=_0x98819d[0x1]['get']({'plain':!![]});delete _0x98819d[0x0]['id'];delete _0x98819d[0x1]['id'];return _['mergeWith'](_0x98819d[0x0],_0x98819d[0x1],function(_0x4e96b7,_0x41e2f8){if(Array['isArray'](_0x41e2f8)&&!_0x41e2f8[_0x1e1d('0x33')]){return _0x4e96b7;}else if(!_0x41e2f8){return _0x4e96b7;}});}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x22b59a,null))[_0x1e1d('0x2b')](function(_0x4e4326){if(_0x4e4326){if(_0x4e4326[_0x1e1d('0x93')]&&_[_0x1e1d('0x68')](_0x4e4326['tags'])){_0x4e4326[_0x1e1d('0x93')]=_0x4e4326['tags'][_0x1e1d('0x9d')]();}logger[_0x1e1d('0x9e')]('[CmContact][merge]\x20to\x20%s\x20from\x20%s',_0x13051d['body']['to'],_0x13051d[_0x1e1d('0x9b')]['from']);return db[_0x1e1d('0x9f')][_0x1e1d('0x2c')]({'where':{'ContactId':[_0x13051d[_0x1e1d('0x9b')]['to'],_0x13051d[_0x1e1d('0x9b')][_0x1e1d('0x46')]]}})[_0x1e1d('0x2b')](function(_0x33bc11){logger[_0x1e1d('0x9e')](_0x1e1d('0xa0'),_0x33bc11);return db[_0x1e1d('0xa1')][_0x1e1d('0x2c')]({'where':{'ContactId':[_0x13051d[_0x1e1d('0x9b')]['to'],_0x13051d[_0x1e1d('0x9b')][_0x1e1d('0x46')]]}})['then'](function(_0x288f14){logger[_0x1e1d('0x9e')](_0x1e1d('0xa2'),_0x288f14);return db['CmContact'][_0x1e1d('0xa3')](_0x4e4326);});});}})['then'](function(_0x44d587){if(_0x44d587){_0x1dcaec=_0x44d587;_0x3f5ee6={'ContactId':_0x1dcaec['id']};_0x199ab7={'where':{'ContactId':[_0x13051d[_0x1e1d('0x9b')]['to'],_0x13051d[_0x1e1d('0x9b')][_0x1e1d('0x46')]]}};return db[_0x1e1d('0xa4')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xa5')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xa6')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xa7')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xa8')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xa7')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xa8')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xa9')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xaa')]['update'](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xab')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xac')]['update'](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xad')]['update'](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xae')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xaf')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xb0')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xb1')]['update'](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xb2')]['update'](_0x3f5ee6,_0x199ab7);}})['then'](function(){if(_0x1dcaec){return db[_0x1e1d('0xb3')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xb4')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xb5')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xb6')]['update'](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xb7')][_0x1e1d('0x2a')](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db[_0x1e1d('0xb8')]['update'](_0x3f5ee6,_0x199ab7);}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return db['CmContact'][_0x1e1d('0x2c')]({'where':{'id':[_0x13051d[_0x1e1d('0x9b')]['to'],_0x13051d[_0x1e1d('0x9b')][_0x1e1d('0x46')]]}});}})[_0x1e1d('0x2b')](function(){if(_0x1dcaec){return _0x1dcaec;}})['then'](respondWithResult(_0x22b59a,null))[_0x1e1d('0x90')](handleError(_0x22b59a,null));};exports[_0x1e1d('0xa3')]=function(_0x17be8e,_0xa139e2){return db[_0x1e1d('0x30')]['describe']()[_0x1e1d('0x2b')](function(_0x4dfffe){if(_0x17be8e[_0x1e1d('0x9b')][_0x1e1d('0x93')]&&_['isArray'](_0x17be8e['body']['tags'])){if(_0x17be8e[_0x1e1d('0x9b')][_0x1e1d('0x93')][_0x1e1d('0x33')]){_0x17be8e[_0x1e1d('0x9b')][_0x1e1d('0x93')]=_0x17be8e[_0x1e1d('0x9b')][_0x1e1d('0x93')]['join'](';')+';';}else{_0x17be8e[_0x1e1d('0x9b')][_0x1e1d('0x93')]=null;}}else{_0x17be8e['body']['tags']=null;}return db[_0x1e1d('0x30')]['create'](_0x17be8e[_0x1e1d('0x9b')],{'fields':_[_0x1e1d('0x32')](_0x4dfffe),'raw':!![]});})[_0x1e1d('0x2b')](respondWithResult(_0xa139e2,0xc9))['catch'](handleError(_0xa139e2,null));};exports[_0x1e1d('0xb9')]=function(_0x5758e4,_0x3eea5f){var _0x480720=[];var _0x45f2fe=0x0;var _0x55d275=0x0;var _0x161895=0x0;return db[_0x1e1d('0x30')][_0x1e1d('0x31')]()[_0x1e1d('0x2b')](function(_0x5b577a){return BPromise[_0x1e1d('0xba')](_0x5758e4['body'],function(_0x1a97cf){var _0x3d3b55={'where':{'$or':[]},'defaults':_0x1a97cf,'fields':_['keys'](_0x5b577a),'raw':!![]};if(_0x1a97cf['duplicates']){for(var _0x23ef40=0x0;_0x23ef40<_0x1a97cf[_0x1e1d('0xbb')][_0x1e1d('0x33')];_0x23ef40++){var _0x387d0d={};_0x387d0d[_0x1a97cf[_0x1e1d('0xbb')][_0x23ef40]]=_0x1a97cf[_0x1a97cf['duplicates'][_0x23ef40]];_0x3d3b55[_0x1e1d('0x43')][_0x1e1d('0xbc')][_0x1e1d('0xbd')](_0x387d0d);}_0x3d3b55['where'][_0x1e1d('0x62')]=_0x1a97cf[_0x1e1d('0x62')];}return db['CmContact'][_0x1e1d('0xbe')](_0x3d3b55)[_0x1e1d('0xbf')](function(_0x221420,_0x427ed3){if(_0x427ed3){_0x45f2fe++;}else{_0x161895++;}})[_0x1e1d('0x90')](function(_0x1ca18d){console[_0x1e1d('0x2d')](_0x1ca18d);_0x55d275++;});});})[_0x1e1d('0x2b')](function(_0x41e401){if(_0x41e401){return{'success':_0x45f2fe,'failure':_0x55d275,'duplicates':_0x161895};}})[_0x1e1d('0x2b')](respondWithResult(_0x3eea5f,0xc9))[_0x1e1d('0x90')](handleError(_0x3eea5f,null));};exports['show']=function(_0x4a6ed6,_0x4cf9db,_0x4034f2){var _0x534aae;return db[_0x1e1d('0x30')]['describe']()[_0x1e1d('0x2b')](function(_0x539f8f){return db['CmContact'][_0x1e1d('0x91')]({'where':{'id':_0x4a6ed6['params']['id']},'include':[{'model':db[_0x1e1d('0x54')],'as':_0x1e1d('0x8e'),'attributes':['id',_0x1e1d('0x2e'),_0x1e1d('0x45')],'required':_0x4a6ed6[_0x1e1d('0x3c')][_0x1e1d('0x67')]?!![]:![]}],'attributes':_['keys'](_0x539f8f)});})[_0x1e1d('0x2b')](function(_0x59f5cb){_0x534aae=_0x59f5cb[_0x1e1d('0x9c')]({'plain':!![]});var _0xf1765d={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x59f5cb&&_0x59f5cb[_0x1e1d('0x62')]){if(_0x59f5cb['ListId']){_0xf1765d['where'][_0x1e1d('0xc0')][_0x1e1d('0xbd')]({'ListId':{'$ne':_0x59f5cb[_0x1e1d('0x62')]}});}}return db[_0x1e1d('0x35')][_0x1e1d('0x96')](_0xf1765d);})[_0x1e1d('0x2b')](function(_0x31486d){return _[_0x1e1d('0xc1')](_0x534aae,_[_0x1e1d('0x5f')](_0x31486d,function(_0x54b1ea){return util[_0x1e1d('0xc2')](_0x1e1d('0xc3'),_0x54b1ea['id']);}));})[_0x1e1d('0x2b')](handleEntityNotFound(_0x4cf9db,null))[_0x1e1d('0x2b')](respondWithResult(_0x4cf9db,null))[_0x1e1d('0x90')](handleError(_0x4cf9db,null));};exports['update']=function(_0x1e17b7,_0x30b0ae){var _0x808264;if(_0x1e17b7[_0x1e1d('0x9b')]['id']){delete _0x1e17b7[_0x1e1d('0x9b')]['id'];}return db[_0x1e1d('0x30')][_0x1e1d('0x91')]({'where':{'id':_0x1e17b7['params']['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x30b0ae,null))[_0x1e1d('0x2b')](saveUpdates(_0x1e17b7[_0x1e1d('0x9b')],null))['then'](function(_0xcce81c){_0x808264=_0xcce81c;var _0x4c45c0={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0xcce81c&&_0xcce81c[_0x1e1d('0x62')]){if(_0xcce81c[_0x1e1d('0x62')]){_0x4c45c0[_0x1e1d('0x43')][_0x1e1d('0xc0')][_0x1e1d('0xbd')]({'ListId':{'$ne':_0xcce81c[_0x1e1d('0x62')]}});}}return db[_0x1e1d('0x35')]['findAll'](_0x4c45c0);})[_0x1e1d('0x2b')](function(_0x123596){if(_0x123596){return _[_0x1e1d('0xc1')](_['pickBy'](_0x1e17b7[_0x1e1d('0x9b')],function(_0x491b75,_0x2a0702){return _['startsWith'](_0x2a0702,'cf_');}),_['map'](_0x123596,function(_0x9f4d97){return util[_0x1e1d('0xc2')](_0x1e1d('0xc3'),_0x9f4d97['id']);}));}})[_0x1e1d('0x2b')](function(_0x5cc9dd){if(_0x5cc9dd&&!_[_0x1e1d('0xc4')](_0x5cc9dd)){var _0x24c0d6=squel[_0x1e1d('0x2a')]()[_0x1e1d('0xc5')]('cm_contacts')[_0x1e1d('0xc6')](_0x5cc9dd)['where'](_0x1e1d('0xc7'),_0x1e17b7[_0x1e1d('0x92')]['id'])[_0x1e1d('0xc8')]();return db[_0x1e1d('0x82')][_0x1e1d('0x3c')](_0x24c0d6[_0x1e1d('0x5d')],{'replacements':_0x24c0d6[_0x1e1d('0x9a')]});}})[_0x1e1d('0x2b')](function(){if(_0x1e17b7[_0x1e1d('0x9b')][_0x1e1d('0xc9')]&&_0x808264){return db[_0x1e1d('0x9f')][_0x1e1d('0x2a')]({'phone':_0x1e17b7['body'][_0x1e1d('0xc9')]},{'where':{'ContactId':_0x808264['id']}});}})[_0x1e1d('0x2b')](function(){return _0x808264;})[_0x1e1d('0x2b')](respondWithResult(_0x30b0ae,null))['catch'](handleError(_0x30b0ae,null));};exports[_0x1e1d('0xca')]=function(_0xdc337c,_0x291c42,_0x3af645){var _0x528ba1={};var _0x497535={};var _0x37dca8;var _0xb04d5;return db[_0x1e1d('0x30')][_0x1e1d('0x36')]({'where':{'id':_0xdc337c[_0x1e1d('0x92')]['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x291c42,null))[_0x1e1d('0x2b')](function(_0x5dcb74){if(_0x5dcb74){_0x37dca8=_0x5dcb74;_0x497535[_0x1e1d('0x3b')]=_[_0x1e1d('0x32')](db[_0x1e1d('0x54')][_0x1e1d('0xcb')]);_0x497535[_0x1e1d('0x3c')]=_['keys'](_0xdc337c[_0x1e1d('0x3c')]);_0x497535[_0x1e1d('0x3d')]=_[_0x1e1d('0x3e')](_0x497535[_0x1e1d('0x3b')],_0x497535[_0x1e1d('0x3c')]);_0x528ba1[_0x1e1d('0x3f')]=_[_0x1e1d('0x3e')](_0x497535[_0x1e1d('0x3b')],qs[_0x1e1d('0x40')](_0xdc337c[_0x1e1d('0x3c')]['fields']));_0x528ba1['attributes']=_0x528ba1[_0x1e1d('0x3f')]['length']?_0x528ba1[_0x1e1d('0x3f')]:_0x497535[_0x1e1d('0x3b')];_0x528ba1[_0x1e1d('0x7a')]=qs[_0x1e1d('0xcc')](_0xdc337c[_0x1e1d('0x3c')][_0x1e1d('0xcc')]);_0x528ba1[_0x1e1d('0x43')]=qs[_0x1e1d('0x3d')](_[_0x1e1d('0xcd')](_0xdc337c[_0x1e1d('0x3c')],_0x497535[_0x1e1d('0x3d')]));if(_0xdc337c[_0x1e1d('0x3c')][_0x1e1d('0x69')]){_0x528ba1[_0x1e1d('0x43')]=_[_0x1e1d('0x85')](_0x528ba1[_0x1e1d('0x43')],{'$or':_[_0x1e1d('0x5f')](_0x528ba1['attributes'],function(_0x39fb27){var _0x4dd68c={};_0x4dd68c[_0x39fb27]={'$like':'%'+_0xdc337c[_0x1e1d('0x3c')][_0x1e1d('0x69')]+'%'};return _0x4dd68c;})});}_0x528ba1=_[_0x1e1d('0x85')]({},_0x528ba1,_0xdc337c[_0x1e1d('0xce')]);return _0x37dca8[_0x1e1d('0xca')](_0x528ba1);}})['then'](function(_0x35e0b0){if(_0x35e0b0){_0xb04d5=_0x35e0b0[_0x1e1d('0x33')];if(!_0xdc337c[_0x1e1d('0x3c')][_0x1e1d('0x41')]('nolimit')){_0x528ba1[_0x1e1d('0x24')]=qs[_0x1e1d('0x24')](_0xdc337c['query'][_0x1e1d('0x24')]);_0x528ba1['offset']=qs[_0x1e1d('0x23')](_0xdc337c[_0x1e1d('0x3c')][_0x1e1d('0x23')]);}return _0x37dca8['getTags'](_0x528ba1);}})['then'](function(_0x16db10){if(_0x16db10){return _0x16db10?{'count':_0xb04d5,'rows':_0x16db10}:null;}})['then'](respondWithResult(_0x291c42,null))[_0x1e1d('0x90')](handleError(_0x291c42,null));};exports[_0x1e1d('0xcf')]=function(_0x3efd70,_0x9b7d84,_0x3a3419){if(_0x3efd70[_0x1e1d('0x9b')]['id']){delete _0x3efd70['body']['id'];}return db[_0x1e1d('0x30')][_0x1e1d('0x36')]({'where':{'id':_0x3efd70['params']['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x9b7d84,null))[_0x1e1d('0x2b')](function(_0xd29074){if(_0xd29074){return _0xd29074['setTags'](_0x3efd70[_0x1e1d('0x9b')][_0x1e1d('0xd0')]||[]);}return null;})[_0x1e1d('0x2b')](respondWithResult(_0x9b7d84,null))['catch'](handleError(_0x9b7d84,null));};exports[_0x1e1d('0xd1')]=function(_0x183e83,_0x18f349,_0x7a2079){var _0x16fb7a={'raw':![],'where':{}};var _0x26a838={};var _0x422310={'count':0x0,'rows':[]};return db[_0x1e1d('0x30')][_0x1e1d('0x36')]({'where':{'id':_0x183e83['params']['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x18f349,null))['then'](function(_0x2667e9){if(_0x2667e9){_0x26a838[_0x1e1d('0x3b')]=_[_0x1e1d('0x32')](db[_0x1e1d('0x9f')][_0x1e1d('0xcb')]);_0x26a838[_0x1e1d('0x3c')]=_['keys'](_0x183e83[_0x1e1d('0x3c')]);_0x26a838['filters']=_[_0x1e1d('0x3e')](_0x26a838['model'],_0x26a838['query']);_0x16fb7a[_0x1e1d('0x3f')]=_[_0x1e1d('0x3e')](_0x26a838[_0x1e1d('0x3b')],qs['fields'](_0x183e83[_0x1e1d('0x3c')][_0x1e1d('0x40')]));_0x16fb7a['attributes']=_0x16fb7a[_0x1e1d('0x3f')][_0x1e1d('0x33')]?_0x16fb7a[_0x1e1d('0x3f')]:_0x26a838['model'];if(!_0x183e83[_0x1e1d('0x3c')][_0x1e1d('0x41')](_0x1e1d('0x42'))){_0x16fb7a[_0x1e1d('0x24')]=qs[_0x1e1d('0x24')](_0x183e83['query'][_0x1e1d('0x24')]);_0x16fb7a[_0x1e1d('0x23')]=qs['offset'](_0x183e83[_0x1e1d('0x3c')][_0x1e1d('0x23')]);}_0x16fb7a['order']=qs[_0x1e1d('0xcc')](_0x183e83[_0x1e1d('0x3c')][_0x1e1d('0xcc')]);_0x16fb7a['where']=qs[_0x1e1d('0x3d')](_[_0x1e1d('0xcd')](_0x183e83[_0x1e1d('0x3c')],_0x26a838[_0x1e1d('0x3d')]));_0x16fb7a[_0x1e1d('0x43')][_0x1e1d('0xd2')]=_0x2667e9['id'];if(_0x183e83[_0x1e1d('0x3c')][_0x1e1d('0x69')]){_0x16fb7a[_0x1e1d('0x43')]=_[_0x1e1d('0x85')](_0x16fb7a[_0x1e1d('0x43')],{'$or':_['map'](_0x16fb7a[_0x1e1d('0x3f')],function(_0x81498){var _0x4ba7a8={};_0x4ba7a8[_0x81498]={'$like':'%'+_0x183e83[_0x1e1d('0x3c')]['filter']+'%'};return _0x4ba7a8;})});}_0x16fb7a=_[_0x1e1d('0x85')]({},_0x16fb7a,_0x183e83[_0x1e1d('0xce')]);return db[_0x1e1d('0x9f')]['count']({'where':_0x16fb7a[_0x1e1d('0x43')]})['then'](function(_0x480590){_0x422310[_0x1e1d('0x22')]=_0x480590;if(_0x183e83[_0x1e1d('0x3c')][_0x1e1d('0xd3')]){_0x16fb7a['include']=[{'all':!![]}];}return db[_0x1e1d('0x9f')][_0x1e1d('0x96')](_0x16fb7a);})[_0x1e1d('0x2b')](function(_0x214880){_0x422310['rows']=_0x214880;return _0x422310;});}})['then'](respondWithFilteredResult(_0x18f349,_0x16fb7a))[_0x1e1d('0x90')](handleError(_0x18f349,null));};exports['getHopperHistories']=function(_0x298552,_0x2bdddf,_0x4b00d7){var _0x8445b5={'raw':!![],'where':{}};var _0x135aa6={};var _0x3b009f={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x298552[_0x1e1d('0x92')]['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x2bdddf,null))[_0x1e1d('0x2b')](function(_0x69a540){if(_0x69a540){_0x135aa6[_0x1e1d('0x3b')]=_['keys'](db[_0x1e1d('0xb0')][_0x1e1d('0xcb')]);_0x135aa6[_0x1e1d('0x3c')]=_['keys'](_0x298552['query']);_0x135aa6[_0x1e1d('0x3d')]=_[_0x1e1d('0x3e')](_0x135aa6['model'],_0x135aa6[_0x1e1d('0x3c')]);_0x8445b5[_0x1e1d('0x3f')]=_[_0x1e1d('0x3e')](_0x135aa6[_0x1e1d('0x3b')],qs['fields'](_0x298552['query'][_0x1e1d('0x40')]));_0x8445b5[_0x1e1d('0x3f')]=_0x8445b5[_0x1e1d('0x3f')]['length']?_0x8445b5[_0x1e1d('0x3f')]:_0x135aa6[_0x1e1d('0x3b')];if(!_0x298552[_0x1e1d('0x3c')]['hasOwnProperty']('nolimit')){_0x8445b5[_0x1e1d('0x24')]=qs['limit'](_0x298552[_0x1e1d('0x3c')][_0x1e1d('0x24')]);_0x8445b5[_0x1e1d('0x23')]=qs[_0x1e1d('0x23')](_0x298552[_0x1e1d('0x3c')][_0x1e1d('0x23')]);}_0x8445b5[_0x1e1d('0x7a')]=qs[_0x1e1d('0xcc')](_0x298552[_0x1e1d('0x3c')][_0x1e1d('0xcc')]);_0x8445b5[_0x1e1d('0x43')]=qs[_0x1e1d('0x3d')](_[_0x1e1d('0xcd')](_0x298552[_0x1e1d('0x3c')],_0x135aa6[_0x1e1d('0x3d')]));_0x8445b5[_0x1e1d('0x43')][_0x1e1d('0xd2')]=_0x69a540['id'];if(_0x298552['query'][_0x1e1d('0x69')]){_0x8445b5[_0x1e1d('0x43')]=_['merge'](_0x8445b5[_0x1e1d('0x43')],{'$or':_[_0x1e1d('0x5f')](_0x8445b5[_0x1e1d('0x3f')],function(_0x932240){var _0x53edc3={};_0x53edc3[_0x932240]={'$like':'%'+_0x298552[_0x1e1d('0x3c')]['filter']+'%'};return _0x53edc3;})});}_0x8445b5=_[_0x1e1d('0x85')]({},_0x8445b5,_0x298552[_0x1e1d('0xce')]);return db[_0x1e1d('0xb0')][_0x1e1d('0x22')]({'where':_0x8445b5[_0x1e1d('0x43')]})[_0x1e1d('0x2b')](function(_0x1353d2){_0x3b009f[_0x1e1d('0x22')]=_0x1353d2;if(_0x298552['query']['includeAll']){_0x8445b5[_0x1e1d('0xd4')]=[{'all':!![]}];}return db['CmHopperHistory']['findAll'](_0x8445b5);})['then'](function(_0x3c6b02){_0x3b009f[_0x1e1d('0x8f')]=_0x3c6b02;return _0x3b009f;});}})[_0x1e1d('0x2b')](respondWithFilteredResult(_0x2bdddf,_0x8445b5))['catch'](handleError(_0x2bdddf,null));};exports['getHopperFinals']=function(_0x3947a3,_0x1f26b6,_0xa4f59){var _0x494833={'raw':!![],'where':{}};var _0x3aa068={};var _0x4cfefb={'count':0x0,'rows':[]};return db[_0x1e1d('0x30')][_0x1e1d('0x36')]({'where':{'id':_0x3947a3['params']['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x1f26b6,null))['then'](function(_0x5f2794){if(_0x5f2794){_0x3aa068[_0x1e1d('0x3b')]=_['keys'](db[_0x1e1d('0xaf')][_0x1e1d('0xcb')]);_0x3aa068[_0x1e1d('0x3c')]=_[_0x1e1d('0x32')](_0x3947a3[_0x1e1d('0x3c')]);_0x3aa068[_0x1e1d('0x3d')]=_[_0x1e1d('0x3e')](_0x3aa068[_0x1e1d('0x3b')],_0x3aa068['query']);_0x494833[_0x1e1d('0x3f')]=_[_0x1e1d('0x3e')](_0x3aa068[_0x1e1d('0x3b')],qs[_0x1e1d('0x40')](_0x3947a3[_0x1e1d('0x3c')][_0x1e1d('0x40')]));_0x494833[_0x1e1d('0x3f')]=_0x494833['attributes'][_0x1e1d('0x33')]?_0x494833[_0x1e1d('0x3f')]:_0x3aa068[_0x1e1d('0x3b')];if(!_0x3947a3[_0x1e1d('0x3c')][_0x1e1d('0x41')](_0x1e1d('0x42'))){_0x494833[_0x1e1d('0x24')]=qs[_0x1e1d('0x24')](_0x3947a3[_0x1e1d('0x3c')][_0x1e1d('0x24')]);_0x494833[_0x1e1d('0x23')]=qs[_0x1e1d('0x23')](_0x3947a3[_0x1e1d('0x3c')]['offset']);}_0x494833[_0x1e1d('0x7a')]=qs[_0x1e1d('0xcc')](_0x3947a3['query'][_0x1e1d('0xcc')]);_0x494833['where']=qs['filters'](_[_0x1e1d('0xcd')](_0x3947a3[_0x1e1d('0x3c')],_0x3aa068[_0x1e1d('0x3d')]));_0x494833[_0x1e1d('0x43')][_0x1e1d('0xd2')]=_0x5f2794['id'];if(_0x3947a3[_0x1e1d('0x3c')][_0x1e1d('0x69')]){_0x494833[_0x1e1d('0x43')]=_[_0x1e1d('0x85')](_0x494833[_0x1e1d('0x43')],{'$or':_['map'](_0x494833[_0x1e1d('0x3f')],function(_0x2ef0c4){var _0x19f71d={};_0x19f71d[_0x2ef0c4]={'$like':'%'+_0x3947a3[_0x1e1d('0x3c')][_0x1e1d('0x69')]+'%'};return _0x19f71d;})});}_0x494833=_['merge']({},_0x494833,_0x3947a3['options']);return db[_0x1e1d('0xaf')][_0x1e1d('0x22')]({'where':_0x494833[_0x1e1d('0x43')]})[_0x1e1d('0x2b')](function(_0x2973b3){_0x4cfefb[_0x1e1d('0x22')]=_0x2973b3;if(_0x3947a3[_0x1e1d('0x3c')][_0x1e1d('0xd3')]){_0x494833['include']=[{'all':!![]}];}return db[_0x1e1d('0xaf')][_0x1e1d('0x96')](_0x494833);})[_0x1e1d('0x2b')](function(_0x3297d8){_0x4cfefb[_0x1e1d('0x8f')]=_0x3297d8;return _0x4cfefb;});}})[_0x1e1d('0x2b')](respondWithFilteredResult(_0x1f26b6,_0x494833))[_0x1e1d('0x90')](handleError(_0x1f26b6,null));};exports[_0x1e1d('0xd5')]=function(_0x5d09ee,_0x41c2cd,_0x4d8d37){var _0x37b1f6={'raw':!![],'where':{}};var _0x2f8525={};var _0x2b1ce0={'count':0x0,'rows':[]};return db[_0x1e1d('0x30')]['findOne']({'where':{'id':_0x5d09ee[_0x1e1d('0x92')]['id']}})[_0x1e1d('0x2b')](handleEntityNotFound(_0x41c2cd,null))[_0x1e1d('0x2b')](function(_0x5b1dbf){if(_0x5b1dbf){_0x2f8525['model']=_[_0x1e1d('0x32')](db['JscriptySessionReport']['rawAttributes']);_0x2f8525['query']=_[_0x1e1d('0x32')](_0x5d09ee[_0x1e1d('0x3c')]);_0x2f8525['filters']=_[_0x1e1d('0x3e')](_0x2f8525[_0x1e1d('0x3b')],_0x2f8525[_0x1e1d('0x3c')]);_0x37b1f6[_0x1e1d('0x3f')]=_[_0x1e1d('0x3e')](_0x2f8525['model'],qs[_0x1e1d('0x40')](_0x5d09ee['query'][_0x1e1d('0x40')]));_0x37b1f6[_0x1e1d('0x3f')]=_0x37b1f6[_0x1e1d('0x3f')][_0x1e1d('0x33')]?_0x37b1f6[_0x1e1d('0x3f')]:_0x2f8525[_0x1e1d('0x3b')];if(!_0x5d09ee[_0x1e1d('0x3c')][_0x1e1d('0x41')]('nolimit')){_0x37b1f6[_0x1e1d('0x24')]=qs[_0x1e1d('0x24')](_0x5d09ee[_0x1e1d('0x3c')][_0x1e1d('0x24')]);_0x37b1f6[_0x1e1d('0x23')]=qs[_0x1e1d('0x23')](_0x5d09ee['query']['offset']);}_0x37b1f6[_0x1e1d('0x7a')]=qs[_0x1e1d('0xcc')](_0x5d09ee[_0x1e1d('0x3c')][_0x1e1d('0xcc')]);_0x37b1f6[_0x1e1d('0x43')]=qs['filters'](_[_0x1e1d('0xcd')](_0x5d09ee[_0x1e1d('0x3c')],_0x2f8525[_0x1e1d('0x3d')]));_0x37b1f6[_0x1e1d('0x43')][_0x1e1d('0xd2')]=_0x5b1dbf['id'];if(_0x5d09ee[_0x1e1d('0x3c')]['filter']){_0x37b1f6[_0x1e1d('0x43')]=_[_0x1e1d('0x85')](_0x37b1f6['where'],{'$or':_['map'](_0x37b1f6[_0x1e1d('0x3f')],function(_0x3a99cb){var _0x46e888={};_0x46e888[_0x3a99cb]={'$like':'%'+_0x5d09ee[_0x1e1d('0x3c')]['filter']+'%'};return _0x46e888;})});}_0x37b1f6=_[_0x1e1d('0x85')]({},_0x37b1f6,_0x5d09ee[_0x1e1d('0xce')]);return db['JscriptySessionReport'][_0x1e1d('0x22')]({'where':_0x37b1f6[_0x1e1d('0x43')]})['then'](function(_0x30a4a2){_0x2b1ce0[_0x1e1d('0x22')]=_0x30a4a2;if(_0x5d09ee[_0x1e1d('0x3c')][_0x1e1d('0xd3')]){_0x37b1f6['include']=[{'all':!![]}];}return db[_0x1e1d('0xb8')][_0x1e1d('0x96')](_0x37b1f6);})['then'](function(_0x5ff477){_0x2b1ce0[_0x1e1d('0x8f')]=_0x5ff477;return _0x2b1ce0;});}})[_0x1e1d('0x2b')](respondWithFilteredResult(_0x41c2cd,_0x37b1f6))['catch'](handleError(_0x41c2cd,null));};exports[_0x1e1d('0xd6')]=function(_0x7c4378,_0x4de5bd,_0x1520df){try{if(!_0x7c4378[_0x1e1d('0x9b')]['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xd7')]){throw new Error(_0x1e1d('0xd8'));}if(!_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xd9')]){throw new Error(_0x1e1d('0xda'));}if(!_0x7c4378[_0x1e1d('0x9b')]['socket_timestamp']){throw new Error(_0x1e1d('0xdb'));}var _0x2ede9b=_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xd7')]['split'](',');var _0x231ed=_0x7c4378['body'][_0x1e1d('0xd9')][_0x1e1d('0x56')](',');if(!_0x2ede9b['length']||!_0x231ed[_0x1e1d('0x33')]||_0x2ede9b[_0x1e1d('0x33')]!==_0x231ed[_0x1e1d('0x33')]){throw new Error(_0x1e1d('0xdc'));}_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0x40')]=_[_0x1e1d('0xdd')](_0x2ede9b,_0x231ed);if(!_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0x40')][_0x1e1d('0xc9')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0x40')][_0x1e1d('0xde')]){throw new Error('No\x20firstName\x20column\x20specified');}var _0x3a8cc3=path['join'](config[_0x1e1d('0xdf')],_0x1e1d('0xe0'),_0x7c4378[_0x1e1d('0xe1')][_0x1e1d('0xe2')]);fs[_0x1e1d('0xe3')](_0x3a8cc3,parseInt('0777',0x8));var _0x5e61c0=require(_0x1e1d('0xe4'))[_0x1e1d('0xe5')](path[_0x1e1d('0x9d')](__dirname,_0x1e1d('0xe6')),[_0x3a8cc3,_0x7c4378['body']['binding_keys'],_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xd9')],_0x7c4378['body'][_0x1e1d('0x62')],_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xe7')],_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xbb')],_0x7c4378[_0x1e1d('0x9b')][_0x1e1d('0xe8')]]);return _0x4de5bd[_0x1e1d('0x1f')](0xc8)[_0x1e1d('0x21')]({'message':_0x1e1d('0xe9'),'pid':_0x5e61c0[_0x1e1d('0xea')]});}catch(_0x1a5bba){return _0x4de5bd['status'](0x1f4)[_0x1e1d('0x2f')](_0x1a5bba);}};exports[_0x1e1d('0xeb')]=function(_0x4136ae,_0x1d27a8,_0x1f9f5e){var _0x1222d5=fs[_0x1e1d('0xec')](_0x4136ae[_0x1e1d('0xe1')]['path']);Papa[_0x1e1d('0xed')](_0x1222d5,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x4cd97f){return _0x1d27a8['status'](0xc8)[_0x1e1d('0x21')]({'file':_0x4136ae[_0x1e1d('0xe1')],'fields':_0x4cd97f[_0x1e1d('0xee')][_0x1e1d('0x40')]});}});};exports[_0x1e1d('0xef')]=function(_0x5d67c3,_0x14053a,_0x3596cf){return db[_0x1e1d('0xf0')][_0x1e1d('0x96')]({'raw':!![],'attributes':['id'],'where':{'role':_0x1e1d('0xf1')}})[_0x1e1d('0x2b')](function(_0x3c5395){var _0x28d6ec=![];if(!_0x5d67c3[_0x1e1d('0x9b')][_0x1e1d('0x62')]){throw new Error('No\x20ListId\x20specified');}if(!_0x5d67c3[_0x1e1d('0x9b')][_0x1e1d('0xf2')][_0x1e1d('0xc9')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x5d67c3[_0x1e1d('0x9b')][_0x1e1d('0xf2')][_0x1e1d('0xde')]){throw new Error(_0x1e1d('0xf3'));}if(!_0x5d67c3['body'][_0x1e1d('0xe8')]){throw new Error(_0x1e1d('0xdb'));}var _0x32cbc5=require(_0x1e1d('0xe4'))[_0x1e1d('0xe5')](path[_0x1e1d('0x9d')](__dirname,_0x1e1d('0xf4')),[_0x5d67c3[_0x1e1d('0x92')]['id'],JSON[_0x1e1d('0xf5')](_0x5d67c3[_0x1e1d('0x9b')]),JSON['stringify'](_0x3c5395)]);_0x32cbc5['on'](_0x1e1d('0xf6'),function(_0x5d87c0){_0x28d6ec=!![];return _0x14053a[_0x1e1d('0x1f')](0xc8)[_0x1e1d('0x21')]({'message':_0x1e1d('0xf7'),'pid':_0x32cbc5[_0x1e1d('0xea')]});});_0x32cbc5['on'](_0x1e1d('0xf8'),function(_0x1dd0c1){if(_0x1dd0c1&&!_0x28d6ec){return _0x14053a[_0x1e1d('0x1f')](0x1f4)[_0x1e1d('0x21')]({'message':_0x1e1d('0xf9'),'pid':_0x32cbc5[_0x1e1d('0xea')]});}});})['catch'](handleError(_0x14053a,null));};
\ No newline at end of file
+var _0x3d2e=['Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','binding_values','Incorrect\x20binding\x20parameters\x20passed!','zipObject','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','filename','chmodSync','child_process','fork','../../components/import/cm/csv','File\x20uploaded\x20correctly!','pid','upload','createReadStream','meta','import','User','binding','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','mail','sms','fax','whatsapp','voice','-createdAt','includes','channel','Invalid\x20channel','toLowerCase','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','Invalid\x20createdAt\x20filter','uniqueid','callerid','starttime','duration','note','userDisposition','UserId','fullname','createdAt','findAndCountAll','startCase','Website','Account','closedAt','key','chat','browserName','customerPort','deviceModel','osName','ratingMessage','ratingType','ratingValue','referer','openchannel','externalUrl','threadId','Interaction','Owner','flatten','sortBy','reverse','bluebird','util','path','lodash','squel','papaparse','ioredis','../../components/parsers/qs','../../config/logger','../../config/environment','../../config/environment/shared','../../mysqldb','redis','socket.io-emitter','./cmContact.socket','status','undefined','limit','count','offset','Content-Range','json','update','then','destroy','end','sendStatus','error','name','send','index','CmContact','describe','keys','length','startsWith','push','CmCustomField','trimStart','cf_','all','fieldType','model','query','fields','attributes','nolimit','order','sort','where','filters','pick','select','field','color','cm_contacts','cm_user_has_contacts','uc.CmContactId\x20=\x20c.id','left_join','ct.CmContactId\x20=\x20c.id','tools_tags','t.id\x20=\x20ct.TagId','c.deletedAt\x20IS\x20NULL','expr','search','parseSearch','sqlOperator','conditions','value','split','map','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','and','dateOfBirth','datetime','castTo','DATE','buildExpression','type','text','start','filter','isNil','Contact','isEmpty','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','replace','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','c.id','QueryTypes','SELECT','clone','DESC','having','t.id\x20IN\x20?','resolve','user','role','some','getLists','c.ListId\x20IS\x20NULL','agent','sequelize','toString','keyBy','merge','c.firstName','c.phone','c.mobile','c.fax','c.email','c.ListId','c.createdAt','c.deletedAt','TagIds','Tags','catch','find','params','columnName','displayName','analytics','findAll','alias','values','body','from','get','mergeWith','isArray','tags','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','ChatInteraction','ChatMessage','MailMessage','MailInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelInteraction','CmHopperFinal','CmHopperHistory','ReportAgentPreview','VoiceCallReport','MailQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','join','dialTimezone','timezones','utcOffset','bulkCreate','each','duplicates','$or','spread','show','omit','format','cf_%d','$and','pickBy','table','setFields','id\x20=\x20?','toParam','phone','getTags','Tag','rawAttributes','intersection','setTags','findOne','ids','getHoppers','hasOwnProperty','ContactId','options','include','getHopperHistories','rows','getHopperFinals','getJscriptySessions','includeAll','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','socket_timestamp'];(function(_0x5027b1,_0x1409a5){var _0x4a46cf=function(_0x121920){while(--_0x121920){_0x5027b1['push'](_0x5027b1['shift']());}};_0x4a46cf(++_0x1409a5);}(_0x3d2e,0x169));var _0xe3d2=function(_0x1c1ecc,_0x52ca15){_0x1c1ecc=_0x1c1ecc-0x0;var _0x39e611=_0x3d2e[_0x1c1ecc];return _0x39e611;};'use strict';var moment=require('moment');var BPromise=require(_0xe3d2('0x0'));var util=require(_0xe3d2('0x1'));var path=require(_0xe3d2('0x2'));var fs=require('fs');var _=require(_0xe3d2('0x3'));var squel=require(_0xe3d2('0x4'));var Papa=require(_0xe3d2('0x5'));var Redis=require(_0xe3d2('0x6'));var qs=require(_0xe3d2('0x7'));var as=require('../../components/parsers/advancedSearch');var logger=require(_0xe3d2('0x8'))('api');var config=require(_0xe3d2('0x9'));var shared=require(_0xe3d2('0xa'));var db=require(_0xe3d2('0xb'))['db'];config[_0xe3d2('0xc')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xe3d2('0xd'))(new Redis(config['redis']));require(_0xe3d2('0xe'))['register'](socket);function respondWithResult(_0x1dd6b0,_0x3dacf1){_0x3dacf1=_0x3dacf1||0xc8;return function(_0xf3db8f){if(_0xf3db8f){return _0x1dd6b0[_0xe3d2('0xf')](_0x3dacf1)['json'](_0xf3db8f);}};}function respondWithFilteredResult(_0x5bbdab,_0x220847){return function(_0x223b40){if(_0x223b40){var _0x1a1465=typeof _0x220847['offset']===_0xe3d2('0x10')&&typeof _0x220847[_0xe3d2('0x11')]===_0xe3d2('0x10');var _0x331df1=_0x223b40[_0xe3d2('0x12')];var _0xa1e846=_0x1a1465?0x0:_0x220847['offset'];var _0x249e35=_0x1a1465?_0x223b40[_0xe3d2('0x12')]:_0x220847[_0xe3d2('0x13')]+_0x220847[_0xe3d2('0x11')];var _0x589f24;if(_0x249e35>=_0x331df1){_0x249e35=_0x331df1;_0x589f24=0xc8;}else{_0x589f24=0xce;}_0x5bbdab[_0xe3d2('0xf')](_0x589f24);return _0x5bbdab['set'](_0xe3d2('0x14'),_0xa1e846+'-'+_0x249e35+'/'+_0x331df1)[_0xe3d2('0x15')](_0x223b40);}return null;};}function saveUpdates(_0x1efabc){return function(_0x13b5e2){if(_0x13b5e2){return _0x13b5e2[_0xe3d2('0x16')](_0x1efabc)[_0xe3d2('0x17')](function(_0x577c60){return _0x577c60;});}return null;};}function removeEntity(_0x2e006c){return function(_0x4bd9a2){if(_0x4bd9a2){return _0x4bd9a2[_0xe3d2('0x18')]()[_0xe3d2('0x17')](function(){_0x2e006c[_0xe3d2('0xf')](0xcc)[_0xe3d2('0x19')]();});}};}function handleEntityNotFound(_0xe188e9){return function(_0xfad5a4){if(!_0xfad5a4){_0xe188e9[_0xe3d2('0x1a')](0x194);}return _0xfad5a4;};}function handleError(_0x277a27,_0x2d8d44){_0x2d8d44=_0x2d8d44||0x1f4;return function(_0x2926d3){logger[_0xe3d2('0x1b')](_0x2926d3['stack']);if(_0x2926d3[_0xe3d2('0x1c')]){delete _0x2926d3[_0xe3d2('0x1c')];}_0x277a27[_0xe3d2('0xf')](_0x2d8d44)[_0xe3d2('0x1d')](_0x2926d3);};}exports[_0xe3d2('0x1e')]=function(_0x196a45,_0x1433eb){var _0x557487={},_0x4023f4={},_0x583824={'count':0x0,'rows':[]};return db[_0xe3d2('0x1f')][_0xe3d2('0x20')]()[_0xe3d2('0x17')](function(_0x1acafa){var _0x3a598e=[];for(var _0x1e9ecd=0x0;_0x1e9ecd<Object[_0xe3d2('0x21')](_0x1acafa)[_0xe3d2('0x22')];_0x1e9ecd++){var _0x502b15=Object[_0xe3d2('0x21')](_0x1acafa)[_0x1e9ecd];if(_[_0xe3d2('0x23')](_0x502b15,'cf_')){_0x3a598e[_0xe3d2('0x24')](db[_0xe3d2('0x25')]['findOne']({'where':{'id':_[_0xe3d2('0x26')](_0x502b15,_0xe3d2('0x27'))},'raw':!![]}));}}return BPromise[_0xe3d2('0x28')](_0x3a598e)[_0xe3d2('0x17')](function(_0x1520af){for(var _0x23f91c=0x0;_0x23f91c<_0x1520af['length'];_0x23f91c++){if(_0x1520af[_0x23f91c]){var _0x11b91f=_0xe3d2('0x27')+_0x1520af[_0x23f91c]['id'];var _0x2300b5=_0x1acafa[_0x11b91f];_0x2300b5[_0xe3d2('0x29')]=_0x1520af[_0x23f91c]['type'];}}return _0x1acafa;});})[_0xe3d2('0x17')](function(_0x492d72){_0x4023f4[_0xe3d2('0x2a')]=_[_0xe3d2('0x21')](_0x492d72);_0x4023f4[_0xe3d2('0x2b')]=_['keys'](_0x196a45[_0xe3d2('0x2b')]);_0x4023f4['filters']=_['intersection'](_0x4023f4['model'],_0x4023f4['query']);_0x557487['attributes']=_['intersection'](_0x4023f4[_0xe3d2('0x2a')],qs['fields'](_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x2c')]));_0x557487[_0xe3d2('0x2d')]=_0x557487[_0xe3d2('0x2d')][_0xe3d2('0x22')]?_0x557487[_0xe3d2('0x2d')]:_0x4023f4['model'];if(!_0x196a45[_0xe3d2('0x2b')]['hasOwnProperty'](_0xe3d2('0x2e'))){_0x557487['limit']=qs[_0xe3d2('0x11')](_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x11')]);_0x557487[_0xe3d2('0x13')]=qs[_0xe3d2('0x13')](_0x196a45[_0xe3d2('0x2b')]['offset']);}_0x557487[_0xe3d2('0x2f')]=qs['sort'](_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x30')]);_0x557487[_0xe3d2('0x31')]=qs[_0xe3d2('0x32')](_[_0xe3d2('0x33')](_0x196a45['query'],_0x4023f4[_0xe3d2('0x32')]),_0x492d72);var _0x1ec4a6=[];var _0x3cbec7=squel[_0xe3d2('0x34')]()[_0xe3d2('0x35')]('id')[_0xe3d2('0x35')]('name')[_0xe3d2('0x35')](_0xe3d2('0x36'))['from']('tools_tags');var _0x387dae=squel[_0xe3d2('0x34')]()['from'](_0xe3d2('0x37'),'c')['left_join'](_0xe3d2('0x38'),'uc',_0xe3d2('0x39'))[_0xe3d2('0x3a')]('cm_contact_has_tags','ct',_0xe3d2('0x3b'))[_0xe3d2('0x3a')](_0xe3d2('0x3c'),'t',_0xe3d2('0x3d'))[_0xe3d2('0x31')](_0xe3d2('0x3e'));var _0xbff85d=squel[_0xe3d2('0x3f')]();var _0xa56ce4=[];var _0x2adb8a=squel[_0xe3d2('0x3f')]();var _0x17c3f5;if(_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x40')]){_0x17c3f5=as[_0xe3d2('0x41')](_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x40')]);var _0x262c4e=_0x17c3f5[_0xe3d2('0x42')];for(var _0x16f9c4=0x0;_0x16f9c4<_0x17c3f5[_0xe3d2('0x43')]['length'];_0x16f9c4++){var _0x17f368=_0x17c3f5[_0xe3d2('0x43')][_0x16f9c4];var _0x5d5355='c';var _0x266f37=_(_0x492d72)[_0xe3d2('0x21')]()['find'](function(_0x405374){return _0x405374===_0x17f368[_0xe3d2('0x35')];});if(_0x266f37)_0x266f37=_0x492d72[_0x17f368[_0xe3d2('0x35')]];if(!_0x266f37){if(_0x17f368['field']==='Tag'){var _0x4d1d51=_0x17f368[_0xe3d2('0x44')][_0xe3d2('0x45')](',')[_0xe3d2('0x46')](function(_0x3a78db){return Number(_0x3a78db);});_0x4d1d51[_0xe3d2('0x47')](function(_0x28bc2d){_0x2adb8a['or'](_0xe3d2('0x48'),'%,'+_0x28bc2d+',%');});_0xa56ce4=_[_0xe3d2('0x49')](_0xa56ce4,_0x4d1d51);}else if(_0x17f368['field']==='User'){_0xbff85d[_0xe3d2('0x4a')]('uc.UserId\x20=\x20?',_0x17f368[_0xe3d2('0x44')]);}}else{if(_0x17f368[_0xe3d2('0x35')]===_0xe3d2('0x4b')||_0x266f37[_0xe3d2('0x29')]===_0xe3d2('0x4c'))_0x17f368[_0xe3d2('0x4d')]=_0xe3d2('0x4e');var _0x33fa7a=as[_0xe3d2('0x4f')](_0x5d5355,_0x266f37[_0xe3d2('0x50')],_0x17f368);_0xbff85d[_0x262c4e](_0x33fa7a[_0xe3d2('0x51')],_0x33fa7a['value'][_0xe3d2('0x52')],_0x33fa7a[_0xe3d2('0x44')][_0xe3d2('0x19')]);}}}else{var _0x17eca5=_(Object[_0xe3d2('0x21')](_0x196a45['query']))[_0xe3d2('0x46')](function(_0x5ccae1){return _0x492d72['hasOwnProperty'](_0x5ccae1)?_0x5ccae1:undefined;})[_0xe3d2('0x53')](function(_0x1f80a4){return!_[_0xe3d2('0x54')](_0x1f80a4);})[_0xe3d2('0x44')]();if(_0x196a45['query'][_0xe3d2('0x55')])_0x17eca5['push']('Contact');if(!_[_0xe3d2('0x56')](_0x17eca5)){_0x17eca5['forEach'](function(_0x10e77a){if(_0x10e77a===_0xe3d2('0x57')){_0x387dae[_0xe3d2('0x31')](_0xe3d2('0x58'),[][_0xe3d2('0x59')](_0x196a45[_0xe3d2('0x2b')][_0x10e77a]));}else if(_0x10e77a==='Contact'){var _0x4065b5='%'+_0x196a45[_0xe3d2('0x2b')][_0x10e77a]+'%';_0x387dae[_0xe3d2('0x31')](_0xe3d2('0x5a'),_0x4065b5);}else{_0x387dae[_0xe3d2('0x31')]('c.'+_0x10e77a+_0xe3d2('0x5b'),_0x196a45[_0xe3d2('0x2b')][_0x10e77a]);}});}if(_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x5c')]){_0xa56ce4=_['isArray'](_0x196a45['query'][_0xe3d2('0x5c')])?_0x196a45['query'][_0xe3d2('0x5c')]:new Array(_0x196a45['query'][_0xe3d2('0x5c')]);_0xa56ce4[_0xe3d2('0x47')](function(_0x3d809f){_0x2adb8a['or'](_0xe3d2('0x48'),'%,'+_0x3d809f+',%');});}if(_0x196a45[_0xe3d2('0x2b')]['filter']){var _0x5d4dcb=_0x196a45[_0xe3d2('0x2b')][_0xe3d2('0x53')][_0xe3d2('0x5d')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(_0x5d4dcb[_0xe3d2('0x45')]('\x20')['length']>0x1){_0xbff85d['or'](_0xe3d2('0x5e'),qs['getFullTextValue'](_0x5d4dcb),null);}else{if(qs[_0xe3d2('0x5f')](_0x5d4dcb)){_0xbff85d['or'](_0xe3d2('0x60'),_0x5d4dcb+'%');_0xbff85d['or'](_0xe3d2('0x61'),_0x5d4dcb+'%');_0xbff85d['or'](_0xe3d2('0x62'),_0x5d4dcb+'%');_0xbff85d['or'](_0xe3d2('0x63'),_0x5d4dcb+'%');}else if(qs[_0xe3d2('0x64')](_0x5d4dcb)){_0xbff85d['or'](_0xe3d2('0x65'),_0x5d4dcb+'%');}else{_0xbff85d['or'](_0xe3d2('0x66'),'%'+_0x5d4dcb+'%');_0xbff85d['or'](_0xe3d2('0x67'),'%'+_0x5d4dcb+'%');_0xbff85d['or'](_0xe3d2('0x65'),'%'+_0x5d4dcb+'%');}}}}_0x387dae['where'](_0xbff85d);_0x387dae['group'](_0xe3d2('0x68'));var _0x119f6c={'type':db['Sequelize'][_0xe3d2('0x69')][_0xe3d2('0x6a')],'raw':!![]};var _0x2f17fe=_0x387dae[_0xe3d2('0x6b')]()[_0xe3d2('0x35')](_0xe3d2('0x68'));if(_0x557487['order']){_0x557487['order'][_0xe3d2('0x47')](function(_0xc345e0){_0x387dae['order']('c.'+_0xc345e0[0x0],_0xc345e0[0x1]===_0xe3d2('0x6c')?![]:!![]);});}if(!_[_0xe3d2('0x56')](_0xa56ce4)){_0x387dae[_0xe3d2('0x6d')](_0x2adb8a);_0x2f17fe[_0xe3d2('0x31')](_0xe3d2('0x6e'),_0xa56ce4);}BPromise[_0xe3d2('0x6f')]()[_0xe3d2('0x17')](function(){if(!_0x17c3f5)return;if(_0x196a45[_0xe3d2('0x70')][_0xe3d2('0x71')]!=='agent')return;if(!_[_0xe3d2('0x72')](_0x17c3f5[_0xe3d2('0x43')],[_0xe3d2('0x35'),'User'])){return _0x196a45[_0xe3d2('0x70')][_0xe3d2('0x73')]({'attributes':['id'],'raw':!![]})[_0xe3d2('0x17')](function(_0x40d766){if(_['isEmpty'](_0x40d766)){_0x2f17fe[_0xe3d2('0x31')](_0xe3d2('0x74'));_0x387dae['where']('c.ListId\x20IS\x20NULL');}else{_0x2f17fe[_0xe3d2('0x31')](_0xe3d2('0x58'),_[_0xe3d2('0x46')](_0x40d766,'id'));_0x387dae[_0xe3d2('0x31')](_0xe3d2('0x58'),_['map'](_0x40d766,'id'));}});}})[_0xe3d2('0x17')](function(){if(_0x196a45[_0xe3d2('0x70')][_0xe3d2('0x71')]===_0xe3d2('0x75')&&!_0x17c3f5&&!_0x196a45[_0xe3d2('0x2b')]['ListId'])return[];return db[_0xe3d2('0x76')][_0xe3d2('0x2b')](_0x2f17fe[_0xe3d2('0x77')](),_0x119f6c);})[_0xe3d2('0x17')](function(_0x3e8816){_0x583824[_0xe3d2('0x12')]=_0x3e8816['length'];if(_0x583824[_0xe3d2('0x12')]===0x0)return[];return db[_0xe3d2('0x76')][_0xe3d2('0x2b')](_0x3cbec7[_0xe3d2('0x77')](),_0x119f6c)[_0xe3d2('0x17')](function(_0x4a4b1a){_0x1ec4a6=_[_0xe3d2('0x78')](_0x4a4b1a,'id');_0x119f6c=_[_0xe3d2('0x79')](_0x119f6c,{'model':db[_0xe3d2('0x1f')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x196a45['query'][_0xe3d2('0x2c')]){_0x557487[_0xe3d2('0x2d')][_0xe3d2('0x47')](function(_0x2f7edf){_0x387dae['field']('c.'+_0x2f7edf);});}else{_0x387dae['field']('c.id');_0x387dae[_0xe3d2('0x35')](_0xe3d2('0x7a'));_0x387dae[_0xe3d2('0x35')]('c.lastName');_0x387dae['field'](_0xe3d2('0x7b'));_0x387dae[_0xe3d2('0x35')](_0xe3d2('0x7c'));_0x387dae['field'](_0xe3d2('0x7d'));_0x387dae[_0xe3d2('0x35')](_0xe3d2('0x7e'));_0x387dae[_0xe3d2('0x35')](_0xe3d2('0x7f'));_0x387dae['field'](_0xe3d2('0x80'));_0x387dae[_0xe3d2('0x35')](_0xe3d2('0x81'));_0x387dae[_0xe3d2('0x35')]('c.CompanyId');_0x387dae[_0xe3d2('0x35')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0xe3d2('0x82'));}if(_0x557487[_0xe3d2('0x11')])_0x387dae['limit'](_0x557487['limit']);if(_0x557487[_0xe3d2('0x13')])_0x387dae[_0xe3d2('0x13')](_0x557487[_0xe3d2('0x13')]);return db[_0xe3d2('0x76')][_0xe3d2('0x2b')](_0x387dae['toString'](),_0x119f6c);});})[_0xe3d2('0x17')](function(_0x598b77){_0x598b77['forEach'](function(_0x4e8540){if(_0x4e8540[_0xe3d2('0x82')]){_0x4e8540[_0xe3d2('0x83')]=[];_0x4e8540[_0xe3d2('0x82')]['split'](',')[_0xe3d2('0x47')](function(_0x4e6d52){_0x4e8540[_0xe3d2('0x83')][_0xe3d2('0x24')](_0x1ec4a6[_0x4e6d52]);});}delete _0x4e8540[_0xe3d2('0x82')];});_0x583824['rows']=_0x598b77;return _0x583824;})[_0xe3d2('0x17')](respondWithFilteredResult(_0x1433eb,_0x557487));})[_0xe3d2('0x84')](handleError(_0x1433eb,null));};exports[_0xe3d2('0x18')]=function(_0x138189,_0x1f4032){return db[_0xe3d2('0x1f')][_0xe3d2('0x85')]({'where':{'id':_0x138189[_0xe3d2('0x86')]['id']}})[_0xe3d2('0x17')](handleEntityNotFound(_0x1f4032,null))[_0xe3d2('0x17')](removeEntity(_0x1f4032,null))[_0xe3d2('0x84')](handleError(_0x1f4032,null));};exports[_0xe3d2('0x20')]=function(_0x885635,_0x151854){return db[_0xe3d2('0x1f')][_0xe3d2('0x20')]()['then'](function(_0x3fc14a){delete _0x3fc14a['tags'];for(var _0x18281d=0x0;_0x18281d<Object['keys'](_0x3fc14a)[_0xe3d2('0x22')];_0x18281d++){var _0x3e1933=Object[_0xe3d2('0x21')](_0x3fc14a)[_0x18281d];if(!_['startsWith'](_0x3e1933,'cf_')){_0x3fc14a[_0x3e1933][_0xe3d2('0x87')]=_0x3e1933;_0x3fc14a[_0x3e1933][_0xe3d2('0x88')]=_0x3e1933;}}return _0x3fc14a;})[_0xe3d2('0x17')](function(_0x4e06da){var _0x4204cf={'where':Boolean(_0x885635[_0xe3d2('0x2b')][_0xe3d2('0x89')])===!![]?undefined:{'$or':[{'ListId':_0x885635[_0xe3d2('0x2b')]['id']},{'ListId':null}]},'raw':!![]};return db['CmCustomField'][_0xe3d2('0x8a')](_0x4204cf)[_0xe3d2('0x17')](function(_0x10990c){for(var _0x2962f9=0x0;_0x2962f9<_0x10990c[_0xe3d2('0x22')];_0x2962f9++){var _0x30418b=_0xe3d2('0x27')+_0x10990c[_0x2962f9]['id'];_0x4e06da[_0x30418b][_0xe3d2('0x87')]=_0x30418b;_0x4e06da[_0x30418b]['displayName']=_0x10990c[_0x2962f9][_0xe3d2('0x8b')];_0x4e06da[_0x30418b]['custom']={'type':_0x10990c[_0x2962f9][_0xe3d2('0x50')],'values':_0x10990c[_0x2962f9][_0xe3d2('0x8c')]};}Object[_0xe3d2('0x21')](_0x4e06da)['forEach'](function(_0x59346d){if(!_0x4e06da[_0x59346d]['hasOwnProperty']('columnName')){delete _0x4e06da[_0x59346d];}});return _0x4e06da;});})[_0xe3d2('0x17')](respondWithResult(_0x151854,null))['catch'](handleError(_0x151854,null));};exports[_0xe3d2('0x79')]=function(_0xaaf650,_0x2669a4){var _0x3c3c9a;var _0x5cb850;var _0x3e2f5a;if(_0xaaf650[_0xe3d2('0x8d')]['id']){delete _0xaaf650[_0xe3d2('0x8d')]['id'];}return db[_0xe3d2('0x1f')][_0xe3d2('0x8a')]({'where':{'id':[_0xaaf650['body']['to'],_0xaaf650[_0xe3d2('0x8d')][_0xe3d2('0x8e')]]}})[_0xe3d2('0x17')](function(_0x48bc5c){if(_0x48bc5c){if(_0x48bc5c[_0xe3d2('0x22')]!==0x2){return null;}_0x48bc5c[0x0]=_0x48bc5c[0x0][_0xe3d2('0x8f')]({'plain':!![]});_0x48bc5c[0x1]=_0x48bc5c[0x1][_0xe3d2('0x8f')]({'plain':!![]});delete _0x48bc5c[0x0]['id'];delete _0x48bc5c[0x1]['id'];return _[_0xe3d2('0x90')](_0x48bc5c[0x0],_0x48bc5c[0x1],function(_0x5d155e,_0xc02ea7){if(Array[_0xe3d2('0x91')](_0xc02ea7)&&!_0xc02ea7[_0xe3d2('0x22')]){return _0x5d155e;}else if(!_0xc02ea7){return _0x5d155e;}});}})[_0xe3d2('0x17')](handleEntityNotFound(_0x2669a4,null))[_0xe3d2('0x17')](function(_0x48687d){if(_0x48687d){if(_0x48687d[_0xe3d2('0x92')]&&_['isArray'](_0x48687d['tags'])){_0x48687d[_0xe3d2('0x92')]=_0x48687d[_0xe3d2('0x92')]['join']();}logger[_0xe3d2('0x93')](_0xe3d2('0x94'),_0xaaf650[_0xe3d2('0x8d')]['to'],_0xaaf650[_0xe3d2('0x8d')]['from']);return db[_0xe3d2('0x95')][_0xe3d2('0x18')]({'where':{'ContactId':[_0xaaf650[_0xe3d2('0x8d')]['to'],_0xaaf650[_0xe3d2('0x8d')]['from']]}})[_0xe3d2('0x17')](function(_0x9ffb23){logger[_0xe3d2('0x93')]('[CmContact][merge][destroy][CmHopper],\x20%s',_0x9ffb23);return db[_0xe3d2('0x96')][_0xe3d2('0x18')]({'where':{'ContactId':[_0xaaf650['body']['to'],_0xaaf650['body'][_0xe3d2('0x8e')]]}})[_0xe3d2('0x17')](function(_0xf0d25e){logger['info'](_0xe3d2('0x97'),_0xf0d25e);return db[_0xe3d2('0x1f')][_0xe3d2('0x98')](_0x48687d);});});}})['then'](function(_0x145992){if(_0x145992){_0x3c3c9a=_0x145992;_0x5cb850={'ContactId':_0x3c3c9a['id']};_0x3e2f5a={'where':{'ContactId':[_0xaaf650[_0xe3d2('0x8d')]['to'],_0xaaf650[_0xe3d2('0x8d')]['from']]}};return db[_0xe3d2('0x99')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0x9a')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})['then'](function(){if(_0x3c3c9a){return db['ChatOfflineMessage'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db['MailInteraction'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})['then'](function(){if(_0x3c3c9a){return db[_0xe3d2('0x9b')]['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0x9c')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db['MailMessage'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db['SmsInteraction'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0x9d')]['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0x9e')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0x9f')]['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa0')]['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db['OpenchannelMessage'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa1')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa2')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa3')]['update'](_0x5cb850,_0x3e2f5a);}})['then'](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa4')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db['ChatQueueReport'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db['FaxQueueReport']['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa5')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})['then'](function(){if(_0x3c3c9a){return db['OpenchannelQueueReport'][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})['then'](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa6')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa7')]['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa8')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})['then'](function(){if(_0x3c3c9a){return db[_0xe3d2('0xa9')]['update'](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0xaa')][_0xe3d2('0x16')](_0x5cb850,_0x3e2f5a);}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return db[_0xe3d2('0x1f')][_0xe3d2('0x18')]({'where':{'id':[_0xaaf650[_0xe3d2('0x8d')]['to'],_0xaaf650['body'][_0xe3d2('0x8e')]]}});}})[_0xe3d2('0x17')](function(){if(_0x3c3c9a){return _0x3c3c9a;}})[_0xe3d2('0x17')](respondWithResult(_0x2669a4,null))[_0xe3d2('0x84')](handleError(_0x2669a4,null));};exports[_0xe3d2('0x98')]=function(_0x3c7622,_0x116699){return db['CmContact'][_0xe3d2('0x20')]()[_0xe3d2('0x17')](function(_0x36abed){if(_0x3c7622[_0xe3d2('0x8d')][_0xe3d2('0x92')]&&_[_0xe3d2('0x91')](_0x3c7622[_0xe3d2('0x8d')][_0xe3d2('0x92')])){if(_0x3c7622[_0xe3d2('0x8d')][_0xe3d2('0x92')][_0xe3d2('0x22')]){_0x3c7622[_0xe3d2('0x8d')]['tags']=_0x3c7622[_0xe3d2('0x8d')]['tags'][_0xe3d2('0xab')](';')+';';}else{_0x3c7622[_0xe3d2('0x8d')]['tags']=null;}}else{_0x3c7622['body'][_0xe3d2('0x92')]=null;}if(!_[_0xe3d2('0x54')](_0x3c7622['body'][_0xe3d2('0xac')])){var _0x15b2b8=_0x3c7622[_0xe3d2('0x8d')]['dialTimezone'];if(!_[_0xe3d2('0x54')](shared[_0xe3d2('0xad')][_0x15b2b8]))_0x3c7622[_0xe3d2('0x8d')][_0xe3d2('0xae')]=shared[_0xe3d2('0xad')][_0x15b2b8][_0xe3d2('0xae')];}return db[_0xe3d2('0x1f')][_0xe3d2('0x98')](_0x3c7622[_0xe3d2('0x8d')],{'fields':_['keys'](_0x36abed),'raw':!![]});})[_0xe3d2('0x17')](respondWithResult(_0x116699,0xc9))[_0xe3d2('0x84')](handleError(_0x116699,null));};exports[_0xe3d2('0xaf')]=function(_0x17d115,_0x208162){var _0x1e665c=0x0;var _0x47a214=0x0;var _0x4a5fab=0x0;return db[_0xe3d2('0x1f')][_0xe3d2('0x20')]()[_0xe3d2('0x17')](function(_0x104263){return BPromise[_0xe3d2('0xb0')](_0x17d115[_0xe3d2('0x8d')],function(_0x4ab502){var _0x1e6d8b={'where':{'$or':[]},'defaults':_0x4ab502,'fields':_[_0xe3d2('0x21')](_0x104263),'raw':!![]};if(_0x4ab502['duplicates']){for(var _0x58efb8=0x0;_0x58efb8<_0x4ab502[_0xe3d2('0xb1')][_0xe3d2('0x22')];_0x58efb8++){var _0x80a4bb={};_0x80a4bb[_0x4ab502['duplicates'][_0x58efb8]]=_0x4ab502[_0x4ab502[_0xe3d2('0xb1')][_0x58efb8]];_0x1e6d8b[_0xe3d2('0x31')][_0xe3d2('0xb2')][_0xe3d2('0x24')](_0x80a4bb);}_0x1e6d8b['where'][_0xe3d2('0x57')]=_0x4ab502[_0xe3d2('0x57')];}return db['CmContact']['findOrCreate'](_0x1e6d8b)[_0xe3d2('0xb3')](function(_0x5e38ca,_0x1b2928){if(_0x1b2928){_0x1e665c++;}else{_0x4a5fab++;}})[_0xe3d2('0x84')](function(){_0x47a214++;});});})[_0xe3d2('0x17')](function(_0x49bea8){if(_0x49bea8){return{'success':_0x1e665c,'failure':_0x47a214,'duplicates':_0x4a5fab};}})[_0xe3d2('0x17')](respondWithResult(_0x208162,0xc9))[_0xe3d2('0x84')](handleError(_0x208162,null));};exports[_0xe3d2('0xb4')]=function(_0xddc0ae,_0x1d7e5f){var _0x280a2b;return db['CmContact'][_0xe3d2('0x20')]()[_0xe3d2('0x17')](function(_0x520e43){return db[_0xe3d2('0x1f')]['find']({'where':{'id':_0xddc0ae[_0xe3d2('0x86')]['id']},'include':[{'model':db['Tag'],'as':_0xe3d2('0x83'),'attributes':['id',_0xe3d2('0x1c'),_0xe3d2('0x36')],'required':_0xddc0ae[_0xe3d2('0x2b')][_0xe3d2('0x5c')]?!![]:![]}],'attributes':_[_0xe3d2('0x21')](_0x520e43)});})[_0xe3d2('0x17')](function(_0x3716cc){if(!_[_0xe3d2('0x54')](_0x3716cc)){_0x280a2b=_0x3716cc[_0xe3d2('0x8f')]({'plain':!![]});var _0xc9234e={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x3716cc&&_0x3716cc[_0xe3d2('0x57')]){if(_0x3716cc[_0xe3d2('0x57')]){_0xc9234e[_0xe3d2('0x31')]['$and']['push']({'ListId':{'$ne':_0x3716cc['ListId']}});}}return db['CmCustomField']['findAll'](_0xc9234e);}})[_0xe3d2('0x17')](function(_0x3d342){if(!_[_0xe3d2('0x54')](_0x3d342)){return _[_0xe3d2('0xb5')](_0x280a2b,_[_0xe3d2('0x46')](_0x3d342,function(_0x1ca50a){return util[_0xe3d2('0xb6')](_0xe3d2('0xb7'),_0x1ca50a['id']);}));}})[_0xe3d2('0x17')](handleEntityNotFound(_0x1d7e5f,null))[_0xe3d2('0x17')](respondWithResult(_0x1d7e5f,null))[_0xe3d2('0x84')](handleError(_0x1d7e5f,null));};exports['update']=function(_0x2484d9,_0x3ee32d){var _0x438cdc;if(_0x2484d9[_0xe3d2('0x8d')]['id']){delete _0x2484d9[_0xe3d2('0x8d')]['id'];}if(!_[_0xe3d2('0x54')](_0x2484d9['body'][_0xe3d2('0xac')])){var _0x4fcff9=_0x2484d9[_0xe3d2('0x8d')][_0xe3d2('0xac')];if(!_[_0xe3d2('0x54')](shared[_0xe3d2('0xad')][_0x4fcff9]))_0x2484d9[_0xe3d2('0x8d')][_0xe3d2('0xae')]=shared['timezones'][_0x4fcff9][_0xe3d2('0xae')];}return db[_0xe3d2('0x1f')][_0xe3d2('0x85')]({'where':{'id':_0x2484d9[_0xe3d2('0x86')]['id']}})[_0xe3d2('0x17')](handleEntityNotFound(_0x3ee32d,null))[_0xe3d2('0x17')](saveUpdates(_0x2484d9[_0xe3d2('0x8d')],null))['then'](function(_0x45b771){_0x438cdc=_0x45b771;var _0x1cf09a={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x45b771&&_0x45b771['ListId']){if(_0x45b771[_0xe3d2('0x57')]){_0x1cf09a[_0xe3d2('0x31')][_0xe3d2('0xb8')][_0xe3d2('0x24')]({'ListId':{'$ne':_0x45b771['ListId']}});}}return db[_0xe3d2('0x25')]['findAll'](_0x1cf09a);})['then'](function(_0x3ee1ec){if(_0x3ee1ec){return _[_0xe3d2('0xb5')](_[_0xe3d2('0xb9')](_0x2484d9['body'],function(_0x5d8ed4,_0x276c1d){return _[_0xe3d2('0x23')](_0x276c1d,'cf_');}),_[_0xe3d2('0x46')](_0x3ee1ec,function(_0x5c0627){return util['format'](_0xe3d2('0xb7'),_0x5c0627['id']);}));}})['then'](function(_0x59d9e9){if(_0x59d9e9&&!_[_0xe3d2('0x56')](_0x59d9e9)){var _0x43848e=squel[_0xe3d2('0x16')]()[_0xe3d2('0xba')](_0xe3d2('0x37'))[_0xe3d2('0xbb')](_0x59d9e9)[_0xe3d2('0x31')](_0xe3d2('0xbc'),_0x2484d9[_0xe3d2('0x86')]['id'])[_0xe3d2('0xbd')]();return db[_0xe3d2('0x76')][_0xe3d2('0x2b')](_0x43848e['text'],{'replacements':_0x43848e[_0xe3d2('0x8c')]});}})[_0xe3d2('0x17')](function(){if(_0x2484d9[_0xe3d2('0x8d')][_0xe3d2('0xbe')]&&_0x438cdc){return db[_0xe3d2('0x95')][_0xe3d2('0x16')]({'phone':_0x2484d9['body'][_0xe3d2('0xbe')]},{'where':{'ContactId':_0x438cdc['id']}});}})['then'](function(){return _0x438cdc;})[_0xe3d2('0x17')](respondWithResult(_0x3ee32d,null))[_0xe3d2('0x84')](handleError(_0x3ee32d,null));};exports[_0xe3d2('0xbf')]=function(_0x348668,_0x594bee){var _0x3249bb={};var _0x4dca77={};var _0x5da1b8;var _0x1541e7;return db['CmContact']['findOne']({'where':{'id':_0x348668[_0xe3d2('0x86')]['id']}})[_0xe3d2('0x17')](handleEntityNotFound(_0x594bee,null))[_0xe3d2('0x17')](function(_0x1347ef){if(_0x1347ef){_0x5da1b8=_0x1347ef;_0x4dca77[_0xe3d2('0x2a')]=_['keys'](db[_0xe3d2('0xc0')][_0xe3d2('0xc1')]);_0x4dca77[_0xe3d2('0x2b')]=_[_0xe3d2('0x21')](_0x348668[_0xe3d2('0x2b')]);_0x4dca77[_0xe3d2('0x32')]=_[_0xe3d2('0xc2')](_0x4dca77[_0xe3d2('0x2a')],_0x4dca77['query']);_0x3249bb['attributes']=_['intersection'](_0x4dca77['model'],qs[_0xe3d2('0x2c')](_0x348668[_0xe3d2('0x2b')][_0xe3d2('0x2c')]));_0x3249bb[_0xe3d2('0x2d')]=_0x3249bb[_0xe3d2('0x2d')][_0xe3d2('0x22')]?_0x3249bb[_0xe3d2('0x2d')]:_0x4dca77['model'];_0x3249bb[_0xe3d2('0x2f')]=qs[_0xe3d2('0x30')](_0x348668[_0xe3d2('0x2b')][_0xe3d2('0x30')]);_0x3249bb[_0xe3d2('0x31')]=qs['filters'](_['pick'](_0x348668[_0xe3d2('0x2b')],_0x4dca77[_0xe3d2('0x32')]));if(_0x348668[_0xe3d2('0x2b')][_0xe3d2('0x53')]){_0x3249bb[_0xe3d2('0x31')]=_[_0xe3d2('0x79')](_0x3249bb['where'],{'$or':_[_0xe3d2('0x46')](_0x3249bb[_0xe3d2('0x2d')],function(_0x40404f){var _0x121c7a={};_0x121c7a[_0x40404f]={'$like':'%'+_0x348668['query'][_0xe3d2('0x53')]+'%'};return _0x121c7a;})});}_0x3249bb=_[_0xe3d2('0x79')]({},_0x3249bb,_0x348668['options']);return _0x5da1b8['getTags'](_0x3249bb);}})[_0xe3d2('0x17')](function(_0xf90f51){if(_0xf90f51){_0x1541e7=_0xf90f51[_0xe3d2('0x22')];if(!_0x348668[_0xe3d2('0x2b')]['hasOwnProperty'](_0xe3d2('0x2e'))){_0x3249bb[_0xe3d2('0x11')]=qs['limit'](_0x348668[_0xe3d2('0x2b')][_0xe3d2('0x11')]);_0x3249bb['offset']=qs[_0xe3d2('0x13')](_0x348668[_0xe3d2('0x2b')][_0xe3d2('0x13')]);}return _0x5da1b8['getTags'](_0x3249bb);}})[_0xe3d2('0x17')](function(_0x4d224e){if(_0x4d224e){return _0x4d224e?{'count':_0x1541e7,'rows':_0x4d224e}:null;}})[_0xe3d2('0x17')](respondWithResult(_0x594bee,null))[_0xe3d2('0x84')](handleError(_0x594bee,null));};exports[_0xe3d2('0xc3')]=function(_0x484f33,_0xab5b30){if(_0x484f33[_0xe3d2('0x8d')]['id']){delete _0x484f33[_0xe3d2('0x8d')]['id'];}return db[_0xe3d2('0x1f')][_0xe3d2('0xc4')]({'where':{'id':_0x484f33['params']['id']}})[_0xe3d2('0x17')](handleEntityNotFound(_0xab5b30,null))[_0xe3d2('0x17')](function(_0x464fa7){if(_0x464fa7){return _0x464fa7[_0xe3d2('0xc3')](_0x484f33[_0xe3d2('0x8d')][_0xe3d2('0xc5')]||[]);}return null;})[_0xe3d2('0x17')](respondWithResult(_0xab5b30,null))['catch'](handleError(_0xab5b30,null));};exports[_0xe3d2('0xc6')]=function(_0x26933e,_0x1a43a5){var _0x19fb0b={'raw':![],'where':{}};var _0x2c1d2b={};var _0x1e0b02={'count':0x0,'rows':[]};return db[_0xe3d2('0x1f')]['findOne']({'where':{'id':_0x26933e['params']['id']}})['then'](handleEntityNotFound(_0x1a43a5,null))[_0xe3d2('0x17')](function(_0xae7a3a){if(_0xae7a3a){_0x2c1d2b[_0xe3d2('0x2a')]=_[_0xe3d2('0x21')](db[_0xe3d2('0x95')]['rawAttributes']);_0x2c1d2b[_0xe3d2('0x2b')]=_[_0xe3d2('0x21')](_0x26933e[_0xe3d2('0x2b')]);_0x2c1d2b[_0xe3d2('0x32')]=_[_0xe3d2('0xc2')](_0x2c1d2b[_0xe3d2('0x2a')],_0x2c1d2b[_0xe3d2('0x2b')]);_0x19fb0b[_0xe3d2('0x2d')]=_[_0xe3d2('0xc2')](_0x2c1d2b[_0xe3d2('0x2a')],qs[_0xe3d2('0x2c')](_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0x2c')]));_0x19fb0b['attributes']=_0x19fb0b[_0xe3d2('0x2d')][_0xe3d2('0x22')]?_0x19fb0b[_0xe3d2('0x2d')]:_0x2c1d2b['model'];if(!_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0xc7')](_0xe3d2('0x2e'))){_0x19fb0b[_0xe3d2('0x11')]=qs[_0xe3d2('0x11')](_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0x11')]);_0x19fb0b['offset']=qs[_0xe3d2('0x13')](_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0x13')]);}_0x19fb0b['order']=qs['sort'](_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0x30')]);_0x19fb0b[_0xe3d2('0x31')]=qs['filters'](_[_0xe3d2('0x33')](_0x26933e[_0xe3d2('0x2b')],_0x2c1d2b[_0xe3d2('0x32')]));_0x19fb0b[_0xe3d2('0x31')][_0xe3d2('0xc8')]=_0xae7a3a['id'];if(_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0x53')]){_0x19fb0b[_0xe3d2('0x31')]=_['merge'](_0x19fb0b['where'],{'$or':_[_0xe3d2('0x46')](_0x19fb0b[_0xe3d2('0x2d')],function(_0xf06c98){var _0x4e03c7={};_0x4e03c7[_0xf06c98]={'$like':'%'+_0x26933e[_0xe3d2('0x2b')][_0xe3d2('0x53')]+'%'};return _0x4e03c7;})});}_0x19fb0b=_[_0xe3d2('0x79')]({},_0x19fb0b,_0x26933e[_0xe3d2('0xc9')]);return db[_0xe3d2('0x95')][_0xe3d2('0x12')]({'where':_0x19fb0b[_0xe3d2('0x31')]})['then'](function(_0x2effac){_0x1e0b02[_0xe3d2('0x12')]=_0x2effac;if(_0x26933e[_0xe3d2('0x2b')]['includeAll']){_0x19fb0b[_0xe3d2('0xca')]=[{'all':!![]}];}return db[_0xe3d2('0x95')][_0xe3d2('0x8a')](_0x19fb0b);})[_0xe3d2('0x17')](function(_0x150b61){_0x1e0b02['rows']=_0x150b61;return _0x1e0b02;});}})['then'](respondWithFilteredResult(_0x1a43a5,_0x19fb0b))[_0xe3d2('0x84')](handleError(_0x1a43a5,null));};exports[_0xe3d2('0xcb')]=function(_0x579071,_0x4eebc2){var _0x16aa98={'raw':!![],'where':{}};var _0x20eed1={};var _0x3219eb={'count':0x0,'rows':[]};return db[_0xe3d2('0x1f')][_0xe3d2('0xc4')]({'where':{'id':_0x579071['params']['id']}})[_0xe3d2('0x17')](handleEntityNotFound(_0x4eebc2,null))[_0xe3d2('0x17')](function(_0x53b0a6){if(_0x53b0a6){_0x20eed1[_0xe3d2('0x2a')]=_[_0xe3d2('0x21')](db[_0xe3d2('0xa2')]['rawAttributes']);_0x20eed1[_0xe3d2('0x2b')]=_[_0xe3d2('0x21')](_0x579071[_0xe3d2('0x2b')]);_0x20eed1[_0xe3d2('0x32')]=_[_0xe3d2('0xc2')](_0x20eed1[_0xe3d2('0x2a')],_0x20eed1[_0xe3d2('0x2b')]);_0x16aa98[_0xe3d2('0x2d')]=_[_0xe3d2('0xc2')](_0x20eed1[_0xe3d2('0x2a')],qs[_0xe3d2('0x2c')](_0x579071[_0xe3d2('0x2b')][_0xe3d2('0x2c')]));_0x16aa98[_0xe3d2('0x2d')]=_0x16aa98[_0xe3d2('0x2d')][_0xe3d2('0x22')]?_0x16aa98[_0xe3d2('0x2d')]:_0x20eed1[_0xe3d2('0x2a')];if(!_0x579071['query'][_0xe3d2('0xc7')](_0xe3d2('0x2e'))){_0x16aa98['limit']=qs['limit'](_0x579071['query'][_0xe3d2('0x11')]);_0x16aa98[_0xe3d2('0x13')]=qs['offset'](_0x579071[_0xe3d2('0x2b')][_0xe3d2('0x13')]);}_0x16aa98['order']=qs[_0xe3d2('0x30')](_0x579071[_0xe3d2('0x2b')][_0xe3d2('0x30')]);_0x16aa98[_0xe3d2('0x31')]=qs[_0xe3d2('0x32')](_[_0xe3d2('0x33')](_0x579071['query'],_0x20eed1[_0xe3d2('0x32')]));_0x16aa98[_0xe3d2('0x31')][_0xe3d2('0xc8')]=_0x53b0a6['id'];if(_0x579071[_0xe3d2('0x2b')][_0xe3d2('0x53')]){_0x16aa98[_0xe3d2('0x31')]=_[_0xe3d2('0x79')](_0x16aa98[_0xe3d2('0x31')],{'$or':_['map'](_0x16aa98[_0xe3d2('0x2d')],function(_0x52ccee){var _0x2c93e2={};_0x2c93e2[_0x52ccee]={'$like':'%'+_0x579071[_0xe3d2('0x2b')][_0xe3d2('0x53')]+'%'};return _0x2c93e2;})});}_0x16aa98=_[_0xe3d2('0x79')]({},_0x16aa98,_0x579071[_0xe3d2('0xc9')]);return db['CmHopperHistory']['count']({'where':_0x16aa98[_0xe3d2('0x31')]})['then'](function(_0x1dea79){_0x3219eb[_0xe3d2('0x12')]=_0x1dea79;if(_0x579071['query']['includeAll']){_0x16aa98['include']=[{'all':!![]}];}return db['CmHopperHistory'][_0xe3d2('0x8a')](_0x16aa98);})[_0xe3d2('0x17')](function(_0x58b396){_0x3219eb[_0xe3d2('0xcc')]=_0x58b396;return _0x3219eb;});}})[_0xe3d2('0x17')](respondWithFilteredResult(_0x4eebc2,_0x16aa98))[_0xe3d2('0x84')](handleError(_0x4eebc2,null));};exports[_0xe3d2('0xcd')]=function(_0x334394,_0x4b731a){var _0x8f96c2={'raw':!![],'where':{}};var _0xcd755c={};var _0xef2186={'count':0x0,'rows':[]};return db[_0xe3d2('0x1f')][_0xe3d2('0xc4')]({'where':{'id':_0x334394[_0xe3d2('0x86')]['id']}})[_0xe3d2('0x17')](handleEntityNotFound(_0x4b731a,null))[_0xe3d2('0x17')](function(_0x6ebb58){if(_0x6ebb58){_0xcd755c[_0xe3d2('0x2a')]=_['keys'](db[_0xe3d2('0xa1')][_0xe3d2('0xc1')]);_0xcd755c[_0xe3d2('0x2b')]=_['keys'](_0x334394['query']);_0xcd755c[_0xe3d2('0x32')]=_[_0xe3d2('0xc2')](_0xcd755c[_0xe3d2('0x2a')],_0xcd755c[_0xe3d2('0x2b')]);_0x8f96c2[_0xe3d2('0x2d')]=_[_0xe3d2('0xc2')](_0xcd755c[_0xe3d2('0x2a')],qs[_0xe3d2('0x2c')](_0x334394['query']['fields']));_0x8f96c2[_0xe3d2('0x2d')]=_0x8f96c2[_0xe3d2('0x2d')][_0xe3d2('0x22')]?_0x8f96c2[_0xe3d2('0x2d')]:_0xcd755c[_0xe3d2('0x2a')];if(!_0x334394[_0xe3d2('0x2b')][_0xe3d2('0xc7')](_0xe3d2('0x2e'))){_0x8f96c2[_0xe3d2('0x11')]=qs['limit'](_0x334394[_0xe3d2('0x2b')][_0xe3d2('0x11')]);_0x8f96c2[_0xe3d2('0x13')]=qs[_0xe3d2('0x13')](_0x334394['query'][_0xe3d2('0x13')]);}_0x8f96c2['order']=qs[_0xe3d2('0x30')](_0x334394['query'][_0xe3d2('0x30')]);_0x8f96c2[_0xe3d2('0x31')]=qs[_0xe3d2('0x32')](_[_0xe3d2('0x33')](_0x334394[_0xe3d2('0x2b')],_0xcd755c['filters']));_0x8f96c2['where'][_0xe3d2('0xc8')]=_0x6ebb58['id'];if(_0x334394[_0xe3d2('0x2b')][_0xe3d2('0x53')]){_0x8f96c2[_0xe3d2('0x31')]=_[_0xe3d2('0x79')](_0x8f96c2['where'],{'$or':_[_0xe3d2('0x46')](_0x8f96c2[_0xe3d2('0x2d')],function(_0x288504){var _0x420a53={};_0x420a53[_0x288504]={'$like':'%'+_0x334394['query']['filter']+'%'};return _0x420a53;})});}_0x8f96c2=_[_0xe3d2('0x79')]({},_0x8f96c2,_0x334394[_0xe3d2('0xc9')]);return db[_0xe3d2('0xa1')]['count']({'where':_0x8f96c2['where']})[_0xe3d2('0x17')](function(_0x520171){_0xef2186[_0xe3d2('0x12')]=_0x520171;if(_0x334394[_0xe3d2('0x2b')]['includeAll']){_0x8f96c2['include']=[{'all':!![]}];}return db[_0xe3d2('0xa1')][_0xe3d2('0x8a')](_0x8f96c2);})[_0xe3d2('0x17')](function(_0x5dd1ed){_0xef2186[_0xe3d2('0xcc')]=_0x5dd1ed;return _0xef2186;});}})['then'](respondWithFilteredResult(_0x4b731a,_0x8f96c2))[_0xe3d2('0x84')](handleError(_0x4b731a,null));};exports[_0xe3d2('0xce')]=function(_0x23e1c7,_0x464b76){var _0x1f7059={'raw':!![],'where':{}};var _0x3c0f8a={};var _0x5c618f={'count':0x0,'rows':[]};return db[_0xe3d2('0x1f')]['findOne']({'where':{'id':_0x23e1c7[_0xe3d2('0x86')]['id']}})['then'](handleEntityNotFound(_0x464b76,null))[_0xe3d2('0x17')](function(_0x344b1e){if(_0x344b1e){_0x3c0f8a[_0xe3d2('0x2a')]=_[_0xe3d2('0x21')](db[_0xe3d2('0xa7')]['rawAttributes']);_0x3c0f8a[_0xe3d2('0x2b')]=_['keys'](_0x23e1c7['query']);_0x3c0f8a['filters']=_['intersection'](_0x3c0f8a['model'],_0x3c0f8a[_0xe3d2('0x2b')]);_0x1f7059['attributes']=_[_0xe3d2('0xc2')](_0x3c0f8a[_0xe3d2('0x2a')],qs[_0xe3d2('0x2c')](_0x23e1c7[_0xe3d2('0x2b')][_0xe3d2('0x2c')]));_0x1f7059[_0xe3d2('0x2d')]=_0x1f7059['attributes'][_0xe3d2('0x22')]?_0x1f7059['attributes']:_0x3c0f8a['model'];if(!_0x23e1c7[_0xe3d2('0x2b')][_0xe3d2('0xc7')]('nolimit')){_0x1f7059[_0xe3d2('0x11')]=qs['limit'](_0x23e1c7[_0xe3d2('0x2b')][_0xe3d2('0x11')]);_0x1f7059['offset']=qs[_0xe3d2('0x13')](_0x23e1c7[_0xe3d2('0x2b')][_0xe3d2('0x13')]);}_0x1f7059['order']=qs[_0xe3d2('0x30')](_0x23e1c7[_0xe3d2('0x2b')][_0xe3d2('0x30')]);_0x1f7059[_0xe3d2('0x31')]=qs[_0xe3d2('0x32')](_['pick'](_0x23e1c7[_0xe3d2('0x2b')],_0x3c0f8a[_0xe3d2('0x32')]));_0x1f7059['where']['ContactId']=_0x344b1e['id'];if(_0x23e1c7['query'][_0xe3d2('0x53')]){_0x1f7059['where']=_['merge'](_0x1f7059[_0xe3d2('0x31')],{'$or':_[_0xe3d2('0x46')](_0x1f7059[_0xe3d2('0x2d')],function(_0x3e1fac){var _0x1ca6a0={};_0x1ca6a0[_0x3e1fac]={'$like':'%'+_0x23e1c7[_0xe3d2('0x2b')]['filter']+'%'};return _0x1ca6a0;})});}_0x1f7059=_[_0xe3d2('0x79')]({},_0x1f7059,_0x23e1c7[_0xe3d2('0xc9')]);return db[_0xe3d2('0xa7')][_0xe3d2('0x12')]({'where':_0x1f7059[_0xe3d2('0x31')]})[_0xe3d2('0x17')](function(_0x175ccb){_0x5c618f['count']=_0x175ccb;if(_0x23e1c7['query'][_0xe3d2('0xcf')]){_0x1f7059[_0xe3d2('0xca')]=[{'all':!![]}];}return db[_0xe3d2('0xa7')][_0xe3d2('0x8a')](_0x1f7059);})['then'](function(_0x5b3684){_0x5c618f['rows']=_0x5b3684;return _0x5c618f;});}})[_0xe3d2('0x17')](respondWithFilteredResult(_0x464b76,_0x1f7059))[_0xe3d2('0x84')](handleError(_0x464b76,null));};exports[_0xe3d2('0xd0')]=function(_0x5549eb,_0x35815c){try{if(!_0x5549eb['body'][_0xe3d2('0x57')]){throw new Error(_0xe3d2('0xd1'));}if(!_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xd2')]){throw new Error(_0xe3d2('0xd3'));}if(!_0x5549eb[_0xe3d2('0x8d')]['binding_values']){throw new Error('No\x20association\x20values\x20specified!');}if(!_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xd4')]){throw new Error(_0xe3d2('0xd5'));}var _0xeece58=_0x5549eb['body'][_0xe3d2('0xd2')][_0xe3d2('0x45')](',');var _0x243573=_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xd6')][_0xe3d2('0x45')](',');if(!_0xeece58[_0xe3d2('0x22')]||!_0x243573[_0xe3d2('0x22')]||_0xeece58[_0xe3d2('0x22')]!==_0x243573[_0xe3d2('0x22')]){throw new Error(_0xe3d2('0xd7'));}_0x5549eb[_0xe3d2('0x8d')]['fields']=_[_0xe3d2('0xd8')](_0xeece58,_0x243573);if(!_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0x2c')][_0xe3d2('0xbe')]){throw new Error(_0xe3d2('0xd9'));}if(!_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0x2c')][_0xe3d2('0xda')]){throw new Error(_0xe3d2('0xdb'));}var _0x5c8455=path[_0xe3d2('0xab')](config[_0xe3d2('0xdc')],_0xe3d2('0xdd'),_0x5549eb[_0xe3d2('0xde')][_0xe3d2('0xdf')]);fs[_0xe3d2('0xe0')](_0x5c8455,parseInt('0777',0x8));var _0x5af084=require(_0xe3d2('0xe1'))[_0xe3d2('0xe2')](path['join'](__dirname,_0xe3d2('0xe3')),[_0x5c8455,_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xd2')],_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xd6')],_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0x57')],_0x5549eb[_0xe3d2('0x8d')]['CompanyId'],_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xb1')],_0x5549eb[_0xe3d2('0x8d')][_0xe3d2('0xd4')]]);return _0x35815c[_0xe3d2('0xf')](0xc8)['json']({'message':_0xe3d2('0xe4'),'pid':_0x5af084[_0xe3d2('0xe5')]});}catch(_0x45237c){return _0x35815c[_0xe3d2('0xf')](0x1f4)[_0xe3d2('0x1d')](_0x45237c);}};exports[_0xe3d2('0xe6')]=function(_0xb83af1,_0x5dd248){var _0x543f6c=fs[_0xe3d2('0xe7')](_0xb83af1[_0xe3d2('0xde')][_0xe3d2('0x2')]);Papa['parse'](_0x543f6c,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x3333da){return _0x5dd248['status'](0xc8)['json']({'file':_0xb83af1['file'],'fields':_0x3333da[_0xe3d2('0xe8')][_0xe3d2('0x2c')]});}});};exports[_0xe3d2('0xe9')]=function(_0x46731b,_0x16a799){return db[_0xe3d2('0xea')][_0xe3d2('0x8a')]({'raw':!![],'attributes':['id'],'where':{'role':_0xe3d2('0x75')}})[_0xe3d2('0x17')](function(_0x5ca8fc){var _0x49a36b=![];if(!_0x46731b['body'][_0xe3d2('0x57')]){throw new Error(_0xe3d2('0xd1'));}if(!_0x46731b['body'][_0xe3d2('0xeb')][_0xe3d2('0xbe')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x46731b['body'][_0xe3d2('0xeb')]['firstName']){throw new Error(_0xe3d2('0xdb'));}if(!_0x46731b[_0xe3d2('0x8d')][_0xe3d2('0xd4')]){throw new Error(_0xe3d2('0xd5'));}var _0x582b43=require('child_process')[_0xe3d2('0xe2')](path['join'](__dirname,'../../components/import/cm/csv2'),[_0x46731b[_0xe3d2('0x86')]['id'],JSON['stringify'](_0x46731b[_0xe3d2('0x8d')]),JSON['stringify'](_0x5ca8fc)]);_0x582b43['on'](_0xe3d2('0xec'),function(){_0x49a36b=!![];return _0x16a799[_0xe3d2('0xf')](0xc8)['json']({'message':_0xe3d2('0xed'),'pid':_0x582b43['pid']});});_0x582b43['on'](_0xe3d2('0xee'),function(_0x1ac57b){if(_0x1ac57b&&!_0x49a36b){return _0x16a799[_0xe3d2('0xf')](0x1f4)[_0xe3d2('0x15')]({'message':_0xe3d2('0xef'),'pid':_0x582b43['pid']});}});})[_0xe3d2('0x84')](handleError(_0x16a799,null));};exports['getJourney']=function(_0x59ae93,_0x327c79){var _0x34bc8f=[_0xe3d2('0xf0'),'chat',_0xe3d2('0xf1'),'openchannel',_0xe3d2('0xf2'),_0xe3d2('0xf3'),_0xe3d2('0xf4')];var _0x276a81={'offset':0x0,'order':qs[_0xe3d2('0x30')](_0xe3d2('0xf5'))},_0x1a716a={'count':0x0,'rows':[]};Promise['resolve']()[_0xe3d2('0x17')](function(){if(_0x59ae93[_0xe3d2('0x2b')]['channel']){if(!_[_0xe3d2('0xf6')](_0x34bc8f,_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xf7')]['toLowerCase']())){throw new Error(_0xe3d2('0xf8'));}_0x34bc8f=[_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xf7')][_0xe3d2('0xf9')]()];}if(_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xfa')]){try{var _0x470fcd=JSON['parse'](_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xfa')]);if(!moment(_0x470fcd[_0xe3d2('0x8e')])[_0xe3d2('0xfb')]()){throw new Error(_0xe3d2('0xfc'));}if(!moment(_0x470fcd['to'])[_0xe3d2('0xfb')]()){throw new Error(_0xe3d2('0xfd'));}}catch(_0x181148){throw new Error(_0xe3d2('0xfe'));}}if(!_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xc7')](_0xe3d2('0x2e'))){_0x276a81[_0xe3d2('0x11')]=qs[_0xe3d2('0x11')](_0x59ae93[_0xe3d2('0x2b')]['limit']||0xa);_0x276a81[_0xe3d2('0x13')]=qs[_0xe3d2('0x13')](_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0x13')]);}var _0x531b1d=_0x34bc8f[_0xe3d2('0x46')](function(_0x542ffc){if(_0x542ffc==='voice'){var _0x10d38f={'attributes':['id',_0xe3d2('0xff'),_0xe3d2('0x50'),'source','destination',_0xe3d2('0x100'),_0xe3d2('0x101'),'endtime',_0xe3d2('0x102'),_0xe3d2('0x103'),'createdAt',_0xe3d2('0x104'),'userSecondDisposition','userThirdDisposition',_0xe3d2('0x105')],'where':{'ContactId':_0x59ae93[_0xe3d2('0x86')]['id']},'include':[{'model':db[_0xe3d2('0xea')],'as':_0xe3d2('0xea'),'attributes':['id',_0xe3d2('0x1c'),_0xe3d2('0x106'),_0xe3d2('0x8b')]}],'order':[[_0xe3d2('0x107'),_0xe3d2('0x6c')]]};if(_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xfa')]){_0x10d38f['where'][_0xe3d2('0x107')]={'$gte':_0x470fcd['from'],'$lte':_0x470fcd['to']};}return db[_0xe3d2('0xa4')][_0xe3d2('0x108')](_0x10d38f)[_0xe3d2('0x17')](function(_0x361229){_0x1a716a[_0xe3d2('0x12')]+=_0x361229[_0xe3d2('0x12')];return _[_0xe3d2('0x46')](_0x361229[_0xe3d2('0xcc')],function(_0xfa7a8f){var _0x255fce=_0xfa7a8f[_0xe3d2('0x8f')]({'plain':!![]});_0x255fce['channel']=_0x542ffc;if(_0x255fce[_0xe3d2('0xea')]){_0x255fce[_0xe3d2('0xea')]={'id':_0x255fce[_0xe3d2('0xea')]['id'],'name':_0x255fce[_0xe3d2('0xea')][_0xe3d2('0x1c')],'fullname':_0x255fce['User'][_0xe3d2('0x106')],'alias':_0x255fce[_0xe3d2('0xea')][_0xe3d2('0x8b')]};}return _0x255fce;});});}else{var _0x553852=_[_0xe3d2('0x109')](_0x542ffc)+(_0x542ffc==='chat'?_0xe3d2('0x10a'):_0xe3d2('0x10b'));var _0x41dbd3={'attributes':['id','closed',_0xe3d2('0x10c'),_0xe3d2('0x107'),'note','disposition','secondDisposition','thirdDisposition','UserId',_0x553852+'Id'],'where':{'ContactId':_0x59ae93['params']['id']},'include':[{'model':db[_0x553852],'as':_0xe3d2('0x10b'),'attributes':['id',_0xe3d2('0x1c'),_0xe3d2('0x10d')]},{'model':db[_0xe3d2('0xea')],'as':'Owner','attributes':['id',_0xe3d2('0x1c'),_0xe3d2('0x106')]},{'model':db[_0xe3d2('0xc0')],'as':_0xe3d2('0x83'),'attributes':['id',_0xe3d2('0x1c'),'color'],'through':{'attributes':[]}}],'order':[[_0xe3d2('0x107'),'DESC']]};if(_0x59ae93[_0xe3d2('0x2b')][_0xe3d2('0xfa')]){_0x41dbd3[_0xe3d2('0x31')][_0xe3d2('0x107')]={'$gte':_0x470fcd[_0xe3d2('0x8e')],'$lte':_0x470fcd['to']};}switch(_0x542ffc){case _0xe3d2('0x10e'):_0x41dbd3['attributes'][_0xe3d2('0x24')](_0xe3d2('0x10f'),'customerIp',_0xe3d2('0x110'),_0xe3d2('0x111'),_0xe3d2('0x112'),_0xe3d2('0x113'),_0xe3d2('0x114'),_0xe3d2('0x115'),_0xe3d2('0x116'));break;case _0xe3d2('0xf0'):_0x41dbd3[_0xe3d2('0x2d')][_0xe3d2('0x24')]('subject','substatus');break;case _0xe3d2('0x117'):_0x41dbd3[_0xe3d2('0x2d')]['push'](_0xe3d2('0x118'),_0xe3d2('0x119'));break;}return db[_[_0xe3d2('0x109')](_0x542ffc)+_0xe3d2('0x11a')][_0xe3d2('0x108')](_0x41dbd3)[_0xe3d2('0x17')](function(_0xc5c28e){_0x1a716a[_0xe3d2('0x12')]+=_0xc5c28e[_0xe3d2('0x12')];return _[_0xe3d2('0x46')](_0xc5c28e['rows'],function(_0x29eb02){var _0x2b8760=_0x29eb02[_0xe3d2('0x8f')]({'plain':!![]});_0x2b8760[_0xe3d2('0xf7')]=_0x542ffc;if(_0x2b8760['Owner']){_0x2b8760[_0xe3d2('0x11b')]={'id':_0x2b8760[_0xe3d2('0x11b')]['id'],'name':_0x2b8760['Owner']['name'],'fullname':_0x2b8760[_0xe3d2('0x11b')][_0xe3d2('0x106')]};}return _0x2b8760;});});}});return Promise[_0xe3d2('0x28')](_0x531b1d);})['then'](function(_0x3ab422){return _(_0x3ab422)[_0xe3d2('0x11c')]()[_0xe3d2('0x11d')](_0xe3d2('0x107'))[_0xe3d2('0x11e')]()[_0xe3d2('0x44')]();})[_0xe3d2('0x17')](function(_0x2932b5){_0x1a716a[_0xe3d2('0xcc')]=_0x276a81['limit']?_0x2932b5['slice'](_0x276a81['offset'],_0x276a81[_0xe3d2('0x13')]+_0x276a81[_0xe3d2('0x11')]):_0x2932b5;return _0x1a716a;})[_0xe3d2('0x17')](respondWithFilteredResult(_0x327c79,_0x276a81))[_0xe3d2('0x84')](handleError(_0x327c79,null));};
\ No newline at end of file