Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / cmContact / cmContact.controller.js
index d428970..a544fbc 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x52d0=['query','user','CmContact','find','params','catch','tags','keys','startsWith','cf_','columnName','analytics','CmCustomField','displayName','alias','type','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','hasOwnProperty','merge','body','from','length','get','mergeWith','isArray','join','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','update','ChatMessage','ChatOfflineMessage','MailMessage','MailInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperFinal','ReportAgentPreview','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','SmsQueueReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','dialTimezone','isNil','timezones','additionalPhones','bulkCreate','duplicates','where','$or','push','ListId','findOrCreate','spread','contact','all','show','Tag','Tags','color','tag','Phones','ContactItemType','Phones.OrderBy','$and','map','format','cf_%d','utcOffset','omit','pickBy','table','cm_contacts','setFields','id\x20=\x20?','toParam','sequelize','text','values','phone','getTags','findOne','model','rawAttributes','filters','intersection','attributes','order','sort','pick','filter','setTags','ids','setAdditionalPhones','items','item_types','ItemTypeId','description','OrderBy','contact\x20phone\x20exists','PHONE','item','ItemType','literal','`ItemType`.OrderBy','ItemType.OrderBy','CmHopperAdditionalPhone','duplicateAdditionalPhones','fromContactId','toContactId','hopperId','fields','nolimit','ContactId','options','includeAll','include','rows','getHopperHistories','CmHopperHistory','getHopperFinals','getJscriptySessions','JscriptySessionReport','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','split','binding_values','Incorrect\x20binding\x20parameters\x20passed!','No\x20phone\x20column\x20specified','No\x20firstName\x20column\x20specified','root','server/files/tmp','filename','0777','child_process','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','send','upload','file','parse','meta','import','User','agent','binding','firstName','fork','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','importUpdates','../../components/import/cm/csvUpdates','getJourney','chat','sms','openchannel','fax','whatsapp','voice','-createdAt','resolve','includes','channel','toLowerCase','Invalid\x20channel','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','uniqueid','source','callerid','starttime','endtime','duration','note','userDisposition','userSecondDisposition','userThirdDisposition','UserId','fullname','DESC','createdAt','VoiceCallReport','startCase','Website','closed','disposition','secondDisposition','key','Owner','customerIp','deviceModel','osName','ratingType','ratingValue','referer','mail','subject','substatus','externalUrl','threadId','Interaction','findAndCountAll','flatten','sortBy','reverse','value','moment','util','path','lodash','squel','ioredis','../../components/contacts','../../components/parsers/qs','api','../../config/environment','../../config/environment/shared','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','register','status','json','offset','limit','undefined','count','set','Content-Range','then','destroy','end','stack','name','describe','getOptions','findAll'];(function(_0x5d25ed,_0x3004e0){var _0x1cd0b7=function(_0x21a0b4){while(--_0x21a0b4){_0x5d25ed['push'](_0x5d25ed['shift']());}};_0x1cd0b7(++_0x3004e0);}(_0x52d0,0x1ec));var _0x052d=function(_0x326017,_0x5205fd){_0x326017=_0x326017-0x0;var _0x5e43b1=_0x52d0[_0x326017];return _0x5e43b1;};'use strict';var moment=require(_0x052d('0x0'));var BPromise=require('bluebird');var util=require(_0x052d('0x1'));var path=require(_0x052d('0x2'));var fs=require('fs');var _=require(_0x052d('0x3'));var squel=require(_0x052d('0x4'));var Papa=require('papaparse');var Redis=require(_0x052d('0x5'));var contacts=require(_0x052d('0x6'));var qs=require(_0x052d('0x7'));var logger=require('../../config/logger')(_0x052d('0x8'));var config=require(_0x052d('0x9'));var shared=require(_0x052d('0xa'));var db=require(_0x052d('0xb'))['db'];config[_0x052d('0xc')]=_[_0x052d('0xd')](config[_0x052d('0xc')],{'host':_0x052d('0xe'),'port':0x18eb});var socket=require(_0x052d('0xf'))(new Redis(config['redis']));require(_0x052d('0x10'))[_0x052d('0x11')](socket);function respondWithResult(_0x23d3dd,_0x1e4f6a){_0x1e4f6a=_0x1e4f6a||0xc8;return function(_0x1122cf){if(_0x1122cf){return _0x23d3dd[_0x052d('0x12')](_0x1e4f6a)[_0x052d('0x13')](_0x1122cf);}};}function respondWithFilteredResult(_0x3d64e5,_0x411f89){return function(_0x51ff7e){if(_0x51ff7e){var _0x5e3778=typeof _0x411f89[_0x052d('0x14')]==='undefined'&&typeof _0x411f89[_0x052d('0x15')]===_0x052d('0x16');var _0x3d4cd8=_0x51ff7e[_0x052d('0x17')];var _0x1b01c9=_0x5e3778?0x0:_0x411f89['offset'];var _0x47546a=_0x5e3778?_0x51ff7e[_0x052d('0x17')]:_0x411f89[_0x052d('0x14')]+_0x411f89['limit'];var _0x377326;if(_0x47546a>=_0x3d4cd8){_0x47546a=_0x3d4cd8;_0x377326=0xc8;}else{_0x377326=0xce;}_0x3d64e5[_0x052d('0x12')](_0x377326);return _0x3d64e5[_0x052d('0x18')](_0x052d('0x19'),_0x1b01c9+'-'+_0x47546a+'/'+_0x3d4cd8)[_0x052d('0x13')](_0x51ff7e);}return null;};}function saveUpdates(_0x125a07){return function(_0x28e7bd){if(_0x28e7bd){return _0x28e7bd['update'](_0x125a07)[_0x052d('0x1a')](function(_0x4631f8){return _0x4631f8;});}return null;};}function removeEntity(_0x2df059){return function(_0x2a73df){if(_0x2a73df){return _0x2a73df[_0x052d('0x1b')]()[_0x052d('0x1a')](function(){_0x2df059[_0x052d('0x12')](0xcc)[_0x052d('0x1c')]();});}};}function handleEntityNotFound(_0x3d1cc6){return function(_0x5c3929){if(!_0x5c3929){_0x3d1cc6['sendStatus'](0x194);}return _0x5c3929;};}function handleError(_0x107847,_0x4f2ee0){_0x4f2ee0=_0x4f2ee0||0x1f4;return function(_0x2b853c){logger['error'](_0x2b853c[_0x052d('0x1d')]);if(_0x2b853c['name']){delete _0x2b853c[_0x052d('0x1e')];}_0x107847[_0x052d('0x12')](_0x4f2ee0)['send'](_0x2b853c);};}exports['index']=function(_0x155f36,_0x1b2f85){var _0x44b4e0={};return contacts[_0x052d('0x1f')]()['then'](function(_0x3406b3){_0x44b4e0=qs[_0x052d('0x20')](_0x3406b3,_0x155f36);return contacts[_0x052d('0x21')](_0x155f36[_0x052d('0x22')],_0x155f36[_0x052d('0x23')],_0x44b4e0,_0x3406b3);})[_0x052d('0x1a')](respondWithFilteredResult(_0x1b2f85,_0x44b4e0))['catch'](handleError(_0x1b2f85,null));};exports[_0x052d('0x1b')]=function(_0x770543,_0x219fd3){return db[_0x052d('0x24')][_0x052d('0x25')]({'where':{'id':_0x770543[_0x052d('0x26')]['id']}})[_0x052d('0x1a')](handleEntityNotFound(_0x219fd3,null))['then'](removeEntity(_0x219fd3,null))[_0x052d('0x27')](handleError(_0x219fd3,null));};exports[_0x052d('0x1f')]=function(_0x2137ea,_0x1bf018){return db[_0x052d('0x24')][_0x052d('0x1f')]()['then'](function(_0x16ee67){delete _0x16ee67[_0x052d('0x28')];for(var _0x3e6fb6=0x0;_0x3e6fb6<Object['keys'](_0x16ee67)['length'];_0x3e6fb6++){var _0x4dd7d3=Object[_0x052d('0x29')](_0x16ee67)[_0x3e6fb6];if(!_[_0x052d('0x2a')](_0x4dd7d3,_0x052d('0x2b'))){_0x16ee67[_0x4dd7d3][_0x052d('0x2c')]=_0x4dd7d3;_0x16ee67[_0x4dd7d3]['displayName']=_0x4dd7d3;}}return _0x16ee67;})[_0x052d('0x1a')](function(_0x4d343a){var _0x449701={'where':Boolean(_0x2137ea[_0x052d('0x22')][_0x052d('0x2d')])===!![]?undefined:{'$or':[{'ListId':_0x2137ea[_0x052d('0x22')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x052d('0x2e')][_0x052d('0x21')](_0x449701)[_0x052d('0x1a')](function(_0x494be3){for(var _0x593378=0x0;_0x593378<_0x494be3['length'];_0x593378++){var _0x542b7f=_0x052d('0x2b')+_0x494be3[_0x593378]['id'];if(_0x4d343a[_0x542b7f]){_0x4d343a[_0x542b7f][_0x052d('0x2c')]=_0x542b7f;_0x4d343a[_0x542b7f][_0x052d('0x2f')]=_0x494be3[_0x593378][_0x052d('0x30')];_0x4d343a[_0x542b7f]['custom']={'type':_0x494be3[_0x593378][_0x052d('0x31')],'values':_0x494be3[_0x593378]['values']};}else{logger['info'](_0x052d('0x32'),_0x542b7f);}}Object[_0x052d('0x29')](_0x4d343a)['forEach'](function(_0x2fc0ec){if(!_0x4d343a[_0x2fc0ec][_0x052d('0x33')](_0x052d('0x2c'))){delete _0x4d343a[_0x2fc0ec];}});return _0x4d343a;});})[_0x052d('0x1a')](respondWithResult(_0x1bf018,null))[_0x052d('0x27')](handleError(_0x1bf018,null));};exports[_0x052d('0x34')]=function(_0x463a66,_0x20d684){var _0x376f3e;var _0x370f14;var _0x2bbae1;if(_0x463a66['body']['id']){delete _0x463a66[_0x052d('0x35')]['id'];}return db[_0x052d('0x24')][_0x052d('0x21')]({'where':{'id':[_0x463a66[_0x052d('0x35')]['to'],_0x463a66[_0x052d('0x35')][_0x052d('0x36')]]}})[_0x052d('0x1a')](function(_0x911227){if(_0x911227){if(_0x911227[_0x052d('0x37')]!==0x2){return null;}_0x911227[0x0]=_0x911227[0x0]['get']({'plain':!![]});_0x911227[0x1]=_0x911227[0x1][_0x052d('0x38')]({'plain':!![]});delete _0x911227[0x0]['id'];delete _0x911227[0x1]['id'];return _[_0x052d('0x39')](_0x911227[0x0],_0x911227[0x1],function(_0x3efe3e,_0x584e2c){if(Array[_0x052d('0x3a')](_0x584e2c)&&!_0x584e2c['length']){return _0x3efe3e;}else if(!_0x584e2c){return _0x3efe3e;}});}})[_0x052d('0x1a')](handleEntityNotFound(_0x20d684,null))[_0x052d('0x1a')](function(_0x321c48){if(_0x321c48){if(_0x321c48['tags']&&_[_0x052d('0x3a')](_0x321c48[_0x052d('0x28')])){_0x321c48[_0x052d('0x28')]=_0x321c48['tags'][_0x052d('0x3b')]();}logger[_0x052d('0x3c')](_0x052d('0x3d'),_0x463a66[_0x052d('0x35')]['to'],_0x463a66[_0x052d('0x35')][_0x052d('0x36')]);return db[_0x052d('0x3e')][_0x052d('0x1b')]({'where':{'ContactId':[_0x463a66['body']['to'],_0x463a66[_0x052d('0x35')][_0x052d('0x36')]]}})['then'](function(_0x4ea7ce){logger[_0x052d('0x3c')](_0x052d('0x3f'),_0x4ea7ce);return db[_0x052d('0x40')][_0x052d('0x1b')]({'where':{'ContactId':[_0x463a66['body']['to'],_0x463a66[_0x052d('0x35')][_0x052d('0x36')]]}})[_0x052d('0x1a')](function(_0x48322a){logger[_0x052d('0x3c')](_0x052d('0x41'),_0x48322a);return db[_0x052d('0x24')]['create'](_0x321c48);});});}})[_0x052d('0x1a')](function(_0x3d846d){if(_0x3d846d){_0x376f3e=_0x3d846d;_0x370f14={'ContactId':_0x376f3e['id']};_0x2bbae1={'where':{'ContactId':[_0x463a66[_0x052d('0x35')]['to'],_0x463a66[_0x052d('0x35')][_0x052d('0x36')]]}};return db['ChatInteraction'][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})['then'](function(){if(_0x376f3e){return db[_0x052d('0x43')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x44')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db['MailInteraction'][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x45')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})['then'](function(){if(_0x376f3e){return db[_0x052d('0x46')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x45')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db['SmsInteraction'][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x47')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})['then'](function(){if(_0x376f3e){return db[_0x052d('0x48')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x49')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x4a')]['update'](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x4b')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x4c')][_0x052d('0x42')]({'CmContactId':_0x376f3e['id']},{'where':{'CmContactId':[_0x463a66[_0x052d('0x35')]['to'],_0x463a66['body'][_0x052d('0x36')]]}});}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x4d')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db['CmHopperHistory'][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x4e')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db['VoiceCallReport'][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x4f')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})['then'](function(){if(_0x376f3e){return db[_0x052d('0x50')]['update'](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x51')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x52')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x53')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db['JscriptySessionReport'][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x54')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})['then'](function(){if(_0x376f3e){return db[_0x052d('0x55')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x56')][_0x052d('0x42')](_0x370f14,_0x2bbae1);}})[_0x052d('0x1a')](function(){if(_0x376f3e){return db[_0x052d('0x24')][_0x052d('0x1b')]({'where':{'id':[_0x463a66['body']['to'],_0x463a66[_0x052d('0x35')][_0x052d('0x36')]]}});}})['then'](function(){if(_0x376f3e){return _0x376f3e;}})['then'](respondWithResult(_0x20d684,null))[_0x052d('0x27')](handleError(_0x20d684,null));};exports['create']=function(_0xa42f71,_0x172036){return db[_0x052d('0x24')][_0x052d('0x1f')]()[_0x052d('0x1a')](function(_0x27f004){if(_0xa42f71[_0x052d('0x35')]['tags']&&_['isArray'](_0xa42f71[_0x052d('0x35')][_0x052d('0x28')])){if(_0xa42f71[_0x052d('0x35')][_0x052d('0x28')][_0x052d('0x37')]){_0xa42f71[_0x052d('0x35')][_0x052d('0x28')]=_0xa42f71[_0x052d('0x35')][_0x052d('0x28')]['join'](';')+';';}else{_0xa42f71[_0x052d('0x35')]['tags']=null;}}else{_0xa42f71[_0x052d('0x35')][_0x052d('0x28')]=null;}if(!_['isNil'](_0xa42f71[_0x052d('0x35')][_0x052d('0x57')])){var _0x51fc29=_0xa42f71[_0x052d('0x35')][_0x052d('0x57')];if(!_[_0x052d('0x58')](shared[_0x052d('0x59')][_0x51fc29]))_0xa42f71['body']['utcOffset']=shared[_0x052d('0x59')][_0x51fc29]['utcOffset'];}return db[_0x052d('0x24')]['create'](_0xa42f71[_0x052d('0x35')],{'fields':_[_0x052d('0x29')](_0x27f004),'raw':!![]});})[_0x052d('0x1a')](function(_0x5ac198){if(_0xa42f71[_0x052d('0x35')][_0x052d('0x5a')]){return insertAdditionalPhones(_0x5ac198,_0xa42f71['body'][_0x052d('0x5a')]);}else{return _0x5ac198;}})[_0x052d('0x1a')](respondWithResult(_0x172036,0xc9))[_0x052d('0x27')](handleError(_0x172036,null));};exports[_0x052d('0x5b')]=function(_0x29cf40,_0x4a3745){var _0x26a5ab=0x0;var _0x145fd1=0x0;var _0x535e70=0x0;var _0x4537fd=[];return db[_0x052d('0x24')][_0x052d('0x1f')]()[_0x052d('0x1a')](function(_0x4aba40){return BPromise['each'](_0x29cf40[_0x052d('0x35')],function(_0x3b3d49){var _0xb6e1a2={'where':{'$or':[]},'defaults':_0x3b3d49,'fields':_[_0x052d('0x29')](_0x4aba40),'raw':!![]};if(_0x3b3d49['duplicates']){for(var _0x5a417c=0x0;_0x5a417c<_0x3b3d49['duplicates'][_0x052d('0x37')];_0x5a417c++){var _0x290e7a={};_0x290e7a[_0x3b3d49[_0x052d('0x5c')][_0x5a417c]]=_0x3b3d49[_0x3b3d49[_0x052d('0x5c')][_0x5a417c]];_0xb6e1a2[_0x052d('0x5d')][_0x052d('0x5e')][_0x052d('0x5f')](_0x290e7a);}_0xb6e1a2['where'][_0x052d('0x60')]=_0x3b3d49[_0x052d('0x60')];}return db[_0x052d('0x24')][_0x052d('0x61')](_0xb6e1a2)[_0x052d('0x62')](function(_0x53a924,_0x2d1daf){if(_0x2d1daf){if(_0x3b3d49['hasOwnProperty'](_0x052d('0x5a'))){_0x4537fd[_0x052d('0x5f')]({'contact':_0x53a924,'additionalPhones':_0x3b3d49[_0x052d('0x5a')]});}_0x26a5ab++;}else{_0x535e70++;}})[_0x052d('0x27')](function(){_0x145fd1++;});});})[_0x052d('0x1a')](function(_0x3bc0a0){if(_0x3bc0a0){if(_0x4537fd['length']>0x0){return new Promise(function(_0x4f6df5){var _0x38f520=[];for(var _0x947785=0x0;_0x947785<_0x4537fd[_0x052d('0x37')];_0x947785++){_0x38f520[_0x052d('0x5f')](insertAdditionalPhones(_0x4537fd[_0x947785][_0x052d('0x63')],_0x4537fd[_0x947785][_0x052d('0x5a')]));}Promise[_0x052d('0x64')](_0x38f520)['then'](function(){_0x4f6df5(0x1);});})[_0x052d('0x1a')](function(){return{'success':_0x26a5ab,'failure':_0x145fd1,'duplicates':_0x535e70};});}else{return{'success':_0x26a5ab,'failure':_0x145fd1,'duplicates':_0x535e70};}}})[_0x052d('0x1a')](respondWithResult(_0x4a3745,0xc9))['catch'](handleError(_0x4a3745,null));};exports[_0x052d('0x65')]=function(_0x181547,_0x1431ab){var _0x41ebce;return db[_0x052d('0x24')]['describe']()[_0x052d('0x1a')](function(_0x278558){return db['CmContact'][_0x052d('0x25')]({'where':{'id':_0x181547[_0x052d('0x26')]['id']},'include':[{'model':db[_0x052d('0x66')],'as':_0x052d('0x67'),'attributes':['id',_0x052d('0x1e'),_0x052d('0x68')],'required':_0x181547[_0x052d('0x22')][_0x052d('0x69')]?!![]:![]},{'model':db[_0x052d('0x4c')],'as':_0x052d('0x6a'),'where':{'CmContactId':_0x181547['params']['id']},'required':![],'include':[{'model':db[_0x052d('0x6b')],'as':'ItemType'}]}],'order':[db['sequelize']['literal'](_0x052d('0x6c'))],'attributes':_['keys'](_0x278558)});})[_0x052d('0x1a')](function(_0x143dcf){if(!_[_0x052d('0x58')](_0x143dcf)){_0x41ebce=_0x143dcf['get']({'plain':!![]});var _0x2ce831={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x143dcf&&_0x143dcf[_0x052d('0x60')]){if(_0x143dcf[_0x052d('0x60')]){_0x2ce831['where'][_0x052d('0x6d')]['push']({'ListId':{'$ne':_0x143dcf[_0x052d('0x60')]}});}}return db[_0x052d('0x2e')][_0x052d('0x21')](_0x2ce831);}})[_0x052d('0x1a')](function(_0x4bbc26){if(!_[_0x052d('0x58')](_0x4bbc26)){return _['omit'](_0x41ebce,_[_0x052d('0x6e')](_0x4bbc26,function(_0x4246b4){return util[_0x052d('0x6f')](_0x052d('0x70'),_0x4246b4['id']);}));}})[_0x052d('0x1a')](handleEntityNotFound(_0x1431ab,null))[_0x052d('0x1a')](respondWithResult(_0x1431ab,null))['catch'](handleError(_0x1431ab,null));};exports[_0x052d('0x42')]=function(_0x59f474,_0xc14636){var _0x5b2459;if(_0x59f474['body']['id']){delete _0x59f474[_0x052d('0x35')]['id'];}if(!_[_0x052d('0x58')](_0x59f474[_0x052d('0x35')][_0x052d('0x57')])){var _0x56406c=_0x59f474[_0x052d('0x35')][_0x052d('0x57')];if(!_[_0x052d('0x58')](shared[_0x052d('0x59')][_0x56406c]))_0x59f474['body']['utcOffset']=shared[_0x052d('0x59')][_0x56406c][_0x052d('0x71')];}return db[_0x052d('0x24')][_0x052d('0x25')]({'where':{'id':_0x59f474['params']['id']}})['then'](handleEntityNotFound(_0xc14636,null))[_0x052d('0x1a')](saveUpdates(_0x59f474[_0x052d('0x35')],null))['then'](function(_0x2af7f9){_0x5b2459=_0x2af7f9;var _0x23889b={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2af7f9&&_0x2af7f9['ListId']){if(_0x2af7f9[_0x052d('0x60')]){_0x23889b[_0x052d('0x5d')][_0x052d('0x6d')][_0x052d('0x5f')]({'ListId':{'$ne':_0x2af7f9[_0x052d('0x60')]}});}}return db[_0x052d('0x2e')][_0x052d('0x21')](_0x23889b);})[_0x052d('0x1a')](function(_0x4c8eca){if(_0x4c8eca){return _[_0x052d('0x72')](_[_0x052d('0x73')](_0x59f474['body'],function(_0x4108c0,_0x56aeb2){return _[_0x052d('0x2a')](_0x56aeb2,_0x052d('0x2b'));}),_[_0x052d('0x6e')](_0x4c8eca,function(_0x3c8ee0){return util['format'](_0x052d('0x70'),_0x3c8ee0['id']);}));}})['then'](function(_0x306046){if(_0x306046&&!_['isEmpty'](_0x306046)){var _0x4b7174=squel['update']()[_0x052d('0x74')](_0x052d('0x75'))[_0x052d('0x76')](_0x306046)[_0x052d('0x5d')](_0x052d('0x77'),_0x59f474['params']['id'])[_0x052d('0x78')]();return db[_0x052d('0x79')][_0x052d('0x22')](_0x4b7174[_0x052d('0x7a')],{'replacements':_0x4b7174[_0x052d('0x7b')]});}})['then'](function(){if(_0x59f474[_0x052d('0x35')][_0x052d('0x7c')]&&_0x5b2459){return db[_0x052d('0x3e')][_0x052d('0x42')]({'phone':_0x59f474[_0x052d('0x35')][_0x052d('0x7c')],'OrderBy':0x0},{'where':{'ContactId':_0x5b2459['id']}});}})[_0x052d('0x1a')](function(){return _0x5b2459;})['then'](respondWithResult(_0xc14636,null))[_0x052d('0x27')](handleError(_0xc14636,null));};exports[_0x052d('0x7d')]=function(_0x3b3d1a,_0x18ccec){var _0x447b70={};var _0x226c81={};var _0x32e933;var _0x1c665c;return db[_0x052d('0x24')][_0x052d('0x7e')]({'where':{'id':_0x3b3d1a[_0x052d('0x26')]['id']}})[_0x052d('0x1a')](handleEntityNotFound(_0x18ccec,null))[_0x052d('0x1a')](function(_0x41bb50){if(_0x41bb50){_0x32e933=_0x41bb50;_0x226c81[_0x052d('0x7f')]=_[_0x052d('0x29')](db['Tag'][_0x052d('0x80')]);_0x226c81[_0x052d('0x22')]=_['keys'](_0x3b3d1a[_0x052d('0x22')]);_0x226c81[_0x052d('0x81')]=_[_0x052d('0x82')](_0x226c81[_0x052d('0x7f')],_0x226c81[_0x052d('0x22')]);_0x447b70[_0x052d('0x83')]=_[_0x052d('0x82')](_0x226c81[_0x052d('0x7f')],qs['fields'](_0x3b3d1a[_0x052d('0x22')]['fields']));_0x447b70[_0x052d('0x83')]=_0x447b70[_0x052d('0x83')][_0x052d('0x37')]?_0x447b70[_0x052d('0x83')]:_0x226c81[_0x052d('0x7f')];_0x447b70[_0x052d('0x84')]=qs[_0x052d('0x85')](_0x3b3d1a[_0x052d('0x22')][_0x052d('0x85')]);_0x447b70[_0x052d('0x5d')]=qs[_0x052d('0x81')](_[_0x052d('0x86')](_0x3b3d1a['query'],_0x226c81[_0x052d('0x81')]));if(_0x3b3d1a[_0x052d('0x22')][_0x052d('0x87')]){_0x447b70[_0x052d('0x5d')]=_[_0x052d('0x34')](_0x447b70['where'],{'$or':_['map'](_0x447b70[_0x052d('0x83')],function(_0x33c034){var _0x548140={};_0x548140[_0x33c034]={'$like':'%'+_0x3b3d1a[_0x052d('0x22')]['filter']+'%'};return _0x548140;})});}_0x447b70=_[_0x052d('0x34')]({},_0x447b70,_0x3b3d1a['options']);return _0x32e933[_0x052d('0x7d')](_0x447b70);}})[_0x052d('0x1a')](function(_0x3774f0){if(_0x3774f0){_0x1c665c=_0x3774f0[_0x052d('0x37')];if(!_0x3b3d1a[_0x052d('0x22')][_0x052d('0x33')]('nolimit')){_0x447b70[_0x052d('0x15')]=qs[_0x052d('0x15')](_0x3b3d1a[_0x052d('0x22')][_0x052d('0x15')]);_0x447b70['offset']=qs['offset'](_0x3b3d1a['query'][_0x052d('0x14')]);}return _0x32e933['getTags'](_0x447b70);}})[_0x052d('0x1a')](function(_0x205392){if(_0x205392){return _0x205392?{'count':_0x1c665c,'rows':_0x205392}:null;}})['then'](respondWithResult(_0x18ccec,null))['catch'](handleError(_0x18ccec,null));};exports[_0x052d('0x88')]=function(_0x4bbb63,_0x2db3af){if(_0x4bbb63['body']['id']){delete _0x4bbb63[_0x052d('0x35')]['id'];}return db['CmContact'][_0x052d('0x7e')]({'where':{'id':_0x4bbb63[_0x052d('0x26')]['id']}})[_0x052d('0x1a')](handleEntityNotFound(_0x2db3af,null))[_0x052d('0x1a')](function(_0xec1d69){if(_0xec1d69){return _0xec1d69[_0x052d('0x88')](_0x4bbb63['body'][_0x052d('0x89')]||[]);}return null;})['then'](respondWithResult(_0x2db3af,null))[_0x052d('0x27')](handleError(_0x2db3af,null));};exports[_0x052d('0x8a')]=function(_0x58b4fe,_0x38b274){var _0x293d94=[];_0x293d94[_0x052d('0x5f')](addAdditionalPhones(_0x58b4fe[_0x052d('0x35')]));Promise['all'](_0x293d94)[_0x052d('0x1a')](function(){_0x293d94=[];_0x293d94[_0x052d('0x5f')](deleteCmHopperPhones(_0x58b4fe[_0x052d('0x35')]['id']));_0x293d94[_0x052d('0x5f')](addCmHopperPhones(_0x58b4fe[_0x052d('0x35')]['id']));Promise[_0x052d('0x64')](_0x293d94)[_0x052d('0x1a')](function(){return[0x1];})[_0x052d('0x1a')](respondWithResult(_0x38b274,null));});};function addAdditionalPhones(_0x26eec6){var _0xc7794d;return new Promise(function(_0x217df9){return db[_0x052d('0x4c')][_0x052d('0x1b')]({'where':{'CmContactId':_0x26eec6['id']}})['then'](function(){db[_0x052d('0x6b')][_0x052d('0x21')]({'raw':!![],'attributes':['id','OrderBy']})[_0x052d('0x1a')](function(_0x1eb78d){var _0x2dcf23=[];for(var _0x5877d8=0x0;_0x5877d8<_0x26eec6[_0x052d('0x8b')][_0x052d('0x37')];_0x5877d8++){var _0x28603f=_0x26eec6[_0x052d('0x8c')]?_[_0x052d('0x58')](_0x26eec6[_0x052d('0x8c')][_0x5877d8])?'':_0x26eec6[_0x052d('0x8c')][_0x5877d8]:_0x26eec6['items'][_0x5877d8][_0x052d('0x8d')]?_0x26eec6['items'][_0x5877d8][_0x052d('0x8d')]:'';var _0x29dd7d=_[_0x052d('0x58')](_0x26eec6[_0x052d('0x8b')][_0x5877d8][_0x052d('0x8e')])?'':_0x26eec6['items'][_0x5877d8][_0x052d('0x8e')];var _0x3ff9e1=_0x28603f+':'+_0x26eec6[_0x052d('0x8b')][_0x5877d8]['phone']+'§'+_0x29dd7d;if(_['isNil'](_0xc7794d))_0xc7794d=_0x3ff9e1;else _0xc7794d+=';'+_0x3ff9e1;var _0x36399f=null;var _0x36c806=null;if(_0x26eec6[_0x052d('0x8c')]){if(!_['isNil'](_0x26eec6[_0x052d('0x8c')][_0x5877d8])){_0x36c806=_[_0x052d('0x25')](_0x1eb78d,function(_0x249892){return _0x249892['id']===_0x26eec6[_0x052d('0x8c')][_0x5877d8];});if(!_[_0x052d('0x58')](_0x36c806)){_0x36399f=_0x36c806[_0x052d('0x8f')];}}}else{if(!_[_0x052d('0x58')](_0x26eec6[_0x052d('0x8b')][_0x5877d8])){_0x36c806=_[_0x052d('0x25')](_0x1eb78d,function(_0xf41878){return _0xf41878['id']===_0x26eec6[_0x052d('0x8b')][_0x5877d8]['ItemTypeId'];});if(!_[_0x052d('0x58')](_0x36c806)){_0x36399f=_0x5877d8;}}}if(_['isNil'](_0x36399f)){_0x36399f=0x64;}_0x2dcf23[_0x052d('0x5f')](addAdditionalPhone(_0x26eec6['id'],_0x26eec6[_0x052d('0x8b')][_0x5877d8]['phone'],_0x26eec6['item_types']?_['isNil'](_0x26eec6[_0x052d('0x8c')][_0x5877d8])?null:_0x26eec6[_0x052d('0x8c')][_0x5877d8]:_0x26eec6[_0x052d('0x8b')][_0x5877d8][_0x052d('0x8d')]?_0x26eec6['items'][_0x5877d8]['ItemTypeId']:null,_0x36399f,_0x29dd7d));}Promise[_0x052d('0x64')](_0x2dcf23)[_0x052d('0x1a')](function(){db[_0x052d('0x24')][_0x052d('0x42')]({'AdditionalPhones':_0xc7794d},{'where':{'id':_0x26eec6['id']}})[_0x052d('0x1a')](function(){_0x217df9(0x1);});});});});});}function addAdditionalPhone(_0x2b4cb5,_0x2781e7,_0x31a883,_0x58ecc9,_0x1c5a89){return db[_0x052d('0x4c')][_0x052d('0x25')]({'where':{'CmContactId':_0x2b4cb5,'item':_0x2781e7}})[_0x052d('0x1a')](function(_0x58f274){if(_0x58f274)logger[_0x052d('0x3c')](_0x052d('0x90'),_0x58f274);else{db['CmContactHasItem']['create']({'CmContactId':_0x2b4cb5,'item':_0x2781e7,'ItemTypeId':_0x31a883,'OrderBy':_0x58ecc9,'ItemClass':_0x052d('0x91'),'description':_0x1c5a89});}});}function deleteCmHopperPhones(_0x3e0b98){return new Promise(function(_0x48c046){return db[_0x052d('0x3e')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x3e0b98}})['then'](function(_0x5ddc30){db['CmHopperAdditionalPhone']['destroy']({'where':{'CmHopperId':{'$in':_['map'](_0x5ddc30,'id')}}});})[_0x052d('0x1a')](function(){_0x48c046(0x1);});});}function addCmHopperPhones(_0x13f444){return new Promise(function(_0x5c2b63){return db['CmHopper'][_0x052d('0x21')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x13f444}})['then'](function(_0x2ffc36){var _0x45ce9e=[];_[_0x052d('0x6e')](_0x2ffc36,function(_0x525e19){_0x45ce9e[_0x052d('0x5f')](createCmHopperPhone(_0x13f444,_0x525e19['id']));});Promise['all'](_0x45ce9e)['then'](function(){_0x5c2b63(0x1);});});});}function createCmHopperPhone(_0x4dd349,_0x45b165){return new Promise(function(_0x5015b2){db[_0x052d('0x4c')][_0x052d('0x21')]({'raw':!![],'attributes':[_0x052d('0x92'),'OrderBy'],'where':{'CmContactId':_0x4dd349,'ItemClass':'PHONE'},'include':[{'model':db[_0x052d('0x6b')],'attributes':[_0x052d('0x8f')],'as':_0x052d('0x93')}],'order':[_0x052d('0x8f'),db['sequelize'][_0x052d('0x94')](_0x052d('0x95'))]})['then'](function(_0x425ad3){var _0xc2016a=0x1;var _0x5155c3=_[_0x052d('0x6e')](_0x425ad3,function(_0x341088){_0x341088['CmHopperId']=_0x45b165;_0x341088[_0x052d('0x7c')]=_0x341088[_0x052d('0x92')];_0x341088[_0x052d('0x8f')]=_0xc2016a;delete _0x341088[_0x052d('0x96')];_0xc2016a=_0xc2016a+0x1;return _0x341088;});return db[_0x052d('0x97')][_0x052d('0x5b')](_0x5155c3,{});})[_0x052d('0x1a')](function(){_0x5015b2(0x1);});});}function insertAdditionalPhones(_0x30ed8e,_0x279152){return new Promise(function(_0x55fb4f){var _0x1b423a=[];for(var _0x2a4399=0x0;_0x2a4399<_0x279152['length'];_0x2a4399++){var _0x2f75ba=_0x279152[_0x2a4399];_0x1b423a[_0x052d('0x5f')](parseContactItemType(_0x2f75ba));}Promise['all'](_0x1b423a)[_0x052d('0x1a')](function(){var _0xe415d4={'id':_0x30ed8e['id'],'items':_0x279152};return addAdditionalPhones(_0xe415d4)[_0x052d('0x1a')](function(){return addCmHopperPhones(_0x30ed8e['id']);});})[_0x052d('0x1a')](function(){_0x55fb4f(_0x30ed8e);});});}function parseContactItemType(_0x4fb2ec){return new Promise(function(_0x182371){if(_0x4fb2ec['hasOwnProperty'](_0x052d('0x8d'))){_0x182371(_0x4fb2ec);}else{return db[_0x052d('0x6b')][_0x052d('0x25')]({'where':{'name':_0x4fb2ec[_0x052d('0x93')]}})['then'](function(_0x1c2ddd){if(_['isNil'](_0x1c2ddd))_0x4fb2ec[_0x052d('0x8d')]=null;else _0x4fb2ec[_0x052d('0x8d')]=_0x1c2ddd['id'];_0x182371(_0x4fb2ec);});}});}exports['getAdditionalPhones']=function(_0x13ff36,_0x330061){return db[_0x052d('0x4c')][_0x052d('0x21')]({'raw':!![],'where':{'CmContactId':_0x13ff36['params']['id'],'ItemClass':_0x052d('0x91')},'include':[{'model':db[_0x052d('0x6b')],'as':'ItemType'}],'order':[[_0x052d('0x8f')],[db[_0x052d('0x79')][_0x052d('0x94')](_0x052d('0x95'))]]})['then'](function(_0x449854){return _0x449854;})[_0x052d('0x1a')](respondWithResult(_0x330061,null))[_0x052d('0x27')](handleError(_0x330061,null));};exports[_0x052d('0x98')]=function(_0x288640,_0x2dd694){return db[_0x052d('0x4c')][_0x052d('0x21')]({'raw':!![],'where':{'CmContactId':_0x288640['body'][_0x052d('0x99')]}})[_0x052d('0x1a')](function(_0xee0083){var _0x181ada=_[_0x052d('0x6e')](_0xee0083,function(_0x4aedb8){_0x4aedb8['CmContactId']=_0x288640[_0x052d('0x35')][_0x052d('0x9a')];return _0x4aedb8;});return db['CmContactHasItem'][_0x052d('0x5b')](_0x181ada,{});})[_0x052d('0x1a')](function(){return addCmHopperPhones(_0x288640[_0x052d('0x35')]['toContactId']);})[_0x052d('0x1a')](function(){return['ok'];})[_0x052d('0x1a')](respondWithResult(_0x2dd694,null))[_0x052d('0x27')](handleError(_0x2dd694,null));};exports['rescheduleAdditionalPhones']=function(_0x544f32,_0x769e98){var _0x33b66d=[];_0x33b66d['push'](createCmHopperPhone(_0x544f32[_0x052d('0x35')]['id'],_0x544f32[_0x052d('0x35')][_0x052d('0x9b')]));Promise[_0x052d('0x64')](_0x33b66d)['then'](function(){return[0x1];})['then'](respondWithResult(_0x769e98,null));};exports['getHoppers']=function(_0x3ae928,_0x3bba51){var _0x100f14={'raw':![],'where':{}};var _0x3921ff={};var _0x2d0f44={'count':0x0,'rows':[]};return db['CmContact'][_0x052d('0x7e')]({'where':{'id':_0x3ae928['params']['id']}})[_0x052d('0x1a')](handleEntityNotFound(_0x3bba51,null))['then'](function(_0x5dca93){if(_0x5dca93){_0x3921ff[_0x052d('0x7f')]=_[_0x052d('0x29')](db[_0x052d('0x3e')][_0x052d('0x80')]);_0x3921ff[_0x052d('0x22')]=_['keys'](_0x3ae928[_0x052d('0x22')]);_0x3921ff[_0x052d('0x81')]=_['intersection'](_0x3921ff[_0x052d('0x7f')],_0x3921ff[_0x052d('0x22')]);_0x100f14['attributes']=_['intersection'](_0x3921ff[_0x052d('0x7f')],qs['fields'](_0x3ae928['query'][_0x052d('0x9c')]));_0x100f14[_0x052d('0x83')]=_0x100f14[_0x052d('0x83')][_0x052d('0x37')]?_0x100f14[_0x052d('0x83')]:_0x3921ff[_0x052d('0x7f')];if(!_0x3ae928['query'][_0x052d('0x33')](_0x052d('0x9d'))){_0x100f14[_0x052d('0x15')]=qs[_0x052d('0x15')](_0x3ae928[_0x052d('0x22')][_0x052d('0x15')]);_0x100f14[_0x052d('0x14')]=qs[_0x052d('0x14')](_0x3ae928[_0x052d('0x22')][_0x052d('0x14')]);}_0x100f14['order']=qs['sort'](_0x3ae928[_0x052d('0x22')][_0x052d('0x85')]);_0x100f14[_0x052d('0x5d')]=qs['filters'](_[_0x052d('0x86')](_0x3ae928['query'],_0x3921ff[_0x052d('0x81')]));_0x100f14['where'][_0x052d('0x9e')]=_0x5dca93['id'];if(_0x3ae928['query'][_0x052d('0x87')]){_0x100f14['where']=_[_0x052d('0x34')](_0x100f14[_0x052d('0x5d')],{'$or':_['map'](_0x100f14['attributes'],function(_0x37a839){var _0x168f89={};_0x168f89[_0x37a839]={'$like':'%'+_0x3ae928[_0x052d('0x22')][_0x052d('0x87')]+'%'};return _0x168f89;})});}_0x100f14=_[_0x052d('0x34')]({},_0x100f14,_0x3ae928[_0x052d('0x9f')]);return db[_0x052d('0x3e')][_0x052d('0x17')]({'where':_0x100f14['where']})[_0x052d('0x1a')](function(_0x25e38b){_0x2d0f44[_0x052d('0x17')]=_0x25e38b;if(_0x3ae928['query'][_0x052d('0xa0')]){_0x100f14[_0x052d('0xa1')]=[{'all':!![]}];}return db[_0x052d('0x3e')][_0x052d('0x21')](_0x100f14);})[_0x052d('0x1a')](function(_0x62062a){_0x2d0f44[_0x052d('0xa2')]=_0x62062a;return _0x2d0f44;});}})[_0x052d('0x1a')](respondWithFilteredResult(_0x3bba51,_0x100f14))['catch'](handleError(_0x3bba51,null));};exports[_0x052d('0xa3')]=function(_0x16ab5f,_0x192c42){var _0x41a43a={'raw':!![],'where':{}};var _0xc59689={};var _0x151590={'count':0x0,'rows':[]};return db[_0x052d('0x24')][_0x052d('0x7e')]({'where':{'id':_0x16ab5f['params']['id']}})[_0x052d('0x1a')](handleEntityNotFound(_0x192c42,null))[_0x052d('0x1a')](function(_0x4121a2){if(_0x4121a2){_0xc59689['model']=_[_0x052d('0x29')](db[_0x052d('0xa4')]['rawAttributes']);_0xc59689[_0x052d('0x22')]=_[_0x052d('0x29')](_0x16ab5f[_0x052d('0x22')]);_0xc59689[_0x052d('0x81')]=_['intersection'](_0xc59689[_0x052d('0x7f')],_0xc59689[_0x052d('0x22')]);_0x41a43a[_0x052d('0x83')]=_[_0x052d('0x82')](_0xc59689[_0x052d('0x7f')],qs['fields'](_0x16ab5f[_0x052d('0x22')][_0x052d('0x9c')]));_0x41a43a['attributes']=_0x41a43a['attributes'][_0x052d('0x37')]?_0x41a43a['attributes']:_0xc59689['model'];if(!_0x16ab5f['query'][_0x052d('0x33')](_0x052d('0x9d'))){_0x41a43a[_0x052d('0x15')]=qs[_0x052d('0x15')](_0x16ab5f['query'][_0x052d('0x15')]);_0x41a43a[_0x052d('0x14')]=qs['offset'](_0x16ab5f[_0x052d('0x22')][_0x052d('0x14')]);}_0x41a43a['order']=qs[_0x052d('0x85')](_0x16ab5f[_0x052d('0x22')]['sort']);_0x41a43a[_0x052d('0x5d')]=qs[_0x052d('0x81')](_[_0x052d('0x86')](_0x16ab5f[_0x052d('0x22')],_0xc59689[_0x052d('0x81')]));_0x41a43a[_0x052d('0x5d')]['ContactId']=_0x4121a2['id'];if(_0x16ab5f['query'][_0x052d('0x87')]){_0x41a43a[_0x052d('0x5d')]=_[_0x052d('0x34')](_0x41a43a[_0x052d('0x5d')],{'$or':_[_0x052d('0x6e')](_0x41a43a['attributes'],function(_0x3d3814){var _0x488cd3={};_0x488cd3[_0x3d3814]={'$like':'%'+_0x16ab5f[_0x052d('0x22')]['filter']+'%'};return _0x488cd3;})});}_0x41a43a=_[_0x052d('0x34')]({},_0x41a43a,_0x16ab5f['options']);return db[_0x052d('0xa4')][_0x052d('0x17')]({'where':_0x41a43a['where']})['then'](function(_0x3a582f){_0x151590[_0x052d('0x17')]=_0x3a582f;if(_0x16ab5f[_0x052d('0x22')]['includeAll']){_0x41a43a[_0x052d('0xa1')]=[{'all':!![]}];}return db[_0x052d('0xa4')]['findAll'](_0x41a43a);})[_0x052d('0x1a')](function(_0x5ba39d){_0x151590['rows']=_0x5ba39d;return _0x151590;});}})[_0x052d('0x1a')](respondWithFilteredResult(_0x192c42,_0x41a43a))[_0x052d('0x27')](handleError(_0x192c42,null));};exports[_0x052d('0xa5')]=function(_0x128f34,_0x3e274e){var _0x41be43={'raw':!![],'where':{}};var _0xa2f18b={};var _0x57fa05={'count':0x0,'rows':[]};return db['CmContact'][_0x052d('0x7e')]({'where':{'id':_0x128f34[_0x052d('0x26')]['id']}})['then'](handleEntityNotFound(_0x3e274e,null))['then'](function(_0x20f0f6){if(_0x20f0f6){_0xa2f18b[_0x052d('0x7f')]=_[_0x052d('0x29')](db[_0x052d('0x4d')]['rawAttributes']);_0xa2f18b[_0x052d('0x22')]=_['keys'](_0x128f34[_0x052d('0x22')]);_0xa2f18b[_0x052d('0x81')]=_[_0x052d('0x82')](_0xa2f18b[_0x052d('0x7f')],_0xa2f18b[_0x052d('0x22')]);_0x41be43[_0x052d('0x83')]=_[_0x052d('0x82')](_0xa2f18b[_0x052d('0x7f')],qs[_0x052d('0x9c')](_0x128f34[_0x052d('0x22')][_0x052d('0x9c')]));_0x41be43['attributes']=_0x41be43[_0x052d('0x83')]['length']?_0x41be43['attributes']:_0xa2f18b['model'];if(!_0x128f34[_0x052d('0x22')][_0x052d('0x33')]('nolimit')){_0x41be43['limit']=qs[_0x052d('0x15')](_0x128f34[_0x052d('0x22')]['limit']);_0x41be43['offset']=qs['offset'](_0x128f34[_0x052d('0x22')][_0x052d('0x14')]);}_0x41be43[_0x052d('0x84')]=qs['sort'](_0x128f34['query']['sort']);_0x41be43[_0x052d('0x5d')]=qs[_0x052d('0x81')](_['pick'](_0x128f34['query'],_0xa2f18b['filters']));_0x41be43[_0x052d('0x5d')][_0x052d('0x9e')]=_0x20f0f6['id'];if(_0x128f34[_0x052d('0x22')][_0x052d('0x87')]){_0x41be43[_0x052d('0x5d')]=_[_0x052d('0x34')](_0x41be43[_0x052d('0x5d')],{'$or':_['map'](_0x41be43[_0x052d('0x83')],function(_0x3faff9){var _0x52cfa0={};_0x52cfa0[_0x3faff9]={'$like':'%'+_0x128f34[_0x052d('0x22')][_0x052d('0x87')]+'%'};return _0x52cfa0;})});}_0x41be43=_[_0x052d('0x34')]({},_0x41be43,_0x128f34[_0x052d('0x9f')]);return db[_0x052d('0x4d')]['count']({'where':_0x41be43[_0x052d('0x5d')]})['then'](function(_0x515aa){_0x57fa05[_0x052d('0x17')]=_0x515aa;if(_0x128f34['query'][_0x052d('0xa0')]){_0x41be43['include']=[{'all':!![]}];}return db[_0x052d('0x4d')][_0x052d('0x21')](_0x41be43);})[_0x052d('0x1a')](function(_0x3ef31b){_0x57fa05[_0x052d('0xa2')]=_0x3ef31b;return _0x57fa05;});}})[_0x052d('0x1a')](respondWithFilteredResult(_0x3e274e,_0x41be43))['catch'](handleError(_0x3e274e,null));};exports[_0x052d('0xa6')]=function(_0x56f6d0,_0xc43697){var _0x5bc16f={'raw':!![],'where':{}};var _0x3158c7={};var _0x117b86={'count':0x0,'rows':[]};return db[_0x052d('0x24')][_0x052d('0x7e')]({'where':{'id':_0x56f6d0[_0x052d('0x26')]['id']}})['then'](handleEntityNotFound(_0xc43697,null))[_0x052d('0x1a')](function(_0x2c2652){if(_0x2c2652){_0x3158c7[_0x052d('0x7f')]=_[_0x052d('0x29')](db['JscriptySessionReport'][_0x052d('0x80')]);_0x3158c7[_0x052d('0x22')]=_['keys'](_0x56f6d0[_0x052d('0x22')]);_0x3158c7[_0x052d('0x81')]=_[_0x052d('0x82')](_0x3158c7['model'],_0x3158c7['query']);_0x5bc16f[_0x052d('0x83')]=_[_0x052d('0x82')](_0x3158c7[_0x052d('0x7f')],qs[_0x052d('0x9c')](_0x56f6d0['query'][_0x052d('0x9c')]));_0x5bc16f[_0x052d('0x83')]=_0x5bc16f[_0x052d('0x83')]['length']?_0x5bc16f[_0x052d('0x83')]:_0x3158c7[_0x052d('0x7f')];if(!_0x56f6d0[_0x052d('0x22')][_0x052d('0x33')]('nolimit')){_0x5bc16f[_0x052d('0x15')]=qs[_0x052d('0x15')](_0x56f6d0[_0x052d('0x22')][_0x052d('0x15')]);_0x5bc16f[_0x052d('0x14')]=qs[_0x052d('0x14')](_0x56f6d0[_0x052d('0x22')][_0x052d('0x14')]);}_0x5bc16f['order']=qs[_0x052d('0x85')](_0x56f6d0[_0x052d('0x22')][_0x052d('0x85')]);_0x5bc16f['where']=qs[_0x052d('0x81')](_['pick'](_0x56f6d0[_0x052d('0x22')],_0x3158c7[_0x052d('0x81')]));_0x5bc16f['where']['ContactId']=_0x2c2652['id'];if(_0x56f6d0[_0x052d('0x22')][_0x052d('0x87')]){_0x5bc16f[_0x052d('0x5d')]=_[_0x052d('0x34')](_0x5bc16f[_0x052d('0x5d')],{'$or':_[_0x052d('0x6e')](_0x5bc16f[_0x052d('0x83')],function(_0xaef1b7){var _0x209fef={};_0x209fef[_0xaef1b7]={'$like':'%'+_0x56f6d0[_0x052d('0x22')][_0x052d('0x87')]+'%'};return _0x209fef;})});}_0x5bc16f=_[_0x052d('0x34')]({},_0x5bc16f,_0x56f6d0['options']);return db[_0x052d('0xa7')][_0x052d('0x17')]({'where':_0x5bc16f[_0x052d('0x5d')]})['then'](function(_0x599232){_0x117b86['count']=_0x599232;if(_0x56f6d0['query'][_0x052d('0xa0')]){_0x5bc16f[_0x052d('0xa1')]=[{'all':!![]}];}return db[_0x052d('0xa7')][_0x052d('0x21')](_0x5bc16f);})[_0x052d('0x1a')](function(_0x539c78){_0x117b86[_0x052d('0xa2')]=_0x539c78;return _0x117b86;});}})[_0x052d('0x1a')](respondWithFilteredResult(_0xc43697,_0x5bc16f))[_0x052d('0x27')](handleError(_0xc43697,null));};exports[_0x052d('0xa8')]=function(_0x22ce66,_0x67e7be){try{if(!_0x22ce66[_0x052d('0x35')]['ListId']){throw new Error(_0x052d('0xa9'));}if(!_0x22ce66[_0x052d('0x35')][_0x052d('0xaa')]){throw new Error(_0x052d('0xab'));}if(!_0x22ce66[_0x052d('0x35')]['binding_values']){throw new Error(_0x052d('0xac'));}if(!_0x22ce66['body'][_0x052d('0xad')]){throw new Error(_0x052d('0xae'));}var _0x54f458=_0x22ce66[_0x052d('0x35')]['binding_keys'][_0x052d('0xaf')](',');var _0x123a74=_0x22ce66[_0x052d('0x35')][_0x052d('0xb0')]['split'](',');if(!_0x54f458[_0x052d('0x37')]||!_0x123a74['length']||_0x54f458[_0x052d('0x37')]!==_0x123a74['length']){throw new Error(_0x052d('0xb1'));}_0x22ce66[_0x052d('0x35')][_0x052d('0x9c')]=_['zipObject'](_0x54f458,_0x123a74);if(!_0x22ce66[_0x052d('0x35')][_0x052d('0x9c')][_0x052d('0x7c')]){throw new Error(_0x052d('0xb2'));}if(!_0x22ce66[_0x052d('0x35')]['fields']['firstName']){throw new Error(_0x052d('0xb3'));}var _0x20b47d=path[_0x052d('0x3b')](config[_0x052d('0xb4')],_0x052d('0xb5'),_0x22ce66['file'][_0x052d('0xb6')]);fs['chmodSync'](_0x20b47d,parseInt(_0x052d('0xb7'),0x8));var _0x56b397=require(_0x052d('0xb8'))['fork'](path[_0x052d('0x3b')](__dirname,_0x052d('0xb9')),[_0x20b47d,_0x22ce66[_0x052d('0x35')][_0x052d('0xaa')],_0x22ce66[_0x052d('0x35')][_0x052d('0xb0')],_0x22ce66[_0x052d('0x35')]['ListId'],_0x22ce66['body'][_0x052d('0xba')],_0x22ce66[_0x052d('0x35')][_0x052d('0x5c')],_0x22ce66['body'][_0x052d('0xad')]]);return _0x67e7be[_0x052d('0x12')](0xc8)[_0x052d('0x13')]({'message':_0x052d('0xbb'),'pid':_0x56b397[_0x052d('0xbc')]});}catch(_0x3f14fd){return _0x67e7be[_0x052d('0x12')](0x1f4)[_0x052d('0xbd')](_0x3f14fd);}};exports[_0x052d('0xbe')]=function(_0x3326c4,_0x3760ca){var _0x1fc211=fs['createReadStream'](_0x3326c4[_0x052d('0xbf')][_0x052d('0x2')]);Papa[_0x052d('0xc0')](_0x1fc211,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x773671){return _0x3760ca[_0x052d('0x12')](0xc8)[_0x052d('0x13')]({'file':_0x3326c4['file'],'fields':_0x773671[_0x052d('0xc1')]['fields']});}});};exports[_0x052d('0xc2')]=function(_0x2692b3,_0x31a154){return db[_0x052d('0xc3')]['findAll']({'raw':!![],'attributes':['id'],'where':{'role':_0x052d('0xc4')}})['then'](function(_0x7ff9b1){var _0x432cd3=![];if(!_0x2692b3[_0x052d('0x35')]['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x2692b3[_0x052d('0x35')][_0x052d('0xc5')][_0x052d('0x7c')]){throw new Error(_0x052d('0xb2'));}if(!_0x2692b3[_0x052d('0x35')][_0x052d('0xc5')][_0x052d('0xc6')]){throw new Error(_0x052d('0xb3'));}if(!_0x2692b3[_0x052d('0x35')]['socket_timestamp']){throw new Error(_0x052d('0xae'));}var _0x22fec4=require(_0x052d('0xb8'))[_0x052d('0xc7')](path['join'](__dirname,_0x052d('0xc8')),[_0x2692b3[_0x052d('0x26')]['id'],JSON[_0x052d('0xc9')](_0x2692b3[_0x052d('0x35')]),JSON[_0x052d('0xc9')](_0x7ff9b1)]);_0x22fec4['on'](_0x052d('0xca'),function(){_0x432cd3=!![];return _0x31a154[_0x052d('0x12')](0xc8)[_0x052d('0x13')]({'message':_0x052d('0xcb'),'pid':_0x22fec4[_0x052d('0xbc')]});});_0x22fec4['on'](_0x052d('0xcc'),function(_0x28dfa0){if(_0x28dfa0&&!_0x432cd3){return _0x31a154[_0x052d('0x12')](0x1f4)[_0x052d('0x13')]({'message':_0x052d('0xcd'),'pid':_0x22fec4[_0x052d('0xbc')]});}});})[_0x052d('0x27')](handleError(_0x31a154,null));};exports[_0x052d('0xce')]=function(_0x4c4429,_0x50de10){return db[_0x052d('0xc3')][_0x052d('0x21')]({'raw':!![],'attributes':['id'],'where':{'role':'agent'}})['then'](function(_0x349380){var _0x1fafc3=![];if(!_0x4c4429[_0x052d('0x35')][_0x052d('0x60')]){throw new Error('No\x20ListId\x20specified');}if(!_0x4c4429[_0x052d('0x35')]['binding'][_0x052d('0x7c')]){throw new Error(_0x052d('0xb2'));}if(!_0x4c4429[_0x052d('0x35')]['binding'][_0x052d('0xc6')]){throw new Error(_0x052d('0xb3'));}if(!_0x4c4429[_0x052d('0x35')][_0x052d('0xad')]){throw new Error(_0x052d('0xae'));}var _0x2d0ff4=require(_0x052d('0xb8'))[_0x052d('0xc7')](path['join'](__dirname,_0x052d('0xcf')),[_0x4c4429[_0x052d('0x26')]['id'],JSON[_0x052d('0xc9')](_0x4c4429[_0x052d('0x35')]),JSON[_0x052d('0xc9')](_0x349380)]);_0x2d0ff4['on'](_0x052d('0xca'),function(){_0x1fafc3=!![];return _0x50de10[_0x052d('0x12')](0xc8)[_0x052d('0x13')]({'message':_0x052d('0xcb'),'pid':_0x2d0ff4[_0x052d('0xbc')]});});_0x2d0ff4['on'](_0x052d('0xcc'),function(_0x29f8a1){if(_0x29f8a1&&!_0x1fafc3){return _0x50de10['status'](0x1f4)[_0x052d('0x13')]({'message':_0x052d('0xcd'),'pid':_0x2d0ff4['pid']});}});})[_0x052d('0x27')](handleError(_0x50de10,null));};exports[_0x052d('0xd0')]=function(_0x13d15c,_0x118de2){var _0x32f605=['mail',_0x052d('0xd1'),_0x052d('0xd2'),_0x052d('0xd3'),_0x052d('0xd4'),_0x052d('0xd5'),_0x052d('0xd6')];var _0x91d110={'offset':0x0,'order':qs[_0x052d('0x85')](_0x052d('0xd7'))},_0x3b3783={'count':0x0,'rows':[]};Promise[_0x052d('0xd8')]()[_0x052d('0x1a')](function(){if(_0x13d15c[_0x052d('0x22')]['channel']){if(!_[_0x052d('0xd9')](_0x32f605,_0x13d15c[_0x052d('0x22')][_0x052d('0xda')][_0x052d('0xdb')]())){throw new Error(_0x052d('0xdc'));}_0x32f605=[_0x13d15c[_0x052d('0x22')][_0x052d('0xda')][_0x052d('0xdb')]()];}if(_0x13d15c[_0x052d('0x22')]['range']){try{var _0xb1a9ef=JSON[_0x052d('0xc0')](_0x13d15c[_0x052d('0x22')]['range']);if(!moment(_0xb1a9ef[_0x052d('0x36')])[_0x052d('0xdd')]()){throw new Error(_0x052d('0xde'));}if(!moment(_0xb1a9ef['to'])[_0x052d('0xdd')]()){throw new Error(_0x052d('0xdf'));}}catch(_0x7089c4){throw new Error('Invalid\x20createdAt\x20filter');}}if(!_0x13d15c[_0x052d('0x22')][_0x052d('0x33')](_0x052d('0x9d'))){_0x91d110[_0x052d('0x15')]=qs[_0x052d('0x15')](_0x13d15c[_0x052d('0x22')]['limit']||0xa);_0x91d110[_0x052d('0x14')]=qs['offset'](_0x13d15c[_0x052d('0x22')][_0x052d('0x14')]);}var _0x1e3925=_0x32f605[_0x052d('0x6e')](function(_0x3fac69){if(_0x3fac69==='voice'){var _0x51ce4d={'attributes':['id',_0x052d('0xe0'),_0x052d('0x31'),_0x052d('0xe1'),'destination',_0x052d('0xe2'),_0x052d('0xe3'),_0x052d('0xe4'),_0x052d('0xe5'),_0x052d('0xe6'),'createdAt',_0x052d('0xe7'),_0x052d('0xe8'),_0x052d('0xe9'),_0x052d('0xea')],'where':{'ContactId':_0x13d15c[_0x052d('0x26')]['id']},'include':[{'model':db[_0x052d('0xc3')],'as':'User','attributes':['id','name',_0x052d('0xeb'),'alias']}],'order':[['createdAt',_0x052d('0xec')]]};if(_0x13d15c[_0x052d('0x22')]['range']){_0x51ce4d[_0x052d('0x5d')][_0x052d('0xed')]={'$gte':_0xb1a9ef[_0x052d('0x36')],'$lte':_0xb1a9ef['to']};}return db[_0x052d('0xee')]['findAndCountAll'](_0x51ce4d)['then'](function(_0x3e6316){_0x3b3783[_0x052d('0x17')]+=_0x3e6316[_0x052d('0x17')];return _[_0x052d('0x6e')](_0x3e6316[_0x052d('0xa2')],function(_0x283572){var _0x69397b=_0x283572[_0x052d('0x38')]({'plain':!![]});_0x69397b[_0x052d('0xda')]=_0x3fac69;if(_0x69397b['User']){_0x69397b[_0x052d('0xc3')]={'id':_0x69397b[_0x052d('0xc3')]['id'],'name':_0x69397b[_0x052d('0xc3')][_0x052d('0x1e')],'fullname':_0x69397b['User'][_0x052d('0xeb')],'alias':_0x69397b[_0x052d('0xc3')][_0x052d('0x30')]};}return _0x69397b;});});}else{var _0x2b91e4=_[_0x052d('0xef')](_0x3fac69)+(_0x3fac69===_0x052d('0xd1')?_0x052d('0xf0'):'Account');var _0x44f94f={'attributes':['id',_0x052d('0xf1'),'closedAt',_0x052d('0xed'),'note',_0x052d('0xf2'),_0x052d('0xf3'),'thirdDisposition',_0x052d('0xea'),_0x2b91e4+'Id'],'where':{'ContactId':_0x13d15c[_0x052d('0x26')]['id']},'include':[{'model':db[_0x2b91e4],'as':'Account','attributes':['id',_0x052d('0x1e'),_0x052d('0xf4')]},{'model':db['User'],'as':_0x052d('0xf5'),'attributes':['id',_0x052d('0x1e'),_0x052d('0xeb')]},{'model':db[_0x052d('0x66')],'as':'Tags','attributes':['id',_0x052d('0x1e'),_0x052d('0x68')],'through':{'attributes':[]}}],'order':[[_0x052d('0xed'),_0x052d('0xec')]]};if(_0x13d15c[_0x052d('0x22')]['range']){_0x44f94f[_0x052d('0x5d')][_0x052d('0xed')]={'$gte':_0xb1a9ef['from'],'$lte':_0xb1a9ef['to']};}switch(_0x3fac69){case'chat':_0x44f94f[_0x052d('0x83')]['push']('browserName',_0x052d('0xf6'),'customerPort',_0x052d('0xf7'),_0x052d('0xf8'),'ratingMessage',_0x052d('0xf9'),_0x052d('0xfa'),_0x052d('0xfb'));break;case _0x052d('0xfc'):_0x44f94f[_0x052d('0x83')][_0x052d('0x5f')](_0x052d('0xfd'),_0x052d('0xfe'));break;case _0x052d('0xd3'):_0x44f94f[_0x052d('0x83')]['push'](_0x052d('0xff'),_0x052d('0x100'));break;}return db[_['startCase'](_0x3fac69)+_0x052d('0x101')][_0x052d('0x102')](_0x44f94f)[_0x052d('0x1a')](function(_0x190df7){_0x3b3783[_0x052d('0x17')]+=_0x190df7['count'];return _['map'](_0x190df7['rows'],function(_0x393a6d){var _0x48e971=_0x393a6d[_0x052d('0x38')]({'plain':!![]});_0x48e971[_0x052d('0xda')]=_0x3fac69;if(_0x48e971[_0x052d('0xf5')]){_0x48e971[_0x052d('0xf5')]={'id':_0x48e971[_0x052d('0xf5')]['id'],'name':_0x48e971[_0x052d('0xf5')][_0x052d('0x1e')],'fullname':_0x48e971['Owner'][_0x052d('0xeb')]};}return _0x48e971;});});}});return Promise[_0x052d('0x64')](_0x1e3925);})[_0x052d('0x1a')](function(_0x315824){return _(_0x315824)[_0x052d('0x103')]()[_0x052d('0x104')]('createdAt')[_0x052d('0x105')]()[_0x052d('0x106')]();})[_0x052d('0x1a')](function(_0x8eef28){_0x3b3783[_0x052d('0xa2')]=_0x91d110[_0x052d('0x15')]?_0x8eef28['slice'](_0x91d110[_0x052d('0x14')],_0x91d110[_0x052d('0x14')]+_0x91d110['limit']):_0x8eef28;return _0x3b3783;})[_0x052d('0x1a')](respondWithFilteredResult(_0x118de2,_0x91d110))[_0x052d('0x27')](handleError(_0x118de2,null));};
\ No newline at end of file
+var _0xf131=['fullname','alias','startCase','Account','closed','closedAt','disposition','secondDisposition','thirdDisposition','Tags','DESC','browserName','customerIp','customerPort','deviceModel','osName','ratingMessage','ratingType','ratingValue','referer','subject','externalUrl','threadId','findAndCountAll','Owner','flatten','sortBy','reverse','value','slice','moment','bluebird','path','lodash','squel','papaparse','../../components/contacts','../../components/parsers/qs','../../config/environment','../../mysqldb','defaults','localhost','socket.io-emitter','redis','register','status','json','offset','undefined','count','limit','set','Content-Range','update','then','destroy','end','sendStatus','error','stack','name','send','index','describe','getOptions','findAll','user','catch','CmContact','params','tags','keys','length','startsWith','cf_','columnName','displayName','query','analytics','custom','type','values','forEach','hasOwnProperty','merge','body','from','get','mergeWith','isArray','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperHistory','ReportAgentPreview','VoiceCallReport','MailQueueReport','SmsQueueReport','WhatsappInteraction','WhatsappQueueReport','create','join','isNil','dialTimezone','timezones','utcOffset','additionalPhones','bulkCreate','each','duplicates','where','$or','push','ListId','findOrCreate','contact','show','find','Tag','color','tag','Phones','sequelize','Phones.OrderBy','map','format','cf_%d','$and','CmCustomField','omit','pickBy','isEmpty','cm_contacts','id\x20=\x20?','text','phone','getTags','model','filters','attributes','intersection','fields','order','sort','pick','filter','nolimit','findOne','setTags','ids','setAdditionalPhones','all','ContactItemType','items','item_types','ItemTypeId','description','contact\x20phone\x20exists','PHONE','CmHopperAdditionalPhone','CmHopper','item','OrderBy','literal','`ItemType`.OrderBy','CmHopperId','ItemType.OrderBy','ItemType','duplicateAdditionalPhones','fromContactId','toContactId','rescheduleAdditionalPhones','getHoppers','rawAttributes','ContactId','options','includeAll','include','rows','getHopperHistories','getHopperFinals','CmHopperFinal','getJscriptySessions','JscriptySessionReport','uploadCsv','No\x20ListId\x20specified','binding_keys','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','split','Incorrect\x20binding\x20parameters\x20passed!','zipObject','firstName','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','filename','chmodSync','0777','fork','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','upload','createReadStream','parse','meta','import','User','agent','No\x20phone\x20column\x20specified','binding','../../components/import/cm/csv2','stringify','message','pid','exit','error\x20child\x20process','importUpdates','child_process','../../components/import/cm/csvUpdates','start\x20child\x20process\x20correctly!','mail','chat','openchannel','whatsapp','voice','-createdAt','resolve','channel','includes','toLowerCase','range','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','Invalid\x20createdAt\x20filter','uniqueid','destination','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','UserId'];(function(_0x47ab99,_0x1b1eb3){var _0x3fa1a5=function(_0x85f150){while(--_0x85f150){_0x47ab99['push'](_0x47ab99['shift']());}};_0x3fa1a5(++_0x1b1eb3);}(_0xf131,0x127));var _0x1f13=function(_0xe19508,_0xafd97e){_0xe19508=_0xe19508-0x0;var _0x6305ff=_0xf131[_0xe19508];return _0x6305ff;};'use strict';var moment=require(_0x1f13('0x0'));var BPromise=require(_0x1f13('0x1'));var util=require('util');var path=require(_0x1f13('0x2'));var fs=require('fs');var _=require(_0x1f13('0x3'));var squel=require(_0x1f13('0x4'));var Papa=require(_0x1f13('0x5'));var Redis=require('ioredis');var contacts=require(_0x1f13('0x6'));var qs=require(_0x1f13('0x7'));var logger=require('../../config/logger')('api');var config=require(_0x1f13('0x8'));var shared=require('../../config/environment/shared');var db=require(_0x1f13('0x9'))['db'];config['redis']=_[_0x1f13('0xa')](config['redis'],{'host':_0x1f13('0xb'),'port':0x18eb});var socket=require(_0x1f13('0xc'))(new Redis(config[_0x1f13('0xd')]));require('./cmContact.socket')[_0x1f13('0xe')](socket);function respondWithResult(_0x38adaa,_0x3d971b){_0x3d971b=_0x3d971b||0xc8;return function(_0xa728ec){if(_0xa728ec){return _0x38adaa[_0x1f13('0xf')](_0x3d971b)[_0x1f13('0x10')](_0xa728ec);}};}function respondWithFilteredResult(_0xd15a7,_0x147633){return function(_0x3b514a){if(_0x3b514a){var _0x19f71a=typeof _0x147633[_0x1f13('0x11')]===_0x1f13('0x12')&&typeof _0x147633['limit']==='undefined';var _0x187fe9=_0x3b514a[_0x1f13('0x13')];var _0x32f7e5=_0x19f71a?0x0:_0x147633[_0x1f13('0x11')];var _0x3e17b0=_0x19f71a?_0x3b514a[_0x1f13('0x13')]:_0x147633[_0x1f13('0x11')]+_0x147633[_0x1f13('0x14')];var _0x2b39ae;if(_0x3e17b0>=_0x187fe9){_0x3e17b0=_0x187fe9;_0x2b39ae=0xc8;}else{_0x2b39ae=0xce;}_0xd15a7['status'](_0x2b39ae);return _0xd15a7[_0x1f13('0x15')](_0x1f13('0x16'),_0x32f7e5+'-'+_0x3e17b0+'/'+_0x187fe9)[_0x1f13('0x10')](_0x3b514a);}return null;};}function saveUpdates(_0x933dba){return function(_0x1cc201){if(_0x1cc201){return _0x1cc201[_0x1f13('0x17')](_0x933dba)[_0x1f13('0x18')](function(_0xf2926){return _0xf2926;});}return null;};}function removeEntity(_0x6ace24){return function(_0x8e35b5){if(_0x8e35b5){return _0x8e35b5[_0x1f13('0x19')]()[_0x1f13('0x18')](function(){_0x6ace24[_0x1f13('0xf')](0xcc)[_0x1f13('0x1a')]();});}};}function handleEntityNotFound(_0x59c7db){return function(_0x5154ba){if(!_0x5154ba){_0x59c7db[_0x1f13('0x1b')](0x194);}return _0x5154ba;};}function handleError(_0x3d427d,_0x413c55){_0x413c55=_0x413c55||0x1f4;return function(_0x45b4be){logger[_0x1f13('0x1c')](_0x45b4be[_0x1f13('0x1d')]);if(_0x45b4be[_0x1f13('0x1e')]){delete _0x45b4be[_0x1f13('0x1e')];}_0x3d427d[_0x1f13('0xf')](_0x413c55)[_0x1f13('0x1f')](_0x45b4be);};}exports[_0x1f13('0x20')]=function(_0x54c98e,_0x2742c3){var _0x286816={};return contacts[_0x1f13('0x21')]()[_0x1f13('0x18')](function(_0x7c2c47){_0x286816=qs[_0x1f13('0x22')](_0x7c2c47,_0x54c98e);return contacts[_0x1f13('0x23')](_0x54c98e['query'],_0x54c98e[_0x1f13('0x24')],_0x286816,_0x7c2c47);})[_0x1f13('0x18')](respondWithFilteredResult(_0x2742c3,_0x286816))[_0x1f13('0x25')](handleError(_0x2742c3,null));};exports[_0x1f13('0x19')]=function(_0x2ec940,_0x56487b){return db[_0x1f13('0x26')]['find']({'where':{'id':_0x2ec940[_0x1f13('0x27')]['id']}})[_0x1f13('0x18')](handleEntityNotFound(_0x56487b,null))[_0x1f13('0x18')](removeEntity(_0x56487b,null))[_0x1f13('0x25')](handleError(_0x56487b,null));};exports[_0x1f13('0x21')]=function(_0x44896d,_0x112497){return db[_0x1f13('0x26')][_0x1f13('0x21')]()[_0x1f13('0x18')](function(_0x5e90b7){delete _0x5e90b7[_0x1f13('0x28')];for(var _0x22808d=0x0;_0x22808d<Object[_0x1f13('0x29')](_0x5e90b7)[_0x1f13('0x2a')];_0x22808d++){var _0x33f421=Object['keys'](_0x5e90b7)[_0x22808d];if(!_[_0x1f13('0x2b')](_0x33f421,_0x1f13('0x2c'))){_0x5e90b7[_0x33f421][_0x1f13('0x2d')]=_0x33f421;_0x5e90b7[_0x33f421][_0x1f13('0x2e')]=_0x33f421;}}return _0x5e90b7;})[_0x1f13('0x18')](function(_0x5da075){var _0x2a0997={'where':Boolean(_0x44896d[_0x1f13('0x2f')][_0x1f13('0x30')])===!![]?undefined:{'$or':[{'ListId':_0x44896d['query']['id']},{'ListId':null}]},'raw':!![]};return db['CmCustomField'][_0x1f13('0x23')](_0x2a0997)[_0x1f13('0x18')](function(_0xbe0070){for(var _0x379464=0x0;_0x379464<_0xbe0070[_0x1f13('0x2a')];_0x379464++){var _0x3ce9bc='cf_'+_0xbe0070[_0x379464]['id'];if(_0x5da075[_0x3ce9bc]){_0x5da075[_0x3ce9bc][_0x1f13('0x2d')]=_0x3ce9bc;_0x5da075[_0x3ce9bc]['displayName']=_0xbe0070[_0x379464]['alias'];_0x5da075[_0x3ce9bc][_0x1f13('0x31')]={'type':_0xbe0070[_0x379464][_0x1f13('0x32')],'values':_0xbe0070[_0x379464][_0x1f13('0x33')]};}else{logger['info']('Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table',_0x3ce9bc);}}Object['keys'](_0x5da075)[_0x1f13('0x34')](function(_0x594a33){if(!_0x5da075[_0x594a33][_0x1f13('0x35')](_0x1f13('0x2d'))){delete _0x5da075[_0x594a33];}});return _0x5da075;});})[_0x1f13('0x18')](respondWithResult(_0x112497,null))[_0x1f13('0x25')](handleError(_0x112497,null));};exports[_0x1f13('0x36')]=function(_0x2a8630,_0xb6f68a){var _0x485520;var _0x1507ba;var _0x6b2bcf;if(_0x2a8630[_0x1f13('0x37')]['id']){delete _0x2a8630['body']['id'];}return db['CmContact'][_0x1f13('0x23')]({'where':{'id':[_0x2a8630[_0x1f13('0x37')]['to'],_0x2a8630['body'][_0x1f13('0x38')]]}})[_0x1f13('0x18')](function(_0x1daa2e){if(_0x1daa2e){if(_0x1daa2e[_0x1f13('0x2a')]!==0x2){return null;}_0x1daa2e[0x0]=_0x1daa2e[0x0][_0x1f13('0x39')]({'plain':!![]});_0x1daa2e[0x1]=_0x1daa2e[0x1][_0x1f13('0x39')]({'plain':!![]});delete _0x1daa2e[0x0]['id'];delete _0x1daa2e[0x1]['id'];return _[_0x1f13('0x3a')](_0x1daa2e[0x0],_0x1daa2e[0x1],function(_0xa6510d,_0x470e72){if(Array[_0x1f13('0x3b')](_0x470e72)&&!_0x470e72[_0x1f13('0x2a')]){return _0xa6510d;}else if(!_0x470e72){return _0xa6510d;}});}})[_0x1f13('0x18')](handleEntityNotFound(_0xb6f68a,null))['then'](function(_0x2375ab){if(_0x2375ab){if(_0x2375ab[_0x1f13('0x28')]&&_['isArray'](_0x2375ab[_0x1f13('0x28')])){_0x2375ab[_0x1f13('0x28')]=_0x2375ab['tags']['join']();}logger[_0x1f13('0x3c')](_0x1f13('0x3d'),_0x2a8630['body']['to'],_0x2a8630[_0x1f13('0x37')][_0x1f13('0x38')]);return db['CmHopper'][_0x1f13('0x19')]({'where':{'ContactId':[_0x2a8630[_0x1f13('0x37')]['to'],_0x2a8630[_0x1f13('0x37')][_0x1f13('0x38')]]}})[_0x1f13('0x18')](function(_0x4d2408){logger['info'](_0x1f13('0x3e'),_0x4d2408);return db[_0x1f13('0x3f')][_0x1f13('0x19')]({'where':{'ContactId':[_0x2a8630[_0x1f13('0x37')]['to'],_0x2a8630['body'][_0x1f13('0x38')]]}})[_0x1f13('0x18')](function(_0x6c74b2){logger[_0x1f13('0x3c')](_0x1f13('0x40'),_0x6c74b2);return db[_0x1f13('0x26')]['create'](_0x2375ab);});});}})['then'](function(_0x14bfa4){if(_0x14bfa4){_0x485520=_0x14bfa4;_0x1507ba={'ContactId':_0x485520['id']};_0x6b2bcf={'where':{'ContactId':[_0x2a8630[_0x1f13('0x37')]['to'],_0x2a8630[_0x1f13('0x37')][_0x1f13('0x38')]]}};return db[_0x1f13('0x41')]['update'](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x42')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x43')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x44')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x45')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x44')]['update'](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x45')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x46')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x47')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x48')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x49')]['update'](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x4a')]['update'](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x4b')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x4c')][_0x1f13('0x17')]({'CmContactId':_0x485520['id']},{'where':{'CmContactId':[_0x2a8630['body']['to'],_0x2a8630[_0x1f13('0x37')]['from']]}});}})[_0x1f13('0x18')](function(){if(_0x485520){return db['CmHopperFinal']['update'](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x4d')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x4e')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x4f')]['update'](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db['ChatQueueReport'][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db['FaxQueueReport'][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x50')]['update'](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db['OpenchannelQueueReport'][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x51')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db['JscriptySessionReport'][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x52')]['update'](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db['WhatsappMessage'][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})[_0x1f13('0x18')](function(){if(_0x485520){return db[_0x1f13('0x53')][_0x1f13('0x17')](_0x1507ba,_0x6b2bcf);}})['then'](function(){if(_0x485520){return db[_0x1f13('0x26')]['destroy']({'where':{'id':[_0x2a8630[_0x1f13('0x37')]['to'],_0x2a8630[_0x1f13('0x37')][_0x1f13('0x38')]]}});}})[_0x1f13('0x18')](function(){if(_0x485520){return _0x485520;}})['then'](respondWithResult(_0xb6f68a,null))['catch'](handleError(_0xb6f68a,null));};exports[_0x1f13('0x54')]=function(_0x457b5b,_0x35f330){return db[_0x1f13('0x26')][_0x1f13('0x21')]()[_0x1f13('0x18')](function(_0x26ce2c){if(_0x457b5b[_0x1f13('0x37')][_0x1f13('0x28')]&&_[_0x1f13('0x3b')](_0x457b5b[_0x1f13('0x37')][_0x1f13('0x28')])){if(_0x457b5b[_0x1f13('0x37')]['tags'][_0x1f13('0x2a')]){_0x457b5b[_0x1f13('0x37')][_0x1f13('0x28')]=_0x457b5b['body']['tags'][_0x1f13('0x55')](';')+';';}else{_0x457b5b[_0x1f13('0x37')][_0x1f13('0x28')]=null;}}else{_0x457b5b['body']['tags']=null;}if(!_[_0x1f13('0x56')](_0x457b5b[_0x1f13('0x37')][_0x1f13('0x57')])){var _0x54a446=_0x457b5b[_0x1f13('0x37')][_0x1f13('0x57')];if(!_[_0x1f13('0x56')](shared[_0x1f13('0x58')][_0x54a446]))_0x457b5b[_0x1f13('0x37')][_0x1f13('0x59')]=shared[_0x1f13('0x58')][_0x54a446][_0x1f13('0x59')];}return db[_0x1f13('0x26')][_0x1f13('0x54')](_0x457b5b[_0x1f13('0x37')],{'fields':_[_0x1f13('0x29')](_0x26ce2c),'raw':!![]});})[_0x1f13('0x18')](function(_0x5be284){if(_0x457b5b['body'][_0x1f13('0x5a')]){return insertAdditionalPhones(_0x5be284,_0x457b5b[_0x1f13('0x37')][_0x1f13('0x5a')]);}else{return _0x5be284;}})[_0x1f13('0x18')](respondWithResult(_0x35f330,0xc9))[_0x1f13('0x25')](handleError(_0x35f330,null));};exports[_0x1f13('0x5b')]=function(_0x5927cb,_0x4fd23b){var _0x312be7=0x0;var _0x2a94b9=0x0;var _0x118860=0x0;var _0x16ecc2=[];return db[_0x1f13('0x26')][_0x1f13('0x21')]()[_0x1f13('0x18')](function(_0x21adca){return BPromise[_0x1f13('0x5c')](_0x5927cb[_0x1f13('0x37')],function(_0x1d312d){var _0x242874={'where':{'$or':[]},'defaults':_0x1d312d,'fields':_[_0x1f13('0x29')](_0x21adca),'raw':!![]};if(_0x1d312d[_0x1f13('0x5d')]){for(var _0xe85d3=0x0;_0xe85d3<_0x1d312d[_0x1f13('0x5d')][_0x1f13('0x2a')];_0xe85d3++){var _0x43d055={};_0x43d055[_0x1d312d[_0x1f13('0x5d')][_0xe85d3]]=_0x1d312d[_0x1d312d['duplicates'][_0xe85d3]];_0x242874[_0x1f13('0x5e')][_0x1f13('0x5f')][_0x1f13('0x60')](_0x43d055);}_0x242874['where']['ListId']=_0x1d312d[_0x1f13('0x61')];}return db[_0x1f13('0x26')][_0x1f13('0x62')](_0x242874)['spread'](function(_0x1f1316,_0x187f26){if(_0x187f26){if(_0x1d312d['hasOwnProperty'](_0x1f13('0x5a'))){_0x16ecc2['push']({'contact':_0x1f1316,'additionalPhones':_0x1d312d[_0x1f13('0x5a')]});}_0x312be7++;}else{_0x118860++;}})[_0x1f13('0x25')](function(){_0x2a94b9++;});});})[_0x1f13('0x18')](function(_0x1c3c4e){if(_0x1c3c4e){if(_0x16ecc2[_0x1f13('0x2a')]>0x0){return new Promise(function(_0x4e1d42){var _0x1f023d=[];for(var _0x56df55=0x0;_0x56df55<_0x16ecc2[_0x1f13('0x2a')];_0x56df55++){_0x1f023d[_0x1f13('0x60')](insertAdditionalPhones(_0x16ecc2[_0x56df55][_0x1f13('0x63')],_0x16ecc2[_0x56df55][_0x1f13('0x5a')]));}Promise['all'](_0x1f023d)[_0x1f13('0x18')](function(){_0x4e1d42(0x1);});})[_0x1f13('0x18')](function(){return{'success':_0x312be7,'failure':_0x2a94b9,'duplicates':_0x118860};});}else{return{'success':_0x312be7,'failure':_0x2a94b9,'duplicates':_0x118860};}}})[_0x1f13('0x18')](respondWithResult(_0x4fd23b,0xc9))[_0x1f13('0x25')](handleError(_0x4fd23b,null));};exports[_0x1f13('0x64')]=function(_0x441620,_0x2b14d1){var _0x3c6c68;return db['CmContact'][_0x1f13('0x21')]()[_0x1f13('0x18')](function(_0x1a2eb6){return db[_0x1f13('0x26')][_0x1f13('0x65')]({'where':{'id':_0x441620[_0x1f13('0x27')]['id']},'include':[{'model':db[_0x1f13('0x66')],'as':'Tags','attributes':['id',_0x1f13('0x1e'),_0x1f13('0x67')],'required':_0x441620[_0x1f13('0x2f')][_0x1f13('0x68')]?!![]:![]},{'model':db['CmContactHasItem'],'as':_0x1f13('0x69'),'where':{'CmContactId':_0x441620['params']['id']},'required':![],'include':[{'model':db['ContactItemType'],'as':'ItemType'}]}],'order':[db[_0x1f13('0x6a')]['literal'](_0x1f13('0x6b'))],'attributes':_[_0x1f13('0x29')](_0x1a2eb6)});})[_0x1f13('0x18')](function(_0x4efb61){if(!_[_0x1f13('0x56')](_0x4efb61)){_0x3c6c68=_0x4efb61[_0x1f13('0x39')]({'plain':!![]});var _0x4bf89b={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x4efb61&&_0x4efb61[_0x1f13('0x61')]){if(_0x4efb61[_0x1f13('0x61')]){_0x4bf89b['where']['$and']['push']({'ListId':{'$ne':_0x4efb61[_0x1f13('0x61')]}});}}return db['CmCustomField']['findAll'](_0x4bf89b);}})[_0x1f13('0x18')](function(_0x49203e){if(!_['isNil'](_0x49203e)){return _['omit'](_0x3c6c68,_[_0x1f13('0x6c')](_0x49203e,function(_0x2730b9){return util[_0x1f13('0x6d')](_0x1f13('0x6e'),_0x2730b9['id']);}));}})[_0x1f13('0x18')](handleEntityNotFound(_0x2b14d1,null))[_0x1f13('0x18')](respondWithResult(_0x2b14d1,null))[_0x1f13('0x25')](handleError(_0x2b14d1,null));};exports['update']=function(_0x4b87c0,_0x1e4de1){var _0x113884;if(_0x4b87c0[_0x1f13('0x37')]['id']){delete _0x4b87c0['body']['id'];}if(!_[_0x1f13('0x56')](_0x4b87c0[_0x1f13('0x37')][_0x1f13('0x57')])){var _0x74e5c0=_0x4b87c0['body']['dialTimezone'];if(!_['isNil'](shared[_0x1f13('0x58')][_0x74e5c0]))_0x4b87c0[_0x1f13('0x37')][_0x1f13('0x59')]=shared[_0x1f13('0x58')][_0x74e5c0][_0x1f13('0x59')];}return db[_0x1f13('0x26')]['find']({'where':{'id':_0x4b87c0[_0x1f13('0x27')]['id']}})[_0x1f13('0x18')](handleEntityNotFound(_0x1e4de1,null))['then'](saveUpdates(_0x4b87c0['body'],null))[_0x1f13('0x18')](function(_0x1bc8a7){_0x113884=_0x1bc8a7;var _0x292abe={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x1bc8a7&&_0x1bc8a7['ListId']){if(_0x1bc8a7[_0x1f13('0x61')]){_0x292abe[_0x1f13('0x5e')][_0x1f13('0x6f')]['push']({'ListId':{'$ne':_0x1bc8a7[_0x1f13('0x61')]}});}}return db[_0x1f13('0x70')][_0x1f13('0x23')](_0x292abe);})['then'](function(_0x5a74b4){if(_0x5a74b4){return _[_0x1f13('0x71')](_[_0x1f13('0x72')](_0x4b87c0[_0x1f13('0x37')],function(_0x5dbd62,_0x5b898c){return _[_0x1f13('0x2b')](_0x5b898c,_0x1f13('0x2c'));}),_['map'](_0x5a74b4,function(_0x56d940){return util[_0x1f13('0x6d')](_0x1f13('0x6e'),_0x56d940['id']);}));}})[_0x1f13('0x18')](function(_0x2a1c35){if(_0x2a1c35&&!_[_0x1f13('0x73')](_0x2a1c35)){var _0x213139=squel[_0x1f13('0x17')]()['table'](_0x1f13('0x74'))['setFields'](_0x2a1c35)[_0x1f13('0x5e')](_0x1f13('0x75'),_0x4b87c0['params']['id'])['toParam']();return db[_0x1f13('0x6a')][_0x1f13('0x2f')](_0x213139[_0x1f13('0x76')],{'replacements':_0x213139['values']});}})[_0x1f13('0x18')](function(){if(_0x4b87c0[_0x1f13('0x37')][_0x1f13('0x77')]&&_0x113884){return db['CmHopper'][_0x1f13('0x17')]({'phone':_0x4b87c0['body'][_0x1f13('0x77')],'OrderBy':0x0},{'where':{'ContactId':_0x113884['id']}});}})[_0x1f13('0x18')](function(){return _0x113884;})[_0x1f13('0x18')](respondWithResult(_0x1e4de1,null))[_0x1f13('0x25')](handleError(_0x1e4de1,null));};exports[_0x1f13('0x78')]=function(_0x4b234c,_0x5f3aa4){var _0x7a9512={};var _0x1056b9={};var _0x5826ea;var _0xbd7e1f;return db[_0x1f13('0x26')]['findOne']({'where':{'id':_0x4b234c[_0x1f13('0x27')]['id']}})[_0x1f13('0x18')](handleEntityNotFound(_0x5f3aa4,null))['then'](function(_0x229cf9){if(_0x229cf9){_0x5826ea=_0x229cf9;_0x1056b9[_0x1f13('0x79')]=_[_0x1f13('0x29')](db['Tag']['rawAttributes']);_0x1056b9[_0x1f13('0x2f')]=_[_0x1f13('0x29')](_0x4b234c[_0x1f13('0x2f')]);_0x1056b9[_0x1f13('0x7a')]=_['intersection'](_0x1056b9[_0x1f13('0x79')],_0x1056b9[_0x1f13('0x2f')]);_0x7a9512[_0x1f13('0x7b')]=_[_0x1f13('0x7c')](_0x1056b9[_0x1f13('0x79')],qs[_0x1f13('0x7d')](_0x4b234c['query'][_0x1f13('0x7d')]));_0x7a9512['attributes']=_0x7a9512[_0x1f13('0x7b')][_0x1f13('0x2a')]?_0x7a9512[_0x1f13('0x7b')]:_0x1056b9['model'];_0x7a9512[_0x1f13('0x7e')]=qs['sort'](_0x4b234c[_0x1f13('0x2f')][_0x1f13('0x7f')]);_0x7a9512[_0x1f13('0x5e')]=qs['filters'](_[_0x1f13('0x80')](_0x4b234c[_0x1f13('0x2f')],_0x1056b9[_0x1f13('0x7a')]));if(_0x4b234c[_0x1f13('0x2f')][_0x1f13('0x81')]){_0x7a9512[_0x1f13('0x5e')]=_['merge'](_0x7a9512['where'],{'$or':_[_0x1f13('0x6c')](_0x7a9512[_0x1f13('0x7b')],function(_0x57f9ca){var _0x39002f={};_0x39002f[_0x57f9ca]={'$like':'%'+_0x4b234c['query'][_0x1f13('0x81')]+'%'};return _0x39002f;})});}_0x7a9512=_[_0x1f13('0x36')]({},_0x7a9512,_0x4b234c['options']);return _0x5826ea[_0x1f13('0x78')](_0x7a9512);}})[_0x1f13('0x18')](function(_0x492038){if(_0x492038){_0xbd7e1f=_0x492038['length'];if(!_0x4b234c[_0x1f13('0x2f')][_0x1f13('0x35')](_0x1f13('0x82'))){_0x7a9512[_0x1f13('0x14')]=qs[_0x1f13('0x14')](_0x4b234c['query']['limit']);_0x7a9512[_0x1f13('0x11')]=qs[_0x1f13('0x11')](_0x4b234c[_0x1f13('0x2f')]['offset']);}return _0x5826ea[_0x1f13('0x78')](_0x7a9512);}})['then'](function(_0x287e1f){if(_0x287e1f){return _0x287e1f?{'count':_0xbd7e1f,'rows':_0x287e1f}:null;}})[_0x1f13('0x18')](respondWithResult(_0x5f3aa4,null))[_0x1f13('0x25')](handleError(_0x5f3aa4,null));};exports['setTags']=function(_0x1c5418,_0x241127){if(_0x1c5418['body']['id']){delete _0x1c5418[_0x1f13('0x37')]['id'];}return db[_0x1f13('0x26')][_0x1f13('0x83')]({'where':{'id':_0x1c5418[_0x1f13('0x27')]['id']}})['then'](handleEntityNotFound(_0x241127,null))['then'](function(_0x33a312){if(_0x33a312){return _0x33a312[_0x1f13('0x84')](_0x1c5418[_0x1f13('0x37')][_0x1f13('0x85')]||[]);}return null;})[_0x1f13('0x18')](respondWithResult(_0x241127,null))[_0x1f13('0x25')](handleError(_0x241127,null));};exports[_0x1f13('0x86')]=function(_0x58ee59,_0x364986){var _0x228f4b=[];_0x228f4b[_0x1f13('0x60')](addAdditionalPhones(_0x58ee59[_0x1f13('0x37')]));Promise['all'](_0x228f4b)[_0x1f13('0x18')](function(){_0x228f4b=[];_0x228f4b[_0x1f13('0x60')](deleteCmHopperPhones(_0x58ee59['body']['id']));_0x228f4b[_0x1f13('0x60')](addCmHopperPhones(_0x58ee59[_0x1f13('0x37')]['id']));Promise[_0x1f13('0x87')](_0x228f4b)[_0x1f13('0x18')](function(){return[0x1];})[_0x1f13('0x18')](respondWithResult(_0x364986,null));});};function addAdditionalPhones(_0x5a0785){var _0x4e6328;return new Promise(function(_0x184dfa){return db[_0x1f13('0x4c')][_0x1f13('0x19')]({'where':{'CmContactId':_0x5a0785['id']}})['then'](function(){db[_0x1f13('0x88')][_0x1f13('0x23')]({'raw':!![],'attributes':['id','OrderBy']})['then'](function(_0x2fd62c){var _0xd0b53e=[];for(var _0x34f4ed=0x0;_0x34f4ed<_0x5a0785[_0x1f13('0x89')][_0x1f13('0x2a')];_0x34f4ed++){var _0x5277c5=_0x5a0785['item_types']?_[_0x1f13('0x56')](_0x5a0785[_0x1f13('0x8a')][_0x34f4ed])?'':_0x5a0785[_0x1f13('0x8a')][_0x34f4ed]:_0x5a0785[_0x1f13('0x89')][_0x34f4ed]['ItemTypeId']?_0x5a0785[_0x1f13('0x89')][_0x34f4ed][_0x1f13('0x8b')]:'';var _0x42b794=_['isNil'](_0x5a0785['items'][_0x34f4ed]['description'])?'':_0x5a0785[_0x1f13('0x89')][_0x34f4ed][_0x1f13('0x8c')];var _0x30ffa4=_0x5277c5+':'+_0x5a0785[_0x1f13('0x89')][_0x34f4ed][_0x1f13('0x77')]+'§'+_0x42b794;if(_[_0x1f13('0x56')](_0x4e6328))_0x4e6328=_0x30ffa4;else _0x4e6328+=';'+_0x30ffa4;var _0xc08cb4=null;var _0x2eb25b=null;if(_0x5a0785[_0x1f13('0x8a')]){if(!_[_0x1f13('0x56')](_0x5a0785[_0x1f13('0x8a')][_0x34f4ed])){_0x2eb25b=_[_0x1f13('0x65')](_0x2fd62c,function(_0xcccf85){return _0xcccf85['id']===_0x5a0785[_0x1f13('0x8a')][_0x34f4ed];});if(!_[_0x1f13('0x56')](_0x2eb25b)){_0xc08cb4=_0x2eb25b['OrderBy'];}}}else{if(!_[_0x1f13('0x56')](_0x5a0785[_0x1f13('0x89')][_0x34f4ed])){_0x2eb25b=_['find'](_0x2fd62c,function(_0x4a4c74){return _0x4a4c74['id']===_0x5a0785[_0x1f13('0x89')][_0x34f4ed][_0x1f13('0x8b')];});if(!_['isNil'](_0x2eb25b)){_0xc08cb4=_0x34f4ed;}}}if(_['isNil'](_0xc08cb4)){_0xc08cb4=0x64;}_0xd0b53e[_0x1f13('0x60')](addAdditionalPhone(_0x5a0785['id'],_0x5a0785[_0x1f13('0x89')][_0x34f4ed][_0x1f13('0x77')],_0x5a0785[_0x1f13('0x8a')]?_['isNil'](_0x5a0785[_0x1f13('0x8a')][_0x34f4ed])?null:_0x5a0785[_0x1f13('0x8a')][_0x34f4ed]:_0x5a0785['items'][_0x34f4ed][_0x1f13('0x8b')]?_0x5a0785['items'][_0x34f4ed][_0x1f13('0x8b')]:null,_0xc08cb4,_0x42b794));}Promise[_0x1f13('0x87')](_0xd0b53e)[_0x1f13('0x18')](function(){db[_0x1f13('0x26')][_0x1f13('0x17')]({'AdditionalPhones':_0x4e6328},{'where':{'id':_0x5a0785['id']}})[_0x1f13('0x18')](function(){_0x184dfa(0x1);});});});});});}function addAdditionalPhone(_0x1e39a5,_0x109078,_0xd05a8f,_0x237f90,_0x20876d){return db[_0x1f13('0x4c')]['find']({'where':{'CmContactId':_0x1e39a5,'item':_0x109078}})['then'](function(_0x1860d1){if(_0x1860d1)logger[_0x1f13('0x3c')](_0x1f13('0x8d'),_0x1860d1);else{db[_0x1f13('0x4c')][_0x1f13('0x54')]({'CmContactId':_0x1e39a5,'item':_0x109078,'ItemTypeId':_0xd05a8f,'OrderBy':_0x237f90,'ItemClass':_0x1f13('0x8e'),'description':_0x20876d});}});}function deleteCmHopperPhones(_0x9fac35){return new Promise(function(_0x4a74aa){return db['CmHopper'][_0x1f13('0x23')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x9fac35}})[_0x1f13('0x18')](function(_0x2a718c){db[_0x1f13('0x8f')][_0x1f13('0x19')]({'where':{'CmHopperId':{'$in':_['map'](_0x2a718c,'id')}}});})[_0x1f13('0x18')](function(){_0x4a74aa(0x1);});});}function addCmHopperPhones(_0x643795){return new Promise(function(_0x3ac17e){return db[_0x1f13('0x90')][_0x1f13('0x23')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x643795}})[_0x1f13('0x18')](function(_0x4c496a){var _0x482d53=[];_[_0x1f13('0x6c')](_0x4c496a,function(_0x55fcff){_0x482d53[_0x1f13('0x60')](createCmHopperPhone(_0x643795,_0x55fcff['id']));});Promise[_0x1f13('0x87')](_0x482d53)[_0x1f13('0x18')](function(){_0x3ac17e(0x1);});});});}function createCmHopperPhone(_0x2a2bdc,_0x558d94){return new Promise(function(_0x59250a){db[_0x1f13('0x4c')][_0x1f13('0x23')]({'raw':!![],'attributes':[_0x1f13('0x91'),'OrderBy'],'where':{'CmContactId':_0x2a2bdc,'ItemClass':_0x1f13('0x8e')},'include':[{'model':db['ContactItemType'],'attributes':[_0x1f13('0x92')],'as':'ItemType'}],'order':[_0x1f13('0x92'),db[_0x1f13('0x6a')][_0x1f13('0x93')](_0x1f13('0x94'))]})[_0x1f13('0x18')](function(_0x5b7cff){var _0x5499b5=0x1;var _0x1f694e=_[_0x1f13('0x6c')](_0x5b7cff,function(_0x23c082){_0x23c082[_0x1f13('0x95')]=_0x558d94;_0x23c082[_0x1f13('0x77')]=_0x23c082[_0x1f13('0x91')];_0x23c082[_0x1f13('0x92')]=_0x5499b5;delete _0x23c082[_0x1f13('0x96')];_0x5499b5=_0x5499b5+0x1;return _0x23c082;});return db[_0x1f13('0x8f')][_0x1f13('0x5b')](_0x1f694e,{});})[_0x1f13('0x18')](function(){_0x59250a(0x1);});});}function insertAdditionalPhones(_0x7e99e2,_0x7d6270){return new Promise(function(_0x58b13c){var _0x147354=[];for(var _0x6469ed=0x0;_0x6469ed<_0x7d6270[_0x1f13('0x2a')];_0x6469ed++){var _0x2a030f=_0x7d6270[_0x6469ed];_0x147354['push'](parseContactItemType(_0x2a030f));}Promise[_0x1f13('0x87')](_0x147354)['then'](function(){var _0x433cd4={'id':_0x7e99e2['id'],'items':_0x7d6270};return addAdditionalPhones(_0x433cd4)[_0x1f13('0x18')](function(){return addCmHopperPhones(_0x7e99e2['id']);});})[_0x1f13('0x18')](function(){_0x58b13c(_0x7e99e2);});});}function parseContactItemType(_0x2f1c21){return new Promise(function(_0x53253a){if(_0x2f1c21[_0x1f13('0x35')]('ItemTypeId')){_0x53253a(_0x2f1c21);}else{return db['ContactItemType'][_0x1f13('0x65')]({'where':{'name':_0x2f1c21[_0x1f13('0x97')]}})[_0x1f13('0x18')](function(_0x6c4f60){if(_[_0x1f13('0x56')](_0x6c4f60))_0x2f1c21['ItemTypeId']=null;else _0x2f1c21[_0x1f13('0x8b')]=_0x6c4f60['id'];_0x53253a(_0x2f1c21);});}});}exports['getAdditionalPhones']=function(_0x38dbe1,_0x51dffd){return db[_0x1f13('0x4c')][_0x1f13('0x23')]({'raw':!![],'where':{'CmContactId':_0x38dbe1[_0x1f13('0x27')]['id'],'ItemClass':'PHONE'},'include':[{'model':db[_0x1f13('0x88')],'as':'ItemType'}],'order':[['OrderBy'],[db[_0x1f13('0x6a')][_0x1f13('0x93')](_0x1f13('0x94'))]]})[_0x1f13('0x18')](function(_0x5e38a6){return _0x5e38a6;})[_0x1f13('0x18')](respondWithResult(_0x51dffd,null))['catch'](handleError(_0x51dffd,null));};exports[_0x1f13('0x98')]=function(_0x56fce5,_0x43427f){return db['CmContactHasItem'][_0x1f13('0x23')]({'raw':!![],'where':{'CmContactId':_0x56fce5[_0x1f13('0x37')][_0x1f13('0x99')]}})[_0x1f13('0x18')](function(_0x57f71a){var _0x518928=_[_0x1f13('0x6c')](_0x57f71a,function(_0x1d57d7){_0x1d57d7['CmContactId']=_0x56fce5['body'][_0x1f13('0x9a')];return _0x1d57d7;});return db['CmContactHasItem'][_0x1f13('0x5b')](_0x518928,{});})[_0x1f13('0x18')](function(){return addCmHopperPhones(_0x56fce5[_0x1f13('0x37')]['toContactId']);})[_0x1f13('0x18')](function(){return['ok'];})[_0x1f13('0x18')](respondWithResult(_0x43427f,null))['catch'](handleError(_0x43427f,null));};exports[_0x1f13('0x9b')]=function(_0x5c62a2,_0x4d1ae0){var _0xb3e1d4=[];_0xb3e1d4[_0x1f13('0x60')](createCmHopperPhone(_0x5c62a2['body']['id'],_0x5c62a2[_0x1f13('0x37')]['hopperId']));Promise[_0x1f13('0x87')](_0xb3e1d4)[_0x1f13('0x18')](function(){return[0x1];})[_0x1f13('0x18')](respondWithResult(_0x4d1ae0,null));};exports[_0x1f13('0x9c')]=function(_0x2a9d84,_0x19cca6){var _0x4a00ad={'raw':![],'where':{}};var _0x338352={};var _0x39cd35={'count':0x0,'rows':[]};return db[_0x1f13('0x26')]['findOne']({'where':{'id':_0x2a9d84[_0x1f13('0x27')]['id']}})['then'](handleEntityNotFound(_0x19cca6,null))[_0x1f13('0x18')](function(_0x2d79c3){if(_0x2d79c3){_0x338352[_0x1f13('0x79')]=_[_0x1f13('0x29')](db['CmHopper'][_0x1f13('0x9d')]);_0x338352[_0x1f13('0x2f')]=_[_0x1f13('0x29')](_0x2a9d84['query']);_0x338352[_0x1f13('0x7a')]=_['intersection'](_0x338352[_0x1f13('0x79')],_0x338352[_0x1f13('0x2f')]);_0x4a00ad[_0x1f13('0x7b')]=_[_0x1f13('0x7c')](_0x338352[_0x1f13('0x79')],qs['fields'](_0x2a9d84[_0x1f13('0x2f')][_0x1f13('0x7d')]));_0x4a00ad[_0x1f13('0x7b')]=_0x4a00ad[_0x1f13('0x7b')][_0x1f13('0x2a')]?_0x4a00ad[_0x1f13('0x7b')]:_0x338352[_0x1f13('0x79')];if(!_0x2a9d84['query'][_0x1f13('0x35')]('nolimit')){_0x4a00ad[_0x1f13('0x14')]=qs['limit'](_0x2a9d84[_0x1f13('0x2f')][_0x1f13('0x14')]);_0x4a00ad[_0x1f13('0x11')]=qs[_0x1f13('0x11')](_0x2a9d84[_0x1f13('0x2f')][_0x1f13('0x11')]);}_0x4a00ad[_0x1f13('0x7e')]=qs[_0x1f13('0x7f')](_0x2a9d84[_0x1f13('0x2f')]['sort']);_0x4a00ad[_0x1f13('0x5e')]=qs[_0x1f13('0x7a')](_[_0x1f13('0x80')](_0x2a9d84['query'],_0x338352['filters']));_0x4a00ad[_0x1f13('0x5e')][_0x1f13('0x9e')]=_0x2d79c3['id'];if(_0x2a9d84[_0x1f13('0x2f')]['filter']){_0x4a00ad['where']=_[_0x1f13('0x36')](_0x4a00ad[_0x1f13('0x5e')],{'$or':_[_0x1f13('0x6c')](_0x4a00ad[_0x1f13('0x7b')],function(_0x129c10){var _0x19d18b={};_0x19d18b[_0x129c10]={'$like':'%'+_0x2a9d84[_0x1f13('0x2f')]['filter']+'%'};return _0x19d18b;})});}_0x4a00ad=_['merge']({},_0x4a00ad,_0x2a9d84[_0x1f13('0x9f')]);return db[_0x1f13('0x90')][_0x1f13('0x13')]({'where':_0x4a00ad[_0x1f13('0x5e')]})[_0x1f13('0x18')](function(_0x20c1ac){_0x39cd35['count']=_0x20c1ac;if(_0x2a9d84[_0x1f13('0x2f')][_0x1f13('0xa0')]){_0x4a00ad[_0x1f13('0xa1')]=[{'all':!![]}];}return db[_0x1f13('0x90')]['findAll'](_0x4a00ad);})[_0x1f13('0x18')](function(_0x46aa33){_0x39cd35[_0x1f13('0xa2')]=_0x46aa33;return _0x39cd35;});}})['then'](respondWithFilteredResult(_0x19cca6,_0x4a00ad))[_0x1f13('0x25')](handleError(_0x19cca6,null));};exports[_0x1f13('0xa3')]=function(_0x252700,_0x2d2eae){var _0x2a4de4={'raw':!![],'where':{}};var _0xe9209f={};var _0x2d8397={'count':0x0,'rows':[]};return db[_0x1f13('0x26')][_0x1f13('0x83')]({'where':{'id':_0x252700['params']['id']}})[_0x1f13('0x18')](handleEntityNotFound(_0x2d2eae,null))['then'](function(_0x2d77a5){if(_0x2d77a5){_0xe9209f[_0x1f13('0x79')]=_[_0x1f13('0x29')](db[_0x1f13('0x4d')]['rawAttributes']);_0xe9209f[_0x1f13('0x2f')]=_['keys'](_0x252700[_0x1f13('0x2f')]);_0xe9209f[_0x1f13('0x7a')]=_['intersection'](_0xe9209f['model'],_0xe9209f[_0x1f13('0x2f')]);_0x2a4de4[_0x1f13('0x7b')]=_[_0x1f13('0x7c')](_0xe9209f[_0x1f13('0x79')],qs[_0x1f13('0x7d')](_0x252700['query'][_0x1f13('0x7d')]));_0x2a4de4[_0x1f13('0x7b')]=_0x2a4de4[_0x1f13('0x7b')][_0x1f13('0x2a')]?_0x2a4de4[_0x1f13('0x7b')]:_0xe9209f['model'];if(!_0x252700['query'][_0x1f13('0x35')]('nolimit')){_0x2a4de4['limit']=qs[_0x1f13('0x14')](_0x252700[_0x1f13('0x2f')]['limit']);_0x2a4de4[_0x1f13('0x11')]=qs[_0x1f13('0x11')](_0x252700['query']['offset']);}_0x2a4de4[_0x1f13('0x7e')]=qs[_0x1f13('0x7f')](_0x252700[_0x1f13('0x2f')][_0x1f13('0x7f')]);_0x2a4de4[_0x1f13('0x5e')]=qs[_0x1f13('0x7a')](_['pick'](_0x252700[_0x1f13('0x2f')],_0xe9209f[_0x1f13('0x7a')]));_0x2a4de4[_0x1f13('0x5e')][_0x1f13('0x9e')]=_0x2d77a5['id'];if(_0x252700[_0x1f13('0x2f')][_0x1f13('0x81')]){_0x2a4de4[_0x1f13('0x5e')]=_['merge'](_0x2a4de4[_0x1f13('0x5e')],{'$or':_[_0x1f13('0x6c')](_0x2a4de4[_0x1f13('0x7b')],function(_0x170e46){var _0x414852={};_0x414852[_0x170e46]={'$like':'%'+_0x252700['query'][_0x1f13('0x81')]+'%'};return _0x414852;})});}_0x2a4de4=_[_0x1f13('0x36')]({},_0x2a4de4,_0x252700[_0x1f13('0x9f')]);return db[_0x1f13('0x4d')]['count']({'where':_0x2a4de4[_0x1f13('0x5e')]})[_0x1f13('0x18')](function(_0x53b825){_0x2d8397['count']=_0x53b825;if(_0x252700['query'][_0x1f13('0xa0')]){_0x2a4de4[_0x1f13('0xa1')]=[{'all':!![]}];}return db['CmHopperHistory'][_0x1f13('0x23')](_0x2a4de4);})[_0x1f13('0x18')](function(_0x256e06){_0x2d8397[_0x1f13('0xa2')]=_0x256e06;return _0x2d8397;});}})['then'](respondWithFilteredResult(_0x2d2eae,_0x2a4de4))['catch'](handleError(_0x2d2eae,null));};exports[_0x1f13('0xa4')]=function(_0x299144,_0x545f5d){var _0x10e942={'raw':!![],'where':{}};var _0x37e15d={};var _0x1b085d={'count':0x0,'rows':[]};return db[_0x1f13('0x26')][_0x1f13('0x83')]({'where':{'id':_0x299144[_0x1f13('0x27')]['id']}})[_0x1f13('0x18')](handleEntityNotFound(_0x545f5d,null))[_0x1f13('0x18')](function(_0x2fd9a2){if(_0x2fd9a2){_0x37e15d['model']=_['keys'](db['CmHopperFinal']['rawAttributes']);_0x37e15d[_0x1f13('0x2f')]=_[_0x1f13('0x29')](_0x299144['query']);_0x37e15d[_0x1f13('0x7a')]=_[_0x1f13('0x7c')](_0x37e15d[_0x1f13('0x79')],_0x37e15d['query']);_0x10e942[_0x1f13('0x7b')]=_[_0x1f13('0x7c')](_0x37e15d[_0x1f13('0x79')],qs[_0x1f13('0x7d')](_0x299144[_0x1f13('0x2f')][_0x1f13('0x7d')]));_0x10e942['attributes']=_0x10e942[_0x1f13('0x7b')][_0x1f13('0x2a')]?_0x10e942['attributes']:_0x37e15d[_0x1f13('0x79')];if(!_0x299144[_0x1f13('0x2f')][_0x1f13('0x35')](_0x1f13('0x82'))){_0x10e942[_0x1f13('0x14')]=qs[_0x1f13('0x14')](_0x299144[_0x1f13('0x2f')][_0x1f13('0x14')]);_0x10e942[_0x1f13('0x11')]=qs[_0x1f13('0x11')](_0x299144[_0x1f13('0x2f')][_0x1f13('0x11')]);}_0x10e942[_0x1f13('0x7e')]=qs[_0x1f13('0x7f')](_0x299144[_0x1f13('0x2f')][_0x1f13('0x7f')]);_0x10e942[_0x1f13('0x5e')]=qs[_0x1f13('0x7a')](_['pick'](_0x299144[_0x1f13('0x2f')],_0x37e15d[_0x1f13('0x7a')]));_0x10e942[_0x1f13('0x5e')][_0x1f13('0x9e')]=_0x2fd9a2['id'];if(_0x299144[_0x1f13('0x2f')][_0x1f13('0x81')]){_0x10e942[_0x1f13('0x5e')]=_[_0x1f13('0x36')](_0x10e942[_0x1f13('0x5e')],{'$or':_['map'](_0x10e942[_0x1f13('0x7b')],function(_0x5a2ca0){var _0xfce451={};_0xfce451[_0x5a2ca0]={'$like':'%'+_0x299144[_0x1f13('0x2f')][_0x1f13('0x81')]+'%'};return _0xfce451;})});}_0x10e942=_[_0x1f13('0x36')]({},_0x10e942,_0x299144[_0x1f13('0x9f')]);return db['CmHopperFinal'][_0x1f13('0x13')]({'where':_0x10e942[_0x1f13('0x5e')]})[_0x1f13('0x18')](function(_0x1b6ee9){_0x1b085d[_0x1f13('0x13')]=_0x1b6ee9;if(_0x299144[_0x1f13('0x2f')][_0x1f13('0xa0')]){_0x10e942['include']=[{'all':!![]}];}return db[_0x1f13('0xa5')]['findAll'](_0x10e942);})[_0x1f13('0x18')](function(_0x3e82f4){_0x1b085d[_0x1f13('0xa2')]=_0x3e82f4;return _0x1b085d;});}})[_0x1f13('0x18')](respondWithFilteredResult(_0x545f5d,_0x10e942))['catch'](handleError(_0x545f5d,null));};exports[_0x1f13('0xa6')]=function(_0x28ea59,_0x323a11){var _0x4e8c00={'raw':!![],'where':{}};var _0x4f0259={};var _0x4d1d65={'count':0x0,'rows':[]};return db['CmContact'][_0x1f13('0x83')]({'where':{'id':_0x28ea59[_0x1f13('0x27')]['id']}})[_0x1f13('0x18')](handleEntityNotFound(_0x323a11,null))[_0x1f13('0x18')](function(_0xe6edf5){if(_0xe6edf5){_0x4f0259[_0x1f13('0x79')]=_[_0x1f13('0x29')](db[_0x1f13('0xa7')]['rawAttributes']);_0x4f0259[_0x1f13('0x2f')]=_[_0x1f13('0x29')](_0x28ea59['query']);_0x4f0259['filters']=_[_0x1f13('0x7c')](_0x4f0259[_0x1f13('0x79')],_0x4f0259[_0x1f13('0x2f')]);_0x4e8c00[_0x1f13('0x7b')]=_[_0x1f13('0x7c')](_0x4f0259[_0x1f13('0x79')],qs[_0x1f13('0x7d')](_0x28ea59[_0x1f13('0x2f')][_0x1f13('0x7d')]));_0x4e8c00[_0x1f13('0x7b')]=_0x4e8c00[_0x1f13('0x7b')][_0x1f13('0x2a')]?_0x4e8c00[_0x1f13('0x7b')]:_0x4f0259[_0x1f13('0x79')];if(!_0x28ea59[_0x1f13('0x2f')]['hasOwnProperty'](_0x1f13('0x82'))){_0x4e8c00[_0x1f13('0x14')]=qs[_0x1f13('0x14')](_0x28ea59[_0x1f13('0x2f')][_0x1f13('0x14')]);_0x4e8c00[_0x1f13('0x11')]=qs[_0x1f13('0x11')](_0x28ea59['query'][_0x1f13('0x11')]);}_0x4e8c00[_0x1f13('0x7e')]=qs[_0x1f13('0x7f')](_0x28ea59[_0x1f13('0x2f')][_0x1f13('0x7f')]);_0x4e8c00['where']=qs['filters'](_[_0x1f13('0x80')](_0x28ea59[_0x1f13('0x2f')],_0x4f0259['filters']));_0x4e8c00['where'][_0x1f13('0x9e')]=_0xe6edf5['id'];if(_0x28ea59[_0x1f13('0x2f')]['filter']){_0x4e8c00[_0x1f13('0x5e')]=_[_0x1f13('0x36')](_0x4e8c00[_0x1f13('0x5e')],{'$or':_[_0x1f13('0x6c')](_0x4e8c00[_0x1f13('0x7b')],function(_0x3e5d12){var _0x3fb56a={};_0x3fb56a[_0x3e5d12]={'$like':'%'+_0x28ea59[_0x1f13('0x2f')]['filter']+'%'};return _0x3fb56a;})});}_0x4e8c00=_['merge']({},_0x4e8c00,_0x28ea59[_0x1f13('0x9f')]);return db[_0x1f13('0xa7')]['count']({'where':_0x4e8c00['where']})[_0x1f13('0x18')](function(_0x46a82a){_0x4d1d65['count']=_0x46a82a;if(_0x28ea59[_0x1f13('0x2f')][_0x1f13('0xa0')]){_0x4e8c00[_0x1f13('0xa1')]=[{'all':!![]}];}return db[_0x1f13('0xa7')]['findAll'](_0x4e8c00);})[_0x1f13('0x18')](function(_0x3986bf){_0x4d1d65[_0x1f13('0xa2')]=_0x3986bf;return _0x4d1d65;});}})['then'](respondWithFilteredResult(_0x323a11,_0x4e8c00))[_0x1f13('0x25')](handleError(_0x323a11,null));};exports[_0x1f13('0xa8')]=function(_0x186e90,_0x1676dd){try{if(!_0x186e90['body'][_0x1f13('0x61')]){throw new Error(_0x1f13('0xa9'));}if(!_0x186e90['body'][_0x1f13('0xaa')]){throw new Error('No\x20association\x20keys\x20specified!');}if(!_0x186e90[_0x1f13('0x37')][_0x1f13('0xab')]){throw new Error(_0x1f13('0xac'));}if(!_0x186e90[_0x1f13('0x37')][_0x1f13('0xad')]){throw new Error(_0x1f13('0xae'));}var _0xc1ee98=_0x186e90[_0x1f13('0x37')]['binding_keys'][_0x1f13('0xaf')](',');var _0x73790d=_0x186e90[_0x1f13('0x37')][_0x1f13('0xab')][_0x1f13('0xaf')](',');if(!_0xc1ee98[_0x1f13('0x2a')]||!_0x73790d[_0x1f13('0x2a')]||_0xc1ee98[_0x1f13('0x2a')]!==_0x73790d[_0x1f13('0x2a')]){throw new Error(_0x1f13('0xb0'));}_0x186e90[_0x1f13('0x37')]['fields']=_[_0x1f13('0xb1')](_0xc1ee98,_0x73790d);if(!_0x186e90[_0x1f13('0x37')][_0x1f13('0x7d')][_0x1f13('0x77')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x186e90['body'][_0x1f13('0x7d')][_0x1f13('0xb2')]){throw new Error(_0x1f13('0xb3'));}var _0x1f04ff=path[_0x1f13('0x55')](config[_0x1f13('0xb4')],_0x1f13('0xb5'),_0x186e90[_0x1f13('0xb6')][_0x1f13('0xb7')]);fs[_0x1f13('0xb8')](_0x1f04ff,parseInt(_0x1f13('0xb9'),0x8));var _0x5f1f87=require('child_process')[_0x1f13('0xba')](path[_0x1f13('0x55')](__dirname,_0x1f13('0xbb')),[_0x1f04ff,_0x186e90[_0x1f13('0x37')]['binding_keys'],_0x186e90[_0x1f13('0x37')]['binding_values'],_0x186e90[_0x1f13('0x37')][_0x1f13('0x61')],_0x186e90[_0x1f13('0x37')][_0x1f13('0xbc')],_0x186e90[_0x1f13('0x37')][_0x1f13('0x5d')],_0x186e90[_0x1f13('0x37')][_0x1f13('0xad')]]);return _0x1676dd[_0x1f13('0xf')](0xc8)[_0x1f13('0x10')]({'message':_0x1f13('0xbd'),'pid':_0x5f1f87['pid']});}catch(_0x453c92){return _0x1676dd[_0x1f13('0xf')](0x1f4)[_0x1f13('0x1f')](_0x453c92);}};exports[_0x1f13('0xbe')]=function(_0xd4e325,_0x11bb18){var _0x2e38ca=fs[_0x1f13('0xbf')](_0xd4e325['file'][_0x1f13('0x2')]);Papa[_0x1f13('0xc0')](_0x2e38ca,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x423ef0){return _0x11bb18[_0x1f13('0xf')](0xc8)['json']({'file':_0xd4e325[_0x1f13('0xb6')],'fields':_0x423ef0[_0x1f13('0xc1')][_0x1f13('0x7d')]});}});};exports[_0x1f13('0xc2')]=function(_0x346251,_0x57789c){return db[_0x1f13('0xc3')][_0x1f13('0x23')]({'raw':!![],'attributes':['id'],'where':{'role':_0x1f13('0xc4')}})['then'](function(_0x1fcb00){var _0x421c0c=![];if(!_0x346251['body'][_0x1f13('0x61')]){throw new Error(_0x1f13('0xa9'));}if(!_0x346251[_0x1f13('0x37')]['binding']['phone']){throw new Error(_0x1f13('0xc5'));}if(!_0x346251[_0x1f13('0x37')][_0x1f13('0xc6')][_0x1f13('0xb2')]){throw new Error(_0x1f13('0xb3'));}if(!_0x346251[_0x1f13('0x37')][_0x1f13('0xad')]){throw new Error(_0x1f13('0xae'));}var _0x236f1d=require('child_process')[_0x1f13('0xba')](path[_0x1f13('0x55')](__dirname,_0x1f13('0xc7')),[_0x346251[_0x1f13('0x27')]['id'],JSON[_0x1f13('0xc8')](_0x346251['body']),JSON['stringify'](_0x1fcb00)]);_0x236f1d['on'](_0x1f13('0xc9'),function(){_0x421c0c=!![];return _0x57789c[_0x1f13('0xf')](0xc8)['json']({'message':'start\x20child\x20process\x20correctly!','pid':_0x236f1d[_0x1f13('0xca')]});});_0x236f1d['on'](_0x1f13('0xcb'),function(_0x4e9622){if(_0x4e9622&&!_0x421c0c){return _0x57789c[_0x1f13('0xf')](0x1f4)[_0x1f13('0x10')]({'message':_0x1f13('0xcc'),'pid':_0x236f1d[_0x1f13('0xca')]});}});})['catch'](handleError(_0x57789c,null));};exports[_0x1f13('0xcd')]=function(_0x21fe84,_0x204020){return db['User'][_0x1f13('0x23')]({'raw':!![],'attributes':['id'],'where':{'role':_0x1f13('0xc4')}})[_0x1f13('0x18')](function(_0xfb915){var _0x285596=![];if(!_0x21fe84[_0x1f13('0x37')]['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x21fe84[_0x1f13('0x37')][_0x1f13('0xc6')][_0x1f13('0x77')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x21fe84['body'][_0x1f13('0xc6')][_0x1f13('0xb2')]){throw new Error('No\x20firstName\x20column\x20specified');}if(!_0x21fe84[_0x1f13('0x37')][_0x1f13('0xad')]){throw new Error(_0x1f13('0xae'));}var _0xcff088=require(_0x1f13('0xce'))[_0x1f13('0xba')](path[_0x1f13('0x55')](__dirname,_0x1f13('0xcf')),[_0x21fe84['params']['id'],JSON['stringify'](_0x21fe84[_0x1f13('0x37')]),JSON[_0x1f13('0xc8')](_0xfb915)]);_0xcff088['on']('message',function(){_0x285596=!![];return _0x204020[_0x1f13('0xf')](0xc8)[_0x1f13('0x10')]({'message':_0x1f13('0xd0'),'pid':_0xcff088[_0x1f13('0xca')]});});_0xcff088['on'](_0x1f13('0xcb'),function(_0x29f895){if(_0x29f895&&!_0x285596){return _0x204020[_0x1f13('0xf')](0x1f4)[_0x1f13('0x10')]({'message':_0x1f13('0xcc'),'pid':_0xcff088[_0x1f13('0xca')]});}});})[_0x1f13('0x25')](handleError(_0x204020,null));};exports['getJourney']=function(_0x4ca182,_0x5f5086){var _0x32ea26=[_0x1f13('0xd1'),_0x1f13('0xd2'),'sms',_0x1f13('0xd3'),'fax',_0x1f13('0xd4'),_0x1f13('0xd5')];var _0xe72235={'offset':0x0,'order':qs[_0x1f13('0x7f')](_0x1f13('0xd6'))},_0x2b0ddc={'count':0x0,'rows':[]};Promise[_0x1f13('0xd7')]()[_0x1f13('0x18')](function(){if(_0x4ca182[_0x1f13('0x2f')][_0x1f13('0xd8')]){if(!_[_0x1f13('0xd9')](_0x32ea26,_0x4ca182[_0x1f13('0x2f')]['channel'][_0x1f13('0xda')]())){throw new Error('Invalid\x20channel');}_0x32ea26=[_0x4ca182[_0x1f13('0x2f')][_0x1f13('0xd8')][_0x1f13('0xda')]()];}if(_0x4ca182['query'][_0x1f13('0xdb')]){try{var _0x10761d=JSON[_0x1f13('0xc0')](_0x4ca182[_0x1f13('0x2f')][_0x1f13('0xdb')]);if(!moment(_0x10761d[_0x1f13('0x38')])['isValid']()){throw new Error(_0x1f13('0xdc'));}if(!moment(_0x10761d['to'])['isValid']()){throw new Error(_0x1f13('0xdd'));}}catch(_0x369f0e){throw new Error(_0x1f13('0xde'));}}if(!_0x4ca182[_0x1f13('0x2f')]['hasOwnProperty'](_0x1f13('0x82'))){_0xe72235[_0x1f13('0x14')]=qs[_0x1f13('0x14')](_0x4ca182[_0x1f13('0x2f')][_0x1f13('0x14')]||0xa);_0xe72235['offset']=qs[_0x1f13('0x11')](_0x4ca182[_0x1f13('0x2f')][_0x1f13('0x11')]);}var _0x1bd663=_0x32ea26[_0x1f13('0x6c')](function(_0x1ae23d){if(_0x1ae23d===_0x1f13('0xd5')){var _0x40fac3={'attributes':['id',_0x1f13('0xdf'),'type','source',_0x1f13('0xe0'),_0x1f13('0xe1'),_0x1f13('0xe2'),_0x1f13('0xe3'),_0x1f13('0xe4'),_0x1f13('0xe5'),_0x1f13('0xe6'),_0x1f13('0xe7'),_0x1f13('0xe8'),_0x1f13('0xe9'),_0x1f13('0xea')],'where':{'ContactId':_0x4ca182['params']['id']},'include':[{'model':db[_0x1f13('0xc3')],'as':'User','attributes':['id','name',_0x1f13('0xeb'),_0x1f13('0xec')]}],'order':[[_0x1f13('0xe6'),'DESC']]};if(_0x4ca182[_0x1f13('0x2f')][_0x1f13('0xdb')]){_0x40fac3['where'][_0x1f13('0xe6')]={'$gte':_0x10761d[_0x1f13('0x38')],'$lte':_0x10761d['to']};}return db[_0x1f13('0x4f')]['findAndCountAll'](_0x40fac3)[_0x1f13('0x18')](function(_0x3dde83){_0x2b0ddc[_0x1f13('0x13')]+=_0x3dde83[_0x1f13('0x13')];return _['map'](_0x3dde83['rows'],function(_0x2857d7){var _0x468cc3=_0x2857d7[_0x1f13('0x39')]({'plain':!![]});_0x468cc3[_0x1f13('0xd8')]=_0x1ae23d;if(_0x468cc3[_0x1f13('0xc3')]){_0x468cc3[_0x1f13('0xc3')]={'id':_0x468cc3[_0x1f13('0xc3')]['id'],'name':_0x468cc3['User'][_0x1f13('0x1e')],'fullname':_0x468cc3[_0x1f13('0xc3')][_0x1f13('0xeb')],'alias':_0x468cc3[_0x1f13('0xc3')][_0x1f13('0xec')]};}return _0x468cc3;});});}else{var _0x172b75=_[_0x1f13('0xed')](_0x1ae23d)+(_0x1ae23d===_0x1f13('0xd2')?'Website':_0x1f13('0xee'));var _0x17fde9={'attributes':['id',_0x1f13('0xef'),_0x1f13('0xf0'),_0x1f13('0xe6'),_0x1f13('0xe5'),_0x1f13('0xf1'),_0x1f13('0xf2'),_0x1f13('0xf3'),_0x1f13('0xea'),_0x172b75+'Id'],'where':{'ContactId':_0x4ca182[_0x1f13('0x27')]['id']},'include':[{'model':db[_0x172b75],'as':_0x1f13('0xee'),'attributes':['id',_0x1f13('0x1e'),'key']},{'model':db[_0x1f13('0xc3')],'as':'Owner','attributes':['id',_0x1f13('0x1e'),'fullname']},{'model':db[_0x1f13('0x66')],'as':_0x1f13('0xf4'),'attributes':['id',_0x1f13('0x1e'),'color'],'through':{'attributes':[]}}],'order':[[_0x1f13('0xe6'),_0x1f13('0xf5')]]};if(_0x4ca182[_0x1f13('0x2f')][_0x1f13('0xdb')]){_0x17fde9[_0x1f13('0x5e')][_0x1f13('0xe6')]={'$gte':_0x10761d[_0x1f13('0x38')],'$lte':_0x10761d['to']};}switch(_0x1ae23d){case'chat':_0x17fde9['attributes'][_0x1f13('0x60')](_0x1f13('0xf6'),_0x1f13('0xf7'),_0x1f13('0xf8'),_0x1f13('0xf9'),_0x1f13('0xfa'),_0x1f13('0xfb'),_0x1f13('0xfc'),_0x1f13('0xfd'),_0x1f13('0xfe'));break;case _0x1f13('0xd1'):_0x17fde9[_0x1f13('0x7b')][_0x1f13('0x60')](_0x1f13('0xff'),'substatus');break;case _0x1f13('0xd3'):_0x17fde9[_0x1f13('0x7b')][_0x1f13('0x60')](_0x1f13('0x100'),_0x1f13('0x101'));break;}return db[_['startCase'](_0x1ae23d)+'Interaction'][_0x1f13('0x102')](_0x17fde9)[_0x1f13('0x18')](function(_0x4cc122){_0x2b0ddc['count']+=_0x4cc122[_0x1f13('0x13')];return _['map'](_0x4cc122['rows'],function(_0x28a7af){var _0x3a00fa=_0x28a7af[_0x1f13('0x39')]({'plain':!![]});_0x3a00fa[_0x1f13('0xd8')]=_0x1ae23d;if(_0x3a00fa[_0x1f13('0x103')]){_0x3a00fa[_0x1f13('0x103')]={'id':_0x3a00fa[_0x1f13('0x103')]['id'],'name':_0x3a00fa[_0x1f13('0x103')][_0x1f13('0x1e')],'fullname':_0x3a00fa[_0x1f13('0x103')][_0x1f13('0xeb')]};}return _0x3a00fa;});});}});return Promise['all'](_0x1bd663);})['then'](function(_0x265d75){return _(_0x265d75)[_0x1f13('0x104')]()[_0x1f13('0x105')]('createdAt')[_0x1f13('0x106')]()[_0x1f13('0x107')]();})[_0x1f13('0x18')](function(_0x43a54c){_0x2b0ddc[_0x1f13('0xa2')]=_0xe72235['limit']?_0x43a54c[_0x1f13('0x108')](_0xe72235['offset'],_0xe72235[_0x1f13('0x11')]+_0xe72235[_0x1f13('0x14')]):_0x43a54c;return _0x2b0ddc;})['then'](respondWithFilteredResult(_0x5f5086,_0xe72235))[_0x1f13('0x25')](handleError(_0x5f5086,null));};
\ No newline at end of file