Built motion from commit (unavailable).|2.5.1
[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 _0x4d7e=['html-pdf','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','./cmContact.socket','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','sendStatus','error','stack','name','index','CmContact','keys','startsWith','cf_','push','CmCustomField','findOne','length','type','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','select','field','from','cm_contacts','left_join','cm_user_has_contacts','uc.CmContactId\x20=\x20c.id','cm_contact_has_tags','ct.CmContactId\x20=\x20c.id','tools_tags','c.deletedAt\x20IS\x20NULL','expr','search','sqlOperator','conditions','Tag','value','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','and','uc.UserId\x20=\x20?','dateOfBirth','fieldType','datetime','castTo','DATE','buildExpression','map','filter','Contact','isEmpty','ListId','concat','CONCAT_WS(\x27\x20\x27,\x20c.firstName,\x20c.lastName,\x20c.email)\x20LIKE\x20?','\x20=\x20?','tag','isArray','replace','split','getFullTextValue','isNumeric','c.id\x20LIKE\x20?','c.phone\x20LIKE\x20?','c.mobile\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','c.lastName\x20LIKE\x20?','c.id','Sequelize','QueryTypes','SELECT','clone','order','DESC','t.id\x20IN\x20?','some','c.ListId\x20IS\x20NULL','c.ListId\x20IN\x20?','sequelize','toString','c.firstName','c.mobile','c.fax','c.email','c.ListId','TagIds','Tags','catch','destroy','params','describe','displayName','findAll','columnName','custom','values','merge','body','get','tags','join','[CmContact][merge]\x20to\x20%s\x20from\x20%s','CmHopper','info','[CmContact][merge][destroy][CmHopper],\x20%s','CmHopperBlack','create','ChatInteraction','ChatMessage','ChatOfflineMessage','MailInteraction','MailMessage','SmsInteraction','FaxInteraction','OpenchannelInteraction','CmHopperFinal','CmHopperHistory','ReportAgentPreview','VoiceCallReport','ChatQueueReport','OpenchannelQueueReport','SmsQueueReport','duplicates','$or','findOrCreate','show','find','color','omit','format','$and','pickBy','table','setFields','id\x20=\x20?','toParam','text','phone','getTags','rawAttributes','pick','options','setTags','ids','rows','includeAll','include','ContactId','getJscriptySessions','JscriptySessionReport','uploadCsv','binding_keys','No\x20association\x20keys\x20specified!','binding_values','Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed','Incorrect\x20binding\x20parameters\x20passed!','zipObject','No\x20phone\x20column\x20specified','firstName','No\x20firstName\x20column\x20specified','root','chmodSync','child_process','../../components/import/cm/csv','CompanyId','File\x20uploaded\x20correctly!','pid','send','upload','createReadStream','file','parse','agent','binding','socket_timestamp','fork','../../components/import/cm/csv2','stringify','message','start\x20child\x20process\x20correctly!','exit','error\x20child\x20process'];(function(_0xe41884,_0x11bb8e){var _0x2634dd=function(_0x583c47){while(--_0x583c47){_0xe41884['push'](_0xe41884['shift']());}};_0x2634dd(++_0x11bb8e);}(_0x4d7e,0xe7));var _0xe4d7=function(_0x2049db,_0x5075fe){_0x2049db=_0x2049db-0x0;var _0x2339f8=_0x4d7e[_0x2049db];return _0x2339f8;};'use strict';var pdf=require(_0xe4d7('0x0'));var emlformat=require(_0xe4d7('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xe4d7('0x2'));var rp=require(_0xe4d7('0x3'));var moment=require(_0xe4d7('0x4'));var BPromise=require(_0xe4d7('0x5'));var Mustache=require(_0xe4d7('0x6'));var util=require(_0xe4d7('0x7'));var path=require(_0xe4d7('0x8'));var sox=require(_0xe4d7('0x9'));var csv=require(_0xe4d7('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xe4d7('0xb'));var squel=require(_0xe4d7('0xc'));var crypto=require(_0xe4d7('0xd'));var jsforce=require(_0xe4d7('0xe'));var deskjs=require(_0xe4d7('0xf'));var toCsv=require(_0xe4d7('0xa'));var querystring=require(_0xe4d7('0x10'));var Papa=require(_0xe4d7('0x11'));var Redis=require(_0xe4d7('0x12'));var authService=require(_0xe4d7('0x13'));var qs=require(_0xe4d7('0x14'));var as=require(_0xe4d7('0x15'));var hardwareService=require(_0xe4d7('0x16'));var logger=require(_0xe4d7('0x17'))(_0xe4d7('0x18'));var utils=require('../../config/utils');var config=require(_0xe4d7('0x19'));var db=require(_0xe4d7('0x1a'))['db'];config[_0xe4d7('0x1b')]=_[_0xe4d7('0x1c')](config[_0xe4d7('0x1b')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xe4d7('0x1d'))['register'](socket);function respondWithStatusCode(_0x7ee7ab,_0x49bc3f){_0x49bc3f=_0x49bc3f||0xcc;return function(_0x2ef008){if(_0x2ef008){return _0x7ee7ab['sendStatus'](_0x49bc3f);}return _0x7ee7ab[_0xe4d7('0x1e')](_0x49bc3f)[_0xe4d7('0x1f')]();};}function respondWithResult(_0x44bea7,_0x3d63c5){_0x3d63c5=_0x3d63c5||0xc8;return function(_0x5adb4e){if(_0x5adb4e){return _0x44bea7[_0xe4d7('0x1e')](_0x3d63c5)[_0xe4d7('0x20')](_0x5adb4e);}};}function respondWithFilteredResult(_0x146a71,_0x2ad313){return function(_0x387515){if(_0x387515){var _0x383a01=_0x387515[_0xe4d7('0x21')],_0x22f105=_0x2ad313[_0xe4d7('0x22')],_0x5d459d=_0x2ad313[_0xe4d7('0x22')]+_0x2ad313[_0xe4d7('0x23')],_0x411dcd;if(_0x5d459d>=_0x383a01){_0x5d459d=_0x383a01;_0x411dcd=0xc8;}else{_0x411dcd=0xce;}_0x146a71[_0xe4d7('0x1e')](_0x411dcd);return _0x146a71[_0xe4d7('0x24')](_0xe4d7('0x25'),_0x22f105+'-'+_0x5d459d+'/'+_0x383a01)[_0xe4d7('0x20')](_0x387515);}return null;};}function patchUpdates(_0x5f5bf3){return function(_0x43ed9d){try{jsonpatch[_0xe4d7('0x26')](_0x43ed9d,_0x5f5bf3,!![]);}catch(_0x2acc52){return BPromise[_0xe4d7('0x27')](_0x2acc52);}return _0x43ed9d[_0xe4d7('0x28')]();};}function saveUpdates(_0x349e44,_0x1ff8e8){return function(_0x653a73){if(_0x653a73){return _0x653a73[_0xe4d7('0x29')](_0x349e44)[_0xe4d7('0x2a')](function(_0x8219ca){return _0x8219ca;});}return null;};}function removeEntity(_0x284b44,_0x2b8757){return function(_0x5dc95b){if(_0x5dc95b){return _0x5dc95b['destroy']()[_0xe4d7('0x2a')](function(){_0x284b44[_0xe4d7('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2368e6,_0x4ae3b6){return function(_0x58fe8f){if(!_0x58fe8f){_0x2368e6[_0xe4d7('0x2b')](0x194);}return _0x58fe8f;};}function handleError(_0x3db1b3,_0x5a3b6b){_0x5a3b6b=_0x5a3b6b||0x1f4;return function(_0x36f512){logger[_0xe4d7('0x2c')](_0x36f512[_0xe4d7('0x2d')]);if(_0x36f512[_0xe4d7('0x2e')]){delete _0x36f512['name'];}_0x3db1b3['status'](_0x5a3b6b)['send'](_0x36f512);};}exports[_0xe4d7('0x2f')]=function(_0x4e4910,_0x5ea48b){var _0x362bde={},_0x540b25={},_0x427020={'count':0x0,'rows':[]};return db[_0xe4d7('0x30')]['describe']()[_0xe4d7('0x2a')](function(_0x58eaa6){var _0x3dc8a7=[];for(var _0x439884=0x0;_0x439884<Object[_0xe4d7('0x31')](_0x58eaa6)['length'];_0x439884++){var _0x22a1f7=Object[_0xe4d7('0x31')](_0x58eaa6)[_0x439884];if(_[_0xe4d7('0x32')](_0x22a1f7,_0xe4d7('0x33'))){_0x3dc8a7[_0xe4d7('0x34')](db[_0xe4d7('0x35')][_0xe4d7('0x36')]({'where':{'id':_['trimStart'](_0x22a1f7,_0xe4d7('0x33'))},'raw':!![]}));}}return BPromise['all'](_0x3dc8a7)[_0xe4d7('0x2a')](function(_0x5b42fc){for(var _0x1d0be9=0x0;_0x1d0be9<_0x5b42fc[_0xe4d7('0x37')];_0x1d0be9++){if(_0x5b42fc[_0x1d0be9]){var _0x3441d3=_0xe4d7('0x33')+_0x5b42fc[_0x1d0be9]['id'];var _0x5824bf=_0x58eaa6[_0x3441d3];_0x5824bf['fieldType']=_0x5b42fc[_0x1d0be9][_0xe4d7('0x38')];}}return _0x58eaa6;});})[_0xe4d7('0x2a')](function(_0x481666){_0x540b25[_0xe4d7('0x39')]=_[_0xe4d7('0x31')](_0x481666);_0x540b25[_0xe4d7('0x3a')]=_[_0xe4d7('0x31')](_0x4e4910[_0xe4d7('0x3a')]);_0x540b25[_0xe4d7('0x3b')]=_[_0xe4d7('0x3c')](_0x540b25[_0xe4d7('0x39')],_0x540b25['query']);_0x362bde[_0xe4d7('0x3d')]=_[_0xe4d7('0x3c')](_0x540b25[_0xe4d7('0x39')],qs[_0xe4d7('0x3e')](_0x4e4910[_0xe4d7('0x3a')]['fields']));_0x362bde['attributes']=_0x362bde['attributes'][_0xe4d7('0x37')]?_0x362bde[_0xe4d7('0x3d')]:_0x540b25['model'];if(!_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x3f')](_0xe4d7('0x40'))){_0x362bde[_0xe4d7('0x23')]=qs[_0xe4d7('0x23')](_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x23')]);_0x362bde[_0xe4d7('0x22')]=qs[_0xe4d7('0x22')](_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x22')]);}_0x362bde['order']=qs[_0xe4d7('0x41')](_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x41')]);_0x362bde[_0xe4d7('0x42')]=qs[_0xe4d7('0x3b')](_['pick'](_0x4e4910[_0xe4d7('0x3a')],_0x540b25[_0xe4d7('0x3b')]),_0x481666);var _0x3839fe=[];var _0x420dd6=squel[_0xe4d7('0x43')]()['field']('id')[_0xe4d7('0x44')](_0xe4d7('0x2e'))[_0xe4d7('0x44')]('color')[_0xe4d7('0x45')]('tools_tags');var _0x547370=squel[_0xe4d7('0x43')]()[_0xe4d7('0x45')](_0xe4d7('0x46'),'c')[_0xe4d7('0x47')](_0xe4d7('0x48'),'uc',_0xe4d7('0x49'))[_0xe4d7('0x47')](_0xe4d7('0x4a'),'ct',_0xe4d7('0x4b'))[_0xe4d7('0x47')](_0xe4d7('0x4c'),'t','t.id\x20=\x20ct.TagId')['where'](_0xe4d7('0x4d'));var _0x5c95b9=squel[_0xe4d7('0x4e')]();var _0x3f6bb4=[];var _0x24b503=squel[_0xe4d7('0x4e')]();var _0x2e17b5;if(_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x4f')]){_0x2e17b5=as['parseSearch'](_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x4f')]);var _0x3c350a=_0x2e17b5[_0xe4d7('0x50')];for(var _0x548527=0x0;_0x548527<_0x2e17b5['conditions']['length'];_0x548527++){var _0x1eb42d=_0x2e17b5[_0xe4d7('0x51')][_0x548527];var _0x26a2bb='c';var _0xb90bcc=_(_0x481666)[_0xe4d7('0x31')]()['find'](function(_0x16b1a7){return _0x16b1a7===_0x1eb42d['field'];});if(_0xb90bcc)_0xb90bcc=_0x481666[_0x1eb42d[_0xe4d7('0x44')]];if(!_0xb90bcc){if(_0x1eb42d[_0xe4d7('0x44')]===_0xe4d7('0x52')){var _0x3c6889=_0x1eb42d[_0xe4d7('0x53')]['split'](',')['map'](function(_0xfb1ec6){return Number(_0xfb1ec6);});_0x3c6889[_0xe4d7('0x54')](function(_0x4a2940){_0x24b503['or'](_0xe4d7('0x55'),'%,'+_0x4a2940+',%');});_0x3f6bb4=_[_0xe4d7('0x56')](_0x3f6bb4,_0x3c6889);}else if(_0x1eb42d[_0xe4d7('0x44')]===_0xe4d7('0x57')){_0x5c95b9[_0xe4d7('0x58')](_0xe4d7('0x59'),_0x1eb42d[_0xe4d7('0x53')]);}}else{if(_0x1eb42d[_0xe4d7('0x44')]===_0xe4d7('0x5a')||_0xb90bcc[_0xe4d7('0x5b')]===_0xe4d7('0x5c'))_0x1eb42d[_0xe4d7('0x5d')]=_0xe4d7('0x5e');var _0x2ab9ab=as[_0xe4d7('0x5f')](_0x26a2bb,_0xb90bcc['type'],_0x1eb42d);_0x5c95b9[_0x3c350a](_0x2ab9ab['text'],_0x2ab9ab[_0xe4d7('0x53')]['start'],_0x2ab9ab['value'][_0xe4d7('0x1f')]);}}}else{var _0x5b6c8f=_(Object[_0xe4d7('0x31')](_0x4e4910[_0xe4d7('0x3a')]))[_0xe4d7('0x60')](function(_0x3fd390){return _0x481666[_0xe4d7('0x3f')](_0x3fd390)?_0x3fd390:undefined;})[_0xe4d7('0x61')](function(_0x57e918){return!_['isNil'](_0x57e918);})[_0xe4d7('0x53')]();if(_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x62')])_0x5b6c8f['push']('Contact');if(!_[_0xe4d7('0x63')](_0x5b6c8f)){_0x5b6c8f['forEach'](function(_0x2b41ec){if(_0x2b41ec===_0xe4d7('0x64')){_0x547370[_0xe4d7('0x42')]('c.ListId\x20IN\x20?',[][_0xe4d7('0x65')](_0x4e4910[_0xe4d7('0x3a')][_0x2b41ec]));}else if(_0x2b41ec==='Contact'){var _0x1a8fe4='%'+_0x4e4910[_0xe4d7('0x3a')][_0x2b41ec]+'%';_0x547370[_0xe4d7('0x42')](_0xe4d7('0x66'),_0x1a8fe4);}else{_0x547370[_0xe4d7('0x42')]('c.'+_0x2b41ec+_0xe4d7('0x67'),_0x4e4910[_0xe4d7('0x3a')][_0x2b41ec]);}});}if(_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x68')]){_0x3f6bb4=_[_0xe4d7('0x69')](_0x4e4910[_0xe4d7('0x3a')]['tag'])?_0x4e4910[_0xe4d7('0x3a')]['tag']:new Array(_0x4e4910['query'][_0xe4d7('0x68')]);_0x3f6bb4[_0xe4d7('0x54')](function(_0x27d975){_0x24b503['or'](_0xe4d7('0x55'),'%,'+_0x27d975+',%');});}if(_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x61')]){var _0xe84b35=_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x61')][_0xe4d7('0x6a')]('\x5c','\x5c\x5c')[_0xe4d7('0x6a')]('\x27\x27','\x27\x27\x27\x27');if(_0xe84b35[_0xe4d7('0x6b')]('\x20')['length']>0x1){_0x5c95b9['or']('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xe4d7('0x6c')](_0xe84b35),null);}else{if(qs[_0xe4d7('0x6d')](_0xe84b35)){_0x5c95b9['or'](_0xe4d7('0x6e'),_0xe84b35+'%');_0x5c95b9['or'](_0xe4d7('0x6f'),_0xe84b35+'%');_0x5c95b9['or'](_0xe4d7('0x70'),_0xe84b35+'%');_0x5c95b9['or']('c.fax\x20LIKE\x20?',_0xe84b35+'%');}else if(qs[_0xe4d7('0x71')](_0xe84b35)){_0x5c95b9['or'](_0xe4d7('0x72'),_0xe84b35+'%');}else{_0x5c95b9['or']('c.firstName\x20LIKE\x20?','%'+_0xe84b35+'%');_0x5c95b9['or'](_0xe4d7('0x73'),'%'+_0xe84b35+'%');_0x5c95b9['or'](_0xe4d7('0x72'),'%'+_0xe84b35+'%');}}}}_0x547370[_0xe4d7('0x42')](_0x5c95b9);_0x547370['group'](_0xe4d7('0x74'));var _0x2ed6db={'type':db[_0xe4d7('0x75')][_0xe4d7('0x76')][_0xe4d7('0x77')],'raw':!![]};var _0x542dea=_0x547370[_0xe4d7('0x78')]()['field'](_0xe4d7('0x74'));if(_0x362bde[_0xe4d7('0x79')]){_0x362bde[_0xe4d7('0x79')][_0xe4d7('0x54')](function(_0x4bb7bd){_0x547370[_0xe4d7('0x79')]('c.'+_0x4bb7bd[0x0],_0x4bb7bd[0x1]===_0xe4d7('0x7a')?![]:!![]);});}if(!_[_0xe4d7('0x63')](_0x3f6bb4)){_0x547370['having'](_0x24b503);_0x542dea[_0xe4d7('0x42')](_0xe4d7('0x7b'),_0x3f6bb4);}BPromise['resolve']()[_0xe4d7('0x2a')](function(){if(_0x2e17b5&&!_[_0xe4d7('0x7c')](_0x2e17b5[_0xe4d7('0x51')],['field','User'])){return _0x4e4910['user']['getLists']({'attributes':['id'],'raw':!![]})[_0xe4d7('0x2a')](function(_0x23dd32){if(_['isEmpty'](_0x23dd32)){_0x542dea['where']('c.ListId\x20IS\x20NULL');_0x547370['where'](_0xe4d7('0x7d'));}else{_0x542dea[_0xe4d7('0x42')]('c.ListId\x20IN\x20?',_['map'](_0x23dd32,'id'));_0x547370[_0xe4d7('0x42')](_0xe4d7('0x7e'),_[_0xe4d7('0x60')](_0x23dd32,'id'));}});}else{return;}})['then'](function(){db[_0xe4d7('0x7f')][_0xe4d7('0x3a')](_0x542dea[_0xe4d7('0x80')](),_0x2ed6db)[_0xe4d7('0x2a')](function(_0x40c68a){_0x427020[_0xe4d7('0x21')]=_0x40c68a['length'];if(_0x427020[_0xe4d7('0x21')]===0x0)return[];return db[_0xe4d7('0x7f')][_0xe4d7('0x3a')](_0x420dd6[_0xe4d7('0x80')](),_0x2ed6db);})[_0xe4d7('0x2a')](function(_0xc97d5f){_0x3839fe=_['keyBy'](_0xc97d5f,'id');_0x2ed6db=_['merge'](_0x2ed6db,{'model':db[_0xe4d7('0x30')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4e4910[_0xe4d7('0x3a')][_0xe4d7('0x3e')]){_0x362bde['attributes']['forEach'](function(_0x2d8943){_0x547370[_0xe4d7('0x44')]('c.'+_0x2d8943);});}else{_0x547370[_0xe4d7('0x44')](_0xe4d7('0x74'));_0x547370[_0xe4d7('0x44')](_0xe4d7('0x81'));_0x547370['field']('c.lastName');_0x547370['field']('c.phone');_0x547370[_0xe4d7('0x44')](_0xe4d7('0x82'));_0x547370[_0xe4d7('0x44')](_0xe4d7('0x83'));_0x547370[_0xe4d7('0x44')](_0xe4d7('0x84'));_0x547370[_0xe4d7('0x44')](_0xe4d7('0x85'));_0x547370[_0xe4d7('0x44')]('c.deletedAt');_0x547370[_0xe4d7('0x44')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0xe4d7('0x86'));}if(_0x362bde[_0xe4d7('0x23')])_0x547370[_0xe4d7('0x23')](_0x362bde[_0xe4d7('0x23')]);if(_0x362bde[_0xe4d7('0x22')])_0x547370['offset'](_0x362bde['offset']);return db[_0xe4d7('0x7f')][_0xe4d7('0x3a')](_0x547370['toString'](),_0x2ed6db);})[_0xe4d7('0x2a')](function(_0x5c0418){_0x5c0418[_0xe4d7('0x54')](function(_0xef5bc4){if(_0xef5bc4[_0xe4d7('0x86')]){_0xef5bc4[_0xe4d7('0x87')]=[];_0xef5bc4[_0xe4d7('0x86')][_0xe4d7('0x6b')](',')[_0xe4d7('0x54')](function(_0x4e92db){_0xef5bc4['Tags'][_0xe4d7('0x34')](_0x3839fe[_0x4e92db]);});}delete _0xef5bc4['TagIds'];});_0x427020['rows']=_0x5c0418;return _0x427020;})[_0xe4d7('0x2a')](respondWithFilteredResult(_0x5ea48b,_0x362bde));});})[_0xe4d7('0x88')](handleError(_0x5ea48b,null));};exports[_0xe4d7('0x89')]=function(_0x3beeae,_0x1db0c2){return db[_0xe4d7('0x30')]['find']({'where':{'id':_0x3beeae[_0xe4d7('0x8a')]['id']}})['then'](handleEntityNotFound(_0x1db0c2,null))['then'](removeEntity(_0x1db0c2,null))[_0xe4d7('0x88')](handleError(_0x1db0c2,null));};exports[_0xe4d7('0x8b')]=function(_0x5b5359,_0x1642c8){return db['CmContact'][_0xe4d7('0x8b')]()['then'](function(_0x5346d1){delete _0x5346d1['tags'];for(var _0x4a5828=0x0;_0x4a5828<Object[_0xe4d7('0x31')](_0x5346d1)[_0xe4d7('0x37')];_0x4a5828++){var _0x88c85e=Object['keys'](_0x5346d1)[_0x4a5828];if(!_[_0xe4d7('0x32')](_0x88c85e,_0xe4d7('0x33'))){_0x5346d1[_0x88c85e]['columnName']=_0x88c85e;_0x5346d1[_0x88c85e][_0xe4d7('0x8c')]=_0x88c85e;}}return _0x5346d1;})[_0xe4d7('0x2a')](function(_0x3c1193){var _0xccb479={'where':{'$or':[{'ListId':_0x5b5359[_0xe4d7('0x3a')]['id']},{'ListId':null}]},'raw':!![]};return db[_0xe4d7('0x35')][_0xe4d7('0x8d')](_0xccb479)['then'](function(_0x4e12ed){for(var _0x12691a=0x0;_0x12691a<_0x4e12ed[_0xe4d7('0x37')];_0x12691a++){var _0x546826=_0xe4d7('0x33')+_0x4e12ed[_0x12691a]['id'];_0x3c1193[_0x546826][_0xe4d7('0x8e')]=_0x546826;_0x3c1193[_0x546826][_0xe4d7('0x8c')]=_0x4e12ed[_0x12691a]['alias'];_0x3c1193[_0x546826][_0xe4d7('0x8f')]={'type':_0x4e12ed[_0x12691a]['type'],'values':_0x4e12ed[_0x12691a][_0xe4d7('0x90')]};}Object[_0xe4d7('0x31')](_0x3c1193)[_0xe4d7('0x54')](function(_0x514caa){if(!_0x3c1193[_0x514caa]['hasOwnProperty']('columnName')){delete _0x3c1193[_0x514caa];}});return _0x3c1193;});})[_0xe4d7('0x2a')](respondWithResult(_0x1642c8,null))[_0xe4d7('0x88')](handleError(_0x1642c8,null));};exports[_0xe4d7('0x91')]=function(_0x16afe7,_0x1f66e7){var _0x2e36af;var _0x45870c;var _0x562620;if(_0x16afe7[_0xe4d7('0x92')]['id']){delete _0x16afe7[_0xe4d7('0x92')]['id'];}return db[_0xe4d7('0x30')][_0xe4d7('0x8d')]({'where':{'id':[_0x16afe7['body']['to'],_0x16afe7[_0xe4d7('0x92')]['from']]}})[_0xe4d7('0x2a')](function(_0x25106f){if(_0x25106f){if(_0x25106f[_0xe4d7('0x37')]!==0x2){return null;}_0x25106f[0x0]=_0x25106f[0x0][_0xe4d7('0x93')]({'plain':!![]});_0x25106f[0x1]=_0x25106f[0x1][_0xe4d7('0x93')]({'plain':!![]});delete _0x25106f[0x0]['id'];delete _0x25106f[0x1]['id'];return _['mergeWith'](_0x25106f[0x0],_0x25106f[0x1],function(_0x4f29b8,_0x527df2){if(Array[_0xe4d7('0x69')](_0x527df2)&&!_0x527df2[_0xe4d7('0x37')]){return _0x4f29b8;}else if(!_0x527df2){return _0x4f29b8;}});}})[_0xe4d7('0x2a')](handleEntityNotFound(_0x1f66e7,null))[_0xe4d7('0x2a')](function(_0x89e2){if(_0x89e2){if(_0x89e2[_0xe4d7('0x94')]&&_[_0xe4d7('0x69')](_0x89e2['tags'])){_0x89e2[_0xe4d7('0x94')]=_0x89e2['tags'][_0xe4d7('0x95')]();}logger['info'](_0xe4d7('0x96'),_0x16afe7[_0xe4d7('0x92')]['to'],_0x16afe7['body'][_0xe4d7('0x45')]);return db[_0xe4d7('0x97')][_0xe4d7('0x89')]({'where':{'ContactId':[_0x16afe7['body']['to'],_0x16afe7[_0xe4d7('0x92')][_0xe4d7('0x45')]]}})['then'](function(_0x15cfbe){logger[_0xe4d7('0x98')](_0xe4d7('0x99'),_0x15cfbe);return db[_0xe4d7('0x9a')][_0xe4d7('0x89')]({'where':{'ContactId':[_0x16afe7[_0xe4d7('0x92')]['to'],_0x16afe7[_0xe4d7('0x92')]['from']]}})['then'](function(_0x352704){logger[_0xe4d7('0x98')]('[CmContact][merge][destroy][CmHopperBlack],\x20%s',_0x352704);return db[_0xe4d7('0x30')][_0xe4d7('0x9b')](_0x89e2);});});}})[_0xe4d7('0x2a')](function(_0x1e3b71){if(_0x1e3b71){_0x2e36af=_0x1e3b71;_0x45870c={'ContactId':_0x2e36af['id']};_0x562620={'where':{'ContactId':[_0x16afe7[_0xe4d7('0x92')]['to'],_0x16afe7['body']['from']]}};return db[_0xe4d7('0x9c')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})['then'](function(){if(_0x2e36af){return db[_0xe4d7('0x9d')]['update'](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0x9e')]['update'](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0x9f')]['update'](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa0')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0x9f')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa0')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})['then'](function(){if(_0x2e36af){return db[_0xe4d7('0xa1')]['update'](_0x45870c,_0x562620);}})['then'](function(){if(_0x2e36af){return db['SmsMessage'][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa2')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db['FaxMessage'][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa3')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db['OpenchannelMessage'][_0xe4d7('0x29')](_0x45870c,_0x562620);}})['then'](function(){if(_0x2e36af){return db[_0xe4d7('0xa4')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa5')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa6')]['update'](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa7')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa8')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db['FaxQueueReport']['update'](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db['MailQueueReport']['update'](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xa9')][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0xaa')]['update'](_0x45870c,_0x562620);}})['then'](function(){if(_0x2e36af){return db['JscriptySessionReport'][_0xe4d7('0x29')](_0x45870c,_0x562620);}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return db[_0xe4d7('0x30')][_0xe4d7('0x89')]({'where':{'id':[_0x16afe7[_0xe4d7('0x92')]['to'],_0x16afe7[_0xe4d7('0x92')][_0xe4d7('0x45')]]}});}})[_0xe4d7('0x2a')](function(){if(_0x2e36af){return _0x2e36af;}})[_0xe4d7('0x2a')](respondWithResult(_0x1f66e7,null))['catch'](handleError(_0x1f66e7,null));};exports[_0xe4d7('0x9b')]=function(_0x3dc73b,_0x5d0538){return db[_0xe4d7('0x30')]['describe']()[_0xe4d7('0x2a')](function(_0x414873){if(_0x3dc73b[_0xe4d7('0x92')][_0xe4d7('0x94')]&&_['isArray'](_0x3dc73b[_0xe4d7('0x92')][_0xe4d7('0x94')])){if(_0x3dc73b['body']['tags'][_0xe4d7('0x37')]){_0x3dc73b['body'][_0xe4d7('0x94')]=_0x3dc73b[_0xe4d7('0x92')][_0xe4d7('0x94')]['join'](';')+';';}else{_0x3dc73b[_0xe4d7('0x92')][_0xe4d7('0x94')]=null;}}else{_0x3dc73b['body'][_0xe4d7('0x94')]=null;}return db[_0xe4d7('0x30')][_0xe4d7('0x9b')](_0x3dc73b[_0xe4d7('0x92')],{'fields':_[_0xe4d7('0x31')](_0x414873),'raw':!![]});})[_0xe4d7('0x2a')](respondWithResult(_0x5d0538,0xc9))['catch'](handleError(_0x5d0538,null));};exports['bulkCreate']=function(_0x4ee315,_0x38020e){var _0x352120=[];var _0x2245cf=0x0;var _0x508615=0x0;var _0x123588=0x0;return db[_0xe4d7('0x30')]['describe']()['then'](function(_0x2af37f){return BPromise['each'](_0x4ee315['body'],function(_0x2ecedc){var _0x1e0d8c={'where':{'$or':[]},'defaults':_0x2ecedc,'fields':_[_0xe4d7('0x31')](_0x2af37f),'raw':!![]};if(_0x2ecedc[_0xe4d7('0xab')]){for(var _0x464626=0x0;_0x464626<_0x2ecedc[_0xe4d7('0xab')]['length'];_0x464626++){var _0x5e5db5={};_0x5e5db5[_0x2ecedc[_0xe4d7('0xab')][_0x464626]]=_0x2ecedc[_0x2ecedc[_0xe4d7('0xab')][_0x464626]];_0x1e0d8c[_0xe4d7('0x42')][_0xe4d7('0xac')]['push'](_0x5e5db5);}_0x1e0d8c[_0xe4d7('0x42')]['ListId']=_0x2ecedc[_0xe4d7('0x64')];}return db[_0xe4d7('0x30')][_0xe4d7('0xad')](_0x1e0d8c)['spread'](function(_0x1391d2,_0x117956){if(_0x117956){_0x2245cf++;}else{_0x123588++;}})[_0xe4d7('0x88')](function(_0x21765d){console[_0xe4d7('0x2c')](_0x21765d);_0x508615++;});});})['then'](function(_0x14f52c){if(_0x14f52c){return{'success':_0x2245cf,'failure':_0x508615,'duplicates':_0x123588};}})[_0xe4d7('0x2a')](respondWithResult(_0x38020e,0xc9))[_0xe4d7('0x88')](handleError(_0x38020e,null));};exports[_0xe4d7('0xae')]=function(_0x4f0fba,_0x1ea167,_0x3d3a36){var _0x42174b;return db['CmContact']['describe']()['then'](function(_0x3b6352){return db[_0xe4d7('0x30')][_0xe4d7('0xaf')]({'where':{'id':_0x4f0fba['params']['id']},'include':[{'model':db['Tag'],'as':_0xe4d7('0x87'),'attributes':['id',_0xe4d7('0x2e'),_0xe4d7('0xb0')],'required':_0x4f0fba[_0xe4d7('0x3a')][_0xe4d7('0x68')]?!![]:![]}],'attributes':_['keys'](_0x3b6352)});})['then'](function(_0x482df7){_0x42174b=_0x482df7[_0xe4d7('0x93')]({'plain':!![]});var _0x31a307={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x482df7&&_0x482df7['ListId']){if(_0x482df7[_0xe4d7('0x64')]){_0x31a307['where']['$and'][_0xe4d7('0x34')]({'ListId':{'$ne':_0x482df7[_0xe4d7('0x64')]}});}}return db['CmCustomField'][_0xe4d7('0x8d')](_0x31a307);})['then'](function(_0x5b06c0){return _[_0xe4d7('0xb1')](_0x42174b,_[_0xe4d7('0x60')](_0x5b06c0,function(_0x3d8b1e){return util[_0xe4d7('0xb2')]('cf_%d',_0x3d8b1e['id']);}));})[_0xe4d7('0x2a')](handleEntityNotFound(_0x1ea167,null))[_0xe4d7('0x2a')](respondWithResult(_0x1ea167,null))['catch'](handleError(_0x1ea167,null));};exports[_0xe4d7('0x29')]=function(_0x4d9e19,_0x4fc125){var _0xa590e0;if(_0x4d9e19[_0xe4d7('0x92')]['id']){delete _0x4d9e19['body']['id'];}return db[_0xe4d7('0x30')][_0xe4d7('0xaf')]({'where':{'id':_0x4d9e19[_0xe4d7('0x8a')]['id']}})[_0xe4d7('0x2a')](handleEntityNotFound(_0x4fc125,null))[_0xe4d7('0x2a')](saveUpdates(_0x4d9e19[_0xe4d7('0x92')],null))[_0xe4d7('0x2a')](function(_0x7ef9f0){_0xa590e0=_0x7ef9f0;var _0x2f34dc={'where':{'$and':[{'ListId':{'$ne':null}}]}};if(_0x7ef9f0&&_0x7ef9f0[_0xe4d7('0x64')]){if(_0x7ef9f0[_0xe4d7('0x64')]){_0x2f34dc[_0xe4d7('0x42')][_0xe4d7('0xb3')][_0xe4d7('0x34')]({'ListId':{'$ne':_0x7ef9f0[_0xe4d7('0x64')]}});}}return db[_0xe4d7('0x35')][_0xe4d7('0x8d')](_0x2f34dc);})['then'](function(_0x3a58b1){if(_0x3a58b1){return _[_0xe4d7('0xb1')](_[_0xe4d7('0xb4')](_0x4d9e19[_0xe4d7('0x92')],function(_0x46b407,_0x2efa1f){return _[_0xe4d7('0x32')](_0x2efa1f,_0xe4d7('0x33'));}),_[_0xe4d7('0x60')](_0x3a58b1,function(_0x510cf6){return util['format']('cf_%d',_0x510cf6['id']);}));}})[_0xe4d7('0x2a')](function(_0x2ded1f){if(_0x2ded1f&&!_['isEmpty'](_0x2ded1f)){var _0x3eca95=squel[_0xe4d7('0x29')]()[_0xe4d7('0xb5')](_0xe4d7('0x46'))[_0xe4d7('0xb6')](_0x2ded1f)[_0xe4d7('0x42')](_0xe4d7('0xb7'),_0x4d9e19[_0xe4d7('0x8a')]['id'])[_0xe4d7('0xb8')]();return db[_0xe4d7('0x7f')][_0xe4d7('0x3a')](_0x3eca95[_0xe4d7('0xb9')],{'replacements':_0x3eca95[_0xe4d7('0x90')]});}})[_0xe4d7('0x2a')](function(){if(_0x4d9e19[_0xe4d7('0x92')][_0xe4d7('0xba')]&&_0xa590e0){return db[_0xe4d7('0x97')]['update']({'phone':_0x4d9e19[_0xe4d7('0x92')][_0xe4d7('0xba')]},{'where':{'ContactId':_0xa590e0['id']}});}})[_0xe4d7('0x2a')](function(){return _0xa590e0;})[_0xe4d7('0x2a')](respondWithResult(_0x4fc125,null))[_0xe4d7('0x88')](handleError(_0x4fc125,null));};exports[_0xe4d7('0xbb')]=function(_0x134120,_0x4135ca,_0x13afa8){var _0x43ceaa={};var _0x105a30={};var _0x49403a;var _0xbdf91a;return db[_0xe4d7('0x30')][_0xe4d7('0x36')]({'where':{'id':_0x134120[_0xe4d7('0x8a')]['id']}})[_0xe4d7('0x2a')](handleEntityNotFound(_0x4135ca,null))[_0xe4d7('0x2a')](function(_0x3cc70d){if(_0x3cc70d){_0x49403a=_0x3cc70d;_0x105a30[_0xe4d7('0x39')]=_[_0xe4d7('0x31')](db['Tag'][_0xe4d7('0xbc')]);_0x105a30[_0xe4d7('0x3a')]=_[_0xe4d7('0x31')](_0x134120[_0xe4d7('0x3a')]);_0x105a30['filters']=_[_0xe4d7('0x3c')](_0x105a30[_0xe4d7('0x39')],_0x105a30[_0xe4d7('0x3a')]);_0x43ceaa['attributes']=_[_0xe4d7('0x3c')](_0x105a30['model'],qs[_0xe4d7('0x3e')](_0x134120['query'][_0xe4d7('0x3e')]));_0x43ceaa[_0xe4d7('0x3d')]=_0x43ceaa[_0xe4d7('0x3d')][_0xe4d7('0x37')]?_0x43ceaa[_0xe4d7('0x3d')]:_0x105a30[_0xe4d7('0x39')];_0x43ceaa[_0xe4d7('0x79')]=qs[_0xe4d7('0x41')](_0x134120[_0xe4d7('0x3a')][_0xe4d7('0x41')]);_0x43ceaa[_0xe4d7('0x42')]=qs[_0xe4d7('0x3b')](_[_0xe4d7('0xbd')](_0x134120[_0xe4d7('0x3a')],_0x105a30['filters']));if(_0x134120[_0xe4d7('0x3a')][_0xe4d7('0x61')]){_0x43ceaa[_0xe4d7('0x42')]=_[_0xe4d7('0x91')](_0x43ceaa[_0xe4d7('0x42')],{'$or':_[_0xe4d7('0x60')](_0x43ceaa['attributes'],function(_0xe97ac7){var _0x2f381d={};_0x2f381d[_0xe97ac7]={'$like':'%'+_0x134120['query']['filter']+'%'};return _0x2f381d;})});}_0x43ceaa=_[_0xe4d7('0x91')]({},_0x43ceaa,_0x134120[_0xe4d7('0xbe')]);return _0x49403a[_0xe4d7('0xbb')](_0x43ceaa);}})[_0xe4d7('0x2a')](function(_0x387182){if(_0x387182){_0xbdf91a=_0x387182[_0xe4d7('0x37')];if(!_0x134120[_0xe4d7('0x3a')]['hasOwnProperty'](_0xe4d7('0x40'))){_0x43ceaa[_0xe4d7('0x23')]=qs[_0xe4d7('0x23')](_0x134120[_0xe4d7('0x3a')][_0xe4d7('0x23')]);_0x43ceaa[_0xe4d7('0x22')]=qs['offset'](_0x134120[_0xe4d7('0x3a')]['offset']);}return _0x49403a[_0xe4d7('0xbb')](_0x43ceaa);}})[_0xe4d7('0x2a')](function(_0x19d6ac){if(_0x19d6ac){return _0x19d6ac?{'count':_0xbdf91a,'rows':_0x19d6ac}:null;}})[_0xe4d7('0x2a')](respondWithResult(_0x4135ca,null))[_0xe4d7('0x88')](handleError(_0x4135ca,null));};exports['setTags']=function(_0x3c334b,_0x223802,_0x3c83b4){if(_0x3c334b[_0xe4d7('0x92')]['id']){delete _0x3c334b[_0xe4d7('0x92')]['id'];}return db['CmContact'][_0xe4d7('0x36')]({'where':{'id':_0x3c334b[_0xe4d7('0x8a')]['id']}})['then'](handleEntityNotFound(_0x223802,null))[_0xe4d7('0x2a')](function(_0x2b0318){if(_0x2b0318){return _0x2b0318[_0xe4d7('0xbf')](_0x3c334b[_0xe4d7('0x92')][_0xe4d7('0xc0')]||[]);}return null;})[_0xe4d7('0x2a')](respondWithResult(_0x223802,null))[_0xe4d7('0x88')](handleError(_0x223802,null));};exports['getHoppers']=function(_0x5e6265,_0x2ec313,_0x19d389){var _0x124d9a={'raw':![],'where':{}};var _0x5dfbe5={};var _0x274c6={'count':0x0,'rows':[]};return db['CmContact'][_0xe4d7('0x36')]({'where':{'id':_0x5e6265[_0xe4d7('0x8a')]['id']}})['then'](handleEntityNotFound(_0x2ec313,null))['then'](function(_0x4bedd6){if(_0x4bedd6){_0x5dfbe5['model']=_['keys'](db[_0xe4d7('0x97')][_0xe4d7('0xbc')]);_0x5dfbe5[_0xe4d7('0x3a')]=_['keys'](_0x5e6265[_0xe4d7('0x3a')]);_0x5dfbe5[_0xe4d7('0x3b')]=_['intersection'](_0x5dfbe5[_0xe4d7('0x39')],_0x5dfbe5[_0xe4d7('0x3a')]);_0x124d9a[_0xe4d7('0x3d')]=_['intersection'](_0x5dfbe5['model'],qs[_0xe4d7('0x3e')](_0x5e6265[_0xe4d7('0x3a')]['fields']));_0x124d9a[_0xe4d7('0x3d')]=_0x124d9a[_0xe4d7('0x3d')][_0xe4d7('0x37')]?_0x124d9a['attributes']:_0x5dfbe5['model'];if(!_0x5e6265['query'][_0xe4d7('0x3f')]('nolimit')){_0x124d9a[_0xe4d7('0x23')]=qs[_0xe4d7('0x23')](_0x5e6265[_0xe4d7('0x3a')]['limit']);_0x124d9a[_0xe4d7('0x22')]=qs[_0xe4d7('0x22')](_0x5e6265[_0xe4d7('0x3a')][_0xe4d7('0x22')]);}_0x124d9a[_0xe4d7('0x79')]=qs[_0xe4d7('0x41')](_0x5e6265[_0xe4d7('0x3a')]['sort']);_0x124d9a[_0xe4d7('0x42')]=qs[_0xe4d7('0x3b')](_['pick'](_0x5e6265[_0xe4d7('0x3a')],_0x5dfbe5['filters']));_0x124d9a[_0xe4d7('0x42')]['ContactId']=_0x4bedd6['id'];if(_0x5e6265[_0xe4d7('0x3a')][_0xe4d7('0x61')]){_0x124d9a[_0xe4d7('0x42')]=_['merge'](_0x124d9a[_0xe4d7('0x42')],{'$or':_[_0xe4d7('0x60')](_0x124d9a['attributes'],function(_0x8b9e84){var _0x3f662c={};_0x3f662c[_0x8b9e84]={'$like':'%'+_0x5e6265['query'][_0xe4d7('0x61')]+'%'};return _0x3f662c;})});}_0x124d9a=_[_0xe4d7('0x91')]({},_0x124d9a,_0x5e6265[_0xe4d7('0xbe')]);return db['CmHopper'][_0xe4d7('0x21')]({'where':_0x124d9a[_0xe4d7('0x42')]})[_0xe4d7('0x2a')](function(_0x2b8c2e){_0x274c6[_0xe4d7('0x21')]=_0x2b8c2e;if(_0x5e6265[_0xe4d7('0x3a')]['includeAll']){_0x124d9a['include']=[{'all':!![]}];}return db['CmHopper'][_0xe4d7('0x8d')](_0x124d9a);})[_0xe4d7('0x2a')](function(_0x54e407){_0x274c6[_0xe4d7('0xc1')]=_0x54e407;return _0x274c6;});}})[_0xe4d7('0x2a')](respondWithFilteredResult(_0x2ec313,_0x124d9a))[_0xe4d7('0x88')](handleError(_0x2ec313,null));};exports['getHopperHistories']=function(_0x43d881,_0x107edb,_0x365544){var _0x3ae74f={'raw':!![],'where':{}};var _0x5ed927={};var _0x3b40cd={'count':0x0,'rows':[]};return db[_0xe4d7('0x30')][_0xe4d7('0x36')]({'where':{'id':_0x43d881[_0xe4d7('0x8a')]['id']}})[_0xe4d7('0x2a')](handleEntityNotFound(_0x107edb,null))['then'](function(_0x331c89){if(_0x331c89){_0x5ed927['model']=_['keys'](db[_0xe4d7('0xa5')]['rawAttributes']);_0x5ed927['query']=_[_0xe4d7('0x31')](_0x43d881['query']);_0x5ed927[_0xe4d7('0x3b')]=_['intersection'](_0x5ed927['model'],_0x5ed927[_0xe4d7('0x3a')]);_0x3ae74f[_0xe4d7('0x3d')]=_[_0xe4d7('0x3c')](_0x5ed927['model'],qs['fields'](_0x43d881[_0xe4d7('0x3a')][_0xe4d7('0x3e')]));_0x3ae74f[_0xe4d7('0x3d')]=_0x3ae74f['attributes']['length']?_0x3ae74f[_0xe4d7('0x3d')]:_0x5ed927[_0xe4d7('0x39')];if(!_0x43d881[_0xe4d7('0x3a')]['hasOwnProperty']('nolimit')){_0x3ae74f[_0xe4d7('0x23')]=qs['limit'](_0x43d881[_0xe4d7('0x3a')][_0xe4d7('0x23')]);_0x3ae74f[_0xe4d7('0x22')]=qs['offset'](_0x43d881['query'][_0xe4d7('0x22')]);}_0x3ae74f['order']=qs[_0xe4d7('0x41')](_0x43d881[_0xe4d7('0x3a')][_0xe4d7('0x41')]);_0x3ae74f['where']=qs[_0xe4d7('0x3b')](_['pick'](_0x43d881[_0xe4d7('0x3a')],_0x5ed927['filters']));_0x3ae74f[_0xe4d7('0x42')]['ContactId']=_0x331c89['id'];if(_0x43d881[_0xe4d7('0x3a')]['filter']){_0x3ae74f[_0xe4d7('0x42')]=_['merge'](_0x3ae74f[_0xe4d7('0x42')],{'$or':_['map'](_0x3ae74f['attributes'],function(_0xcf2083){var _0x5d9003={};_0x5d9003[_0xcf2083]={'$like':'%'+_0x43d881['query'][_0xe4d7('0x61')]+'%'};return _0x5d9003;})});}_0x3ae74f=_[_0xe4d7('0x91')]({},_0x3ae74f,_0x43d881['options']);return db[_0xe4d7('0xa5')][_0xe4d7('0x21')]({'where':_0x3ae74f[_0xe4d7('0x42')]})[_0xe4d7('0x2a')](function(_0x45dede){_0x3b40cd[_0xe4d7('0x21')]=_0x45dede;if(_0x43d881[_0xe4d7('0x3a')][_0xe4d7('0xc2')]){_0x3ae74f[_0xe4d7('0xc3')]=[{'all':!![]}];}return db[_0xe4d7('0xa5')]['findAll'](_0x3ae74f);})['then'](function(_0xad08ed){_0x3b40cd[_0xe4d7('0xc1')]=_0xad08ed;return _0x3b40cd;});}})['then'](respondWithFilteredResult(_0x107edb,_0x3ae74f))[_0xe4d7('0x88')](handleError(_0x107edb,null));};exports['getHopperFinals']=function(_0x1f78ea,_0x33b09e,_0x46295c){var _0x408a31={'raw':!![],'where':{}};var _0x632dae={};var _0x442551={'count':0x0,'rows':[]};return db[_0xe4d7('0x30')][_0xe4d7('0x36')]({'where':{'id':_0x1f78ea['params']['id']}})[_0xe4d7('0x2a')](handleEntityNotFound(_0x33b09e,null))[_0xe4d7('0x2a')](function(_0x3e0ac1){if(_0x3e0ac1){_0x632dae[_0xe4d7('0x39')]=_[_0xe4d7('0x31')](db[_0xe4d7('0xa4')][_0xe4d7('0xbc')]);_0x632dae[_0xe4d7('0x3a')]=_[_0xe4d7('0x31')](_0x1f78ea[_0xe4d7('0x3a')]);_0x632dae['filters']=_[_0xe4d7('0x3c')](_0x632dae[_0xe4d7('0x39')],_0x632dae[_0xe4d7('0x3a')]);_0x408a31[_0xe4d7('0x3d')]=_[_0xe4d7('0x3c')](_0x632dae[_0xe4d7('0x39')],qs['fields'](_0x1f78ea[_0xe4d7('0x3a')][_0xe4d7('0x3e')]));_0x408a31['attributes']=_0x408a31[_0xe4d7('0x3d')][_0xe4d7('0x37')]?_0x408a31[_0xe4d7('0x3d')]:_0x632dae[_0xe4d7('0x39')];if(!_0x1f78ea[_0xe4d7('0x3a')][_0xe4d7('0x3f')](_0xe4d7('0x40'))){_0x408a31[_0xe4d7('0x23')]=qs[_0xe4d7('0x23')](_0x1f78ea['query']['limit']);_0x408a31['offset']=qs[_0xe4d7('0x22')](_0x1f78ea[_0xe4d7('0x3a')][_0xe4d7('0x22')]);}_0x408a31['order']=qs[_0xe4d7('0x41')](_0x1f78ea[_0xe4d7('0x3a')][_0xe4d7('0x41')]);_0x408a31['where']=qs[_0xe4d7('0x3b')](_[_0xe4d7('0xbd')](_0x1f78ea['query'],_0x632dae['filters']));_0x408a31[_0xe4d7('0x42')][_0xe4d7('0xc4')]=_0x3e0ac1['id'];if(_0x1f78ea[_0xe4d7('0x3a')][_0xe4d7('0x61')]){_0x408a31[_0xe4d7('0x42')]=_['merge'](_0x408a31[_0xe4d7('0x42')],{'$or':_[_0xe4d7('0x60')](_0x408a31[_0xe4d7('0x3d')],function(_0x375f37){var _0x2c0848={};_0x2c0848[_0x375f37]={'$like':'%'+_0x1f78ea[_0xe4d7('0x3a')][_0xe4d7('0x61')]+'%'};return _0x2c0848;})});}_0x408a31=_[_0xe4d7('0x91')]({},_0x408a31,_0x1f78ea[_0xe4d7('0xbe')]);return db[_0xe4d7('0xa4')][_0xe4d7('0x21')]({'where':_0x408a31[_0xe4d7('0x42')]})[_0xe4d7('0x2a')](function(_0x89f9e){_0x442551[_0xe4d7('0x21')]=_0x89f9e;if(_0x1f78ea['query'][_0xe4d7('0xc2')]){_0x408a31[_0xe4d7('0xc3')]=[{'all':!![]}];}return db[_0xe4d7('0xa4')]['findAll'](_0x408a31);})[_0xe4d7('0x2a')](function(_0x5b5a74){_0x442551[_0xe4d7('0xc1')]=_0x5b5a74;return _0x442551;});}})[_0xe4d7('0x2a')](respondWithFilteredResult(_0x33b09e,_0x408a31))[_0xe4d7('0x88')](handleError(_0x33b09e,null));};exports[_0xe4d7('0xc5')]=function(_0x2872d5,_0x1b903e,_0x4986cb){var _0x218bc1={'raw':!![],'where':{}};var _0x4194e1={};var _0x1e55fd={'count':0x0,'rows':[]};return db[_0xe4d7('0x30')][_0xe4d7('0x36')]({'where':{'id':_0x2872d5[_0xe4d7('0x8a')]['id']}})[_0xe4d7('0x2a')](handleEntityNotFound(_0x1b903e,null))[_0xe4d7('0x2a')](function(_0x3eea77){if(_0x3eea77){_0x4194e1[_0xe4d7('0x39')]=_['keys'](db[_0xe4d7('0xc6')]['rawAttributes']);_0x4194e1[_0xe4d7('0x3a')]=_[_0xe4d7('0x31')](_0x2872d5[_0xe4d7('0x3a')]);_0x4194e1[_0xe4d7('0x3b')]=_[_0xe4d7('0x3c')](_0x4194e1[_0xe4d7('0x39')],_0x4194e1[_0xe4d7('0x3a')]);_0x218bc1[_0xe4d7('0x3d')]=_[_0xe4d7('0x3c')](_0x4194e1[_0xe4d7('0x39')],qs[_0xe4d7('0x3e')](_0x2872d5[_0xe4d7('0x3a')][_0xe4d7('0x3e')]));_0x218bc1[_0xe4d7('0x3d')]=_0x218bc1[_0xe4d7('0x3d')][_0xe4d7('0x37')]?_0x218bc1[_0xe4d7('0x3d')]:_0x4194e1[_0xe4d7('0x39')];if(!_0x2872d5[_0xe4d7('0x3a')][_0xe4d7('0x3f')](_0xe4d7('0x40'))){_0x218bc1[_0xe4d7('0x23')]=qs[_0xe4d7('0x23')](_0x2872d5['query'][_0xe4d7('0x23')]);_0x218bc1[_0xe4d7('0x22')]=qs[_0xe4d7('0x22')](_0x2872d5['query'][_0xe4d7('0x22')]);}_0x218bc1[_0xe4d7('0x79')]=qs[_0xe4d7('0x41')](_0x2872d5['query'][_0xe4d7('0x41')]);_0x218bc1[_0xe4d7('0x42')]=qs[_0xe4d7('0x3b')](_['pick'](_0x2872d5['query'],_0x4194e1[_0xe4d7('0x3b')]));_0x218bc1[_0xe4d7('0x42')][_0xe4d7('0xc4')]=_0x3eea77['id'];if(_0x2872d5[_0xe4d7('0x3a')][_0xe4d7('0x61')]){_0x218bc1[_0xe4d7('0x42')]=_['merge'](_0x218bc1[_0xe4d7('0x42')],{'$or':_['map'](_0x218bc1[_0xe4d7('0x3d')],function(_0x23903c){var _0x30142d={};_0x30142d[_0x23903c]={'$like':'%'+_0x2872d5[_0xe4d7('0x3a')][_0xe4d7('0x61')]+'%'};return _0x30142d;})});}_0x218bc1=_[_0xe4d7('0x91')]({},_0x218bc1,_0x2872d5[_0xe4d7('0xbe')]);return db[_0xe4d7('0xc6')][_0xe4d7('0x21')]({'where':_0x218bc1[_0xe4d7('0x42')]})[_0xe4d7('0x2a')](function(_0x350b39){_0x1e55fd[_0xe4d7('0x21')]=_0x350b39;if(_0x2872d5['query'][_0xe4d7('0xc2')]){_0x218bc1[_0xe4d7('0xc3')]=[{'all':!![]}];}return db['JscriptySessionReport']['findAll'](_0x218bc1);})[_0xe4d7('0x2a')](function(_0x536083){_0x1e55fd['rows']=_0x536083;return _0x1e55fd;});}})[_0xe4d7('0x2a')](respondWithFilteredResult(_0x1b903e,_0x218bc1))[_0xe4d7('0x88')](handleError(_0x1b903e,null));};exports[_0xe4d7('0xc7')]=function(_0x6151b5,_0x1ca435,_0xb6a941){try{if(!_0x6151b5['body']['ListId']){throw new Error('No\x20ListId\x20specified');}if(!_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0xc8')]){throw new Error(_0xe4d7('0xc9'));}if(!_0x6151b5['body'][_0xe4d7('0xca')]){throw new Error('No\x20association\x20values\x20specified!');}if(!_0x6151b5[_0xe4d7('0x92')]['socket_timestamp']){throw new Error(_0xe4d7('0xcb'));}var _0x171142=_0x6151b5['body']['binding_keys'][_0xe4d7('0x6b')](',');var _0x4777d0=_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0xca')]['split'](',');if(!_0x171142['length']||!_0x4777d0[_0xe4d7('0x37')]||_0x171142[_0xe4d7('0x37')]!==_0x4777d0[_0xe4d7('0x37')]){throw new Error(_0xe4d7('0xcc'));}_0x6151b5['body'][_0xe4d7('0x3e')]=_[_0xe4d7('0xcd')](_0x171142,_0x4777d0);if(!_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0x3e')][_0xe4d7('0xba')]){throw new Error(_0xe4d7('0xce'));}if(!_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0x3e')][_0xe4d7('0xcf')]){throw new Error(_0xe4d7('0xd0'));}var _0x3a9553=path['join'](config[_0xe4d7('0xd1')],'server/files/tmp',_0x6151b5['file']['filename']);fs[_0xe4d7('0xd2')](_0x3a9553,parseInt('0777',0x8));var _0x38d785=require(_0xe4d7('0xd3'))['fork'](path[_0xe4d7('0x95')](__dirname,_0xe4d7('0xd4')),[_0x3a9553,_0x6151b5[_0xe4d7('0x92')]['binding_keys'],_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0xca')],_0x6151b5['body'][_0xe4d7('0x64')],_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0xd5')],_0x6151b5[_0xe4d7('0x92')][_0xe4d7('0xab')],_0x6151b5[_0xe4d7('0x92')]['socket_timestamp']]);return _0x1ca435['status'](0xc8)[_0xe4d7('0x20')]({'message':_0xe4d7('0xd6'),'pid':_0x38d785[_0xe4d7('0xd7')]});}catch(_0x40db56){return _0x1ca435[_0xe4d7('0x1e')](0x1f4)[_0xe4d7('0xd8')](_0x40db56);}};exports[_0xe4d7('0xd9')]=function(_0x8dcb87,_0x57dee9,_0x39b4f5){var _0xaa7e21=fs[_0xe4d7('0xda')](_0x8dcb87[_0xe4d7('0xdb')]['path']);Papa[_0xe4d7('0xdc')](_0xaa7e21,{'header':!![],'skipEmptyLines':!![],'preview':0x1,'complete':function(_0x5469a0){return _0x57dee9[_0xe4d7('0x1e')](0xc8)[_0xe4d7('0x20')]({'file':_0x8dcb87[_0xe4d7('0xdb')],'fields':_0x5469a0['meta']['fields']});}});};exports['import']=function(_0xf362b2,_0x140249,_0x594fec){return db[_0xe4d7('0x57')][_0xe4d7('0x8d')]({'raw':!![],'attributes':['id'],'where':{'role':_0xe4d7('0xdd')}})['then'](function(_0x1a634c){var _0x1057a8=![];if(!_0xf362b2['body'][_0xe4d7('0x64')]){throw new Error('No\x20ListId\x20specified');}if(!_0xf362b2[_0xe4d7('0x92')][_0xe4d7('0xde')]['phone']){throw new Error(_0xe4d7('0xce'));}if(!_0xf362b2[_0xe4d7('0x92')][_0xe4d7('0xde')][_0xe4d7('0xcf')]){throw new Error(_0xe4d7('0xd0'));}if(!_0xf362b2[_0xe4d7('0x92')][_0xe4d7('0xdf')]){throw new Error('Unable\x20to\x20synchronize\x20socket,\x20no\x20timestamp\x20passed');}var _0x2b8081=require(_0xe4d7('0xd3'))[_0xe4d7('0xe0')](path[_0xe4d7('0x95')](__dirname,_0xe4d7('0xe1')),[_0xf362b2[_0xe4d7('0x8a')]['id'],JSON[_0xe4d7('0xe2')](_0xf362b2[_0xe4d7('0x92')]),JSON[_0xe4d7('0xe2')](_0x1a634c)]);_0x2b8081['on'](_0xe4d7('0xe3'),function(_0x3118f6){_0x1057a8=!![];return _0x140249[_0xe4d7('0x1e')](0xc8)[_0xe4d7('0x20')]({'message':_0xe4d7('0xe4'),'pid':_0x2b8081[_0xe4d7('0xd7')]});});_0x2b8081['on'](_0xe4d7('0xe5'),function(_0x5a4a8d){if(_0x5a4a8d&&!_0x1057a8){return _0x140249[_0xe4d7('0x1e')](0x1f4)[_0xe4d7('0x20')]({'message':_0xe4d7('0xe6'),'pid':_0x2b8081[_0xe4d7('0xd7')]});}});})[_0xe4d7('0x88')](handleError(_0x140249,null));};