Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / cmContact / cmContact.controller.js
index ece2a1f..93df52f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd08c=['getTags','rawAttributes','intersection','options','setTags','ids','getHoppers','ContactId','rows','getHopperHistories','includeAll','include','getHopperFinals','getJscriptySessions','JscriptySessionReport','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','binding_values','No\x20association\x20values\x20specified!','socket_timestamp','Incorrect\x20binding\x20parameters\x20passed!','zipObject','root','server/files/tmp','file','filename','chmodSync','0777','child_process','fork','../../components/import/cm/csv','CompanyId','upload','createReadStream','path','parse','meta','binding','firstName','No\x20firstName\x20column\x20specified','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','../../components/import/cm/csv2','stringify','start\x20child\x20process\x20correctly!','pid','error\x20child\x20process','getJourney','chat','sms','openchannel','whatsapp','channel','includes','toLowerCase','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','Invalid\x20createdAt\x20filter','voice','destination','callerid','duration','note','createdAt','userDisposition','userSecondDisposition','userThirdDisposition','UserId','fullname','findAndCountAll','Website','closed','closedAt','disposition','secondDisposition','thirdDisposition','key','Owner','browserName','customerIp','customerPort','deviceModel','osName','ratingType','ratingValue','referer','mail','substatus','threadId','startCase','Interaction','sortBy','slice','eml-format','rimraf','fast-json-patch','request-promise','moment','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./cmContact.socket','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','index','describe','keys','length','cf_','findOne','trimStart','all','fieldType','type','model','query','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters','pick','select','field','color','from','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','conditions','Tag','value','split','map','forEach','union','and','datetime','DATE','buildExpression','text','start','filter','isNil','Contact','isEmpty','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','replace','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','c.fax\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','c.id','Sequelize','QueryTypes','SELECT','clone','DESC','t.id\x20IN\x20?','resolve','role','some','User','user','getLists','c.ListId\x20IS\x20NULL','agent','sequelize','toString','keyBy','merge','CmContact','c.firstName','c.lastName','c.phone','c.mobile','c.email','c.ListId','c.deletedAt','c.CompanyId','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','push','catch','find','tags','startsWith','displayName','alias','values','columnName','body','findAll','get','mergeWith','join','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','ChatInteraction','update','MailInteraction','MailMessage','SmsInteraction','SmsMessage','FaxInteraction','FaxMessage','OpenchannelInteraction','CmHopperFinal','CmHopperHistory','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','OpenchannelQueueReport','SmsQueueReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','bulkCreate','each','duplicates','$or','findOrCreate','spread','show','CmCustomField','format','cf_%d','params','$and','omit','pickBy','table','setFields','toParam','phone'];(function(_0x57df28,_0x1aae4b){var _0x5a0cf9=function(_0x58a0fa){while(--_0x58a0fa){_0x57df28['push'](_0x57df28['shift']());}};_0x5a0cf9(++_0x1aae4b);}(_0xd08c,0x18f));var _0xcd08=function(_0xe4270f,_0x26de62){_0xe4270f=_0xe4270f-0x0;var _0x105519=_0xd08c[_0xe4270f];return _0x105519;};'use strict';var emlformat=require(_0xcd08('0x0'));var rimraf=require(_0xcd08('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xcd08('0x2'));var rp=require(_0xcd08('0x3'));var moment=require(_0xcd08('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xcd08('0x5'));var path=require('path');var sox=require(_0xcd08('0x6'));var csv=require(_0xcd08('0x7'));var ejs=require(_0xcd08('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xcd08('0x9'));var squel=require(_0xcd08('0xa'));var crypto=require(_0xcd08('0xb'));var jsforce=require(_0xcd08('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xcd08('0x7'));var querystring=require('querystring');var Papa=require(_0xcd08('0xd'));var Redis=require(_0xcd08('0xe'));var authService=require(_0xcd08('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xcd08('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xcd08('0x11'));var utils=require(_0xcd08('0x12'));var config=require(_0xcd08('0x13'));var licenseUtil=require(_0xcd08('0x14'));var db=require(_0xcd08('0x15'))['db'];config[_0xcd08('0x16')]=_[_0xcd08('0x17')](config[_0xcd08('0x16')],{'host':_0xcd08('0x18'),'port':0x18eb});var socket=require(_0xcd08('0x19'))(new Redis(config[_0xcd08('0x16')]));require(_0xcd08('0x1a'))['register'](socket);function respondWithStatusCode(_0x1aa6e7,_0x18c3d3){_0x18c3d3=_0x18c3d3||0xcc;return function(_0x308a78){if(_0x308a78){return _0x1aa6e7[_0xcd08('0x1b')](_0x18c3d3);}return _0x1aa6e7['status'](_0x18c3d3)[_0xcd08('0x1c')]();};}function respondWithResult(_0x57dbfc,_0x404f65){_0x404f65=_0x404f65||0xc8;return function(_0x19cdd7){if(_0x19cdd7){return _0x57dbfc[_0xcd08('0x1d')](_0x404f65)[_0xcd08('0x1e')](_0x19cdd7);}};}function respondWithFilteredResult(_0x5e2e6a,_0x3f2dd4){return function(_0xc8d7a7){if(_0xc8d7a7){var _0x23bbfd=typeof _0x3f2dd4[_0xcd08('0x1f')]===_0xcd08('0x20')&&typeof _0x3f2dd4['limit']===_0xcd08('0x20');var _0x1652cc=_0xc8d7a7['count'];var _0x31c91d=_0x23bbfd?0x0:_0x3f2dd4[_0xcd08('0x1f')];var _0x4a343d=_0x23bbfd?_0xc8d7a7[_0xcd08('0x21')]:_0x3f2dd4['offset']+_0x3f2dd4[_0xcd08('0x22')];var _0x490ba9;if(_0x4a343d>=_0x1652cc){_0x4a343d=_0x1652cc;_0x490ba9=0xc8;}else{_0x490ba9=0xce;}_0x5e2e6a[_0xcd08('0x1d')](_0x490ba9);return _0x5e2e6a[_0xcd08('0x23')](_0xcd08('0x24'),_0x31c91d+'-'+_0x4a343d+'/'+_0x1652cc)[_0xcd08('0x1e')](_0xc8d7a7);}return null;};}function patchUpdates(_0x4635cc){return function(_0x4ecc4a){try{jsonpatch[_0xcd08('0x25')](_0x4ecc4a,_0x4635cc,!![]);}catch(_0x1b44b6){return BPromise[_0xcd08('0x26')](_0x1b44b6);}return _0x4ecc4a[_0xcd08('0x27')]();};}function saveUpdates(_0x430246,_0x3282b9){return function(_0x2d6932){if(_0x2d6932){return _0x2d6932['update'](_0x430246)[_0xcd08('0x28')](function(_0x49da90){return _0x49da90;});}return null;};}function removeEntity(_0x52a0c4,_0x17dcdc){return function(_0x4f0f16){if(_0x4f0f16){return _0x4f0f16[_0xcd08('0x29')]()[_0xcd08('0x28')](function(){_0x52a0c4[_0xcd08('0x1d')](0xcc)[_0xcd08('0x1c')]();});}};}function handleEntityNotFound(_0x1f1aff,_0x17fb23){return function(_0x493986){if(!_0x493986){_0x1f1aff[_0xcd08('0x1b')](0x194);}return _0x493986;};}function handleError(_0x1eba3e,_0x1f6cd7){_0x1f6cd7=_0x1f6cd7||0x1f4;return function(_0x153ed6){logger[_0xcd08('0x2a')](_0x153ed6[_0xcd08('0x2b')]);if(_0x153ed6[_0xcd08('0x2c')]){delete _0x153ed6[_0xcd08('0x2c')];}_0x1eba3e[_0xcd08('0x1d')](_0x1f6cd7)[_0xcd08('0x2d')](_0x153ed6);};}exports[_0xcd08('0x2e')]=function(_0x28011c,_0x332dc8){var _0x53f9b8={},_0x38a5ae={},_0x308b34={'count':0x0,'rows':[]};return db['CmContact'][_0xcd08('0x2f')]()['then'](function(_0x131ad9){var _0x52edd3=[];for(var _0x4b178f=0x0;_0x4b178f<Object[_0xcd08('0x30')](_0x131ad9)[_0xcd08('0x31')];_0x4b178f++){var _0x233b21=Object[_0xcd08('0x30')](_0x131ad9)[_0x4b178f];if(_['startsWith'](_0x233b21,_0xcd08('0x32'))){_0x52edd3['push'](db['CmCustomField'][_0xcd08('0x33')]({'where':{'id':_[_0xcd08('0x34')](_0x233b21,_0xcd08('0x32'))},'raw':!![]}));}}return BPromise[_0xcd08('0x35')](_0x52edd3)[_0xcd08('0x28')](function(_0x677cf9){for(var _0x38466a=0x0;_0x38466a<_0x677cf9['length'];_0x38466a++){if(_0x677cf9[_0x38466a]){var _0x5b0858=_0xcd08('0x32')+_0x677cf9[_0x38466a]['id'];var _0x126156=_0x131ad9[_0x5b0858];_0x126156[_0xcd08('0x36')]=_0x677cf9[_0x38466a][_0xcd08('0x37')];}}return _0x131ad9;});})[_0xcd08('0x28')](function(_0x33e2dd){_0x38a5ae[_0xcd08('0x38')]=_[_0xcd08('0x30')](_0x33e2dd);_0x38a5ae['query']=_['keys'](_0x28011c[_0xcd08('0x39')]);_0x38a5ae['filters']=_['intersection'](_0x38a5ae[_0xcd08('0x38')],_0x38a5ae[_0xcd08('0x39')]);_0x53f9b8[_0xcd08('0x3a')]=_['intersection'](_0x38a5ae[_0xcd08('0x38')],qs[_0xcd08('0x3b')](_0x28011c[_0xcd08('0x39')][_0xcd08('0x3b')]));_0x53f9b8[_0xcd08('0x3a')]=_0x53f9b8[_0xcd08('0x3a')][_0xcd08('0x31')]?_0x53f9b8[_0xcd08('0x3a')]:_0x38a5ae[_0xcd08('0x38')];if(!_0x28011c[_0xcd08('0x39')][_0xcd08('0x3c')](_0xcd08('0x3d'))){_0x53f9b8[_0xcd08('0x22')]=qs['limit'](_0x28011c['query']['limit']);_0x53f9b8[_0xcd08('0x1f')]=qs[_0xcd08('0x1f')](_0x28011c[_0xcd08('0x39')]['offset']);}_0x53f9b8[_0xcd08('0x3e')]=qs[_0xcd08('0x3f')](_0x28011c['query'][_0xcd08('0x3f')]);_0x53f9b8[_0xcd08('0x40')]=qs[_0xcd08('0x41')](_[_0xcd08('0x42')](_0x28011c['query'],_0x38a5ae[_0xcd08('0x41')]),_0x33e2dd);var _0x1d8c6e=[];var _0x4c5c6e=squel[_0xcd08('0x43')]()[_0xcd08('0x44')]('id')['field'](_0xcd08('0x2c'))['field'](_0xcd08('0x45'))[_0xcd08('0x46')]('tools_tags');var _0x474289=squel[_0xcd08('0x43')]()[_0xcd08('0x46')](_0xcd08('0x47'),'c')[_0xcd08('0x48')](_0xcd08('0x49'),'uc',_0xcd08('0x4a'))[_0xcd08('0x48')](_0xcd08('0x4b'),'ct',_0xcd08('0x4c'))[_0xcd08('0x48')]('tools_tags','t',_0xcd08('0x4d'))[_0xcd08('0x40')](_0xcd08('0x4e'));var _0x5dc8ef=squel['expr']();var _0x1326af=[];var _0x22e544=squel[_0xcd08('0x4f')]();var _0x310b80;if(_0x28011c[_0xcd08('0x39')]['search']){_0x310b80=as['parseSearch'](_0x28011c[_0xcd08('0x39')][_0xcd08('0x50')]);var _0x3b5663=_0x310b80['sqlOperator'];for(var _0x4cb3fc=0x0;_0x4cb3fc<_0x310b80[_0xcd08('0x51')][_0xcd08('0x31')];_0x4cb3fc++){var _0x5a6051=_0x310b80[_0xcd08('0x51')][_0x4cb3fc];var _0x3154a6='c';var _0x4c6eed=_(_0x33e2dd)[_0xcd08('0x30')]()['find'](function(_0x2ecb8b){return _0x2ecb8b===_0x5a6051[_0xcd08('0x44')];});if(_0x4c6eed)_0x4c6eed=_0x33e2dd[_0x5a6051[_0xcd08('0x44')]];if(!_0x4c6eed){if(_0x5a6051['field']===_0xcd08('0x52')){var _0x223ec5=_0x5a6051[_0xcd08('0x53')][_0xcd08('0x54')](',')[_0xcd08('0x55')](function(_0xfae3c){return Number(_0xfae3c);});_0x223ec5[_0xcd08('0x56')](function(_0x43f81c){_0x22e544['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x43f81c+',%');});_0x1326af=_[_0xcd08('0x57')](_0x1326af,_0x223ec5);}else if(_0x5a6051[_0xcd08('0x44')]==='User'){_0x5dc8ef[_0xcd08('0x58')]('uc.UserId\x20=\x20?',_0x5a6051['value']);}}else{if(_0x5a6051[_0xcd08('0x44')]==='dateOfBirth'||_0x4c6eed[_0xcd08('0x36')]===_0xcd08('0x59'))_0x5a6051['castTo']=_0xcd08('0x5a');var _0x348b76=as[_0xcd08('0x5b')](_0x3154a6,_0x4c6eed[_0xcd08('0x37')],_0x5a6051);_0x5dc8ef[_0x3b5663](_0x348b76[_0xcd08('0x5c')],_0x348b76[_0xcd08('0x53')][_0xcd08('0x5d')],_0x348b76[_0xcd08('0x53')][_0xcd08('0x1c')]);}}}else{var _0x4d27a7=_(Object[_0xcd08('0x30')](_0x28011c[_0xcd08('0x39')]))[_0xcd08('0x55')](function(_0x96677c){return _0x33e2dd[_0xcd08('0x3c')](_0x96677c)?_0x96677c:undefined;})[_0xcd08('0x5e')](function(_0x283380){return!_[_0xcd08('0x5f')](_0x283380);})[_0xcd08('0x53')]();if(_0x28011c[_0xcd08('0x39')][_0xcd08('0x60')])_0x4d27a7['push'](_0xcd08('0x60'));if(!_[_0xcd08('0x61')](_0x4d27a7)){_0x4d27a7[_0xcd08('0x56')](function(_0x26a30c){if(_0x26a30c===_0xcd08('0x62')){_0x474289[_0xcd08('0x40')](_0xcd08('0x63'),[][_0xcd08('0x64')](_0x28011c[_0xcd08('0x39')][_0x26a30c]));}else if(_0x26a30c===_0xcd08('0x60')){var _0x259dc2='%'+_0x28011c[_0xcd08('0x39')][_0x26a30c]+'%';_0x474289[_0xcd08('0x40')](_0xcd08('0x65'),_0x259dc2);}else{_0x474289[_0xcd08('0x40')]('c.'+_0x26a30c+_0xcd08('0x66'),_0x28011c[_0xcd08('0x39')][_0x26a30c]);}});}if(_0x28011c['query'][_0xcd08('0x67')]){_0x1326af=_[_0xcd08('0x68')](_0x28011c[_0xcd08('0x39')][_0xcd08('0x67')])?_0x28011c[_0xcd08('0x39')][_0xcd08('0x67')]:new Array(_0x28011c[_0xcd08('0x39')]['tag']);_0x1326af[_0xcd08('0x56')](function(_0x3fd68e){_0x22e544['or'](_0xcd08('0x69'),'%,'+_0x3fd68e+',%');});}if(_0x28011c[_0xcd08('0x39')]['filter']){var _0x2e773b=_0x28011c[_0xcd08('0x39')][_0xcd08('0x5e')][_0xcd08('0x6a')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(_0x2e773b[_0xcd08('0x54')]('\x20')[_0xcd08('0x31')]>0x1){_0x5dc8ef['or'](_0xcd08('0x6b'),qs['getFullTextValue'](_0x2e773b),null);}else{if(qs[_0xcd08('0x6c')](_0x2e773b)){_0x5dc8ef['or'](_0xcd08('0x6d'),_0x2e773b+'%');_0x5dc8ef['or'](_0xcd08('0x6e'),_0x2e773b+'%');_0x5dc8ef['or'](_0xcd08('0x6f'),_0x2e773b+'%');_0x5dc8ef['or'](_0xcd08('0x70'),_0x2e773b+'%');}else if(qs[_0xcd08('0x71')](_0x2e773b)){_0x5dc8ef['or'](_0xcd08('0x72'),_0x2e773b+'%');}else{_0x5dc8ef['or'](_0xcd08('0x73'),'%'+_0x2e773b+'%');_0x5dc8ef['or'](_0xcd08('0x74'),'%'+_0x2e773b+'%');_0x5dc8ef['or'](_0xcd08('0x72'),'%'+_0x2e773b+'%');}}}}_0x474289[_0xcd08('0x40')](_0x5dc8ef);_0x474289['group'](_0xcd08('0x75'));var _0x18deac={'type':db[_0xcd08('0x76')][_0xcd08('0x77')][_0xcd08('0x78')],'raw':!![]};var _0x4b9193=_0x474289[_0xcd08('0x79')]()['field'](_0xcd08('0x75'));if(_0x53f9b8[_0xcd08('0x3e')]){_0x53f9b8[_0xcd08('0x3e')][_0xcd08('0x56')](function(_0x2860c1){_0x474289[_0xcd08('0x3e')]('c.'+_0x2860c1[0x0],_0x2860c1[0x1]===_0xcd08('0x7a')?![]:!![]);});}if(!_[_0xcd08('0x61')](_0x1326af)){_0x474289['having'](_0x22e544);_0x4b9193[_0xcd08('0x40')](_0xcd08('0x7b'),_0x1326af);}BPromise[_0xcd08('0x7c')]()['then'](function(){if(!_0x310b80)return;if(_0x28011c['user'][_0xcd08('0x7d')]!=='agent')return;if(!_[_0xcd08('0x7e')](_0x310b80['conditions'],[_0xcd08('0x44'),_0xcd08('0x7f')])){return _0x28011c[_0xcd08('0x80')][_0xcd08('0x81')]({'attributes':['id'],'raw':!![]})[_0xcd08('0x28')](function(_0x2e250f){if(_[_0xcd08('0x61')](_0x2e250f)){_0x4b9193[_0xcd08('0x40')](_0xcd08('0x82'));_0x474289['where'](_0xcd08('0x82'));}else{_0x4b9193['where'](_0xcd08('0x63'),_[_0xcd08('0x55')](_0x2e250f,'id'));_0x474289[_0xcd08('0x40')]('c.ListId\x20IN\x20?',_[_0xcd08('0x55')](_0x2e250f,'id'));}});}})[_0xcd08('0x28')](function(){if(_0x28011c[_0xcd08('0x80')][_0xcd08('0x7d')]===_0xcd08('0x83')&&!_0x310b80&&!_0x28011c[_0xcd08('0x39')]['ListId'])return[];return db[_0xcd08('0x84')][_0xcd08('0x39')](_0x4b9193[_0xcd08('0x85')](),_0x18deac);})[_0xcd08('0x28')](function(_0x251cfb){_0x308b34[_0xcd08('0x21')]=_0x251cfb[_0xcd08('0x31')];if(_0x308b34[_0xcd08('0x21')]===0x0)return[];return db[_0xcd08('0x84')][_0xcd08('0x39')](_0x4c5c6e[_0xcd08('0x85')](),_0x18deac)[_0xcd08('0x28')](function(_0x5ab489){_0x1d8c6e=_[_0xcd08('0x86')](_0x5ab489,'id');_0x18deac=_[_0xcd08('0x87')](_0x18deac,{'model':db[_0xcd08('0x88')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x28011c['query'][_0xcd08('0x3b')]){_0x53f9b8[_0xcd08('0x3a')][_0xcd08('0x56')](function(_0x33ad83){_0x474289[_0xcd08('0x44')]('c.'+_0x33ad83);});}else{_0x474289[_0xcd08('0x44')]('c.id');_0x474289[_0xcd08('0x44')](_0xcd08('0x89'));_0x474289[_0xcd08('0x44')](_0xcd08('0x8a'));_0x474289[_0xcd08('0x44')](_0xcd08('0x8b'));_0x474289[_0xcd08('0x44')](_0xcd08('0x8c'));_0x474289['field']('c.fax');_0x474289[_0xcd08('0x44')](_0xcd08('0x8d'));_0x474289[_0xcd08('0x44')](_0xcd08('0x8e'));_0x474289['field']('c.createdAt');_0x474289[_0xcd08('0x44')](_0xcd08('0x8f'));_0x474289[_0xcd08('0x44')](_0xcd08('0x90'));_0x474289[_0xcd08('0x44')](_0xcd08('0x91'),_0xcd08('0x92'));}if(_0x53f9b8['limit'])_0x474289[_0xcd08('0x22')](_0x53f9b8[_0xcd08('0x22')]);if(_0x53f9b8[_0xcd08('0x1f')])_0x474289['offset'](_0x53f9b8[_0xcd08('0x1f')]);return db[_0xcd08('0x84')][_0xcd08('0x39')](_0x474289[_0xcd08('0x85')](),_0x18deac);});})[_0xcd08('0x28')](function(_0x21e360){_0x21e360['forEach'](function(_0x31d95f){if(_0x31d95f[_0xcd08('0x92')]){_0x31d95f[_0xcd08('0x93')]=[];_0x31d95f[_0xcd08('0x92')][_0xcd08('0x54')](',')[_0xcd08('0x56')](function(_0x44356b){_0x31d95f[_0xcd08('0x93')][_0xcd08('0x94')](_0x1d8c6e[_0x44356b]);});}delete _0x31d95f[_0xcd08('0x92')];});_0x308b34['rows']=_0x21e360;return _0x308b34;})[_0xcd08('0x28')](respondWithFilteredResult(_0x332dc8,_0x53f9b8));})[_0xcd08('0x95')](handleError(_0x332dc8,null));};exports['destroy']=function(_0x252aa5,_0x1bbc11){return db[_0xcd08('0x88')][_0xcd08('0x96')]({'where':{'id':_0x252aa5['params']['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x1bbc11,null))[_0xcd08('0x28')](removeEntity(_0x1bbc11,null))[_0xcd08('0x95')](handleError(_0x1bbc11,null));};exports['describe']=function(_0x53933b,_0x34cfc7){return db[_0xcd08('0x88')]['describe']()['then'](function(_0xaf8138){delete _0xaf8138[_0xcd08('0x97')];for(var _0x683556=0x0;_0x683556<Object[_0xcd08('0x30')](_0xaf8138)[_0xcd08('0x31')];_0x683556++){var _0x4ad507=Object['keys'](_0xaf8138)[_0x683556];if(!_[_0xcd08('0x98')](_0x4ad507,_0xcd08('0x32'))){_0xaf8138[_0x4ad507]['columnName']=_0x4ad507;_0xaf8138[_0x4ad507][_0xcd08('0x99')]=_0x4ad507;}}return _0xaf8138;})[_0xcd08('0x28')](function(_0x577017){var _0x259091={'where':{'$or':[{'ListId':_0x53933b[_0xcd08('0x39')]['id']},{'ListId':null}]},'raw':!![]};return db['CmCustomField']['findAll'](_0x259091)[_0xcd08('0x28')](function(_0x529068){for(var _0x5dd57e=0x0;_0x5dd57e<_0x529068[_0xcd08('0x31')];_0x5dd57e++){var _0x358a5b='cf_'+_0x529068[_0x5dd57e]['id'];_0x577017[_0x358a5b]['columnName']=_0x358a5b;_0x577017[_0x358a5b]['displayName']=_0x529068[_0x5dd57e][_0xcd08('0x9a')];_0x577017[_0x358a5b]['custom']={'type':_0x529068[_0x5dd57e][_0xcd08('0x37')],'values':_0x529068[_0x5dd57e][_0xcd08('0x9b')]};}Object[_0xcd08('0x30')](_0x577017)[_0xcd08('0x56')](function(_0x17ab87){if(!_0x577017[_0x17ab87][_0xcd08('0x3c')](_0xcd08('0x9c'))){delete _0x577017[_0x17ab87];}});return _0x577017;});})[_0xcd08('0x28')](respondWithResult(_0x34cfc7,null))[_0xcd08('0x95')](handleError(_0x34cfc7,null));};exports[_0xcd08('0x87')]=function(_0x4b64a4,_0x54684b){var _0x5b76b5;var _0x20da50;var _0x226927;if(_0x4b64a4[_0xcd08('0x9d')]['id']){delete _0x4b64a4[_0xcd08('0x9d')]['id'];}return db[_0xcd08('0x88')][_0xcd08('0x9e')]({'where':{'id':[_0x4b64a4[_0xcd08('0x9d')]['to'],_0x4b64a4[_0xcd08('0x9d')]['from']]}})[_0xcd08('0x28')](function(_0x275b42){if(_0x275b42){if(_0x275b42[_0xcd08('0x31')]!==0x2){return null;}_0x275b42[0x0]=_0x275b42[0x0][_0xcd08('0x9f')]({'plain':!![]});_0x275b42[0x1]=_0x275b42[0x1]['get']({'plain':!![]});delete _0x275b42[0x0]['id'];delete _0x275b42[0x1]['id'];return _[_0xcd08('0xa0')](_0x275b42[0x0],_0x275b42[0x1],function(_0x26ec61,_0x249972){if(Array[_0xcd08('0x68')](_0x249972)&&!_0x249972['length']){return _0x26ec61;}else if(!_0x249972){return _0x26ec61;}});}})['then'](handleEntityNotFound(_0x54684b,null))[_0xcd08('0x28')](function(_0x25446a){if(_0x25446a){if(_0x25446a[_0xcd08('0x97')]&&_['isArray'](_0x25446a['tags'])){_0x25446a[_0xcd08('0x97')]=_0x25446a[_0xcd08('0x97')][_0xcd08('0xa1')]();}logger[_0xcd08('0xa2')](_0xcd08('0xa3'),_0x4b64a4[_0xcd08('0x9d')]['to'],_0x4b64a4[_0xcd08('0x9d')]['from']);return db[_0xcd08('0xa4')][_0xcd08('0x29')]({'where':{'ContactId':[_0x4b64a4[_0xcd08('0x9d')]['to'],_0x4b64a4[_0xcd08('0x9d')][_0xcd08('0x46')]]}})[_0xcd08('0x28')](function(_0xbc7781){logger[_0xcd08('0xa2')](_0xcd08('0xa5'),_0xbc7781);return db[_0xcd08('0xa6')]['destroy']({'where':{'ContactId':[_0x4b64a4[_0xcd08('0x9d')]['to'],_0x4b64a4['body'][_0xcd08('0x46')]]}})[_0xcd08('0x28')](function(_0xf8ab71){logger['info'](_0xcd08('0xa7'),_0xf8ab71);return db[_0xcd08('0x88')][_0xcd08('0xa8')](_0x25446a);});});}})[_0xcd08('0x28')](function(_0x36eaa6){if(_0x36eaa6){_0x5b76b5=_0x36eaa6;_0x20da50={'ContactId':_0x5b76b5['id']};_0x226927={'where':{'ContactId':[_0x4b64a4[_0xcd08('0x9d')]['to'],_0x4b64a4[_0xcd08('0x9d')][_0xcd08('0x46')]]}};return db[_0xcd08('0xa9')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db['ChatMessage'][_0xcd08('0xaa')](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db['ChatOfflineMessage']['update'](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db[_0xcd08('0xab')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db[_0xcd08('0xac')]['update'](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xab')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db['MailMessage']['update'](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xad')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db[_0xcd08('0xae')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xaf')]['update'](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb0')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db[_0xcd08('0xb1')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db['OpenchannelMessage'][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb2')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb3')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db['ReportAgentPreview'][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb4')]['update'](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb5')]['update'](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb6')]['update'](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb7')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb8')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xb9')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db['JscriptySessionReport'][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xba')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})['then'](function(){if(_0x5b76b5){return db[_0xcd08('0xbb')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0xbc')][_0xcd08('0xaa')](_0x20da50,_0x226927);}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return db[_0xcd08('0x88')][_0xcd08('0x29')]({'where':{'id':[_0x4b64a4[_0xcd08('0x9d')]['to'],_0x4b64a4[_0xcd08('0x9d')]['from']]}});}})[_0xcd08('0x28')](function(){if(_0x5b76b5){return _0x5b76b5;}})[_0xcd08('0x28')](respondWithResult(_0x54684b,null))[_0xcd08('0x95')](handleError(_0x54684b,null));};exports['create']=function(_0xb85e54,_0x44002c){return db[_0xcd08('0x88')][_0xcd08('0x2f')]()['then'](function(_0x3e6e63){if(_0xb85e54['body'][_0xcd08('0x97')]&&_[_0xcd08('0x68')](_0xb85e54[_0xcd08('0x9d')][_0xcd08('0x97')])){if(_0xb85e54[_0xcd08('0x9d')][_0xcd08('0x97')]['length']){_0xb85e54[_0xcd08('0x9d')][_0xcd08('0x97')]=_0xb85e54[_0xcd08('0x9d')]['tags'][_0xcd08('0xa1')](';')+';';}else{_0xb85e54[_0xcd08('0x9d')][_0xcd08('0x97')]=null;}}else{_0xb85e54[_0xcd08('0x9d')][_0xcd08('0x97')]=null;}return db[_0xcd08('0x88')][_0xcd08('0xa8')](_0xb85e54[_0xcd08('0x9d')],{'fields':_[_0xcd08('0x30')](_0x3e6e63),'raw':!![]});})[_0xcd08('0x28')](respondWithResult(_0x44002c,0xc9))[_0xcd08('0x95')](handleError(_0x44002c,null));};exports[_0xcd08('0xbd')]=function(_0x186cc6,_0x392ce7){var _0x2f4c7f=[];var _0x3e53b0=0x0;var _0x3fb462=0x0;var _0x2e527=0x0;return db['CmContact'][_0xcd08('0x2f')]()[_0xcd08('0x28')](function(_0x2f12ca){return BPromise[_0xcd08('0xbe')](_0x186cc6[_0xcd08('0x9d')],function(_0x23c829){var _0x4bc484={'where':{'$or':[]},'defaults':_0x23c829,'fields':_[_0xcd08('0x30')](_0x2f12ca),'raw':!![]};if(_0x23c829[_0xcd08('0xbf')]){for(var _0x1e983c=0x0;_0x1e983c<_0x23c829[_0xcd08('0xbf')][_0xcd08('0x31')];_0x1e983c++){var _0x355e65={};_0x355e65[_0x23c829[_0xcd08('0xbf')][_0x1e983c]]=_0x23c829[_0x23c829[_0xcd08('0xbf')][_0x1e983c]];_0x4bc484[_0xcd08('0x40')][_0xcd08('0xc0')][_0xcd08('0x94')](_0x355e65);}_0x4bc484['where']['ListId']=_0x23c829[_0xcd08('0x62')];}return db[_0xcd08('0x88')][_0xcd08('0xc1')](_0x4bc484)[_0xcd08('0xc2')](function(_0x518d1c,_0x2349f9){if(_0x2349f9){_0x3e53b0++;}else{_0x2e527++;}})[_0xcd08('0x95')](function(_0x28b981){console['error'](_0x28b981);_0x3fb462++;});});})[_0xcd08('0x28')](function(_0x51c297){if(_0x51c297){return{'success':_0x3e53b0,'failure':_0x3fb462,'duplicates':_0x2e527};}})[_0xcd08('0x28')](respondWithResult(_0x392ce7,0xc9))[_0xcd08('0x95')](handleError(_0x392ce7,null));};exports[_0xcd08('0xc3')]=function(_0x1765e9,_0x240807,_0x166b8a){var _0x14282d;return db[_0xcd08('0x88')][_0xcd08('0x2f')]()[_0xcd08('0x28')](function(_0x551bf7){return db[_0xcd08('0x88')]['find']({'where':{'id':_0x1765e9['params']['id']},'include':[{'model':db[_0xcd08('0x52')],'as':_0xcd08('0x93'),'attributes':['id',_0xcd08('0x2c'),_0xcd08('0x45')],'required':_0x1765e9['query']['tag']?!![]:![]}],'attributes':_[_0xcd08('0x30')](_0x551bf7)});})['then'](function(_0x2b9fcb){_0x14282d=_0x2b9fcb[_0xcd08('0x9f')]({'plain':!![]});var _0x1aef30={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2b9fcb&&_0x2b9fcb[_0xcd08('0x62')]){if(_0x2b9fcb[_0xcd08('0x62')]){_0x1aef30[_0xcd08('0x40')]['$and'][_0xcd08('0x94')]({'ListId':{'$ne':_0x2b9fcb['ListId']}});}}return db[_0xcd08('0xc4')][_0xcd08('0x9e')](_0x1aef30);})[_0xcd08('0x28')](function(_0xbaa70c){return _['omit'](_0x14282d,_[_0xcd08('0x55')](_0xbaa70c,function(_0x13345b){return util[_0xcd08('0xc5')](_0xcd08('0xc6'),_0x13345b['id']);}));})[_0xcd08('0x28')](handleEntityNotFound(_0x240807,null))[_0xcd08('0x28')](respondWithResult(_0x240807,null))['catch'](handleError(_0x240807,null));};exports[_0xcd08('0xaa')]=function(_0x58f10b,_0x463bc6){var _0x264742;if(_0x58f10b['body']['id']){delete _0x58f10b[_0xcd08('0x9d')]['id'];}return db[_0xcd08('0x88')][_0xcd08('0x96')]({'where':{'id':_0x58f10b[_0xcd08('0xc7')]['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x463bc6,null))['then'](saveUpdates(_0x58f10b['body'],null))[_0xcd08('0x28')](function(_0x29fb6a){_0x264742=_0x29fb6a;var _0x25ce82={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x29fb6a&&_0x29fb6a[_0xcd08('0x62')]){if(_0x29fb6a['ListId']){_0x25ce82['where'][_0xcd08('0xc8')][_0xcd08('0x94')]({'ListId':{'$ne':_0x29fb6a[_0xcd08('0x62')]}});}}return db[_0xcd08('0xc4')][_0xcd08('0x9e')](_0x25ce82);})[_0xcd08('0x28')](function(_0x24f258){if(_0x24f258){return _[_0xcd08('0xc9')](_[_0xcd08('0xca')](_0x58f10b[_0xcd08('0x9d')],function(_0x20de43,_0x730265){return _['startsWith'](_0x730265,_0xcd08('0x32'));}),_[_0xcd08('0x55')](_0x24f258,function(_0x2c8791){return util[_0xcd08('0xc5')](_0xcd08('0xc6'),_0x2c8791['id']);}));}})[_0xcd08('0x28')](function(_0x53ca99){if(_0x53ca99&&!_['isEmpty'](_0x53ca99)){var _0x4acebe=squel[_0xcd08('0xaa')]()[_0xcd08('0xcb')](_0xcd08('0x47'))[_0xcd08('0xcc')](_0x53ca99)[_0xcd08('0x40')]('id\x20=\x20?',_0x58f10b[_0xcd08('0xc7')]['id'])[_0xcd08('0xcd')]();return db[_0xcd08('0x84')]['query'](_0x4acebe['text'],{'replacements':_0x4acebe[_0xcd08('0x9b')]});}})[_0xcd08('0x28')](function(){if(_0x58f10b[_0xcd08('0x9d')][_0xcd08('0xce')]&&_0x264742){return db['CmHopper'][_0xcd08('0xaa')]({'phone':_0x58f10b[_0xcd08('0x9d')][_0xcd08('0xce')]},{'where':{'ContactId':_0x264742['id']}});}})[_0xcd08('0x28')](function(){return _0x264742;})[_0xcd08('0x28')](respondWithResult(_0x463bc6,null))[_0xcd08('0x95')](handleError(_0x463bc6,null));};exports[_0xcd08('0xcf')]=function(_0x113922,_0x46ac95,_0x19e25d){var _0x363efc={};var _0xa39c35={};var _0x109cd0;var _0x461aa8;return db[_0xcd08('0x88')][_0xcd08('0x33')]({'where':{'id':_0x113922[_0xcd08('0xc7')]['id']}})['then'](handleEntityNotFound(_0x46ac95,null))['then'](function(_0x2bf2ed){if(_0x2bf2ed){_0x109cd0=_0x2bf2ed;_0xa39c35['model']=_['keys'](db[_0xcd08('0x52')][_0xcd08('0xd0')]);_0xa39c35[_0xcd08('0x39')]=_[_0xcd08('0x30')](_0x113922[_0xcd08('0x39')]);_0xa39c35[_0xcd08('0x41')]=_[_0xcd08('0xd1')](_0xa39c35[_0xcd08('0x38')],_0xa39c35[_0xcd08('0x39')]);_0x363efc['attributes']=_['intersection'](_0xa39c35[_0xcd08('0x38')],qs[_0xcd08('0x3b')](_0x113922[_0xcd08('0x39')][_0xcd08('0x3b')]));_0x363efc[_0xcd08('0x3a')]=_0x363efc[_0xcd08('0x3a')]['length']?_0x363efc[_0xcd08('0x3a')]:_0xa39c35[_0xcd08('0x38')];_0x363efc['order']=qs[_0xcd08('0x3f')](_0x113922[_0xcd08('0x39')][_0xcd08('0x3f')]);_0x363efc[_0xcd08('0x40')]=qs[_0xcd08('0x41')](_['pick'](_0x113922[_0xcd08('0x39')],_0xa39c35[_0xcd08('0x41')]));if(_0x113922[_0xcd08('0x39')][_0xcd08('0x5e')]){_0x363efc['where']=_['merge'](_0x363efc['where'],{'$or':_['map'](_0x363efc[_0xcd08('0x3a')],function(_0x4ce0d9){var _0x18ede2={};_0x18ede2[_0x4ce0d9]={'$like':'%'+_0x113922[_0xcd08('0x39')][_0xcd08('0x5e')]+'%'};return _0x18ede2;})});}_0x363efc=_[_0xcd08('0x87')]({},_0x363efc,_0x113922[_0xcd08('0xd2')]);return _0x109cd0[_0xcd08('0xcf')](_0x363efc);}})[_0xcd08('0x28')](function(_0x4d1c00){if(_0x4d1c00){_0x461aa8=_0x4d1c00[_0xcd08('0x31')];if(!_0x113922[_0xcd08('0x39')][_0xcd08('0x3c')]('nolimit')){_0x363efc[_0xcd08('0x22')]=qs[_0xcd08('0x22')](_0x113922['query'][_0xcd08('0x22')]);_0x363efc[_0xcd08('0x1f')]=qs[_0xcd08('0x1f')](_0x113922[_0xcd08('0x39')][_0xcd08('0x1f')]);}return _0x109cd0[_0xcd08('0xcf')](_0x363efc);}})[_0xcd08('0x28')](function(_0x2c2176){if(_0x2c2176){return _0x2c2176?{'count':_0x461aa8,'rows':_0x2c2176}:null;}})['then'](respondWithResult(_0x46ac95,null))[_0xcd08('0x95')](handleError(_0x46ac95,null));};exports[_0xcd08('0xd3')]=function(_0x44ce00,_0x25d242,_0x5e404a){if(_0x44ce00[_0xcd08('0x9d')]['id']){delete _0x44ce00[_0xcd08('0x9d')]['id'];}return db['CmContact'][_0xcd08('0x33')]({'where':{'id':_0x44ce00['params']['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x25d242,null))[_0xcd08('0x28')](function(_0x301034){if(_0x301034){return _0x301034['setTags'](_0x44ce00[_0xcd08('0x9d')][_0xcd08('0xd4')]||[]);}return null;})[_0xcd08('0x28')](respondWithResult(_0x25d242,null))[_0xcd08('0x95')](handleError(_0x25d242,null));};exports[_0xcd08('0xd5')]=function(_0x46aef5,_0x1389db,_0xc785c7){var _0x596b4b={'raw':![],'where':{}};var _0x3a5654={};var _0x3932e2={'count':0x0,'rows':[]};return db[_0xcd08('0x88')][_0xcd08('0x33')]({'where':{'id':_0x46aef5[_0xcd08('0xc7')]['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x1389db,null))[_0xcd08('0x28')](function(_0x4af385){if(_0x4af385){_0x3a5654[_0xcd08('0x38')]=_['keys'](db['CmHopper'][_0xcd08('0xd0')]);_0x3a5654[_0xcd08('0x39')]=_[_0xcd08('0x30')](_0x46aef5['query']);_0x3a5654[_0xcd08('0x41')]=_['intersection'](_0x3a5654[_0xcd08('0x38')],_0x3a5654['query']);_0x596b4b[_0xcd08('0x3a')]=_[_0xcd08('0xd1')](_0x3a5654['model'],qs[_0xcd08('0x3b')](_0x46aef5[_0xcd08('0x39')][_0xcd08('0x3b')]));_0x596b4b['attributes']=_0x596b4b['attributes'][_0xcd08('0x31')]?_0x596b4b[_0xcd08('0x3a')]:_0x3a5654['model'];if(!_0x46aef5[_0xcd08('0x39')]['hasOwnProperty']('nolimit')){_0x596b4b[_0xcd08('0x22')]=qs[_0xcd08('0x22')](_0x46aef5[_0xcd08('0x39')][_0xcd08('0x22')]);_0x596b4b['offset']=qs[_0xcd08('0x1f')](_0x46aef5[_0xcd08('0x39')][_0xcd08('0x1f')]);}_0x596b4b[_0xcd08('0x3e')]=qs[_0xcd08('0x3f')](_0x46aef5[_0xcd08('0x39')][_0xcd08('0x3f')]);_0x596b4b[_0xcd08('0x40')]=qs[_0xcd08('0x41')](_['pick'](_0x46aef5[_0xcd08('0x39')],_0x3a5654[_0xcd08('0x41')]));_0x596b4b[_0xcd08('0x40')][_0xcd08('0xd6')]=_0x4af385['id'];if(_0x46aef5[_0xcd08('0x39')]['filter']){_0x596b4b[_0xcd08('0x40')]=_[_0xcd08('0x87')](_0x596b4b[_0xcd08('0x40')],{'$or':_[_0xcd08('0x55')](_0x596b4b[_0xcd08('0x3a')],function(_0xdb530){var _0x14b27c={};_0x14b27c[_0xdb530]={'$like':'%'+_0x46aef5[_0xcd08('0x39')][_0xcd08('0x5e')]+'%'};return _0x14b27c;})});}_0x596b4b=_[_0xcd08('0x87')]({},_0x596b4b,_0x46aef5['options']);return db[_0xcd08('0xa4')]['count']({'where':_0x596b4b[_0xcd08('0x40')]})[_0xcd08('0x28')](function(_0x581643){_0x3932e2['count']=_0x581643;if(_0x46aef5[_0xcd08('0x39')]['includeAll']){_0x596b4b['include']=[{'all':!![]}];}return db[_0xcd08('0xa4')][_0xcd08('0x9e')](_0x596b4b);})['then'](function(_0x5742e3){_0x3932e2[_0xcd08('0xd7')]=_0x5742e3;return _0x3932e2;});}})[_0xcd08('0x28')](respondWithFilteredResult(_0x1389db,_0x596b4b))[_0xcd08('0x95')](handleError(_0x1389db,null));};exports[_0xcd08('0xd8')]=function(_0x16331,_0x28db7,_0x8634bf){var _0x12f870={'raw':!![],'where':{}};var _0x4b2800={};var _0x100fdc={'count':0x0,'rows':[]};return db['CmContact'][_0xcd08('0x33')]({'where':{'id':_0x16331['params']['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x28db7,null))[_0xcd08('0x28')](function(_0x549fd8){if(_0x549fd8){_0x4b2800[_0xcd08('0x38')]=_[_0xcd08('0x30')](db[_0xcd08('0xb3')][_0xcd08('0xd0')]);_0x4b2800[_0xcd08('0x39')]=_[_0xcd08('0x30')](_0x16331['query']);_0x4b2800[_0xcd08('0x41')]=_[_0xcd08('0xd1')](_0x4b2800[_0xcd08('0x38')],_0x4b2800[_0xcd08('0x39')]);_0x12f870[_0xcd08('0x3a')]=_[_0xcd08('0xd1')](_0x4b2800[_0xcd08('0x38')],qs[_0xcd08('0x3b')](_0x16331[_0xcd08('0x39')][_0xcd08('0x3b')]));_0x12f870[_0xcd08('0x3a')]=_0x12f870[_0xcd08('0x3a')]['length']?_0x12f870['attributes']:_0x4b2800[_0xcd08('0x38')];if(!_0x16331[_0xcd08('0x39')][_0xcd08('0x3c')](_0xcd08('0x3d'))){_0x12f870[_0xcd08('0x22')]=qs[_0xcd08('0x22')](_0x16331[_0xcd08('0x39')]['limit']);_0x12f870[_0xcd08('0x1f')]=qs[_0xcd08('0x1f')](_0x16331[_0xcd08('0x39')][_0xcd08('0x1f')]);}_0x12f870[_0xcd08('0x3e')]=qs[_0xcd08('0x3f')](_0x16331['query'][_0xcd08('0x3f')]);_0x12f870[_0xcd08('0x40')]=qs[_0xcd08('0x41')](_[_0xcd08('0x42')](_0x16331[_0xcd08('0x39')],_0x4b2800[_0xcd08('0x41')]));_0x12f870[_0xcd08('0x40')][_0xcd08('0xd6')]=_0x549fd8['id'];if(_0x16331[_0xcd08('0x39')]['filter']){_0x12f870[_0xcd08('0x40')]=_[_0xcd08('0x87')](_0x12f870[_0xcd08('0x40')],{'$or':_[_0xcd08('0x55')](_0x12f870[_0xcd08('0x3a')],function(_0x1e45dd){var _0x52d7e1={};_0x52d7e1[_0x1e45dd]={'$like':'%'+_0x16331[_0xcd08('0x39')][_0xcd08('0x5e')]+'%'};return _0x52d7e1;})});}_0x12f870=_['merge']({},_0x12f870,_0x16331[_0xcd08('0xd2')]);return db['CmHopperHistory']['count']({'where':_0x12f870[_0xcd08('0x40')]})[_0xcd08('0x28')](function(_0x5baa71){_0x100fdc[_0xcd08('0x21')]=_0x5baa71;if(_0x16331[_0xcd08('0x39')][_0xcd08('0xd9')]){_0x12f870[_0xcd08('0xda')]=[{'all':!![]}];}return db[_0xcd08('0xb3')][_0xcd08('0x9e')](_0x12f870);})['then'](function(_0x1b8195){_0x100fdc[_0xcd08('0xd7')]=_0x1b8195;return _0x100fdc;});}})[_0xcd08('0x28')](respondWithFilteredResult(_0x28db7,_0x12f870))[_0xcd08('0x95')](handleError(_0x28db7,null));};exports[_0xcd08('0xdb')]=function(_0x1dae3f,_0x280a54,_0x155dc1){var _0x54c3b5={'raw':!![],'where':{}};var _0x5726cc={};var _0x4681c5={'count':0x0,'rows':[]};return db[_0xcd08('0x88')][_0xcd08('0x33')]({'where':{'id':_0x1dae3f['params']['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x280a54,null))[_0xcd08('0x28')](function(_0x4897ed){if(_0x4897ed){_0x5726cc[_0xcd08('0x38')]=_[_0xcd08('0x30')](db['CmHopperFinal'][_0xcd08('0xd0')]);_0x5726cc[_0xcd08('0x39')]=_['keys'](_0x1dae3f['query']);_0x5726cc[_0xcd08('0x41')]=_[_0xcd08('0xd1')](_0x5726cc['model'],_0x5726cc[_0xcd08('0x39')]);_0x54c3b5[_0xcd08('0x3a')]=_[_0xcd08('0xd1')](_0x5726cc[_0xcd08('0x38')],qs[_0xcd08('0x3b')](_0x1dae3f[_0xcd08('0x39')]['fields']));_0x54c3b5[_0xcd08('0x3a')]=_0x54c3b5[_0xcd08('0x3a')][_0xcd08('0x31')]?_0x54c3b5[_0xcd08('0x3a')]:_0x5726cc[_0xcd08('0x38')];if(!_0x1dae3f['query'][_0xcd08('0x3c')](_0xcd08('0x3d'))){_0x54c3b5['limit']=qs[_0xcd08('0x22')](_0x1dae3f[_0xcd08('0x39')]['limit']);_0x54c3b5[_0xcd08('0x1f')]=qs[_0xcd08('0x1f')](_0x1dae3f['query'][_0xcd08('0x1f')]);}_0x54c3b5['order']=qs['sort'](_0x1dae3f[_0xcd08('0x39')][_0xcd08('0x3f')]);_0x54c3b5[_0xcd08('0x40')]=qs[_0xcd08('0x41')](_[_0xcd08('0x42')](_0x1dae3f[_0xcd08('0x39')],_0x5726cc[_0xcd08('0x41')]));_0x54c3b5[_0xcd08('0x40')]['ContactId']=_0x4897ed['id'];if(_0x1dae3f[_0xcd08('0x39')][_0xcd08('0x5e')]){_0x54c3b5[_0xcd08('0x40')]=_['merge'](_0x54c3b5[_0xcd08('0x40')],{'$or':_[_0xcd08('0x55')](_0x54c3b5['attributes'],function(_0x5e3cf1){var _0x10aa74={};_0x10aa74[_0x5e3cf1]={'$like':'%'+_0x1dae3f['query'][_0xcd08('0x5e')]+'%'};return _0x10aa74;})});}_0x54c3b5=_['merge']({},_0x54c3b5,_0x1dae3f[_0xcd08('0xd2')]);return db['CmHopperFinal'][_0xcd08('0x21')]({'where':_0x54c3b5[_0xcd08('0x40')]})[_0xcd08('0x28')](function(_0x32b171){_0x4681c5[_0xcd08('0x21')]=_0x32b171;if(_0x1dae3f[_0xcd08('0x39')][_0xcd08('0xd9')]){_0x54c3b5['include']=[{'all':!![]}];}return db[_0xcd08('0xb2')][_0xcd08('0x9e')](_0x54c3b5);})[_0xcd08('0x28')](function(_0x3720d1){_0x4681c5['rows']=_0x3720d1;return _0x4681c5;});}})['then'](respondWithFilteredResult(_0x280a54,_0x54c3b5))[_0xcd08('0x95')](handleError(_0x280a54,null));};exports[_0xcd08('0xdc')]=function(_0x393fd8,_0x12424c,_0x18c82b){var _0x2d02e5={'raw':!![],'where':{}};var _0x4792b3={};var _0x171f66={'count':0x0,'rows':[]};return db['CmContact'][_0xcd08('0x33')]({'where':{'id':_0x393fd8[_0xcd08('0xc7')]['id']}})[_0xcd08('0x28')](handleEntityNotFound(_0x12424c,null))['then'](function(_0x5e4b0a){if(_0x5e4b0a){_0x4792b3[_0xcd08('0x38')]=_[_0xcd08('0x30')](db[_0xcd08('0xdd')]['rawAttributes']);_0x4792b3[_0xcd08('0x39')]=_['keys'](_0x393fd8[_0xcd08('0x39')]);_0x4792b3[_0xcd08('0x41')]=_[_0xcd08('0xd1')](_0x4792b3[_0xcd08('0x38')],_0x4792b3[_0xcd08('0x39')]);_0x2d02e5[_0xcd08('0x3a')]=_['intersection'](_0x4792b3[_0xcd08('0x38')],qs['fields'](_0x393fd8['query'][_0xcd08('0x3b')]));_0x2d02e5[_0xcd08('0x3a')]=_0x2d02e5['attributes'][_0xcd08('0x31')]?_0x2d02e5[_0xcd08('0x3a')]:_0x4792b3['model'];if(!_0x393fd8['query']['hasOwnProperty'](_0xcd08('0x3d'))){_0x2d02e5[_0xcd08('0x22')]=qs[_0xcd08('0x22')](_0x393fd8[_0xcd08('0x39')][_0xcd08('0x22')]);_0x2d02e5[_0xcd08('0x1f')]=qs['offset'](_0x393fd8[_0xcd08('0x39')][_0xcd08('0x1f')]);}_0x2d02e5[_0xcd08('0x3e')]=qs[_0xcd08('0x3f')](_0x393fd8[_0xcd08('0x39')][_0xcd08('0x3f')]);_0x2d02e5[_0xcd08('0x40')]=qs[_0xcd08('0x41')](_[_0xcd08('0x42')](_0x393fd8['query'],_0x4792b3[_0xcd08('0x41')]));_0x2d02e5[_0xcd08('0x40')][_0xcd08('0xd6')]=_0x5e4b0a['id'];if(_0x393fd8['query'][_0xcd08('0x5e')]){_0x2d02e5[_0xcd08('0x40')]=_[_0xcd08('0x87')](_0x2d02e5[_0xcd08('0x40')],{'$or':_[_0xcd08('0x55')](_0x2d02e5[_0xcd08('0x3a')],function(_0x3b6b06){var _0x7cdaa5={};_0x7cdaa5[_0x3b6b06]={'$like':'%'+_0x393fd8[_0xcd08('0x39')][_0xcd08('0x5e')]+'%'};return _0x7cdaa5;})});}_0x2d02e5=_['merge']({},_0x2d02e5,_0x393fd8[_0xcd08('0xd2')]);return db[_0xcd08('0xdd')]['count']({'where':_0x2d02e5[_0xcd08('0x40')]})[_0xcd08('0x28')](function(_0x516f86){_0x171f66['count']=_0x516f86;if(_0x393fd8[_0xcd08('0x39')][_0xcd08('0xd9')]){_0x2d02e5['include']=[{'all':!![]}];}return db[_0xcd08('0xdd')][_0xcd08('0x9e')](_0x2d02e5);})['then'](function(_0x27815c){_0x171f66[_0xcd08('0xd7')]=_0x27815c;return _0x171f66;});}})['then'](respondWithFilteredResult(_0x12424c,_0x2d02e5))[_0xcd08('0x95')](handleError(_0x12424c,null));};exports[_0xcd08('0xde')]=function(_0xf21626,_0x3995b7,_0x37cdd4){try{if(!_0xf21626[_0xcd08('0x9d')][_0xcd08('0x62')]){throw new Error(_0xcd08('0xdf'));}if(!_0xf21626[_0xcd08('0x9d')][_0xcd08('0xe0')]){throw new Error(_0xcd08('0xe1'));}if(!_0xf21626[_0xcd08('0x9d')][_0xcd08('0xe2')]){throw new Error(_0xcd08('0xe3'));}if(!_0xf21626['body'][_0xcd08('0xe4')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x28ccf9=_0xf21626[_0xcd08('0x9d')]['binding_keys'][_0xcd08('0x54')](',');var _0xb35c41=_0xf21626[_0xcd08('0x9d')][_0xcd08('0xe2')][_0xcd08('0x54')](',');if(!_0x28ccf9[_0xcd08('0x31')]||!_0xb35c41[_0xcd08('0x31')]||_0x28ccf9[_0xcd08('0x31')]!==_0xb35c41[_0xcd08('0x31')]){throw new Error(_0xcd08('0xe5'));}_0xf21626['body'][_0xcd08('0x3b')]=_[_0xcd08('0xe6')](_0x28ccf9,_0xb35c41);if(!_0xf21626[_0xcd08('0x9d')][_0xcd08('0x3b')][_0xcd08('0xce')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0xf21626[_0xcd08('0x9d')][_0xcd08('0x3b')]['firstName']){throw new Error('No\x20firstName\x20column\x20specified');}var _0x139851=path[_0xcd08('0xa1')](config[_0xcd08('0xe7')],_0xcd08('0xe8'),_0xf21626[_0xcd08('0xe9')][_0xcd08('0xea')]);fs[_0xcd08('0xeb')](_0x139851,parseInt(_0xcd08('0xec'),0x8));var _0x48d065=require(_0xcd08('0xed'))[_0xcd08('0xee')](path[_0xcd08('0xa1')](__dirname,_0xcd08('0xef')),[_0x139851,_0xf21626['body'][_0xcd08('0xe0')],_0xf21626['body'][_0xcd08('0xe2')],_0xf21626['body'][_0xcd08('0x62')],_0xf21626[_0xcd08('0x9d')][_0xcd08('0xf0')],_0xf21626['body'][_0xcd08('0xbf')],_0xf21626['body'][_0xcd08('0xe4')]]);return _0x3995b7[_0xcd08('0x1d')](0xc8)[_0xcd08('0x1e')]({'message':'File\x20uploaded\x20correctly!','pid':_0x48d065['pid']});}catch(_0x245961){return _0x3995b7[_0xcd08('0x1d')](0x1f4)[_0xcd08('0x2d')](_0x245961);}};exports[_0xcd08('0xf1')]=function(_0x5b0e9b,_0x23bb55,_0x134ba2){var _0x451a86=fs[_0xcd08('0xf2')](_0x5b0e9b[_0xcd08('0xe9')][_0xcd08('0xf3')]);Papa[_0xcd08('0xf4')](_0x451a86,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0xcab461){return _0x23bb55['status'](0xc8)['json']({'file':_0x5b0e9b[_0xcd08('0xe9')],'fields':_0xcab461[_0xcd08('0xf5')][_0xcd08('0x3b')]});}});};exports['import']=function(_0x38be75,_0x3551bf,_0x2bf93d){return db[_0xcd08('0x7f')][_0xcd08('0x9e')]({'raw':!![],'attributes':['id'],'where':{'role':_0xcd08('0x83')}})[_0xcd08('0x28')](function(_0x54e749){var _0x175cc3=![];if(!_0x38be75['body'][_0xcd08('0x62')]){throw new Error(_0xcd08('0xdf'));}if(!_0x38be75[_0xcd08('0x9d')][_0xcd08('0xf6')][_0xcd08('0xce')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x38be75[_0xcd08('0x9d')][_0xcd08('0xf6')][_0xcd08('0xf7')]){throw new Error(_0xcd08('0xf8'));}if(!_0x38be75[_0xcd08('0x9d')][_0xcd08('0xe4')]){throw new Error(_0xcd08('0xf9'));}var _0x29fa39=require(_0xcd08('0xed'))['fork'](path[_0xcd08('0xa1')](__dirname,_0xcd08('0xfa')),[_0x38be75[_0xcd08('0xc7')]['id'],JSON[_0xcd08('0xfb')](_0x38be75[_0xcd08('0x9d')]),JSON[_0xcd08('0xfb')](_0x54e749)]);_0x29fa39['on']('message',function(_0x5713f4){_0x175cc3=!![];return _0x3551bf[_0xcd08('0x1d')](0xc8)[_0xcd08('0x1e')]({'message':_0xcd08('0xfc'),'pid':_0x29fa39[_0xcd08('0xfd')]});});_0x29fa39['on']('exit',function(_0x353b06){if(_0x353b06&&!_0x175cc3){return _0x3551bf['status'](0x1f4)[_0xcd08('0x1e')]({'message':_0xcd08('0xfe'),'pid':_0x29fa39[_0xcd08('0xfd')]});}});})['catch'](handleError(_0x3551bf,null));};exports[_0xcd08('0xff')]=function(_0x18eb3e,_0x3c2162){var _0x4d1abd=['mail',_0xcd08('0x100'),_0xcd08('0x101'),_0xcd08('0x102'),'fax',_0xcd08('0x103'),'voice'];var _0x3d4ce7={'offset':0x0,'order':qs[_0xcd08('0x3f')]('-createdAt')},_0x1d7585={'count':0x0,'rows':[]};Promise[_0xcd08('0x7c')]()[_0xcd08('0x28')](function(){if(_0x18eb3e[_0xcd08('0x39')][_0xcd08('0x104')]){if(!_[_0xcd08('0x105')](_0x4d1abd,_0x18eb3e['query'][_0xcd08('0x104')][_0xcd08('0x106')]())){throw new Error('Invalid\x20channel');}_0x4d1abd=[_0x18eb3e[_0xcd08('0x39')][_0xcd08('0x104')][_0xcd08('0x106')]()];}if(_0x18eb3e['query'][_0xcd08('0x107')]){try{var _0x36d5b9=JSON[_0xcd08('0xf4')](_0x18eb3e[_0xcd08('0x39')][_0xcd08('0x107')]);if(!moment(_0x36d5b9[_0xcd08('0x46')])[_0xcd08('0x108')]()){throw new Error(_0xcd08('0x109'));}if(!moment(_0x36d5b9['to'])[_0xcd08('0x108')]()){throw new Error(_0xcd08('0x10a'));}}catch(_0x183ff8){throw new Error(_0xcd08('0x10b'));}}if(!_0x18eb3e[_0xcd08('0x39')]['hasOwnProperty'](_0xcd08('0x3d'))){_0x3d4ce7[_0xcd08('0x22')]=qs[_0xcd08('0x22')](_0x18eb3e[_0xcd08('0x39')]['limit']||0xa);_0x3d4ce7['offset']=qs[_0xcd08('0x1f')](_0x18eb3e[_0xcd08('0x39')][_0xcd08('0x1f')]);}var _0x40bd38=_0x4d1abd[_0xcd08('0x55')](function(_0x3e0adb){if(_0x3e0adb===_0xcd08('0x10c')){var _0x1620f8={'attributes':['id','uniqueid',_0xcd08('0x37'),'source',_0xcd08('0x10d'),_0xcd08('0x10e'),'starttime','endtime',_0xcd08('0x10f'),_0xcd08('0x110'),_0xcd08('0x111'),_0xcd08('0x112'),_0xcd08('0x113'),_0xcd08('0x114'),_0xcd08('0x115')],'where':{'ContactId':_0x18eb3e[_0xcd08('0xc7')]['id']},'include':[{'model':db['User'],'as':_0xcd08('0x7f'),'attributes':['id','name',_0xcd08('0x116'),'alias']}],'order':[['createdAt',_0xcd08('0x7a')]]};if(_0x18eb3e[_0xcd08('0x39')][_0xcd08('0x107')]){_0x1620f8[_0xcd08('0x40')][_0xcd08('0x111')]={'$gte':_0x36d5b9[_0xcd08('0x46')],'$lte':_0x36d5b9['to']};}return db[_0xcd08('0xb4')][_0xcd08('0x117')](_0x1620f8)['then'](function(_0x3087d6){_0x1d7585[_0xcd08('0x21')]+=_0x3087d6[_0xcd08('0x21')];return _['map'](_0x3087d6[_0xcd08('0xd7')],function(_0x4de215){var _0x3f8772=_0x4de215[_0xcd08('0x9f')]({'plain':!![]});_0x3f8772[_0xcd08('0x104')]=_0x3e0adb;if(_0x3f8772[_0xcd08('0x7f')]){_0x3f8772[_0xcd08('0x7f')]={'id':_0x3f8772[_0xcd08('0x7f')]['id'],'name':_0x3f8772[_0xcd08('0x7f')][_0xcd08('0x2c')],'fullname':_0x3f8772[_0xcd08('0x7f')][_0xcd08('0x116')],'alias':_0x3f8772[_0xcd08('0x7f')]['alias']};}return _0x3f8772;});});}else{var _0x5729a3=_['startCase'](_0x3e0adb)+(_0x3e0adb===_0xcd08('0x100')?_0xcd08('0x118'):'Account');var _0x1cf43e={'attributes':['id',_0xcd08('0x119'),_0xcd08('0x11a'),'createdAt',_0xcd08('0x110'),_0xcd08('0x11b'),_0xcd08('0x11c'),_0xcd08('0x11d'),_0xcd08('0x115'),_0x5729a3+'Id'],'where':{'ContactId':_0x18eb3e[_0xcd08('0xc7')]['id']},'include':[{'model':db[_0x5729a3],'as':'Account','attributes':['id',_0xcd08('0x2c'),_0xcd08('0x11e')]},{'model':db[_0xcd08('0x7f')],'as':_0xcd08('0x11f'),'attributes':['id',_0xcd08('0x2c'),_0xcd08('0x116')]},{'model':db[_0xcd08('0x52')],'as':'Tags','attributes':['id',_0xcd08('0x2c'),'color'],'through':{'attributes':[]}}],'order':[[_0xcd08('0x111'),'DESC']]};if(_0x18eb3e[_0xcd08('0x39')][_0xcd08('0x107')]){_0x1cf43e[_0xcd08('0x40')][_0xcd08('0x111')]={'$gte':_0x36d5b9[_0xcd08('0x46')],'$lte':_0x36d5b9['to']};}switch(_0x3e0adb){case _0xcd08('0x100'):_0x1cf43e['attributes']['push'](_0xcd08('0x120'),_0xcd08('0x121'),_0xcd08('0x122'),_0xcd08('0x123'),_0xcd08('0x124'),'ratingMessage',_0xcd08('0x125'),_0xcd08('0x126'),_0xcd08('0x127'));break;case _0xcd08('0x128'):_0x1cf43e[_0xcd08('0x3a')][_0xcd08('0x94')]('subject',_0xcd08('0x129'));break;case'openchannel':_0x1cf43e[_0xcd08('0x3a')][_0xcd08('0x94')]('externalUrl',_0xcd08('0x12a'));break;}return db[_[_0xcd08('0x12b')](_0x3e0adb)+_0xcd08('0x12c')][_0xcd08('0x117')](_0x1cf43e)['then'](function(_0x44241d){_0x1d7585['count']+=_0x44241d[_0xcd08('0x21')];return _[_0xcd08('0x55')](_0x44241d[_0xcd08('0xd7')],function(_0x5c3405){var _0x689b2b=_0x5c3405[_0xcd08('0x9f')]({'plain':!![]});_0x689b2b['channel']=_0x3e0adb;if(_0x689b2b[_0xcd08('0x11f')]){_0x689b2b['Owner']={'id':_0x689b2b['Owner']['id'],'name':_0x689b2b['Owner'][_0xcd08('0x2c')],'fullname':_0x689b2b[_0xcd08('0x11f')][_0xcd08('0x116')]};}return _0x689b2b;});});}});return Promise['all'](_0x40bd38);})[_0xcd08('0x28')](function(_0x1ec316){return _(_0x1ec316)['flatten']()[_0xcd08('0x12d')](_0xcd08('0x111'))['reverse']()[_0xcd08('0x53')]();})[_0xcd08('0x28')](function(_0xfe4e7){_0x1d7585['rows']=_0x3d4ce7[_0xcd08('0x22')]?_0xfe4e7[_0xcd08('0x12e')](_0x3d4ce7[_0xcd08('0x1f')],_0x3d4ce7['offset']+_0x3d4ce7[_0xcd08('0x22')]):_0xfe4e7;return _0x1d7585;})[_0xcd08('0x28')](respondWithFilteredResult(_0x3c2162,_0x3d4ce7))[_0xcd08('0x95')](handleError(_0x3c2162,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