18 var _0x8975=['send','index','map','CmList','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','order','sort','pick','filter','where','VIRTUAL','merge','options','include','findAll','rows','catch','show','params','includeAll','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','addDisposition','ListId','getDispositions','findOne','nolimit','Disposition','removeDispositions','ids','addContacts','CmContact','tags','isArray','join','push','each','success','dataValues','errors','message','CmCustomField','CustomFields','concat','format','cf_%d','getContacts','getContactsCsv','ContactItemType','select','cm_contacts','c.ListId\x20=\x20?','c.deletedAt\x20is\x20null','distinct','field','c.cf_','customField_','alias','item','from','cm_contact_has_items','ItemTypeId\x20=\x20?','CmContactId\x20=\x20c.id','additionalPhone_','description_additionalPhone_','toString','isEmpty','writeFileSync','/tmp/list_%d_%s.csv','setHeader','list_%d_%s.csv','Content-type','text/csv','addCustomField','transaction','addCustomFields','Sequelize','TEXT','text','number','INTEGER','switch','BOOLEAN','defaultValue','sequelize','queryInterface','addColumn','cf_%s','getCustomFields','findAndCountAll','getGlobalCustomFields','addAgents','omit','spread','emit','userCmList:save','removeAgents','userCmList:remove','getAgents','User','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','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/utils','../../config/environment','redis','defaults','socket.io-emitter','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','save','then','destroy','get','Lists','UserProfileResource','sendStatus','error','stack','name'];(function(_0x4713a5,_0x5ec6f2){var _0x566e68=function(_0x38f47d){while(--_0x38f47d){_0x4713a5['push'](_0x4713a5['shift']());}};_0x566e68(++_0x5ec6f2);}(_0x8975,0x7a));var _0x5897=function(_0x178e48,_0x3c9509){_0x178e48=_0x178e48-0x0;var _0x440d7e=_0x8975[_0x178e48];return _0x440d7e;};'use strict';var emlformat=require(_0x5897('0x0'));var rimraf=require(_0x5897('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5897('0x2'));var rp=require(_0x5897('0x3'));var moment=require('moment');var BPromise=require(_0x5897('0x4'));var Mustache=require(_0x5897('0x5'));var util=require(_0x5897('0x6'));var path=require('path');var sox=require(_0x5897('0x7'));var csv=require(_0x5897('0x8'));var ejs=require(_0x5897('0x9'));var fs=require('fs');var fs_extra=require(_0x5897('0xa'));var _=require(_0x5897('0xb'));var squel=require(_0x5897('0xc'));var crypto=require(_0x5897('0xd'));var jsforce=require(_0x5897('0xe'));var deskjs=require(_0x5897('0xf'));var toCsv=require(_0x5897('0x8'));var querystring=require(_0x5897('0x10'));var Papa=require(_0x5897('0x11'));var Redis=require(_0x5897('0x12'));var authService=require(_0x5897('0x13'));var qs=require(_0x5897('0x14'));var as=require(_0x5897('0x15'));var hardwareService=require(_0x5897('0x16'));var logger=require(_0x5897('0x17'))(_0x5897('0x18'));var utils=require(_0x5897('0x19'));var config=require(_0x5897('0x1a'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var csv_results;config[_0x5897('0x1b')]=_[_0x5897('0x1c')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x5897('0x1d'))(new Redis(config['redis']));require('./cmList.socket')['register'](socket);function respondWithStatusCode(_0x2fd2c0,_0x106b80){_0x106b80=_0x106b80||0xcc;return function(_0x599fc8){if(_0x599fc8){return _0x2fd2c0['sendStatus'](_0x106b80);}return _0x2fd2c0[_0x5897('0x1e')](_0x106b80)[_0x5897('0x1f')]();};}function respondWithResult(_0xd3c90f,_0x5acfa7){_0x5acfa7=_0x5acfa7||0xc8;return function(_0x1a1438){if(_0x1a1438){return _0xd3c90f[_0x5897('0x1e')](_0x5acfa7)[_0x5897('0x20')](_0x1a1438);}};}function respondWithFilteredResult(_0x2913bb,_0x16c7c2){return function(_0x12bba6){if(_0x12bba6){var _0x1ef191=typeof _0x16c7c2[_0x5897('0x21')]===_0x5897('0x22')&&typeof _0x16c7c2['limit']==='undefined';var _0x8b31ae=_0x12bba6[_0x5897('0x23')];var _0x5db6f6=_0x1ef191?0x0:_0x16c7c2[_0x5897('0x21')];var _0x218942=_0x1ef191?_0x12bba6[_0x5897('0x23')]:_0x16c7c2[_0x5897('0x21')]+_0x16c7c2[_0x5897('0x24')];var _0x501b82;if(_0x218942>=_0x8b31ae){_0x218942=_0x8b31ae;_0x501b82=0xc8;}else{_0x501b82=0xce;}_0x2913bb[_0x5897('0x1e')](_0x501b82);return _0x2913bb['set'](_0x5897('0x25'),_0x5db6f6+'-'+_0x218942+'/'+_0x8b31ae)['json'](_0x12bba6);}return null;};}function patchUpdates(_0x807e41){return function(_0x4e11c9){try{jsonpatch[_0x5897('0x26')](_0x4e11c9,_0x807e41,!![]);}catch(_0x5727d7){return BPromise[_0x5897('0x27')](_0x5727d7);}return _0x4e11c9[_0x5897('0x28')]();};}function saveUpdates(_0x236579,_0x2d62f8){return function(_0x224a83){if(_0x224a83){return _0x224a83['update'](_0x236579)[_0x5897('0x29')](function(_0x33206b){return _0x33206b;});}return null;};}function removeEntity(_0xad136d,_0x124e59){return function(_0x3389cb){if(_0x3389cb){return _0x3389cb[_0x5897('0x2a')]()[_0x5897('0x29')](function(){var _0x4bde65=_0x3389cb[_0x5897('0x2b')]({'plain':!![]});var _0x5ba48d=_0x5897('0x2c');return db[_0x5897('0x2d')][_0x5897('0x2a')]({'where':{'type':_0x5ba48d,'resourceId':_0x4bde65['id']}})[_0x5897('0x29')](function(){return _0x3389cb;});})[_0x5897('0x29')](function(){_0xad136d[_0x5897('0x1e')](0xcc)[_0x5897('0x1f')]();});}};}function handleEntityNotFound(_0x39b9ea,_0x11dc6d){return function(_0x1f0aac){if(!_0x1f0aac){_0x39b9ea[_0x5897('0x2e')](0x194);}return _0x1f0aac;};}function handleError(_0x29ea60,_0x25d1a3){_0x25d1a3=_0x25d1a3||0x1f4;return function(_0x411ffd){logger[_0x5897('0x2f')](_0x411ffd[_0x5897('0x30')]);if(_0x411ffd[_0x5897('0x31')]){delete _0x411ffd['name'];}_0x29ea60['status'](_0x25d1a3)[_0x5897('0x32')](_0x411ffd);};}exports[_0x5897('0x33')]=function(_0x5b08ee,_0x4e346b){var _0x12536c={},_0x1e0ef9={},_0x224dcd={'count':0x0,'rows':[]};var _0x394bdc=_[_0x5897('0x34')](db[_0x5897('0x35')][_0x5897('0x36')],function(_0x11f1a3){return{'name':_0x11f1a3[_0x5897('0x37')],'type':_0x11f1a3[_0x5897('0x38')][_0x5897('0x39')]};});_0x1e0ef9[_0x5897('0x3a')]=_[_0x5897('0x34')](_0x394bdc,_0x5897('0x31'));_0x1e0ef9[_0x5897('0x3b')]=_[_0x5897('0x3c')](_0x5b08ee['query']);_0x1e0ef9[_0x5897('0x3d')]=_['intersection'](_0x1e0ef9[_0x5897('0x3a')],_0x1e0ef9[_0x5897('0x3b')]);_0x12536c[_0x5897('0x3e')]=_[_0x5897('0x3f')](_0x1e0ef9['model'],qs[_0x5897('0x40')](_0x5b08ee[_0x5897('0x3b')][_0x5897('0x40')]));_0x12536c['attributes']=_0x12536c['attributes'][_0x5897('0x41')]?_0x12536c[_0x5897('0x3e')]:_0x1e0ef9['model'];if(!_0x5b08ee[_0x5897('0x3b')][_0x5897('0x42')]('nolimit')){_0x12536c[_0x5897('0x24')]=qs[_0x5897('0x24')](_0x5b08ee['query'][_0x5897('0x24')]);_0x12536c[_0x5897('0x21')]=qs[_0x5897('0x21')](_0x5b08ee[_0x5897('0x3b')][_0x5897('0x21')]);}_0x12536c[_0x5897('0x43')]=qs[_0x5897('0x44')](_0x5b08ee[_0x5897('0x3b')][_0x5897('0x44')]);_0x12536c['where']=qs[_0x5897('0x3d')](_[_0x5897('0x45')](_0x5b08ee['query'],_0x1e0ef9[_0x5897('0x3d')]),_0x394bdc);if(_0x5b08ee[_0x5897('0x3b')][_0x5897('0x46')]){_0x12536c[_0x5897('0x47')]=_['merge'](_0x12536c[_0x5897('0x47')],{'$or':_['map'](_0x394bdc,function(_0x11dd81){if(_0x11dd81[_0x5897('0x38')]!==_0x5897('0x48')){var _0x1e9e09={};_0x1e9e09[_0x11dd81['name']]={'$like':'%'+_0x5b08ee[_0x5897('0x3b')][_0x5897('0x46')]+'%'};return _0x1e9e09;}})});}_0x12536c=_[_0x5897('0x49')]({},_0x12536c,_0x5b08ee[_0x5897('0x4a')]);var _0x5b01f4={'where':_0x12536c['where']};return db[_0x5897('0x35')][_0x5897('0x23')](_0x5b01f4)['then'](function(_0x1eebf2){_0x224dcd[_0x5897('0x23')]=_0x1eebf2;if(_0x5b08ee[_0x5897('0x3b')]['includeAll']){_0x12536c[_0x5897('0x4b')]=[{'all':!![]}];}return db['CmList'][_0x5897('0x4c')](_0x12536c);})[_0x5897('0x29')](function(_0x23dc82){_0x224dcd[_0x5897('0x4d')]=_0x23dc82;return _0x224dcd;})[_0x5897('0x29')](respondWithFilteredResult(_0x4e346b,_0x12536c))[_0x5897('0x4e')](handleError(_0x4e346b,null));};exports[_0x5897('0x4f')]=function(_0x2f57ac,_0x150b0d){var _0xa97a35={'raw':![],'where':{'id':_0x2f57ac[_0x5897('0x50')]['id']}},_0xeb9c73={};_0xeb9c73[_0x5897('0x3a')]=_[_0x5897('0x3c')](db[_0x5897('0x35')][_0x5897('0x36')]);_0xeb9c73[_0x5897('0x3b')]=_[_0x5897('0x3c')](_0x2f57ac[_0x5897('0x3b')]);_0xeb9c73[_0x5897('0x3d')]=_['intersection'](_0xeb9c73[_0x5897('0x3a')],_0xeb9c73[_0x5897('0x3b')]);_0xa97a35[_0x5897('0x3e')]=_[_0x5897('0x3f')](_0xeb9c73['model'],qs[_0x5897('0x40')](_0x2f57ac['query'][_0x5897('0x40')]));_0xa97a35['attributes']=_0xa97a35[_0x5897('0x3e')][_0x5897('0x41')]?_0xa97a35['attributes']:_0xeb9c73['model'];if(_0x2f57ac['query'][_0x5897('0x51')]){_0xa97a35[_0x5897('0x4b')]=[{'all':!![]}];}_0xa97a35=_[_0x5897('0x49')]({},_0xa97a35,_0x2f57ac[_0x5897('0x4a')]);return db[_0x5897('0x35')]['find'](_0xa97a35)['then'](handleEntityNotFound(_0x150b0d,null))[_0x5897('0x29')](respondWithResult(_0x150b0d,null))[_0x5897('0x4e')](handleError(_0x150b0d,null));};exports[_0x5897('0x52')]=function(_0x373ebc,_0x1c5738){return db['CmList']['create'](_0x373ebc[_0x5897('0x53')],{})[_0x5897('0x29')](function(_0x47cfac){var _0x58f16b=_0x373ebc[_0x5897('0x54')][_0x5897('0x2b')]({'plain':!![]});if(!_0x58f16b)throw new Error(_0x5897('0x55'));if(_0x58f16b[_0x5897('0x56')]===_0x5897('0x54')){var _0x3b49cf=_0x47cfac[_0x5897('0x2b')]({'plain':!![]});var _0x51c86b=_0x5897('0x2c');return db[_0x5897('0x57')][_0x5897('0x58')]({'where':{'name':_0x51c86b,'userProfileId':_0x58f16b[_0x5897('0x59')]},'raw':!![]})[_0x5897('0x29')](function(_0x28e4ef){if(_0x28e4ef&&_0x28e4ef[_0x5897('0x5a')]===0x0){return db[_0x5897('0x2d')][_0x5897('0x52')]({'name':_0x3b49cf['name'],'resourceId':_0x3b49cf['id'],'type':_0x28e4ef[_0x5897('0x31')],'sectionId':_0x28e4ef['id']},{})['then'](function(){return _0x47cfac;});}else{return _0x47cfac;}})[_0x5897('0x4e')](function(_0x50a24d){logger[_0x5897('0x2f')](_0x5897('0x5b'),_0x50a24d);throw _0x50a24d;});}return _0x47cfac;})[_0x5897('0x29')](respondWithResult(_0x1c5738,0xc9))[_0x5897('0x4e')](handleError(_0x1c5738,null));};exports[_0x5897('0x5c')]=function(_0xc5eb1b,_0x34a3e0){if(_0xc5eb1b[_0x5897('0x53')]['id']){delete _0xc5eb1b[_0x5897('0x53')]['id'];}return db[_0x5897('0x35')][_0x5897('0x58')]({'where':{'id':_0xc5eb1b[_0x5897('0x50')]['id']}})['then'](handleEntityNotFound(_0x34a3e0,null))[_0x5897('0x29')](saveUpdates(_0xc5eb1b[_0x5897('0x53')],null))[_0x5897('0x29')](respondWithResult(_0x34a3e0,null))['catch'](handleError(_0x34a3e0,null));};exports[_0x5897('0x2a')]=function(_0x32e649,_0x34e70b){return db[_0x5897('0x35')][_0x5897('0x58')]({'where':{'id':_0x32e649[_0x5897('0x50')]['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x34e70b,null))[_0x5897('0x29')](removeEntity(_0x34e70b,null))['catch'](handleError(_0x34e70b,null));};exports[_0x5897('0x5d')]=function(_0x5b0e5a,_0x2369c2){return db[_0x5897('0x35')][_0x5897('0x5d')]()[_0x5897('0x29')](respondWithResult(_0x2369c2,null))[_0x5897('0x4e')](handleError(_0x2369c2,null));};exports[_0x5897('0x5e')]=function(_0x1fb268,_0x135ad7,_0x566723){if(_0x1fb268['body']['id']){delete _0x1fb268[_0x5897('0x53')]['id'];}return db[_0x5897('0x35')]['find']({'where':{'id':_0x1fb268['params']['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x135ad7,null))['then'](function(_0x27a061){if(_0x27a061){_0x1fb268[_0x5897('0x53')][_0x5897('0x5f')]=_0x27a061['id'];return db['Disposition'][_0x5897('0x52')](_0x1fb268[_0x5897('0x53')]);}})['then'](respondWithResult(_0x135ad7,null))[_0x5897('0x4e')](handleError(_0x135ad7,null));};exports[_0x5897('0x60')]=function(_0x5e75dd,_0x3a00d7,_0xd1dba1){var _0x1f276c={'raw':![],'where':{}};var _0x2bc190={};var _0x2c0df3={'count':0x0,'rows':[]};return db[_0x5897('0x35')][_0x5897('0x61')]({'where':{'id':_0x5e75dd[_0x5897('0x50')]['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x3a00d7,null))[_0x5897('0x29')](function(_0x25acb5){if(_0x25acb5){_0x2bc190[_0x5897('0x3a')]=_[_0x5897('0x3c')](db['Disposition'][_0x5897('0x36')]);_0x2bc190[_0x5897('0x3b')]=_[_0x5897('0x3c')](_0x5e75dd['query']);_0x2bc190[_0x5897('0x3d')]=_[_0x5897('0x3f')](_0x2bc190['model'],_0x2bc190[_0x5897('0x3b')]);_0x1f276c[_0x5897('0x3e')]=_[_0x5897('0x3f')](_0x2bc190[_0x5897('0x3a')],qs[_0x5897('0x40')](_0x5e75dd['query'][_0x5897('0x40')]));_0x1f276c['attributes']=_0x1f276c['attributes']['length']?_0x1f276c['attributes']:_0x2bc190[_0x5897('0x3a')];if(!_0x5e75dd[_0x5897('0x3b')]['hasOwnProperty'](_0x5897('0x62'))){_0x1f276c[_0x5897('0x24')]=qs[_0x5897('0x24')](_0x5e75dd[_0x5897('0x3b')][_0x5897('0x24')]);_0x1f276c[_0x5897('0x21')]=qs[_0x5897('0x21')](_0x5e75dd[_0x5897('0x3b')][_0x5897('0x21')]);}_0x1f276c[_0x5897('0x43')]=qs[_0x5897('0x44')](_0x5e75dd[_0x5897('0x3b')][_0x5897('0x44')]);_0x1f276c[_0x5897('0x47')]=qs[_0x5897('0x3d')](_['pick'](_0x5e75dd[_0x5897('0x3b')],_0x2bc190[_0x5897('0x3d')]));_0x1f276c[_0x5897('0x47')][_0x5897('0x5f')]=_0x25acb5['id'];if(_0x5e75dd[_0x5897('0x3b')][_0x5897('0x46')]){_0x1f276c[_0x5897('0x47')]=_[_0x5897('0x49')](_0x1f276c[_0x5897('0x47')],{'$or':_[_0x5897('0x34')](_0x1f276c[_0x5897('0x3e')],function(_0x2dd2f0){var _0x3227fb={};_0x3227fb[_0x2dd2f0]={'$like':'%'+_0x5e75dd['query'][_0x5897('0x46')]+'%'};return _0x3227fb;})});}_0x1f276c=_['merge']({},_0x1f276c,_0x5e75dd[_0x5897('0x4a')]);return db[_0x5897('0x63')]['count']({'where':_0x1f276c[_0x5897('0x47')]})[_0x5897('0x29')](function(_0x3fd7da){_0x2c0df3['count']=_0x3fd7da;if(_0x5e75dd[_0x5897('0x3b')][_0x5897('0x51')]){_0x1f276c[_0x5897('0x4b')]=[{'all':!![]}];}return db[_0x5897('0x63')]['findAll'](_0x1f276c);})['then'](function(_0x16cf65){_0x2c0df3[_0x5897('0x4d')]=_0x16cf65;return _0x2c0df3;});}})[_0x5897('0x29')](respondWithFilteredResult(_0x3a00d7,_0x1f276c))[_0x5897('0x4e')](handleError(_0x3a00d7,null));};exports[_0x5897('0x64')]=function(_0x1e0b72,_0x14b2d7,_0x33e2bc){return db['CmList'][_0x5897('0x58')]({'where':{'id':_0x1e0b72[_0x5897('0x50')]['id']}})['then'](handleEntityNotFound(_0x14b2d7,null))[_0x5897('0x29')](function(_0xb3b22e){if(_0xb3b22e){return _0xb3b22e[_0x5897('0x64')](_0x1e0b72['query'][_0x5897('0x65')]);}})[_0x5897('0x29')](respondWithStatusCode(_0x14b2d7,null))[_0x5897('0x4e')](handleError(_0x14b2d7,null));};exports[_0x5897('0x66')]=function(_0x3d6f25,_0x2c1d7b,_0xa94447){return db[_0x5897('0x35')][_0x5897('0x58')]({'where':{'id':_0x3d6f25[_0x5897('0x50')]['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x2c1d7b,null))[_0x5897('0x29')](function(_0xe163b3){if(_0xe163b3){var _0x13db76=[];var _0xb6ef80={'success':[],'errors':[]};return db[_0x5897('0x67')]['describe']()[_0x5897('0x29')](function(_0x36924d){if(_0x3d6f25['body'][_0x5897('0x68')]&&_[_0x5897('0x69')](_0x3d6f25[_0x5897('0x53')][_0x5897('0x68')])){if(_0x3d6f25['body']['tags'][_0x5897('0x41')]){_0x3d6f25[_0x5897('0x53')][_0x5897('0x68')]=_0x3d6f25['body'][_0x5897('0x68')][_0x5897('0x6a')](';')+';';}else{_0x3d6f25[_0x5897('0x53')][_0x5897('0x68')]=null;}}else{_0x3d6f25[_0x5897('0x53')][_0x5897('0x68')]=null;}if(_0x3d6f25[_0x5897('0x53')]&&_[_0x5897('0x69')](_0x3d6f25[_0x5897('0x53')])){for(var _0x42a429=0x0;_0x42a429<_0x3d6f25[_0x5897('0x53')]['length'];_0x42a429+=0x1){_0x3d6f25[_0x5897('0x53')][_0x42a429]['ListId']=_0x3d6f25[_0x5897('0x50')]['id'];_0x13db76[_0x5897('0x6b')](_0x3d6f25['body'][_0x42a429]);}return BPromise[_0x5897('0x6c')](_0x13db76,function(_0x3f8139){return db[_0x5897('0x67')][_0x5897('0x52')](_['omit'](_0x3f8139,[_0x5897('0x65'),'id'])||{},{'fields':_['keys'](_0x36924d),'raw':!![]})[_0x5897('0x29')](function(_0x26456c){_0xb6ef80[_0x5897('0x6d')]['push'](_0x26456c[_0x5897('0x6e')]);})['catch'](function(_0x3f6789){_0xb6ef80[_0x5897('0x6f')][_0x5897('0x6b')]({'data':_0x3f8139,'error':_0x3f6789[_0x5897('0x70')]});});})[_0x5897('0x29')](function(_0x40452b){return _0xb6ef80;})[_0x5897('0x4e')](function(_0x5b4e7b){return _0x5b4e7b;});}else{_0x2c1d7b[_0x5897('0x1e')](0x190)[_0x5897('0x20')]({'message':'Malformed\x20request\x20syntax'});}});}})[_0x5897('0x29')](respondWithResult(_0x2c1d7b,null))[_0x5897('0x4e')](handleError(_0x2c1d7b,null));};exports['getContacts']=function(_0x29eee9,_0x229325,_0x1a28c4){var _0x5571cb;return db[_0x5897('0x35')]['find']({'where':{'id':_0x29eee9['params']['id']},'include':[{'model':db[_0x5897('0x71')],'as':_0x5897('0x72')}]})[_0x5897('0x29')](handleEntityNotFound(_0x229325,null))[_0x5897('0x29')](function(_0x264b9c){if(_0x264b9c){_0x5571cb=_0x264b9c;return db[_0x5897('0x67')][_0x5897('0x36')];}})[_0x5897('0x29')](function(_0x31ba7c){if(_0x31ba7c){var _0x24c57={};var _0x6f7de0={};_0x6f7de0[_0x5897('0x3a')]=_[_0x5897('0x73')](_['keys'](_0x31ba7c),_[_0x5897('0x34')](_0x5571cb['CustomFields'],function(_0x2e7a75){return util[_0x5897('0x74')](_0x5897('0x75'),_0x2e7a75['id']);}));_0x6f7de0[_0x5897('0x3b')]=_[_0x5897('0x3c')](_0x29eee9[_0x5897('0x3b')]);_0x6f7de0[_0x5897('0x3d')]=_[_0x5897('0x3f')](_0x6f7de0[_0x5897('0x3a')],_0x6f7de0[_0x5897('0x3b')]);_0x24c57['attributes']=_[_0x5897('0x3f')](_0x6f7de0[_0x5897('0x3a')],qs['fields'](_0x29eee9['query'][_0x5897('0x40')]));_0x24c57[_0x5897('0x3e')]=_0x24c57[_0x5897('0x3e')][_0x5897('0x41')]?_0x24c57[_0x5897('0x3e')]:_0x6f7de0[_0x5897('0x3a')];if(!_0x29eee9[_0x5897('0x3b')][_0x5897('0x42')]('nolimit')){_0x24c57[_0x5897('0x24')]=qs[_0x5897('0x24')](_0x29eee9[_0x5897('0x3b')][_0x5897('0x24')]);_0x24c57['offset']=qs[_0x5897('0x21')](_0x29eee9[_0x5897('0x3b')][_0x5897('0x21')]);}_0x24c57[_0x5897('0x43')]=qs['sort'](_0x29eee9['query'][_0x5897('0x44')]);_0x24c57[_0x5897('0x47')]=qs[_0x5897('0x3d')](_['pick'](_0x29eee9[_0x5897('0x3b')],_0x6f7de0[_0x5897('0x3d')]));_0x24c57['raw']=!![];if(_0x29eee9['query'][_0x5897('0x46')]){_0x24c57[_0x5897('0x47')]=_[_0x5897('0x49')](_0x24c57[_0x5897('0x47')],{'$or':_[_0x5897('0x34')](_0x24c57[_0x5897('0x3e')],function(_0x15162c){var _0x3fe1bc={};_0x3fe1bc[_0x15162c]={'$like':'%'+_0x29eee9[_0x5897('0x3b')][_0x5897('0x46')]+'%'};return _0x3fe1bc;})});}_0x24c57=_[_0x5897('0x49')]({},_0x24c57,_0x29eee9[_0x5897('0x4a')]);return _0x5571cb[_0x5897('0x76')](_0x24c57);}})[_0x5897('0x29')](respondWithResult(_0x229325,null))['catch'](handleError(_0x229325,null));};exports[_0x5897('0x77')]=function(_0x55347c,_0x3205d2,_0x2cf1ce){var _0x281cc0;var _0x2726fb;var _0x386cd6;var _0x2972dd=_0x55347c[_0x5897('0x50')]['id'];csv_results=[];return db[_0x5897('0x78')][_0x5897('0x4c')]({'attributes':['id',_0x5897('0x31')],'raw':!![],'order':['OrderBy']})[_0x5897('0x29')](function(_0x160f51){_0x281cc0=_0x160f51;var _0x58e0bd=_[_0x5897('0x3c')](db[_0x5897('0x67')]['rawAttributes']);return db[_0x5897('0x71')][_0x5897('0x4c')]({'raw':!![],'attributes':['id','alias']})[_0x5897('0x29')](function(_0x1153f8){_0x2726fb=_0x1153f8;var _0x5b66c7=squel[_0x5897('0x79')]()[_0x5897('0x40')](_0x58e0bd)['from'](_0x5897('0x7a'),'c')['where'](_0x5897('0x7b'),_0x2972dd)['where'](_0x5897('0x7c'))[_0x5897('0x7d')]();for(var _0x1f3fa1=0x0;_0x1f3fa1<_0x2726fb['length'];_0x1f3fa1++){_0x5b66c7[_0x5897('0x7e')](_0x5897('0x7f')+_0x2726fb[_0x1f3fa1]['id'],_0x5897('0x80')+_0x2726fb[_0x1f3fa1][_0x5897('0x81')]);}for(var _0x1f3fa1=0x0;_0x1f3fa1<_0x281cc0[_0x5897('0x41')];_0x1f3fa1++){_0x5b66c7[_0x5897('0x7e')](squel[_0x5897('0x79')]()[_0x5897('0x7e')](_0x5897('0x82'))[_0x5897('0x83')](_0x5897('0x84'))[_0x5897('0x47')](_0x5897('0x85'),_0x281cc0[_0x1f3fa1]['id'])[_0x5897('0x47')](_0x5897('0x86')),_0x5897('0x87')+_0x281cc0[_0x1f3fa1]['name']);_0x5b66c7[_0x5897('0x7e')](squel[_0x5897('0x79')]()[_0x5897('0x7e')]('description')[_0x5897('0x83')](_0x5897('0x84'))['where'](_0x5897('0x85'),_0x281cc0[_0x1f3fa1]['id'])[_0x5897('0x47')](_0x5897('0x86')),_0x5897('0x88')+_0x281cc0[_0x1f3fa1][_0x5897('0x31')]);}var _0x42e998=[];_0x42e998['push'](_0x5b66c7[_0x5897('0x89')]());BPromise[_0x5897('0x6c')](_0x42e998,handleQuery)[_0x5897('0x29')](function(_0x26c233){handleQuery(_0x5b66c7['toString']());var _0xf49e1b=csv_results[0x0];if(!_[_0x5897('0x8a')](_0xf49e1b)){var _0x1ad0e7=toCsv(_0xf49e1b);var _0x102d1f=Date['now']();fs[_0x5897('0x8b')](util[_0x5897('0x74')](_0x5897('0x8c'),_0x2972dd,_0x102d1f),_0x1ad0e7);_0x3205d2[_0x5897('0x8d')]('Content-disposition','attachment;\x20filename='+util[_0x5897('0x74')](_0x5897('0x8e'),_0x2972dd,_0x102d1f));_0x3205d2[_0x5897('0x8d')](_0x5897('0x8f'),_0x5897('0x90'));return _0x3205d2['download'](util['format'](_0x5897('0x8c'),_0x2972dd,_0x102d1f));}else{return _0x3205d2['sendStatus'](0xcc);}});});});};exports[_0x5897('0x91')]=function(_0x3e79a5,_0x55ae28,_0x721b06){var _0x51b932;delete _0x3e79a5[_0x5897('0x53')]['id'];return db[_0x5897('0x35')][_0x5897('0x61')]({'where':{'id':_0x3e79a5['params']['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x55ae28,null))[_0x5897('0x29')](function(_0x7f19fe){if(_0x7f19fe){return db['sequelize'][_0x5897('0x92')](function(_0x9bd47e){return db[_0x5897('0x71')][_0x5897('0x52')](_0x3e79a5[_0x5897('0x53')],{'transaction':_0x9bd47e})[_0x5897('0x29')](function(_0x234896){_0x51b932=_0x234896;return _0x7f19fe[_0x5897('0x93')](_0x234896,{'transaction':_0x9bd47e});})['then'](function(){var _0x268999={'type':db[_0x5897('0x94')][_0x5897('0x95')],'transaction':_0x9bd47e};switch(_0x3e79a5['body'][_0x5897('0x38')]){case _0x5897('0x96'):_0x268999[_0x5897('0x38')]=db[_0x5897('0x94')][_0x5897('0x95')];break;case _0x5897('0x97'):_0x268999[_0x5897('0x38')]=db['Sequelize'][_0x5897('0x98')];break;case _0x5897('0x99'):_0x268999[_0x5897('0x38')]=db['Sequelize'][_0x5897('0x9a')];_0x268999[_0x5897('0x9b')]=![];break;default:}return db[_0x5897('0x9c')][_0x5897('0x9d')][_0x5897('0x9e')](_0x5897('0x7a'),util['format'](_0x5897('0x9f'),_0x51b932['id']),_0x268999);})[_0x5897('0x29')](function(){return _0x51b932;});});}})[_0x5897('0x29')](respondWithResult(_0x55ae28,null))[_0x5897('0x4e')](handleError(_0x55ae28,null));};exports[_0x5897('0xa0')]=function(_0x4c6a89,_0x3fe6de,_0x35eeda){var _0x40279f={};var _0x7b3d9d={};var _0x20cb69;var _0x2c2f4d;return db[_0x5897('0x35')][_0x5897('0x61')]({'where':{'id':_0x4c6a89['params']['id']}})['then'](handleEntityNotFound(_0x3fe6de,null))['then'](function(_0x51d78b){if(_0x51d78b){_0x20cb69=_0x51d78b;_0x7b3d9d[_0x5897('0x3a')]=_['keys'](db[_0x5897('0x71')]['rawAttributes']);_0x7b3d9d['query']=_[_0x5897('0x3c')](_0x4c6a89[_0x5897('0x3b')]);_0x7b3d9d[_0x5897('0x3d')]=_[_0x5897('0x3f')](_0x7b3d9d[_0x5897('0x3a')],_0x7b3d9d[_0x5897('0x3b')]);_0x40279f[_0x5897('0x3e')]=_[_0x5897('0x3f')](_0x7b3d9d['model'],qs['fields'](_0x4c6a89[_0x5897('0x3b')]['fields']));_0x40279f[_0x5897('0x3e')]=_0x40279f[_0x5897('0x3e')][_0x5897('0x41')]?_0x40279f[_0x5897('0x3e')]:_0x7b3d9d[_0x5897('0x3a')];_0x40279f[_0x5897('0x43')]=qs[_0x5897('0x44')](_0x4c6a89[_0x5897('0x3b')][_0x5897('0x44')]);_0x40279f[_0x5897('0x47')]=qs[_0x5897('0x3d')](_[_0x5897('0x45')](_0x4c6a89['query'],_0x7b3d9d[_0x5897('0x3d')]));_0x40279f[_0x5897('0x47')]=_[_0x5897('0x49')](_0x40279f[_0x5897('0x47')],{'$or':[{'ListId':_0x51d78b['id']},{'ListId':null}]});if(_0x4c6a89['query'][_0x5897('0x46')]){_0x40279f['where']=_[_0x5897('0x49')](_0x40279f[_0x5897('0x47')],{'$or':_['map'](_0x40279f[_0x5897('0x3e')],function(_0x558e28){var _0x129be0={};_0x129be0[_0x558e28]={'$like':'%'+_0x4c6a89[_0x5897('0x3b')][_0x5897('0x46')]+'%'};return _0x129be0;})});}_0x40279f=_['merge']({},_0x40279f,_0x4c6a89[_0x5897('0x4a')]);return db[_0x5897('0x71')][_0x5897('0xa1')](_0x40279f);}})[_0x5897('0x29')](respondWithResult(_0x3fe6de,null))['catch'](handleError(_0x3fe6de,null));};exports[_0x5897('0xa2')]=function(_0x43137b,_0x473327){return db[_0x5897('0x71')][_0x5897('0xa1')]({'where':{'ListId':null}})[_0x5897('0x29')](handleEntityNotFound(_0x473327,null))[_0x5897('0x29')](function(_0x3f8353){return _0x3f8353;})[_0x5897('0x29')](respondWithResult(_0x473327,null))[_0x5897('0x4e')](handleError(_0x473327,null));};exports[_0x5897('0xa3')]=function(_0x167159,_0x5e6d51,_0x44fa12){return db[_0x5897('0x35')]['find']({'where':{'id':_0x167159[_0x5897('0x50')]['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x5e6d51,null))[_0x5897('0x29')](function(_0x35fd1b){if(_0x35fd1b){return _0x35fd1b[_0x5897('0xa3')](_0x167159[_0x5897('0x53')]['ids'],_[_0x5897('0xa4')](_0x167159[_0x5897('0x53')],[_0x5897('0x65'),'id'])||{})[_0x5897('0xa5')](function(_0x1cbb0b){for(var _0x2baa71=0x0;_0x2baa71<_0x167159[_0x5897('0x53')]['ids'][_0x5897('0x41')];_0x2baa71+=0x1){socket[_0x5897('0xa6')](_0x5897('0xa7'),{'UserId':Number(_0x167159[_0x5897('0x53')][_0x5897('0x65')][_0x2baa71]),'CmListId':Number(_0x167159[_0x5897('0x50')]['id'])});}return _0x1cbb0b;});}})[_0x5897('0x29')](respondWithResult(_0x5e6d51,null))[_0x5897('0x4e')](handleError(_0x5e6d51,null));};exports[_0x5897('0xa8')]=function(_0x4d8518,_0x10fe12,_0x7b6685){return db['CmList'][_0x5897('0x58')]({'where':{'id':_0x4d8518[_0x5897('0x50')]['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x10fe12,null))[_0x5897('0x29')](function(_0x262e2b){if(_0x262e2b){return _0x262e2b[_0x5897('0xa8')](_0x4d8518['query'][_0x5897('0x65')])[_0x5897('0x29')](function(){if(_[_0x5897('0x69')](_0x4d8518[_0x5897('0x3b')]['ids'])){for(var _0x591a97=0x0;_0x591a97<_0x4d8518[_0x5897('0x3b')]['ids']['length'];_0x591a97+=0x1){socket[_0x5897('0xa6')](_0x5897('0xa9'),{'UserId':Number(_0x4d8518['query'][_0x5897('0x65')][_0x591a97]),'CmListId':Number(_0x4d8518[_0x5897('0x50')]['id'])});}}else{socket['emit']('userCmList:remove',{'UserId':Number(_0x4d8518[_0x5897('0x3b')][_0x5897('0x65')]),'CmListId':Number(_0x4d8518[_0x5897('0x50')]['id'])});}});}})[_0x5897('0x29')](respondWithStatusCode(_0x10fe12,null))['catch'](handleError(_0x10fe12,null));};exports[_0x5897('0xaa')]=function(_0x34e6ab,_0x52fcfa,_0x2e6ca0){var _0x1310e8={};var _0x49fa47={};var _0x4f8ad7;var _0x4f88d8;return db[_0x5897('0x35')]['findOne']({'where':{'id':_0x34e6ab[_0x5897('0x50')]['id']}})[_0x5897('0x29')](handleEntityNotFound(_0x52fcfa,null))[_0x5897('0x29')](function(_0x127584){if(_0x127584){_0x4f8ad7=_0x127584;_0x49fa47[_0x5897('0x3a')]=_['keys'](db[_0x5897('0xab')][_0x5897('0x36')]);_0x49fa47[_0x5897('0x3b')]=_[_0x5897('0x3c')](_0x34e6ab['query']);_0x49fa47[_0x5897('0x3d')]=_['intersection'](_0x49fa47[_0x5897('0x3a')],_0x49fa47['query']);_0x1310e8['attributes']=_[_0x5897('0x3f')](_0x49fa47[_0x5897('0x3a')],qs[_0x5897('0x40')](_0x34e6ab[_0x5897('0x3b')][_0x5897('0x40')]));_0x1310e8[_0x5897('0x3e')]=_0x1310e8[_0x5897('0x3e')][_0x5897('0x41')]?_0x1310e8[_0x5897('0x3e')]:_0x49fa47[_0x5897('0x3a')];_0x1310e8[_0x5897('0x43')]=qs[_0x5897('0x44')](_0x34e6ab['query'][_0x5897('0x44')]);_0x1310e8['where']=qs[_0x5897('0x3d')](_[_0x5897('0x45')](_0x34e6ab[_0x5897('0x3b')],_0x49fa47[_0x5897('0x3d')]));if(_0x34e6ab[_0x5897('0x3b')]['filter']){_0x1310e8[_0x5897('0x47')]=_[_0x5897('0x49')](_0x1310e8['where'],{'$or':_[_0x5897('0x34')](_0x1310e8['attributes'],function(_0x40d253){var _0x5e693f={};_0x5e693f[_0x40d253]={'$like':'%'+_0x34e6ab[_0x5897('0x3b')][_0x5897('0x46')]+'%'};return _0x5e693f;})});}_0x1310e8=_[_0x5897('0x49')]({},_0x1310e8,_0x34e6ab['options']);return _0x4f8ad7[_0x5897('0xaa')](_0x1310e8);}})[_0x5897('0x29')](function(_0xddcfd6){if(_0xddcfd6){_0x4f88d8=_0xddcfd6[_0x5897('0x41')];if(!_0x34e6ab[_0x5897('0x3b')][_0x5897('0x42')](_0x5897('0x62'))){_0x1310e8['limit']=qs[_0x5897('0x24')](_0x34e6ab[_0x5897('0x3b')][_0x5897('0x24')]);_0x1310e8[_0x5897('0x21')]=qs['offset'](_0x34e6ab[_0x5897('0x3b')][_0x5897('0x21')]);}return _0x4f8ad7['getAgents'](_0x1310e8);}})[_0x5897('0x29')](function(_0x16d857){if(_0x16d857){return _0x16d857?{'count':_0x4f88d8,'rows':_0x16d857}:null;}})['then'](respondWithResult(_0x52fcfa,null))[_0x5897('0x4e')](handleError(_0x52fcfa,null));};function handleQuery(_0xa5e86c){logger['info'](_0xa5e86c);return db['sequelize'][_0x5897('0x3b')](_0xa5e86c)[_0x5897('0xa5')](function(_0x576de1){csv_results[_0x5897('0x6b')](_0x576de1);})[_0x5897('0x4e')](function(_0x3cf39c){logger[_0x5897('0x2f')](_0x3cf39c[_0x5897('0x70')]);});}