Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / cmContact / cmContact.controller.js
index 9e350fb..8f60593 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa467=['Website','Account','closedAt','disposition','key','Owner','browserName','customerIp','customerPort','deviceModel','ratingMessage','ratingType','ratingValue','referer','subject','externalUrl','threadId','Interaction','flatten','sortBy','reverse','value','slice','moment','bluebird','util','lodash','ioredis','../../components/contacts','../../config/logger','../../config/environment','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','register','status','offset','undefined','limit','count','set','Content-Range','json','update','destroy','end','sendStatus','stack','name','send','index','describe','then','getOptions','findAll','user','catch','CmContact','find','params','tags','keys','startsWith','cf_','columnName','displayName','analytics','query','CmCustomField','length','alias','custom','info','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','forEach','hasOwnProperty','merge','body','from','get','isArray','join','[CmContact][merge]\x20to\x20%s\x20from\x20%s','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','MailInteraction','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperHistory','ReportAgentPreview','VoiceCallReport','ChatQueueReport','FaxQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappMessage','WhatsappQueueReport','dialTimezone','isNil','timezones','utcOffset','additionalPhones','bulkCreate','each','duplicates','$or','push','where','findOrCreate','spread','all','show','Tags','color','Phones','ContactItemType','ItemType','literal','ListId','$and','omit','map','format','pickBy','cf_%d','table','cm_contacts','toParam','sequelize','values','CmHopper','phone','getTags','model','Tag','intersection','attributes','fields','order','sort','filters','pick','filter','options','nolimit','setTags','ids','setAdditionalPhones','items','item_types','ItemTypeId','description','OrderBy','contact\x20phone\x20exists','PHONE','CmHopperAdditionalPhone','item','`ItemType`.OrderBy','CmHopperId','ItemType.OrderBy','getAdditionalPhones','duplicateAdditionalPhones','fromContactId','CmContactId','toContactId','rescheduleAdditionalPhones','hopperId','findOne','rawAttributes','ContactId','includeAll','getHopperHistories','include','rows','getHopperFinals','CmHopperFinal','getJscriptySessions','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','root','server/files/tmp','filename','chmodSync','child_process','fork','../../components/import/cm/csv','File\x20uploaded\x20correctly!','pid','upload','createReadStream','file','parse','meta','User','binding','firstName','No\x20firstName\x20column\x20specified','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','importUpdates','agent','No\x20ListId\x20specified','../../components/import/cm/csvUpdates','getJourney','mail','chat','sms','openchannel','fax','-createdAt','resolve','channel','includes','toLowerCase','Invalid\x20channel','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','Invalid\x20createdAt\x20filter','voice','uniqueid','type','source','destination','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','UserId','DESC','findAndCountAll','fullname','startCase'];(function(_0x5b897c,_0x8cf2a6){var _0x44767f=function(_0x554e55){while(--_0x554e55){_0x5b897c['push'](_0x5b897c['shift']());}};_0x44767f(++_0x8cf2a6);}(_0xa467,0x118));var _0x7a46=function(_0x493c6f,_0x29f930){_0x493c6f=_0x493c6f-0x0;var _0x23ab5a=_0xa467[_0x493c6f];return _0x23ab5a;};'use strict';var moment=require(_0x7a46('0x0'));var BPromise=require(_0x7a46('0x1'));var util=require(_0x7a46('0x2'));var path=require('path');var fs=require('fs');var _=require(_0x7a46('0x3'));var squel=require('squel');var Papa=require('papaparse');var Redis=require(_0x7a46('0x4'));var contacts=require(_0x7a46('0x5'));var qs=require('../../components/parsers/qs');var logger=require(_0x7a46('0x6'))('api');var config=require(_0x7a46('0x7'));var shared=require('../../config/environment/shared');var db=require('../../mysqldb')['db'];config[_0x7a46('0x8')]=_[_0x7a46('0x9')](config['redis'],{'host':_0x7a46('0xa'),'port':0x18eb});var socket=require(_0x7a46('0xb'))(new Redis(config[_0x7a46('0x8')]));require(_0x7a46('0xc'))[_0x7a46('0xd')](socket);function respondWithResult(_0xb1a7bb,_0x1a0f0c){_0x1a0f0c=_0x1a0f0c||0xc8;return function(_0x3dd476){if(_0x3dd476){return _0xb1a7bb[_0x7a46('0xe')](_0x1a0f0c)['json'](_0x3dd476);}};}function respondWithFilteredResult(_0x44f553,_0x4ad9e4){return function(_0x3597ea){if(_0x3597ea){var _0x5346ba=typeof _0x4ad9e4[_0x7a46('0xf')]===_0x7a46('0x10')&&typeof _0x4ad9e4[_0x7a46('0x11')]===_0x7a46('0x10');var _0x4eaeec=_0x3597ea[_0x7a46('0x12')];var _0x4355de=_0x5346ba?0x0:_0x4ad9e4[_0x7a46('0xf')];var _0x1201c8=_0x5346ba?_0x3597ea[_0x7a46('0x12')]:_0x4ad9e4[_0x7a46('0xf')]+_0x4ad9e4[_0x7a46('0x11')];var _0x36511a;if(_0x1201c8>=_0x4eaeec){_0x1201c8=_0x4eaeec;_0x36511a=0xc8;}else{_0x36511a=0xce;}_0x44f553[_0x7a46('0xe')](_0x36511a);return _0x44f553[_0x7a46('0x13')](_0x7a46('0x14'),_0x4355de+'-'+_0x1201c8+'/'+_0x4eaeec)[_0x7a46('0x15')](_0x3597ea);}return null;};}function saveUpdates(_0x4477c5){return function(_0x4434eb){if(_0x4434eb){return _0x4434eb[_0x7a46('0x16')](_0x4477c5)['then'](function(_0x80667){return _0x80667;});}return null;};}function removeEntity(_0x378328){return function(_0x5ef89d){if(_0x5ef89d){return _0x5ef89d[_0x7a46('0x17')]()['then'](function(){_0x378328[_0x7a46('0xe')](0xcc)[_0x7a46('0x18')]();});}};}function handleEntityNotFound(_0xe29521){return function(_0x407677){if(!_0x407677){_0xe29521[_0x7a46('0x19')](0x194);}return _0x407677;};}function handleError(_0x12c75a,_0x38d5a6){_0x38d5a6=_0x38d5a6||0x1f4;return function(_0x2c6912){logger['error'](_0x2c6912[_0x7a46('0x1a')]);if(_0x2c6912[_0x7a46('0x1b')]){delete _0x2c6912['name'];}_0x12c75a['status'](_0x38d5a6)[_0x7a46('0x1c')](_0x2c6912);};}exports[_0x7a46('0x1d')]=function(_0x58c2d5,_0x444e7e){var _0x259454={};return contacts[_0x7a46('0x1e')]()[_0x7a46('0x1f')](function(_0x1f3f54){_0x259454=qs[_0x7a46('0x20')](_0x1f3f54,_0x58c2d5);return contacts[_0x7a46('0x21')](_0x58c2d5['query'],_0x58c2d5[_0x7a46('0x22')],_0x259454,_0x1f3f54);})[_0x7a46('0x1f')](respondWithFilteredResult(_0x444e7e,_0x259454))[_0x7a46('0x23')](handleError(_0x444e7e,null));};exports[_0x7a46('0x17')]=function(_0x5bd8ed,_0x10bff5){return db[_0x7a46('0x24')][_0x7a46('0x25')]({'where':{'id':_0x5bd8ed[_0x7a46('0x26')]['id']}})[_0x7a46('0x1f')](handleEntityNotFound(_0x10bff5,null))[_0x7a46('0x1f')](removeEntity(_0x10bff5,null))[_0x7a46('0x23')](handleError(_0x10bff5,null));};exports[_0x7a46('0x1e')]=function(_0x187c6a,_0x1fb7b3){return db['CmContact']['describe']()[_0x7a46('0x1f')](function(_0x45d30e){delete _0x45d30e[_0x7a46('0x27')];for(var _0x3a60f4=0x0;_0x3a60f4<Object[_0x7a46('0x28')](_0x45d30e)['length'];_0x3a60f4++){var _0x2491ea=Object[_0x7a46('0x28')](_0x45d30e)[_0x3a60f4];if(!_[_0x7a46('0x29')](_0x2491ea,_0x7a46('0x2a'))){_0x45d30e[_0x2491ea][_0x7a46('0x2b')]=_0x2491ea;_0x45d30e[_0x2491ea][_0x7a46('0x2c')]=_0x2491ea;}}return _0x45d30e;})[_0x7a46('0x1f')](function(_0x2fe6a8){var _0x465421={'where':Boolean(_0x187c6a['query'][_0x7a46('0x2d')])===!![]?undefined:{'$or':[{'ListId':_0x187c6a[_0x7a46('0x2e')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x7a46('0x2f')][_0x7a46('0x21')](_0x465421)[_0x7a46('0x1f')](function(_0x37afc6){for(var _0x5c1f4b=0x0;_0x5c1f4b<_0x37afc6[_0x7a46('0x30')];_0x5c1f4b++){var _0x4a60dd=_0x7a46('0x2a')+_0x37afc6[_0x5c1f4b]['id'];if(_0x2fe6a8[_0x4a60dd]){_0x2fe6a8[_0x4a60dd][_0x7a46('0x2b')]=_0x4a60dd;_0x2fe6a8[_0x4a60dd][_0x7a46('0x2c')]=_0x37afc6[_0x5c1f4b][_0x7a46('0x31')];_0x2fe6a8[_0x4a60dd][_0x7a46('0x32')]={'type':_0x37afc6[_0x5c1f4b]['type'],'values':_0x37afc6[_0x5c1f4b]['values']};}else{logger[_0x7a46('0x33')](_0x7a46('0x34'),_0x4a60dd);}}Object[_0x7a46('0x28')](_0x2fe6a8)[_0x7a46('0x35')](function(_0x366411){if(!_0x2fe6a8[_0x366411][_0x7a46('0x36')](_0x7a46('0x2b'))){delete _0x2fe6a8[_0x366411];}});return _0x2fe6a8;});})[_0x7a46('0x1f')](respondWithResult(_0x1fb7b3,null))[_0x7a46('0x23')](handleError(_0x1fb7b3,null));};exports[_0x7a46('0x37')]=function(_0x2a419b,_0x5a8b49){var _0x2057fa;var _0x40f0c3;var _0x1f9bb8;if(_0x2a419b[_0x7a46('0x38')]['id']){delete _0x2a419b[_0x7a46('0x38')]['id'];}return db[_0x7a46('0x24')][_0x7a46('0x21')]({'where':{'id':[_0x2a419b[_0x7a46('0x38')]['to'],_0x2a419b['body'][_0x7a46('0x39')]]}})[_0x7a46('0x1f')](function(_0x572bb2){if(_0x572bb2){if(_0x572bb2[_0x7a46('0x30')]!==0x2){return null;}_0x572bb2[0x0]=_0x572bb2[0x0]['get']({'plain':!![]});_0x572bb2[0x1]=_0x572bb2[0x1][_0x7a46('0x3a')]({'plain':!![]});delete _0x572bb2[0x0]['id'];delete _0x572bb2[0x1]['id'];return _['mergeWith'](_0x572bb2[0x0],_0x572bb2[0x1],function(_0x24f107,_0x56ba17){if(Array['isArray'](_0x56ba17)&&!_0x56ba17[_0x7a46('0x30')]){return _0x24f107;}else if(!_0x56ba17){return _0x24f107;}});}})[_0x7a46('0x1f')](handleEntityNotFound(_0x5a8b49,null))[_0x7a46('0x1f')](function(_0x1bc0fb){if(_0x1bc0fb){if(_0x1bc0fb[_0x7a46('0x27')]&&_[_0x7a46('0x3b')](_0x1bc0fb[_0x7a46('0x27')])){_0x1bc0fb[_0x7a46('0x27')]=_0x1bc0fb['tags'][_0x7a46('0x3c')]();}logger[_0x7a46('0x33')](_0x7a46('0x3d'),_0x2a419b['body']['to'],_0x2a419b[_0x7a46('0x38')]['from']);return db['CmHopper'][_0x7a46('0x17')]({'where':{'ContactId':[_0x2a419b[_0x7a46('0x38')]['to'],_0x2a419b[_0x7a46('0x38')][_0x7a46('0x39')]]}})[_0x7a46('0x1f')](function(_0x576ebb){logger['info'](_0x7a46('0x3e'),_0x576ebb);return db[_0x7a46('0x3f')][_0x7a46('0x17')]({'where':{'ContactId':[_0x2a419b[_0x7a46('0x38')]['to'],_0x2a419b[_0x7a46('0x38')][_0x7a46('0x39')]]}})[_0x7a46('0x1f')](function(_0x5f29c6){logger[_0x7a46('0x33')](_0x7a46('0x40'),_0x5f29c6);return db['CmContact'][_0x7a46('0x41')](_0x1bc0fb);});});}})['then'](function(_0xf4afc3){if(_0xf4afc3){_0x2057fa=_0xf4afc3;_0x40f0c3={'ContactId':_0x2057fa['id']};_0x1f9bb8={'where':{'ContactId':[_0x2a419b['body']['to'],_0x2a419b[_0x7a46('0x38')][_0x7a46('0x39')]]}};return db['ChatInteraction'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db['ChatMessage'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db['ChatOfflineMessage'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x42')]['update'](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db['MailMessage']['update'](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x42')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db['MailMessage']['update'](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db['SmsInteraction']['update'](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db['SmsMessage'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db['FaxInteraction']['update'](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db['FaxMessage'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x43')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x44')]['update'](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x45')]['update']({'CmContactId':_0x2057fa['id']},{'where':{'CmContactId':[_0x2a419b[_0x7a46('0x38')]['to'],_0x2a419b[_0x7a46('0x38')][_0x7a46('0x39')]]}});}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db['CmHopperFinal'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x46')]['update'](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x47')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x48')]['update'](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db[_0x7a46('0x49')]['update'](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x4a')]['update'](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db['MailQueueReport'][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x4b')]['update'](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db[_0x7a46('0x4c')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x4d')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db['WhatsappInteraction']['update'](_0x40f0c3,_0x1f9bb8);}})['then'](function(){if(_0x2057fa){return db[_0x7a46('0x4e')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x4f')][_0x7a46('0x16')](_0x40f0c3,_0x1f9bb8);}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return db[_0x7a46('0x24')]['destroy']({'where':{'id':[_0x2a419b[_0x7a46('0x38')]['to'],_0x2a419b[_0x7a46('0x38')][_0x7a46('0x39')]]}});}})[_0x7a46('0x1f')](function(){if(_0x2057fa){return _0x2057fa;}})[_0x7a46('0x1f')](respondWithResult(_0x5a8b49,null))[_0x7a46('0x23')](handleError(_0x5a8b49,null));};exports[_0x7a46('0x41')]=function(_0xe42959,_0x52b0a2){return db[_0x7a46('0x24')][_0x7a46('0x1e')]()[_0x7a46('0x1f')](function(_0x3ce430){if(_0xe42959[_0x7a46('0x38')][_0x7a46('0x27')]&&_[_0x7a46('0x3b')](_0xe42959[_0x7a46('0x38')]['tags'])){if(_0xe42959[_0x7a46('0x38')]['tags']['length']){_0xe42959[_0x7a46('0x38')]['tags']=_0xe42959['body'][_0x7a46('0x27')][_0x7a46('0x3c')](';')+';';}else{_0xe42959[_0x7a46('0x38')]['tags']=null;}}else{_0xe42959['body'][_0x7a46('0x27')]=null;}if(!_['isNil'](_0xe42959[_0x7a46('0x38')][_0x7a46('0x50')])){var _0x13bce3=_0xe42959['body'][_0x7a46('0x50')];if(!_[_0x7a46('0x51')](shared[_0x7a46('0x52')][_0x13bce3]))_0xe42959['body']['utcOffset']=shared[_0x7a46('0x52')][_0x13bce3][_0x7a46('0x53')];}return db[_0x7a46('0x24')][_0x7a46('0x41')](_0xe42959[_0x7a46('0x38')],{'fields':_[_0x7a46('0x28')](_0x3ce430),'raw':!![]});})['then'](function(_0x578ced){if(_0xe42959[_0x7a46('0x38')][_0x7a46('0x54')]){return insertAdditionalPhones(_0x578ced,_0xe42959[_0x7a46('0x38')][_0x7a46('0x54')]);}else{return _0x578ced;}})[_0x7a46('0x1f')](respondWithResult(_0x52b0a2,0xc9))[_0x7a46('0x23')](handleError(_0x52b0a2,null));};exports[_0x7a46('0x55')]=function(_0x16367c,_0x451dc3){var _0x55767e=0x0;var _0x5de092=0x0;var _0x45b8b7=0x0;var _0x414e05=[];return db['CmContact']['describe']()[_0x7a46('0x1f')](function(_0x37062c){return BPromise[_0x7a46('0x56')](_0x16367c['body'],function(_0x47ca5e){var _0x5141e6={'where':{'$or':[]},'defaults':_0x47ca5e,'fields':_[_0x7a46('0x28')](_0x37062c),'raw':!![]};if(_0x47ca5e['duplicates']){for(var _0x57af4a=0x0;_0x57af4a<_0x47ca5e[_0x7a46('0x57')][_0x7a46('0x30')];_0x57af4a++){var _0x5537ae={};_0x5537ae[_0x47ca5e[_0x7a46('0x57')][_0x57af4a]]=_0x47ca5e[_0x47ca5e[_0x7a46('0x57')][_0x57af4a]];_0x5141e6['where'][_0x7a46('0x58')][_0x7a46('0x59')](_0x5537ae);}_0x5141e6[_0x7a46('0x5a')]['ListId']=_0x47ca5e['ListId'];}return db[_0x7a46('0x24')][_0x7a46('0x5b')](_0x5141e6)[_0x7a46('0x5c')](function(_0x152e37,_0x5bc009){if(_0x5bc009){if(_0x47ca5e[_0x7a46('0x36')]('additionalPhones')){_0x414e05['push']({'contact':_0x152e37,'additionalPhones':_0x47ca5e[_0x7a46('0x54')]});}_0x55767e++;}else{_0x45b8b7++;}})['catch'](function(){_0x5de092++;});});})['then'](function(_0x1ae5e3){if(_0x1ae5e3){if(_0x414e05[_0x7a46('0x30')]>0x0){return new Promise(function(_0x45ea0e){var _0xd6f659=[];for(var _0x5ce2f8=0x0;_0x5ce2f8<_0x414e05[_0x7a46('0x30')];_0x5ce2f8++){_0xd6f659['push'](insertAdditionalPhones(_0x414e05[_0x5ce2f8]['contact'],_0x414e05[_0x5ce2f8][_0x7a46('0x54')]));}Promise[_0x7a46('0x5d')](_0xd6f659)['then'](function(){_0x45ea0e(0x1);});})[_0x7a46('0x1f')](function(){return{'success':_0x55767e,'failure':_0x5de092,'duplicates':_0x45b8b7};});}else{return{'success':_0x55767e,'failure':_0x5de092,'duplicates':_0x45b8b7};}}})[_0x7a46('0x1f')](respondWithResult(_0x451dc3,0xc9))['catch'](handleError(_0x451dc3,null));};exports[_0x7a46('0x5e')]=function(_0x4b1676,_0x27b0b9){var _0x27e588;return db[_0x7a46('0x24')][_0x7a46('0x1e')]()[_0x7a46('0x1f')](function(_0x308fd3){return db[_0x7a46('0x24')][_0x7a46('0x25')]({'where':{'id':_0x4b1676[_0x7a46('0x26')]['id']},'include':[{'model':db['Tag'],'as':_0x7a46('0x5f'),'attributes':['id',_0x7a46('0x1b'),_0x7a46('0x60')],'required':_0x4b1676[_0x7a46('0x2e')]['tag']?!![]:![]},{'model':db[_0x7a46('0x45')],'as':_0x7a46('0x61'),'where':{'CmContactId':_0x4b1676[_0x7a46('0x26')]['id']},'required':![],'include':[{'model':db[_0x7a46('0x62')],'as':_0x7a46('0x63')}]}],'order':[db['sequelize'][_0x7a46('0x64')]('Phones.OrderBy')],'attributes':_[_0x7a46('0x28')](_0x308fd3)});})['then'](function(_0x4b66eb){if(!_['isNil'](_0x4b66eb)){_0x27e588=_0x4b66eb[_0x7a46('0x3a')]({'plain':!![]});var _0x6952fc={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x4b66eb&&_0x4b66eb[_0x7a46('0x65')]){if(_0x4b66eb[_0x7a46('0x65')]){_0x6952fc[_0x7a46('0x5a')][_0x7a46('0x66')][_0x7a46('0x59')]({'ListId':{'$ne':_0x4b66eb['ListId']}});}}return db[_0x7a46('0x2f')][_0x7a46('0x21')](_0x6952fc);}})['then'](function(_0x4390c8){if(!_[_0x7a46('0x51')](_0x4390c8)){return _[_0x7a46('0x67')](_0x27e588,_[_0x7a46('0x68')](_0x4390c8,function(_0x22f2cc){return util[_0x7a46('0x69')]('cf_%d',_0x22f2cc['id']);}));}})['then'](handleEntityNotFound(_0x27b0b9,null))[_0x7a46('0x1f')](respondWithResult(_0x27b0b9,null))[_0x7a46('0x23')](handleError(_0x27b0b9,null));};exports[_0x7a46('0x16')]=function(_0x25870d,_0xaa4c0b){var _0x44f1b2;if(_0x25870d['body']['id']){delete _0x25870d[_0x7a46('0x38')]['id'];}if(!_['isNil'](_0x25870d[_0x7a46('0x38')]['dialTimezone'])){var _0xd89215=_0x25870d['body'][_0x7a46('0x50')];if(!_[_0x7a46('0x51')](shared[_0x7a46('0x52')][_0xd89215]))_0x25870d[_0x7a46('0x38')][_0x7a46('0x53')]=shared[_0x7a46('0x52')][_0xd89215]['utcOffset'];}return db[_0x7a46('0x24')]['find']({'where':{'id':_0x25870d[_0x7a46('0x26')]['id']}})[_0x7a46('0x1f')](handleEntityNotFound(_0xaa4c0b,null))[_0x7a46('0x1f')](saveUpdates(_0x25870d[_0x7a46('0x38')],null))[_0x7a46('0x1f')](function(_0x28863a){_0x44f1b2=_0x28863a;var _0x98011c={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x28863a&&_0x28863a[_0x7a46('0x65')]){if(_0x28863a[_0x7a46('0x65')]){_0x98011c[_0x7a46('0x5a')][_0x7a46('0x66')]['push']({'ListId':{'$ne':_0x28863a[_0x7a46('0x65')]}});}}return db[_0x7a46('0x2f')]['findAll'](_0x98011c);})[_0x7a46('0x1f')](function(_0x18b781){if(_0x18b781){return _[_0x7a46('0x67')](_[_0x7a46('0x6a')](_0x25870d[_0x7a46('0x38')],function(_0x4569c5,_0x41df29){return _['startsWith'](_0x41df29,_0x7a46('0x2a'));}),_[_0x7a46('0x68')](_0x18b781,function(_0x2be1c8){return util[_0x7a46('0x69')](_0x7a46('0x6b'),_0x2be1c8['id']);}));}})['then'](function(_0xc0d790){if(_0xc0d790&&!_['isEmpty'](_0xc0d790)){var _0x20ce32=squel[_0x7a46('0x16')]()[_0x7a46('0x6c')](_0x7a46('0x6d'))['setFields'](_0xc0d790)[_0x7a46('0x5a')]('id\x20=\x20?',_0x25870d[_0x7a46('0x26')]['id'])[_0x7a46('0x6e')]();return db[_0x7a46('0x6f')]['query'](_0x20ce32['text'],{'replacements':_0x20ce32[_0x7a46('0x70')]});}})[_0x7a46('0x1f')](function(){if(_0x25870d[_0x7a46('0x38')]['phone']&&_0x44f1b2){return db[_0x7a46('0x71')][_0x7a46('0x16')]({'phone':_0x25870d['body'][_0x7a46('0x72')],'OrderBy':0x0},{'where':{'ContactId':_0x44f1b2['id']}});}})[_0x7a46('0x1f')](function(){return _0x44f1b2;})[_0x7a46('0x1f')](respondWithResult(_0xaa4c0b,null))[_0x7a46('0x23')](handleError(_0xaa4c0b,null));};exports[_0x7a46('0x73')]=function(_0x30dca5,_0x460b18){var _0x1fbe42={};var _0x32ec50={};var _0x13c7dd;var _0xcb7b5d;return db[_0x7a46('0x24')]['findOne']({'where':{'id':_0x30dca5[_0x7a46('0x26')]['id']}})['then'](handleEntityNotFound(_0x460b18,null))[_0x7a46('0x1f')](function(_0x3b3119){if(_0x3b3119){_0x13c7dd=_0x3b3119;_0x32ec50[_0x7a46('0x74')]=_['keys'](db[_0x7a46('0x75')]['rawAttributes']);_0x32ec50[_0x7a46('0x2e')]=_['keys'](_0x30dca5['query']);_0x32ec50['filters']=_[_0x7a46('0x76')](_0x32ec50[_0x7a46('0x74')],_0x32ec50[_0x7a46('0x2e')]);_0x1fbe42[_0x7a46('0x77')]=_[_0x7a46('0x76')](_0x32ec50['model'],qs[_0x7a46('0x78')](_0x30dca5[_0x7a46('0x2e')][_0x7a46('0x78')]));_0x1fbe42[_0x7a46('0x77')]=_0x1fbe42[_0x7a46('0x77')][_0x7a46('0x30')]?_0x1fbe42['attributes']:_0x32ec50[_0x7a46('0x74')];_0x1fbe42[_0x7a46('0x79')]=qs[_0x7a46('0x7a')](_0x30dca5['query']['sort']);_0x1fbe42['where']=qs[_0x7a46('0x7b')](_[_0x7a46('0x7c')](_0x30dca5[_0x7a46('0x2e')],_0x32ec50[_0x7a46('0x7b')]));if(_0x30dca5[_0x7a46('0x2e')][_0x7a46('0x7d')]){_0x1fbe42[_0x7a46('0x5a')]=_[_0x7a46('0x37')](_0x1fbe42[_0x7a46('0x5a')],{'$or':_[_0x7a46('0x68')](_0x1fbe42[_0x7a46('0x77')],function(_0x1a4483){var _0x348aac={};_0x348aac[_0x1a4483]={'$like':'%'+_0x30dca5[_0x7a46('0x2e')][_0x7a46('0x7d')]+'%'};return _0x348aac;})});}_0x1fbe42=_['merge']({},_0x1fbe42,_0x30dca5[_0x7a46('0x7e')]);return _0x13c7dd[_0x7a46('0x73')](_0x1fbe42);}})['then'](function(_0xc03790){if(_0xc03790){_0xcb7b5d=_0xc03790[_0x7a46('0x30')];if(!_0x30dca5[_0x7a46('0x2e')]['hasOwnProperty'](_0x7a46('0x7f'))){_0x1fbe42[_0x7a46('0x11')]=qs[_0x7a46('0x11')](_0x30dca5['query']['limit']);_0x1fbe42[_0x7a46('0xf')]=qs[_0x7a46('0xf')](_0x30dca5[_0x7a46('0x2e')][_0x7a46('0xf')]);}return _0x13c7dd['getTags'](_0x1fbe42);}})['then'](function(_0x577abc){if(_0x577abc){return _0x577abc?{'count':_0xcb7b5d,'rows':_0x577abc}:null;}})[_0x7a46('0x1f')](respondWithResult(_0x460b18,null))[_0x7a46('0x23')](handleError(_0x460b18,null));};exports[_0x7a46('0x80')]=function(_0x4dc7dd,_0x1ae607){if(_0x4dc7dd[_0x7a46('0x38')]['id']){delete _0x4dc7dd[_0x7a46('0x38')]['id'];}return db[_0x7a46('0x24')]['findOne']({'where':{'id':_0x4dc7dd['params']['id']}})[_0x7a46('0x1f')](handleEntityNotFound(_0x1ae607,null))[_0x7a46('0x1f')](function(_0x221fbc){if(_0x221fbc){return _0x221fbc[_0x7a46('0x80')](_0x4dc7dd[_0x7a46('0x38')][_0x7a46('0x81')]||[]);}return null;})[_0x7a46('0x1f')](respondWithResult(_0x1ae607,null))[_0x7a46('0x23')](handleError(_0x1ae607,null));};exports[_0x7a46('0x82')]=function(_0x11f0e5,_0x2804ba){var _0x5ac295=[];_0x5ac295[_0x7a46('0x59')](addAdditionalPhones(_0x11f0e5[_0x7a46('0x38')]));Promise['all'](_0x5ac295)[_0x7a46('0x1f')](function(){_0x5ac295=[];_0x5ac295[_0x7a46('0x59')](deleteCmHopperPhones(_0x11f0e5[_0x7a46('0x38')]['id']));_0x5ac295[_0x7a46('0x59')](addCmHopperPhones(_0x11f0e5[_0x7a46('0x38')]['id']));Promise['all'](_0x5ac295)[_0x7a46('0x1f')](function(){return[0x1];})['then'](respondWithResult(_0x2804ba,null));});};function addAdditionalPhones(_0x2b54c1){var _0x343342;return new Promise(function(_0x10986b){return db[_0x7a46('0x45')][_0x7a46('0x17')]({'where':{'CmContactId':_0x2b54c1['id']}})['then'](function(){db[_0x7a46('0x62')][_0x7a46('0x21')]({'raw':!![],'attributes':['id','OrderBy']})[_0x7a46('0x1f')](function(_0x490dcc){var _0x135513=[];for(var _0x8bc755=0x0;_0x8bc755<_0x2b54c1[_0x7a46('0x83')][_0x7a46('0x30')];_0x8bc755++){var _0x3aab66=_0x2b54c1['item_types']?_[_0x7a46('0x51')](_0x2b54c1[_0x7a46('0x84')][_0x8bc755])?'':_0x2b54c1[_0x7a46('0x84')][_0x8bc755]:_0x2b54c1[_0x7a46('0x83')][_0x8bc755][_0x7a46('0x85')]?_0x2b54c1['items'][_0x8bc755][_0x7a46('0x85')]:'';var _0x714f4e=_[_0x7a46('0x51')](_0x2b54c1[_0x7a46('0x83')][_0x8bc755]['description'])?'':_0x2b54c1['items'][_0x8bc755][_0x7a46('0x86')];var _0xc6f28f=_0x3aab66+':'+_0x2b54c1['items'][_0x8bc755]['phone']+'§'+_0x714f4e;if(_[_0x7a46('0x51')](_0x343342))_0x343342=_0xc6f28f;else _0x343342+=';'+_0xc6f28f;var _0x113f67=null;var _0x2162cb=null;if(_0x2b54c1['item_types']){if(!_[_0x7a46('0x51')](_0x2b54c1[_0x7a46('0x84')][_0x8bc755])){_0x2162cb=_[_0x7a46('0x25')](_0x490dcc,function(_0x346361){return _0x346361['id']===_0x2b54c1[_0x7a46('0x84')][_0x8bc755];});if(!_[_0x7a46('0x51')](_0x2162cb)){_0x113f67=_0x2162cb[_0x7a46('0x87')];}}}else{if(!_[_0x7a46('0x51')](_0x2b54c1[_0x7a46('0x83')][_0x8bc755])){_0x2162cb=_[_0x7a46('0x25')](_0x490dcc,function(_0x3ced76){return _0x3ced76['id']===_0x2b54c1[_0x7a46('0x83')][_0x8bc755][_0x7a46('0x85')];});if(!_[_0x7a46('0x51')](_0x2162cb)){_0x113f67=_0x8bc755;}}}if(_['isNil'](_0x113f67)){_0x113f67=0x64;}_0x135513[_0x7a46('0x59')](addAdditionalPhone(_0x2b54c1['id'],_0x2b54c1[_0x7a46('0x83')][_0x8bc755]['phone'],_0x2b54c1['item_types']?_[_0x7a46('0x51')](_0x2b54c1[_0x7a46('0x84')][_0x8bc755])?null:_0x2b54c1['item_types'][_0x8bc755]:_0x2b54c1[_0x7a46('0x83')][_0x8bc755]['ItemTypeId']?_0x2b54c1[_0x7a46('0x83')][_0x8bc755][_0x7a46('0x85')]:null,_0x113f67,_0x714f4e));}Promise[_0x7a46('0x5d')](_0x135513)[_0x7a46('0x1f')](function(){db[_0x7a46('0x24')][_0x7a46('0x16')]({'AdditionalPhones':_0x343342},{'where':{'id':_0x2b54c1['id']}})[_0x7a46('0x1f')](function(){_0x10986b(0x1);});});});});});}function addAdditionalPhone(_0x2ea48f,_0x4b7ec3,_0x395720,_0x29ede7,_0x29a268){return db[_0x7a46('0x45')][_0x7a46('0x25')]({'where':{'CmContactId':_0x2ea48f,'item':_0x4b7ec3}})[_0x7a46('0x1f')](function(_0x51309e){if(_0x51309e)logger[_0x7a46('0x33')](_0x7a46('0x88'),_0x51309e);else{db[_0x7a46('0x45')]['create']({'CmContactId':_0x2ea48f,'item':_0x4b7ec3,'ItemTypeId':_0x395720,'OrderBy':_0x29ede7,'ItemClass':_0x7a46('0x89'),'description':_0x29a268});}});}function deleteCmHopperPhones(_0x4f0612){return new Promise(function(_0x8e9f77){return db[_0x7a46('0x71')][_0x7a46('0x21')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x4f0612}})[_0x7a46('0x1f')](function(_0x23da08){db[_0x7a46('0x8a')][_0x7a46('0x17')]({'where':{'CmHopperId':{'$in':_[_0x7a46('0x68')](_0x23da08,'id')}}});})[_0x7a46('0x1f')](function(){_0x8e9f77(0x1);});});}function addCmHopperPhones(_0x5b82df){return new Promise(function(_0x43adf7){return db['CmHopper'][_0x7a46('0x21')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x5b82df}})['then'](function(_0x370ee4){var _0x25d426=[];_[_0x7a46('0x68')](_0x370ee4,function(_0xd4f756){_0x25d426[_0x7a46('0x59')](createCmHopperPhone(_0x5b82df,_0xd4f756['id']));});Promise[_0x7a46('0x5d')](_0x25d426)[_0x7a46('0x1f')](function(){_0x43adf7(0x1);});});});}function createCmHopperPhone(_0x1b9c58,_0x4bc75c){return new Promise(function(_0x8c1da8){db[_0x7a46('0x45')]['findAll']({'raw':!![],'attributes':[_0x7a46('0x8b'),_0x7a46('0x87')],'where':{'CmContactId':_0x1b9c58,'ItemClass':_0x7a46('0x89')},'include':[{'model':db[_0x7a46('0x62')],'attributes':['OrderBy'],'as':'ItemType'}],'order':['OrderBy',db[_0x7a46('0x6f')][_0x7a46('0x64')](_0x7a46('0x8c'))]})[_0x7a46('0x1f')](function(_0x37ccb1){var _0x247027=0x1;var _0x32950c=_[_0x7a46('0x68')](_0x37ccb1,function(_0x22c5ba){_0x22c5ba[_0x7a46('0x8d')]=_0x4bc75c;_0x22c5ba['phone']=_0x22c5ba[_0x7a46('0x8b')];_0x22c5ba['OrderBy']=_0x247027;delete _0x22c5ba[_0x7a46('0x8e')];_0x247027=_0x247027+0x1;return _0x22c5ba;});return db[_0x7a46('0x8a')][_0x7a46('0x55')](_0x32950c,{});})[_0x7a46('0x1f')](function(){_0x8c1da8(0x1);});});}function insertAdditionalPhones(_0x5ee6e2,_0x1a0ec8){return new Promise(function(_0x438a78){var _0x24171f=[];for(var _0x3208f1=0x0;_0x3208f1<_0x1a0ec8[_0x7a46('0x30')];_0x3208f1++){var _0x42efcd=_0x1a0ec8[_0x3208f1];_0x24171f['push'](parseContactItemType(_0x42efcd));}Promise[_0x7a46('0x5d')](_0x24171f)['then'](function(){var _0x320b9f={'id':_0x5ee6e2['id'],'items':_0x1a0ec8};return addAdditionalPhones(_0x320b9f)[_0x7a46('0x1f')](function(){return addCmHopperPhones(_0x5ee6e2['id']);});})[_0x7a46('0x1f')](function(){_0x438a78(_0x5ee6e2);});});}function parseContactItemType(_0xef39f3){return new Promise(function(_0x10d6da){if(_0xef39f3[_0x7a46('0x36')](_0x7a46('0x85'))){_0x10d6da(_0xef39f3);}else{return db[_0x7a46('0x62')][_0x7a46('0x25')]({'where':{'name':_0xef39f3['ItemType']}})[_0x7a46('0x1f')](function(_0x379d27){if(_[_0x7a46('0x51')](_0x379d27))_0xef39f3['ItemTypeId']=null;else _0xef39f3[_0x7a46('0x85')]=_0x379d27['id'];_0x10d6da(_0xef39f3);});}});}exports[_0x7a46('0x8f')]=function(_0x69a445,_0x580018){return db[_0x7a46('0x45')][_0x7a46('0x21')]({'raw':!![],'where':{'CmContactId':_0x69a445[_0x7a46('0x26')]['id'],'ItemClass':_0x7a46('0x89')},'include':[{'model':db['ContactItemType'],'as':_0x7a46('0x63')}],'order':[[_0x7a46('0x87')],[db[_0x7a46('0x6f')][_0x7a46('0x64')](_0x7a46('0x8c'))]]})['then'](function(_0x7edcd4){return _0x7edcd4;})[_0x7a46('0x1f')](respondWithResult(_0x580018,null))[_0x7a46('0x23')](handleError(_0x580018,null));};exports[_0x7a46('0x90')]=function(_0xc2f5d8,_0x747abe){return db['CmContactHasItem'][_0x7a46('0x21')]({'raw':!![],'where':{'CmContactId':_0xc2f5d8[_0x7a46('0x38')][_0x7a46('0x91')]}})[_0x7a46('0x1f')](function(_0x559d02){var _0x45b18f=_[_0x7a46('0x68')](_0x559d02,function(_0x4f60aa){_0x4f60aa[_0x7a46('0x92')]=_0xc2f5d8[_0x7a46('0x38')][_0x7a46('0x93')];return _0x4f60aa;});return db[_0x7a46('0x45')][_0x7a46('0x55')](_0x45b18f,{});})[_0x7a46('0x1f')](function(){return addCmHopperPhones(_0xc2f5d8[_0x7a46('0x38')][_0x7a46('0x93')]);})['then'](function(){return['ok'];})[_0x7a46('0x1f')](respondWithResult(_0x747abe,null))[_0x7a46('0x23')](handleError(_0x747abe,null));};exports[_0x7a46('0x94')]=function(_0x58011a,_0x317d93){var _0x169905=[];_0x169905['push'](createCmHopperPhone(_0x58011a['body']['id'],_0x58011a['body'][_0x7a46('0x95')]));Promise['all'](_0x169905)[_0x7a46('0x1f')](function(){return[0x1];})['then'](respondWithResult(_0x317d93,null));};exports['getHoppers']=function(_0x2e29f1,_0x1fd6cf){var _0x1cec3c={'raw':![],'where':{}};var _0x2cd59d={};var _0xd58273={'count':0x0,'rows':[]};return db['CmContact'][_0x7a46('0x96')]({'where':{'id':_0x2e29f1[_0x7a46('0x26')]['id']}})['then'](handleEntityNotFound(_0x1fd6cf,null))[_0x7a46('0x1f')](function(_0x1285d4){if(_0x1285d4){_0x2cd59d[_0x7a46('0x74')]=_[_0x7a46('0x28')](db[_0x7a46('0x71')][_0x7a46('0x97')]);_0x2cd59d['query']=_['keys'](_0x2e29f1[_0x7a46('0x2e')]);_0x2cd59d[_0x7a46('0x7b')]=_['intersection'](_0x2cd59d['model'],_0x2cd59d['query']);_0x1cec3c['attributes']=_[_0x7a46('0x76')](_0x2cd59d['model'],qs[_0x7a46('0x78')](_0x2e29f1['query']['fields']));_0x1cec3c[_0x7a46('0x77')]=_0x1cec3c[_0x7a46('0x77')][_0x7a46('0x30')]?_0x1cec3c[_0x7a46('0x77')]:_0x2cd59d[_0x7a46('0x74')];if(!_0x2e29f1[_0x7a46('0x2e')][_0x7a46('0x36')]('nolimit')){_0x1cec3c[_0x7a46('0x11')]=qs[_0x7a46('0x11')](_0x2e29f1['query'][_0x7a46('0x11')]);_0x1cec3c[_0x7a46('0xf')]=qs[_0x7a46('0xf')](_0x2e29f1[_0x7a46('0x2e')][_0x7a46('0xf')]);}_0x1cec3c[_0x7a46('0x79')]=qs['sort'](_0x2e29f1[_0x7a46('0x2e')][_0x7a46('0x7a')]);_0x1cec3c[_0x7a46('0x5a')]=qs[_0x7a46('0x7b')](_[_0x7a46('0x7c')](_0x2e29f1['query'],_0x2cd59d[_0x7a46('0x7b')]));_0x1cec3c[_0x7a46('0x5a')][_0x7a46('0x98')]=_0x1285d4['id'];if(_0x2e29f1[_0x7a46('0x2e')]['filter']){_0x1cec3c[_0x7a46('0x5a')]=_[_0x7a46('0x37')](_0x1cec3c[_0x7a46('0x5a')],{'$or':_[_0x7a46('0x68')](_0x1cec3c[_0x7a46('0x77')],function(_0x5ae603){var _0x5b1802={};_0x5b1802[_0x5ae603]={'$like':'%'+_0x2e29f1[_0x7a46('0x2e')][_0x7a46('0x7d')]+'%'};return _0x5b1802;})});}_0x1cec3c=_[_0x7a46('0x37')]({},_0x1cec3c,_0x2e29f1['options']);return db[_0x7a46('0x71')][_0x7a46('0x12')]({'where':_0x1cec3c[_0x7a46('0x5a')]})[_0x7a46('0x1f')](function(_0x19511b){_0xd58273[_0x7a46('0x12')]=_0x19511b;if(_0x2e29f1['query'][_0x7a46('0x99')]){_0x1cec3c['include']=[{'all':!![]}];}return db[_0x7a46('0x71')]['findAll'](_0x1cec3c);})[_0x7a46('0x1f')](function(_0x3a7b1a){_0xd58273['rows']=_0x3a7b1a;return _0xd58273;});}})[_0x7a46('0x1f')](respondWithFilteredResult(_0x1fd6cf,_0x1cec3c))['catch'](handleError(_0x1fd6cf,null));};exports[_0x7a46('0x9a')]=function(_0x2c85e6,_0x1d8d38){var _0x57f60d={'raw':!![],'where':{}};var _0x4dfbec={};var _0x32136c={'count':0x0,'rows':[]};return db[_0x7a46('0x24')][_0x7a46('0x96')]({'where':{'id':_0x2c85e6[_0x7a46('0x26')]['id']}})[_0x7a46('0x1f')](handleEntityNotFound(_0x1d8d38,null))[_0x7a46('0x1f')](function(_0x35f7f4){if(_0x35f7f4){_0x4dfbec[_0x7a46('0x74')]=_[_0x7a46('0x28')](db[_0x7a46('0x46')][_0x7a46('0x97')]);_0x4dfbec[_0x7a46('0x2e')]=_[_0x7a46('0x28')](_0x2c85e6[_0x7a46('0x2e')]);_0x4dfbec[_0x7a46('0x7b')]=_[_0x7a46('0x76')](_0x4dfbec[_0x7a46('0x74')],_0x4dfbec['query']);_0x57f60d[_0x7a46('0x77')]=_[_0x7a46('0x76')](_0x4dfbec[_0x7a46('0x74')],qs[_0x7a46('0x78')](_0x2c85e6[_0x7a46('0x2e')]['fields']));_0x57f60d[_0x7a46('0x77')]=_0x57f60d[_0x7a46('0x77')][_0x7a46('0x30')]?_0x57f60d[_0x7a46('0x77')]:_0x4dfbec[_0x7a46('0x74')];if(!_0x2c85e6[_0x7a46('0x2e')][_0x7a46('0x36')]('nolimit')){_0x57f60d[_0x7a46('0x11')]=qs['limit'](_0x2c85e6[_0x7a46('0x2e')][_0x7a46('0x11')]);_0x57f60d[_0x7a46('0xf')]=qs[_0x7a46('0xf')](_0x2c85e6[_0x7a46('0x2e')][_0x7a46('0xf')]);}_0x57f60d[_0x7a46('0x79')]=qs['sort'](_0x2c85e6[_0x7a46('0x2e')][_0x7a46('0x7a')]);_0x57f60d[_0x7a46('0x5a')]=qs[_0x7a46('0x7b')](_[_0x7a46('0x7c')](_0x2c85e6['query'],_0x4dfbec['filters']));_0x57f60d['where'][_0x7a46('0x98')]=_0x35f7f4['id'];if(_0x2c85e6[_0x7a46('0x2e')][_0x7a46('0x7d')]){_0x57f60d[_0x7a46('0x5a')]=_[_0x7a46('0x37')](_0x57f60d[_0x7a46('0x5a')],{'$or':_['map'](_0x57f60d['attributes'],function(_0x48c783){var _0x5eebbf={};_0x5eebbf[_0x48c783]={'$like':'%'+_0x2c85e6['query']['filter']+'%'};return _0x5eebbf;})});}_0x57f60d=_[_0x7a46('0x37')]({},_0x57f60d,_0x2c85e6['options']);return db[_0x7a46('0x46')][_0x7a46('0x12')]({'where':_0x57f60d[_0x7a46('0x5a')]})[_0x7a46('0x1f')](function(_0xc210e7){_0x32136c['count']=_0xc210e7;if(_0x2c85e6[_0x7a46('0x2e')][_0x7a46('0x99')]){_0x57f60d[_0x7a46('0x9b')]=[{'all':!![]}];}return db[_0x7a46('0x46')][_0x7a46('0x21')](_0x57f60d);})[_0x7a46('0x1f')](function(_0x2177bf){_0x32136c[_0x7a46('0x9c')]=_0x2177bf;return _0x32136c;});}})[_0x7a46('0x1f')](respondWithFilteredResult(_0x1d8d38,_0x57f60d))[_0x7a46('0x23')](handleError(_0x1d8d38,null));};exports[_0x7a46('0x9d')]=function(_0x388d99,_0x396e2f){var _0x144e5a={'raw':!![],'where':{}};var _0x408c49={};var _0x348ac5={'count':0x0,'rows':[]};return db[_0x7a46('0x24')][_0x7a46('0x96')]({'where':{'id':_0x388d99[_0x7a46('0x26')]['id']}})[_0x7a46('0x1f')](handleEntityNotFound(_0x396e2f,null))['then'](function(_0x16fbcb){if(_0x16fbcb){_0x408c49['model']=_[_0x7a46('0x28')](db[_0x7a46('0x9e')]['rawAttributes']);_0x408c49[_0x7a46('0x2e')]=_[_0x7a46('0x28')](_0x388d99[_0x7a46('0x2e')]);_0x408c49[_0x7a46('0x7b')]=_[_0x7a46('0x76')](_0x408c49['model'],_0x408c49[_0x7a46('0x2e')]);_0x144e5a[_0x7a46('0x77')]=_[_0x7a46('0x76')](_0x408c49[_0x7a46('0x74')],qs[_0x7a46('0x78')](_0x388d99[_0x7a46('0x2e')][_0x7a46('0x78')]));_0x144e5a['attributes']=_0x144e5a[_0x7a46('0x77')][_0x7a46('0x30')]?_0x144e5a[_0x7a46('0x77')]:_0x408c49['model'];if(!_0x388d99['query'][_0x7a46('0x36')](_0x7a46('0x7f'))){_0x144e5a['limit']=qs[_0x7a46('0x11')](_0x388d99[_0x7a46('0x2e')][_0x7a46('0x11')]);_0x144e5a[_0x7a46('0xf')]=qs[_0x7a46('0xf')](_0x388d99[_0x7a46('0x2e')][_0x7a46('0xf')]);}_0x144e5a[_0x7a46('0x79')]=qs[_0x7a46('0x7a')](_0x388d99['query'][_0x7a46('0x7a')]);_0x144e5a[_0x7a46('0x5a')]=qs[_0x7a46('0x7b')](_[_0x7a46('0x7c')](_0x388d99[_0x7a46('0x2e')],_0x408c49[_0x7a46('0x7b')]));_0x144e5a[_0x7a46('0x5a')][_0x7a46('0x98')]=_0x16fbcb['id'];if(_0x388d99[_0x7a46('0x2e')][_0x7a46('0x7d')]){_0x144e5a['where']=_[_0x7a46('0x37')](_0x144e5a[_0x7a46('0x5a')],{'$or':_[_0x7a46('0x68')](_0x144e5a[_0x7a46('0x77')],function(_0x3e899b){var _0x36da4d={};_0x36da4d[_0x3e899b]={'$like':'%'+_0x388d99[_0x7a46('0x2e')][_0x7a46('0x7d')]+'%'};return _0x36da4d;})});}_0x144e5a=_[_0x7a46('0x37')]({},_0x144e5a,_0x388d99[_0x7a46('0x7e')]);return db[_0x7a46('0x9e')][_0x7a46('0x12')]({'where':_0x144e5a['where']})['then'](function(_0x45ee9d){_0x348ac5[_0x7a46('0x12')]=_0x45ee9d;if(_0x388d99['query'][_0x7a46('0x99')]){_0x144e5a['include']=[{'all':!![]}];}return db[_0x7a46('0x9e')]['findAll'](_0x144e5a);})[_0x7a46('0x1f')](function(_0x560baf){_0x348ac5[_0x7a46('0x9c')]=_0x560baf;return _0x348ac5;});}})[_0x7a46('0x1f')](respondWithFilteredResult(_0x396e2f,_0x144e5a))[_0x7a46('0x23')](handleError(_0x396e2f,null));};exports[_0x7a46('0x9f')]=function(_0xbdd111,_0x249882){var _0x4ec6e3={'raw':!![],'where':{}};var _0x19a69a={};var _0x42050b={'count':0x0,'rows':[]};return db[_0x7a46('0x24')][_0x7a46('0x96')]({'where':{'id':_0xbdd111['params']['id']}})[_0x7a46('0x1f')](handleEntityNotFound(_0x249882,null))[_0x7a46('0x1f')](function(_0x395d67){if(_0x395d67){_0x19a69a['model']=_[_0x7a46('0x28')](db[_0x7a46('0x4d')][_0x7a46('0x97')]);_0x19a69a['query']=_[_0x7a46('0x28')](_0xbdd111[_0x7a46('0x2e')]);_0x19a69a[_0x7a46('0x7b')]=_['intersection'](_0x19a69a['model'],_0x19a69a[_0x7a46('0x2e')]);_0x4ec6e3[_0x7a46('0x77')]=_[_0x7a46('0x76')](_0x19a69a[_0x7a46('0x74')],qs[_0x7a46('0x78')](_0xbdd111['query'][_0x7a46('0x78')]));_0x4ec6e3['attributes']=_0x4ec6e3['attributes']['length']?_0x4ec6e3[_0x7a46('0x77')]:_0x19a69a[_0x7a46('0x74')];if(!_0xbdd111[_0x7a46('0x2e')][_0x7a46('0x36')](_0x7a46('0x7f'))){_0x4ec6e3[_0x7a46('0x11')]=qs[_0x7a46('0x11')](_0xbdd111[_0x7a46('0x2e')][_0x7a46('0x11')]);_0x4ec6e3[_0x7a46('0xf')]=qs['offset'](_0xbdd111[_0x7a46('0x2e')]['offset']);}_0x4ec6e3[_0x7a46('0x79')]=qs[_0x7a46('0x7a')](_0xbdd111[_0x7a46('0x2e')]['sort']);_0x4ec6e3['where']=qs[_0x7a46('0x7b')](_['pick'](_0xbdd111['query'],_0x19a69a['filters']));_0x4ec6e3[_0x7a46('0x5a')][_0x7a46('0x98')]=_0x395d67['id'];if(_0xbdd111['query']['filter']){_0x4ec6e3[_0x7a46('0x5a')]=_[_0x7a46('0x37')](_0x4ec6e3[_0x7a46('0x5a')],{'$or':_['map'](_0x4ec6e3[_0x7a46('0x77')],function(_0x328ad7){var _0x4d1ded={};_0x4d1ded[_0x328ad7]={'$like':'%'+_0xbdd111[_0x7a46('0x2e')][_0x7a46('0x7d')]+'%'};return _0x4d1ded;})});}_0x4ec6e3=_['merge']({},_0x4ec6e3,_0xbdd111['options']);return db['JscriptySessionReport'][_0x7a46('0x12')]({'where':_0x4ec6e3['where']})['then'](function(_0x320f22){_0x42050b[_0x7a46('0x12')]=_0x320f22;if(_0xbdd111[_0x7a46('0x2e')][_0x7a46('0x99')]){_0x4ec6e3[_0x7a46('0x9b')]=[{'all':!![]}];}return db[_0x7a46('0x4d')][_0x7a46('0x21')](_0x4ec6e3);})[_0x7a46('0x1f')](function(_0x2caeb7){_0x42050b[_0x7a46('0x9c')]=_0x2caeb7;return _0x42050b;});}})['then'](respondWithFilteredResult(_0x249882,_0x4ec6e3))['catch'](handleError(_0x249882,null));};exports['uploadCsv']=function(_0x3e6c5a,_0x1552e1){try{if(!_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0x65')]){throw new Error('No\x20ListId\x20specified');}if(!_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0xa0')]){throw new Error(_0x7a46('0xa1'));}if(!_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0xa2')]){throw new Error(_0x7a46('0xa3'));}if(!_0x3e6c5a['body'][_0x7a46('0xa4')]){throw new Error(_0x7a46('0xa5'));}var _0x5d2e9f=_0x3e6c5a[_0x7a46('0x38')]['binding_keys']['split'](',');var _0x398eb4=_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0xa2')][_0x7a46('0xa6')](',');if(!_0x5d2e9f[_0x7a46('0x30')]||!_0x398eb4['length']||_0x5d2e9f[_0x7a46('0x30')]!==_0x398eb4[_0x7a46('0x30')]){throw new Error(_0x7a46('0xa7'));}_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0x78')]=_[_0x7a46('0xa8')](_0x5d2e9f,_0x398eb4);if(!_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0x78')][_0x7a46('0x72')]){throw new Error(_0x7a46('0xa9'));}if(!_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0x78')]['firstName']){throw new Error('No\x20firstName\x20column\x20specified');}var _0x28781a=path['join'](config[_0x7a46('0xaa')],_0x7a46('0xab'),_0x3e6c5a['file'][_0x7a46('0xac')]);fs[_0x7a46('0xad')](_0x28781a,parseInt('0777',0x8));var _0x11b675=require(_0x7a46('0xae'))[_0x7a46('0xaf')](path['join'](__dirname,_0x7a46('0xb0')),[_0x28781a,_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0xa0')],_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0xa2')],_0x3e6c5a['body'][_0x7a46('0x65')],_0x3e6c5a['body']['CompanyId'],_0x3e6c5a[_0x7a46('0x38')][_0x7a46('0x57')],_0x3e6c5a[_0x7a46('0x38')]['socket_timestamp']]);return _0x1552e1['status'](0xc8)[_0x7a46('0x15')]({'message':_0x7a46('0xb1'),'pid':_0x11b675[_0x7a46('0xb2')]});}catch(_0x2de974){return _0x1552e1[_0x7a46('0xe')](0x1f4)['send'](_0x2de974);}};exports[_0x7a46('0xb3')]=function(_0x4f7e4b,_0xbde1){var _0x1a23d7=fs[_0x7a46('0xb4')](_0x4f7e4b[_0x7a46('0xb5')]['path']);Papa[_0x7a46('0xb6')](_0x1a23d7,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x56dfd3){return _0xbde1['status'](0xc8)[_0x7a46('0x15')]({'file':_0x4f7e4b['file'],'fields':_0x56dfd3[_0x7a46('0xb7')][_0x7a46('0x78')]});}});};exports['import']=function(_0x4df328,_0x10f836){return db[_0x7a46('0xb8')][_0x7a46('0x21')]({'raw':!![],'attributes':['id'],'where':{'role':'agent'}})[_0x7a46('0x1f')](function(_0x1b3759){var _0x3a478b=![];if(!_0x4df328['body'][_0x7a46('0x65')]){throw new Error('No\x20ListId\x20specified');}if(!_0x4df328[_0x7a46('0x38')][_0x7a46('0xb9')]['phone']){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x4df328[_0x7a46('0x38')][_0x7a46('0xb9')][_0x7a46('0xba')]){throw new Error(_0x7a46('0xbb'));}if(!_0x4df328[_0x7a46('0x38')][_0x7a46('0xa4')]){throw new Error(_0x7a46('0xa5'));}var _0x316254=require(_0x7a46('0xae'))[_0x7a46('0xaf')](path[_0x7a46('0x3c')](__dirname,_0x7a46('0xbc')),[_0x4df328[_0x7a46('0x26')]['id'],JSON[_0x7a46('0xbd')](_0x4df328[_0x7a46('0x38')]),JSON[_0x7a46('0xbd')](_0x1b3759)]);_0x316254['on'](_0x7a46('0xbe'),function(){_0x3a478b=!![];return _0x10f836[_0x7a46('0xe')](0xc8)['json']({'message':_0x7a46('0xbf'),'pid':_0x316254['pid']});});_0x316254['on'](_0x7a46('0xc0'),function(_0x1f5c3a){if(_0x1f5c3a&&!_0x3a478b){return _0x10f836[_0x7a46('0xe')](0x1f4)[_0x7a46('0x15')]({'message':_0x7a46('0xc1'),'pid':_0x316254['pid']});}});})[_0x7a46('0x23')](handleError(_0x10f836,null));};exports[_0x7a46('0xc2')]=function(_0x184fe4,_0x2aff32){return db[_0x7a46('0xb8')][_0x7a46('0x21')]({'raw':!![],'attributes':['id'],'where':{'role':_0x7a46('0xc3')}})[_0x7a46('0x1f')](function(_0x194633){var _0x3f8213=![];if(!_0x184fe4[_0x7a46('0x38')][_0x7a46('0x65')]){throw new Error(_0x7a46('0xc4'));}if(!_0x184fe4[_0x7a46('0x38')][_0x7a46('0xb9')][_0x7a46('0x72')]){throw new Error(_0x7a46('0xa9'));}if(!_0x184fe4[_0x7a46('0x38')][_0x7a46('0xb9')][_0x7a46('0xba')]){throw new Error('No\x20firstName\x20column\x20specified');}if(!_0x184fe4[_0x7a46('0x38')]['socket_timestamp']){throw new Error(_0x7a46('0xa5'));}var _0x5d9e35=require(_0x7a46('0xae'))['fork'](path[_0x7a46('0x3c')](__dirname,_0x7a46('0xc5')),[_0x184fe4['params']['id'],JSON[_0x7a46('0xbd')](_0x184fe4[_0x7a46('0x38')]),JSON['stringify'](_0x194633)]);_0x5d9e35['on'](_0x7a46('0xbe'),function(){_0x3f8213=!![];return _0x2aff32['status'](0xc8)['json']({'message':'start\x20child\x20process\x20correctly!','pid':_0x5d9e35[_0x7a46('0xb2')]});});_0x5d9e35['on']('exit',function(_0x18357e){if(_0x18357e&&!_0x3f8213){return _0x2aff32[_0x7a46('0xe')](0x1f4)[_0x7a46('0x15')]({'message':'error\x20child\x20process','pid':_0x5d9e35[_0x7a46('0xb2')]});}});})[_0x7a46('0x23')](handleError(_0x2aff32,null));};exports[_0x7a46('0xc6')]=function(_0x2d8391,_0x35e6ba){var _0x27842b=[_0x7a46('0xc7'),_0x7a46('0xc8'),_0x7a46('0xc9'),_0x7a46('0xca'),_0x7a46('0xcb'),'whatsapp','voice'];var _0x6f55a3={'offset':0x0,'order':qs[_0x7a46('0x7a')](_0x7a46('0xcc'))},_0x3206fe={'count':0x0,'rows':[]};Promise[_0x7a46('0xcd')]()[_0x7a46('0x1f')](function(){if(_0x2d8391[_0x7a46('0x2e')][_0x7a46('0xce')]){if(!_[_0x7a46('0xcf')](_0x27842b,_0x2d8391[_0x7a46('0x2e')][_0x7a46('0xce')][_0x7a46('0xd0')]())){throw new Error(_0x7a46('0xd1'));}_0x27842b=[_0x2d8391[_0x7a46('0x2e')][_0x7a46('0xce')][_0x7a46('0xd0')]()];}if(_0x2d8391[_0x7a46('0x2e')][_0x7a46('0xd2')]){try{var _0x35cb16=JSON[_0x7a46('0xb6')](_0x2d8391['query'][_0x7a46('0xd2')]);if(!moment(_0x35cb16[_0x7a46('0x39')])[_0x7a46('0xd3')]()){throw new Error(_0x7a46('0xd4'));}if(!moment(_0x35cb16['to'])[_0x7a46('0xd3')]()){throw new Error(_0x7a46('0xd5'));}}catch(_0x1d9250){throw new Error(_0x7a46('0xd6'));}}if(!_0x2d8391[_0x7a46('0x2e')]['hasOwnProperty'](_0x7a46('0x7f'))){_0x6f55a3[_0x7a46('0x11')]=qs[_0x7a46('0x11')](_0x2d8391[_0x7a46('0x2e')][_0x7a46('0x11')]||0xa);_0x6f55a3[_0x7a46('0xf')]=qs['offset'](_0x2d8391[_0x7a46('0x2e')][_0x7a46('0xf')]);}var _0xecbcd1=_0x27842b[_0x7a46('0x68')](function(_0x5befbf){if(_0x5befbf===_0x7a46('0xd7')){var _0x190602={'attributes':['id',_0x7a46('0xd8'),_0x7a46('0xd9'),_0x7a46('0xda'),_0x7a46('0xdb'),_0x7a46('0xdc'),_0x7a46('0xdd'),_0x7a46('0xde'),_0x7a46('0xdf'),_0x7a46('0xe0'),_0x7a46('0xe1'),_0x7a46('0xe2'),_0x7a46('0xe3'),_0x7a46('0xe4'),_0x7a46('0xe5')],'where':{'ContactId':_0x2d8391[_0x7a46('0x26')]['id']},'include':[{'model':db[_0x7a46('0xb8')],'as':_0x7a46('0xb8'),'attributes':['id',_0x7a46('0x1b'),'fullname',_0x7a46('0x31')]}],'order':[[_0x7a46('0xe1'),_0x7a46('0xe6')]]};if(_0x2d8391[_0x7a46('0x2e')]['range']){_0x190602[_0x7a46('0x5a')][_0x7a46('0xe1')]={'$gte':_0x35cb16[_0x7a46('0x39')],'$lte':_0x35cb16['to']};}return db[_0x7a46('0x48')][_0x7a46('0xe7')](_0x190602)['then'](function(_0x19113e){_0x3206fe[_0x7a46('0x12')]+=_0x19113e[_0x7a46('0x12')];return _[_0x7a46('0x68')](_0x19113e[_0x7a46('0x9c')],function(_0x53a74b){var _0x4f7582=_0x53a74b[_0x7a46('0x3a')]({'plain':!![]});_0x4f7582[_0x7a46('0xce')]=_0x5befbf;if(_0x4f7582['User']){_0x4f7582[_0x7a46('0xb8')]={'id':_0x4f7582[_0x7a46('0xb8')]['id'],'name':_0x4f7582[_0x7a46('0xb8')][_0x7a46('0x1b')],'fullname':_0x4f7582[_0x7a46('0xb8')][_0x7a46('0xe8')],'alias':_0x4f7582[_0x7a46('0xb8')]['alias']};}return _0x4f7582;});});}else{var _0x2713ee=_[_0x7a46('0xe9')](_0x5befbf)+(_0x5befbf==='chat'?_0x7a46('0xea'):_0x7a46('0xeb'));var _0x13f1c6={'attributes':['id','closed',_0x7a46('0xec'),_0x7a46('0xe1'),_0x7a46('0xe0'),_0x7a46('0xed'),'secondDisposition','thirdDisposition',_0x7a46('0xe5'),_0x2713ee+'Id'],'where':{'ContactId':_0x2d8391[_0x7a46('0x26')]['id']},'include':[{'model':db[_0x2713ee],'as':'Account','attributes':['id',_0x7a46('0x1b'),_0x7a46('0xee')]},{'model':db['User'],'as':_0x7a46('0xef'),'attributes':['id',_0x7a46('0x1b'),_0x7a46('0xe8')]},{'model':db['Tag'],'as':'Tags','attributes':['id',_0x7a46('0x1b'),_0x7a46('0x60')],'through':{'attributes':[]}}],'order':[[_0x7a46('0xe1'),_0x7a46('0xe6')]]};if(_0x2d8391[_0x7a46('0x2e')]['range']){_0x13f1c6['where']['createdAt']={'$gte':_0x35cb16[_0x7a46('0x39')],'$lte':_0x35cb16['to']};}switch(_0x5befbf){case _0x7a46('0xc8'):_0x13f1c6[_0x7a46('0x77')][_0x7a46('0x59')](_0x7a46('0xf0'),_0x7a46('0xf1'),_0x7a46('0xf2'),_0x7a46('0xf3'),'osName',_0x7a46('0xf4'),_0x7a46('0xf5'),_0x7a46('0xf6'),_0x7a46('0xf7'));break;case _0x7a46('0xc7'):_0x13f1c6[_0x7a46('0x77')][_0x7a46('0x59')](_0x7a46('0xf8'),'substatus');break;case _0x7a46('0xca'):_0x13f1c6[_0x7a46('0x77')]['push'](_0x7a46('0xf9'),_0x7a46('0xfa'));break;}return db[_[_0x7a46('0xe9')](_0x5befbf)+_0x7a46('0xfb')][_0x7a46('0xe7')](_0x13f1c6)[_0x7a46('0x1f')](function(_0x5d4d01){_0x3206fe[_0x7a46('0x12')]+=_0x5d4d01[_0x7a46('0x12')];return _[_0x7a46('0x68')](_0x5d4d01[_0x7a46('0x9c')],function(_0x4106c2){var _0xd9d58=_0x4106c2[_0x7a46('0x3a')]({'plain':!![]});_0xd9d58[_0x7a46('0xce')]=_0x5befbf;if(_0xd9d58[_0x7a46('0xef')]){_0xd9d58[_0x7a46('0xef')]={'id':_0xd9d58['Owner']['id'],'name':_0xd9d58[_0x7a46('0xef')]['name'],'fullname':_0xd9d58[_0x7a46('0xef')][_0x7a46('0xe8')]};}return _0xd9d58;});});}});return Promise[_0x7a46('0x5d')](_0xecbcd1);})[_0x7a46('0x1f')](function(_0x7444b4){return _(_0x7444b4)[_0x7a46('0xfc')]()[_0x7a46('0xfd')](_0x7a46('0xe1'))[_0x7a46('0xfe')]()[_0x7a46('0xff')]();})[_0x7a46('0x1f')](function(_0x2d2428){_0x3206fe['rows']=_0x6f55a3[_0x7a46('0x11')]?_0x2d2428[_0x7a46('0x100')](_0x6f55a3[_0x7a46('0xf')],_0x6f55a3[_0x7a46('0xf')]+_0x6f55a3['limit']):_0x2d2428;return _0x3206fe;})['then'](respondWithFilteredResult(_0x35e6ba,_0x6f55a3))[_0x7a46('0x23')](handleError(_0x35e6ba,null));};
\ No newline at end of file
+var _0xeadc=['query','user','find','catch','CmContact','tags','keys','length','cf_','displayName','analytics','CmCustomField','findAll','columnName','alias','custom','values','info','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','forEach','merge','body','get','mergeWith','isArray','join','from','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperHistory','ReportAgentPreview','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','JscriptySessionReport','WhatsappInteraction','WhatsappQueueReport','isNil','dialTimezone','timezones','utcOffset','additionalPhones','each','duplicates','$or','ListId','hasOwnProperty','push','show','params','Tag','Tags','color','tag','Phones','ItemType','sequelize','literal','Phones.OrderBy','where','omit','map','format','cf_%d','$and','pickBy','startsWith','isEmpty','table','cm_contacts','setFields','toParam','text','phone','CmHopper','getTags','findOne','rawAttributes','filters','intersection','model','fields','attributes','order','sort','pick','filter','nolimit','setTags','setAdditionalPhones','all','ContactItemType','OrderBy','item_types','items','ItemTypeId','CmHopperAdditionalPhone','PHONE','`ItemType`.OrderBy','CmHopperId','item','ItemType.OrderBy','bulkCreate','getAdditionalPhones','duplicateAdditionalPhones','CmContactId','toContactId','rescheduleAdditionalPhones','getHoppers','ContactId','options','include','rows','getHopperHistories','includeAll','getHopperFinals','CmHopperFinal','getJscriptySessions','uploadCsv','No\x20ListId\x20specified','binding_keys','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','split','zipObject','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','file','filename','chmodSync','0777','child_process','fork','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','upload','createReadStream','parse','import','User','agent','binding','../../components/import/cm/csv2','stringify','message','exit','importUpdates','../../components/import/cm/csvUpdates','start\x20child\x20process\x20correctly!','error\x20child\x20process','getJourney','mail','sms','openchannel','fax','whatsapp','-createdAt','resolve','channel','Invalid\x20channel','toLowerCase','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20createdAt\x20filter','voice','uniqueid','type','source','destination','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','UserId','fullname','DESC','VoiceCallReport','findAndCountAll','chat','Website','Account','closed','closedAt','disposition','thirdDisposition','key','browserName','customerIp','deviceModel','osName','ratingMessage','ratingType','subject','substatus','externalUrl','threadId','startCase','Interaction','Owner','flatten','value','slice','moment','bluebird','util','path','lodash','papaparse','ioredis','../../components/contacts','../../components/parsers/qs','api','../../config/environment','../../config/environment/shared','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','status','json','offset','limit','undefined','count','Content-Range','update','then','destroy','end','error','stack','name','send','describe'];(function(_0x2fae15,_0x23322c){var _0x30bfb8=function(_0x451e0e){while(--_0x451e0e){_0x2fae15['push'](_0x2fae15['shift']());}};_0x30bfb8(++_0x23322c);}(_0xeadc,0x1e6));var _0xcead=function(_0xa706e0,_0x2021d2){_0xa706e0=_0xa706e0-0x0;var _0x2e7580=_0xeadc[_0xa706e0];return _0x2e7580;};'use strict';var moment=require(_0xcead('0x0'));var BPromise=require(_0xcead('0x1'));var util=require(_0xcead('0x2'));var path=require(_0xcead('0x3'));var fs=require('fs');var _=require(_0xcead('0x4'));var squel=require('squel');var Papa=require(_0xcead('0x5'));var Redis=require(_0xcead('0x6'));var contacts=require(_0xcead('0x7'));var qs=require(_0xcead('0x8'));var logger=require('../../config/logger')(_0xcead('0x9'));var config=require(_0xcead('0xa'));var shared=require(_0xcead('0xb'));var db=require(_0xcead('0xc'))['db'];config[_0xcead('0xd')]=_[_0xcead('0xe')](config[_0xcead('0xd')],{'host':_0xcead('0xf'),'port':0x18eb});var socket=require(_0xcead('0x10'))(new Redis(config[_0xcead('0xd')]));require('./cmContact.socket')[_0xcead('0x11')](socket);function respondWithResult(_0x448b28,_0x468b78){_0x468b78=_0x468b78||0xc8;return function(_0xea5c48){if(_0xea5c48){return _0x448b28[_0xcead('0x12')](_0x468b78)[_0xcead('0x13')](_0xea5c48);}};}function respondWithFilteredResult(_0x11c444,_0x5643dc){return function(_0x444e54){if(_0x444e54){var _0x4eb2c8=typeof _0x5643dc[_0xcead('0x14')]==='undefined'&&typeof _0x5643dc[_0xcead('0x15')]===_0xcead('0x16');var _0xe99980=_0x444e54['count'];var _0x1a45a7=_0x4eb2c8?0x0:_0x5643dc[_0xcead('0x14')];var _0x1a6088=_0x4eb2c8?_0x444e54[_0xcead('0x17')]:_0x5643dc[_0xcead('0x14')]+_0x5643dc[_0xcead('0x15')];var _0x31a522;if(_0x1a6088>=_0xe99980){_0x1a6088=_0xe99980;_0x31a522=0xc8;}else{_0x31a522=0xce;}_0x11c444[_0xcead('0x12')](_0x31a522);return _0x11c444['set'](_0xcead('0x18'),_0x1a45a7+'-'+_0x1a6088+'/'+_0xe99980)[_0xcead('0x13')](_0x444e54);}return null;};}function saveUpdates(_0x50aee3){return function(_0x2ae0db){if(_0x2ae0db){return _0x2ae0db[_0xcead('0x19')](_0x50aee3)[_0xcead('0x1a')](function(_0x11bd8b){return _0x11bd8b;});}return null;};}function removeEntity(_0x21fb37){return function(_0x234cb2){if(_0x234cb2){return _0x234cb2[_0xcead('0x1b')]()[_0xcead('0x1a')](function(){_0x21fb37['status'](0xcc)[_0xcead('0x1c')]();});}};}function handleEntityNotFound(_0x5f50af){return function(_0x8c2841){if(!_0x8c2841){_0x5f50af['sendStatus'](0x194);}return _0x8c2841;};}function handleError(_0x57cdd3,_0x283825){_0x283825=_0x283825||0x1f4;return function(_0x3a6ae4){logger[_0xcead('0x1d')](_0x3a6ae4[_0xcead('0x1e')]);if(_0x3a6ae4[_0xcead('0x1f')]){delete _0x3a6ae4[_0xcead('0x1f')];}_0x57cdd3[_0xcead('0x12')](_0x283825)[_0xcead('0x20')](_0x3a6ae4);};}exports['index']=function(_0x2e573c,_0x20e782){var _0x279b66={};return contacts[_0xcead('0x21')]()[_0xcead('0x1a')](function(_0x535085){_0x279b66=qs['getOptions'](_0x535085,_0x2e573c);return contacts['findAll'](_0x2e573c[_0xcead('0x22')],_0x2e573c[_0xcead('0x23')],_0x279b66,_0x535085);})[_0xcead('0x1a')](respondWithFilteredResult(_0x20e782,_0x279b66))['catch'](handleError(_0x20e782,null));};exports[_0xcead('0x1b')]=function(_0x5853e9,_0x2cea52){return db['CmContact'][_0xcead('0x24')]({'where':{'id':_0x5853e9['params']['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x2cea52,null))[_0xcead('0x1a')](removeEntity(_0x2cea52,null))[_0xcead('0x25')](handleError(_0x2cea52,null));};exports[_0xcead('0x21')]=function(_0x593d87,_0x1768a0){return db[_0xcead('0x26')]['describe']()[_0xcead('0x1a')](function(_0x19a802){delete _0x19a802[_0xcead('0x27')];for(var _0x48a30c=0x0;_0x48a30c<Object[_0xcead('0x28')](_0x19a802)[_0xcead('0x29')];_0x48a30c++){var _0x72e4a4=Object['keys'](_0x19a802)[_0x48a30c];if(!_['startsWith'](_0x72e4a4,_0xcead('0x2a'))){_0x19a802[_0x72e4a4]['columnName']=_0x72e4a4;_0x19a802[_0x72e4a4][_0xcead('0x2b')]=_0x72e4a4;}}return _0x19a802;})['then'](function(_0x457588){var _0x38bca6={'where':Boolean(_0x593d87[_0xcead('0x22')][_0xcead('0x2c')])===!![]?undefined:{'$or':[{'ListId':_0x593d87[_0xcead('0x22')]['id']},{'ListId':null}]},'raw':!![]};return db[_0xcead('0x2d')][_0xcead('0x2e')](_0x38bca6)['then'](function(_0x2e97b4){for(var _0x477893=0x0;_0x477893<_0x2e97b4[_0xcead('0x29')];_0x477893++){var _0x10c639=_0xcead('0x2a')+_0x2e97b4[_0x477893]['id'];if(_0x457588[_0x10c639]){_0x457588[_0x10c639][_0xcead('0x2f')]=_0x10c639;_0x457588[_0x10c639][_0xcead('0x2b')]=_0x2e97b4[_0x477893][_0xcead('0x30')];_0x457588[_0x10c639][_0xcead('0x31')]={'type':_0x2e97b4[_0x477893]['type'],'values':_0x2e97b4[_0x477893][_0xcead('0x32')]};}else{logger[_0xcead('0x33')](_0xcead('0x34'),_0x10c639);}}Object[_0xcead('0x28')](_0x457588)[_0xcead('0x35')](function(_0x2038fb){if(!_0x457588[_0x2038fb]['hasOwnProperty'](_0xcead('0x2f'))){delete _0x457588[_0x2038fb];}});return _0x457588;});})['then'](respondWithResult(_0x1768a0,null))[_0xcead('0x25')](handleError(_0x1768a0,null));};exports[_0xcead('0x36')]=function(_0x27593e,_0x37a681){var _0x51f64f;var _0x4497d8;var _0x5c71e2;if(_0x27593e['body']['id']){delete _0x27593e[_0xcead('0x37')]['id'];}return db[_0xcead('0x26')][_0xcead('0x2e')]({'where':{'id':[_0x27593e[_0xcead('0x37')]['to'],_0x27593e[_0xcead('0x37')]['from']]}})[_0xcead('0x1a')](function(_0x4d53a5){if(_0x4d53a5){if(_0x4d53a5['length']!==0x2){return null;}_0x4d53a5[0x0]=_0x4d53a5[0x0][_0xcead('0x38')]({'plain':!![]});_0x4d53a5[0x1]=_0x4d53a5[0x1][_0xcead('0x38')]({'plain':!![]});delete _0x4d53a5[0x0]['id'];delete _0x4d53a5[0x1]['id'];return _[_0xcead('0x39')](_0x4d53a5[0x0],_0x4d53a5[0x1],function(_0x1be31a,_0x332217){if(Array[_0xcead('0x3a')](_0x332217)&&!_0x332217[_0xcead('0x29')]){return _0x1be31a;}else if(!_0x332217){return _0x1be31a;}});}})[_0xcead('0x1a')](handleEntityNotFound(_0x37a681,null))[_0xcead('0x1a')](function(_0x5155ab){if(_0x5155ab){if(_0x5155ab[_0xcead('0x27')]&&_['isArray'](_0x5155ab['tags'])){_0x5155ab[_0xcead('0x27')]=_0x5155ab[_0xcead('0x27')][_0xcead('0x3b')]();}logger[_0xcead('0x33')]('[CmContact][merge]\x20to\x20%s\x20from\x20%s',_0x27593e['body']['to'],_0x27593e['body'][_0xcead('0x3c')]);return db['CmHopper'][_0xcead('0x1b')]({'where':{'ContactId':[_0x27593e[_0xcead('0x37')]['to'],_0x27593e[_0xcead('0x37')][_0xcead('0x3c')]]}})[_0xcead('0x1a')](function(_0x2eaa4c){logger['info']('[CmContact][merge][destroy][CmHopper],\x20%s',_0x2eaa4c);return db[_0xcead('0x3d')][_0xcead('0x1b')]({'where':{'ContactId':[_0x27593e[_0xcead('0x37')]['to'],_0x27593e[_0xcead('0x37')]['from']]}})[_0xcead('0x1a')](function(_0x2bc420){logger['info'](_0xcead('0x3e'),_0x2bc420);return db[_0xcead('0x26')][_0xcead('0x3f')](_0x5155ab);});});}})[_0xcead('0x1a')](function(_0x1ce049){if(_0x1ce049){_0x51f64f=_0x1ce049;_0x4497d8={'ContactId':_0x51f64f['id']};_0x5c71e2={'where':{'ContactId':[_0x27593e[_0xcead('0x37')]['to'],_0x27593e[_0xcead('0x37')][_0xcead('0x3c')]]}};return db[_0xcead('0x40')]['update'](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x41')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x42')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x43')]['update'](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x44')]['update'](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db['MailInteraction'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x44')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x45')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x46')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db['FaxInteraction'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db['FaxMessage'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x47')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x48')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x49')][_0xcead('0x19')]({'CmContactId':_0x51f64f['id']},{'where':{'CmContactId':[_0x27593e[_0xcead('0x37')]['to'],_0x27593e[_0xcead('0x37')][_0xcead('0x3c')]]}});}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db['CmHopperFinal'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x4a')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x4b')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db['VoiceCallReport'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x4c')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x4d')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x4e')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x4f')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db['SmsQueueReport'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db[_0xcead('0x50')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x51')]['update'](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db['WhatsappMessage'][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})['then'](function(){if(_0x51f64f){return db[_0xcead('0x52')][_0xcead('0x19')](_0x4497d8,_0x5c71e2);}})[_0xcead('0x1a')](function(){if(_0x51f64f){return db['CmContact'][_0xcead('0x1b')]({'where':{'id':[_0x27593e['body']['to'],_0x27593e[_0xcead('0x37')][_0xcead('0x3c')]]}});}})[_0xcead('0x1a')](function(){if(_0x51f64f){return _0x51f64f;}})[_0xcead('0x1a')](respondWithResult(_0x37a681,null))[_0xcead('0x25')](handleError(_0x37a681,null));};exports[_0xcead('0x3f')]=function(_0x5a1991,_0x13db28){return db[_0xcead('0x26')]['describe']()[_0xcead('0x1a')](function(_0x46a1bc){if(_0x5a1991['body'][_0xcead('0x27')]&&_[_0xcead('0x3a')](_0x5a1991['body'][_0xcead('0x27')])){if(_0x5a1991[_0xcead('0x37')][_0xcead('0x27')]['length']){_0x5a1991['body']['tags']=_0x5a1991[_0xcead('0x37')][_0xcead('0x27')][_0xcead('0x3b')](';')+';';}else{_0x5a1991[_0xcead('0x37')][_0xcead('0x27')]=null;}}else{_0x5a1991[_0xcead('0x37')][_0xcead('0x27')]=null;}if(!_[_0xcead('0x53')](_0x5a1991['body']['dialTimezone'])){var _0x1c3207=_0x5a1991['body'][_0xcead('0x54')];if(!_['isNil'](shared['timezones'][_0x1c3207]))_0x5a1991['body']['utcOffset']=shared[_0xcead('0x55')][_0x1c3207][_0xcead('0x56')];}return db[_0xcead('0x26')][_0xcead('0x3f')](_0x5a1991[_0xcead('0x37')],{'fields':_[_0xcead('0x28')](_0x46a1bc),'raw':!![]});})[_0xcead('0x1a')](function(_0x52820a){if(_0x5a1991[_0xcead('0x37')][_0xcead('0x57')]){return insertAdditionalPhones(_0x52820a,_0x5a1991[_0xcead('0x37')][_0xcead('0x57')]);}else{return _0x52820a;}})[_0xcead('0x1a')](respondWithResult(_0x13db28,0xc9))[_0xcead('0x25')](handleError(_0x13db28,null));};exports['bulkCreate']=function(_0x389f5e,_0x232df){var _0x3ac961=0x0;var _0x4518ee=0x0;var _0x6707de=0x0;var _0x550470=[];return db[_0xcead('0x26')][_0xcead('0x21')]()['then'](function(_0x1f1777){return BPromise[_0xcead('0x58')](_0x389f5e[_0xcead('0x37')],function(_0x1a4d88){var _0x1cd19f={'where':{'$or':[]},'defaults':_0x1a4d88,'fields':_[_0xcead('0x28')](_0x1f1777),'raw':!![]};if(_0x1a4d88[_0xcead('0x59')]){for(var _0x49b234=0x0;_0x49b234<_0x1a4d88[_0xcead('0x59')][_0xcead('0x29')];_0x49b234++){var _0x31179b={};_0x31179b[_0x1a4d88[_0xcead('0x59')][_0x49b234]]=_0x1a4d88[_0x1a4d88[_0xcead('0x59')][_0x49b234]];_0x1cd19f['where'][_0xcead('0x5a')]['push'](_0x31179b);}_0x1cd19f['where']['ListId']=_0x1a4d88[_0xcead('0x5b')];}return db['CmContact']['findOrCreate'](_0x1cd19f)['spread'](function(_0xf04eac,_0x4cee37){if(_0x4cee37){if(_0x1a4d88[_0xcead('0x5c')]('additionalPhones')){_0x550470[_0xcead('0x5d')]({'contact':_0xf04eac,'additionalPhones':_0x1a4d88[_0xcead('0x57')]});}_0x3ac961++;}else{_0x6707de++;}})[_0xcead('0x25')](function(){_0x4518ee++;});});})[_0xcead('0x1a')](function(_0x3655f4){if(_0x3655f4){if(_0x550470[_0xcead('0x29')]>0x0){return new Promise(function(_0x3b5128){var _0x8d6556=[];for(var _0x1bd7a0=0x0;_0x1bd7a0<_0x550470[_0xcead('0x29')];_0x1bd7a0++){_0x8d6556['push'](insertAdditionalPhones(_0x550470[_0x1bd7a0]['contact'],_0x550470[_0x1bd7a0][_0xcead('0x57')]));}Promise['all'](_0x8d6556)[_0xcead('0x1a')](function(){_0x3b5128(0x1);});})[_0xcead('0x1a')](function(){return{'success':_0x3ac961,'failure':_0x4518ee,'duplicates':_0x6707de};});}else{return{'success':_0x3ac961,'failure':_0x4518ee,'duplicates':_0x6707de};}}})[_0xcead('0x1a')](respondWithResult(_0x232df,0xc9))['catch'](handleError(_0x232df,null));};exports[_0xcead('0x5e')]=function(_0x527e81,_0x4144a5){var _0x2811ee;return db['CmContact'][_0xcead('0x21')]()[_0xcead('0x1a')](function(_0x514e78){return db[_0xcead('0x26')]['find']({'where':{'id':_0x527e81[_0xcead('0x5f')]['id']},'include':[{'model':db[_0xcead('0x60')],'as':_0xcead('0x61'),'attributes':['id',_0xcead('0x1f'),_0xcead('0x62')],'required':_0x527e81[_0xcead('0x22')][_0xcead('0x63')]?!![]:![]},{'model':db[_0xcead('0x49')],'as':_0xcead('0x64'),'where':{'CmContactId':_0x527e81[_0xcead('0x5f')]['id']},'required':![],'include':[{'model':db['ContactItemType'],'as':_0xcead('0x65')}]}],'order':[db[_0xcead('0x66')][_0xcead('0x67')](_0xcead('0x68'))],'attributes':_[_0xcead('0x28')](_0x514e78)});})['then'](function(_0x5afb95){if(!_[_0xcead('0x53')](_0x5afb95)){_0x2811ee=_0x5afb95[_0xcead('0x38')]({'plain':!![]});var _0x330655={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x5afb95&&_0x5afb95[_0xcead('0x5b')]){if(_0x5afb95[_0xcead('0x5b')]){_0x330655[_0xcead('0x69')]['$and'][_0xcead('0x5d')]({'ListId':{'$ne':_0x5afb95['ListId']}});}}return db[_0xcead('0x2d')][_0xcead('0x2e')](_0x330655);}})[_0xcead('0x1a')](function(_0x30642c){if(!_[_0xcead('0x53')](_0x30642c)){return _[_0xcead('0x6a')](_0x2811ee,_[_0xcead('0x6b')](_0x30642c,function(_0x52e0e4){return util[_0xcead('0x6c')](_0xcead('0x6d'),_0x52e0e4['id']);}));}})[_0xcead('0x1a')](handleEntityNotFound(_0x4144a5,null))[_0xcead('0x1a')](respondWithResult(_0x4144a5,null))['catch'](handleError(_0x4144a5,null));};exports[_0xcead('0x19')]=function(_0x3d3754,_0x170235){var _0x37608e;if(_0x3d3754[_0xcead('0x37')]['id']){delete _0x3d3754[_0xcead('0x37')]['id'];}if(!_[_0xcead('0x53')](_0x3d3754['body'][_0xcead('0x54')])){var _0x4811c7=_0x3d3754['body'][_0xcead('0x54')];if(!_[_0xcead('0x53')](shared[_0xcead('0x55')][_0x4811c7]))_0x3d3754[_0xcead('0x37')]['utcOffset']=shared[_0xcead('0x55')][_0x4811c7][_0xcead('0x56')];}return db['CmContact'][_0xcead('0x24')]({'where':{'id':_0x3d3754['params']['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x170235,null))[_0xcead('0x1a')](saveUpdates(_0x3d3754['body'],null))[_0xcead('0x1a')](function(_0x1527fd){_0x37608e=_0x1527fd;var _0x1c8fb8={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x1527fd&&_0x1527fd[_0xcead('0x5b')]){if(_0x1527fd[_0xcead('0x5b')]){_0x1c8fb8['where'][_0xcead('0x6e')][_0xcead('0x5d')]({'ListId':{'$ne':_0x1527fd[_0xcead('0x5b')]}});}}return db['CmCustomField'][_0xcead('0x2e')](_0x1c8fb8);})[_0xcead('0x1a')](function(_0x1e76bb){if(_0x1e76bb){return _['omit'](_[_0xcead('0x6f')](_0x3d3754['body'],function(_0x26fd12,_0x2b5471){return _[_0xcead('0x70')](_0x2b5471,_0xcead('0x2a'));}),_[_0xcead('0x6b')](_0x1e76bb,function(_0x3c02f1){return util['format'](_0xcead('0x6d'),_0x3c02f1['id']);}));}})[_0xcead('0x1a')](function(_0x4b6e65){if(_0x4b6e65&&!_[_0xcead('0x71')](_0x4b6e65)){var _0x5a90e8=squel['update']()[_0xcead('0x72')](_0xcead('0x73'))[_0xcead('0x74')](_0x4b6e65)[_0xcead('0x69')]('id\x20=\x20?',_0x3d3754[_0xcead('0x5f')]['id'])[_0xcead('0x75')]();return db[_0xcead('0x66')]['query'](_0x5a90e8[_0xcead('0x76')],{'replacements':_0x5a90e8[_0xcead('0x32')]});}})[_0xcead('0x1a')](function(){if(_0x3d3754[_0xcead('0x37')][_0xcead('0x77')]&&_0x37608e){return db[_0xcead('0x78')][_0xcead('0x19')]({'phone':_0x3d3754[_0xcead('0x37')][_0xcead('0x77')],'OrderBy':0x0},{'where':{'ContactId':_0x37608e['id']}});}})[_0xcead('0x1a')](function(){return _0x37608e;})[_0xcead('0x1a')](respondWithResult(_0x170235,null))['catch'](handleError(_0x170235,null));};exports[_0xcead('0x79')]=function(_0x7e80cd,_0x4770b6){var _0x32e7ce={};var _0x2e40e9={};var _0x2477cf;var _0x69eb53;return db['CmContact'][_0xcead('0x7a')]({'where':{'id':_0x7e80cd[_0xcead('0x5f')]['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x4770b6,null))[_0xcead('0x1a')](function(_0x20a022){if(_0x20a022){_0x2477cf=_0x20a022;_0x2e40e9['model']=_[_0xcead('0x28')](db['Tag'][_0xcead('0x7b')]);_0x2e40e9[_0xcead('0x22')]=_[_0xcead('0x28')](_0x7e80cd['query']);_0x2e40e9[_0xcead('0x7c')]=_[_0xcead('0x7d')](_0x2e40e9[_0xcead('0x7e')],_0x2e40e9[_0xcead('0x22')]);_0x32e7ce['attributes']=_[_0xcead('0x7d')](_0x2e40e9[_0xcead('0x7e')],qs['fields'](_0x7e80cd['query'][_0xcead('0x7f')]));_0x32e7ce[_0xcead('0x80')]=_0x32e7ce[_0xcead('0x80')][_0xcead('0x29')]?_0x32e7ce['attributes']:_0x2e40e9['model'];_0x32e7ce[_0xcead('0x81')]=qs[_0xcead('0x82')](_0x7e80cd[_0xcead('0x22')][_0xcead('0x82')]);_0x32e7ce[_0xcead('0x69')]=qs[_0xcead('0x7c')](_[_0xcead('0x83')](_0x7e80cd[_0xcead('0x22')],_0x2e40e9[_0xcead('0x7c')]));if(_0x7e80cd[_0xcead('0x22')]['filter']){_0x32e7ce[_0xcead('0x69')]=_['merge'](_0x32e7ce['where'],{'$or':_[_0xcead('0x6b')](_0x32e7ce[_0xcead('0x80')],function(_0x527cc6){var _0x1c38e0={};_0x1c38e0[_0x527cc6]={'$like':'%'+_0x7e80cd[_0xcead('0x22')][_0xcead('0x84')]+'%'};return _0x1c38e0;})});}_0x32e7ce=_[_0xcead('0x36')]({},_0x32e7ce,_0x7e80cd['options']);return _0x2477cf[_0xcead('0x79')](_0x32e7ce);}})[_0xcead('0x1a')](function(_0x2ebd9e){if(_0x2ebd9e){_0x69eb53=_0x2ebd9e[_0xcead('0x29')];if(!_0x7e80cd[_0xcead('0x22')]['hasOwnProperty'](_0xcead('0x85'))){_0x32e7ce[_0xcead('0x15')]=qs['limit'](_0x7e80cd['query']['limit']);_0x32e7ce[_0xcead('0x14')]=qs['offset'](_0x7e80cd[_0xcead('0x22')][_0xcead('0x14')]);}return _0x2477cf['getTags'](_0x32e7ce);}})[_0xcead('0x1a')](function(_0x549cde){if(_0x549cde){return _0x549cde?{'count':_0x69eb53,'rows':_0x549cde}:null;}})[_0xcead('0x1a')](respondWithResult(_0x4770b6,null))['catch'](handleError(_0x4770b6,null));};exports[_0xcead('0x86')]=function(_0x2cdab4,_0x5c4899){if(_0x2cdab4['body']['id']){delete _0x2cdab4['body']['id'];}return db['CmContact'][_0xcead('0x7a')]({'where':{'id':_0x2cdab4['params']['id']}})['then'](handleEntityNotFound(_0x5c4899,null))['then'](function(_0x1ffc42){if(_0x1ffc42){return _0x1ffc42[_0xcead('0x86')](_0x2cdab4[_0xcead('0x37')]['ids']||[]);}return null;})[_0xcead('0x1a')](respondWithResult(_0x5c4899,null))[_0xcead('0x25')](handleError(_0x5c4899,null));};exports[_0xcead('0x87')]=function(_0x223b29,_0x2bf877){var _0x259f9c=[];_0x259f9c[_0xcead('0x5d')](addAdditionalPhones(_0x223b29[_0xcead('0x37')]));Promise[_0xcead('0x88')](_0x259f9c)['then'](function(){_0x259f9c=[];_0x259f9c[_0xcead('0x5d')](deleteCmHopperPhones(_0x223b29[_0xcead('0x37')]['id']));_0x259f9c[_0xcead('0x5d')](addCmHopperPhones(_0x223b29[_0xcead('0x37')]['id']));Promise[_0xcead('0x88')](_0x259f9c)[_0xcead('0x1a')](function(){return[0x1];})[_0xcead('0x1a')](respondWithResult(_0x2bf877,null));});};function addAdditionalPhones(_0x5e6f28){var _0x1b4cc5;return new Promise(function(_0x507cfc){return db['CmContactHasItem'][_0xcead('0x1b')]({'where':{'CmContactId':_0x5e6f28['id']}})[_0xcead('0x1a')](function(){db[_0xcead('0x89')]['findAll']({'raw':!![],'attributes':['id',_0xcead('0x8a')]})['then'](function(_0x3dab88){var _0x375ec5=[];for(var _0x28a0ff=0x0;_0x28a0ff<_0x5e6f28['items'][_0xcead('0x29')];_0x28a0ff++){var _0x457876=_0x5e6f28[_0xcead('0x8b')]?_[_0xcead('0x53')](_0x5e6f28[_0xcead('0x8b')][_0x28a0ff])?'':_0x5e6f28[_0xcead('0x8b')][_0x28a0ff]:_0x5e6f28[_0xcead('0x8c')][_0x28a0ff][_0xcead('0x8d')]?_0x5e6f28[_0xcead('0x8c')][_0x28a0ff][_0xcead('0x8d')]:'';var _0x3ddffe=_[_0xcead('0x53')](_0x5e6f28[_0xcead('0x8c')][_0x28a0ff]['description'])?'':_0x5e6f28[_0xcead('0x8c')][_0x28a0ff]['description'];var _0x32445c=_0x457876+':'+_0x5e6f28['items'][_0x28a0ff][_0xcead('0x77')]+'§'+_0x3ddffe;if(_['isNil'](_0x1b4cc5))_0x1b4cc5=_0x32445c;else _0x1b4cc5+=';'+_0x32445c;var _0x289b6e=null;var _0x153fbd=null;if(_0x5e6f28[_0xcead('0x8b')]){if(!_[_0xcead('0x53')](_0x5e6f28['item_types'][_0x28a0ff])){_0x153fbd=_[_0xcead('0x24')](_0x3dab88,function(_0x21e707){return _0x21e707['id']===_0x5e6f28[_0xcead('0x8b')][_0x28a0ff];});if(!_[_0xcead('0x53')](_0x153fbd)){_0x289b6e=_0x153fbd['OrderBy'];}}}else{if(!_['isNil'](_0x5e6f28[_0xcead('0x8c')][_0x28a0ff])){_0x153fbd=_[_0xcead('0x24')](_0x3dab88,function(_0x6d71c2){return _0x6d71c2['id']===_0x5e6f28[_0xcead('0x8c')][_0x28a0ff][_0xcead('0x8d')];});if(!_[_0xcead('0x53')](_0x153fbd)){_0x289b6e=_0x28a0ff;}}}if(_[_0xcead('0x53')](_0x289b6e)){_0x289b6e=0x64;}_0x375ec5[_0xcead('0x5d')](addAdditionalPhone(_0x5e6f28['id'],_0x5e6f28[_0xcead('0x8c')][_0x28a0ff][_0xcead('0x77')],_0x5e6f28['item_types']?_[_0xcead('0x53')](_0x5e6f28[_0xcead('0x8b')][_0x28a0ff])?null:_0x5e6f28['item_types'][_0x28a0ff]:_0x5e6f28[_0xcead('0x8c')][_0x28a0ff][_0xcead('0x8d')]?_0x5e6f28[_0xcead('0x8c')][_0x28a0ff][_0xcead('0x8d')]:null,_0x289b6e,_0x3ddffe));}Promise['all'](_0x375ec5)[_0xcead('0x1a')](function(){db[_0xcead('0x26')]['update']({'AdditionalPhones':_0x1b4cc5},{'where':{'id':_0x5e6f28['id']}})[_0xcead('0x1a')](function(){_0x507cfc(0x1);});});});});});}function addAdditionalPhone(_0x5d3057,_0x5c4152,_0x4bd41d,_0x43ce64,_0x1b36b3){return db[_0xcead('0x49')][_0xcead('0x24')]({'where':{'CmContactId':_0x5d3057,'item':_0x5c4152}})['then'](function(_0x4fb1e5){if(_0x4fb1e5)logger[_0xcead('0x33')]('contact\x20phone\x20exists',_0x4fb1e5);else{db[_0xcead('0x49')]['create']({'CmContactId':_0x5d3057,'item':_0x5c4152,'ItemTypeId':_0x4bd41d,'OrderBy':_0x43ce64,'ItemClass':'PHONE','description':_0x1b36b3});}});}function deleteCmHopperPhones(_0x205b3a){return new Promise(function(_0x5cce1d){return db[_0xcead('0x78')][_0xcead('0x2e')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x205b3a}})[_0xcead('0x1a')](function(_0x30bc57){db[_0xcead('0x8e')]['destroy']({'where':{'CmHopperId':{'$in':_[_0xcead('0x6b')](_0x30bc57,'id')}}});})['then'](function(){_0x5cce1d(0x1);});});}function addCmHopperPhones(_0x68e82e){return new Promise(function(_0x4deeda){return db[_0xcead('0x78')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x68e82e}})[_0xcead('0x1a')](function(_0x363ae7){var _0xa9614d=[];_['map'](_0x363ae7,function(_0x1d82c1){_0xa9614d[_0xcead('0x5d')](createCmHopperPhone(_0x68e82e,_0x1d82c1['id']));});Promise[_0xcead('0x88')](_0xa9614d)[_0xcead('0x1a')](function(){_0x4deeda(0x1);});});});}function createCmHopperPhone(_0x47e428,_0x1adee0){return new Promise(function(_0x5ddaec){db[_0xcead('0x49')]['findAll']({'raw':!![],'attributes':['item','OrderBy'],'where':{'CmContactId':_0x47e428,'ItemClass':_0xcead('0x8f')},'include':[{'model':db['ContactItemType'],'attributes':[_0xcead('0x8a')],'as':_0xcead('0x65')}],'order':[_0xcead('0x8a'),db[_0xcead('0x66')][_0xcead('0x67')](_0xcead('0x90'))]})[_0xcead('0x1a')](function(_0x53ee4e){var _0x44928c=0x1;var _0x443e2d=_[_0xcead('0x6b')](_0x53ee4e,function(_0x2ce341){_0x2ce341[_0xcead('0x91')]=_0x1adee0;_0x2ce341[_0xcead('0x77')]=_0x2ce341[_0xcead('0x92')];_0x2ce341['OrderBy']=_0x44928c;delete _0x2ce341[_0xcead('0x93')];_0x44928c=_0x44928c+0x1;return _0x2ce341;});return db[_0xcead('0x8e')][_0xcead('0x94')](_0x443e2d,{});})[_0xcead('0x1a')](function(){_0x5ddaec(0x1);});});}function insertAdditionalPhones(_0x4f979f,_0x12db4d){return new Promise(function(_0x561bfe){var _0x272eed=[];for(var _0x1d563b=0x0;_0x1d563b<_0x12db4d[_0xcead('0x29')];_0x1d563b++){var _0x5daa04=_0x12db4d[_0x1d563b];_0x272eed[_0xcead('0x5d')](parseContactItemType(_0x5daa04));}Promise[_0xcead('0x88')](_0x272eed)[_0xcead('0x1a')](function(){var _0x222c89={'id':_0x4f979f['id'],'items':_0x12db4d};return addAdditionalPhones(_0x222c89)[_0xcead('0x1a')](function(){return addCmHopperPhones(_0x4f979f['id']);});})[_0xcead('0x1a')](function(){_0x561bfe(_0x4f979f);});});}function parseContactItemType(_0x259ff8){return new Promise(function(_0xef008c){if(_0x259ff8['hasOwnProperty'](_0xcead('0x8d'))){_0xef008c(_0x259ff8);}else{return db['ContactItemType'][_0xcead('0x24')]({'where':{'name':_0x259ff8[_0xcead('0x65')]}})['then'](function(_0x339049){if(_[_0xcead('0x53')](_0x339049))_0x259ff8[_0xcead('0x8d')]=null;else _0x259ff8[_0xcead('0x8d')]=_0x339049['id'];_0xef008c(_0x259ff8);});}});}exports[_0xcead('0x95')]=function(_0x4f99ed,_0x44c2fa){return db['CmContactHasItem'][_0xcead('0x2e')]({'raw':!![],'where':{'CmContactId':_0x4f99ed['params']['id'],'ItemClass':'PHONE'},'include':[{'model':db[_0xcead('0x89')],'as':_0xcead('0x65')}],'order':[[_0xcead('0x8a')],[db[_0xcead('0x66')]['literal']('`ItemType`.OrderBy')]]})[_0xcead('0x1a')](function(_0x4615b1){return _0x4615b1;})[_0xcead('0x1a')](respondWithResult(_0x44c2fa,null))[_0xcead('0x25')](handleError(_0x44c2fa,null));};exports[_0xcead('0x96')]=function(_0x1ff137,_0x120d70){return db[_0xcead('0x49')][_0xcead('0x2e')]({'raw':!![],'where':{'CmContactId':_0x1ff137['body']['fromContactId']}})[_0xcead('0x1a')](function(_0x44d99d){var _0x1a06ea=_['map'](_0x44d99d,function(_0x50a499){_0x50a499[_0xcead('0x97')]=_0x1ff137[_0xcead('0x37')][_0xcead('0x98')];return _0x50a499;});return db[_0xcead('0x49')][_0xcead('0x94')](_0x1a06ea,{});})[_0xcead('0x1a')](function(){return addCmHopperPhones(_0x1ff137[_0xcead('0x37')][_0xcead('0x98')]);})['then'](function(){return['ok'];})[_0xcead('0x1a')](respondWithResult(_0x120d70,null))[_0xcead('0x25')](handleError(_0x120d70,null));};exports[_0xcead('0x99')]=function(_0x588837,_0x561062){var _0x4a4ac3=[];_0x4a4ac3[_0xcead('0x5d')](createCmHopperPhone(_0x588837[_0xcead('0x37')]['id'],_0x588837[_0xcead('0x37')]['hopperId']));Promise[_0xcead('0x88')](_0x4a4ac3)[_0xcead('0x1a')](function(){return[0x1];})[_0xcead('0x1a')](respondWithResult(_0x561062,null));};exports[_0xcead('0x9a')]=function(_0x405b3e,_0x408734){var _0x260702={'raw':![],'where':{}};var _0x9a0280={};var _0x518555={'count':0x0,'rows':[]};return db[_0xcead('0x26')][_0xcead('0x7a')]({'where':{'id':_0x405b3e['params']['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x408734,null))[_0xcead('0x1a')](function(_0x32d499){if(_0x32d499){_0x9a0280[_0xcead('0x7e')]=_['keys'](db[_0xcead('0x78')][_0xcead('0x7b')]);_0x9a0280['query']=_[_0xcead('0x28')](_0x405b3e['query']);_0x9a0280[_0xcead('0x7c')]=_[_0xcead('0x7d')](_0x9a0280[_0xcead('0x7e')],_0x9a0280[_0xcead('0x22')]);_0x260702['attributes']=_['intersection'](_0x9a0280[_0xcead('0x7e')],qs[_0xcead('0x7f')](_0x405b3e[_0xcead('0x22')][_0xcead('0x7f')]));_0x260702['attributes']=_0x260702['attributes'][_0xcead('0x29')]?_0x260702[_0xcead('0x80')]:_0x9a0280['model'];if(!_0x405b3e[_0xcead('0x22')][_0xcead('0x5c')](_0xcead('0x85'))){_0x260702[_0xcead('0x15')]=qs[_0xcead('0x15')](_0x405b3e[_0xcead('0x22')][_0xcead('0x15')]);_0x260702[_0xcead('0x14')]=qs['offset'](_0x405b3e[_0xcead('0x22')][_0xcead('0x14')]);}_0x260702[_0xcead('0x81')]=qs[_0xcead('0x82')](_0x405b3e[_0xcead('0x22')]['sort']);_0x260702[_0xcead('0x69')]=qs[_0xcead('0x7c')](_[_0xcead('0x83')](_0x405b3e[_0xcead('0x22')],_0x9a0280['filters']));_0x260702['where'][_0xcead('0x9b')]=_0x32d499['id'];if(_0x405b3e['query'][_0xcead('0x84')]){_0x260702[_0xcead('0x69')]=_[_0xcead('0x36')](_0x260702[_0xcead('0x69')],{'$or':_[_0xcead('0x6b')](_0x260702['attributes'],function(_0x5377c1){var _0x100729={};_0x100729[_0x5377c1]={'$like':'%'+_0x405b3e[_0xcead('0x22')][_0xcead('0x84')]+'%'};return _0x100729;})});}_0x260702=_[_0xcead('0x36')]({},_0x260702,_0x405b3e[_0xcead('0x9c')]);return db[_0xcead('0x78')][_0xcead('0x17')]({'where':_0x260702['where']})[_0xcead('0x1a')](function(_0x3c152e){_0x518555['count']=_0x3c152e;if(_0x405b3e['query']['includeAll']){_0x260702[_0xcead('0x9d')]=[{'all':!![]}];}return db[_0xcead('0x78')][_0xcead('0x2e')](_0x260702);})['then'](function(_0x26f69e){_0x518555[_0xcead('0x9e')]=_0x26f69e;return _0x518555;});}})['then'](respondWithFilteredResult(_0x408734,_0x260702))[_0xcead('0x25')](handleError(_0x408734,null));};exports[_0xcead('0x9f')]=function(_0x191971,_0x5388ae){var _0x3f236b={'raw':!![],'where':{}};var _0x4f71a2={};var _0x3b0a0f={'count':0x0,'rows':[]};return db[_0xcead('0x26')][_0xcead('0x7a')]({'where':{'id':_0x191971['params']['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x5388ae,null))[_0xcead('0x1a')](function(_0x2ab61f){if(_0x2ab61f){_0x4f71a2[_0xcead('0x7e')]=_['keys'](db[_0xcead('0x4a')][_0xcead('0x7b')]);_0x4f71a2[_0xcead('0x22')]=_[_0xcead('0x28')](_0x191971[_0xcead('0x22')]);_0x4f71a2[_0xcead('0x7c')]=_['intersection'](_0x4f71a2[_0xcead('0x7e')],_0x4f71a2[_0xcead('0x22')]);_0x3f236b[_0xcead('0x80')]=_[_0xcead('0x7d')](_0x4f71a2[_0xcead('0x7e')],qs[_0xcead('0x7f')](_0x191971[_0xcead('0x22')][_0xcead('0x7f')]));_0x3f236b[_0xcead('0x80')]=_0x3f236b[_0xcead('0x80')][_0xcead('0x29')]?_0x3f236b[_0xcead('0x80')]:_0x4f71a2[_0xcead('0x7e')];if(!_0x191971[_0xcead('0x22')]['hasOwnProperty']('nolimit')){_0x3f236b[_0xcead('0x15')]=qs['limit'](_0x191971[_0xcead('0x22')][_0xcead('0x15')]);_0x3f236b[_0xcead('0x14')]=qs[_0xcead('0x14')](_0x191971['query'][_0xcead('0x14')]);}_0x3f236b['order']=qs[_0xcead('0x82')](_0x191971['query'][_0xcead('0x82')]);_0x3f236b[_0xcead('0x69')]=qs[_0xcead('0x7c')](_[_0xcead('0x83')](_0x191971[_0xcead('0x22')],_0x4f71a2['filters']));_0x3f236b[_0xcead('0x69')][_0xcead('0x9b')]=_0x2ab61f['id'];if(_0x191971[_0xcead('0x22')][_0xcead('0x84')]){_0x3f236b['where']=_[_0xcead('0x36')](_0x3f236b[_0xcead('0x69')],{'$or':_[_0xcead('0x6b')](_0x3f236b['attributes'],function(_0x419efd){var _0x3ec1d7={};_0x3ec1d7[_0x419efd]={'$like':'%'+_0x191971[_0xcead('0x22')][_0xcead('0x84')]+'%'};return _0x3ec1d7;})});}_0x3f236b=_[_0xcead('0x36')]({},_0x3f236b,_0x191971[_0xcead('0x9c')]);return db[_0xcead('0x4a')][_0xcead('0x17')]({'where':_0x3f236b[_0xcead('0x69')]})[_0xcead('0x1a')](function(_0x7670ac){_0x3b0a0f[_0xcead('0x17')]=_0x7670ac;if(_0x191971[_0xcead('0x22')][_0xcead('0xa0')]){_0x3f236b[_0xcead('0x9d')]=[{'all':!![]}];}return db['CmHopperHistory']['findAll'](_0x3f236b);})[_0xcead('0x1a')](function(_0xe96ecf){_0x3b0a0f[_0xcead('0x9e')]=_0xe96ecf;return _0x3b0a0f;});}})[_0xcead('0x1a')](respondWithFilteredResult(_0x5388ae,_0x3f236b))[_0xcead('0x25')](handleError(_0x5388ae,null));};exports[_0xcead('0xa1')]=function(_0x3b5270,_0x17cb77){var _0x3e628e={'raw':!![],'where':{}};var _0x189281={};var _0x383884={'count':0x0,'rows':[]};return db['CmContact'][_0xcead('0x7a')]({'where':{'id':_0x3b5270['params']['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x17cb77,null))['then'](function(_0x524586){if(_0x524586){_0x189281[_0xcead('0x7e')]=_[_0xcead('0x28')](db['CmHopperFinal'][_0xcead('0x7b')]);_0x189281[_0xcead('0x22')]=_['keys'](_0x3b5270[_0xcead('0x22')]);_0x189281[_0xcead('0x7c')]=_['intersection'](_0x189281[_0xcead('0x7e')],_0x189281[_0xcead('0x22')]);_0x3e628e[_0xcead('0x80')]=_[_0xcead('0x7d')](_0x189281[_0xcead('0x7e')],qs[_0xcead('0x7f')](_0x3b5270[_0xcead('0x22')]['fields']));_0x3e628e['attributes']=_0x3e628e[_0xcead('0x80')][_0xcead('0x29')]?_0x3e628e[_0xcead('0x80')]:_0x189281[_0xcead('0x7e')];if(!_0x3b5270[_0xcead('0x22')][_0xcead('0x5c')](_0xcead('0x85'))){_0x3e628e['limit']=qs[_0xcead('0x15')](_0x3b5270['query'][_0xcead('0x15')]);_0x3e628e[_0xcead('0x14')]=qs[_0xcead('0x14')](_0x3b5270[_0xcead('0x22')][_0xcead('0x14')]);}_0x3e628e[_0xcead('0x81')]=qs[_0xcead('0x82')](_0x3b5270[_0xcead('0x22')]['sort']);_0x3e628e[_0xcead('0x69')]=qs[_0xcead('0x7c')](_[_0xcead('0x83')](_0x3b5270[_0xcead('0x22')],_0x189281[_0xcead('0x7c')]));_0x3e628e['where'][_0xcead('0x9b')]=_0x524586['id'];if(_0x3b5270[_0xcead('0x22')]['filter']){_0x3e628e[_0xcead('0x69')]=_[_0xcead('0x36')](_0x3e628e[_0xcead('0x69')],{'$or':_['map'](_0x3e628e['attributes'],function(_0x270dda){var _0x31864a={};_0x31864a[_0x270dda]={'$like':'%'+_0x3b5270[_0xcead('0x22')][_0xcead('0x84')]+'%'};return _0x31864a;})});}_0x3e628e=_['merge']({},_0x3e628e,_0x3b5270[_0xcead('0x9c')]);return db[_0xcead('0xa2')][_0xcead('0x17')]({'where':_0x3e628e[_0xcead('0x69')]})[_0xcead('0x1a')](function(_0x3988e6){_0x383884[_0xcead('0x17')]=_0x3988e6;if(_0x3b5270[_0xcead('0x22')]['includeAll']){_0x3e628e[_0xcead('0x9d')]=[{'all':!![]}];}return db[_0xcead('0xa2')][_0xcead('0x2e')](_0x3e628e);})['then'](function(_0x2d92f5){_0x383884[_0xcead('0x9e')]=_0x2d92f5;return _0x383884;});}})['then'](respondWithFilteredResult(_0x17cb77,_0x3e628e))[_0xcead('0x25')](handleError(_0x17cb77,null));};exports[_0xcead('0xa3')]=function(_0x2ed13b,_0x3e7323){var _0x2e17f7={'raw':!![],'where':{}};var _0x254cc0={};var _0x5b2d78={'count':0x0,'rows':[]};return db[_0xcead('0x26')]['findOne']({'where':{'id':_0x2ed13b['params']['id']}})[_0xcead('0x1a')](handleEntityNotFound(_0x3e7323,null))[_0xcead('0x1a')](function(_0x20df44){if(_0x20df44){_0x254cc0[_0xcead('0x7e')]=_[_0xcead('0x28')](db[_0xcead('0x50')][_0xcead('0x7b')]);_0x254cc0[_0xcead('0x22')]=_[_0xcead('0x28')](_0x2ed13b[_0xcead('0x22')]);_0x254cc0['filters']=_[_0xcead('0x7d')](_0x254cc0[_0xcead('0x7e')],_0x254cc0[_0xcead('0x22')]);_0x2e17f7[_0xcead('0x80')]=_[_0xcead('0x7d')](_0x254cc0[_0xcead('0x7e')],qs['fields'](_0x2ed13b[_0xcead('0x22')][_0xcead('0x7f')]));_0x2e17f7[_0xcead('0x80')]=_0x2e17f7['attributes'][_0xcead('0x29')]?_0x2e17f7['attributes']:_0x254cc0[_0xcead('0x7e')];if(!_0x2ed13b[_0xcead('0x22')][_0xcead('0x5c')](_0xcead('0x85'))){_0x2e17f7[_0xcead('0x15')]=qs[_0xcead('0x15')](_0x2ed13b[_0xcead('0x22')][_0xcead('0x15')]);_0x2e17f7[_0xcead('0x14')]=qs[_0xcead('0x14')](_0x2ed13b[_0xcead('0x22')]['offset']);}_0x2e17f7[_0xcead('0x81')]=qs[_0xcead('0x82')](_0x2ed13b[_0xcead('0x22')]['sort']);_0x2e17f7[_0xcead('0x69')]=qs[_0xcead('0x7c')](_[_0xcead('0x83')](_0x2ed13b[_0xcead('0x22')],_0x254cc0[_0xcead('0x7c')]));_0x2e17f7['where']['ContactId']=_0x20df44['id'];if(_0x2ed13b['query']['filter']){_0x2e17f7[_0xcead('0x69')]=_[_0xcead('0x36')](_0x2e17f7['where'],{'$or':_[_0xcead('0x6b')](_0x2e17f7['attributes'],function(_0x668d37){var _0x30a3c9={};_0x30a3c9[_0x668d37]={'$like':'%'+_0x2ed13b['query'][_0xcead('0x84')]+'%'};return _0x30a3c9;})});}_0x2e17f7=_[_0xcead('0x36')]({},_0x2e17f7,_0x2ed13b['options']);return db[_0xcead('0x50')][_0xcead('0x17')]({'where':_0x2e17f7[_0xcead('0x69')]})[_0xcead('0x1a')](function(_0xfd2367){_0x5b2d78['count']=_0xfd2367;if(_0x2ed13b[_0xcead('0x22')][_0xcead('0xa0')]){_0x2e17f7['include']=[{'all':!![]}];}return db[_0xcead('0x50')][_0xcead('0x2e')](_0x2e17f7);})['then'](function(_0xd533b0){_0x5b2d78[_0xcead('0x9e')]=_0xd533b0;return _0x5b2d78;});}})[_0xcead('0x1a')](respondWithFilteredResult(_0x3e7323,_0x2e17f7))[_0xcead('0x25')](handleError(_0x3e7323,null));};exports[_0xcead('0xa4')]=function(_0x2779a2,_0x47b329){try{if(!_0x2779a2[_0xcead('0x37')][_0xcead('0x5b')]){throw new Error(_0xcead('0xa5'));}if(!_0x2779a2[_0xcead('0x37')][_0xcead('0xa6')]){throw new Error('No\x20association\x20keys\x20specified!');}if(!_0x2779a2[_0xcead('0x37')][_0xcead('0xa7')]){throw new Error(_0xcead('0xa8'));}if(!_0x2779a2[_0xcead('0x37')][_0xcead('0xa9')]){throw new Error(_0xcead('0xaa'));}var _0x47eafb=_0x2779a2['body'][_0xcead('0xa6')][_0xcead('0xab')](',');var _0x5db194=_0x2779a2['body'][_0xcead('0xa7')][_0xcead('0xab')](',');if(!_0x47eafb['length']||!_0x5db194['length']||_0x47eafb[_0xcead('0x29')]!==_0x5db194[_0xcead('0x29')]){throw new Error('Incorrect\x20binding\x20parameters\x20passed!');}_0x2779a2[_0xcead('0x37')][_0xcead('0x7f')]=_[_0xcead('0xac')](_0x47eafb,_0x5db194);if(!_0x2779a2[_0xcead('0x37')][_0xcead('0x7f')]['phone']){throw new Error(_0xcead('0xad'));}if(!_0x2779a2[_0xcead('0x37')][_0xcead('0x7f')][_0xcead('0xae')]){throw new Error(_0xcead('0xaf'));}var _0x34707c=path[_0xcead('0x3b')](config[_0xcead('0xb0')],'server/files/tmp',_0x2779a2[_0xcead('0xb1')][_0xcead('0xb2')]);fs[_0xcead('0xb3')](_0x34707c,parseInt(_0xcead('0xb4'),0x8));var _0x3a90b1=require(_0xcead('0xb5'))[_0xcead('0xb6')](path['join'](__dirname,_0xcead('0xb7')),[_0x34707c,_0x2779a2[_0xcead('0x37')]['binding_keys'],_0x2779a2[_0xcead('0x37')][_0xcead('0xa7')],_0x2779a2[_0xcead('0x37')][_0xcead('0x5b')],_0x2779a2['body'][_0xcead('0xb8')],_0x2779a2[_0xcead('0x37')][_0xcead('0x59')],_0x2779a2['body']['socket_timestamp']]);return _0x47b329[_0xcead('0x12')](0xc8)[_0xcead('0x13')]({'message':_0xcead('0xb9'),'pid':_0x3a90b1[_0xcead('0xba')]});}catch(_0x4eeebf){return _0x47b329[_0xcead('0x12')](0x1f4)[_0xcead('0x20')](_0x4eeebf);}};exports[_0xcead('0xbb')]=function(_0x25cc0c,_0x1ecb5e){var _0x4463d7=fs[_0xcead('0xbc')](_0x25cc0c[_0xcead('0xb1')][_0xcead('0x3')]);Papa[_0xcead('0xbd')](_0x4463d7,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x16de08){return _0x1ecb5e[_0xcead('0x12')](0xc8)[_0xcead('0x13')]({'file':_0x25cc0c[_0xcead('0xb1')],'fields':_0x16de08['meta'][_0xcead('0x7f')]});}});};exports[_0xcead('0xbe')]=function(_0x2364da,_0x5e0fdb){return db[_0xcead('0xbf')][_0xcead('0x2e')]({'raw':!![],'attributes':['id'],'where':{'role':_0xcead('0xc0')}})[_0xcead('0x1a')](function(_0x456727){var _0x148cbb=![];if(!_0x2364da['body'][_0xcead('0x5b')]){throw new Error('No\x20ListId\x20specified');}if(!_0x2364da[_0xcead('0x37')][_0xcead('0xc1')][_0xcead('0x77')]){throw new Error(_0xcead('0xad'));}if(!_0x2364da[_0xcead('0x37')][_0xcead('0xc1')][_0xcead('0xae')]){throw new Error(_0xcead('0xaf'));}if(!_0x2364da[_0xcead('0x37')][_0xcead('0xa9')]){throw new Error(_0xcead('0xaa'));}var _0x243824=require('child_process')[_0xcead('0xb6')](path[_0xcead('0x3b')](__dirname,_0xcead('0xc2')),[_0x2364da[_0xcead('0x5f')]['id'],JSON['stringify'](_0x2364da[_0xcead('0x37')]),JSON[_0xcead('0xc3')](_0x456727)]);_0x243824['on'](_0xcead('0xc4'),function(){_0x148cbb=!![];return _0x5e0fdb[_0xcead('0x12')](0xc8)[_0xcead('0x13')]({'message':'start\x20child\x20process\x20correctly!','pid':_0x243824[_0xcead('0xba')]});});_0x243824['on'](_0xcead('0xc5'),function(_0x138b45){if(_0x138b45&&!_0x148cbb){return _0x5e0fdb[_0xcead('0x12')](0x1f4)[_0xcead('0x13')]({'message':'error\x20child\x20process','pid':_0x243824[_0xcead('0xba')]});}});})[_0xcead('0x25')](handleError(_0x5e0fdb,null));};exports[_0xcead('0xc6')]=function(_0x4282fd,_0x4c74f5){return db[_0xcead('0xbf')][_0xcead('0x2e')]({'raw':!![],'attributes':['id'],'where':{'role':_0xcead('0xc0')}})[_0xcead('0x1a')](function(_0x310265){var _0x2af65d=![];if(!_0x4282fd[_0xcead('0x37')][_0xcead('0x5b')]){throw new Error(_0xcead('0xa5'));}if(!_0x4282fd[_0xcead('0x37')]['binding']['phone']){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x4282fd[_0xcead('0x37')][_0xcead('0xc1')][_0xcead('0xae')]){throw new Error(_0xcead('0xaf'));}if(!_0x4282fd[_0xcead('0x37')]['socket_timestamp']){throw new Error(_0xcead('0xaa'));}var _0x3e61e0=require('child_process')['fork'](path[_0xcead('0x3b')](__dirname,_0xcead('0xc7')),[_0x4282fd[_0xcead('0x5f')]['id'],JSON[_0xcead('0xc3')](_0x4282fd['body']),JSON['stringify'](_0x310265)]);_0x3e61e0['on'](_0xcead('0xc4'),function(){_0x2af65d=!![];return _0x4c74f5[_0xcead('0x12')](0xc8)[_0xcead('0x13')]({'message':_0xcead('0xc8'),'pid':_0x3e61e0['pid']});});_0x3e61e0['on'](_0xcead('0xc5'),function(_0x31aada){if(_0x31aada&&!_0x2af65d){return _0x4c74f5[_0xcead('0x12')](0x1f4)[_0xcead('0x13')]({'message':_0xcead('0xc9'),'pid':_0x3e61e0['pid']});}});})[_0xcead('0x25')](handleError(_0x4c74f5,null));};exports[_0xcead('0xca')]=function(_0x51719b,_0x1c90fc){var _0x4b95c0=[_0xcead('0xcb'),'chat',_0xcead('0xcc'),_0xcead('0xcd'),_0xcead('0xce'),_0xcead('0xcf'),'voice'];var _0x2e41e4={'offset':0x0,'order':qs[_0xcead('0x82')](_0xcead('0xd0'))},_0x1ae9d7={'count':0x0,'rows':[]};Promise[_0xcead('0xd1')]()['then'](function(){if(_0x51719b[_0xcead('0x22')][_0xcead('0xd2')]){if(!_['includes'](_0x4b95c0,_0x51719b['query'][_0xcead('0xd2')]['toLowerCase']())){throw new Error(_0xcead('0xd3'));}_0x4b95c0=[_0x51719b[_0xcead('0x22')][_0xcead('0xd2')][_0xcead('0xd4')]()];}if(_0x51719b[_0xcead('0x22')][_0xcead('0xd5')]){try{var _0x2571df=JSON['parse'](_0x51719b['query'][_0xcead('0xd5')]);if(!moment(_0x2571df[_0xcead('0x3c')])[_0xcead('0xd6')]()){throw new Error(_0xcead('0xd7'));}if(!moment(_0x2571df['to'])[_0xcead('0xd6')]()){throw new Error('Invalid\x20date\x20for\x20range\x20to\x20filter');}}catch(_0x4562c9){throw new Error(_0xcead('0xd8'));}}if(!_0x51719b[_0xcead('0x22')][_0xcead('0x5c')]('nolimit')){_0x2e41e4[_0xcead('0x15')]=qs[_0xcead('0x15')](_0x51719b[_0xcead('0x22')][_0xcead('0x15')]||0xa);_0x2e41e4['offset']=qs[_0xcead('0x14')](_0x51719b[_0xcead('0x22')][_0xcead('0x14')]);}var _0x271267=_0x4b95c0[_0xcead('0x6b')](function(_0x818ca4){if(_0x818ca4===_0xcead('0xd9')){var _0x198b60={'attributes':['id',_0xcead('0xda'),_0xcead('0xdb'),_0xcead('0xdc'),_0xcead('0xdd'),_0xcead('0xde'),_0xcead('0xdf'),_0xcead('0xe0'),_0xcead('0xe1'),_0xcead('0xe2'),_0xcead('0xe3'),_0xcead('0xe4'),_0xcead('0xe5'),_0xcead('0xe6'),_0xcead('0xe7')],'where':{'ContactId':_0x51719b['params']['id']},'include':[{'model':db[_0xcead('0xbf')],'as':_0xcead('0xbf'),'attributes':['id',_0xcead('0x1f'),_0xcead('0xe8'),_0xcead('0x30')]}],'order':[[_0xcead('0xe3'),_0xcead('0xe9')]]};if(_0x51719b[_0xcead('0x22')][_0xcead('0xd5')]){_0x198b60['where'][_0xcead('0xe3')]={'$gte':_0x2571df[_0xcead('0x3c')],'$lte':_0x2571df['to']};}return db[_0xcead('0xea')][_0xcead('0xeb')](_0x198b60)[_0xcead('0x1a')](function(_0x425eaa){_0x1ae9d7[_0xcead('0x17')]+=_0x425eaa[_0xcead('0x17')];return _[_0xcead('0x6b')](_0x425eaa[_0xcead('0x9e')],function(_0xa704fc){var _0x6ef208=_0xa704fc['get']({'plain':!![]});_0x6ef208[_0xcead('0xd2')]=_0x818ca4;if(_0x6ef208[_0xcead('0xbf')]){_0x6ef208[_0xcead('0xbf')]={'id':_0x6ef208['User']['id'],'name':_0x6ef208[_0xcead('0xbf')][_0xcead('0x1f')],'fullname':_0x6ef208[_0xcead('0xbf')][_0xcead('0xe8')],'alias':_0x6ef208[_0xcead('0xbf')]['alias']};}return _0x6ef208;});});}else{var _0x552cf9=_['startCase'](_0x818ca4)+(_0x818ca4===_0xcead('0xec')?_0xcead('0xed'):_0xcead('0xee'));var _0x2cb3eb={'attributes':['id',_0xcead('0xef'),_0xcead('0xf0'),_0xcead('0xe3'),_0xcead('0xe2'),_0xcead('0xf1'),'secondDisposition',_0xcead('0xf2'),_0xcead('0xe7'),_0x552cf9+'Id'],'where':{'ContactId':_0x51719b[_0xcead('0x5f')]['id']},'include':[{'model':db[_0x552cf9],'as':_0xcead('0xee'),'attributes':['id',_0xcead('0x1f'),_0xcead('0xf3')]},{'model':db[_0xcead('0xbf')],'as':'Owner','attributes':['id',_0xcead('0x1f'),_0xcead('0xe8')]},{'model':db[_0xcead('0x60')],'as':'Tags','attributes':['id',_0xcead('0x1f'),_0xcead('0x62')],'through':{'attributes':[]}}],'order':[[_0xcead('0xe3'),'DESC']]};if(_0x51719b[_0xcead('0x22')][_0xcead('0xd5')]){_0x2cb3eb[_0xcead('0x69')]['createdAt']={'$gte':_0x2571df['from'],'$lte':_0x2571df['to']};}switch(_0x818ca4){case _0xcead('0xec'):_0x2cb3eb['attributes']['push'](_0xcead('0xf4'),_0xcead('0xf5'),'customerPort',_0xcead('0xf6'),_0xcead('0xf7'),_0xcead('0xf8'),_0xcead('0xf9'),'ratingValue','referer');break;case _0xcead('0xcb'):_0x2cb3eb['attributes'][_0xcead('0x5d')](_0xcead('0xfa'),_0xcead('0xfb'));break;case _0xcead('0xcd'):_0x2cb3eb['attributes'][_0xcead('0x5d')](_0xcead('0xfc'),_0xcead('0xfd'));break;}return db[_[_0xcead('0xfe')](_0x818ca4)+_0xcead('0xff')][_0xcead('0xeb')](_0x2cb3eb)['then'](function(_0x49a7c6){_0x1ae9d7[_0xcead('0x17')]+=_0x49a7c6['count'];return _['map'](_0x49a7c6['rows'],function(_0x3b549d){var _0x36c752=_0x3b549d['get']({'plain':!![]});_0x36c752[_0xcead('0xd2')]=_0x818ca4;if(_0x36c752[_0xcead('0x100')]){_0x36c752[_0xcead('0x100')]={'id':_0x36c752[_0xcead('0x100')]['id'],'name':_0x36c752[_0xcead('0x100')][_0xcead('0x1f')],'fullname':_0x36c752[_0xcead('0x100')][_0xcead('0xe8')]};}return _0x36c752;});});}});return Promise[_0xcead('0x88')](_0x271267);})[_0xcead('0x1a')](function(_0xc3a6e6){return _(_0xc3a6e6)[_0xcead('0x101')]()['sortBy'](_0xcead('0xe3'))['reverse']()[_0xcead('0x102')]();})[_0xcead('0x1a')](function(_0x1b5d7d){_0x1ae9d7[_0xcead('0x9e')]=_0x2e41e4[_0xcead('0x15')]?_0x1b5d7d[_0xcead('0x103')](_0x2e41e4['offset'],_0x2e41e4[_0xcead('0x14')]+_0x2e41e4[_0xcead('0x15')]):_0x1b5d7d;return _0x1ae9d7;})[_0xcead('0x1a')](respondWithFilteredResult(_0x1c90fc,_0x2e41e4))[_0xcead('0x25')](handleError(_0x1c90fc,null));};
\ No newline at end of file