Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / cmContact / cmContact.controller.js
index 74124ce..93df52f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4e24=['table','setFields','id\x20=\x20?','phone','CmHopper','rawAttributes','fields','options','getTags','setTags','getHoppers','ContactId','includeAll','getHopperHistories','getHopperFinals','include','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','Incorrect\x20binding\x20parameters\x20passed!','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','server/files/tmp','0777','child_process','../../components/import/cm/csv','CompanyId','pid','upload','createReadStream','file','parse','meta','import','binding','fork','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','getJourney','mail','chat','sms','openchannel','fax','whatsapp','voice','-createdAt','channel','includes','toLowerCase','Invalid\x20channel','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','Invalid\x20createdAt\x20filter','uniqueid','destination','callerid','starttime','endtime','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','VoiceCallReport','findAndCountAll','alias','Website','closedAt','secondDisposition','thirdDisposition','UserId','key','Owner','fullname','color','browserName','customerIp','deviceModel','ratingType','ratingValue','referer','subject','substatus','externalUrl','threadId','startCase','Interaction','sortBy','slice','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','register','status','end','count','offset','limit','Content-Range','json','destroy','error','stack','name','send','index','CmContact','describe','then','keys','startsWith','push','CmCustomField','findOne','trimStart','cf_','all','length','type','model','query','attributes','intersection','hasOwnProperty','nolimit','order','sort','where','filters','pick','field','from','tools_tags','select','cm_contacts','left_join','cm_user_has_contacts','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','ct.CmContactId\x20=\x20c.id','t.id\x20=\x20ct.TagId','c.deletedAt\x20IS\x20NULL','expr','search','sqlOperator','conditions','find','Tag','value','map','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','and','uc.UserId\x20=\x20?','dateOfBirth','fieldType','datetime','DATE','buildExpression','text','isNil','Contact','isEmpty','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','filter','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.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','group','c.id','Sequelize','QueryTypes','SELECT','clone','DESC','t.id\x20IN\x20?','resolve','agent','User','user','getLists','role','sequelize','toString','keyBy','merge','c.lastName','c.phone','c.mobile','c.fax','c.email','c.createdAt','c.deletedAt','c.CompanyId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','split','rows','catch','params','tags','displayName','findAll','columnName','custom','values','body','get','mergeWith','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','create','ChatMessage','update','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','OpenchannelInteraction','OpenchannelMessage','CmHopperFinal','CmHopperHistory','ReportAgentPreview','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','SmsQueueReport','JscriptySessionReport','WhatsappInteraction','WhatsappQueueReport','join','bulkCreate','each','duplicates','$or','findOrCreate','spread','show','omit','format','$and','pickBy'];(function(_0x5f1391,_0x19c132){var _0x50ebe3=function(_0x3d00a3){while(--_0x3d00a3){_0x5f1391['push'](_0x5f1391['shift']());}};_0x50ebe3(++_0x19c132);}(_0x4e24,0x64));var _0x44e2=function(_0x5735e6,_0x209ce3){_0x5735e6=_0x5735e6-0x0;var _0x1bb10e=_0x4e24[_0x5735e6];return _0x1bb10e;};'use strict';var pdf=require(_0x44e2('0x0'));var emlformat=require(_0x44e2('0x1'));var rimraf=require(_0x44e2('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x44e2('0x3'));var rp=require(_0x44e2('0x4'));var moment=require(_0x44e2('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x44e2('0x6'));var path=require(_0x44e2('0x7'));var sox=require(_0x44e2('0x8'));var csv=require(_0x44e2('0x9'));var ejs=require(_0x44e2('0xa'));var fs=require('fs');var _=require(_0x44e2('0xb'));var squel=require(_0x44e2('0xc'));var crypto=require(_0x44e2('0xd'));var jsforce=require(_0x44e2('0xe'));var deskjs=require(_0x44e2('0xf'));var toCsv=require(_0x44e2('0x9'));var querystring=require(_0x44e2('0x10'));var Papa=require(_0x44e2('0x11'));var Redis=require(_0x44e2('0x12'));var authService=require(_0x44e2('0x13'));var qs=require(_0x44e2('0x14'));var as=require(_0x44e2('0x15'));var hardwareService=require(_0x44e2('0x16'));var logger=require('../../config/logger')(_0x44e2('0x17'));var utils=require(_0x44e2('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x44e2('0x19'));var db=require('../../mysqldb')['db'];config[_0x44e2('0x1a')]=_[_0x44e2('0x1b')](config[_0x44e2('0x1a')],{'host':_0x44e2('0x1c'),'port':0x18eb});var socket=require(_0x44e2('0x1d'))(new Redis(config[_0x44e2('0x1a')]));require(_0x44e2('0x1e'))[_0x44e2('0x1f')](socket);function respondWithStatusCode(_0x3581da,_0x2858ce){_0x2858ce=_0x2858ce||0xcc;return function(_0x4cb31f){if(_0x4cb31f){return _0x3581da['sendStatus'](_0x2858ce);}return _0x3581da[_0x44e2('0x20')](_0x2858ce)[_0x44e2('0x21')]();};}function respondWithResult(_0x1f3977,_0x4bc1fb){_0x4bc1fb=_0x4bc1fb||0xc8;return function(_0x57f148){if(_0x57f148){return _0x1f3977[_0x44e2('0x20')](_0x4bc1fb)['json'](_0x57f148);}};}function respondWithFilteredResult(_0x1bf3ee,_0x5edba0){return function(_0x4cb46b){if(_0x4cb46b){var _0xebf851=_0x4cb46b[_0x44e2('0x22')],_0xf94e7b=_0x5edba0[_0x44e2('0x23')],_0x50a6cd=_0x5edba0[_0x44e2('0x23')]+_0x5edba0[_0x44e2('0x24')],_0x1b8029;if(_0x50a6cd>=_0xebf851){_0x50a6cd=_0xebf851;_0x1b8029=0xc8;}else{_0x1b8029=0xce;}_0x1bf3ee[_0x44e2('0x20')](_0x1b8029);return _0x1bf3ee['set'](_0x44e2('0x25'),_0xf94e7b+'-'+_0x50a6cd+'/'+_0xebf851)[_0x44e2('0x26')](_0x4cb46b);}return null;};}function patchUpdates(_0x48c8b2){return function(_0x2cb0f0){try{jsonpatch['apply'](_0x2cb0f0,_0x48c8b2,!![]);}catch(_0x177e06){return BPromise['reject'](_0x177e06);}return _0x2cb0f0['save']();};}function saveUpdates(_0x45b381,_0x1f0f7c){return function(_0x170cd7){if(_0x170cd7){return _0x170cd7['update'](_0x45b381)['then'](function(_0x5b164b){return _0x5b164b;});}return null;};}function removeEntity(_0x276ae2,_0x42c9ad){return function(_0x1c3e12){if(_0x1c3e12){return _0x1c3e12[_0x44e2('0x27')]()['then'](function(){_0x276ae2[_0x44e2('0x20')](0xcc)[_0x44e2('0x21')]();});}};}function handleEntityNotFound(_0x23801a,_0x25df78){return function(_0x1b0d7c){if(!_0x1b0d7c){_0x23801a['sendStatus'](0x194);}return _0x1b0d7c;};}function handleError(_0x4a3b97,_0x32ee08){_0x32ee08=_0x32ee08||0x1f4;return function(_0x3ddf6b){logger[_0x44e2('0x28')](_0x3ddf6b[_0x44e2('0x29')]);if(_0x3ddf6b[_0x44e2('0x2a')]){delete _0x3ddf6b[_0x44e2('0x2a')];}_0x4a3b97['status'](_0x32ee08)[_0x44e2('0x2b')](_0x3ddf6b);};}exports[_0x44e2('0x2c')]=function(_0x41622f,_0x5b0ad4){var _0x50967a={},_0x58e627={},_0x49af30={'count':0x0,'rows':[]};return db[_0x44e2('0x2d')][_0x44e2('0x2e')]()[_0x44e2('0x2f')](function(_0x2f2e40){var _0x5d7c86=[];for(var _0x57b586=0x0;_0x57b586<Object[_0x44e2('0x30')](_0x2f2e40)['length'];_0x57b586++){var _0x31c5e0=Object[_0x44e2('0x30')](_0x2f2e40)[_0x57b586];if(_[_0x44e2('0x31')](_0x31c5e0,'cf_')){_0x5d7c86[_0x44e2('0x32')](db[_0x44e2('0x33')][_0x44e2('0x34')]({'where':{'id':_[_0x44e2('0x35')](_0x31c5e0,_0x44e2('0x36'))},'raw':!![]}));}}return BPromise[_0x44e2('0x37')](_0x5d7c86)['then'](function(_0x28163d){for(var _0x337cab=0x0;_0x337cab<_0x28163d[_0x44e2('0x38')];_0x337cab++){if(_0x28163d[_0x337cab]){var _0x270b8a=_0x44e2('0x36')+_0x28163d[_0x337cab]['id'];var _0x1db8f5=_0x2f2e40[_0x270b8a];_0x1db8f5['fieldType']=_0x28163d[_0x337cab][_0x44e2('0x39')];}}return _0x2f2e40;});})[_0x44e2('0x2f')](function(_0x440c30){_0x58e627[_0x44e2('0x3a')]=_[_0x44e2('0x30')](_0x440c30);_0x58e627[_0x44e2('0x3b')]=_[_0x44e2('0x30')](_0x41622f[_0x44e2('0x3b')]);_0x58e627['filters']=_['intersection'](_0x58e627[_0x44e2('0x3a')],_0x58e627[_0x44e2('0x3b')]);_0x50967a[_0x44e2('0x3c')]=_[_0x44e2('0x3d')](_0x58e627[_0x44e2('0x3a')],qs['fields'](_0x41622f[_0x44e2('0x3b')]['fields']));_0x50967a[_0x44e2('0x3c')]=_0x50967a[_0x44e2('0x3c')][_0x44e2('0x38')]?_0x50967a[_0x44e2('0x3c')]:_0x58e627[_0x44e2('0x3a')];if(!_0x41622f[_0x44e2('0x3b')][_0x44e2('0x3e')](_0x44e2('0x3f'))){_0x50967a[_0x44e2('0x24')]=qs[_0x44e2('0x24')](_0x41622f[_0x44e2('0x3b')][_0x44e2('0x24')]);_0x50967a['offset']=qs[_0x44e2('0x23')](_0x41622f[_0x44e2('0x3b')]['offset']);}_0x50967a[_0x44e2('0x40')]=qs[_0x44e2('0x41')](_0x41622f[_0x44e2('0x3b')]['sort']);_0x50967a[_0x44e2('0x42')]=qs[_0x44e2('0x43')](_[_0x44e2('0x44')](_0x41622f[_0x44e2('0x3b')],_0x58e627[_0x44e2('0x43')]),_0x440c30);var _0x4bd7bd=[];var _0x5673d9=squel['select']()[_0x44e2('0x45')]('id')[_0x44e2('0x45')](_0x44e2('0x2a'))['field']('color')[_0x44e2('0x46')](_0x44e2('0x47'));var _0x4982c4=squel[_0x44e2('0x48')]()[_0x44e2('0x46')](_0x44e2('0x49'),'c')[_0x44e2('0x4a')](_0x44e2('0x4b'),'uc',_0x44e2('0x4c'))[_0x44e2('0x4a')](_0x44e2('0x4d'),'ct',_0x44e2('0x4e'))[_0x44e2('0x4a')](_0x44e2('0x47'),'t',_0x44e2('0x4f'))['where'](_0x44e2('0x50'));var _0x1b69c7=squel[_0x44e2('0x51')]();var _0x17d6b0=[];var _0x402bb7=squel[_0x44e2('0x51')]();var _0x4bd3a9;if(_0x41622f['query']['search']){_0x4bd3a9=as['parseSearch'](_0x41622f[_0x44e2('0x3b')][_0x44e2('0x52')]);var _0x119fe1=_0x4bd3a9[_0x44e2('0x53')];for(var _0xc18d95=0x0;_0xc18d95<_0x4bd3a9['conditions'][_0x44e2('0x38')];_0xc18d95++){var _0x4ac37b=_0x4bd3a9[_0x44e2('0x54')][_0xc18d95];var _0x527538='c';var _0x10e481=_(_0x440c30)['keys']()[_0x44e2('0x55')](function(_0x481479){return _0x481479===_0x4ac37b[_0x44e2('0x45')];});if(_0x10e481)_0x10e481=_0x440c30[_0x4ac37b['field']];if(!_0x10e481){if(_0x4ac37b[_0x44e2('0x45')]===_0x44e2('0x56')){var _0xe9f23e=_0x4ac37b[_0x44e2('0x57')]['split'](',')[_0x44e2('0x58')](function(_0x35955e){return Number(_0x35955e);});_0xe9f23e[_0x44e2('0x59')](function(_0xb3d45b){_0x402bb7['or'](_0x44e2('0x5a'),'%,'+_0xb3d45b+',%');});_0x17d6b0=_['union'](_0x17d6b0,_0xe9f23e);}else if(_0x4ac37b['field']==='User'){_0x1b69c7[_0x44e2('0x5b')](_0x44e2('0x5c'),_0x4ac37b['value']);}}else{if(_0x4ac37b[_0x44e2('0x45')]===_0x44e2('0x5d')||_0x10e481[_0x44e2('0x5e')]===_0x44e2('0x5f'))_0x4ac37b['castTo']=_0x44e2('0x60');var _0x5bef55=as[_0x44e2('0x61')](_0x527538,_0x10e481[_0x44e2('0x39')],_0x4ac37b);_0x1b69c7[_0x119fe1](_0x5bef55[_0x44e2('0x62')],_0x5bef55['value']['start'],_0x5bef55[_0x44e2('0x57')][_0x44e2('0x21')]);}}}else{var _0x5934b6=_(Object['keys'](_0x41622f[_0x44e2('0x3b')]))[_0x44e2('0x58')](function(_0x46a38d){return _0x440c30[_0x44e2('0x3e')](_0x46a38d)?_0x46a38d:undefined;})['filter'](function(_0x2bc8e0){return!_[_0x44e2('0x63')](_0x2bc8e0);})[_0x44e2('0x57')]();if(_0x41622f[_0x44e2('0x3b')]['Contact'])_0x5934b6[_0x44e2('0x32')](_0x44e2('0x64'));if(!_[_0x44e2('0x65')](_0x5934b6)){_0x5934b6[_0x44e2('0x59')](function(_0x3c31ec){if(_0x3c31ec===_0x44e2('0x66')){_0x4982c4[_0x44e2('0x42')](_0x44e2('0x67'),[][_0x44e2('0x68')](_0x41622f[_0x44e2('0x3b')][_0x3c31ec]));}else if(_0x3c31ec==='Contact'){var _0x3b3384='%'+_0x41622f[_0x44e2('0x3b')][_0x3c31ec]+'%';_0x4982c4[_0x44e2('0x42')](_0x44e2('0x69'),_0x3b3384);}else{_0x4982c4[_0x44e2('0x42')]('c.'+_0x3c31ec+_0x44e2('0x6a'),_0x41622f['query'][_0x3c31ec]);}});}if(_0x41622f[_0x44e2('0x3b')][_0x44e2('0x6b')]){_0x17d6b0=_[_0x44e2('0x6c')](_0x41622f[_0x44e2('0x3b')][_0x44e2('0x6b')])?_0x41622f[_0x44e2('0x3b')][_0x44e2('0x6b')]:new Array(_0x41622f[_0x44e2('0x3b')][_0x44e2('0x6b')]);_0x17d6b0[_0x44e2('0x59')](function(_0x413912){_0x402bb7['or'](_0x44e2('0x5a'),'%,'+_0x413912+',%');});}if(_0x41622f['query'][_0x44e2('0x6d')]){var _0x1f781c=_0x41622f['query'][_0x44e2('0x6d')]['replace']('\x5c','\x5c\x5c')[_0x44e2('0x6e')](/'/g,'\x27\x27');if(_0x1f781c['split']('\x20')[_0x44e2('0x38')]>0x1){_0x1b69c7['or'](_0x44e2('0x6f'),qs[_0x44e2('0x70')](_0x1f781c),null);}else{if(qs[_0x44e2('0x71')](_0x1f781c)){_0x1b69c7['or'](_0x44e2('0x72'),_0x1f781c+'%');_0x1b69c7['or'](_0x44e2('0x73'),_0x1f781c+'%');_0x1b69c7['or']('c.mobile\x20LIKE\x20?',_0x1f781c+'%');_0x1b69c7['or'](_0x44e2('0x74'),_0x1f781c+'%');}else if(qs[_0x44e2('0x75')](_0x1f781c)){_0x1b69c7['or'](_0x44e2('0x76'),_0x1f781c+'%');}else{_0x1b69c7['or'](_0x44e2('0x77'),'%'+_0x1f781c+'%');_0x1b69c7['or'](_0x44e2('0x78'),'%'+_0x1f781c+'%');_0x1b69c7['or'](_0x44e2('0x76'),'%'+_0x1f781c+'%');}}}}_0x4982c4[_0x44e2('0x42')](_0x1b69c7);_0x4982c4[_0x44e2('0x79')](_0x44e2('0x7a'));var _0x442bbb={'type':db[_0x44e2('0x7b')][_0x44e2('0x7c')][_0x44e2('0x7d')],'raw':!![]};var _0xb9adf7=_0x4982c4[_0x44e2('0x7e')]()[_0x44e2('0x45')](_0x44e2('0x7a'));if(_0x50967a['order']){_0x50967a[_0x44e2('0x40')][_0x44e2('0x59')](function(_0x2c5d1a){_0x4982c4[_0x44e2('0x40')]('c.'+_0x2c5d1a[0x0],_0x2c5d1a[0x1]===_0x44e2('0x7f')?![]:!![]);});}if(!_[_0x44e2('0x65')](_0x17d6b0)){_0x4982c4['having'](_0x402bb7);_0xb9adf7[_0x44e2('0x42')](_0x44e2('0x80'),_0x17d6b0);}BPromise[_0x44e2('0x81')]()[_0x44e2('0x2f')](function(){if(!_0x4bd3a9)return;if(_0x41622f['user']['role']!==_0x44e2('0x82'))return;if(!_['some'](_0x4bd3a9[_0x44e2('0x54')],[_0x44e2('0x45'),_0x44e2('0x83')])){return _0x41622f[_0x44e2('0x84')][_0x44e2('0x85')]({'attributes':['id'],'raw':!![]})['then'](function(_0x37acab){if(_[_0x44e2('0x65')](_0x37acab)){_0xb9adf7[_0x44e2('0x42')]('c.ListId\x20IS\x20NULL');_0x4982c4[_0x44e2('0x42')]('c.ListId\x20IS\x20NULL');}else{_0xb9adf7[_0x44e2('0x42')]('c.ListId\x20IN\x20?',_[_0x44e2('0x58')](_0x37acab,'id'));_0x4982c4[_0x44e2('0x42')]('c.ListId\x20IN\x20?',_[_0x44e2('0x58')](_0x37acab,'id'));}});}})['then'](function(){if(_0x41622f[_0x44e2('0x84')][_0x44e2('0x86')]===_0x44e2('0x82')&&!_0x4bd3a9&&!_0x41622f[_0x44e2('0x3b')][_0x44e2('0x66')])return[];return db[_0x44e2('0x87')][_0x44e2('0x3b')](_0xb9adf7[_0x44e2('0x88')](),_0x442bbb);})[_0x44e2('0x2f')](function(_0x43525c){_0x49af30['count']=_0x43525c[_0x44e2('0x38')];if(_0x49af30[_0x44e2('0x22')]===0x0)return[];return db[_0x44e2('0x87')]['query'](_0x5673d9['toString'](),_0x442bbb)[_0x44e2('0x2f')](function(_0x5e1cef){_0x4bd7bd=_[_0x44e2('0x89')](_0x5e1cef,'id');_0x442bbb=_[_0x44e2('0x8a')](_0x442bbb,{'model':db[_0x44e2('0x2d')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x41622f[_0x44e2('0x3b')]['fields']){_0x50967a[_0x44e2('0x3c')][_0x44e2('0x59')](function(_0x4a55ab){_0x4982c4[_0x44e2('0x45')]('c.'+_0x4a55ab);});}else{_0x4982c4[_0x44e2('0x45')]('c.id');_0x4982c4[_0x44e2('0x45')]('c.firstName');_0x4982c4[_0x44e2('0x45')](_0x44e2('0x8b'));_0x4982c4[_0x44e2('0x45')](_0x44e2('0x8c'));_0x4982c4[_0x44e2('0x45')](_0x44e2('0x8d'));_0x4982c4[_0x44e2('0x45')](_0x44e2('0x8e'));_0x4982c4['field'](_0x44e2('0x8f'));_0x4982c4[_0x44e2('0x45')]('c.ListId');_0x4982c4['field'](_0x44e2('0x90'));_0x4982c4['field'](_0x44e2('0x91'));_0x4982c4[_0x44e2('0x45')](_0x44e2('0x92'));_0x4982c4[_0x44e2('0x45')](_0x44e2('0x93'),_0x44e2('0x94'));}if(_0x50967a[_0x44e2('0x24')])_0x4982c4['limit'](_0x50967a[_0x44e2('0x24')]);if(_0x50967a['offset'])_0x4982c4['offset'](_0x50967a[_0x44e2('0x23')]);return db[_0x44e2('0x87')][_0x44e2('0x3b')](_0x4982c4[_0x44e2('0x88')](),_0x442bbb);});})[_0x44e2('0x2f')](function(_0x408dae){_0x408dae['forEach'](function(_0x15cea0){if(_0x15cea0[_0x44e2('0x94')]){_0x15cea0[_0x44e2('0x95')]=[];_0x15cea0[_0x44e2('0x94')][_0x44e2('0x96')](',')[_0x44e2('0x59')](function(_0x12a5e8){_0x15cea0[_0x44e2('0x95')][_0x44e2('0x32')](_0x4bd7bd[_0x12a5e8]);});}delete _0x15cea0[_0x44e2('0x94')];});_0x49af30[_0x44e2('0x97')]=_0x408dae;return _0x49af30;})[_0x44e2('0x2f')](respondWithFilteredResult(_0x5b0ad4,_0x50967a));})[_0x44e2('0x98')](handleError(_0x5b0ad4,null));};exports[_0x44e2('0x27')]=function(_0x15049b,_0x492a33){return db[_0x44e2('0x2d')][_0x44e2('0x55')]({'where':{'id':_0x15049b[_0x44e2('0x99')]['id']}})['then'](handleEntityNotFound(_0x492a33,null))['then'](removeEntity(_0x492a33,null))[_0x44e2('0x98')](handleError(_0x492a33,null));};exports[_0x44e2('0x2e')]=function(_0x206c47,_0x3c2dcc){return db['CmContact'][_0x44e2('0x2e')]()[_0x44e2('0x2f')](function(_0x3666a9){delete _0x3666a9[_0x44e2('0x9a')];for(var _0xaf31c=0x0;_0xaf31c<Object[_0x44e2('0x30')](_0x3666a9)[_0x44e2('0x38')];_0xaf31c++){var _0x46974a=Object[_0x44e2('0x30')](_0x3666a9)[_0xaf31c];if(!_[_0x44e2('0x31')](_0x46974a,_0x44e2('0x36'))){_0x3666a9[_0x46974a]['columnName']=_0x46974a;_0x3666a9[_0x46974a][_0x44e2('0x9b')]=_0x46974a;}}return _0x3666a9;})['then'](function(_0x37341c){var _0x4465e8={'where':{'$or':[{'ListId':_0x206c47[_0x44e2('0x3b')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x44e2('0x33')][_0x44e2('0x9c')](_0x4465e8)[_0x44e2('0x2f')](function(_0x1b1e3f){for(var _0x17f254=0x0;_0x17f254<_0x1b1e3f['length'];_0x17f254++){var _0x3283fe=_0x44e2('0x36')+_0x1b1e3f[_0x17f254]['id'];_0x37341c[_0x3283fe][_0x44e2('0x9d')]=_0x3283fe;_0x37341c[_0x3283fe][_0x44e2('0x9b')]=_0x1b1e3f[_0x17f254]['alias'];_0x37341c[_0x3283fe][_0x44e2('0x9e')]={'type':_0x1b1e3f[_0x17f254]['type'],'values':_0x1b1e3f[_0x17f254][_0x44e2('0x9f')]};}Object['keys'](_0x37341c)['forEach'](function(_0x2bdb42){if(!_0x37341c[_0x2bdb42][_0x44e2('0x3e')](_0x44e2('0x9d'))){delete _0x37341c[_0x2bdb42];}});return _0x37341c;});})[_0x44e2('0x2f')](respondWithResult(_0x3c2dcc,null))[_0x44e2('0x98')](handleError(_0x3c2dcc,null));};exports[_0x44e2('0x8a')]=function(_0x46471e,_0x3ca7b){var _0x2ff11c;var _0x4e46b8;var _0x547f21;if(_0x46471e[_0x44e2('0xa0')]['id']){delete _0x46471e['body']['id'];}return db[_0x44e2('0x2d')][_0x44e2('0x9c')]({'where':{'id':[_0x46471e['body']['to'],_0x46471e[_0x44e2('0xa0')][_0x44e2('0x46')]]}})[_0x44e2('0x2f')](function(_0x2a997b){if(_0x2a997b){if(_0x2a997b[_0x44e2('0x38')]!==0x2){return null;}_0x2a997b[0x0]=_0x2a997b[0x0][_0x44e2('0xa1')]({'plain':!![]});_0x2a997b[0x1]=_0x2a997b[0x1]['get']({'plain':!![]});delete _0x2a997b[0x0]['id'];delete _0x2a997b[0x1]['id'];return _[_0x44e2('0xa2')](_0x2a997b[0x0],_0x2a997b[0x1],function(_0x2c3f77,_0x25fb39){if(Array[_0x44e2('0x6c')](_0x25fb39)&&!_0x25fb39[_0x44e2('0x38')]){return _0x2c3f77;}else if(!_0x25fb39){return _0x2c3f77;}});}})[_0x44e2('0x2f')](handleEntityNotFound(_0x3ca7b,null))[_0x44e2('0x2f')](function(_0x3b1885){if(_0x3b1885){if(_0x3b1885[_0x44e2('0x9a')]&&_['isArray'](_0x3b1885[_0x44e2('0x9a')])){_0x3b1885[_0x44e2('0x9a')]=_0x3b1885['tags']['join']();}logger[_0x44e2('0xa3')](_0x44e2('0xa4'),_0x46471e[_0x44e2('0xa0')]['to'],_0x46471e[_0x44e2('0xa0')][_0x44e2('0x46')]);return db['CmHopper'][_0x44e2('0x27')]({'where':{'ContactId':[_0x46471e[_0x44e2('0xa0')]['to'],_0x46471e['body']['from']]}})['then'](function(_0x3edbfb){logger[_0x44e2('0xa3')](_0x44e2('0xa5'),_0x3edbfb);return db[_0x44e2('0xa6')]['destroy']({'where':{'ContactId':[_0x46471e[_0x44e2('0xa0')]['to'],_0x46471e['body'][_0x44e2('0x46')]]}})['then'](function(_0x10bc3e){logger[_0x44e2('0xa3')]('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x10bc3e);return db[_0x44e2('0x2d')][_0x44e2('0xa7')](_0x3b1885);});});}})[_0x44e2('0x2f')](function(_0x3707c6){if(_0x3707c6){_0x2ff11c=_0x3707c6;_0x4e46b8={'ContactId':_0x2ff11c['id']};_0x547f21={'where':{'ContactId':[_0x46471e[_0x44e2('0xa0')]['to'],_0x46471e['body']['from']]}};return db['ChatInteraction']['update'](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xa8')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db['ChatOfflineMessage']['update'](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xaa')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xab')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xaa')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xab')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xac')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xad')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xae')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db['FaxMessage'][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xaf')]['update'](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db[_0x44e2('0xb0')]['update'](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db[_0x44e2('0xb1')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xb2')]['update'](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xb3')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db['VoiceCallReport']['update'](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db[_0x44e2('0xb4')]['update'](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xb5')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db[_0x44e2('0xb6')]['update'](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db[_0x44e2('0xb7')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xb8')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db[_0x44e2('0xb9')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xba')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})['then'](function(){if(_0x2ff11c){return db['WhatsappMessage'][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db[_0x44e2('0xbb')][_0x44e2('0xa9')](_0x4e46b8,_0x547f21);}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return db['CmContact']['destroy']({'where':{'id':[_0x46471e[_0x44e2('0xa0')]['to'],_0x46471e[_0x44e2('0xa0')][_0x44e2('0x46')]]}});}})[_0x44e2('0x2f')](function(){if(_0x2ff11c){return _0x2ff11c;}})['then'](respondWithResult(_0x3ca7b,null))[_0x44e2('0x98')](handleError(_0x3ca7b,null));};exports['create']=function(_0x33cf7d,_0x47167c){return db['CmContact'][_0x44e2('0x2e')]()[_0x44e2('0x2f')](function(_0x54abbd){if(_0x33cf7d[_0x44e2('0xa0')]['tags']&&_[_0x44e2('0x6c')](_0x33cf7d[_0x44e2('0xa0')][_0x44e2('0x9a')])){if(_0x33cf7d[_0x44e2('0xa0')][_0x44e2('0x9a')][_0x44e2('0x38')]){_0x33cf7d['body']['tags']=_0x33cf7d[_0x44e2('0xa0')]['tags'][_0x44e2('0xbc')](';')+';';}else{_0x33cf7d[_0x44e2('0xa0')][_0x44e2('0x9a')]=null;}}else{_0x33cf7d[_0x44e2('0xa0')]['tags']=null;}return db[_0x44e2('0x2d')][_0x44e2('0xa7')](_0x33cf7d[_0x44e2('0xa0')],{'fields':_[_0x44e2('0x30')](_0x54abbd),'raw':!![]});})['then'](respondWithResult(_0x47167c,0xc9))['catch'](handleError(_0x47167c,null));};exports[_0x44e2('0xbd')]=function(_0x3539b9,_0x260201){var _0x32dbcb=[];var _0x3e970a=0x0;var _0x45d903=0x0;var _0x268816=0x0;return db[_0x44e2('0x2d')][_0x44e2('0x2e')]()[_0x44e2('0x2f')](function(_0x32ab76){return BPromise[_0x44e2('0xbe')](_0x3539b9[_0x44e2('0xa0')],function(_0x3c1ab3){var _0x430781={'where':{'$or':[]},'defaults':_0x3c1ab3,'fields':_[_0x44e2('0x30')](_0x32ab76),'raw':!![]};if(_0x3c1ab3[_0x44e2('0xbf')]){for(var _0x5a389f=0x0;_0x5a389f<_0x3c1ab3[_0x44e2('0xbf')][_0x44e2('0x38')];_0x5a389f++){var _0x242d50={};_0x242d50[_0x3c1ab3['duplicates'][_0x5a389f]]=_0x3c1ab3[_0x3c1ab3[_0x44e2('0xbf')][_0x5a389f]];_0x430781[_0x44e2('0x42')][_0x44e2('0xc0')]['push'](_0x242d50);}_0x430781[_0x44e2('0x42')][_0x44e2('0x66')]=_0x3c1ab3['ListId'];}return db[_0x44e2('0x2d')][_0x44e2('0xc1')](_0x430781)[_0x44e2('0xc2')](function(_0x501edf,_0x4391d9){if(_0x4391d9){_0x3e970a++;}else{_0x268816++;}})[_0x44e2('0x98')](function(_0x6093d8){console['error'](_0x6093d8);_0x45d903++;});});})[_0x44e2('0x2f')](function(_0x519e4e){if(_0x519e4e){return{'success':_0x3e970a,'failure':_0x45d903,'duplicates':_0x268816};}})[_0x44e2('0x2f')](respondWithResult(_0x260201,0xc9))[_0x44e2('0x98')](handleError(_0x260201,null));};exports[_0x44e2('0xc3')]=function(_0x1177b1,_0x23a595,_0x650197){var _0x3b499a;return db['CmContact']['describe']()[_0x44e2('0x2f')](function(_0x43eecc){return db['CmContact'][_0x44e2('0x55')]({'where':{'id':_0x1177b1[_0x44e2('0x99')]['id']},'include':[{'model':db[_0x44e2('0x56')],'as':_0x44e2('0x95'),'attributes':['id',_0x44e2('0x2a'),'color'],'required':_0x1177b1[_0x44e2('0x3b')][_0x44e2('0x6b')]?!![]:![]}],'attributes':_[_0x44e2('0x30')](_0x43eecc)});})['then'](function(_0x4e7143){_0x3b499a=_0x4e7143[_0x44e2('0xa1')]({'plain':!![]});var _0x40dd05={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x4e7143&&_0x4e7143[_0x44e2('0x66')]){if(_0x4e7143[_0x44e2('0x66')]){_0x40dd05[_0x44e2('0x42')]['$and'][_0x44e2('0x32')]({'ListId':{'$ne':_0x4e7143[_0x44e2('0x66')]}});}}return db['CmCustomField']['findAll'](_0x40dd05);})[_0x44e2('0x2f')](function(_0x49ab22){return _[_0x44e2('0xc4')](_0x3b499a,_[_0x44e2('0x58')](_0x49ab22,function(_0x57eeb7){return util[_0x44e2('0xc5')]('cf_%d',_0x57eeb7['id']);}));})['then'](handleEntityNotFound(_0x23a595,null))[_0x44e2('0x2f')](respondWithResult(_0x23a595,null))[_0x44e2('0x98')](handleError(_0x23a595,null));};exports[_0x44e2('0xa9')]=function(_0x57b4ff,_0x249c37){var _0x15b19b;if(_0x57b4ff['body']['id']){delete _0x57b4ff[_0x44e2('0xa0')]['id'];}return db[_0x44e2('0x2d')][_0x44e2('0x55')]({'where':{'id':_0x57b4ff['params']['id']}})[_0x44e2('0x2f')](handleEntityNotFound(_0x249c37,null))[_0x44e2('0x2f')](saveUpdates(_0x57b4ff['body'],null))['then'](function(_0x35d825){_0x15b19b=_0x35d825;var _0x1ae4e7={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x35d825&&_0x35d825[_0x44e2('0x66')]){if(_0x35d825['ListId']){_0x1ae4e7[_0x44e2('0x42')][_0x44e2('0xc6')][_0x44e2('0x32')]({'ListId':{'$ne':_0x35d825[_0x44e2('0x66')]}});}}return db[_0x44e2('0x33')][_0x44e2('0x9c')](_0x1ae4e7);})[_0x44e2('0x2f')](function(_0x201d71){if(_0x201d71){return _[_0x44e2('0xc4')](_[_0x44e2('0xc7')](_0x57b4ff[_0x44e2('0xa0')],function(_0x4dcf3d,_0x35ceb7){return _[_0x44e2('0x31')](_0x35ceb7,_0x44e2('0x36'));}),_[_0x44e2('0x58')](_0x201d71,function(_0x3fb73c){return util[_0x44e2('0xc5')]('cf_%d',_0x3fb73c['id']);}));}})[_0x44e2('0x2f')](function(_0x52fc10){if(_0x52fc10&&!_[_0x44e2('0x65')](_0x52fc10)){var _0x4f49da=squel[_0x44e2('0xa9')]()[_0x44e2('0xc8')]('cm_contacts')[_0x44e2('0xc9')](_0x52fc10)[_0x44e2('0x42')](_0x44e2('0xca'),_0x57b4ff[_0x44e2('0x99')]['id'])['toParam']();return db[_0x44e2('0x87')][_0x44e2('0x3b')](_0x4f49da[_0x44e2('0x62')],{'replacements':_0x4f49da['values']});}})[_0x44e2('0x2f')](function(){if(_0x57b4ff[_0x44e2('0xa0')][_0x44e2('0xcb')]&&_0x15b19b){return db[_0x44e2('0xcc')][_0x44e2('0xa9')]({'phone':_0x57b4ff[_0x44e2('0xa0')][_0x44e2('0xcb')]},{'where':{'ContactId':_0x15b19b['id']}});}})['then'](function(){return _0x15b19b;})['then'](respondWithResult(_0x249c37,null))[_0x44e2('0x98')](handleError(_0x249c37,null));};exports['getTags']=function(_0x1e95d4,_0x1fb75b,_0x43d194){var _0x44e866={};var _0x1ac1b3={};var _0x3eb15c;var _0x10e4db;return db[_0x44e2('0x2d')][_0x44e2('0x34')]({'where':{'id':_0x1e95d4['params']['id']}})[_0x44e2('0x2f')](handleEntityNotFound(_0x1fb75b,null))[_0x44e2('0x2f')](function(_0x2c8b81){if(_0x2c8b81){_0x3eb15c=_0x2c8b81;_0x1ac1b3[_0x44e2('0x3a')]=_[_0x44e2('0x30')](db[_0x44e2('0x56')][_0x44e2('0xcd')]);_0x1ac1b3[_0x44e2('0x3b')]=_[_0x44e2('0x30')](_0x1e95d4[_0x44e2('0x3b')]);_0x1ac1b3[_0x44e2('0x43')]=_[_0x44e2('0x3d')](_0x1ac1b3['model'],_0x1ac1b3['query']);_0x44e866['attributes']=_['intersection'](_0x1ac1b3[_0x44e2('0x3a')],qs['fields'](_0x1e95d4['query'][_0x44e2('0xce')]));_0x44e866['attributes']=_0x44e866[_0x44e2('0x3c')][_0x44e2('0x38')]?_0x44e866[_0x44e2('0x3c')]:_0x1ac1b3[_0x44e2('0x3a')];_0x44e866[_0x44e2('0x40')]=qs[_0x44e2('0x41')](_0x1e95d4['query'][_0x44e2('0x41')]);_0x44e866[_0x44e2('0x42')]=qs[_0x44e2('0x43')](_[_0x44e2('0x44')](_0x1e95d4[_0x44e2('0x3b')],_0x1ac1b3[_0x44e2('0x43')]));if(_0x1e95d4[_0x44e2('0x3b')][_0x44e2('0x6d')]){_0x44e866['where']=_[_0x44e2('0x8a')](_0x44e866[_0x44e2('0x42')],{'$or':_[_0x44e2('0x58')](_0x44e866[_0x44e2('0x3c')],function(_0x13853d){var _0x14b3d4={};_0x14b3d4[_0x13853d]={'$like':'%'+_0x1e95d4['query'][_0x44e2('0x6d')]+'%'};return _0x14b3d4;})});}_0x44e866=_[_0x44e2('0x8a')]({},_0x44e866,_0x1e95d4[_0x44e2('0xcf')]);return _0x3eb15c[_0x44e2('0xd0')](_0x44e866);}})['then'](function(_0x3d1a8c){if(_0x3d1a8c){_0x10e4db=_0x3d1a8c['length'];if(!_0x1e95d4['query'][_0x44e2('0x3e')]('nolimit')){_0x44e866['limit']=qs[_0x44e2('0x24')](_0x1e95d4[_0x44e2('0x3b')][_0x44e2('0x24')]);_0x44e866[_0x44e2('0x23')]=qs['offset'](_0x1e95d4[_0x44e2('0x3b')][_0x44e2('0x23')]);}return _0x3eb15c[_0x44e2('0xd0')](_0x44e866);}})['then'](function(_0x161108){if(_0x161108){return _0x161108?{'count':_0x10e4db,'rows':_0x161108}:null;}})[_0x44e2('0x2f')](respondWithResult(_0x1fb75b,null))[_0x44e2('0x98')](handleError(_0x1fb75b,null));};exports['setTags']=function(_0x22d9cc,_0x5bb401,_0x34a405){if(_0x22d9cc[_0x44e2('0xa0')]['id']){delete _0x22d9cc[_0x44e2('0xa0')]['id'];}return db['CmContact']['findOne']({'where':{'id':_0x22d9cc[_0x44e2('0x99')]['id']}})[_0x44e2('0x2f')](handleEntityNotFound(_0x5bb401,null))[_0x44e2('0x2f')](function(_0x4343e1){if(_0x4343e1){return _0x4343e1[_0x44e2('0xd1')](_0x22d9cc[_0x44e2('0xa0')]['ids']||[]);}return null;})['then'](respondWithResult(_0x5bb401,null))[_0x44e2('0x98')](handleError(_0x5bb401,null));};exports[_0x44e2('0xd2')]=function(_0x7b0a26,_0x4e5c00,_0x5280fd){var _0x5c69de={'raw':![],'where':{}};var _0x13486={};var _0x289e00={'count':0x0,'rows':[]};return db['CmContact'][_0x44e2('0x34')]({'where':{'id':_0x7b0a26['params']['id']}})[_0x44e2('0x2f')](handleEntityNotFound(_0x4e5c00,null))[_0x44e2('0x2f')](function(_0x521cf5){if(_0x521cf5){_0x13486[_0x44e2('0x3a')]=_[_0x44e2('0x30')](db[_0x44e2('0xcc')]['rawAttributes']);_0x13486[_0x44e2('0x3b')]=_[_0x44e2('0x30')](_0x7b0a26[_0x44e2('0x3b')]);_0x13486['filters']=_[_0x44e2('0x3d')](_0x13486[_0x44e2('0x3a')],_0x13486[_0x44e2('0x3b')]);_0x5c69de['attributes']=_[_0x44e2('0x3d')](_0x13486[_0x44e2('0x3a')],qs['fields'](_0x7b0a26[_0x44e2('0x3b')][_0x44e2('0xce')]));_0x5c69de[_0x44e2('0x3c')]=_0x5c69de[_0x44e2('0x3c')][_0x44e2('0x38')]?_0x5c69de['attributes']:_0x13486[_0x44e2('0x3a')];if(!_0x7b0a26[_0x44e2('0x3b')]['hasOwnProperty']('nolimit')){_0x5c69de[_0x44e2('0x24')]=qs['limit'](_0x7b0a26[_0x44e2('0x3b')][_0x44e2('0x24')]);_0x5c69de[_0x44e2('0x23')]=qs[_0x44e2('0x23')](_0x7b0a26[_0x44e2('0x3b')][_0x44e2('0x23')]);}_0x5c69de[_0x44e2('0x40')]=qs[_0x44e2('0x41')](_0x7b0a26[_0x44e2('0x3b')]['sort']);_0x5c69de['where']=qs['filters'](_[_0x44e2('0x44')](_0x7b0a26['query'],_0x13486[_0x44e2('0x43')]));_0x5c69de[_0x44e2('0x42')][_0x44e2('0xd3')]=_0x521cf5['id'];if(_0x7b0a26[_0x44e2('0x3b')][_0x44e2('0x6d')]){_0x5c69de[_0x44e2('0x42')]=_[_0x44e2('0x8a')](_0x5c69de['where'],{'$or':_['map'](_0x5c69de[_0x44e2('0x3c')],function(_0x8d4ca7){var _0x3f04d0={};_0x3f04d0[_0x8d4ca7]={'$like':'%'+_0x7b0a26[_0x44e2('0x3b')][_0x44e2('0x6d')]+'%'};return _0x3f04d0;})});}_0x5c69de=_['merge']({},_0x5c69de,_0x7b0a26['options']);return db[_0x44e2('0xcc')][_0x44e2('0x22')]({'where':_0x5c69de[_0x44e2('0x42')]})['then'](function(_0x1d8d8b){_0x289e00[_0x44e2('0x22')]=_0x1d8d8b;if(_0x7b0a26['query'][_0x44e2('0xd4')]){_0x5c69de['include']=[{'all':!![]}];}return db[_0x44e2('0xcc')][_0x44e2('0x9c')](_0x5c69de);})[_0x44e2('0x2f')](function(_0x15e1b0){_0x289e00[_0x44e2('0x97')]=_0x15e1b0;return _0x289e00;});}})[_0x44e2('0x2f')](respondWithFilteredResult(_0x4e5c00,_0x5c69de))[_0x44e2('0x98')](handleError(_0x4e5c00,null));};exports[_0x44e2('0xd5')]=function(_0x25d98b,_0x1e0cf4,_0x3cbae4){var _0x2bb32d={'raw':!![],'where':{}};var _0x95bc27={};var _0x414150={'count':0x0,'rows':[]};return db[_0x44e2('0x2d')][_0x44e2('0x34')]({'where':{'id':_0x25d98b['params']['id']}})[_0x44e2('0x2f')](handleEntityNotFound(_0x1e0cf4,null))['then'](function(_0x48be2c){if(_0x48be2c){_0x95bc27[_0x44e2('0x3a')]=_[_0x44e2('0x30')](db[_0x44e2('0xb2')][_0x44e2('0xcd')]);_0x95bc27['query']=_['keys'](_0x25d98b[_0x44e2('0x3b')]);_0x95bc27[_0x44e2('0x43')]=_[_0x44e2('0x3d')](_0x95bc27['model'],_0x95bc27['query']);_0x2bb32d[_0x44e2('0x3c')]=_[_0x44e2('0x3d')](_0x95bc27[_0x44e2('0x3a')],qs[_0x44e2('0xce')](_0x25d98b[_0x44e2('0x3b')][_0x44e2('0xce')]));_0x2bb32d[_0x44e2('0x3c')]=_0x2bb32d[_0x44e2('0x3c')][_0x44e2('0x38')]?_0x2bb32d[_0x44e2('0x3c')]:_0x95bc27[_0x44e2('0x3a')];if(!_0x25d98b[_0x44e2('0x3b')][_0x44e2('0x3e')](_0x44e2('0x3f'))){_0x2bb32d[_0x44e2('0x24')]=qs[_0x44e2('0x24')](_0x25d98b[_0x44e2('0x3b')][_0x44e2('0x24')]);_0x2bb32d[_0x44e2('0x23')]=qs[_0x44e2('0x23')](_0x25d98b[_0x44e2('0x3b')]['offset']);}_0x2bb32d[_0x44e2('0x40')]=qs[_0x44e2('0x41')](_0x25d98b['query'][_0x44e2('0x41')]);_0x2bb32d['where']=qs['filters'](_['pick'](_0x25d98b[_0x44e2('0x3b')],_0x95bc27[_0x44e2('0x43')]));_0x2bb32d[_0x44e2('0x42')][_0x44e2('0xd3')]=_0x48be2c['id'];if(_0x25d98b[_0x44e2('0x3b')][_0x44e2('0x6d')]){_0x2bb32d[_0x44e2('0x42')]=_[_0x44e2('0x8a')](_0x2bb32d[_0x44e2('0x42')],{'$or':_[_0x44e2('0x58')](_0x2bb32d[_0x44e2('0x3c')],function(_0x1b2b66){var _0x3dfd73={};_0x3dfd73[_0x1b2b66]={'$like':'%'+_0x25d98b[_0x44e2('0x3b')][_0x44e2('0x6d')]+'%'};return _0x3dfd73;})});}_0x2bb32d=_[_0x44e2('0x8a')]({},_0x2bb32d,_0x25d98b['options']);return db[_0x44e2('0xb2')][_0x44e2('0x22')]({'where':_0x2bb32d[_0x44e2('0x42')]})['then'](function(_0x155f00){_0x414150[_0x44e2('0x22')]=_0x155f00;if(_0x25d98b[_0x44e2('0x3b')][_0x44e2('0xd4')]){_0x2bb32d['include']=[{'all':!![]}];}return db[_0x44e2('0xb2')][_0x44e2('0x9c')](_0x2bb32d);})[_0x44e2('0x2f')](function(_0x553864){_0x414150[_0x44e2('0x97')]=_0x553864;return _0x414150;});}})[_0x44e2('0x2f')](respondWithFilteredResult(_0x1e0cf4,_0x2bb32d))[_0x44e2('0x98')](handleError(_0x1e0cf4,null));};exports[_0x44e2('0xd6')]=function(_0x5245d5,_0x4dadd6,_0x4c2961){var _0x4105ea={'raw':!![],'where':{}};var _0x916185={};var _0x1d61a9={'count':0x0,'rows':[]};return db['CmContact']['findOne']({'where':{'id':_0x5245d5[_0x44e2('0x99')]['id']}})['then'](handleEntityNotFound(_0x4dadd6,null))[_0x44e2('0x2f')](function(_0x43e541){if(_0x43e541){_0x916185[_0x44e2('0x3a')]=_[_0x44e2('0x30')](db[_0x44e2('0xb1')][_0x44e2('0xcd')]);_0x916185['query']=_[_0x44e2('0x30')](_0x5245d5['query']);_0x916185[_0x44e2('0x43')]=_['intersection'](_0x916185['model'],_0x916185['query']);_0x4105ea[_0x44e2('0x3c')]=_[_0x44e2('0x3d')](_0x916185[_0x44e2('0x3a')],qs[_0x44e2('0xce')](_0x5245d5[_0x44e2('0x3b')]['fields']));_0x4105ea[_0x44e2('0x3c')]=_0x4105ea[_0x44e2('0x3c')]['length']?_0x4105ea['attributes']:_0x916185[_0x44e2('0x3a')];if(!_0x5245d5[_0x44e2('0x3b')][_0x44e2('0x3e')]('nolimit')){_0x4105ea[_0x44e2('0x24')]=qs[_0x44e2('0x24')](_0x5245d5[_0x44e2('0x3b')][_0x44e2('0x24')]);_0x4105ea[_0x44e2('0x23')]=qs[_0x44e2('0x23')](_0x5245d5[_0x44e2('0x3b')]['offset']);}_0x4105ea[_0x44e2('0x40')]=qs[_0x44e2('0x41')](_0x5245d5[_0x44e2('0x3b')][_0x44e2('0x41')]);_0x4105ea[_0x44e2('0x42')]=qs['filters'](_[_0x44e2('0x44')](_0x5245d5['query'],_0x916185[_0x44e2('0x43')]));_0x4105ea[_0x44e2('0x42')][_0x44e2('0xd3')]=_0x43e541['id'];if(_0x5245d5[_0x44e2('0x3b')][_0x44e2('0x6d')]){_0x4105ea[_0x44e2('0x42')]=_['merge'](_0x4105ea['where'],{'$or':_['map'](_0x4105ea[_0x44e2('0x3c')],function(_0x2a2f21){var _0x3397e8={};_0x3397e8[_0x2a2f21]={'$like':'%'+_0x5245d5[_0x44e2('0x3b')][_0x44e2('0x6d')]+'%'};return _0x3397e8;})});}_0x4105ea=_[_0x44e2('0x8a')]({},_0x4105ea,_0x5245d5['options']);return db['CmHopperFinal'][_0x44e2('0x22')]({'where':_0x4105ea[_0x44e2('0x42')]})[_0x44e2('0x2f')](function(_0x8c391f){_0x1d61a9[_0x44e2('0x22')]=_0x8c391f;if(_0x5245d5[_0x44e2('0x3b')]['includeAll']){_0x4105ea[_0x44e2('0xd7')]=[{'all':!![]}];}return db['CmHopperFinal']['findAll'](_0x4105ea);})['then'](function(_0x933628){_0x1d61a9[_0x44e2('0x97')]=_0x933628;return _0x1d61a9;});}})[_0x44e2('0x2f')](respondWithFilteredResult(_0x4dadd6,_0x4105ea))['catch'](handleError(_0x4dadd6,null));};exports['getJscriptySessions']=function(_0x54fd94,_0xe4a78b,_0x282cf7){var _0x36806e={'raw':!![],'where':{}};var _0x518a74={};var _0x374821={'count':0x0,'rows':[]};return db[_0x44e2('0x2d')][_0x44e2('0x34')]({'where':{'id':_0x54fd94[_0x44e2('0x99')]['id']}})[_0x44e2('0x2f')](handleEntityNotFound(_0xe4a78b,null))['then'](function(_0xbe9dc6){if(_0xbe9dc6){_0x518a74['model']=_[_0x44e2('0x30')](db[_0x44e2('0xb9')][_0x44e2('0xcd')]);_0x518a74[_0x44e2('0x3b')]=_['keys'](_0x54fd94['query']);_0x518a74['filters']=_[_0x44e2('0x3d')](_0x518a74[_0x44e2('0x3a')],_0x518a74[_0x44e2('0x3b')]);_0x36806e[_0x44e2('0x3c')]=_[_0x44e2('0x3d')](_0x518a74['model'],qs[_0x44e2('0xce')](_0x54fd94[_0x44e2('0x3b')][_0x44e2('0xce')]));_0x36806e[_0x44e2('0x3c')]=_0x36806e[_0x44e2('0x3c')][_0x44e2('0x38')]?_0x36806e['attributes']:_0x518a74[_0x44e2('0x3a')];if(!_0x54fd94[_0x44e2('0x3b')][_0x44e2('0x3e')]('nolimit')){_0x36806e[_0x44e2('0x24')]=qs[_0x44e2('0x24')](_0x54fd94[_0x44e2('0x3b')]['limit']);_0x36806e[_0x44e2('0x23')]=qs[_0x44e2('0x23')](_0x54fd94[_0x44e2('0x3b')][_0x44e2('0x23')]);}_0x36806e[_0x44e2('0x40')]=qs[_0x44e2('0x41')](_0x54fd94[_0x44e2('0x3b')][_0x44e2('0x41')]);_0x36806e['where']=qs[_0x44e2('0x43')](_[_0x44e2('0x44')](_0x54fd94[_0x44e2('0x3b')],_0x518a74[_0x44e2('0x43')]));_0x36806e['where'][_0x44e2('0xd3')]=_0xbe9dc6['id'];if(_0x54fd94[_0x44e2('0x3b')][_0x44e2('0x6d')]){_0x36806e[_0x44e2('0x42')]=_[_0x44e2('0x8a')](_0x36806e['where'],{'$or':_[_0x44e2('0x58')](_0x36806e[_0x44e2('0x3c')],function(_0x50dcf3){var _0x13dd3f={};_0x13dd3f[_0x50dcf3]={'$like':'%'+_0x54fd94[_0x44e2('0x3b')][_0x44e2('0x6d')]+'%'};return _0x13dd3f;})});}_0x36806e=_['merge']({},_0x36806e,_0x54fd94[_0x44e2('0xcf')]);return db['JscriptySessionReport'][_0x44e2('0x22')]({'where':_0x36806e[_0x44e2('0x42')]})[_0x44e2('0x2f')](function(_0x1d30ac){_0x374821[_0x44e2('0x22')]=_0x1d30ac;if(_0x54fd94[_0x44e2('0x3b')][_0x44e2('0xd4')]){_0x36806e[_0x44e2('0xd7')]=[{'all':!![]}];}return db[_0x44e2('0xb9')]['findAll'](_0x36806e);})[_0x44e2('0x2f')](function(_0x2163d3){_0x374821['rows']=_0x2163d3;return _0x374821;});}})[_0x44e2('0x2f')](respondWithFilteredResult(_0xe4a78b,_0x36806e))['catch'](handleError(_0xe4a78b,null));};exports[_0x44e2('0xd8')]=function(_0x57136c,_0x31e885,_0x2e8276){try{if(!_0x57136c[_0x44e2('0xa0')][_0x44e2('0x66')]){throw new Error(_0x44e2('0xd9'));}if(!_0x57136c[_0x44e2('0xa0')][_0x44e2('0xda')]){throw new Error(_0x44e2('0xdb'));}if(!_0x57136c['body'][_0x44e2('0xdc')]){throw new Error(_0x44e2('0xdd'));}if(!_0x57136c['body'][_0x44e2('0xde')]){throw new Error(_0x44e2('0xdf'));}var _0x404d73=_0x57136c['body'][_0x44e2('0xda')]['split'](',');var _0x254070=_0x57136c[_0x44e2('0xa0')]['binding_values'][_0x44e2('0x96')](',');if(!_0x404d73[_0x44e2('0x38')]||!_0x254070[_0x44e2('0x38')]||_0x404d73[_0x44e2('0x38')]!==_0x254070[_0x44e2('0x38')]){throw new Error(_0x44e2('0xe0'));}_0x57136c[_0x44e2('0xa0')][_0x44e2('0xce')]=_['zipObject'](_0x404d73,_0x254070);if(!_0x57136c['body'][_0x44e2('0xce')][_0x44e2('0xcb')]){throw new Error(_0x44e2('0xe1'));}if(!_0x57136c[_0x44e2('0xa0')][_0x44e2('0xce')][_0x44e2('0xe2')]){throw new Error(_0x44e2('0xe3'));}var _0x3ce6f7=path[_0x44e2('0xbc')](config['root'],_0x44e2('0xe4'),_0x57136c['file']['filename']);fs['chmodSync'](_0x3ce6f7,parseInt(_0x44e2('0xe5'),0x8));var _0x1e51f7=require(_0x44e2('0xe6'))['fork'](path[_0x44e2('0xbc')](__dirname,_0x44e2('0xe7')),[_0x3ce6f7,_0x57136c['body'][_0x44e2('0xda')],_0x57136c[_0x44e2('0xa0')][_0x44e2('0xdc')],_0x57136c[_0x44e2('0xa0')][_0x44e2('0x66')],_0x57136c[_0x44e2('0xa0')][_0x44e2('0xe8')],_0x57136c[_0x44e2('0xa0')]['duplicates'],_0x57136c[_0x44e2('0xa0')][_0x44e2('0xde')]]);return _0x31e885[_0x44e2('0x20')](0xc8)['json']({'message':'File\x20uploaded\x20correctly!','pid':_0x1e51f7[_0x44e2('0xe9')]});}catch(_0x449ff8){return _0x31e885['status'](0x1f4)['send'](_0x449ff8);}};exports[_0x44e2('0xea')]=function(_0x38f1e8,_0x3eae31,_0x199f90){var _0x4e9357=fs[_0x44e2('0xeb')](_0x38f1e8[_0x44e2('0xec')]['path']);Papa[_0x44e2('0xed')](_0x4e9357,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x365eb0){return _0x3eae31[_0x44e2('0x20')](0xc8)[_0x44e2('0x26')]({'file':_0x38f1e8['file'],'fields':_0x365eb0[_0x44e2('0xee')][_0x44e2('0xce')]});}});};exports[_0x44e2('0xef')]=function(_0x144a64,_0x206182,_0x42354c){return db[_0x44e2('0x83')][_0x44e2('0x9c')]({'raw':!![],'attributes':['id'],'where':{'role':_0x44e2('0x82')}})[_0x44e2('0x2f')](function(_0x1614e3){var _0x3c3e65=![];if(!_0x144a64[_0x44e2('0xa0')][_0x44e2('0x66')]){throw new Error('No\x20ListId\x20specified');}if(!_0x144a64[_0x44e2('0xa0')][_0x44e2('0xf0')][_0x44e2('0xcb')]){throw new Error(_0x44e2('0xe1'));}if(!_0x144a64['body'][_0x44e2('0xf0')][_0x44e2('0xe2')]){throw new Error(_0x44e2('0xe3'));}if(!_0x144a64['body'][_0x44e2('0xde')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x1cea25=require(_0x44e2('0xe6'))[_0x44e2('0xf1')](path[_0x44e2('0xbc')](__dirname,_0x44e2('0xf2')),[_0x144a64[_0x44e2('0x99')]['id'],JSON[_0x44e2('0xf3')](_0x144a64[_0x44e2('0xa0')]),JSON[_0x44e2('0xf3')](_0x1614e3)]);_0x1cea25['on'](_0x44e2('0xf4'),function(_0x5bd2bc){_0x3c3e65=!![];return _0x206182[_0x44e2('0x20')](0xc8)[_0x44e2('0x26')]({'message':_0x44e2('0xf5'),'pid':_0x1cea25['pid']});});_0x1cea25['on'](_0x44e2('0xf6'),function(_0x2b09de){if(_0x2b09de&&!_0x3c3e65){return _0x206182[_0x44e2('0x20')](0x1f4)[_0x44e2('0x26')]({'message':'error\x20child\x20process','pid':_0x1cea25[_0x44e2('0xe9')]});}});})[_0x44e2('0x98')](handleError(_0x206182,null));};exports[_0x44e2('0xf7')]=function(_0x3d20ad,_0x1f4b19){var _0x471de0=[_0x44e2('0xf8'),_0x44e2('0xf9'),_0x44e2('0xfa'),_0x44e2('0xfb'),_0x44e2('0xfc'),_0x44e2('0xfd'),_0x44e2('0xfe')];var _0x3ba7e9={'offset':0x0,'order':qs[_0x44e2('0x41')](_0x44e2('0xff'))},_0x5aa725={'count':0x0,'rows':[]};Promise[_0x44e2('0x81')]()[_0x44e2('0x2f')](function(){if(_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x100')]){if(!_[_0x44e2('0x101')](_0x471de0,_0x3d20ad['query']['channel'][_0x44e2('0x102')]())){throw new Error(_0x44e2('0x103'));}_0x471de0=[_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x100')][_0x44e2('0x102')]()];}if(_0x3d20ad['query']['range']){try{var _0x4b2022=JSON['parse'](_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x104')]);if(!moment(_0x4b2022[_0x44e2('0x46')])[_0x44e2('0x105')]()){throw new Error(_0x44e2('0x106'));}if(!moment(_0x4b2022['to'])[_0x44e2('0x105')]()){throw new Error(_0x44e2('0x107'));}}catch(_0x142564){throw new Error(_0x44e2('0x108'));}}if(!_0x3d20ad[_0x44e2('0x3b')]['hasOwnProperty'](_0x44e2('0x3f'))){_0x3ba7e9[_0x44e2('0x24')]=qs['limit'](_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x24')]||0xa);_0x3ba7e9['offset']=qs[_0x44e2('0x23')](_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x23')]);}var _0x39191e=_0x471de0[_0x44e2('0x58')](function(_0x56f7c6){if(_0x56f7c6===_0x44e2('0xfe')){var _0x4595b1={'attributes':['id',_0x44e2('0x109'),_0x44e2('0x39'),'source',_0x44e2('0x10a'),_0x44e2('0x10b'),_0x44e2('0x10c'),_0x44e2('0x10d'),'duration','note',_0x44e2('0x10e'),_0x44e2('0x10f'),_0x44e2('0x110'),_0x44e2('0x111')],'where':{'ContactId':_0x3d20ad[_0x44e2('0x99')]['id']},'include':[{'model':db[_0x44e2('0x83')],'as':_0x44e2('0x83'),'attributes':['id',_0x44e2('0x2a'),'fullname','alias']}],'order':[[_0x44e2('0x10e'),_0x44e2('0x7f')]]};if(_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x104')]){_0x4595b1[_0x44e2('0x42')][_0x44e2('0x10e')]={'$gte':_0x4b2022[_0x44e2('0x46')],'$lte':_0x4b2022['to']};}return db[_0x44e2('0x112')][_0x44e2('0x113')](_0x4595b1)[_0x44e2('0x2f')](function(_0x4eefe8){_0x5aa725[_0x44e2('0x22')]+=_0x4eefe8[_0x44e2('0x22')];return _['map'](_0x4eefe8[_0x44e2('0x97')],function(_0xa59590){var _0x1f5bd6=_0xa59590['get']({'plain':!![]});_0x1f5bd6['channel']=_0x56f7c6;if(_0x1f5bd6[_0x44e2('0x83')]){_0x1f5bd6[_0x44e2('0x83')]={'id':_0x1f5bd6['User']['id'],'name':_0x1f5bd6['User']['name'],'fullname':_0x1f5bd6[_0x44e2('0x83')]['fullname'],'alias':_0x1f5bd6[_0x44e2('0x83')][_0x44e2('0x114')]};}return _0x1f5bd6;});});}else{var _0x23983d=_['startCase'](_0x56f7c6)+(_0x56f7c6===_0x44e2('0xf9')?_0x44e2('0x115'):'Account');var _0x5bc2f3={'attributes':['id','closed',_0x44e2('0x116'),'createdAt','note','disposition',_0x44e2('0x117'),_0x44e2('0x118'),_0x44e2('0x119'),_0x23983d+'Id'],'where':{'ContactId':_0x3d20ad['params']['id']},'include':[{'model':db[_0x23983d],'as':'Account','attributes':['id',_0x44e2('0x2a'),_0x44e2('0x11a')]},{'model':db[_0x44e2('0x83')],'as':_0x44e2('0x11b'),'attributes':['id',_0x44e2('0x2a'),_0x44e2('0x11c')]},{'model':db['Tag'],'as':_0x44e2('0x95'),'attributes':['id',_0x44e2('0x2a'),_0x44e2('0x11d')],'through':{'attributes':[]}}],'order':[['createdAt',_0x44e2('0x7f')]]};if(_0x3d20ad[_0x44e2('0x3b')][_0x44e2('0x104')]){_0x5bc2f3[_0x44e2('0x42')][_0x44e2('0x10e')]={'$gte':_0x4b2022['from'],'$lte':_0x4b2022['to']};}switch(_0x56f7c6){case'chat':_0x5bc2f3['attributes'][_0x44e2('0x32')](_0x44e2('0x11e'),_0x44e2('0x11f'),'customerPort',_0x44e2('0x120'),'osName','ratingMessage',_0x44e2('0x121'),_0x44e2('0x122'),_0x44e2('0x123'));break;case _0x44e2('0xf8'):_0x5bc2f3[_0x44e2('0x3c')][_0x44e2('0x32')](_0x44e2('0x124'),_0x44e2('0x125'));break;case _0x44e2('0xfb'):_0x5bc2f3['attributes']['push'](_0x44e2('0x126'),_0x44e2('0x127'));break;}return db[_[_0x44e2('0x128')](_0x56f7c6)+_0x44e2('0x129')][_0x44e2('0x113')](_0x5bc2f3)[_0x44e2('0x2f')](function(_0xf92e34){_0x5aa725[_0x44e2('0x22')]+=_0xf92e34[_0x44e2('0x22')];return _[_0x44e2('0x58')](_0xf92e34[_0x44e2('0x97')],function(_0x1b161a){var _0x521bd6=_0x1b161a[_0x44e2('0xa1')]({'plain':!![]});_0x521bd6['channel']=_0x56f7c6;if(_0x521bd6['Owner']){_0x521bd6[_0x44e2('0x11b')]={'id':_0x521bd6[_0x44e2('0x11b')]['id'],'name':_0x521bd6[_0x44e2('0x11b')][_0x44e2('0x2a')],'fullname':_0x521bd6[_0x44e2('0x11b')][_0x44e2('0x11c')]};}return _0x521bd6;});});}});return Promise[_0x44e2('0x37')](_0x39191e);})[_0x44e2('0x2f')](function(_0x4f22c4){return _(_0x4f22c4)['flatten']()[_0x44e2('0x12a')](_0x44e2('0x10e'))['reverse']()[_0x44e2('0x57')]();})[_0x44e2('0x2f')](function(_0x2fd503){_0x5aa725[_0x44e2('0x97')]=_0x3ba7e9[_0x44e2('0x24')]?_0x2fd503[_0x44e2('0x12b')](_0x3ba7e9[_0x44e2('0x23')],_0x3ba7e9[_0x44e2('0x23')]+_0x3ba7e9[_0x44e2('0x24')]):_0x2fd503;return _0x5aa725;})[_0x44e2('0x2f')](respondWithFilteredResult(_0x1f4b19,_0x3ba7e9))[_0x44e2('0x98')](handleError(_0x1f4b19,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