Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / cmContact / cmContact.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xedc1=['isEmail','c.email\x20LIKE\x20?','c.firstName\x20LIKE\x20?','c.lastName\x20LIKE\x20?','group','c.id','QueryTypes','SELECT','order','DESC','having','t.id\x20IN\x20?','resolve','user','agent','some','role','sequelize','toString','keyBy','merge','c.firstName','c.lastName','c.phone','c.mobile','c.fax','c.email','c.ListId','c.createdAt','c.deletedAt','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','Tags','rows','catch','destroy','CmContact','find','params','columnName','displayName','analytics','findAll','alias','custom','body','get','mergeWith','tags','join','info','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','[CmContact][merge][destroy][CmHopper],\x20%s','[CmContact][merge][destroy][CmHopperBlack],\x20%s','create','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','FaxMessage','OpenchannelInteraction','CmContactHasItem','ReportAgentPreview','VoiceCallReport','ChatQueueReport','FaxQueueReport','MailQueueReport','SmsQueueReport','WhatsappInteraction','WhatsappMessage','WhatsappQueueReport','isNil','dialTimezone','timezones','utcOffset','additionalPhones','each','duplicates','$or','findOrCreate','spread','show','ContactItemType','ItemType','literal','Phones.OrderBy','$and','format','cf_%d','omit','pickBy','table','cm_contacts','setFields','id\x20=\x20?','toParam','values','phone','getTags','rawAttributes','setTags','ids','setAdditionalPhones','OrderBy','items','item_types','ItemTypeId','description','contact\x20phone\x20exists','PHONE','CmHopperAdditionalPhone','item','`ItemType`.OrderBy','CmHopperId','ItemType.OrderBy','bulkCreate','getAdditionalPhones','fromContactId','CmContactId','hopperId','getHoppers','ContactId','includeAll','getHopperHistories','CmHopperHistory','include','CmHopperFinal','getJscriptySessions','JscriptySessionReport','options','uploadCsv','No\x20ListId\x20specified','binding_keys','No\x20association\x20keys\x20specified!','binding_values','socket_timestamp','zipObject','No\x20phone\x20column\x20specified','No\x20firstName\x20column\x20specified','root','server/files/tmp','filename','chmodSync','0777','child_process','fork','../../components/import/cm/csv','pid','upload','createReadStream','file','parse','binding','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','importUpdates','firstName','../../components/import/cm/csvUpdates','error\x20child\x20process','mail','chat','sms','openchannel','fax','whatsapp','voice','channel','includes','toLowerCase','Invalid\x20channel','range','isValid','Invalid\x20date\x20for\x20range\x20from\x20filter','Invalid\x20date\x20for\x20range\x20to\x20filter','uniqueid','starttime','endtime','duration','note','userDisposition','UserId','fullname','createdAt','findAndCountAll','startCase','Website','Account','closed','closedAt','disposition','secondDisposition','thirdDisposition','key','color','browserName','customerIp','customerPort','deviceModel','ratingMessage','ratingType','subject','substatus','externalUrl','Interaction','Owner','reverse','slice','bluebird','util','path','lodash','squel','papaparse','ioredis','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./cmContact.socket','register','status','json','offset','undefined','limit','count','set','Content-Range','update','then','end','sendStatus','error','name','send','index','describe','keys','startsWith','CmCustomField','findOne','trimStart','cf_','all','length','fieldType','type','model','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','sort','pick','select','field','from','tools_tags','left_join','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','ct.CmContactId\x20=\x20c.id','where','c.deletedAt\x20IS\x20NULL','expr','search','sqlOperator','conditions','Tag','split','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','and','value','dateOfBirth','datetime','castTo','buildExpression','text','map','Contact','push','isEmpty','ListId','c.ListId\x20IN\x20?','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','filter','replace','getFullTextValue','isNumeric','c.id\x20LIKE\x20?','c.mobile\x20LIKE\x20?'];(function(_0x469665,_0x394876){var _0x291ab5=function(_0x55c1c7){while(--_0x55c1c7){_0x469665['push'](_0x469665['shift']());}};_0x291ab5(++_0x394876);}(_0xedc1,0xd6));var _0x1edc=function(_0x50c00a,_0x2afdb8){_0x50c00a=_0x50c00a-0x0;var _0x37e299=_0xedc1[_0x50c00a];return _0x37e299;};'use strict';var moment=require('moment');var BPromise=require(_0x1edc('0x0'));var util=require(_0x1edc('0x1'));var path=require(_0x1edc('0x2'));var fs=require('fs');var _=require(_0x1edc('0x3'));var squel=require(_0x1edc('0x4'));var Papa=require(_0x1edc('0x5'));var Redis=require(_0x1edc('0x6'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var logger=require(_0x1edc('0x7'))(_0x1edc('0x8'));var config=require(_0x1edc('0x9'));var shared=require('../../config/environment/shared');var db=require(_0x1edc('0xa'))['db'];config[_0x1edc('0xb')]=_[_0x1edc('0xc')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x1edc('0xd'))(new Redis(config['redis']));require(_0x1edc('0xe'))[_0x1edc('0xf')](socket);function respondWithResult(_0x2d9d16,_0x44729c){_0x44729c=_0x44729c||0xc8;return function(_0xf6fbab){if(_0xf6fbab){return _0x2d9d16[_0x1edc('0x10')](_0x44729c)[_0x1edc('0x11')](_0xf6fbab);}};}function respondWithFilteredResult(_0xa2a2c5,_0x3f904f){return function(_0x597578){if(_0x597578){var _0x14807e=typeof _0x3f904f[_0x1edc('0x12')]===_0x1edc('0x13')&&typeof _0x3f904f[_0x1edc('0x14')]===_0x1edc('0x13');var _0x59b1ac=_0x597578[_0x1edc('0x15')];var _0x5862e1=_0x14807e?0x0:_0x3f904f[_0x1edc('0x12')];var _0x496e70=_0x14807e?_0x597578['count']:_0x3f904f[_0x1edc('0x12')]+_0x3f904f[_0x1edc('0x14')];var _0x514eca;if(_0x496e70>=_0x59b1ac){_0x496e70=_0x59b1ac;_0x514eca=0xc8;}else{_0x514eca=0xce;}_0xa2a2c5[_0x1edc('0x10')](_0x514eca);return _0xa2a2c5[_0x1edc('0x16')](_0x1edc('0x17'),_0x5862e1+'-'+_0x496e70+'/'+_0x59b1ac)[_0x1edc('0x11')](_0x597578);}return null;};}function saveUpdates(_0x4df1c3){return function(_0x5a2af4){if(_0x5a2af4){return _0x5a2af4[_0x1edc('0x18')](_0x4df1c3)[_0x1edc('0x19')](function(_0x191211){return _0x191211;});}return null;};}function removeEntity(_0x392d20){return function(_0x14b35b){if(_0x14b35b){return _0x14b35b['destroy']()[_0x1edc('0x19')](function(){_0x392d20[_0x1edc('0x10')](0xcc)[_0x1edc('0x1a')]();});}};}function handleEntityNotFound(_0x356a2c){return function(_0x23e07c){if(!_0x23e07c){_0x356a2c[_0x1edc('0x1b')](0x194);}return _0x23e07c;};}function handleError(_0x39afa1,_0x493202){_0x493202=_0x493202||0x1f4;return function(_0x536f88){logger[_0x1edc('0x1c')](_0x536f88['stack']);if(_0x536f88[_0x1edc('0x1d')]){delete _0x536f88[_0x1edc('0x1d')];}_0x39afa1[_0x1edc('0x10')](_0x493202)[_0x1edc('0x1e')](_0x536f88);};}exports[_0x1edc('0x1f')]=function(_0x123aa4,_0x3b96d6){var _0x52e357={},_0xf51b94={},_0x198137={'count':0x0,'rows':[]};return db['CmContact'][_0x1edc('0x20')]()[_0x1edc('0x19')](function(_0x1db062){var _0x57b802=[];for(var _0x3787ab=0x0;_0x3787ab<Object[_0x1edc('0x21')](_0x1db062)['length'];_0x3787ab++){var _0x262d01=Object[_0x1edc('0x21')](_0x1db062)[_0x3787ab];if(_[_0x1edc('0x22')](_0x262d01,'cf_')){_0x57b802['push'](db[_0x1edc('0x23')][_0x1edc('0x24')]({'where':{'id':_[_0x1edc('0x25')](_0x262d01,_0x1edc('0x26'))},'raw':!![]}));}}return BPromise[_0x1edc('0x27')](_0x57b802)[_0x1edc('0x19')](function(_0x20a2e3){for(var _0x5ea18f=0x0;_0x5ea18f<_0x20a2e3[_0x1edc('0x28')];_0x5ea18f++){if(_0x20a2e3[_0x5ea18f]){var _0x327515=_0x1edc('0x26')+_0x20a2e3[_0x5ea18f]['id'];var _0x4ac3d6=_0x1db062[_0x327515];_0x4ac3d6[_0x1edc('0x29')]=_0x20a2e3[_0x5ea18f][_0x1edc('0x2a')];}}return _0x1db062;});})[_0x1edc('0x19')](function(_0x5c373b){_0xf51b94[_0x1edc('0x2b')]=_[_0x1edc('0x21')](_0x5c373b);_0xf51b94[_0x1edc('0x2c')]=_[_0x1edc('0x21')](_0x123aa4['query']);_0xf51b94[_0x1edc('0x2d')]=_[_0x1edc('0x2e')](_0xf51b94['model'],_0xf51b94['query']);_0x52e357['attributes']=_[_0x1edc('0x2e')](_0xf51b94['model'],qs[_0x1edc('0x2f')](_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x2f')]));_0x52e357[_0x1edc('0x30')]=_0x52e357[_0x1edc('0x30')]['length']?_0x52e357['attributes']:_0xf51b94[_0x1edc('0x2b')];if(!_0x123aa4['query'][_0x1edc('0x31')](_0x1edc('0x32'))){_0x52e357[_0x1edc('0x14')]=qs['limit'](_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x14')]);_0x52e357[_0x1edc('0x12')]=qs[_0x1edc('0x12')](_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x12')]);}_0x52e357['order']=qs[_0x1edc('0x33')](_0x123aa4['query'][_0x1edc('0x33')]);_0x52e357['where']=qs[_0x1edc('0x2d')](_[_0x1edc('0x34')](_0x123aa4[_0x1edc('0x2c')],_0xf51b94['filters']),_0x5c373b);var _0x3ccd0c=[];var _0x59a7b0=squel[_0x1edc('0x35')]()[_0x1edc('0x36')]('id')['field'](_0x1edc('0x1d'))[_0x1edc('0x36')]('color')[_0x1edc('0x37')](_0x1edc('0x38'));var _0x133052=squel[_0x1edc('0x35')]()['from']('cm_contacts','c')[_0x1edc('0x39')]('cm_user_has_contacts','uc',_0x1edc('0x3a'))[_0x1edc('0x39')](_0x1edc('0x3b'),'ct',_0x1edc('0x3c'))['left_join'](_0x1edc('0x38'),'t','t.id\x20=\x20ct.TagId')[_0x1edc('0x3d')](_0x1edc('0x3e'));var _0x233341=squel['expr']();var _0x5654d8=[];var _0xf2b68f=squel[_0x1edc('0x3f')]();var _0x39a021;if(_0x123aa4[_0x1edc('0x2c')]['search']){_0x39a021=as['parseSearch'](_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x40')]);var _0x13d95e=_0x39a021[_0x1edc('0x41')];for(var _0x257c97=0x0;_0x257c97<_0x39a021[_0x1edc('0x42')][_0x1edc('0x28')];_0x257c97++){var _0x446bdf=_0x39a021[_0x1edc('0x42')][_0x257c97];var _0x1cdf4f='c';var _0x20a248=_(_0x5c373b)[_0x1edc('0x21')]()['find'](function(_0x148f0e){return _0x148f0e===_0x446bdf['field'];});if(_0x20a248)_0x20a248=_0x5c373b[_0x446bdf[_0x1edc('0x36')]];if(!_0x20a248){if(_0x446bdf['field']===_0x1edc('0x43')){var _0x4d4fe3=_0x446bdf['value'][_0x1edc('0x44')](',')['map'](function(_0xe4c22a){return Number(_0xe4c22a);});_0x4d4fe3[_0x1edc('0x45')](function(_0x58ce8c){_0xf2b68f['or'](_0x1edc('0x46'),'%,'+_0x58ce8c+',%');});_0x5654d8=_[_0x1edc('0x47')](_0x5654d8,_0x4d4fe3);}else if(_0x446bdf[_0x1edc('0x36')]===_0x1edc('0x48')){_0x233341[_0x1edc('0x49')]('uc.UserId\x20=\x20?',_0x446bdf[_0x1edc('0x4a')]);}}else{if(_0x446bdf[_0x1edc('0x36')]===_0x1edc('0x4b')||_0x20a248[_0x1edc('0x29')]===_0x1edc('0x4c'))_0x446bdf[_0x1edc('0x4d')]='DATE';var _0x3fd694=as[_0x1edc('0x4e')](_0x1cdf4f,_0x20a248[_0x1edc('0x2a')],_0x446bdf);_0x233341[_0x13d95e](_0x3fd694[_0x1edc('0x4f')],_0x3fd694['value']['start'],_0x3fd694[_0x1edc('0x4a')]['end']);}}}else{var _0x4c2720=_(Object[_0x1edc('0x21')](_0x123aa4[_0x1edc('0x2c')]))[_0x1edc('0x50')](function(_0x1cad5a){return _0x5c373b[_0x1edc('0x31')](_0x1cad5a)?_0x1cad5a:undefined;})['filter'](function(_0x2d93dd){return!_['isNil'](_0x2d93dd);})[_0x1edc('0x4a')]();if(_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x51')])_0x4c2720[_0x1edc('0x52')](_0x1edc('0x51'));if(!_[_0x1edc('0x53')](_0x4c2720)){_0x4c2720[_0x1edc('0x45')](function(_0x823789){if(_0x823789===_0x1edc('0x54')){_0x133052['where'](_0x1edc('0x55'),[][_0x1edc('0x56')](_0x123aa4[_0x1edc('0x2c')][_0x823789]));}else if(_0x823789===_0x1edc('0x51')){var _0xe635d='%'+_0x123aa4[_0x1edc('0x2c')][_0x823789]+'%';_0x133052[_0x1edc('0x3d')](_0x1edc('0x57'),_0xe635d);}else{_0x133052[_0x1edc('0x3d')]('c.'+_0x823789+_0x1edc('0x58'),_0x123aa4[_0x1edc('0x2c')][_0x823789]);}});}if(_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x59')]){_0x5654d8=_[_0x1edc('0x5a')](_0x123aa4[_0x1edc('0x2c')]['tag'])?_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x59')]:new Array(_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x59')]);_0x5654d8[_0x1edc('0x45')](function(_0x2803aa){_0xf2b68f['or'](_0x1edc('0x46'),'%,'+_0x2803aa+',%');});}if(_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x5b')]){var _0x7074a2=_0x123aa4['query'][_0x1edc('0x5b')][_0x1edc('0x5c')]('\x5c','\x5c\x5c')[_0x1edc('0x5c')](/'/g,'\x27\x27');if(_0x7074a2[_0x1edc('0x44')]('\x20')['length']>0x1){_0x233341['or']('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x1edc('0x5d')](_0x7074a2),null);}else{if(qs[_0x1edc('0x5e')](_0x7074a2)){_0x233341['or'](_0x1edc('0x5f'),_0x7074a2+'%');_0x233341['or']('c.phone\x20LIKE\x20?',_0x7074a2+'%');_0x233341['or'](_0x1edc('0x60'),_0x7074a2+'%');_0x233341['or']('c.fax\x20LIKE\x20?',_0x7074a2+'%');}else if(qs[_0x1edc('0x61')](_0x7074a2)){_0x233341['or'](_0x1edc('0x62'),_0x7074a2+'%');}else{_0x233341['or'](_0x1edc('0x63'),'%'+_0x7074a2+'%');_0x233341['or'](_0x1edc('0x64'),'%'+_0x7074a2+'%');_0x233341['or'](_0x1edc('0x62'),'%'+_0x7074a2+'%');}}}}_0x133052[_0x1edc('0x3d')](_0x233341);_0x133052[_0x1edc('0x65')](_0x1edc('0x66'));var _0x3e9047={'type':db['Sequelize'][_0x1edc('0x67')][_0x1edc('0x68')],'raw':!![]};var _0x5bc930=_0x133052['clone']()[_0x1edc('0x36')](_0x1edc('0x66'));if(_0x52e357['order']){_0x52e357[_0x1edc('0x69')][_0x1edc('0x45')](function(_0x2b06c4){_0x133052[_0x1edc('0x69')]('c.'+_0x2b06c4[0x0],_0x2b06c4[0x1]===_0x1edc('0x6a')?![]:!![]);});}if(!_['isEmpty'](_0x5654d8)){_0x133052[_0x1edc('0x6b')](_0xf2b68f);_0x5bc930[_0x1edc('0x3d')](_0x1edc('0x6c'),_0x5654d8);}BPromise[_0x1edc('0x6d')]()[_0x1edc('0x19')](function(){if(!_0x39a021)return;if(_0x123aa4[_0x1edc('0x6e')]['role']!==_0x1edc('0x6f'))return;if(!_[_0x1edc('0x70')](_0x39a021[_0x1edc('0x42')],[_0x1edc('0x36'),_0x1edc('0x48')])){return _0x123aa4['user']['getLists']({'attributes':['id'],'raw':!![]})['then'](function(_0x3fc519){if(_[_0x1edc('0x53')](_0x3fc519)){_0x5bc930[_0x1edc('0x3d')]('c.ListId\x20IS\x20NULL');_0x133052['where']('c.ListId\x20IS\x20NULL');}else{_0x5bc930[_0x1edc('0x3d')](_0x1edc('0x55'),_[_0x1edc('0x50')](_0x3fc519,'id'));_0x133052[_0x1edc('0x3d')]('c.ListId\x20IN\x20?',_[_0x1edc('0x50')](_0x3fc519,'id'));}});}})['then'](function(){if(_0x123aa4[_0x1edc('0x6e')][_0x1edc('0x71')]===_0x1edc('0x6f')&&!_0x39a021&&!_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x54')])return[];return db[_0x1edc('0x72')][_0x1edc('0x2c')](_0x5bc930[_0x1edc('0x73')](),_0x3e9047);})[_0x1edc('0x19')](function(_0x53f1d0){_0x198137['count']=_0x53f1d0[_0x1edc('0x28')];if(_0x198137[_0x1edc('0x15')]===0x0)return[];return db[_0x1edc('0x72')][_0x1edc('0x2c')](_0x59a7b0[_0x1edc('0x73')](),_0x3e9047)[_0x1edc('0x19')](function(_0x521642){_0x3ccd0c=_[_0x1edc('0x74')](_0x521642,'id');_0x3e9047=_[_0x1edc('0x75')](_0x3e9047,{'model':db['CmContact'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x123aa4[_0x1edc('0x2c')][_0x1edc('0x2f')]){_0x52e357[_0x1edc('0x30')][_0x1edc('0x45')](function(_0x2933f5){_0x133052[_0x1edc('0x36')]('c.'+_0x2933f5);});}else{_0x133052[_0x1edc('0x36')](_0x1edc('0x66'));_0x133052['field'](_0x1edc('0x76'));_0x133052[_0x1edc('0x36')](_0x1edc('0x77'));_0x133052[_0x1edc('0x36')](_0x1edc('0x78'));_0x133052['field'](_0x1edc('0x79'));_0x133052[_0x1edc('0x36')](_0x1edc('0x7a'));_0x133052[_0x1edc('0x36')](_0x1edc('0x7b'));_0x133052[_0x1edc('0x36')](_0x1edc('0x7c'));_0x133052[_0x1edc('0x36')](_0x1edc('0x7d'));_0x133052[_0x1edc('0x36')](_0x1edc('0x7e'));_0x133052[_0x1edc('0x36')]('c.CompanyId');_0x133052[_0x1edc('0x36')](_0x1edc('0x7f'),_0x1edc('0x80'));}if(_0x52e357[_0x1edc('0x14')])_0x133052[_0x1edc('0x14')](_0x52e357[_0x1edc('0x14')]);if(_0x52e357[_0x1edc('0x12')])_0x133052['offset'](_0x52e357[_0x1edc('0x12')]);return db[_0x1edc('0x72')][_0x1edc('0x2c')](_0x133052[_0x1edc('0x73')](),_0x3e9047);});})[_0x1edc('0x19')](function(_0x5c9619){_0x5c9619[_0x1edc('0x45')](function(_0x5ae0b6){if(_0x5ae0b6['TagIds']){_0x5ae0b6[_0x1edc('0x81')]=[];_0x5ae0b6[_0x1edc('0x80')][_0x1edc('0x44')](',')[_0x1edc('0x45')](function(_0x4b3cc7){_0x5ae0b6[_0x1edc('0x81')]['push'](_0x3ccd0c[_0x4b3cc7]);});}delete _0x5ae0b6[_0x1edc('0x80')];});_0x198137[_0x1edc('0x82')]=_0x5c9619;return _0x198137;})[_0x1edc('0x19')](respondWithFilteredResult(_0x3b96d6,_0x52e357));})[_0x1edc('0x83')](handleError(_0x3b96d6,null));};exports[_0x1edc('0x84')]=function(_0x521984,_0x3e8f59){return db[_0x1edc('0x85')][_0x1edc('0x86')]({'where':{'id':_0x521984[_0x1edc('0x87')]['id']}})['then'](handleEntityNotFound(_0x3e8f59,null))[_0x1edc('0x19')](removeEntity(_0x3e8f59,null))['catch'](handleError(_0x3e8f59,null));};exports[_0x1edc('0x20')]=function(_0x3643cd,_0xd39591){return db[_0x1edc('0x85')][_0x1edc('0x20')]()['then'](function(_0x1ec342){delete _0x1ec342['tags'];for(var _0x38e8e1=0x0;_0x38e8e1<Object['keys'](_0x1ec342)[_0x1edc('0x28')];_0x38e8e1++){var _0x5cebc3=Object[_0x1edc('0x21')](_0x1ec342)[_0x38e8e1];if(!_[_0x1edc('0x22')](_0x5cebc3,_0x1edc('0x26'))){_0x1ec342[_0x5cebc3][_0x1edc('0x88')]=_0x5cebc3;_0x1ec342[_0x5cebc3][_0x1edc('0x89')]=_0x5cebc3;}}return _0x1ec342;})[_0x1edc('0x19')](function(_0x34a56b){var _0x2317a8={'where':Boolean(_0x3643cd[_0x1edc('0x2c')][_0x1edc('0x8a')])===!![]?undefined:{'$or':[{'ListId':_0x3643cd[_0x1edc('0x2c')]['id']},{'ListId':null}]},'raw':!![]};return db[_0x1edc('0x23')][_0x1edc('0x8b')](_0x2317a8)[_0x1edc('0x19')](function(_0x48e62d){for(var _0x36b1f3=0x0;_0x36b1f3<_0x48e62d[_0x1edc('0x28')];_0x36b1f3++){var _0x3b81a8=_0x1edc('0x26')+_0x48e62d[_0x36b1f3]['id'];_0x34a56b[_0x3b81a8]['columnName']=_0x3b81a8;_0x34a56b[_0x3b81a8][_0x1edc('0x89')]=_0x48e62d[_0x36b1f3][_0x1edc('0x8c')];_0x34a56b[_0x3b81a8][_0x1edc('0x8d')]={'type':_0x48e62d[_0x36b1f3][_0x1edc('0x2a')],'values':_0x48e62d[_0x36b1f3]['values']};}Object[_0x1edc('0x21')](_0x34a56b)[_0x1edc('0x45')](function(_0x590a2e){if(!_0x34a56b[_0x590a2e][_0x1edc('0x31')]('columnName')){delete _0x34a56b[_0x590a2e];}});return _0x34a56b;});})[_0x1edc('0x19')](respondWithResult(_0xd39591,null))['catch'](handleError(_0xd39591,null));};exports[_0x1edc('0x75')]=function(_0x1542dc,_0x1075c3){var _0x45a659;var _0x4932ae;var _0x475c1d;if(_0x1542dc[_0x1edc('0x8e')]['id']){delete _0x1542dc['body']['id'];}return db[_0x1edc('0x85')][_0x1edc('0x8b')]({'where':{'id':[_0x1542dc[_0x1edc('0x8e')]['to'],_0x1542dc['body'][_0x1edc('0x37')]]}})[_0x1edc('0x19')](function(_0x41e196){if(_0x41e196){if(_0x41e196[_0x1edc('0x28')]!==0x2){return null;}_0x41e196[0x0]=_0x41e196[0x0][_0x1edc('0x8f')]({'plain':!![]});_0x41e196[0x1]=_0x41e196[0x1][_0x1edc('0x8f')]({'plain':!![]});delete _0x41e196[0x0]['id'];delete _0x41e196[0x1]['id'];return _[_0x1edc('0x90')](_0x41e196[0x0],_0x41e196[0x1],function(_0x3fc566,_0x32fb89){if(Array[_0x1edc('0x5a')](_0x32fb89)&&!_0x32fb89['length']){return _0x3fc566;}else if(!_0x32fb89){return _0x3fc566;}});}})['then'](handleEntityNotFound(_0x1075c3,null))[_0x1edc('0x19')](function(_0x5a0e52){if(_0x5a0e52){if(_0x5a0e52[_0x1edc('0x91')]&&_[_0x1edc('0x5a')](_0x5a0e52[_0x1edc('0x91')])){_0x5a0e52[_0x1edc('0x91')]=_0x5a0e52[_0x1edc('0x91')][_0x1edc('0x92')]();}logger[_0x1edc('0x93')](_0x1edc('0x94'),_0x1542dc[_0x1edc('0x8e')]['to'],_0x1542dc['body'][_0x1edc('0x37')]);return db[_0x1edc('0x95')][_0x1edc('0x84')]({'where':{'ContactId':[_0x1542dc['body']['to'],_0x1542dc[_0x1edc('0x8e')]['from']]}})[_0x1edc('0x19')](function(_0x135e8e){logger[_0x1edc('0x93')](_0x1edc('0x96'),_0x135e8e);return db['CmHopperBlack']['destroy']({'where':{'ContactId':[_0x1542dc[_0x1edc('0x8e')]['to'],_0x1542dc[_0x1edc('0x8e')][_0x1edc('0x37')]]}})[_0x1edc('0x19')](function(_0xd7bebb){logger['info'](_0x1edc('0x97'),_0xd7bebb);return db[_0x1edc('0x85')][_0x1edc('0x98')](_0x5a0e52);});});}})['then'](function(_0x146ace){if(_0x146ace){_0x45a659=_0x146ace;_0x4932ae={'ContactId':_0x45a659['id']};_0x475c1d={'where':{'ContactId':[_0x1542dc['body']['to'],_0x1542dc[_0x1edc('0x8e')][_0x1edc('0x37')]]}};return db[_0x1edc('0x99')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9a')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9b')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9c')]['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['MailMessage'][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9c')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9d')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9e')]['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['SmsMessage']['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['FaxInteraction'][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x9f')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa0')]['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['OpenchannelMessage']['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa1')][_0x1edc('0x18')]({'CmContactId':_0x45a659['id']},{'where':{'CmContactId':[_0x1542dc[_0x1edc('0x8e')]['to'],_0x1542dc[_0x1edc('0x8e')][_0x1edc('0x37')]]}});}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['CmHopperFinal'][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['CmHopperHistory'][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa2')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})['then'](function(){if(_0x45a659){return db[_0x1edc('0xa3')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa4')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa5')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})['then'](function(){if(_0x45a659){return db[_0x1edc('0xa6')]['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['OpenchannelQueueReport'][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa7')]['update'](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db['JscriptySessionReport'][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa8')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0xa9')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})['then'](function(){if(_0x45a659){return db[_0x1edc('0xaa')][_0x1edc('0x18')](_0x4932ae,_0x475c1d);}})[_0x1edc('0x19')](function(){if(_0x45a659){return db[_0x1edc('0x85')][_0x1edc('0x84')]({'where':{'id':[_0x1542dc[_0x1edc('0x8e')]['to'],_0x1542dc[_0x1edc('0x8e')][_0x1edc('0x37')]]}});}})[_0x1edc('0x19')](function(){if(_0x45a659){return _0x45a659;}})['then'](respondWithResult(_0x1075c3,null))[_0x1edc('0x83')](handleError(_0x1075c3,null));};exports['create']=function(_0x3cdc83,_0x15a49a){return db[_0x1edc('0x85')][_0x1edc('0x20')]()['then'](function(_0x42e5c2){if(_0x3cdc83[_0x1edc('0x8e')]['tags']&&_[_0x1edc('0x5a')](_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0x91')])){if(_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0x91')]['length']){_0x3cdc83[_0x1edc('0x8e')]['tags']=_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0x91')][_0x1edc('0x92')](';')+';';}else{_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0x91')]=null;}}else{_0x3cdc83[_0x1edc('0x8e')]['tags']=null;}if(!_[_0x1edc('0xab')](_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0xac')])){var _0x412821=_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0xac')];if(!_[_0x1edc('0xab')](shared['timezones'][_0x412821]))_0x3cdc83[_0x1edc('0x8e')]['utcOffset']=shared[_0x1edc('0xad')][_0x412821][_0x1edc('0xae')];}return db[_0x1edc('0x85')][_0x1edc('0x98')](_0x3cdc83[_0x1edc('0x8e')],{'fields':_[_0x1edc('0x21')](_0x42e5c2),'raw':!![]});})['then'](function(_0xbc95bd){if(_0x3cdc83[_0x1edc('0x8e')][_0x1edc('0xaf')]){return insertAdditionalPhones(_0xbc95bd,_0x3cdc83[_0x1edc('0x8e')]['additionalPhones']);}else{return _0xbc95bd;}})[_0x1edc('0x19')](respondWithResult(_0x15a49a,0xc9))[_0x1edc('0x83')](handleError(_0x15a49a,null));};exports['bulkCreate']=function(_0x23453f,_0x3d2a3c){var _0x253db1=0x0;var _0x5503c7=0x0;var _0x631e6d=0x0;var _0x4c6c52=[];return db[_0x1edc('0x85')][_0x1edc('0x20')]()[_0x1edc('0x19')](function(_0x32e4b6){return BPromise[_0x1edc('0xb0')](_0x23453f['body'],function(_0x203215){var _0x48d1f6={'where':{'$or':[]},'defaults':_0x203215,'fields':_[_0x1edc('0x21')](_0x32e4b6),'raw':!![]};if(_0x203215[_0x1edc('0xb1')]){for(var _0x31b75d=0x0;_0x31b75d<_0x203215[_0x1edc('0xb1')][_0x1edc('0x28')];_0x31b75d++){var _0x513427={};_0x513427[_0x203215[_0x1edc('0xb1')][_0x31b75d]]=_0x203215[_0x203215['duplicates'][_0x31b75d]];_0x48d1f6['where'][_0x1edc('0xb2')][_0x1edc('0x52')](_0x513427);}_0x48d1f6[_0x1edc('0x3d')][_0x1edc('0x54')]=_0x203215['ListId'];}return db[_0x1edc('0x85')][_0x1edc('0xb3')](_0x48d1f6)[_0x1edc('0xb4')](function(_0x4051dd,_0x550145){if(_0x550145){if(_0x203215[_0x1edc('0x31')](_0x1edc('0xaf'))){_0x4c6c52[_0x1edc('0x52')]({'contact':_0x4051dd,'additionalPhones':_0x203215[_0x1edc('0xaf')]});}_0x253db1++;}else{_0x631e6d++;}})[_0x1edc('0x83')](function(){_0x5503c7++;});});})[_0x1edc('0x19')](function(_0x1ff8f){if(_0x1ff8f){if(_0x4c6c52['length']>0x0){return new Promise(function(_0x14c0c5,_0x3b85cc){var _0x4a9eb5=[];for(var _0x7e7d41=0x0;_0x7e7d41<_0x4c6c52[_0x1edc('0x28')];_0x7e7d41++){_0x4a9eb5[_0x1edc('0x52')](insertAdditionalPhones(_0x4c6c52[_0x7e7d41]['contact'],_0x4c6c52[_0x7e7d41]['additionalPhones']));}Promise[_0x1edc('0x27')](_0x4a9eb5)[_0x1edc('0x19')](function(){_0x14c0c5(0x1);});})[_0x1edc('0x19')](function(){return{'success':_0x253db1,'failure':_0x5503c7,'duplicates':_0x631e6d};});}else{return{'success':_0x253db1,'failure':_0x5503c7,'duplicates':_0x631e6d};}}})[_0x1edc('0x19')](respondWithResult(_0x3d2a3c,0xc9))[_0x1edc('0x83')](handleError(_0x3d2a3c,null));};exports[_0x1edc('0xb5')]=function(_0x31a4b3,_0x5cbc3e){var _0x227f3d;return db[_0x1edc('0x85')][_0x1edc('0x20')]()[_0x1edc('0x19')](function(_0x19ef98){return db[_0x1edc('0x85')][_0x1edc('0x86')]({'where':{'id':_0x31a4b3[_0x1edc('0x87')]['id']},'include':[{'model':db[_0x1edc('0x43')],'as':_0x1edc('0x81'),'attributes':['id',_0x1edc('0x1d'),'color'],'required':_0x31a4b3['query'][_0x1edc('0x59')]?!![]:![]},{'model':db[_0x1edc('0xa1')],'as':'Phones','where':{'CmContactId':_0x31a4b3[_0x1edc('0x87')]['id']},'required':![],'include':[{'model':db[_0x1edc('0xb6')],'as':_0x1edc('0xb7')}]}],'order':[db['sequelize'][_0x1edc('0xb8')](_0x1edc('0xb9'))],'attributes':_['keys'](_0x19ef98)});})[_0x1edc('0x19')](function(_0x1e1717){if(!_['isNil'](_0x1e1717)){_0x227f3d=_0x1e1717['get']({'plain':!![]});var _0x31dea8={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x1e1717&&_0x1e1717[_0x1edc('0x54')]){if(_0x1e1717[_0x1edc('0x54')]){_0x31dea8[_0x1edc('0x3d')][_0x1edc('0xba')][_0x1edc('0x52')]({'ListId':{'$ne':_0x1e1717[_0x1edc('0x54')]}});}}return db[_0x1edc('0x23')][_0x1edc('0x8b')](_0x31dea8);}})[_0x1edc('0x19')](function(_0xda2d69){if(!_[_0x1edc('0xab')](_0xda2d69)){return _['omit'](_0x227f3d,_['map'](_0xda2d69,function(_0x7bebc8){return util[_0x1edc('0xbb')](_0x1edc('0xbc'),_0x7bebc8['id']);}));}})[_0x1edc('0x19')](handleEntityNotFound(_0x5cbc3e,null))[_0x1edc('0x19')](respondWithResult(_0x5cbc3e,null))[_0x1edc('0x83')](handleError(_0x5cbc3e,null));};exports[_0x1edc('0x18')]=function(_0x3d4fd9,_0x17bb35){var _0x543c76;if(_0x3d4fd9[_0x1edc('0x8e')]['id']){delete _0x3d4fd9['body']['id'];}if(!_[_0x1edc('0xab')](_0x3d4fd9[_0x1edc('0x8e')][_0x1edc('0xac')])){var _0x1ff634=_0x3d4fd9['body'][_0x1edc('0xac')];if(!_[_0x1edc('0xab')](shared['timezones'][_0x1ff634]))_0x3d4fd9[_0x1edc('0x8e')][_0x1edc('0xae')]=shared[_0x1edc('0xad')][_0x1ff634]['utcOffset'];}return db[_0x1edc('0x85')][_0x1edc('0x86')]({'where':{'id':_0x3d4fd9[_0x1edc('0x87')]['id']}})['then'](handleEntityNotFound(_0x17bb35,null))['then'](saveUpdates(_0x3d4fd9['body'],null))[_0x1edc('0x19')](function(_0x2fe6d0){_0x543c76=_0x2fe6d0;var _0x5e319f={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x2fe6d0&&_0x2fe6d0[_0x1edc('0x54')]){if(_0x2fe6d0[_0x1edc('0x54')]){_0x5e319f[_0x1edc('0x3d')]['$and'][_0x1edc('0x52')]({'ListId':{'$ne':_0x2fe6d0[_0x1edc('0x54')]}});}}return db['CmCustomField'][_0x1edc('0x8b')](_0x5e319f);})['then'](function(_0x2bd251){if(_0x2bd251){return _[_0x1edc('0xbd')](_[_0x1edc('0xbe')](_0x3d4fd9[_0x1edc('0x8e')],function(_0x5c6179,_0x3380be){return _[_0x1edc('0x22')](_0x3380be,_0x1edc('0x26'));}),_[_0x1edc('0x50')](_0x2bd251,function(_0x109e5b){return util[_0x1edc('0xbb')](_0x1edc('0xbc'),_0x109e5b['id']);}));}})[_0x1edc('0x19')](function(_0xe8aa71){if(_0xe8aa71&&!_['isEmpty'](_0xe8aa71)){var _0x5085a2=squel[_0x1edc('0x18')]()[_0x1edc('0xbf')](_0x1edc('0xc0'))[_0x1edc('0xc1')](_0xe8aa71)[_0x1edc('0x3d')](_0x1edc('0xc2'),_0x3d4fd9[_0x1edc('0x87')]['id'])[_0x1edc('0xc3')]();return db[_0x1edc('0x72')][_0x1edc('0x2c')](_0x5085a2[_0x1edc('0x4f')],{'replacements':_0x5085a2[_0x1edc('0xc4')]});}})[_0x1edc('0x19')](function(){if(_0x3d4fd9['body'][_0x1edc('0xc5')]&&_0x543c76){return db['CmHopper'][_0x1edc('0x18')]({'phone':_0x3d4fd9['body'][_0x1edc('0xc5')],'OrderBy':0x0},{'where':{'ContactId':_0x543c76['id']}});}})[_0x1edc('0x19')](function(){return _0x543c76;})[_0x1edc('0x19')](respondWithResult(_0x17bb35,null))[_0x1edc('0x83')](handleError(_0x17bb35,null));};exports[_0x1edc('0xc6')]=function(_0x3d0cfc,_0x313f89){var _0x4f9d52={};var _0x2331ce={};var _0x23d6a8;var _0x13c047;return db[_0x1edc('0x85')][_0x1edc('0x24')]({'where':{'id':_0x3d0cfc[_0x1edc('0x87')]['id']}})[_0x1edc('0x19')](handleEntityNotFound(_0x313f89,null))[_0x1edc('0x19')](function(_0x4d40ba){if(_0x4d40ba){_0x23d6a8=_0x4d40ba;_0x2331ce[_0x1edc('0x2b')]=_['keys'](db['Tag'][_0x1edc('0xc7')]);_0x2331ce[_0x1edc('0x2c')]=_[_0x1edc('0x21')](_0x3d0cfc['query']);_0x2331ce[_0x1edc('0x2d')]=_[_0x1edc('0x2e')](_0x2331ce[_0x1edc('0x2b')],_0x2331ce[_0x1edc('0x2c')]);_0x4f9d52['attributes']=_[_0x1edc('0x2e')](_0x2331ce['model'],qs[_0x1edc('0x2f')](_0x3d0cfc[_0x1edc('0x2c')][_0x1edc('0x2f')]));_0x4f9d52['attributes']=_0x4f9d52[_0x1edc('0x30')][_0x1edc('0x28')]?_0x4f9d52['attributes']:_0x2331ce[_0x1edc('0x2b')];_0x4f9d52['order']=qs[_0x1edc('0x33')](_0x3d0cfc[_0x1edc('0x2c')]['sort']);_0x4f9d52[_0x1edc('0x3d')]=qs[_0x1edc('0x2d')](_['pick'](_0x3d0cfc[_0x1edc('0x2c')],_0x2331ce['filters']));if(_0x3d0cfc[_0x1edc('0x2c')]['filter']){_0x4f9d52[_0x1edc('0x3d')]=_[_0x1edc('0x75')](_0x4f9d52[_0x1edc('0x3d')],{'$or':_[_0x1edc('0x50')](_0x4f9d52[_0x1edc('0x30')],function(_0x3c196b){var _0x27ea15={};_0x27ea15[_0x3c196b]={'$like':'%'+_0x3d0cfc['query'][_0x1edc('0x5b')]+'%'};return _0x27ea15;})});}_0x4f9d52=_[_0x1edc('0x75')]({},_0x4f9d52,_0x3d0cfc['options']);return _0x23d6a8[_0x1edc('0xc6')](_0x4f9d52);}})[_0x1edc('0x19')](function(_0x2cf11f){if(_0x2cf11f){_0x13c047=_0x2cf11f['length'];if(!_0x3d0cfc[_0x1edc('0x2c')]['hasOwnProperty'](_0x1edc('0x32'))){_0x4f9d52[_0x1edc('0x14')]=qs[_0x1edc('0x14')](_0x3d0cfc[_0x1edc('0x2c')]['limit']);_0x4f9d52[_0x1edc('0x12')]=qs[_0x1edc('0x12')](_0x3d0cfc['query']['offset']);}return _0x23d6a8['getTags'](_0x4f9d52);}})[_0x1edc('0x19')](function(_0xacb3ed){if(_0xacb3ed){return _0xacb3ed?{'count':_0x13c047,'rows':_0xacb3ed}:null;}})[_0x1edc('0x19')](respondWithResult(_0x313f89,null))['catch'](handleError(_0x313f89,null));};exports['setTags']=function(_0x2ecefc,_0x355968){if(_0x2ecefc['body']['id']){delete _0x2ecefc[_0x1edc('0x8e')]['id'];}return db[_0x1edc('0x85')][_0x1edc('0x24')]({'where':{'id':_0x2ecefc[_0x1edc('0x87')]['id']}})[_0x1edc('0x19')](handleEntityNotFound(_0x355968,null))['then'](function(_0x29f311){if(_0x29f311){return _0x29f311[_0x1edc('0xc8')](_0x2ecefc[_0x1edc('0x8e')][_0x1edc('0xc9')]||[]);}return null;})[_0x1edc('0x19')](respondWithResult(_0x355968,null))[_0x1edc('0x83')](handleError(_0x355968,null));};exports[_0x1edc('0xca')]=function(_0x5f0d32,_0x554afe){var _0x1d2b3d=[];_0x1d2b3d['push'](addAdditionalPhones(_0x5f0d32[_0x1edc('0x8e')]));Promise[_0x1edc('0x27')](_0x1d2b3d)[_0x1edc('0x19')](function(){_0x1d2b3d=[];_0x1d2b3d[_0x1edc('0x52')](deleteCmHopperPhones(_0x5f0d32[_0x1edc('0x8e')]['id']));_0x1d2b3d[_0x1edc('0x52')](addCmHopperPhones(_0x5f0d32[_0x1edc('0x8e')]['id']));Promise[_0x1edc('0x27')](_0x1d2b3d)[_0x1edc('0x19')](function(){return[0x1];})[_0x1edc('0x19')](respondWithResult(_0x554afe,null));});};function addAdditionalPhones(_0x543d55){var _0x32c80a;return new Promise(function(_0x49ebe8,_0x197de5){return db[_0x1edc('0xa1')]['destroy']({'where':{'CmContactId':_0x543d55['id']}})[_0x1edc('0x19')](function(){db['ContactItemType'][_0x1edc('0x8b')]({'raw':!![],'attributes':['id',_0x1edc('0xcb')]})[_0x1edc('0x19')](function(_0x11bddd){var _0x3c1fdc=[];for(var _0x1610fc=0x0;_0x1610fc<_0x543d55[_0x1edc('0xcc')][_0x1edc('0x28')];_0x1610fc++){var _0x4150ec=_0x543d55[_0x1edc('0xcd')]?_[_0x1edc('0xab')](_0x543d55[_0x1edc('0xcd')][_0x1610fc])?'':_0x543d55[_0x1edc('0xcd')][_0x1610fc]:_0x543d55[_0x1edc('0xcc')][_0x1610fc][_0x1edc('0xce')]?_0x543d55[_0x1edc('0xcc')][_0x1610fc]['ItemTypeId']:'';var _0x5b70ee=_[_0x1edc('0xab')](_0x543d55[_0x1edc('0xcc')][_0x1610fc][_0x1edc('0xcf')])?'':_0x543d55[_0x1edc('0xcc')][_0x1610fc][_0x1edc('0xcf')];var _0x22dca6=_0x4150ec+':'+_0x543d55[_0x1edc('0xcc')][_0x1610fc][_0x1edc('0xc5')]+'ยง'+_0x5b70ee;if(_[_0x1edc('0xab')](_0x32c80a))_0x32c80a=_0x22dca6;else _0x32c80a+=';'+_0x22dca6;var _0x49c069=null;if(_0x543d55[_0x1edc('0xcd')]){if(!_['isNil'](_0x543d55[_0x1edc('0xcd')][_0x1610fc])){var _0x2e5b8e=_[_0x1edc('0x86')](_0x11bddd,function(_0x728e6e){return _0x728e6e['id']===_0x543d55[_0x1edc('0xcd')][_0x1610fc];});if(!_['isNil'](_0x2e5b8e)){_0x49c069=_0x2e5b8e['OrderBy'];}}}else{if(!_[_0x1edc('0xab')](_0x543d55[_0x1edc('0xcc')][_0x1610fc])){var _0x2e5b8e=_[_0x1edc('0x86')](_0x11bddd,function(_0x6b4d49){return _0x6b4d49['id']===_0x543d55['items'][_0x1610fc]['ItemTypeId'];});if(!_['isNil'](_0x2e5b8e)){_0x49c069=_0x1610fc;}}}if(_[_0x1edc('0xab')](_0x49c069)){_0x49c069=0x64;}_0x3c1fdc[_0x1edc('0x52')](addAdditionalPhone(_0x543d55['id'],_0x543d55['items'][_0x1610fc][_0x1edc('0xc5')],_0x543d55['item_types']?_['isNil'](_0x543d55[_0x1edc('0xcd')][_0x1610fc])?null:_0x543d55[_0x1edc('0xcd')][_0x1610fc]:_0x543d55['items'][_0x1610fc][_0x1edc('0xce')]?_0x543d55[_0x1edc('0xcc')][_0x1610fc][_0x1edc('0xce')]:null,_0x49c069,_0x5b70ee));}Promise['all'](_0x3c1fdc)[_0x1edc('0x19')](function(){db['CmContact'][_0x1edc('0x18')]({'AdditionalPhones':_0x32c80a},{'where':{'id':_0x543d55['id']}})[_0x1edc('0x19')](function(){_0x49ebe8(0x1);});});});});});}function addAdditionalPhone(_0x4d9620,_0x3e3df6,_0xb8ee7,_0x360693,_0x41857e){return db[_0x1edc('0xa1')][_0x1edc('0x86')]({'where':{'CmContactId':_0x4d9620,'item':_0x3e3df6}})[_0x1edc('0x19')](function(_0x10bd98){if(_0x10bd98)logger['info'](_0x1edc('0xd0'),_0x10bd98);else{db[_0x1edc('0xa1')][_0x1edc('0x98')]({'CmContactId':_0x4d9620,'item':_0x3e3df6,'ItemTypeId':_0xb8ee7,'OrderBy':_0x360693,'ItemClass':_0x1edc('0xd1'),'description':_0x41857e});}});}function deletePhones(_0x103628){return db[_0x1edc('0xa1')]['destroy']({'where':{'CmContactId':_0x103628}});}function deleteCmHopperPhones(_0x5dd241){return new Promise(function(_0x359ff6,_0x4335ac){return db[_0x1edc('0x95')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x5dd241}})[_0x1edc('0x19')](function(_0x348561){db[_0x1edc('0xd2')][_0x1edc('0x84')]({'where':{'CmHopperId':{'$in':_[_0x1edc('0x50')](_0x348561,'id')}}});})[_0x1edc('0x19')](function(){_0x359ff6(0x1);});});}function addCmHopperPhones(_0x10c5f8){return new Promise(function(_0x1c3b0a,_0x356fdb){return db[_0x1edc('0x95')]['findAll']({'raw':!![],'attributes':['id'],'where':{'ContactId':_0x10c5f8}})[_0x1edc('0x19')](function(_0x59e966){var _0x588ea5=[];_[_0x1edc('0x50')](_0x59e966,function(_0x57610d){_0x588ea5[_0x1edc('0x52')](createCmHopperPhone(_0x10c5f8,_0x57610d['id']));});Promise[_0x1edc('0x27')](_0x588ea5)[_0x1edc('0x19')](function(){_0x1c3b0a(0x1);});});});}function createCmHopperPhone(_0x3755c5,_0xc4cb93){return new Promise(function(_0x518c69,_0x5218c7){db['CmContactHasItem'][_0x1edc('0x8b')]({'raw':!![],'attributes':[_0x1edc('0xd3'),_0x1edc('0xcb')],'where':{'CmContactId':_0x3755c5,'ItemClass':_0x1edc('0xd1')},'include':[{'model':db[_0x1edc('0xb6')],'attributes':[_0x1edc('0xcb')],'as':'ItemType'}],'order':[_0x1edc('0xcb'),db[_0x1edc('0x72')][_0x1edc('0xb8')](_0x1edc('0xd4'))]})['then'](function(_0x521f6c){var _0x8ce1f0=0x1;var _0x31c6e2=_[_0x1edc('0x50')](_0x521f6c,function(_0x44abde){_0x44abde[_0x1edc('0xd5')]=_0xc4cb93;_0x44abde[_0x1edc('0xc5')]=_0x44abde['item'];_0x44abde[_0x1edc('0xcb')]=_0x8ce1f0;delete _0x44abde[_0x1edc('0xd6')];_0x8ce1f0=_0x8ce1f0+0x1;return _0x44abde;});return db[_0x1edc('0xd2')][_0x1edc('0xd7')](_0x31c6e2,{});})[_0x1edc('0x19')](function(){_0x518c69(0x1);});});}function insertAdditionalPhones(_0x5a20a1,_0x793bd5){return new Promise(function(_0x360c7b,_0x35ca6c){var _0x25048a=[];for(var _0x787da=0x0;_0x787da<_0x793bd5[_0x1edc('0x28')];_0x787da++){var _0x42cf2e=_0x793bd5[_0x787da];_0x25048a[_0x1edc('0x52')](parseContactItemType(_0x42cf2e));}Promise[_0x1edc('0x27')](_0x25048a)[_0x1edc('0x19')](function(){var _0x5242d2={'id':_0x5a20a1['id'],'items':_0x793bd5};return addAdditionalPhones(_0x5242d2)[_0x1edc('0x19')](function(_0xc7f3e6){return addCmHopperPhones(_0x5a20a1['id']);});})[_0x1edc('0x19')](function(){_0x360c7b(_0x5a20a1);});});}function parseContactItemType(_0x4ccc15){return new Promise(function(_0x27d969,_0xa58b2e){if(_0x4ccc15[_0x1edc('0x31')](_0x1edc('0xce'))){_0x27d969(_0x4ccc15);}else{return db['ContactItemType'][_0x1edc('0x86')]({'where':{'name':_0x4ccc15[_0x1edc('0xb7')]}})['then'](function(_0x13216f){if(_[_0x1edc('0xab')](_0x13216f))_0x4ccc15[_0x1edc('0xce')]=null;else _0x4ccc15[_0x1edc('0xce')]=_0x13216f['id'];_0x27d969(_0x4ccc15);});}});}exports[_0x1edc('0xd8')]=function(_0x38395d,_0x50becb){return db['CmContactHasItem'][_0x1edc('0x8b')]({'raw':!![],'where':{'CmContactId':_0x38395d[_0x1edc('0x87')]['id'],'ItemClass':_0x1edc('0xd1')},'include':[{'model':db[_0x1edc('0xb6')],'as':_0x1edc('0xb7')}],'order':[[_0x1edc('0xcb')],[db[_0x1edc('0x72')][_0x1edc('0xb8')](_0x1edc('0xd4'))]]})[_0x1edc('0x19')](function(_0x3c24bb){return _0x3c24bb;})[_0x1edc('0x19')](respondWithResult(_0x50becb,null))[_0x1edc('0x83')](handleError(_0x50becb,null));};exports['duplicateAdditionalPhones']=function(_0x3d26eb,_0x61349d){return db['CmContactHasItem'][_0x1edc('0x8b')]({'raw':!![],'where':{'CmContactId':_0x3d26eb[_0x1edc('0x8e')][_0x1edc('0xd9')]}})[_0x1edc('0x19')](function(_0x165b59){var _0x1c73cc=_[_0x1edc('0x50')](_0x165b59,function(_0x304f2d){_0x304f2d[_0x1edc('0xda')]=_0x3d26eb[_0x1edc('0x8e')]['toContactId'];return _0x304f2d;});return db[_0x1edc('0xa1')][_0x1edc('0xd7')](_0x1c73cc,{});})[_0x1edc('0x19')](function(_0x1b43a7){return addCmHopperPhones(_0x3d26eb[_0x1edc('0x8e')]['toContactId']);})[_0x1edc('0x19')](function(_0x443339){return['ok'];})[_0x1edc('0x19')](respondWithResult(_0x61349d,null))[_0x1edc('0x83')](handleError(_0x61349d,null));};exports['rescheduleAdditionalPhones']=function(_0x349574,_0x571163){var _0x28f3ed=[];_0x28f3ed[_0x1edc('0x52')](createCmHopperPhone(_0x349574['body']['id'],_0x349574[_0x1edc('0x8e')][_0x1edc('0xdb')]));Promise[_0x1edc('0x27')](_0x28f3ed)[_0x1edc('0x19')](function(){return[0x1];})[_0x1edc('0x19')](respondWithResult(_0x571163,null));};exports[_0x1edc('0xdc')]=function(_0x3985c1,_0x5886d4){var _0x5fe968={'raw':![],'where':{}};var _0xe79fbe={};var _0x33bbf4={'count':0x0,'rows':[]};return db[_0x1edc('0x85')][_0x1edc('0x24')]({'where':{'id':_0x3985c1['params']['id']}})['then'](handleEntityNotFound(_0x5886d4,null))[_0x1edc('0x19')](function(_0x4f3107){if(_0x4f3107){_0xe79fbe[_0x1edc('0x2b')]=_[_0x1edc('0x21')](db[_0x1edc('0x95')][_0x1edc('0xc7')]);_0xe79fbe['query']=_[_0x1edc('0x21')](_0x3985c1[_0x1edc('0x2c')]);_0xe79fbe[_0x1edc('0x2d')]=_[_0x1edc('0x2e')](_0xe79fbe[_0x1edc('0x2b')],_0xe79fbe[_0x1edc('0x2c')]);_0x5fe968[_0x1edc('0x30')]=_[_0x1edc('0x2e')](_0xe79fbe[_0x1edc('0x2b')],qs[_0x1edc('0x2f')](_0x3985c1[_0x1edc('0x2c')][_0x1edc('0x2f')]));_0x5fe968[_0x1edc('0x30')]=_0x5fe968[_0x1edc('0x30')]['length']?_0x5fe968['attributes']:_0xe79fbe[_0x1edc('0x2b')];if(!_0x3985c1[_0x1edc('0x2c')][_0x1edc('0x31')](_0x1edc('0x32'))){_0x5fe968[_0x1edc('0x14')]=qs[_0x1edc('0x14')](_0x3985c1['query'][_0x1edc('0x14')]);_0x5fe968[_0x1edc('0x12')]=qs['offset'](_0x3985c1['query'][_0x1edc('0x12')]);}_0x5fe968['order']=qs[_0x1edc('0x33')](_0x3985c1['query'][_0x1edc('0x33')]);_0x5fe968[_0x1edc('0x3d')]=qs[_0x1edc('0x2d')](_[_0x1edc('0x34')](_0x3985c1['query'],_0xe79fbe[_0x1edc('0x2d')]));_0x5fe968['where'][_0x1edc('0xdd')]=_0x4f3107['id'];if(_0x3985c1[_0x1edc('0x2c')]['filter']){_0x5fe968[_0x1edc('0x3d')]=_[_0x1edc('0x75')](_0x5fe968[_0x1edc('0x3d')],{'$or':_['map'](_0x5fe968[_0x1edc('0x30')],function(_0x3672cb){var _0x444e7c={};_0x444e7c[_0x3672cb]={'$like':'%'+_0x3985c1['query'][_0x1edc('0x5b')]+'%'};return _0x444e7c;})});}_0x5fe968=_[_0x1edc('0x75')]({},_0x5fe968,_0x3985c1['options']);return db[_0x1edc('0x95')][_0x1edc('0x15')]({'where':_0x5fe968[_0x1edc('0x3d')]})[_0x1edc('0x19')](function(_0x209a0e){_0x33bbf4[_0x1edc('0x15')]=_0x209a0e;if(_0x3985c1[_0x1edc('0x2c')][_0x1edc('0xde')]){_0x5fe968['include']=[{'all':!![]}];}return db[_0x1edc('0x95')][_0x1edc('0x8b')](_0x5fe968);})[_0x1edc('0x19')](function(_0x17c231){_0x33bbf4['rows']=_0x17c231;return _0x33bbf4;});}})[_0x1edc('0x19')](respondWithFilteredResult(_0x5886d4,_0x5fe968))[_0x1edc('0x83')](handleError(_0x5886d4,null));};exports[_0x1edc('0xdf')]=function(_0x846e02,_0x3d3f3c){var _0x546597={'raw':!![],'where':{}};var _0x348c51={};var _0x3eb34d={'count':0x0,'rows':[]};return db[_0x1edc('0x85')][_0x1edc('0x24')]({'where':{'id':_0x846e02[_0x1edc('0x87')]['id']}})[_0x1edc('0x19')](handleEntityNotFound(_0x3d3f3c,null))['then'](function(_0x54dd87){if(_0x54dd87){_0x348c51[_0x1edc('0x2b')]=_[_0x1edc('0x21')](db[_0x1edc('0xe0')]['rawAttributes']);_0x348c51[_0x1edc('0x2c')]=_[_0x1edc('0x21')](_0x846e02[_0x1edc('0x2c')]);_0x348c51['filters']=_[_0x1edc('0x2e')](_0x348c51['model'],_0x348c51[_0x1edc('0x2c')]);_0x546597[_0x1edc('0x30')]=_['intersection'](_0x348c51[_0x1edc('0x2b')],qs['fields'](_0x846e02[_0x1edc('0x2c')][_0x1edc('0x2f')]));_0x546597[_0x1edc('0x30')]=_0x546597[_0x1edc('0x30')][_0x1edc('0x28')]?_0x546597[_0x1edc('0x30')]:_0x348c51[_0x1edc('0x2b')];if(!_0x846e02[_0x1edc('0x2c')][_0x1edc('0x31')](_0x1edc('0x32'))){_0x546597[_0x1edc('0x14')]=qs[_0x1edc('0x14')](_0x846e02[_0x1edc('0x2c')][_0x1edc('0x14')]);_0x546597[_0x1edc('0x12')]=qs[_0x1edc('0x12')](_0x846e02[_0x1edc('0x2c')][_0x1edc('0x12')]);}_0x546597[_0x1edc('0x69')]=qs[_0x1edc('0x33')](_0x846e02[_0x1edc('0x2c')][_0x1edc('0x33')]);_0x546597[_0x1edc('0x3d')]=qs[_0x1edc('0x2d')](_['pick'](_0x846e02[_0x1edc('0x2c')],_0x348c51['filters']));_0x546597['where']['ContactId']=_0x54dd87['id'];if(_0x846e02[_0x1edc('0x2c')]['filter']){_0x546597[_0x1edc('0x3d')]=_['merge'](_0x546597[_0x1edc('0x3d')],{'$or':_[_0x1edc('0x50')](_0x546597['attributes'],function(_0x56cd39){var _0x5ad01f={};_0x5ad01f[_0x56cd39]={'$like':'%'+_0x846e02[_0x1edc('0x2c')]['filter']+'%'};return _0x5ad01f;})});}_0x546597=_[_0x1edc('0x75')]({},_0x546597,_0x846e02['options']);return db[_0x1edc('0xe0')]['count']({'where':_0x546597[_0x1edc('0x3d')]})[_0x1edc('0x19')](function(_0x5af916){_0x3eb34d[_0x1edc('0x15')]=_0x5af916;if(_0x846e02[_0x1edc('0x2c')][_0x1edc('0xde')]){_0x546597[_0x1edc('0xe1')]=[{'all':!![]}];}return db[_0x1edc('0xe0')]['findAll'](_0x546597);})[_0x1edc('0x19')](function(_0x587b1d){_0x3eb34d[_0x1edc('0x82')]=_0x587b1d;return _0x3eb34d;});}})[_0x1edc('0x19')](respondWithFilteredResult(_0x3d3f3c,_0x546597))['catch'](handleError(_0x3d3f3c,null));};exports['getHopperFinals']=function(_0x47cc42,_0xd1db6e){var _0x5b0d4e={'raw':!![],'where':{}};var _0x45008f={};var _0x50814f={'count':0x0,'rows':[]};return db[_0x1edc('0x85')][_0x1edc('0x24')]({'where':{'id':_0x47cc42['params']['id']}})[_0x1edc('0x19')](handleEntityNotFound(_0xd1db6e,null))[_0x1edc('0x19')](function(_0x21535c){if(_0x21535c){_0x45008f[_0x1edc('0x2b')]=_[_0x1edc('0x21')](db['CmHopperFinal']['rawAttributes']);_0x45008f[_0x1edc('0x2c')]=_[_0x1edc('0x21')](_0x47cc42[_0x1edc('0x2c')]);_0x45008f[_0x1edc('0x2d')]=_['intersection'](_0x45008f['model'],_0x45008f[_0x1edc('0x2c')]);_0x5b0d4e[_0x1edc('0x30')]=_['intersection'](_0x45008f[_0x1edc('0x2b')],qs[_0x1edc('0x2f')](_0x47cc42['query'][_0x1edc('0x2f')]));_0x5b0d4e[_0x1edc('0x30')]=_0x5b0d4e[_0x1edc('0x30')][_0x1edc('0x28')]?_0x5b0d4e['attributes']:_0x45008f[_0x1edc('0x2b')];if(!_0x47cc42[_0x1edc('0x2c')][_0x1edc('0x31')]('nolimit')){_0x5b0d4e[_0x1edc('0x14')]=qs[_0x1edc('0x14')](_0x47cc42[_0x1edc('0x2c')][_0x1edc('0x14')]);_0x5b0d4e[_0x1edc('0x12')]=qs[_0x1edc('0x12')](_0x47cc42[_0x1edc('0x2c')][_0x1edc('0x12')]);}_0x5b0d4e[_0x1edc('0x69')]=qs['sort'](_0x47cc42[_0x1edc('0x2c')][_0x1edc('0x33')]);_0x5b0d4e[_0x1edc('0x3d')]=qs['filters'](_[_0x1edc('0x34')](_0x47cc42[_0x1edc('0x2c')],_0x45008f[_0x1edc('0x2d')]));_0x5b0d4e[_0x1edc('0x3d')]['ContactId']=_0x21535c['id'];if(_0x47cc42[_0x1edc('0x2c')][_0x1edc('0x5b')]){_0x5b0d4e['where']=_['merge'](_0x5b0d4e[_0x1edc('0x3d')],{'$or':_[_0x1edc('0x50')](_0x5b0d4e[_0x1edc('0x30')],function(_0x78f316){var _0x4aa788={};_0x4aa788[_0x78f316]={'$like':'%'+_0x47cc42[_0x1edc('0x2c')][_0x1edc('0x5b')]+'%'};return _0x4aa788;})});}_0x5b0d4e=_[_0x1edc('0x75')]({},_0x5b0d4e,_0x47cc42['options']);return db[_0x1edc('0xe2')][_0x1edc('0x15')]({'where':_0x5b0d4e[_0x1edc('0x3d')]})[_0x1edc('0x19')](function(_0x439908){_0x50814f[_0x1edc('0x15')]=_0x439908;if(_0x47cc42[_0x1edc('0x2c')][_0x1edc('0xde')]){_0x5b0d4e[_0x1edc('0xe1')]=[{'all':!![]}];}return db[_0x1edc('0xe2')][_0x1edc('0x8b')](_0x5b0d4e);})[_0x1edc('0x19')](function(_0x1115b9){_0x50814f['rows']=_0x1115b9;return _0x50814f;});}})['then'](respondWithFilteredResult(_0xd1db6e,_0x5b0d4e))['catch'](handleError(_0xd1db6e,null));};exports[_0x1edc('0xe3')]=function(_0xeb35df,_0x34dc72){var _0x29f2b8={'raw':!![],'where':{}};var _0x3a4571={};var _0x4848c9={'count':0x0,'rows':[]};return db[_0x1edc('0x85')][_0x1edc('0x24')]({'where':{'id':_0xeb35df[_0x1edc('0x87')]['id']}})['then'](handleEntityNotFound(_0x34dc72,null))[_0x1edc('0x19')](function(_0x1a1186){if(_0x1a1186){_0x3a4571[_0x1edc('0x2b')]=_['keys'](db[_0x1edc('0xe4')]['rawAttributes']);_0x3a4571['query']=_[_0x1edc('0x21')](_0xeb35df['query']);_0x3a4571[_0x1edc('0x2d')]=_[_0x1edc('0x2e')](_0x3a4571[_0x1edc('0x2b')],_0x3a4571[_0x1edc('0x2c')]);_0x29f2b8[_0x1edc('0x30')]=_['intersection'](_0x3a4571[_0x1edc('0x2b')],qs[_0x1edc('0x2f')](_0xeb35df['query']['fields']));_0x29f2b8[_0x1edc('0x30')]=_0x29f2b8[_0x1edc('0x30')][_0x1edc('0x28')]?_0x29f2b8[_0x1edc('0x30')]:_0x3a4571[_0x1edc('0x2b')];if(!_0xeb35df[_0x1edc('0x2c')][_0x1edc('0x31')](_0x1edc('0x32'))){_0x29f2b8[_0x1edc('0x14')]=qs[_0x1edc('0x14')](_0xeb35df[_0x1edc('0x2c')]['limit']);_0x29f2b8['offset']=qs[_0x1edc('0x12')](_0xeb35df[_0x1edc('0x2c')][_0x1edc('0x12')]);}_0x29f2b8['order']=qs[_0x1edc('0x33')](_0xeb35df['query'][_0x1edc('0x33')]);_0x29f2b8['where']=qs['filters'](_['pick'](_0xeb35df[_0x1edc('0x2c')],_0x3a4571[_0x1edc('0x2d')]));_0x29f2b8[_0x1edc('0x3d')][_0x1edc('0xdd')]=_0x1a1186['id'];if(_0xeb35df[_0x1edc('0x2c')]['filter']){_0x29f2b8[_0x1edc('0x3d')]=_['merge'](_0x29f2b8[_0x1edc('0x3d')],{'$or':_['map'](_0x29f2b8[_0x1edc('0x30')],function(_0x3feeae){var _0x361e30={};_0x361e30[_0x3feeae]={'$like':'%'+_0xeb35df[_0x1edc('0x2c')][_0x1edc('0x5b')]+'%'};return _0x361e30;})});}_0x29f2b8=_[_0x1edc('0x75')]({},_0x29f2b8,_0xeb35df[_0x1edc('0xe5')]);return db[_0x1edc('0xe4')][_0x1edc('0x15')]({'where':_0x29f2b8[_0x1edc('0x3d')]})[_0x1edc('0x19')](function(_0x57eb77){_0x4848c9['count']=_0x57eb77;if(_0xeb35df[_0x1edc('0x2c')]['includeAll']){_0x29f2b8[_0x1edc('0xe1')]=[{'all':!![]}];}return db['JscriptySessionReport'][_0x1edc('0x8b')](_0x29f2b8);})[_0x1edc('0x19')](function(_0x18f955){_0x4848c9[_0x1edc('0x82')]=_0x18f955;return _0x4848c9;});}})['then'](respondWithFilteredResult(_0x34dc72,_0x29f2b8))[_0x1edc('0x83')](handleError(_0x34dc72,null));};exports[_0x1edc('0xe6')]=function(_0x1c731f,_0x1c7de0){try{if(!_0x1c731f[_0x1edc('0x8e')][_0x1edc('0x54')]){throw new Error(_0x1edc('0xe7'));}if(!_0x1c731f[_0x1edc('0x8e')][_0x1edc('0xe8')]){throw new Error(_0x1edc('0xe9'));}if(!_0x1c731f[_0x1edc('0x8e')][_0x1edc('0xea')]){throw new Error('No\x20association\x20values\x20specified!');}if(!_0x1c731f['body'][_0x1edc('0xeb')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x58cc87=_0x1c731f[_0x1edc('0x8e')][_0x1edc('0xe8')]['split'](',');var _0x35f480=_0x1c731f['body'][_0x1edc('0xea')][_0x1edc('0x44')](',');if(!_0x58cc87[_0x1edc('0x28')]||!_0x35f480['length']||_0x58cc87[_0x1edc('0x28')]!==_0x35f480[_0x1edc('0x28')]){throw new Error('Incorrect\x20binding\x20parameters\x20passed!');}_0x1c731f[_0x1edc('0x8e')][_0x1edc('0x2f')]=_[_0x1edc('0xec')](_0x58cc87,_0x35f480);if(!_0x1c731f[_0x1edc('0x8e')][_0x1edc('0x2f')][_0x1edc('0xc5')]){throw new Error(_0x1edc('0xed'));}if(!_0x1c731f['body'][_0x1edc('0x2f')]['firstName']){throw new Error(_0x1edc('0xee'));}var _0x1aca72=path[_0x1edc('0x92')](config[_0x1edc('0xef')],_0x1edc('0xf0'),_0x1c731f['file'][_0x1edc('0xf1')]);fs[_0x1edc('0xf2')](_0x1aca72,parseInt(_0x1edc('0xf3'),0x8));var _0x501f18=require(_0x1edc('0xf4'))[_0x1edc('0xf5')](path[_0x1edc('0x92')](__dirname,_0x1edc('0xf6')),[_0x1aca72,_0x1c731f['body']['binding_keys'],_0x1c731f[_0x1edc('0x8e')][_0x1edc('0xea')],_0x1c731f[_0x1edc('0x8e')][_0x1edc('0x54')],_0x1c731f[_0x1edc('0x8e')]['CompanyId'],_0x1c731f[_0x1edc('0x8e')][_0x1edc('0xb1')],_0x1c731f[_0x1edc('0x8e')][_0x1edc('0xeb')]]);return _0x1c7de0[_0x1edc('0x10')](0xc8)[_0x1edc('0x11')]({'message':'File\x20uploaded\x20correctly!','pid':_0x501f18[_0x1edc('0xf7')]});}catch(_0x15acf4){return _0x1c7de0[_0x1edc('0x10')](0x1f4)[_0x1edc('0x1e')](_0x15acf4);}};exports[_0x1edc('0xf8')]=function(_0x4805a4,_0x285a3f){var _0x4666e6=fs[_0x1edc('0xf9')](_0x4805a4[_0x1edc('0xfa')][_0x1edc('0x2')]);Papa[_0x1edc('0xfb')](_0x4666e6,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x41279e){return _0x285a3f[_0x1edc('0x10')](0xc8)['json']({'file':_0x4805a4[_0x1edc('0xfa')],'fields':_0x41279e['meta'][_0x1edc('0x2f')]});}});};exports['import']=function(_0x5df4e8,_0x1e6eca){return db[_0x1edc('0x48')][_0x1edc('0x8b')]({'raw':!![],'attributes':['id'],'where':{'role':_0x1edc('0x6f')}})['then'](function(_0x41a4e9){var _0x432d82=![];if(!_0x5df4e8[_0x1edc('0x8e')]['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x5df4e8[_0x1edc('0x8e')][_0x1edc('0xfc')][_0x1edc('0xc5')]){throw new Error(_0x1edc('0xed'));}if(!_0x5df4e8['body'][_0x1edc('0xfc')]['firstName']){throw new Error(_0x1edc('0xee'));}if(!_0x5df4e8[_0x1edc('0x8e')]['socket_timestamp']){throw new Error(_0x1edc('0xfd'));}var _0x389c74=require('child_process')[_0x1edc('0xf5')](path['join'](__dirname,_0x1edc('0xfe')),[_0x5df4e8[_0x1edc('0x87')]['id'],JSON[_0x1edc('0xff')](_0x5df4e8['body']),JSON[_0x1edc('0xff')](_0x41a4e9)]);_0x389c74['on'](_0x1edc('0x100'),function(){_0x432d82=!![];return _0x1e6eca[_0x1edc('0x10')](0xc8)[_0x1edc('0x11')]({'message':_0x1edc('0x101'),'pid':_0x389c74[_0x1edc('0xf7')]});});_0x389c74['on'](_0x1edc('0x102'),function(_0x285d58){if(_0x285d58&&!_0x432d82){return _0x1e6eca[_0x1edc('0x10')](0x1f4)[_0x1edc('0x11')]({'message':'error\x20child\x20process','pid':_0x389c74['pid']});}});})[_0x1edc('0x83')](handleError(_0x1e6eca,null));};exports[_0x1edc('0x103')]=function(_0x40b2e9,_0x119c4f,_0x57a9d8){return db[_0x1edc('0x48')][_0x1edc('0x8b')]({'raw':!![],'attributes':['id'],'where':{'role':_0x1edc('0x6f')}})[_0x1edc('0x19')](function(_0x2590ab){var _0x43e65e=![];if(!_0x40b2e9[_0x1edc('0x8e')][_0x1edc('0x54')]){throw new Error('No\x20ListId\x20specified');}if(!_0x40b2e9[_0x1edc('0x8e')][_0x1edc('0xfc')][_0x1edc('0xc5')]){throw new Error('No\x20phone\x20column\x20specified');}if(!_0x40b2e9['body']['binding'][_0x1edc('0x104')]){throw new Error(_0x1edc('0xee'));}if(!_0x40b2e9['body']['socket_timestamp']){throw new Error(_0x1edc('0xfd'));}var _0x5d85db=require(_0x1edc('0xf4'))[_0x1edc('0xf5')](path['join'](__dirname,_0x1edc('0x105')),[_0x40b2e9[_0x1edc('0x87')]['id'],JSON[_0x1edc('0xff')](_0x40b2e9[_0x1edc('0x8e')]),JSON[_0x1edc('0xff')](_0x2590ab)]);_0x5d85db['on'](_0x1edc('0x100'),function(_0x13a19c){_0x43e65e=!![];return _0x119c4f[_0x1edc('0x10')](0xc8)[_0x1edc('0x11')]({'message':_0x1edc('0x101'),'pid':_0x5d85db[_0x1edc('0xf7')]});});_0x5d85db['on'](_0x1edc('0x102'),function(_0x143376){if(_0x143376&&!_0x43e65e){return _0x119c4f['status'](0x1f4)[_0x1edc('0x11')]({'message':_0x1edc('0x106'),'pid':_0x5d85db[_0x1edc('0xf7')]});}});})[_0x1edc('0x83')](handleError(_0x119c4f,null));};exports['getJourney']=function(_0xad4e81,_0xe18008){var _0x48810d=[_0x1edc('0x107'),_0x1edc('0x108'),_0x1edc('0x109'),_0x1edc('0x10a'),_0x1edc('0x10b'),_0x1edc('0x10c'),_0x1edc('0x10d')];var _0x44efbf={'offset':0x0,'order':qs['sort']('-createdAt')},_0x3a5cb5={'count':0x0,'rows':[]};Promise[_0x1edc('0x6d')]()[_0x1edc('0x19')](function(){if(_0xad4e81[_0x1edc('0x2c')][_0x1edc('0x10e')]){if(!_[_0x1edc('0x10f')](_0x48810d,_0xad4e81['query'][_0x1edc('0x10e')][_0x1edc('0x110')]())){throw new Error(_0x1edc('0x111'));}_0x48810d=[_0xad4e81[_0x1edc('0x2c')]['channel']['toLowerCase']()];}if(_0xad4e81[_0x1edc('0x2c')][_0x1edc('0x112')]){try{var _0x44ff3f=JSON[_0x1edc('0xfb')](_0xad4e81[_0x1edc('0x2c')][_0x1edc('0x112')]);if(!moment(_0x44ff3f['from'])[_0x1edc('0x113')]()){throw new Error(_0x1edc('0x114'));}if(!moment(_0x44ff3f['to'])[_0x1edc('0x113')]()){throw new Error(_0x1edc('0x115'));}}catch(_0x297e12){throw new Error('Invalid\x20createdAt\x20filter');}}if(!_0xad4e81[_0x1edc('0x2c')][_0x1edc('0x31')](_0x1edc('0x32'))){_0x44efbf[_0x1edc('0x14')]=qs['limit'](_0xad4e81[_0x1edc('0x2c')][_0x1edc('0x14')]||0xa);_0x44efbf[_0x1edc('0x12')]=qs[_0x1edc('0x12')](_0xad4e81['query']['offset']);}var _0xc81d2c=_0x48810d[_0x1edc('0x50')](function(_0x1498c9){if(_0x1498c9==='voice'){var _0x107c4b={'attributes':['id',_0x1edc('0x116'),_0x1edc('0x2a'),'source','destination','callerid',_0x1edc('0x117'),_0x1edc('0x118'),_0x1edc('0x119'),_0x1edc('0x11a'),'createdAt',_0x1edc('0x11b'),'userSecondDisposition','userThirdDisposition',_0x1edc('0x11c')],'where':{'ContactId':_0xad4e81['params']['id']},'include':[{'model':db['User'],'as':'User','attributes':['id',_0x1edc('0x1d'),_0x1edc('0x11d'),_0x1edc('0x8c')]}],'order':[[_0x1edc('0x11e'),'DESC']]};if(_0xad4e81[_0x1edc('0x2c')]['range']){_0x107c4b[_0x1edc('0x3d')][_0x1edc('0x11e')]={'$gte':_0x44ff3f[_0x1edc('0x37')],'$lte':_0x44ff3f['to']};}return db[_0x1edc('0xa3')][_0x1edc('0x11f')](_0x107c4b)[_0x1edc('0x19')](function(_0x3d63b1){_0x3a5cb5[_0x1edc('0x15')]+=_0x3d63b1['count'];return _[_0x1edc('0x50')](_0x3d63b1[_0x1edc('0x82')],function(_0x3fbbfd){var _0x3b8f94=_0x3fbbfd[_0x1edc('0x8f')]({'plain':!![]});_0x3b8f94[_0x1edc('0x10e')]=_0x1498c9;if(_0x3b8f94[_0x1edc('0x48')]){_0x3b8f94[_0x1edc('0x48')]={'id':_0x3b8f94[_0x1edc('0x48')]['id'],'name':_0x3b8f94['User']['name'],'fullname':_0x3b8f94[_0x1edc('0x48')]['fullname'],'alias':_0x3b8f94[_0x1edc('0x48')][_0x1edc('0x8c')]};}return _0x3b8f94;});});}else{var _0x13e103=_[_0x1edc('0x120')](_0x1498c9)+(_0x1498c9===_0x1edc('0x108')?_0x1edc('0x121'):_0x1edc('0x122'));var _0x56bf4f={'attributes':['id',_0x1edc('0x123'),_0x1edc('0x124'),'createdAt',_0x1edc('0x11a'),_0x1edc('0x125'),_0x1edc('0x126'),_0x1edc('0x127'),_0x1edc('0x11c'),_0x13e103+'Id'],'where':{'ContactId':_0xad4e81[_0x1edc('0x87')]['id']},'include':[{'model':db[_0x13e103],'as':'Account','attributes':['id','name',_0x1edc('0x128')]},{'model':db[_0x1edc('0x48')],'as':'Owner','attributes':['id',_0x1edc('0x1d'),_0x1edc('0x11d')]},{'model':db[_0x1edc('0x43')],'as':_0x1edc('0x81'),'attributes':['id',_0x1edc('0x1d'),_0x1edc('0x129')],'through':{'attributes':[]}}],'order':[[_0x1edc('0x11e'),_0x1edc('0x6a')]]};if(_0xad4e81[_0x1edc('0x2c')][_0x1edc('0x112')]){_0x56bf4f['where'][_0x1edc('0x11e')]={'$gte':_0x44ff3f[_0x1edc('0x37')],'$lte':_0x44ff3f['to']};}switch(_0x1498c9){case _0x1edc('0x108'):_0x56bf4f[_0x1edc('0x30')][_0x1edc('0x52')](_0x1edc('0x12a'),_0x1edc('0x12b'),_0x1edc('0x12c'),_0x1edc('0x12d'),'osName',_0x1edc('0x12e'),_0x1edc('0x12f'),'ratingValue','referer');break;case'mail':_0x56bf4f['attributes']['push'](_0x1edc('0x130'),_0x1edc('0x131'));break;case'openchannel':_0x56bf4f[_0x1edc('0x30')][_0x1edc('0x52')](_0x1edc('0x132'),'threadId');break;}return db[_[_0x1edc('0x120')](_0x1498c9)+_0x1edc('0x133')][_0x1edc('0x11f')](_0x56bf4f)[_0x1edc('0x19')](function(_0x5120f8){_0x3a5cb5[_0x1edc('0x15')]+=_0x5120f8['count'];return _[_0x1edc('0x50')](_0x5120f8[_0x1edc('0x82')],function(_0x52d6dd){var _0x143ef9=_0x52d6dd['get']({'plain':!![]});_0x143ef9['channel']=_0x1498c9;if(_0x143ef9[_0x1edc('0x134')]){_0x143ef9[_0x1edc('0x134')]={'id':_0x143ef9[_0x1edc('0x134')]['id'],'name':_0x143ef9[_0x1edc('0x134')][_0x1edc('0x1d')],'fullname':_0x143ef9['Owner'][_0x1edc('0x11d')]};}return _0x143ef9;});});}});return Promise[_0x1edc('0x27')](_0xc81d2c);})[_0x1edc('0x19')](function(_0x568d66){return _(_0x568d66)['flatten']()['sortBy'](_0x1edc('0x11e'))[_0x1edc('0x135')]()[_0x1edc('0x4a')]();})[_0x1edc('0x19')](function(_0x9a0975){_0x3a5cb5[_0x1edc('0x82')]=_0x44efbf['limit']?_0x9a0975[_0x1edc('0x136')](_0x44efbf[_0x1edc('0x12')],_0x44efbf[_0x1edc('0x12')]+_0x44efbf[_0x1edc('0x14')]):_0x9a0975;return _0x3a5cb5;})[_0x1edc('0x19')](respondWithFilteredResult(_0xe18008,_0x44efbf))[_0x1edc('0x83')](handleError(_0xe18008,null));};