Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / cmContact / cmContact.controller.js
index b97fc6c..93df52f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x34e8=['reverse','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','ejs','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','sendStatus','end','status','json','count','offset','limit','set','apply','reject','then','destroy','error','stack','name','CmContact','describe','keys','length','cf_','push','CmCustomField','findOne','trimStart','all','fieldType','query','filters','intersection','model','fields','attributes','hasOwnProperty','nolimit','order','sort','pick','field','tools_tags','select','from','cm_contacts','left_join','cm_user_has_contacts','ct.CmContactId\x20=\x20c.id','where','c.deletedAt\x20IS\x20NULL','expr','search','parseSearch','sqlOperator','conditions','Tag','value','split','map','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','and','uc.UserId\x20=\x20?','dateOfBirth','datetime','castTo','buildExpression','text','start','filter','isNil','isEmpty','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','isArray','tag','replace','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','group','c.id','Sequelize','QueryTypes','SELECT','having','t.id\x20IN\x20?','resolve','user','role','some','c.ListId\x20IS\x20NULL','ListId','sequelize','toString','keyBy','merge','c.firstName','c.lastName','c.phone','c.fax','c.ListId','c.createdAt','c.deletedAt','c.CompanyId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','rows','find','catch','tags','startsWith','columnName','findAll','displayName','alias','custom','values','body','get','mergeWith','join','info','CmHopper','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','ChatInteraction','update','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelMessage','CmHopperFinal','ReportAgentPreview','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','bulkCreate','each','duplicates','$or','show','params','color','omit','format','cf_%d','$and','pickBy','setFields','toParam','phone','rawAttributes','options','getTags','setTags','getHoppers','ContactId','includeAll','include','CmHopperHistory','getJscriptySessions','uploadCsv','No\x20ListId\x20specified','No\x20association\x20keys\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','binding_keys','zipObject','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','filename','chmodSync','fork','../../components/import/cm/csv','File\x20uploaded\x20correctly!','send','upload','createReadStream','meta','import','binding','child_process','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process','pid','getJourney','chat','sms','openchannel','fax','whatsapp','voice','-createdAt','channel','Invalid\x20channel','toLowerCase','range','parse','Invalid\x20date\x20for\x20range\x20from\x20filter','isValid','Invalid\x20date\x20for\x20range\x20to\x20filter','uniqueid','type','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','fullname','DESC','findAndCountAll','startCase','Website','Account','closed','closedAt','disposition','thirdDisposition','UserId','browserName','customerIp','deviceModel','osName','ratingMessage','ratingType','ratingValue','subject','externalUrl','threadId','Owner','flatten','sortBy'];(function(_0x45f1f5,_0x3824ab){var _0x45060b=function(_0x337ab9){while(--_0x337ab9){_0x45f1f5['push'](_0x45f1f5['shift']());}};_0x45060b(++_0x3824ab);}(_0x34e8,0x12c));var _0x834e=function(_0x4df5d3,_0x31abec){_0x4df5d3=_0x4df5d3-0x0;var _0x2e4ebc=_0x34e8[_0x4df5d3];return _0x2e4ebc;};'use strict';var pdf=require(_0x834e('0x0'));var emlformat=require(_0x834e('0x1'));var rimraf=require(_0x834e('0x2'));var zipdir=require(_0x834e('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x834e('0x4'));var moment=require(_0x834e('0x5'));var BPromise=require(_0x834e('0x6'));var Mustache=require(_0x834e('0x7'));var util=require(_0x834e('0x8'));var path=require(_0x834e('0x9'));var sox=require(_0x834e('0xa'));var csv=require('to-csv');var ejs=require(_0x834e('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x834e('0xc'));var crypto=require(_0x834e('0xd'));var jsforce=require(_0x834e('0xe'));var deskjs=require(_0x834e('0xf'));var toCsv=require(_0x834e('0x10'));var querystring=require(_0x834e('0x11'));var Papa=require(_0x834e('0x12'));var Redis=require(_0x834e('0x13'));var authService=require(_0x834e('0x14'));var qs=require(_0x834e('0x15'));var as=require(_0x834e('0x16'));var hardwareService=require(_0x834e('0x17'));var logger=require(_0x834e('0x18'))(_0x834e('0x19'));var utils=require(_0x834e('0x1a'));var config=require(_0x834e('0x1b'));var licenseUtil=require(_0x834e('0x1c'));var db=require('../../mysqldb')['db'];config[_0x834e('0x1d')]=_[_0x834e('0x1e')](config['redis'],{'host':_0x834e('0x1f'),'port':0x18eb});var socket=require(_0x834e('0x20'))(new Redis(config[_0x834e('0x1d')]));require(_0x834e('0x21'))['register'](socket);function respondWithStatusCode(_0x43156c,_0x302cbd){_0x302cbd=_0x302cbd||0xcc;return function(_0x57274a){if(_0x57274a){return _0x43156c[_0x834e('0x22')](_0x302cbd);}return _0x43156c['status'](_0x302cbd)[_0x834e('0x23')]();};}function respondWithResult(_0x36d443,_0x478afe){_0x478afe=_0x478afe||0xc8;return function(_0x43ac41){if(_0x43ac41){return _0x36d443[_0x834e('0x24')](_0x478afe)[_0x834e('0x25')](_0x43ac41);}};}function respondWithFilteredResult(_0x50b3f6,_0x283e56){return function(_0x211e9a){if(_0x211e9a){var _0x34e41a=_0x211e9a[_0x834e('0x26')],_0xb993a1=_0x283e56['offset'],_0x237947=_0x283e56[_0x834e('0x27')]+_0x283e56[_0x834e('0x28')],_0x254677;if(_0x237947>=_0x34e41a){_0x237947=_0x34e41a;_0x254677=0xc8;}else{_0x254677=0xce;}_0x50b3f6[_0x834e('0x24')](_0x254677);return _0x50b3f6[_0x834e('0x29')]('Content-Range',_0xb993a1+'-'+_0x237947+'/'+_0x34e41a)[_0x834e('0x25')](_0x211e9a);}return null;};}function patchUpdates(_0x62f8f1){return function(_0x5a05c0){try{jsonpatch[_0x834e('0x2a')](_0x5a05c0,_0x62f8f1,!![]);}catch(_0x28d687){return BPromise[_0x834e('0x2b')](_0x28d687);}return _0x5a05c0['save']();};}function saveUpdates(_0x4e3f48,_0x231619){return function(_0x34563b){if(_0x34563b){return _0x34563b['update'](_0x4e3f48)[_0x834e('0x2c')](function(_0x1dc1e0){return _0x1dc1e0;});}return null;};}function removeEntity(_0x58f4fd,_0x3bc4f7){return function(_0x2e1983){if(_0x2e1983){return _0x2e1983[_0x834e('0x2d')]()['then'](function(){_0x58f4fd[_0x834e('0x24')](0xcc)[_0x834e('0x23')]();});}};}function handleEntityNotFound(_0x5e1cc5,_0x5bef62){return function(_0x1e713a){if(!_0x1e713a){_0x5e1cc5['sendStatus'](0x194);}return _0x1e713a;};}function handleError(_0x2826ec,_0x3f1b0b){_0x3f1b0b=_0x3f1b0b||0x1f4;return function(_0x3db026){logger[_0x834e('0x2e')](_0x3db026[_0x834e('0x2f')]);if(_0x3db026[_0x834e('0x30')]){delete _0x3db026['name'];}_0x2826ec['status'](_0x3f1b0b)['send'](_0x3db026);};}exports['index']=function(_0x2c7a8d,_0x567cea){var _0x106d6a={},_0x5dacc1={},_0xb5bc06={'count':0x0,'rows':[]};return db[_0x834e('0x31')][_0x834e('0x32')]()[_0x834e('0x2c')](function(_0x4551f5){var _0x390119=[];for(var _0x3d149d=0x0;_0x3d149d<Object[_0x834e('0x33')](_0x4551f5)[_0x834e('0x34')];_0x3d149d++){var _0x493289=Object[_0x834e('0x33')](_0x4551f5)[_0x3d149d];if(_['startsWith'](_0x493289,_0x834e('0x35'))){_0x390119[_0x834e('0x36')](db[_0x834e('0x37')][_0x834e('0x38')]({'where':{'id':_[_0x834e('0x39')](_0x493289,_0x834e('0x35'))},'raw':!![]}));}}return BPromise[_0x834e('0x3a')](_0x390119)[_0x834e('0x2c')](function(_0x358c31){for(var _0x12b2bc=0x0;_0x12b2bc<_0x358c31['length'];_0x12b2bc++){if(_0x358c31[_0x12b2bc]){var _0x2a3c7f=_0x834e('0x35')+_0x358c31[_0x12b2bc]['id'];var _0x24a9df=_0x4551f5[_0x2a3c7f];_0x24a9df[_0x834e('0x3b')]=_0x358c31[_0x12b2bc]['type'];}}return _0x4551f5;});})[_0x834e('0x2c')](function(_0x379d60){_0x5dacc1['model']=_['keys'](_0x379d60);_0x5dacc1['query']=_[_0x834e('0x33')](_0x2c7a8d[_0x834e('0x3c')]);_0x5dacc1[_0x834e('0x3d')]=_[_0x834e('0x3e')](_0x5dacc1[_0x834e('0x3f')],_0x5dacc1[_0x834e('0x3c')]);_0x106d6a['attributes']=_[_0x834e('0x3e')](_0x5dacc1['model'],qs[_0x834e('0x40')](_0x2c7a8d[_0x834e('0x3c')]['fields']));_0x106d6a[_0x834e('0x41')]=_0x106d6a[_0x834e('0x41')]['length']?_0x106d6a['attributes']:_0x5dacc1[_0x834e('0x3f')];if(!_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x42')](_0x834e('0x43'))){_0x106d6a[_0x834e('0x28')]=qs['limit'](_0x2c7a8d[_0x834e('0x3c')]['limit']);_0x106d6a['offset']=qs[_0x834e('0x27')](_0x2c7a8d['query'][_0x834e('0x27')]);}_0x106d6a[_0x834e('0x44')]=qs[_0x834e('0x45')](_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x45')]);_0x106d6a['where']=qs[_0x834e('0x3d')](_[_0x834e('0x46')](_0x2c7a8d[_0x834e('0x3c')],_0x5dacc1['filters']),_0x379d60);var _0x35380e=[];var _0x16ac45=squel['select']()[_0x834e('0x47')]('id')['field'](_0x834e('0x30'))[_0x834e('0x47')]('color')['from'](_0x834e('0x48'));var _0x16969b=squel[_0x834e('0x49')]()[_0x834e('0x4a')](_0x834e('0x4b'),'c')[_0x834e('0x4c')](_0x834e('0x4d'),'uc','uc.CmContactId\x20=\x20c.id')[_0x834e('0x4c')]('cm_contact_has_tags','ct',_0x834e('0x4e'))['left_join'](_0x834e('0x48'),'t','t.id\x20=\x20ct.TagId')[_0x834e('0x4f')](_0x834e('0x50'));var _0x51c731=squel[_0x834e('0x51')]();var _0x3f2321=[];var _0xa880cb=squel[_0x834e('0x51')]();var _0x252ea0;if(_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x52')]){_0x252ea0=as[_0x834e('0x53')](_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x52')]);var _0x5f3943=_0x252ea0[_0x834e('0x54')];for(var _0x6fff27=0x0;_0x6fff27<_0x252ea0['conditions'][_0x834e('0x34')];_0x6fff27++){var _0x42fd90=_0x252ea0[_0x834e('0x55')][_0x6fff27];var _0x2112d5='c';var _0x19b5ef=_(_0x379d60)[_0x834e('0x33')]()['find'](function(_0x59c855){return _0x59c855===_0x42fd90[_0x834e('0x47')];});if(_0x19b5ef)_0x19b5ef=_0x379d60[_0x42fd90[_0x834e('0x47')]];if(!_0x19b5ef){if(_0x42fd90[_0x834e('0x47')]===_0x834e('0x56')){var _0x3da408=_0x42fd90[_0x834e('0x57')][_0x834e('0x58')](',')[_0x834e('0x59')](function(_0x1419eb){return Number(_0x1419eb);});_0x3da408[_0x834e('0x5a')](function(_0xf02f0d){_0xa880cb['or'](_0x834e('0x5b'),'%,'+_0xf02f0d+',%');});_0x3f2321=_[_0x834e('0x5c')](_0x3f2321,_0x3da408);}else if(_0x42fd90[_0x834e('0x47')]===_0x834e('0x5d')){_0x51c731[_0x834e('0x5e')](_0x834e('0x5f'),_0x42fd90[_0x834e('0x57')]);}}else{if(_0x42fd90[_0x834e('0x47')]===_0x834e('0x60')||_0x19b5ef['fieldType']===_0x834e('0x61'))_0x42fd90[_0x834e('0x62')]='DATE';var _0x3c00a3=as[_0x834e('0x63')](_0x2112d5,_0x19b5ef['type'],_0x42fd90);_0x51c731[_0x5f3943](_0x3c00a3[_0x834e('0x64')],_0x3c00a3[_0x834e('0x57')][_0x834e('0x65')],_0x3c00a3[_0x834e('0x57')][_0x834e('0x23')]);}}}else{var _0xb77aab=_(Object[_0x834e('0x33')](_0x2c7a8d['query']))[_0x834e('0x59')](function(_0x8bc6c6){return _0x379d60[_0x834e('0x42')](_0x8bc6c6)?_0x8bc6c6:undefined;})[_0x834e('0x66')](function(_0x86ad2b){return!_[_0x834e('0x67')](_0x86ad2b);})[_0x834e('0x57')]();if(_0x2c7a8d[_0x834e('0x3c')]['Contact'])_0xb77aab[_0x834e('0x36')]('Contact');if(!_[_0x834e('0x68')](_0xb77aab)){_0xb77aab['forEach'](function(_0x35b6b8){if(_0x35b6b8==='ListId'){_0x16969b['where'](_0x834e('0x69'),[][_0x834e('0x6a')](_0x2c7a8d['query'][_0x35b6b8]));}else if(_0x35b6b8==='Contact'){var _0x2c8155='%'+_0x2c7a8d[_0x834e('0x3c')][_0x35b6b8]+'%';_0x16969b[_0x834e('0x4f')](_0x834e('0x6b'),_0x2c8155);}else{_0x16969b[_0x834e('0x4f')]('c.'+_0x35b6b8+_0x834e('0x6c'),_0x2c7a8d[_0x834e('0x3c')][_0x35b6b8]);}});}if(_0x2c7a8d[_0x834e('0x3c')]['tag']){_0x3f2321=_[_0x834e('0x6d')](_0x2c7a8d[_0x834e('0x3c')]['tag'])?_0x2c7a8d[_0x834e('0x3c')]['tag']:new Array(_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x6e')]);_0x3f2321['forEach'](function(_0x41ef86){_0xa880cb['or'](_0x834e('0x5b'),'%,'+_0x41ef86+',%');});}if(_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x66')]){var _0x5a2924=_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x66')][_0x834e('0x6f')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(_0x5a2924[_0x834e('0x58')]('\x20')[_0x834e('0x34')]>0x1){_0x51c731['or'](_0x834e('0x70'),qs[_0x834e('0x71')](_0x5a2924),null);}else{if(qs[_0x834e('0x72')](_0x5a2924)){_0x51c731['or'](_0x834e('0x73'),_0x5a2924+'%');_0x51c731['or'](_0x834e('0x74'),_0x5a2924+'%');_0x51c731['or'](_0x834e('0x75'),_0x5a2924+'%');_0x51c731['or'](_0x834e('0x76'),_0x5a2924+'%');}else if(qs[_0x834e('0x77')](_0x5a2924)){_0x51c731['or'](_0x834e('0x78'),_0x5a2924+'%');}else{_0x51c731['or'](_0x834e('0x79'),'%'+_0x5a2924+'%');_0x51c731['or'](_0x834e('0x7a'),'%'+_0x5a2924+'%');_0x51c731['or'](_0x834e('0x78'),'%'+_0x5a2924+'%');}}}}_0x16969b[_0x834e('0x4f')](_0x51c731);_0x16969b[_0x834e('0x7b')](_0x834e('0x7c'));var _0x14ed83={'type':db[_0x834e('0x7d')][_0x834e('0x7e')][_0x834e('0x7f')],'raw':!![]};var _0x2cb233=_0x16969b['clone']()[_0x834e('0x47')](_0x834e('0x7c'));if(_0x106d6a[_0x834e('0x44')]){_0x106d6a[_0x834e('0x44')]['forEach'](function(_0x30faa8){_0x16969b['order']('c.'+_0x30faa8[0x0],_0x30faa8[0x1]==='DESC'?![]:!![]);});}if(!_[_0x834e('0x68')](_0x3f2321)){_0x16969b[_0x834e('0x80')](_0xa880cb);_0x2cb233[_0x834e('0x4f')](_0x834e('0x81'),_0x3f2321);}BPromise[_0x834e('0x82')]()[_0x834e('0x2c')](function(){if(!_0x252ea0)return;if(_0x2c7a8d[_0x834e('0x83')][_0x834e('0x84')]!=='agent')return;if(!_[_0x834e('0x85')](_0x252ea0['conditions'],[_0x834e('0x47'),_0x834e('0x5d')])){return _0x2c7a8d['user']['getLists']({'attributes':['id'],'raw':!![]})[_0x834e('0x2c')](function(_0x82f2a7){if(_[_0x834e('0x68')](_0x82f2a7)){_0x2cb233[_0x834e('0x4f')](_0x834e('0x86'));_0x16969b['where'](_0x834e('0x86'));}else{_0x2cb233[_0x834e('0x4f')](_0x834e('0x69'),_[_0x834e('0x59')](_0x82f2a7,'id'));_0x16969b[_0x834e('0x4f')](_0x834e('0x69'),_[_0x834e('0x59')](_0x82f2a7,'id'));}});}})[_0x834e('0x2c')](function(){if(_0x2c7a8d[_0x834e('0x83')][_0x834e('0x84')]==='agent'&&!_0x252ea0&&!_0x2c7a8d[_0x834e('0x3c')][_0x834e('0x87')])return[];return db[_0x834e('0x88')][_0x834e('0x3c')](_0x2cb233['toString'](),_0x14ed83);})[_0x834e('0x2c')](function(_0x4ac5f2){_0xb5bc06['count']=_0x4ac5f2['length'];if(_0xb5bc06[_0x834e('0x26')]===0x0)return[];return db[_0x834e('0x88')]['query'](_0x16ac45[_0x834e('0x89')](),_0x14ed83)[_0x834e('0x2c')](function(_0x4d4477){_0x35380e=_[_0x834e('0x8a')](_0x4d4477,'id');_0x14ed83=_[_0x834e('0x8b')](_0x14ed83,{'model':db['CmContact'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x2c7a8d['query'][_0x834e('0x40')]){_0x106d6a[_0x834e('0x41')][_0x834e('0x5a')](function(_0x44c909){_0x16969b[_0x834e('0x47')]('c.'+_0x44c909);});}else{_0x16969b['field'](_0x834e('0x7c'));_0x16969b['field'](_0x834e('0x8c'));_0x16969b[_0x834e('0x47')](_0x834e('0x8d'));_0x16969b['field'](_0x834e('0x8e'));_0x16969b[_0x834e('0x47')]('c.mobile');_0x16969b[_0x834e('0x47')](_0x834e('0x8f'));_0x16969b[_0x834e('0x47')]('c.email');_0x16969b[_0x834e('0x47')](_0x834e('0x90'));_0x16969b[_0x834e('0x47')](_0x834e('0x91'));_0x16969b[_0x834e('0x47')](_0x834e('0x92'));_0x16969b[_0x834e('0x47')](_0x834e('0x93'));_0x16969b[_0x834e('0x47')](_0x834e('0x94'),'TagIds');}if(_0x106d6a['limit'])_0x16969b['limit'](_0x106d6a[_0x834e('0x28')]);if(_0x106d6a[_0x834e('0x27')])_0x16969b[_0x834e('0x27')](_0x106d6a[_0x834e('0x27')]);return db[_0x834e('0x88')]['query'](_0x16969b['toString'](),_0x14ed83);});})[_0x834e('0x2c')](function(_0x1ad428){_0x1ad428[_0x834e('0x5a')](function(_0x18ddac){if(_0x18ddac[_0x834e('0x95')]){_0x18ddac['Tags']=[];_0x18ddac[_0x834e('0x95')][_0x834e('0x58')](',')[_0x834e('0x5a')](function(_0x4e1735){_0x18ddac[_0x834e('0x96')][_0x834e('0x36')](_0x35380e[_0x4e1735]);});}delete _0x18ddac[_0x834e('0x95')];});_0xb5bc06[_0x834e('0x97')]=_0x1ad428;return _0xb5bc06;})[_0x834e('0x2c')](respondWithFilteredResult(_0x567cea,_0x106d6a));})['catch'](handleError(_0x567cea,null));};exports['destroy']=function(_0x227797,_0x40a872){return db['CmContact'][_0x834e('0x98')]({'where':{'id':_0x227797['params']['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x40a872,null))[_0x834e('0x2c')](removeEntity(_0x40a872,null))[_0x834e('0x99')](handleError(_0x40a872,null));};exports['describe']=function(_0x155c0f,_0x49e721){return db['CmContact']['describe']()[_0x834e('0x2c')](function(_0x4627ac){delete _0x4627ac[_0x834e('0x9a')];for(var _0x1d76c6=0x0;_0x1d76c6<Object[_0x834e('0x33')](_0x4627ac)[_0x834e('0x34')];_0x1d76c6++){var _0x3aa388=Object[_0x834e('0x33')](_0x4627ac)[_0x1d76c6];if(!_[_0x834e('0x9b')](_0x3aa388,'cf_')){_0x4627ac[_0x3aa388][_0x834e('0x9c')]=_0x3aa388;_0x4627ac[_0x3aa388]['displayName']=_0x3aa388;}}return _0x4627ac;})[_0x834e('0x2c')](function(_0x97c1a6){var _0x38bfa4={'where':{'$or':[{'ListId':_0x155c0f[_0x834e('0x3c')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x834e('0x37')][_0x834e('0x9d')](_0x38bfa4)['then'](function(_0x56d0f8){for(var _0xeb096d=0x0;_0xeb096d<_0x56d0f8[_0x834e('0x34')];_0xeb096d++){var _0x4eff8d=_0x834e('0x35')+_0x56d0f8[_0xeb096d]['id'];_0x97c1a6[_0x4eff8d][_0x834e('0x9c')]=_0x4eff8d;_0x97c1a6[_0x4eff8d][_0x834e('0x9e')]=_0x56d0f8[_0xeb096d][_0x834e('0x9f')];_0x97c1a6[_0x4eff8d][_0x834e('0xa0')]={'type':_0x56d0f8[_0xeb096d]['type'],'values':_0x56d0f8[_0xeb096d][_0x834e('0xa1')]};}Object[_0x834e('0x33')](_0x97c1a6)['forEach'](function(_0x54178d){if(!_0x97c1a6[_0x54178d]['hasOwnProperty'](_0x834e('0x9c'))){delete _0x97c1a6[_0x54178d];}});return _0x97c1a6;});})[_0x834e('0x2c')](respondWithResult(_0x49e721,null))['catch'](handleError(_0x49e721,null));};exports[_0x834e('0x8b')]=function(_0x1f053f,_0x49b480){var _0xfb93b1;var _0x49eed7;var _0x4813a8;if(_0x1f053f[_0x834e('0xa2')]['id']){delete _0x1f053f[_0x834e('0xa2')]['id'];}return db[_0x834e('0x31')][_0x834e('0x9d')]({'where':{'id':[_0x1f053f['body']['to'],_0x1f053f[_0x834e('0xa2')][_0x834e('0x4a')]]}})[_0x834e('0x2c')](function(_0x1b0b41){if(_0x1b0b41){if(_0x1b0b41[_0x834e('0x34')]!==0x2){return null;}_0x1b0b41[0x0]=_0x1b0b41[0x0][_0x834e('0xa3')]({'plain':!![]});_0x1b0b41[0x1]=_0x1b0b41[0x1][_0x834e('0xa3')]({'plain':!![]});delete _0x1b0b41[0x0]['id'];delete _0x1b0b41[0x1]['id'];return _[_0x834e('0xa4')](_0x1b0b41[0x0],_0x1b0b41[0x1],function(_0x13c5a4,_0x2821fe){if(Array[_0x834e('0x6d')](_0x2821fe)&&!_0x2821fe[_0x834e('0x34')]){return _0x13c5a4;}else if(!_0x2821fe){return _0x13c5a4;}});}})[_0x834e('0x2c')](handleEntityNotFound(_0x49b480,null))[_0x834e('0x2c')](function(_0x37ae42){if(_0x37ae42){if(_0x37ae42[_0x834e('0x9a')]&&_[_0x834e('0x6d')](_0x37ae42[_0x834e('0x9a')])){_0x37ae42[_0x834e('0x9a')]=_0x37ae42[_0x834e('0x9a')][_0x834e('0xa5')]();}logger[_0x834e('0xa6')]('[CmContact][merge]\x20to\x20%s\x20from\x20%s',_0x1f053f[_0x834e('0xa2')]['to'],_0x1f053f[_0x834e('0xa2')][_0x834e('0x4a')]);return db[_0x834e('0xa7')][_0x834e('0x2d')]({'where':{'ContactId':[_0x1f053f[_0x834e('0xa2')]['to'],_0x1f053f[_0x834e('0xa2')][_0x834e('0x4a')]]}})[_0x834e('0x2c')](function(_0x4d226b){logger['info']('[CmContact][merge][destroy][CmHopper],\x20%s',_0x4d226b);return db[_0x834e('0xa8')]['destroy']({'where':{'ContactId':[_0x1f053f[_0x834e('0xa2')]['to'],_0x1f053f[_0x834e('0xa2')][_0x834e('0x4a')]]}})['then'](function(_0xae00f){logger[_0x834e('0xa6')](_0x834e('0xa9'),_0xae00f);return db[_0x834e('0x31')][_0x834e('0xaa')](_0x37ae42);});});}})[_0x834e('0x2c')](function(_0x528052){if(_0x528052){_0xfb93b1=_0x528052;_0x49eed7={'ContactId':_0xfb93b1['id']};_0x4813a8={'where':{'ContactId':[_0x1f053f[_0x834e('0xa2')]['to'],_0x1f053f[_0x834e('0xa2')][_0x834e('0x4a')]]}};return db[_0x834e('0xab')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db['ChatMessage']['update'](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xad')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xae')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xaf')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xae')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db['MailMessage']['update'](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xb0')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xb1')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xb2')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xb3')]['update'](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db['OpenchannelInteraction']['update'](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xb4')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xb5')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db['CmHopperHistory'][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xb6')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xb7')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xb8')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0xb9')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xba')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xbb')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xbc')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return db[_0x834e('0xbd')][_0x834e('0xac')](_0x49eed7,_0x4813a8);}})['then'](function(){if(_0xfb93b1){return db[_0x834e('0x31')][_0x834e('0x2d')]({'where':{'id':[_0x1f053f['body']['to'],_0x1f053f[_0x834e('0xa2')]['from']]}});}})[_0x834e('0x2c')](function(){if(_0xfb93b1){return _0xfb93b1;}})['then'](respondWithResult(_0x49b480,null))[_0x834e('0x99')](handleError(_0x49b480,null));};exports['create']=function(_0x2b6d1,_0x14ba55){return db[_0x834e('0x31')][_0x834e('0x32')]()['then'](function(_0x3d4608){if(_0x2b6d1[_0x834e('0xa2')][_0x834e('0x9a')]&&_[_0x834e('0x6d')](_0x2b6d1[_0x834e('0xa2')][_0x834e('0x9a')])){if(_0x2b6d1[_0x834e('0xa2')][_0x834e('0x9a')][_0x834e('0x34')]){_0x2b6d1[_0x834e('0xa2')][_0x834e('0x9a')]=_0x2b6d1[_0x834e('0xa2')][_0x834e('0x9a')][_0x834e('0xa5')](';')+';';}else{_0x2b6d1[_0x834e('0xa2')][_0x834e('0x9a')]=null;}}else{_0x2b6d1[_0x834e('0xa2')]['tags']=null;}return db['CmContact'][_0x834e('0xaa')](_0x2b6d1[_0x834e('0xa2')],{'fields':_[_0x834e('0x33')](_0x3d4608),'raw':!![]});})[_0x834e('0x2c')](respondWithResult(_0x14ba55,0xc9))[_0x834e('0x99')](handleError(_0x14ba55,null));};exports[_0x834e('0xbe')]=function(_0x22f90d,_0x40fd40){var _0x3ef7af=[];var _0x58cd3b=0x0;var _0x25f1f9=0x0;var _0x32645e=0x0;return db['CmContact'][_0x834e('0x32')]()['then'](function(_0x2fdb72){return BPromise[_0x834e('0xbf')](_0x22f90d[_0x834e('0xa2')],function(_0x557373){var _0x1a65b4={'where':{'$or':[]},'defaults':_0x557373,'fields':_[_0x834e('0x33')](_0x2fdb72),'raw':!![]};if(_0x557373['duplicates']){for(var _0x4f7c62=0x0;_0x4f7c62<_0x557373[_0x834e('0xc0')][_0x834e('0x34')];_0x4f7c62++){var _0x4e0f4d={};_0x4e0f4d[_0x557373[_0x834e('0xc0')][_0x4f7c62]]=_0x557373[_0x557373[_0x834e('0xc0')][_0x4f7c62]];_0x1a65b4[_0x834e('0x4f')][_0x834e('0xc1')][_0x834e('0x36')](_0x4e0f4d);}_0x1a65b4['where']['ListId']=_0x557373[_0x834e('0x87')];}return db['CmContact']['findOrCreate'](_0x1a65b4)['spread'](function(_0xac9d00,_0x3634f7){if(_0x3634f7){_0x58cd3b++;}else{_0x32645e++;}})['catch'](function(_0x1caf92){console[_0x834e('0x2e')](_0x1caf92);_0x25f1f9++;});});})[_0x834e('0x2c')](function(_0x43e44a){if(_0x43e44a){return{'success':_0x58cd3b,'failure':_0x25f1f9,'duplicates':_0x32645e};}})['then'](respondWithResult(_0x40fd40,0xc9))[_0x834e('0x99')](handleError(_0x40fd40,null));};exports[_0x834e('0xc2')]=function(_0x117196,_0x5633f4,_0x3d8af7){var _0x5f3b7d;return db[_0x834e('0x31')]['describe']()[_0x834e('0x2c')](function(_0x108100){return db['CmContact'][_0x834e('0x98')]({'where':{'id':_0x117196[_0x834e('0xc3')]['id']},'include':[{'model':db[_0x834e('0x56')],'as':_0x834e('0x96'),'attributes':['id',_0x834e('0x30'),_0x834e('0xc4')],'required':_0x117196['query'][_0x834e('0x6e')]?!![]:![]}],'attributes':_[_0x834e('0x33')](_0x108100)});})[_0x834e('0x2c')](function(_0x29dce9){_0x5f3b7d=_0x29dce9[_0x834e('0xa3')]({'plain':!![]});var _0x1b8e67={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x29dce9&&_0x29dce9['ListId']){if(_0x29dce9[_0x834e('0x87')]){_0x1b8e67['where']['$and'][_0x834e('0x36')]({'ListId':{'$ne':_0x29dce9['ListId']}});}}return db['CmCustomField'][_0x834e('0x9d')](_0x1b8e67);})[_0x834e('0x2c')](function(_0x257fed){return _[_0x834e('0xc5')](_0x5f3b7d,_[_0x834e('0x59')](_0x257fed,function(_0x3e0ee6){return util[_0x834e('0xc6')](_0x834e('0xc7'),_0x3e0ee6['id']);}));})[_0x834e('0x2c')](handleEntityNotFound(_0x5633f4,null))[_0x834e('0x2c')](respondWithResult(_0x5633f4,null))[_0x834e('0x99')](handleError(_0x5633f4,null));};exports[_0x834e('0xac')]=function(_0x1fb379,_0x34df10){var _0x4b54ec;if(_0x1fb379[_0x834e('0xa2')]['id']){delete _0x1fb379['body']['id'];}return db[_0x834e('0x31')][_0x834e('0x98')]({'where':{'id':_0x1fb379[_0x834e('0xc3')]['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x34df10,null))['then'](saveUpdates(_0x1fb379['body'],null))[_0x834e('0x2c')](function(_0x376203){_0x4b54ec=_0x376203;var _0x5d8466={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x376203&&_0x376203[_0x834e('0x87')]){if(_0x376203[_0x834e('0x87')]){_0x5d8466['where'][_0x834e('0xc8')][_0x834e('0x36')]({'ListId':{'$ne':_0x376203[_0x834e('0x87')]}});}}return db[_0x834e('0x37')]['findAll'](_0x5d8466);})['then'](function(_0x4ead1d){if(_0x4ead1d){return _['omit'](_[_0x834e('0xc9')](_0x1fb379[_0x834e('0xa2')],function(_0x47891e,_0x41ba0c){return _['startsWith'](_0x41ba0c,_0x834e('0x35'));}),_[_0x834e('0x59')](_0x4ead1d,function(_0x343a59){return util[_0x834e('0xc6')](_0x834e('0xc7'),_0x343a59['id']);}));}})[_0x834e('0x2c')](function(_0x3c775f){if(_0x3c775f&&!_['isEmpty'](_0x3c775f)){var _0x12a0f3=squel[_0x834e('0xac')]()['table'](_0x834e('0x4b'))[_0x834e('0xca')](_0x3c775f)['where']('id\x20=\x20?',_0x1fb379['params']['id'])[_0x834e('0xcb')]();return db[_0x834e('0x88')][_0x834e('0x3c')](_0x12a0f3['text'],{'replacements':_0x12a0f3[_0x834e('0xa1')]});}})[_0x834e('0x2c')](function(){if(_0x1fb379[_0x834e('0xa2')][_0x834e('0xcc')]&&_0x4b54ec){return db[_0x834e('0xa7')][_0x834e('0xac')]({'phone':_0x1fb379[_0x834e('0xa2')][_0x834e('0xcc')]},{'where':{'ContactId':_0x4b54ec['id']}});}})[_0x834e('0x2c')](function(){return _0x4b54ec;})[_0x834e('0x2c')](respondWithResult(_0x34df10,null))['catch'](handleError(_0x34df10,null));};exports['getTags']=function(_0x117e8f,_0x290a7b,_0xbc7704){var _0x3eda93={};var _0x4303a6={};var _0xd22e8f;var _0x281922;return db[_0x834e('0x31')][_0x834e('0x38')]({'where':{'id':_0x117e8f[_0x834e('0xc3')]['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x290a7b,null))[_0x834e('0x2c')](function(_0x13b354){if(_0x13b354){_0xd22e8f=_0x13b354;_0x4303a6['model']=_[_0x834e('0x33')](db[_0x834e('0x56')][_0x834e('0xcd')]);_0x4303a6[_0x834e('0x3c')]=_['keys'](_0x117e8f['query']);_0x4303a6['filters']=_[_0x834e('0x3e')](_0x4303a6[_0x834e('0x3f')],_0x4303a6[_0x834e('0x3c')]);_0x3eda93[_0x834e('0x41')]=_[_0x834e('0x3e')](_0x4303a6[_0x834e('0x3f')],qs[_0x834e('0x40')](_0x117e8f[_0x834e('0x3c')]['fields']));_0x3eda93['attributes']=_0x3eda93['attributes']['length']?_0x3eda93[_0x834e('0x41')]:_0x4303a6[_0x834e('0x3f')];_0x3eda93[_0x834e('0x44')]=qs[_0x834e('0x45')](_0x117e8f[_0x834e('0x3c')][_0x834e('0x45')]);_0x3eda93[_0x834e('0x4f')]=qs[_0x834e('0x3d')](_[_0x834e('0x46')](_0x117e8f['query'],_0x4303a6['filters']));if(_0x117e8f['query']['filter']){_0x3eda93[_0x834e('0x4f')]=_[_0x834e('0x8b')](_0x3eda93[_0x834e('0x4f')],{'$or':_[_0x834e('0x59')](_0x3eda93[_0x834e('0x41')],function(_0xcb9751){var _0x416bea={};_0x416bea[_0xcb9751]={'$like':'%'+_0x117e8f[_0x834e('0x3c')][_0x834e('0x66')]+'%'};return _0x416bea;})});}_0x3eda93=_[_0x834e('0x8b')]({},_0x3eda93,_0x117e8f[_0x834e('0xce')]);return _0xd22e8f[_0x834e('0xcf')](_0x3eda93);}})[_0x834e('0x2c')](function(_0x2222d6){if(_0x2222d6){_0x281922=_0x2222d6[_0x834e('0x34')];if(!_0x117e8f[_0x834e('0x3c')]['hasOwnProperty'](_0x834e('0x43'))){_0x3eda93['limit']=qs[_0x834e('0x28')](_0x117e8f[_0x834e('0x3c')][_0x834e('0x28')]);_0x3eda93['offset']=qs[_0x834e('0x27')](_0x117e8f[_0x834e('0x3c')]['offset']);}return _0xd22e8f['getTags'](_0x3eda93);}})[_0x834e('0x2c')](function(_0xdf6824){if(_0xdf6824){return _0xdf6824?{'count':_0x281922,'rows':_0xdf6824}:null;}})[_0x834e('0x2c')](respondWithResult(_0x290a7b,null))[_0x834e('0x99')](handleError(_0x290a7b,null));};exports[_0x834e('0xd0')]=function(_0x2e9116,_0x3eb2e8,_0x239a4e){if(_0x2e9116['body']['id']){delete _0x2e9116[_0x834e('0xa2')]['id'];}return db[_0x834e('0x31')][_0x834e('0x38')]({'where':{'id':_0x2e9116[_0x834e('0xc3')]['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x3eb2e8,null))[_0x834e('0x2c')](function(_0x17aaae){if(_0x17aaae){return _0x17aaae['setTags'](_0x2e9116[_0x834e('0xa2')]['ids']||[]);}return null;})['then'](respondWithResult(_0x3eb2e8,null))[_0x834e('0x99')](handleError(_0x3eb2e8,null));};exports[_0x834e('0xd1')]=function(_0x4b16fa,_0x3ce91b,_0x310356){var _0x52b95c={'raw':![],'where':{}};var _0x29952f={};var _0x418da2={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x4b16fa[_0x834e('0xc3')]['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x3ce91b,null))['then'](function(_0x58a935){if(_0x58a935){_0x29952f[_0x834e('0x3f')]=_[_0x834e('0x33')](db['CmHopper']['rawAttributes']);_0x29952f['query']=_['keys'](_0x4b16fa[_0x834e('0x3c')]);_0x29952f['filters']=_[_0x834e('0x3e')](_0x29952f['model'],_0x29952f[_0x834e('0x3c')]);_0x52b95c[_0x834e('0x41')]=_[_0x834e('0x3e')](_0x29952f[_0x834e('0x3f')],qs['fields'](_0x4b16fa[_0x834e('0x3c')][_0x834e('0x40')]));_0x52b95c[_0x834e('0x41')]=_0x52b95c[_0x834e('0x41')][_0x834e('0x34')]?_0x52b95c[_0x834e('0x41')]:_0x29952f[_0x834e('0x3f')];if(!_0x4b16fa[_0x834e('0x3c')][_0x834e('0x42')](_0x834e('0x43'))){_0x52b95c['limit']=qs[_0x834e('0x28')](_0x4b16fa['query'][_0x834e('0x28')]);_0x52b95c[_0x834e('0x27')]=qs[_0x834e('0x27')](_0x4b16fa[_0x834e('0x3c')][_0x834e('0x27')]);}_0x52b95c['order']=qs[_0x834e('0x45')](_0x4b16fa['query']['sort']);_0x52b95c[_0x834e('0x4f')]=qs[_0x834e('0x3d')](_[_0x834e('0x46')](_0x4b16fa['query'],_0x29952f[_0x834e('0x3d')]));_0x52b95c[_0x834e('0x4f')][_0x834e('0xd2')]=_0x58a935['id'];if(_0x4b16fa[_0x834e('0x3c')][_0x834e('0x66')]){_0x52b95c[_0x834e('0x4f')]=_[_0x834e('0x8b')](_0x52b95c[_0x834e('0x4f')],{'$or':_[_0x834e('0x59')](_0x52b95c[_0x834e('0x41')],function(_0x21d7d8){var _0x578204={};_0x578204[_0x21d7d8]={'$like':'%'+_0x4b16fa[_0x834e('0x3c')][_0x834e('0x66')]+'%'};return _0x578204;})});}_0x52b95c=_[_0x834e('0x8b')]({},_0x52b95c,_0x4b16fa[_0x834e('0xce')]);return db[_0x834e('0xa7')][_0x834e('0x26')]({'where':_0x52b95c['where']})[_0x834e('0x2c')](function(_0x18629c){_0x418da2[_0x834e('0x26')]=_0x18629c;if(_0x4b16fa[_0x834e('0x3c')][_0x834e('0xd3')]){_0x52b95c[_0x834e('0xd4')]=[{'all':!![]}];}return db[_0x834e('0xa7')][_0x834e('0x9d')](_0x52b95c);})[_0x834e('0x2c')](function(_0x1766b9){_0x418da2['rows']=_0x1766b9;return _0x418da2;});}})['then'](respondWithFilteredResult(_0x3ce91b,_0x52b95c))[_0x834e('0x99')](handleError(_0x3ce91b,null));};exports['getHopperHistories']=function(_0x4094d5,_0x449530,_0x1a79e0){var _0x198f0e={'raw':!![],'where':{}};var _0x1daa58={};var _0x1d53c6={'count':0x0,'rows':[]};return db['CmContact'][_0x834e('0x38')]({'where':{'id':_0x4094d5['params']['id']}})['then'](handleEntityNotFound(_0x449530,null))['then'](function(_0x137fdd){if(_0x137fdd){_0x1daa58[_0x834e('0x3f')]=_['keys'](db['CmHopperHistory']['rawAttributes']);_0x1daa58[_0x834e('0x3c')]=_[_0x834e('0x33')](_0x4094d5[_0x834e('0x3c')]);_0x1daa58['filters']=_[_0x834e('0x3e')](_0x1daa58[_0x834e('0x3f')],_0x1daa58[_0x834e('0x3c')]);_0x198f0e[_0x834e('0x41')]=_[_0x834e('0x3e')](_0x1daa58[_0x834e('0x3f')],qs['fields'](_0x4094d5['query']['fields']));_0x198f0e['attributes']=_0x198f0e[_0x834e('0x41')][_0x834e('0x34')]?_0x198f0e[_0x834e('0x41')]:_0x1daa58[_0x834e('0x3f')];if(!_0x4094d5[_0x834e('0x3c')][_0x834e('0x42')](_0x834e('0x43'))){_0x198f0e[_0x834e('0x28')]=qs[_0x834e('0x28')](_0x4094d5[_0x834e('0x3c')][_0x834e('0x28')]);_0x198f0e[_0x834e('0x27')]=qs[_0x834e('0x27')](_0x4094d5[_0x834e('0x3c')][_0x834e('0x27')]);}_0x198f0e['order']=qs['sort'](_0x4094d5[_0x834e('0x3c')][_0x834e('0x45')]);_0x198f0e[_0x834e('0x4f')]=qs['filters'](_[_0x834e('0x46')](_0x4094d5[_0x834e('0x3c')],_0x1daa58[_0x834e('0x3d')]));_0x198f0e[_0x834e('0x4f')][_0x834e('0xd2')]=_0x137fdd['id'];if(_0x4094d5[_0x834e('0x3c')][_0x834e('0x66')]){_0x198f0e[_0x834e('0x4f')]=_[_0x834e('0x8b')](_0x198f0e['where'],{'$or':_[_0x834e('0x59')](_0x198f0e[_0x834e('0x41')],function(_0x3b4691){var _0x2f1de8={};_0x2f1de8[_0x3b4691]={'$like':'%'+_0x4094d5['query'][_0x834e('0x66')]+'%'};return _0x2f1de8;})});}_0x198f0e=_[_0x834e('0x8b')]({},_0x198f0e,_0x4094d5[_0x834e('0xce')]);return db[_0x834e('0xd5')][_0x834e('0x26')]({'where':_0x198f0e[_0x834e('0x4f')]})[_0x834e('0x2c')](function(_0x2a6e9a){_0x1d53c6[_0x834e('0x26')]=_0x2a6e9a;if(_0x4094d5['query'][_0x834e('0xd3')]){_0x198f0e['include']=[{'all':!![]}];}return db[_0x834e('0xd5')]['findAll'](_0x198f0e);})[_0x834e('0x2c')](function(_0x32f2f0){_0x1d53c6[_0x834e('0x97')]=_0x32f2f0;return _0x1d53c6;});}})[_0x834e('0x2c')](respondWithFilteredResult(_0x449530,_0x198f0e))[_0x834e('0x99')](handleError(_0x449530,null));};exports['getHopperFinals']=function(_0x17f7d9,_0x29f970,_0x5850d2){var _0x5b891e={'raw':!![],'where':{}};var _0x10df58={};var _0x4db3c5={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x17f7d9[_0x834e('0xc3')]['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x29f970,null))[_0x834e('0x2c')](function(_0x26fac2){if(_0x26fac2){_0x10df58[_0x834e('0x3f')]=_[_0x834e('0x33')](db[_0x834e('0xb5')]['rawAttributes']);_0x10df58[_0x834e('0x3c')]=_[_0x834e('0x33')](_0x17f7d9['query']);_0x10df58['filters']=_[_0x834e('0x3e')](_0x10df58[_0x834e('0x3f')],_0x10df58['query']);_0x5b891e['attributes']=_[_0x834e('0x3e')](_0x10df58[_0x834e('0x3f')],qs[_0x834e('0x40')](_0x17f7d9['query'][_0x834e('0x40')]));_0x5b891e[_0x834e('0x41')]=_0x5b891e[_0x834e('0x41')]['length']?_0x5b891e[_0x834e('0x41')]:_0x10df58['model'];if(!_0x17f7d9[_0x834e('0x3c')][_0x834e('0x42')](_0x834e('0x43'))){_0x5b891e[_0x834e('0x28')]=qs[_0x834e('0x28')](_0x17f7d9['query'][_0x834e('0x28')]);_0x5b891e[_0x834e('0x27')]=qs[_0x834e('0x27')](_0x17f7d9[_0x834e('0x3c')][_0x834e('0x27')]);}_0x5b891e['order']=qs['sort'](_0x17f7d9[_0x834e('0x3c')][_0x834e('0x45')]);_0x5b891e[_0x834e('0x4f')]=qs['filters'](_[_0x834e('0x46')](_0x17f7d9[_0x834e('0x3c')],_0x10df58[_0x834e('0x3d')]));_0x5b891e[_0x834e('0x4f')]['ContactId']=_0x26fac2['id'];if(_0x17f7d9[_0x834e('0x3c')][_0x834e('0x66')]){_0x5b891e['where']=_[_0x834e('0x8b')](_0x5b891e[_0x834e('0x4f')],{'$or':_[_0x834e('0x59')](_0x5b891e[_0x834e('0x41')],function(_0x4b0246){var _0x32a56d={};_0x32a56d[_0x4b0246]={'$like':'%'+_0x17f7d9['query'][_0x834e('0x66')]+'%'};return _0x32a56d;})});}_0x5b891e=_[_0x834e('0x8b')]({},_0x5b891e,_0x17f7d9[_0x834e('0xce')]);return db[_0x834e('0xb5')][_0x834e('0x26')]({'where':_0x5b891e[_0x834e('0x4f')]})['then'](function(_0x4948ef){_0x4db3c5[_0x834e('0x26')]=_0x4948ef;if(_0x17f7d9[_0x834e('0x3c')]['includeAll']){_0x5b891e[_0x834e('0xd4')]=[{'all':!![]}];}return db['CmHopperFinal'][_0x834e('0x9d')](_0x5b891e);})[_0x834e('0x2c')](function(_0x319d6c){_0x4db3c5[_0x834e('0x97')]=_0x319d6c;return _0x4db3c5;});}})[_0x834e('0x2c')](respondWithFilteredResult(_0x29f970,_0x5b891e))[_0x834e('0x99')](handleError(_0x29f970,null));};exports[_0x834e('0xd6')]=function(_0x56ae60,_0x122b03,_0x19031a){var _0x2a6bca={'raw':!![],'where':{}};var _0x223d48={};var _0x1c03bc={'count':0x0,'rows':[]};return db['CmContact'][_0x834e('0x38')]({'where':{'id':_0x56ae60[_0x834e('0xc3')]['id']}})[_0x834e('0x2c')](handleEntityNotFound(_0x122b03,null))['then'](function(_0x5563f1){if(_0x5563f1){_0x223d48['model']=_[_0x834e('0x33')](db[_0x834e('0xbd')][_0x834e('0xcd')]);_0x223d48[_0x834e('0x3c')]=_[_0x834e('0x33')](_0x56ae60[_0x834e('0x3c')]);_0x223d48[_0x834e('0x3d')]=_[_0x834e('0x3e')](_0x223d48[_0x834e('0x3f')],_0x223d48[_0x834e('0x3c')]);_0x2a6bca[_0x834e('0x41')]=_['intersection'](_0x223d48[_0x834e('0x3f')],qs[_0x834e('0x40')](_0x56ae60[_0x834e('0x3c')][_0x834e('0x40')]));_0x2a6bca[_0x834e('0x41')]=_0x2a6bca[_0x834e('0x41')][_0x834e('0x34')]?_0x2a6bca[_0x834e('0x41')]:_0x223d48['model'];if(!_0x56ae60[_0x834e('0x3c')][_0x834e('0x42')]('nolimit')){_0x2a6bca[_0x834e('0x28')]=qs[_0x834e('0x28')](_0x56ae60[_0x834e('0x3c')][_0x834e('0x28')]);_0x2a6bca['offset']=qs['offset'](_0x56ae60[_0x834e('0x3c')]['offset']);}_0x2a6bca[_0x834e('0x44')]=qs[_0x834e('0x45')](_0x56ae60[_0x834e('0x3c')][_0x834e('0x45')]);_0x2a6bca[_0x834e('0x4f')]=qs['filters'](_[_0x834e('0x46')](_0x56ae60['query'],_0x223d48['filters']));_0x2a6bca[_0x834e('0x4f')][_0x834e('0xd2')]=_0x5563f1['id'];if(_0x56ae60[_0x834e('0x3c')][_0x834e('0x66')]){_0x2a6bca[_0x834e('0x4f')]=_[_0x834e('0x8b')](_0x2a6bca['where'],{'$or':_[_0x834e('0x59')](_0x2a6bca[_0x834e('0x41')],function(_0x58443a){var _0x423b03={};_0x423b03[_0x58443a]={'$like':'%'+_0x56ae60[_0x834e('0x3c')]['filter']+'%'};return _0x423b03;})});}_0x2a6bca=_[_0x834e('0x8b')]({},_0x2a6bca,_0x56ae60[_0x834e('0xce')]);return db['JscriptySessionReport'][_0x834e('0x26')]({'where':_0x2a6bca[_0x834e('0x4f')]})[_0x834e('0x2c')](function(_0x3b658a){_0x1c03bc[_0x834e('0x26')]=_0x3b658a;if(_0x56ae60[_0x834e('0x3c')][_0x834e('0xd3')]){_0x2a6bca[_0x834e('0xd4')]=[{'all':!![]}];}return db[_0x834e('0xbd')][_0x834e('0x9d')](_0x2a6bca);})['then'](function(_0x2d871e){_0x1c03bc[_0x834e('0x97')]=_0x2d871e;return _0x1c03bc;});}})[_0x834e('0x2c')](respondWithFilteredResult(_0x122b03,_0x2a6bca))[_0x834e('0x99')](handleError(_0x122b03,null));};exports[_0x834e('0xd7')]=function(_0x1bccb4,_0x2d61c1,_0x40b75e){try{if(!_0x1bccb4[_0x834e('0xa2')][_0x834e('0x87')]){throw new Error(_0x834e('0xd8'));}if(!_0x1bccb4[_0x834e('0xa2')]['binding_keys']){throw new Error(_0x834e('0xd9'));}if(!_0x1bccb4[_0x834e('0xa2')]['binding_values']){throw new Error('No\x20association\x20values\x20specified!');}if(!_0x1bccb4['body'][_0x834e('0xda')]){throw new Error(_0x834e('0xdb'));}var _0x3b74c0=_0x1bccb4[_0x834e('0xa2')][_0x834e('0xdc')][_0x834e('0x58')](',');var _0x2ebc69=_0x1bccb4['body']['binding_values']['split'](',');if(!_0x3b74c0['length']||!_0x2ebc69[_0x834e('0x34')]||_0x3b74c0[_0x834e('0x34')]!==_0x2ebc69[_0x834e('0x34')]){throw new Error('Incorrect\x20binding\x20parameters\x20passed!');}_0x1bccb4['body']['fields']=_[_0x834e('0xdd')](_0x3b74c0,_0x2ebc69);if(!_0x1bccb4['body']['fields'][_0x834e('0xcc')]){throw new Error(_0x834e('0xde'));}if(!_0x1bccb4[_0x834e('0xa2')][_0x834e('0x40')][_0x834e('0xdf')]){throw new Error(_0x834e('0xe0'));}var _0x2905ba=path['join'](config[_0x834e('0xe1')],_0x834e('0xe2'),_0x1bccb4[_0x834e('0xe3')][_0x834e('0xe4')]);fs[_0x834e('0xe5')](_0x2905ba,parseInt('0777',0x8));var _0x215955=require('child_process')[_0x834e('0xe6')](path[_0x834e('0xa5')](__dirname,_0x834e('0xe7')),[_0x2905ba,_0x1bccb4['body']['binding_keys'],_0x1bccb4['body']['binding_values'],_0x1bccb4[_0x834e('0xa2')][_0x834e('0x87')],_0x1bccb4['body']['CompanyId'],_0x1bccb4[_0x834e('0xa2')][_0x834e('0xc0')],_0x1bccb4[_0x834e('0xa2')]['socket_timestamp']]);return _0x2d61c1[_0x834e('0x24')](0xc8)[_0x834e('0x25')]({'message':_0x834e('0xe8'),'pid':_0x215955['pid']});}catch(_0x2e228f){return _0x2d61c1[_0x834e('0x24')](0x1f4)[_0x834e('0xe9')](_0x2e228f);}};exports[_0x834e('0xea')]=function(_0x298f4b,_0x38273f,_0x51971c){var _0x59eabe=fs[_0x834e('0xeb')](_0x298f4b[_0x834e('0xe3')][_0x834e('0x9')]);Papa['parse'](_0x59eabe,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x3f8695){return _0x38273f[_0x834e('0x24')](0xc8)[_0x834e('0x25')]({'file':_0x298f4b[_0x834e('0xe3')],'fields':_0x3f8695[_0x834e('0xec')][_0x834e('0x40')]});}});};exports[_0x834e('0xed')]=function(_0x2d245e,_0x25fa75,_0x277d41){return db[_0x834e('0x5d')][_0x834e('0x9d')]({'raw':!![],'attributes':['id'],'where':{'role':'agent'}})[_0x834e('0x2c')](function(_0x57479c){var _0x27253d=![];if(!_0x2d245e['body'][_0x834e('0x87')]){throw new Error(_0x834e('0xd8'));}if(!_0x2d245e[_0x834e('0xa2')][_0x834e('0xee')][_0x834e('0xcc')]){throw new Error(_0x834e('0xde'));}if(!_0x2d245e[_0x834e('0xa2')][_0x834e('0xee')]['firstName']){throw new Error('No\x20firstName\x20column\x20specified');}if(!_0x2d245e['body'][_0x834e('0xda')]){throw new Error(_0x834e('0xdb'));}var _0xb5aa04=require(_0x834e('0xef'))[_0x834e('0xe6')](path[_0x834e('0xa5')](__dirname,_0x834e('0xf0')),[_0x2d245e[_0x834e('0xc3')]['id'],JSON['stringify'](_0x2d245e['body']),JSON[_0x834e('0xf1')](_0x57479c)]);_0xb5aa04['on'](_0x834e('0xf2'),function(_0x54d41c){_0x27253d=!![];return _0x25fa75['status'](0xc8)['json']({'message':_0x834e('0xf3'),'pid':_0xb5aa04['pid']});});_0xb5aa04['on'](_0x834e('0xf4'),function(_0x42a007){if(_0x42a007&&!_0x27253d){return _0x25fa75[_0x834e('0x24')](0x1f4)['json']({'message':_0x834e('0xf5'),'pid':_0xb5aa04[_0x834e('0xf6')]});}});})[_0x834e('0x99')](handleError(_0x25fa75,null));};exports[_0x834e('0xf7')]=function(_0x33ffcd,_0x3dd6a5){var _0x5a08a4=['mail',_0x834e('0xf8'),_0x834e('0xf9'),_0x834e('0xfa'),_0x834e('0xfb'),_0x834e('0xfc'),_0x834e('0xfd')];var _0x40e17a={'offset':0x0,'order':qs['sort'](_0x834e('0xfe'))},_0x4a67ae={'count':0x0,'rows':[]};Promise['resolve']()['then'](function(){if(_0x33ffcd[_0x834e('0x3c')][_0x834e('0xff')]){if(!_['includes'](_0x5a08a4,_0x33ffcd[_0x834e('0x3c')]['channel']['toLowerCase']())){throw new Error(_0x834e('0x100'));}_0x5a08a4=[_0x33ffcd['query'][_0x834e('0xff')][_0x834e('0x101')]()];}if(_0x33ffcd[_0x834e('0x3c')][_0x834e('0x102')]){try{var _0x436d97=JSON[_0x834e('0x103')](_0x33ffcd[_0x834e('0x3c')][_0x834e('0x102')]);if(!moment(_0x436d97[_0x834e('0x4a')])['isValid']()){throw new Error(_0x834e('0x104'));}if(!moment(_0x436d97['to'])[_0x834e('0x105')]()){throw new Error(_0x834e('0x106'));}}catch(_0x462317){throw new Error('Invalid\x20createdAt\x20filter');}}if(!_0x33ffcd['query'][_0x834e('0x42')](_0x834e('0x43'))){_0x40e17a['limit']=qs[_0x834e('0x28')](_0x33ffcd['query'][_0x834e('0x28')]||0xa);_0x40e17a[_0x834e('0x27')]=qs[_0x834e('0x27')](_0x33ffcd[_0x834e('0x3c')][_0x834e('0x27')]);}var _0x919566=_0x5a08a4['map'](function(_0x560a5d){if(_0x560a5d==='voice'){var _0xbafedb={'attributes':['id',_0x834e('0x107'),_0x834e('0x108'),'source','destination',_0x834e('0x109'),_0x834e('0x10a'),_0x834e('0x10b'),_0x834e('0x10c'),_0x834e('0x10d'),_0x834e('0x10e'),_0x834e('0x10f'),_0x834e('0x110'),_0x834e('0x111')],'where':{'ContactId':_0x33ffcd[_0x834e('0xc3')]['id']},'include':[{'model':db[_0x834e('0x5d')],'as':'User','attributes':['id',_0x834e('0x30'),_0x834e('0x112'),'alias']}],'order':[[_0x834e('0x10e'),_0x834e('0x113')]]};if(_0x33ffcd[_0x834e('0x3c')][_0x834e('0x102')]){_0xbafedb[_0x834e('0x4f')][_0x834e('0x10e')]={'$gte':_0x436d97[_0x834e('0x4a')],'$lte':_0x436d97['to']};}return db[_0x834e('0xb7')][_0x834e('0x114')](_0xbafedb)[_0x834e('0x2c')](function(_0x3b477a){_0x4a67ae[_0x834e('0x26')]+=_0x3b477a[_0x834e('0x26')];return _[_0x834e('0x59')](_0x3b477a[_0x834e('0x97')],function(_0xd9ca92){var _0x2c52ab=_0xd9ca92[_0x834e('0xa3')]({'plain':!![]});_0x2c52ab[_0x834e('0xff')]=_0x560a5d;if(_0x2c52ab[_0x834e('0x5d')]){_0x2c52ab[_0x834e('0x5d')]={'id':_0x2c52ab[_0x834e('0x5d')]['id'],'name':_0x2c52ab[_0x834e('0x5d')]['name'],'fullname':_0x2c52ab[_0x834e('0x5d')][_0x834e('0x112')],'alias':_0x2c52ab[_0x834e('0x5d')][_0x834e('0x9f')]};}return _0x2c52ab;});});}else{var _0x3fd7a3=_[_0x834e('0x115')](_0x560a5d)+(_0x560a5d===_0x834e('0xf8')?_0x834e('0x116'):_0x834e('0x117'));var _0x41d0a7={'attributes':['id',_0x834e('0x118'),_0x834e('0x119'),'createdAt',_0x834e('0x10d'),_0x834e('0x11a'),'secondDisposition',_0x834e('0x11b'),_0x834e('0x11c'),_0x3fd7a3+'Id'],'where':{'ContactId':_0x33ffcd['params']['id']},'include':[{'model':db[_0x3fd7a3],'as':_0x834e('0x117'),'attributes':['id',_0x834e('0x30'),'key']},{'model':db['User'],'as':'Owner','attributes':['id',_0x834e('0x30'),_0x834e('0x112')]},{'model':db[_0x834e('0x56')],'as':_0x834e('0x96'),'attributes':['id','name',_0x834e('0xc4')],'through':{'attributes':[]}}],'order':[[_0x834e('0x10e'),_0x834e('0x113')]]};if(_0x33ffcd['query'][_0x834e('0x102')]){_0x41d0a7[_0x834e('0x4f')][_0x834e('0x10e')]={'$gte':_0x436d97['from'],'$lte':_0x436d97['to']};}switch(_0x560a5d){case _0x834e('0xf8'):_0x41d0a7[_0x834e('0x41')]['push'](_0x834e('0x11d'),_0x834e('0x11e'),'customerPort',_0x834e('0x11f'),_0x834e('0x120'),_0x834e('0x121'),_0x834e('0x122'),_0x834e('0x123'),'referer');break;case'mail':_0x41d0a7[_0x834e('0x41')][_0x834e('0x36')](_0x834e('0x124'),'substatus');break;case _0x834e('0xfa'):_0x41d0a7[_0x834e('0x41')][_0x834e('0x36')](_0x834e('0x125'),_0x834e('0x126'));break;}return db[_[_0x834e('0x115')](_0x560a5d)+'Interaction'][_0x834e('0x114')](_0x41d0a7)[_0x834e('0x2c')](function(_0x2ed7fe){_0x4a67ae[_0x834e('0x26')]+=_0x2ed7fe[_0x834e('0x26')];return _['map'](_0x2ed7fe['rows'],function(_0x17de34){var _0x5eca84=_0x17de34[_0x834e('0xa3')]({'plain':!![]});_0x5eca84[_0x834e('0xff')]=_0x560a5d;if(_0x5eca84[_0x834e('0x127')]){_0x5eca84[_0x834e('0x127')]={'id':_0x5eca84[_0x834e('0x127')]['id'],'name':_0x5eca84[_0x834e('0x127')][_0x834e('0x30')],'fullname':_0x5eca84['Owner'][_0x834e('0x112')]};}return _0x5eca84;});});}});return Promise[_0x834e('0x3a')](_0x919566);})['then'](function(_0x1a3260){return _(_0x1a3260)[_0x834e('0x128')]()[_0x834e('0x129')]('createdAt')[_0x834e('0x12a')]()['value']();})[_0x834e('0x2c')](function(_0x5d3809){_0x4a67ae[_0x834e('0x97')]=_0x40e17a[_0x834e('0x28')]?_0x5d3809['slice'](_0x40e17a[_0x834e('0x27')],_0x40e17a['offset']+_0x40e17a[_0x834e('0x28')]):_0x5d3809;return _0x4a67ae;})[_0x834e('0x2c')](respondWithFilteredResult(_0x3dd6a5,_0x40e17a))[_0x834e('0x99')](handleError(_0x3dd6a5,null));};
\ No newline at end of file
+var _0xb94d=['where','$or','push','ListId','findOrCreate','spread','contact','all','show','find','Tags','name','ContactItemType','ItemType','sequelize','literal','Phones.OrderBy','isNil','$and','omit','map','format','cf_%d','pickBy','cf_','isEmpty','table','cm_contacts','setFields','id\x20=\x20?','text','phone','getTags','findOne','model','Tag','rawAttributes','filters','attributes','intersection','fields','order','sort','filter','nolimit','setTags','setAdditionalPhones','OrderBy','items','item_types','description','ItemTypeId','contact\x20phone\x20exists','PHONE','CmHopper','CmHopperAdditionalPhone','item','`ItemType`.OrderBy','CmHopperId','ItemType.OrderBy','getAdditionalPhones','duplicateAdditionalPhones','fromContactId','CmContactId','toContactId','hopperId','getHoppers','pick','ContactId','options','include','rows','getHopperHistories','includeAll','getHopperFinals','uploadCsv','binding_keys','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','split','Incorrect\x20binding\x20parameters\x20passed!','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','server/files/tmp','file','child_process','fork','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','upload','meta','import','User','agent','No\x20ListId\x20specified','binding','../../components/import/cm/csv2','stringify','message','exit','error\x20child\x20process','importUpdates','../../components/import/cm/csvUpdates','getJourney','chat','openchannel','fax','voice','-createdAt','resolve','includes','channel','toLowerCase','Invalid\x20channel','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20createdAt\x20filter','uniqueid','source','destination','callerid','starttime','endtime','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','VoiceCallReport','findAndCountAll','startCase','Website','closed','closedAt','disposition','secondDisposition','thirdDisposition','UserId','Account','key','Owner','color','DESC','browserName','customerIp','customerPort','deviceModel','ratingMessage','ratingType','mail','subject','externalUrl','threadId','fullname','flatten','sortBy','value','slice','moment','lodash','squel','ioredis','../../components/contacts','../../components/parsers/qs','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','register','status','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','sendStatus','error','send','index','findAll','query','catch','params','describe','CmContact','tags','keys','length','startsWith','columnName','analytics','CmCustomField','displayName','alias','type','values','info','Custom\x20field\x20%s\x20not\x20found\x20on\x20cm_contacts\x20table','forEach','hasOwnProperty','merge','body','get','mergeWith','isArray','join','from','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','OpenchannelInteraction','OpenchannelMessage','CmContactHasItem','CmHopperFinal','CmHopperHistory','FaxQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','create','dialTimezone','utcOffset','timezones','additionalPhones','bulkCreate','duplicates'];(function(_0x2576d7,_0x167624){var _0x16a08c=function(_0x19de1e){while(--_0x19de1e){_0x2576d7['push'](_0x2576d7['shift']());}};_0x16a08c(++_0x167624);}(_0xb94d,0xa6));var _0xdb94=function(_0x152121,_0x120c53){_0x152121=_0x152121-0x0;var _0x592a85=_0xb94d[_0x152121];return _0x592a85;};'use strict';var moment=require(_0xdb94('0x0'));var BPromise=require('bluebird');var util=require('util');var path=require('path');var fs=require('fs');var _=require(_0xdb94('0x1'));var squel=require(_0xdb94('0x2'));var Papa=require('papaparse');var Redis=require(_0xdb94('0x3'));var contacts=require(_0xdb94('0x4'));var qs=require(_0xdb94('0x5'));var logger=require(_0xdb94('0x6'))('api');var config=require(_0xdb94('0x7'));var shared=require('../../config/environment/shared');var db=require(_0xdb94('0x8'))['db'];config[_0xdb94('0x9')]=_[_0xdb94('0xa')](config[_0xdb94('0x9')],{'host':_0xdb94('0xb'),'port':0x18eb});var socket=require(_0xdb94('0xc'))(new Redis(config[_0xdb94('0x9')]));require(_0xdb94('0xd'))[_0xdb94('0xe')](socket);function respondWithResult(_0x3ffc6e,_0x2d7f4c){_0x2d7f4c=_0x2d7f4c||0xc8;return function(_0x31daeb){if(_0x31daeb){return _0x3ffc6e[_0xdb94('0xf')](_0x2d7f4c)[_0xdb94('0x10')](_0x31daeb);}};}function respondWithFilteredResult(_0x23b044,_0x329646){return function(_0x4650a9){if(_0x4650a9){var _0x34310c=typeof _0x329646[_0xdb94('0x11')]===_0xdb94('0x12')&&typeof _0x329646[_0xdb94('0x13')]===_0xdb94('0x12');var _0x59cbb3=_0x4650a9[_0xdb94('0x14')];var _0x4db975=_0x34310c?0x0:_0x329646[_0xdb94('0x11')];var _0x307725=_0x34310c?_0x4650a9[_0xdb94('0x14')]:_0x329646[_0xdb94('0x11')]+_0x329646[_0xdb94('0x13')];var _0x341c8c;if(_0x307725>=_0x59cbb3){_0x307725=_0x59cbb3;_0x341c8c=0xc8;}else{_0x341c8c=0xce;}_0x23b044[_0xdb94('0xf')](_0x341c8c);return _0x23b044[_0xdb94('0x15')](_0xdb94('0x16'),_0x4db975+'-'+_0x307725+'/'+_0x59cbb3)[_0xdb94('0x10')](_0x4650a9);}return null;};}function saveUpdates(_0x37e716){return function(_0x1dd952){if(_0x1dd952){return _0x1dd952[_0xdb94('0x17')](_0x37e716)[_0xdb94('0x18')](function(_0x4c5994){return _0x4c5994;});}return null;};}function removeEntity(_0x38fa25){return function(_0x512ccd){if(_0x512ccd){return _0x512ccd[_0xdb94('0x19')]()[_0xdb94('0x18')](function(){_0x38fa25[_0xdb94('0xf')](0xcc)['end']();});}};}function handleEntityNotFound(_0x39695c){return function(_0x5b12d5){if(!_0x5b12d5){_0x39695c[_0xdb94('0x1a')](0x194);}return _0x5b12d5;};}function handleError(_0xd074be,_0x3d7285){_0x3d7285=_0x3d7285||0x1f4;return function(_0x2be650){logger[_0xdb94('0x1b')](_0x2be650['stack']);if(_0x2be650['name']){delete _0x2be650['name'];}_0xd074be[_0xdb94('0xf')](_0x3d7285)[_0xdb94('0x1c')](_0x2be650);};}exports[_0xdb94('0x1d')]=function(_0x37ae65,_0x2ca1a9){var _0x5e4b61={};return contacts['describe']()['then'](function(_0xdab26){_0x5e4b61=qs['getOptions'](_0xdab26,_0x37ae65);return contacts[_0xdb94('0x1e')](_0x37ae65[_0xdb94('0x1f')],_0x37ae65['user'],_0x5e4b61,_0xdab26);})[_0xdb94('0x18')](respondWithFilteredResult(_0x2ca1a9,_0x5e4b61))[_0xdb94('0x20')](handleError(_0x2ca1a9,null));};exports[_0xdb94('0x19')]=function(_0x594b82,_0xb549aa){return db['CmContact']['find']({'where':{'id':_0x594b82[_0xdb94('0x21')]['id']}})['then'](handleEntityNotFound(_0xb549aa,null))[_0xdb94('0x18')](removeEntity(_0xb549aa,null))['catch'](handleError(_0xb549aa,null));};exports[_0xdb94('0x22')]=function(_0x34c70b,_0x5d4f28){return db[_0xdb94('0x23')][_0xdb94('0x22')]()[_0xdb94('0x18')](function(_0x5d9a22){delete _0x5d9a22[_0xdb94('0x24')];for(var _0xbc39a9=0x0;_0xbc39a9<Object[_0xdb94('0x25')](_0x5d9a22)[_0xdb94('0x26')];_0xbc39a9++){var _0x929d96=Object['keys'](_0x5d9a22)[_0xbc39a9];if(!_[_0xdb94('0x27')](_0x929d96,'cf_')){_0x5d9a22[_0x929d96][_0xdb94('0x28')]=_0x929d96;_0x5d9a22[_0x929d96]['displayName']=_0x929d96;}}return _0x5d9a22;})['then'](function(_0xffcbc3){var _0x1c6922={'where':Boolean(_0x34c70b[_0xdb94('0x1f')][_0xdb94('0x29')])===!![]?undefined:{'$or':[{'ListId':_0x34c70b[_0xdb94('0x1f')]['id']},{'ListId':null}]},'raw':!![]};return db[_0xdb94('0x2a')][_0xdb94('0x1e')](_0x1c6922)[_0xdb94('0x18')](function(_0x3d4895){for(var _0x35ea2f=0x0;_0x35ea2f<_0x3d4895['length'];_0x35ea2f++){var _0x3eacb4='cf_'+_0x3d4895[_0x35ea2f]['id'];if(_0xffcbc3[_0x3eacb4]){_0xffcbc3[_0x3eacb4][_0xdb94('0x28')]=_0x3eacb4;_0xffcbc3[_0x3eacb4][_0xdb94('0x2b')]=_0x3d4895[_0x35ea2f][_0xdb94('0x2c')];_0xffcbc3[_0x3eacb4]['custom']={'type':_0x3d4895[_0x35ea2f][_0xdb94('0x2d')],'values':_0x3d4895[_0x35ea2f][_0xdb94('0x2e')]};}else{logger[_0xdb94('0x2f')](_0xdb94('0x30'),_0x3eacb4);}}Object['keys'](_0xffcbc3)[_0xdb94('0x31')](function(_0x1549e3){if(!_0xffcbc3[_0x1549e3][_0xdb94('0x32')](_0xdb94('0x28'))){delete _0xffcbc3[_0x1549e3];}});return _0xffcbc3;});})[_0xdb94('0x18')](respondWithResult(_0x5d4f28,null))[_0xdb94('0x20')](handleError(_0x5d4f28,null));};exports[_0xdb94('0x33')]=function(_0x40998c,_0x5cb9d6){var _0x37fe6d;var _0x2e7ea9;var _0x236c55;if(_0x40998c[_0xdb94('0x34')]['id']){delete _0x40998c[_0xdb94('0x34')]['id'];}return db[_0xdb94('0x23')][_0xdb94('0x1e')]({'where':{'id':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')]['from']]}})[_0xdb94('0x18')](function(_0x5988d1){if(_0x5988d1){if(_0x5988d1[_0xdb94('0x26')]!==0x2){return null;}_0x5988d1[0x0]=_0x5988d1[0x0][_0xdb94('0x35')]({'plain':!![]});_0x5988d1[0x1]=_0x5988d1[0x1][_0xdb94('0x35')]({'plain':!![]});delete _0x5988d1[0x0]['id'];delete _0x5988d1[0x1]['id'];return _[_0xdb94('0x36')](_0x5988d1[0x0],_0x5988d1[0x1],function(_0x5a1196,_0x2dce74){if(Array['isArray'](_0x2dce74)&&!_0x2dce74[_0xdb94('0x26')]){return _0x5a1196;}else if(!_0x2dce74){return _0x5a1196;}});}})[_0xdb94('0x18')](handleEntityNotFound(_0x5cb9d6,null))[_0xdb94('0x18')](function(_0x1593de){if(_0x1593de){if(_0x1593de[_0xdb94('0x24')]&&_[_0xdb94('0x37')](_0x1593de['tags'])){_0x1593de[_0xdb94('0x24')]=_0x1593de['tags'][_0xdb94('0x38')]();}logger[_0xdb94('0x2f')]('[CmContact][merge]\x20to\x20%s\x20from\x20%s',_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')][_0xdb94('0x39')]);return db['CmHopper'][_0xdb94('0x19')]({'where':{'ContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')][_0xdb94('0x39')]]}})[_0xdb94('0x18')](function(_0x4d789d){logger[_0xdb94('0x2f')](_0xdb94('0x3a'),_0x4d789d);return db[_0xdb94('0x3b')][_0xdb94('0x19')]({'where':{'ContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')]['from']]}})[_0xdb94('0x18')](function(_0x1c46a7){logger[_0xdb94('0x2f')]('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x1c46a7);return db[_0xdb94('0x23')]['create'](_0x1593de);});});}})[_0xdb94('0x18')](function(_0x4def80){if(_0x4def80){_0x37fe6d=_0x4def80;_0x2e7ea9={'ContactId':_0x37fe6d['id']};_0x236c55={'where':{'ContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')][_0xdb94('0x39')]]}};return db['ChatInteraction'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['ChatMessage'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3c')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3d')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['MailMessage'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3d')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3e')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x3f')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x40')]['update'](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x41')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['FaxMessage']['update'](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x42')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x43')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x44')][_0xdb94('0x17')]({'CmContactId':_0x37fe6d['id']},{'where':{'CmContactId':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c[_0xdb94('0x34')]['from']]}});}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x45')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x46')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['ReportAgentPreview'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db['VoiceCallReport'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['ChatQueueReport'][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x47')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db['MailQueueReport']['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x48')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x49')]['update'](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x4a')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x4b')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x4c')]['update'](_0x2e7ea9,_0x236c55);}})['then'](function(){if(_0x37fe6d){return db[_0xdb94('0x4d')][_0xdb94('0x17')](_0x2e7ea9,_0x236c55);}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return db[_0xdb94('0x23')][_0xdb94('0x19')]({'where':{'id':[_0x40998c[_0xdb94('0x34')]['to'],_0x40998c['body']['from']]}});}})[_0xdb94('0x18')](function(){if(_0x37fe6d){return _0x37fe6d;}})[_0xdb94('0x18')](respondWithResult(_0x5cb9d6,null))[_0xdb94('0x20')](handleError(_0x5cb9d6,null));};exports[_0xdb94('0x4e')]=function(_0x5f5d6e,_0x53d900){return db[_0xdb94('0x23')][_0xdb94('0x22')]()[_0xdb94('0x18')](function(_0x1d54e3){if(_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x24')]&&_[_0xdb94('0x37')](_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x24')])){if(_0x5f5d6e[_0xdb94('0x34')]['tags'][_0xdb94('0x26')]){_0x5f5d6e['body'][_0xdb94('0x24')]=_0x5f5d6e['body'][_0xdb94('0x24')]['join'](';')+';';}else{_0x5f5d6e[_0xdb94('0x34')]['tags']=null;}}else{_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x24')]=null;}if(!_['isNil'](_0x5f5d6e['body']['dialTimezone'])){var _0x5d6baf=_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x4f')];if(!_['isNil'](shared['timezones'][_0x5d6baf]))_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x50')]=shared[_0xdb94('0x51')][_0x5d6baf][_0xdb94('0x50')];}return db[_0xdb94('0x23')][_0xdb94('0x4e')](_0x5f5d6e['body'],{'fields':_[_0xdb94('0x25')](_0x1d54e3),'raw':!![]});})[_0xdb94('0x18')](function(_0x472d97){if(_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x52')]){return insertAdditionalPhones(_0x472d97,_0x5f5d6e[_0xdb94('0x34')][_0xdb94('0x52')]);}else{return _0x472d97;}})['then'](respondWithResult(_0x53d900,0xc9))[_0xdb94('0x20')](handleError(_0x53d900,null));};exports[_0xdb94('0x53')]=function(_0x5894d4,_0x4cf70b){var _0x26dfda=0x0;var _0x20c72d=0x0;var _0x3656b2=0x0;var _0xe78a79=[];return db[_0xdb94('0x23')][_0xdb94('0x22')]()[_0xdb94('0x18')](function(_0x1700e0){return BPromise['each'](_0x5894d4[_0xdb94('0x34')],function(_0x3f6c70){var _0x322161={'where':{'$or':[]},'defaults':_0x3f6c70,'fields':_[_0xdb94('0x25')](_0x1700e0),'raw':!![]};if(_0x3f6c70[_0xdb94('0x54')]){for(var _0x15ef26=0x0;_0x15ef26<_0x3f6c70[_0xdb94('0x54')][_0xdb94('0x26')];_0x15ef26++){var _0x392ddb={};_0x392ddb[_0x3f6c70['duplicates'][_0x15ef26]]=_0x3f6c70[_0x3f6c70[_0xdb94('0x54')][_0x15ef26]];_0x322161[_0xdb94('0x55')][_0xdb94('0x56')][_0xdb94('0x57')](_0x392ddb);}_0x322161[_0xdb94('0x55')][_0xdb94('0x58')]=_0x3f6c70['ListId'];}return db['CmContact'][_0xdb94('0x59')](_0x322161)[_0xdb94('0x5a')](function(_0x192174,_0x25f195){if(_0x25f195){if(_0x3f6c70[_0xdb94('0x32')](_0xdb94('0x52'))){_0xe78a79[_0xdb94('0x57')]({'contact':_0x192174,'additionalPhones':_0x3f6c70['additionalPhones']});}_0x26dfda++;}else{_0x3656b2++;}})['catch'](function(){_0x20c72d++;});});})['then'](function(_0x4cfb39){if(_0x4cfb39){if(_0xe78a79[_0xdb94('0x26')]>0x0){return new Promise(function(_0x248bf3){var _0x22cd79=[];for(var _0x1ec6f9=0x0;_0x1ec6f9<_0xe78a79[_0xdb94('0x26')];_0x1ec6f9++){_0x22cd79[_0xdb94('0x57')](insertAdditionalPhones(_0xe78a79[_0x1ec6f9][_0xdb94('0x5b')],_0xe78a79[_0x1ec6f9][_0xdb94('0x52')]));}Promise[_0xdb94('0x5c')](_0x22cd79)[_0xdb94('0x18')](function(){_0x248bf3(0x1);});})['then'](function(){return{'success':_0x26dfda,'failure':_0x20c72d,'duplicates':_0x3656b2};});}else{return{'success':_0x26dfda,'failure':_0x20c72d,'duplicates':_0x3656b2};}}})['then'](respondWithResult(_0x4cf70b,0xc9))['catch'](handleError(_0x4cf70b,null));};exports[_0xdb94('0x5d')]=function(_0x371055,_0x32e173){var _0x3a6ee6;return db[_0xdb94('0x23')][_0xdb94('0x22')]()['then'](function(_0x228fb6){return db[_0xdb94('0x23')][_0xdb94('0x5e')]({'where':{'id':_0x371055['params']['id']},'include':[{'model':db['Tag'],'as':_0xdb94('0x5f'),'attributes':['id',_0xdb94('0x60'),'color'],'required':_0x371055[_0xdb94('0x1f')]['tag']?!![]:![]},{'model':db[_0xdb94('0x44')],'as':'Phones','where':{'CmContactId':_0x371055[_0xdb94('0x21')]['id']},'required':![],'include':[{'model':db[_0xdb94('0x61')],'as':_0xdb94('0x62')}]}],'order':[db[_0xdb94('0x63')][_0xdb94('0x64')](_0xdb94('0x65'))],'attributes':_['keys'](_0x228fb6)});})[_0xdb94('0x18')](function(_0x551e5a){if(!_[_0xdb94('0x66')](_0x551e5a)){_0x3a6ee6=_0x551e5a[_0xdb94('0x35')]({'plain':!![]});var _0x5f0291={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x551e5a&&_0x551e5a[_0xdb94('0x58')]){if(_0x551e5a[_0xdb94('0x58')]){_0x5f0291[_0xdb94('0x55')][_0xdb94('0x67')]['push']({'ListId':{'$ne':_0x551e5a['ListId']}});}}return db[_0xdb94('0x2a')][_0xdb94('0x1e')](_0x5f0291);}})[_0xdb94('0x18')](function(_0x3ffd48){if(!_[_0xdb94('0x66')](_0x3ffd48)){return _[_0xdb94('0x68')](_0x3a6ee6,_[_0xdb94('0x69')](_0x3ffd48,function(_0x683597){return util[_0xdb94('0x6a')](_0xdb94('0x6b'),_0x683597['id']);}));}})[_0xdb94('0x18')](handleEntityNotFound(_0x32e173,null))[_0xdb94('0x18')](respondWithResult(_0x32e173,null))[_0xdb94('0x20')](handleError(_0x32e173,null));};exports[_0xdb94('0x17')]=function(_0x31f2c1,_0x3bbe09){var _0x3e1df4;if(_0x31f2c1[_0xdb94('0x34')]['id']){delete _0x31f2c1[_0xdb94('0x34')]['id'];}if(!_[_0xdb94('0x66')](_0x31f2c1['body'][_0xdb94('0x4f')])){var _0x5a7e1f=_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x4f')];if(!_[_0xdb94('0x66')](shared['timezones'][_0x5a7e1f]))_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x50')]=shared['timezones'][_0x5a7e1f][_0xdb94('0x50')];}return db[_0xdb94('0x23')][_0xdb94('0x5e')]({'where':{'id':_0x31f2c1[_0xdb94('0x21')]['id']}})['then'](handleEntityNotFound(_0x3bbe09,null))['then'](saveUpdates(_0x31f2c1[_0xdb94('0x34')],null))[_0xdb94('0x18')](function(_0x2a3279){_0x3e1df4=_0x2a3279;var _0x333dac={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2a3279&&_0x2a3279[_0xdb94('0x58')]){if(_0x2a3279[_0xdb94('0x58')]){_0x333dac[_0xdb94('0x55')]['$and']['push']({'ListId':{'$ne':_0x2a3279['ListId']}});}}return db[_0xdb94('0x2a')]['findAll'](_0x333dac);})[_0xdb94('0x18')](function(_0x1d1b4b){if(_0x1d1b4b){return _[_0xdb94('0x68')](_[_0xdb94('0x6c')](_0x31f2c1[_0xdb94('0x34')],function(_0xbf088c,_0x43f245){return _[_0xdb94('0x27')](_0x43f245,_0xdb94('0x6d'));}),_[_0xdb94('0x69')](_0x1d1b4b,function(_0x38a2ab){return util['format']('cf_%d',_0x38a2ab['id']);}));}})['then'](function(_0x1f9bf0){if(_0x1f9bf0&&!_[_0xdb94('0x6e')](_0x1f9bf0)){var _0x563559=squel[_0xdb94('0x17')]()[_0xdb94('0x6f')](_0xdb94('0x70'))[_0xdb94('0x71')](_0x1f9bf0)['where'](_0xdb94('0x72'),_0x31f2c1['params']['id'])['toParam']();return db[_0xdb94('0x63')][_0xdb94('0x1f')](_0x563559[_0xdb94('0x73')],{'replacements':_0x563559[_0xdb94('0x2e')]});}})['then'](function(){if(_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x74')]&&_0x3e1df4){return db['CmHopper']['update']({'phone':_0x31f2c1[_0xdb94('0x34')][_0xdb94('0x74')],'OrderBy':0x0},{'where':{'ContactId':_0x3e1df4['id']}});}})[_0xdb94('0x18')](function(){return _0x3e1df4;})[_0xdb94('0x18')](respondWithResult(_0x3bbe09,null))[_0xdb94('0x20')](handleError(_0x3bbe09,null));};exports[_0xdb94('0x75')]=function(_0x416769,_0x3bca46){var _0xc8f95e={};var _0x58b06b={};var _0x8fc959;var _0x996f22;return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x416769[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x3bca46,null))[_0xdb94('0x18')](function(_0x1da82d){if(_0x1da82d){_0x8fc959=_0x1da82d;_0x58b06b[_0xdb94('0x77')]=_[_0xdb94('0x25')](db[_0xdb94('0x78')][_0xdb94('0x79')]);_0x58b06b[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x416769[_0xdb94('0x1f')]);_0x58b06b[_0xdb94('0x7a')]=_['intersection'](_0x58b06b['model'],_0x58b06b[_0xdb94('0x1f')]);_0xc8f95e[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x58b06b[_0xdb94('0x77')],qs[_0xdb94('0x7d')](_0x416769[_0xdb94('0x1f')]['fields']));_0xc8f95e[_0xdb94('0x7b')]=_0xc8f95e[_0xdb94('0x7b')][_0xdb94('0x26')]?_0xc8f95e[_0xdb94('0x7b')]:_0x58b06b['model'];_0xc8f95e[_0xdb94('0x7e')]=qs[_0xdb94('0x7f')](_0x416769[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0xc8f95e[_0xdb94('0x55')]=qs['filters'](_['pick'](_0x416769['query'],_0x58b06b[_0xdb94('0x7a')]));if(_0x416769[_0xdb94('0x1f')][_0xdb94('0x80')]){_0xc8f95e['where']=_[_0xdb94('0x33')](_0xc8f95e['where'],{'$or':_[_0xdb94('0x69')](_0xc8f95e[_0xdb94('0x7b')],function(_0x2674b1){var _0x46bb58={};_0x46bb58[_0x2674b1]={'$like':'%'+_0x416769[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x46bb58;})});}_0xc8f95e=_[_0xdb94('0x33')]({},_0xc8f95e,_0x416769['options']);return _0x8fc959[_0xdb94('0x75')](_0xc8f95e);}})[_0xdb94('0x18')](function(_0x44858c){if(_0x44858c){_0x996f22=_0x44858c[_0xdb94('0x26')];if(!_0x416769[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0xc8f95e[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x416769[_0xdb94('0x1f')][_0xdb94('0x13')]);_0xc8f95e[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x416769[_0xdb94('0x1f')]['offset']);}return _0x8fc959['getTags'](_0xc8f95e);}})[_0xdb94('0x18')](function(_0x3ba98d){if(_0x3ba98d){return _0x3ba98d?{'count':_0x996f22,'rows':_0x3ba98d}:null;}})[_0xdb94('0x18')](respondWithResult(_0x3bca46,null))[_0xdb94('0x20')](handleError(_0x3bca46,null));};exports['setTags']=function(_0x38a3c3,_0x128863){if(_0x38a3c3[_0xdb94('0x34')]['id']){delete _0x38a3c3['body']['id'];}return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x38a3c3[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x128863,null))[_0xdb94('0x18')](function(_0x1fab19){if(_0x1fab19){return _0x1fab19[_0xdb94('0x82')](_0x38a3c3[_0xdb94('0x34')]['ids']||[]);}return null;})[_0xdb94('0x18')](respondWithResult(_0x128863,null))['catch'](handleError(_0x128863,null));};exports[_0xdb94('0x83')]=function(_0x50f76f,_0x36e191){var _0x21a825=[];_0x21a825[_0xdb94('0x57')](addAdditionalPhones(_0x50f76f[_0xdb94('0x34')]));Promise['all'](_0x21a825)[_0xdb94('0x18')](function(){_0x21a825=[];_0x21a825[_0xdb94('0x57')](deleteCmHopperPhones(_0x50f76f[_0xdb94('0x34')]['id']));_0x21a825[_0xdb94('0x57')](addCmHopperPhones(_0x50f76f[_0xdb94('0x34')]['id']));Promise['all'](_0x21a825)[_0xdb94('0x18')](function(){return[0x1];})['then'](respondWithResult(_0x36e191,null));});};function addAdditionalPhones(_0x10b9db){var _0x4faecf;return new Promise(function(_0x3169a3){return db['CmContactHasItem'][_0xdb94('0x19')]({'where':{'CmContactId':_0x10b9db['id']}})[_0xdb94('0x18')](function(){db[_0xdb94('0x61')][_0xdb94('0x1e')]({'raw':!![],'attributes':['id',_0xdb94('0x84')]})['then'](function(_0x21b693){var _0x1e5bd3=[];for(var _0x21c234=0x0;_0x21c234<_0x10b9db[_0xdb94('0x85')][_0xdb94('0x26')];_0x21c234++){var _0x44d35c=_0x10b9db['item_types']?_['isNil'](_0x10b9db['item_types'][_0x21c234])?'':_0x10b9db[_0xdb94('0x86')][_0x21c234]:_0x10b9db[_0xdb94('0x85')][_0x21c234]['ItemTypeId']?_0x10b9db[_0xdb94('0x85')][_0x21c234]['ItemTypeId']:'';var _0x45747b=_['isNil'](_0x10b9db[_0xdb94('0x85')][_0x21c234]['description'])?'':_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x87')];var _0x43359e=_0x44d35c+':'+_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x74')]+'ยง'+_0x45747b;if(_[_0xdb94('0x66')](_0x4faecf))_0x4faecf=_0x43359e;else _0x4faecf+=';'+_0x43359e;var _0x24525a=null;var _0x196af6=null;if(_0x10b9db[_0xdb94('0x86')]){if(!_[_0xdb94('0x66')](_0x10b9db[_0xdb94('0x86')][_0x21c234])){_0x196af6=_[_0xdb94('0x5e')](_0x21b693,function(_0x9d863b){return _0x9d863b['id']===_0x10b9db['item_types'][_0x21c234];});if(!_[_0xdb94('0x66')](_0x196af6)){_0x24525a=_0x196af6['OrderBy'];}}}else{if(!_[_0xdb94('0x66')](_0x10b9db['items'][_0x21c234])){_0x196af6=_[_0xdb94('0x5e')](_0x21b693,function(_0x1b2071){return _0x1b2071['id']===_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x88')];});if(!_[_0xdb94('0x66')](_0x196af6)){_0x24525a=_0x21c234;}}}if(_[_0xdb94('0x66')](_0x24525a)){_0x24525a=0x64;}_0x1e5bd3[_0xdb94('0x57')](addAdditionalPhone(_0x10b9db['id'],_0x10b9db[_0xdb94('0x85')][_0x21c234]['phone'],_0x10b9db[_0xdb94('0x86')]?_[_0xdb94('0x66')](_0x10b9db['item_types'][_0x21c234])?null:_0x10b9db[_0xdb94('0x86')][_0x21c234]:_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x88')]?_0x10b9db[_0xdb94('0x85')][_0x21c234][_0xdb94('0x88')]:null,_0x24525a,_0x45747b));}Promise['all'](_0x1e5bd3)['then'](function(){db[_0xdb94('0x23')]['update']({'AdditionalPhones':_0x4faecf},{'where':{'id':_0x10b9db['id']}})[_0xdb94('0x18')](function(){_0x3169a3(0x1);});});});});});}function addAdditionalPhone(_0x4bd1cc,_0x549da3,_0x2c7920,_0x49ad0f,_0x4cc783){return db[_0xdb94('0x44')][_0xdb94('0x5e')]({'where':{'CmContactId':_0x4bd1cc,'item':_0x549da3}})[_0xdb94('0x18')](function(_0x1feae0){if(_0x1feae0)logger[_0xdb94('0x2f')](_0xdb94('0x89'),_0x1feae0);else{db[_0xdb94('0x44')][_0xdb94('0x4e')]({'CmContactId':_0x4bd1cc,'item':_0x549da3,'ItemTypeId':_0x2c7920,'OrderBy':_0x49ad0f,'ItemClass':_0xdb94('0x8a'),'description':_0x4cc783});}});}function deleteCmHopperPhones(_0x249924){return new Promise(function(_0x2de5fe){return db[_0xdb94('0x8b')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x249924}})[_0xdb94('0x18')](function(_0x5d683c){db[_0xdb94('0x8c')][_0xdb94('0x19')]({'where':{'CmHopperId':{'$in':_[_0xdb94('0x69')](_0x5d683c,'id')}}});})[_0xdb94('0x18')](function(){_0x2de5fe(0x1);});});}function addCmHopperPhones(_0xbcfeb6){return new Promise(function(_0x357d29){return db['CmHopper'][_0xdb94('0x1e')]({'raw':!![],'attributes':['id'],'where':{'ContactId':_0xbcfeb6}})[_0xdb94('0x18')](function(_0x359cf1){var _0x1f4771=[];_[_0xdb94('0x69')](_0x359cf1,function(_0x543185){_0x1f4771[_0xdb94('0x57')](createCmHopperPhone(_0xbcfeb6,_0x543185['id']));});Promise['all'](_0x1f4771)['then'](function(){_0x357d29(0x1);});});});}function createCmHopperPhone(_0x1c821b,_0x3f32ac){return new Promise(function(_0x101355){db[_0xdb94('0x44')]['findAll']({'raw':!![],'attributes':[_0xdb94('0x8d'),_0xdb94('0x84')],'where':{'CmContactId':_0x1c821b,'ItemClass':_0xdb94('0x8a')},'include':[{'model':db[_0xdb94('0x61')],'attributes':[_0xdb94('0x84')],'as':_0xdb94('0x62')}],'order':[_0xdb94('0x84'),db[_0xdb94('0x63')]['literal'](_0xdb94('0x8e'))]})['then'](function(_0x1ce70b){var _0x3c8dd8=0x1;var _0x1e5711=_[_0xdb94('0x69')](_0x1ce70b,function(_0x3324f4){_0x3324f4[_0xdb94('0x8f')]=_0x3f32ac;_0x3324f4['phone']=_0x3324f4[_0xdb94('0x8d')];_0x3324f4[_0xdb94('0x84')]=_0x3c8dd8;delete _0x3324f4[_0xdb94('0x90')];_0x3c8dd8=_0x3c8dd8+0x1;return _0x3324f4;});return db[_0xdb94('0x8c')]['bulkCreate'](_0x1e5711,{});})['then'](function(){_0x101355(0x1);});});}function insertAdditionalPhones(_0x5266a2,_0x448417){return new Promise(function(_0xf6465d){var _0xcb545=[];for(var _0x4c9e36=0x0;_0x4c9e36<_0x448417[_0xdb94('0x26')];_0x4c9e36++){var _0x5cbf1a=_0x448417[_0x4c9e36];_0xcb545['push'](parseContactItemType(_0x5cbf1a));}Promise['all'](_0xcb545)[_0xdb94('0x18')](function(){var _0x22169c={'id':_0x5266a2['id'],'items':_0x448417};return addAdditionalPhones(_0x22169c)['then'](function(){return addCmHopperPhones(_0x5266a2['id']);});})[_0xdb94('0x18')](function(){_0xf6465d(_0x5266a2);});});}function parseContactItemType(_0xcd661){return new Promise(function(_0x5b1069){if(_0xcd661['hasOwnProperty'](_0xdb94('0x88'))){_0x5b1069(_0xcd661);}else{return db[_0xdb94('0x61')][_0xdb94('0x5e')]({'where':{'name':_0xcd661[_0xdb94('0x62')]}})['then'](function(_0x6b6190){if(_[_0xdb94('0x66')](_0x6b6190))_0xcd661[_0xdb94('0x88')]=null;else _0xcd661['ItemTypeId']=_0x6b6190['id'];_0x5b1069(_0xcd661);});}});}exports[_0xdb94('0x91')]=function(_0x22ff73,_0x3218b7){return db[_0xdb94('0x44')][_0xdb94('0x1e')]({'raw':!![],'where':{'CmContactId':_0x22ff73[_0xdb94('0x21')]['id'],'ItemClass':_0xdb94('0x8a')},'include':[{'model':db[_0xdb94('0x61')],'as':'ItemType'}],'order':[['OrderBy'],[db['sequelize'][_0xdb94('0x64')](_0xdb94('0x8e'))]]})[_0xdb94('0x18')](function(_0x54ee3d){return _0x54ee3d;})[_0xdb94('0x18')](respondWithResult(_0x3218b7,null))['catch'](handleError(_0x3218b7,null));};exports[_0xdb94('0x92')]=function(_0x454bae,_0x5d3f66){return db['CmContactHasItem']['findAll']({'raw':!![],'where':{'CmContactId':_0x454bae[_0xdb94('0x34')][_0xdb94('0x93')]}})[_0xdb94('0x18')](function(_0x173f98){var _0x3487ce=_['map'](_0x173f98,function(_0x28742e){_0x28742e[_0xdb94('0x94')]=_0x454bae[_0xdb94('0x34')][_0xdb94('0x95')];return _0x28742e;});return db[_0xdb94('0x44')][_0xdb94('0x53')](_0x3487ce,{});})[_0xdb94('0x18')](function(){return addCmHopperPhones(_0x454bae[_0xdb94('0x34')][_0xdb94('0x95')]);})[_0xdb94('0x18')](function(){return['ok'];})[_0xdb94('0x18')](respondWithResult(_0x5d3f66,null))[_0xdb94('0x20')](handleError(_0x5d3f66,null));};exports['rescheduleAdditionalPhones']=function(_0x404fb6,_0x11ec5f){var _0x15f845=[];_0x15f845[_0xdb94('0x57')](createCmHopperPhone(_0x404fb6[_0xdb94('0x34')]['id'],_0x404fb6['body'][_0xdb94('0x96')]));Promise[_0xdb94('0x5c')](_0x15f845)[_0xdb94('0x18')](function(){return[0x1];})[_0xdb94('0x18')](respondWithResult(_0x11ec5f,null));};exports[_0xdb94('0x97')]=function(_0x39b8ba,_0x210343){var _0x215997={'raw':![],'where':{}};var _0x269cd4={};var _0x48c9da={'count':0x0,'rows':[]};return db[_0xdb94('0x23')]['findOne']({'where':{'id':_0x39b8ba[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x210343,null))['then'](function(_0x23f35e){if(_0x23f35e){_0x269cd4[_0xdb94('0x77')]=_[_0xdb94('0x25')](db['CmHopper'][_0xdb94('0x79')]);_0x269cd4[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x39b8ba[_0xdb94('0x1f')]);_0x269cd4[_0xdb94('0x7a')]=_[_0xdb94('0x7c')](_0x269cd4[_0xdb94('0x77')],_0x269cd4['query']);_0x215997[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x269cd4['model'],qs[_0xdb94('0x7d')](_0x39b8ba['query'][_0xdb94('0x7d')]));_0x215997[_0xdb94('0x7b')]=_0x215997[_0xdb94('0x7b')][_0xdb94('0x26')]?_0x215997[_0xdb94('0x7b')]:_0x269cd4[_0xdb94('0x77')];if(!_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0x215997['limit']=qs[_0xdb94('0x13')](_0x39b8ba['query'][_0xdb94('0x13')]);_0x215997['offset']=qs[_0xdb94('0x11')](_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x215997[_0xdb94('0x7e')]=qs[_0xdb94('0x7f')](_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0x215997[_0xdb94('0x55')]=qs[_0xdb94('0x7a')](_[_0xdb94('0x98')](_0x39b8ba['query'],_0x269cd4[_0xdb94('0x7a')]));_0x215997[_0xdb94('0x55')][_0xdb94('0x99')]=_0x23f35e['id'];if(_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x215997[_0xdb94('0x55')]=_[_0xdb94('0x33')](_0x215997[_0xdb94('0x55')],{'$or':_[_0xdb94('0x69')](_0x215997[_0xdb94('0x7b')],function(_0x350bf8){var _0x45821f={};_0x45821f[_0x350bf8]={'$like':'%'+_0x39b8ba[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x45821f;})});}_0x215997=_[_0xdb94('0x33')]({},_0x215997,_0x39b8ba[_0xdb94('0x9a')]);return db[_0xdb94('0x8b')][_0xdb94('0x14')]({'where':_0x215997['where']})[_0xdb94('0x18')](function(_0x5015f){_0x48c9da[_0xdb94('0x14')]=_0x5015f;if(_0x39b8ba[_0xdb94('0x1f')]['includeAll']){_0x215997[_0xdb94('0x9b')]=[{'all':!![]}];}return db[_0xdb94('0x8b')][_0xdb94('0x1e')](_0x215997);})[_0xdb94('0x18')](function(_0xc08a68){_0x48c9da[_0xdb94('0x9c')]=_0xc08a68;return _0x48c9da;});}})['then'](respondWithFilteredResult(_0x210343,_0x215997))[_0xdb94('0x20')](handleError(_0x210343,null));};exports[_0xdb94('0x9d')]=function(_0x2e04e3,_0xbe8234){var _0x350761={'raw':!![],'where':{}};var _0x4081a1={};var _0x195c90={'count':0x0,'rows':[]};return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x2e04e3[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0xbe8234,null))['then'](function(_0x1a13b9){if(_0x1a13b9){_0x4081a1['model']=_['keys'](db[_0xdb94('0x46')][_0xdb94('0x79')]);_0x4081a1[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x2e04e3[_0xdb94('0x1f')]);_0x4081a1[_0xdb94('0x7a')]=_['intersection'](_0x4081a1[_0xdb94('0x77')],_0x4081a1[_0xdb94('0x1f')]);_0x350761[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x4081a1[_0xdb94('0x77')],qs[_0xdb94('0x7d')](_0x2e04e3['query'][_0xdb94('0x7d')]));_0x350761[_0xdb94('0x7b')]=_0x350761[_0xdb94('0x7b')][_0xdb94('0x26')]?_0x350761[_0xdb94('0x7b')]:_0x4081a1[_0xdb94('0x77')];if(!_0x2e04e3[_0xdb94('0x1f')]['hasOwnProperty'](_0xdb94('0x81'))){_0x350761[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x13')]);_0x350761[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x350761['order']=qs[_0xdb94('0x7f')](_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0x350761[_0xdb94('0x55')]=qs[_0xdb94('0x7a')](_['pick'](_0x2e04e3[_0xdb94('0x1f')],_0x4081a1['filters']));_0x350761[_0xdb94('0x55')]['ContactId']=_0x1a13b9['id'];if(_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x350761['where']=_['merge'](_0x350761[_0xdb94('0x55')],{'$or':_[_0xdb94('0x69')](_0x350761[_0xdb94('0x7b')],function(_0x13b8fa){var _0x477a63={};_0x477a63[_0x13b8fa]={'$like':'%'+_0x2e04e3[_0xdb94('0x1f')]['filter']+'%'};return _0x477a63;})});}_0x350761=_[_0xdb94('0x33')]({},_0x350761,_0x2e04e3['options']);return db[_0xdb94('0x46')][_0xdb94('0x14')]({'where':_0x350761[_0xdb94('0x55')]})[_0xdb94('0x18')](function(_0x4f4109){_0x195c90[_0xdb94('0x14')]=_0x4f4109;if(_0x2e04e3[_0xdb94('0x1f')][_0xdb94('0x9e')]){_0x350761[_0xdb94('0x9b')]=[{'all':!![]}];}return db[_0xdb94('0x46')][_0xdb94('0x1e')](_0x350761);})[_0xdb94('0x18')](function(_0x791e36){_0x195c90[_0xdb94('0x9c')]=_0x791e36;return _0x195c90;});}})[_0xdb94('0x18')](respondWithFilteredResult(_0xbe8234,_0x350761))[_0xdb94('0x20')](handleError(_0xbe8234,null));};exports[_0xdb94('0x9f')]=function(_0x243de5,_0x14d124){var _0x40d014={'raw':!![],'where':{}};var _0x4ece04={};var _0x40054e={'count':0x0,'rows':[]};return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x243de5[_0xdb94('0x21')]['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0x14d124,null))[_0xdb94('0x18')](function(_0x4818f7){if(_0x4818f7){_0x4ece04[_0xdb94('0x77')]=_[_0xdb94('0x25')](db[_0xdb94('0x45')][_0xdb94('0x79')]);_0x4ece04['query']=_[_0xdb94('0x25')](_0x243de5[_0xdb94('0x1f')]);_0x4ece04[_0xdb94('0x7a')]=_[_0xdb94('0x7c')](_0x4ece04[_0xdb94('0x77')],_0x4ece04['query']);_0x40d014[_0xdb94('0x7b')]=_[_0xdb94('0x7c')](_0x4ece04[_0xdb94('0x77')],qs['fields'](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x7d')]));_0x40d014[_0xdb94('0x7b')]=_0x40d014['attributes']['length']?_0x40d014['attributes']:_0x4ece04[_0xdb94('0x77')];if(!_0x243de5['query'][_0xdb94('0x32')](_0xdb94('0x81'))){_0x40d014['limit']=qs[_0xdb94('0x13')](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x13')]);_0x40d014['offset']=qs['offset'](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x40d014[_0xdb94('0x7e')]=qs['sort'](_0x243de5[_0xdb94('0x1f')][_0xdb94('0x7f')]);_0x40d014['where']=qs[_0xdb94('0x7a')](_[_0xdb94('0x98')](_0x243de5[_0xdb94('0x1f')],_0x4ece04['filters']));_0x40d014[_0xdb94('0x55')][_0xdb94('0x99')]=_0x4818f7['id'];if(_0x243de5[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x40d014[_0xdb94('0x55')]=_[_0xdb94('0x33')](_0x40d014['where'],{'$or':_[_0xdb94('0x69')](_0x40d014[_0xdb94('0x7b')],function(_0x1f5328){var _0x5be65c={};_0x5be65c[_0x1f5328]={'$like':'%'+_0x243de5[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x5be65c;})});}_0x40d014=_[_0xdb94('0x33')]({},_0x40d014,_0x243de5[_0xdb94('0x9a')]);return db[_0xdb94('0x45')][_0xdb94('0x14')]({'where':_0x40d014[_0xdb94('0x55')]})['then'](function(_0x2f53d3){_0x40054e[_0xdb94('0x14')]=_0x2f53d3;if(_0x243de5['query']['includeAll']){_0x40d014['include']=[{'all':!![]}];}return db[_0xdb94('0x45')][_0xdb94('0x1e')](_0x40d014);})[_0xdb94('0x18')](function(_0x564abf){_0x40054e[_0xdb94('0x9c')]=_0x564abf;return _0x40054e;});}})[_0xdb94('0x18')](respondWithFilteredResult(_0x14d124,_0x40d014))[_0xdb94('0x20')](handleError(_0x14d124,null));};exports['getJscriptySessions']=function(_0x117e9f,_0xfb2007){var _0x2fea6d={'raw':!![],'where':{}};var _0x480790={};var _0x3c48f4={'count':0x0,'rows':[]};return db[_0xdb94('0x23')][_0xdb94('0x76')]({'where':{'id':_0x117e9f['params']['id']}})[_0xdb94('0x18')](handleEntityNotFound(_0xfb2007,null))['then'](function(_0x51d1ed){if(_0x51d1ed){_0x480790['model']=_['keys'](db[_0xdb94('0x4a')][_0xdb94('0x79')]);_0x480790[_0xdb94('0x1f')]=_[_0xdb94('0x25')](_0x117e9f[_0xdb94('0x1f')]);_0x480790[_0xdb94('0x7a')]=_[_0xdb94('0x7c')](_0x480790[_0xdb94('0x77')],_0x480790[_0xdb94('0x1f')]);_0x2fea6d['attributes']=_[_0xdb94('0x7c')](_0x480790['model'],qs[_0xdb94('0x7d')](_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x7d')]));_0x2fea6d[_0xdb94('0x7b')]=_0x2fea6d[_0xdb94('0x7b')][_0xdb94('0x26')]?_0x2fea6d['attributes']:_0x480790['model'];if(!_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0x2fea6d[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x117e9f[_0xdb94('0x1f')]['limit']);_0x2fea6d[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x11')]);}_0x2fea6d[_0xdb94('0x7e')]=qs[_0xdb94('0x7f')](_0x117e9f['query'][_0xdb94('0x7f')]);_0x2fea6d[_0xdb94('0x55')]=qs[_0xdb94('0x7a')](_[_0xdb94('0x98')](_0x117e9f[_0xdb94('0x1f')],_0x480790[_0xdb94('0x7a')]));_0x2fea6d['where'][_0xdb94('0x99')]=_0x51d1ed['id'];if(_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x80')]){_0x2fea6d[_0xdb94('0x55')]=_[_0xdb94('0x33')](_0x2fea6d[_0xdb94('0x55')],{'$or':_[_0xdb94('0x69')](_0x2fea6d['attributes'],function(_0x17f28c){var _0x32e32a={};_0x32e32a[_0x17f28c]={'$like':'%'+_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x80')]+'%'};return _0x32e32a;})});}_0x2fea6d=_[_0xdb94('0x33')]({},_0x2fea6d,_0x117e9f[_0xdb94('0x9a')]);return db[_0xdb94('0x4a')][_0xdb94('0x14')]({'where':_0x2fea6d[_0xdb94('0x55')]})[_0xdb94('0x18')](function(_0x55d3ab){_0x3c48f4[_0xdb94('0x14')]=_0x55d3ab;if(_0x117e9f[_0xdb94('0x1f')][_0xdb94('0x9e')]){_0x2fea6d[_0xdb94('0x9b')]=[{'all':!![]}];}return db['JscriptySessionReport'][_0xdb94('0x1e')](_0x2fea6d);})['then'](function(_0x160178){_0x3c48f4['rows']=_0x160178;return _0x3c48f4;});}})[_0xdb94('0x18')](respondWithFilteredResult(_0xfb2007,_0x2fea6d))[_0xdb94('0x20')](handleError(_0xfb2007,null));};exports[_0xdb94('0xa0')]=function(_0x46661c,_0x30f04c){try{if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0x58')]){throw new Error('No\x20ListId\x20specified');}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0xa1')]){throw new Error('No\x20association\x20keys\x20specified!');}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0xa2')]){throw new Error(_0xdb94('0xa3'));}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0xa4')]){throw new Error(_0xdb94('0xa5'));}var _0x20d0b0=_0x46661c['body'][_0xdb94('0xa1')][_0xdb94('0xa6')](',');var _0x4ce05e=_0x46661c[_0xdb94('0x34')][_0xdb94('0xa2')][_0xdb94('0xa6')](',');if(!_0x20d0b0[_0xdb94('0x26')]||!_0x4ce05e['length']||_0x20d0b0[_0xdb94('0x26')]!==_0x4ce05e[_0xdb94('0x26')]){throw new Error(_0xdb94('0xa7'));}_0x46661c[_0xdb94('0x34')]['fields']=_['zipObject'](_0x20d0b0,_0x4ce05e);if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0x7d')][_0xdb94('0x74')]){throw new Error(_0xdb94('0xa8'));}if(!_0x46661c[_0xdb94('0x34')][_0xdb94('0x7d')][_0xdb94('0xa9')]){throw new Error(_0xdb94('0xaa'));}var _0x3c5db9=path[_0xdb94('0x38')](config[_0xdb94('0xab')],_0xdb94('0xac'),_0x46661c[_0xdb94('0xad')]['filename']);fs['chmodSync'](_0x3c5db9,parseInt('0777',0x8));var _0xe04dea=require(_0xdb94('0xae'))[_0xdb94('0xaf')](path['join'](__dirname,_0xdb94('0xb0')),[_0x3c5db9,_0x46661c[_0xdb94('0x34')][_0xdb94('0xa1')],_0x46661c[_0xdb94('0x34')][_0xdb94('0xa2')],_0x46661c['body'][_0xdb94('0x58')],_0x46661c['body'][_0xdb94('0xb1')],_0x46661c['body'][_0xdb94('0x54')],_0x46661c[_0xdb94('0x34')][_0xdb94('0xa4')]]);return _0x30f04c[_0xdb94('0xf')](0xc8)['json']({'message':_0xdb94('0xb2'),'pid':_0xe04dea[_0xdb94('0xb3')]});}catch(_0x40d6fd){return _0x30f04c[_0xdb94('0xf')](0x1f4)['send'](_0x40d6fd);}};exports[_0xdb94('0xb4')]=function(_0x357a12,_0x2b3d3f){var _0x1b8197=fs['createReadStream'](_0x357a12[_0xdb94('0xad')]['path']);Papa['parse'](_0x1b8197,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x5824cc){return _0x2b3d3f['status'](0xc8)[_0xdb94('0x10')]({'file':_0x357a12[_0xdb94('0xad')],'fields':_0x5824cc[_0xdb94('0xb5')]['fields']});}});};exports[_0xdb94('0xb6')]=function(_0x2cfab7,_0x497cf6){return db[_0xdb94('0xb7')][_0xdb94('0x1e')]({'raw':!![],'attributes':['id'],'where':{'role':_0xdb94('0xb8')}})[_0xdb94('0x18')](function(_0x2bb0d8){var _0x431f29=![];if(!_0x2cfab7[_0xdb94('0x34')][_0xdb94('0x58')]){throw new Error(_0xdb94('0xb9'));}if(!_0x2cfab7[_0xdb94('0x34')]['binding'][_0xdb94('0x74')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x2cfab7[_0xdb94('0x34')][_0xdb94('0xba')][_0xdb94('0xa9')]){throw new Error(_0xdb94('0xaa'));}if(!_0x2cfab7['body'][_0xdb94('0xa4')]){throw new Error(_0xdb94('0xa5'));}var _0x3676ba=require(_0xdb94('0xae'))[_0xdb94('0xaf')](path[_0xdb94('0x38')](__dirname,_0xdb94('0xbb')),[_0x2cfab7[_0xdb94('0x21')]['id'],JSON['stringify'](_0x2cfab7[_0xdb94('0x34')]),JSON[_0xdb94('0xbc')](_0x2bb0d8)]);_0x3676ba['on'](_0xdb94('0xbd'),function(){_0x431f29=!![];return _0x497cf6[_0xdb94('0xf')](0xc8)[_0xdb94('0x10')]({'message':'start\x20child\x20process\x20correctly!','pid':_0x3676ba[_0xdb94('0xb3')]});});_0x3676ba['on'](_0xdb94('0xbe'),function(_0x2fb36c){if(_0x2fb36c&&!_0x431f29){return _0x497cf6[_0xdb94('0xf')](0x1f4)[_0xdb94('0x10')]({'message':_0xdb94('0xbf'),'pid':_0x3676ba['pid']});}});})[_0xdb94('0x20')](handleError(_0x497cf6,null));};exports[_0xdb94('0xc0')]=function(_0x39f7f6,_0x1ae6f4){return db['User']['findAll']({'raw':!![],'attributes':['id'],'where':{'role':_0xdb94('0xb8')}})[_0xdb94('0x18')](function(_0x30363f){var _0x5545cd=![];if(!_0x39f7f6['body'][_0xdb94('0x58')]){throw new Error(_0xdb94('0xb9'));}if(!_0x39f7f6[_0xdb94('0x34')][_0xdb94('0xba')][_0xdb94('0x74')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x39f7f6[_0xdb94('0x34')][_0xdb94('0xba')][_0xdb94('0xa9')]){throw new Error(_0xdb94('0xaa'));}if(!_0x39f7f6[_0xdb94('0x34')][_0xdb94('0xa4')]){throw new Error(_0xdb94('0xa5'));}var _0x44bbf2=require(_0xdb94('0xae'))[_0xdb94('0xaf')](path[_0xdb94('0x38')](__dirname,_0xdb94('0xc1')),[_0x39f7f6[_0xdb94('0x21')]['id'],JSON[_0xdb94('0xbc')](_0x39f7f6[_0xdb94('0x34')]),JSON['stringify'](_0x30363f)]);_0x44bbf2['on'](_0xdb94('0xbd'),function(){_0x5545cd=!![];return _0x1ae6f4['status'](0xc8)[_0xdb94('0x10')]({'message':'start\x20child\x20process\x20correctly!','pid':_0x44bbf2[_0xdb94('0xb3')]});});_0x44bbf2['on'](_0xdb94('0xbe'),function(_0x4dc8a8){if(_0x4dc8a8&&!_0x5545cd){return _0x1ae6f4[_0xdb94('0xf')](0x1f4)[_0xdb94('0x10')]({'message':_0xdb94('0xbf'),'pid':_0x44bbf2[_0xdb94('0xb3')]});}});})[_0xdb94('0x20')](handleError(_0x1ae6f4,null));};exports[_0xdb94('0xc2')]=function(_0x1f1ea3,_0x2128f6){var _0x13e689=['mail',_0xdb94('0xc3'),'sms',_0xdb94('0xc4'),_0xdb94('0xc5'),'whatsapp',_0xdb94('0xc6')];var _0x6e0474={'offset':0x0,'order':qs['sort'](_0xdb94('0xc7'))},_0x265782={'count':0x0,'rows':[]};Promise[_0xdb94('0xc8')]()[_0xdb94('0x18')](function(){if(_0x1f1ea3[_0xdb94('0x1f')]['channel']){if(!_[_0xdb94('0xc9')](_0x13e689,_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0xca')][_0xdb94('0xcb')]())){throw new Error(_0xdb94('0xcc'));}_0x13e689=[_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0xca')][_0xdb94('0xcb')]()];}if(_0x1f1ea3[_0xdb94('0x1f')]['range']){try{var _0x4042e2=JSON['parse'](_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0xcd')]);if(!moment(_0x4042e2['from'])[_0xdb94('0xce')]()){throw new Error(_0xdb94('0xcf'));}if(!moment(_0x4042e2['to'])['isValid']()){throw new Error('Invalid\x20date\x20for\x20range\x20to\x20filter');}}catch(_0x5f599f){throw new Error(_0xdb94('0xd0'));}}if(!_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0x32')](_0xdb94('0x81'))){_0x6e0474[_0xdb94('0x13')]=qs[_0xdb94('0x13')](_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0x13')]||0xa);_0x6e0474[_0xdb94('0x11')]=qs[_0xdb94('0x11')](_0x1f1ea3[_0xdb94('0x1f')][_0xdb94('0x11')]);}var _0x254fb0=_0x13e689[_0xdb94('0x69')](function(_0x28c17c){if(_0x28c17c===_0xdb94('0xc6')){var _0x2b5eb1={'attributes':['id',_0xdb94('0xd1'),_0xdb94('0x2d'),_0xdb94('0xd2'),_0xdb94('0xd3'),_0xdb94('0xd4'),_0xdb94('0xd5'),_0xdb94('0xd6'),_0xdb94('0xd7'),_0xdb94('0xd8'),_0xdb94('0xd9'),_0xdb94('0xda'),_0xdb94('0xdb'),_0xdb94('0xdc'),'UserId'],'where':{'ContactId':_0x1f1ea3[_0xdb94('0x21')]['id']},'include':[{'model':db[_0xdb94('0xb7')],'as':'User','attributes':['id','name','fullname',_0xdb94('0x2c')]}],'order':[[_0xdb94('0xd9'),'DESC']]};if(_0x1f1ea3[_0xdb94('0x1f')]['range']){_0x2b5eb1['where'][_0xdb94('0xd9')]={'$gte':_0x4042e2['from'],'$lte':_0x4042e2['to']};}return db[_0xdb94('0xdd')][_0xdb94('0xde')](_0x2b5eb1)[_0xdb94('0x18')](function(_0x3aee7c){_0x265782['count']+=_0x3aee7c[_0xdb94('0x14')];return _[_0xdb94('0x69')](_0x3aee7c['rows'],function(_0x336902){var _0x4c8e62=_0x336902[_0xdb94('0x35')]({'plain':!![]});_0x4c8e62['channel']=_0x28c17c;if(_0x4c8e62[_0xdb94('0xb7')]){_0x4c8e62[_0xdb94('0xb7')]={'id':_0x4c8e62[_0xdb94('0xb7')]['id'],'name':_0x4c8e62[_0xdb94('0xb7')]['name'],'fullname':_0x4c8e62[_0xdb94('0xb7')]['fullname'],'alias':_0x4c8e62['User'][_0xdb94('0x2c')]};}return _0x4c8e62;});});}else{var _0x2fd3cf=_[_0xdb94('0xdf')](_0x28c17c)+(_0x28c17c===_0xdb94('0xc3')?_0xdb94('0xe0'):'Account');var _0x597af9={'attributes':['id',_0xdb94('0xe1'),_0xdb94('0xe2'),_0xdb94('0xd9'),_0xdb94('0xd8'),_0xdb94('0xe3'),_0xdb94('0xe4'),_0xdb94('0xe5'),_0xdb94('0xe6'),_0x2fd3cf+'Id'],'where':{'ContactId':_0x1f1ea3[_0xdb94('0x21')]['id']},'include':[{'model':db[_0x2fd3cf],'as':_0xdb94('0xe7'),'attributes':['id',_0xdb94('0x60'),_0xdb94('0xe8')]},{'model':db[_0xdb94('0xb7')],'as':_0xdb94('0xe9'),'attributes':['id','name','fullname']},{'model':db['Tag'],'as':'Tags','attributes':['id','name',_0xdb94('0xea')],'through':{'attributes':[]}}],'order':[[_0xdb94('0xd9'),_0xdb94('0xeb')]]};if(_0x1f1ea3[_0xdb94('0x1f')]['range']){_0x597af9[_0xdb94('0x55')][_0xdb94('0xd9')]={'$gte':_0x4042e2[_0xdb94('0x39')],'$lte':_0x4042e2['to']};}switch(_0x28c17c){case _0xdb94('0xc3'):_0x597af9[_0xdb94('0x7b')]['push'](_0xdb94('0xec'),_0xdb94('0xed'),_0xdb94('0xee'),_0xdb94('0xef'),'osName',_0xdb94('0xf0'),_0xdb94('0xf1'),'ratingValue','referer');break;case _0xdb94('0xf2'):_0x597af9[_0xdb94('0x7b')][_0xdb94('0x57')](_0xdb94('0xf3'),'substatus');break;case'openchannel':_0x597af9[_0xdb94('0x7b')]['push'](_0xdb94('0xf4'),_0xdb94('0xf5'));break;}return db[_[_0xdb94('0xdf')](_0x28c17c)+'Interaction'][_0xdb94('0xde')](_0x597af9)[_0xdb94('0x18')](function(_0x4ef47e){_0x265782['count']+=_0x4ef47e[_0xdb94('0x14')];return _[_0xdb94('0x69')](_0x4ef47e[_0xdb94('0x9c')],function(_0x303e39){var _0x114c1a=_0x303e39[_0xdb94('0x35')]({'plain':!![]});_0x114c1a[_0xdb94('0xca')]=_0x28c17c;if(_0x114c1a[_0xdb94('0xe9')]){_0x114c1a[_0xdb94('0xe9')]={'id':_0x114c1a[_0xdb94('0xe9')]['id'],'name':_0x114c1a[_0xdb94('0xe9')][_0xdb94('0x60')],'fullname':_0x114c1a[_0xdb94('0xe9')][_0xdb94('0xf6')]};}return _0x114c1a;});});}});return Promise['all'](_0x254fb0);})[_0xdb94('0x18')](function(_0x5220f8){return _(_0x5220f8)[_0xdb94('0xf7')]()[_0xdb94('0xf8')]('createdAt')['reverse']()[_0xdb94('0xf9')]();})[_0xdb94('0x18')](function(_0x19e647){_0x265782['rows']=_0x6e0474[_0xdb94('0x13')]?_0x19e647[_0xdb94('0xfa')](_0x6e0474[_0xdb94('0x11')],_0x6e0474[_0xdb94('0x11')]+_0x6e0474[_0xdb94('0x13')]):_0x19e647;return _0x265782;})[_0xdb94('0x18')](respondWithFilteredResult(_0x2128f6,_0x6e0474))[_0xdb94('0x20')](handleError(_0x2128f6,null));};
\ No newline at end of file