ac5dfcab259efce8820b105c87ab5646f4cec98b
[motion-next.git] / server / api / cmList / cmList.controller.js
1 const a157_0x57b2=['status','key','omit','util','errors','userProfileId','text','params','../../rediscache','format','addContacts','Content-type','where','queryInterface','Disposition','show','User','message','isArray','fieldName','raw','emit','UserProfileSection','ListId','join','limit','VIRTUAL','type','INTEGER','ids','dataValues','concat','number','query','BOOLEAN','count','set','../../config/logger','order','push','rawAttributes','../../components/parsers/qs','tags','text/csv','attributes','switch','addCustomFields','getCustomFields','userCmList:remove','create','undefined','describe','name','body','removeAgents','cm_contacts','autoAssociation','download','list_%d_%s.csv','then','setHeader','Unable\x20to\x20retrieve\x20the\x20current\x20user','send','getContacts','get','model','like','merge','register','role','Sequelize','offset','user','each','CmList','fields','options','destroy','/tmp/list_%d_%s.csv','lodash','findAll','getAgents','map','Content-Range','nolimit','sequelize','Lists','catch','userCmList:save','keys','TEXT','to-csv','CustomFields','addCustomField','UserProfileResource','json','index','filters','intersection','length','stack','cf_%d','rows','update','api','includeAll','attachment;\x20filename=','findOne','error','sort','addAgents','CmCustomField','filter','./cmList.socket','sendStatus','include','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','../../mysqldb','defaultValue','end','pick','transaction','CmContact','now','addDisposition'];(function(_0x545898,_0x57b260){const _0x37510c=function(_0x2550e7){while(--_0x2550e7){_0x545898['push'](_0x545898['shift']());}};_0x37510c(++_0x57b260);}(a157_0x57b2,0x8b));const a157_0x3751=function(_0x545898,_0x57b260){_0x545898=_0x545898-0x0;let _0x37510c=a157_0x57b2[_0x545898];return _0x37510c;};const _0x3d1777=a157_0x3751;'use strict';const util=require(_0x3d1777('0x72')),fs=require('fs'),_=require(_0x3d1777('0x41')),toCsv=require(_0x3d1777('0x4d')),{getSocket}=require(_0x3d1777('0x77')),socket=getSocket(),qs=require(_0x3d1777('0x1b')),logger=require(_0x3d1777('0x17'))(_0x3d1777('0x5a')),db=require(_0x3d1777('0x67'))['db'],{Op}=require('sequelize');require(_0x3d1777('0x63'))[_0x3d1777('0x36')](socket);function respondWithStatusCode(_0x2550e7,_0x588b7f){return _0x588b7f=_0x588b7f||0xcc,function(_0x5e46e8){const _0x57637c=a157_0x3751;if(_0x5e46e8)return _0x2550e7['sendStatus'](_0x588b7f);return _0x2550e7[_0x57637c('0x6f')](_0x588b7f)[_0x57637c('0x69')]();};}function respondWithResult(_0x335c47,_0x59fc36){return _0x59fc36=_0x59fc36||0xc8,function(_0x7905ca){const _0x10e4b9=a157_0x3751;if(_0x7905ca)return _0x335c47[_0x10e4b9('0x6f')](_0x59fc36)[_0x10e4b9('0x51')](_0x7905ca);};}function respondWithFilteredResult(_0x118001,_0x3acdd3){return function(_0x3b4e51){const _0x50ff3e=a157_0x3751;if(_0x3b4e51){const _0xea1d9f=_0x3b4e51[_0x50ff3e('0x15')],_0x1721fb=_0x3acdd3[_0x50ff3e('0x39')];let _0xd2895=_0x3acdd3[_0x50ff3e('0x39')]+_0x3acdd3[_0x50ff3e('0xb')],_0x4ff4c8;return _0xd2895>=_0xea1d9f?(_0xd2895=_0xea1d9f,_0x4ff4c8=0xc8):_0x4ff4c8=0xce,_0x118001[_0x50ff3e('0x6f')](_0x4ff4c8),_0x118001[_0x50ff3e('0x16')](_0x50ff3e('0x45'),_0x1721fb+'-'+_0xd2895+'/'+_0xea1d9f)[_0x50ff3e('0x51')](_0x3b4e51);}return null;};}function saveUpdates(_0x5d57bc){return function(_0x10b65a){const _0x3bc068=a157_0x3751;if(_0x10b65a)return _0x10b65a[_0x3bc068('0x59')](_0x5d57bc)['then'](function(_0x17f19d){return _0x17f19d;});return null;};}function removeEntity(_0x2d15fe){return function(_0x4cfada){const _0x50e241=a157_0x3751;if(_0x4cfada)return _0x4cfada[_0x50e241('0x3f')]()['then'](function(){const _0xdd3a1b=_0x50e241,_0x2f46e9=_0x4cfada[_0xdd3a1b('0x32')]({'plain':!![]}),_0xf2708d=_0xdd3a1b('0x48');return db[_0xdd3a1b('0x50')][_0xdd3a1b('0x3f')]({'where':{'type':_0xf2708d,'resourceId':_0x2f46e9['id']}})['then'](function(){return _0x4cfada;});})[_0x50e241('0x2d')](function(){const _0x1ab52e=_0x50e241;_0x2d15fe[_0x1ab52e('0x6f')](0xcc)[_0x1ab52e('0x69')]();});};}function handleEntityNotFound(_0x16e0e5){return function(_0xc79bca){const _0x24d732=a157_0x3751;return!_0xc79bca&&_0x16e0e5[_0x24d732('0x64')](0x194),_0xc79bca;};}function handleError(_0x43176a,_0x2e61c8){return _0x2e61c8=_0x2e61c8||0x1f4,function(_0x10bded){const _0x42ebde=a157_0x3751;logger[_0x42ebde('0x5e')](_0x10bded[_0x42ebde('0x56')]),_0x10bded[_0x42ebde('0x26')]&&delete _0x10bded[_0x42ebde('0x26')],_0x43176a[_0x42ebde('0x6f')](_0x2e61c8)[_0x42ebde('0x30')](_0x10bded);};}exports[_0x3d1777('0x52')]=function(_0x258c77,_0x114e67){const _0x3cc2f7=_0x3d1777;let _0xf5dd34={};const _0x21018b={},_0x1125e3={'count':0x0,'rows':[]},_0x51ce4b=_['map'](db[_0x3cc2f7('0x3c')][_0x3cc2f7('0x1a')],function(_0x1a0404){const _0x464c4f=_0x3cc2f7;return{'name':_0x1a0404[_0x464c4f('0x5')],'type':_0x1a0404[_0x464c4f('0xd')][_0x464c4f('0x70')]};});_0x21018b[_0x3cc2f7('0x33')]=_[_0x3cc2f7('0x44')](_0x51ce4b,'name'),_0x21018b['query']=_['keys'](_0x258c77[_0x3cc2f7('0x13')]),_0x21018b[_0x3cc2f7('0x53')]=_['intersection'](_0x21018b[_0x3cc2f7('0x33')],_0x21018b[_0x3cc2f7('0x13')]),_0xf5dd34['attributes']=_[_0x3cc2f7('0x54')](_0x21018b[_0x3cc2f7('0x33')],qs[_0x3cc2f7('0x3d')](_0x258c77[_0x3cc2f7('0x13')][_0x3cc2f7('0x3d')])),_0xf5dd34[_0x3cc2f7('0x1e')]=_0xf5dd34[_0x3cc2f7('0x1e')]['length']?_0xf5dd34['attributes']:_0x21018b[_0x3cc2f7('0x33')];typeof _0x258c77[_0x3cc2f7('0x13')][_0x3cc2f7('0x46')]===_0x3cc2f7('0x24')&&(_0xf5dd34[_0x3cc2f7('0xb')]=qs[_0x3cc2f7('0xb')](_0x258c77[_0x3cc2f7('0x13')][_0x3cc2f7('0xb')]),_0xf5dd34[_0x3cc2f7('0x39')]=qs['offset'](_0x258c77[_0x3cc2f7('0x13')][_0x3cc2f7('0x39')]));_0xf5dd34[_0x3cc2f7('0x18')]=qs[_0x3cc2f7('0x5f')](_0x258c77[_0x3cc2f7('0x13')][_0x3cc2f7('0x5f')]),_0xf5dd34['where']=qs[_0x3cc2f7('0x53')](_['pick'](_0x258c77[_0x3cc2f7('0x13')],_0x21018b['filters']),_0x51ce4b);_0x258c77[_0x3cc2f7('0x13')][_0x3cc2f7('0x62')]&&(_0xf5dd34[_0x3cc2f7('0x7b')]=_[_0x3cc2f7('0x35')](_0xf5dd34[_0x3cc2f7('0x7b')],{[Op['or']]:_[_0x3cc2f7('0x44')](_0x51ce4b,function(_0x23f837){const _0xee9017=_0x3cc2f7;if(_0x23f837[_0xee9017('0xd')]!==_0xee9017('0xc')){const _0x148da1={};return _0x148da1[_0x23f837[_0xee9017('0x26')]]={[Op['like']]:'%'+_0x258c77['query'][_0xee9017('0x62')]+'%'},_0x148da1;}})}));_0xf5dd34=_['merge']({},_0xf5dd34,_0x258c77[_0x3cc2f7('0x3e')]);const _0x39aec5={'where':_0xf5dd34['where']};return db[_0x3cc2f7('0x3c')][_0x3cc2f7('0x15')](_0x39aec5)[_0x3cc2f7('0x2d')](function(_0x281c26){const _0x2c4365=_0x3cc2f7;return _0x1125e3[_0x2c4365('0x15')]=_0x281c26,_0x258c77[_0x2c4365('0x13')][_0x2c4365('0x5b')]&&(_0xf5dd34['include']=[{'all':!![]}]),db[_0x2c4365('0x3c')][_0x2c4365('0x42')](_0xf5dd34);})[_0x3cc2f7('0x2d')](function(_0x299f79){const _0x74a536=_0x3cc2f7;return _0x1125e3[_0x74a536('0x58')]=_0x299f79,_0x1125e3;})[_0x3cc2f7('0x2d')](respondWithFilteredResult(_0x114e67,_0xf5dd34))[_0x3cc2f7('0x49')](handleError(_0x114e67,null));},exports[_0x3d1777('0x1')]=function(_0x13402a,_0x532437){const _0x40c2af=_0x3d1777;let _0x2505fa={'raw':![],'where':{'id':_0x13402a[_0x40c2af('0x76')]['id']}};const _0x58da76={};return _0x58da76[_0x40c2af('0x33')]=_[_0x40c2af('0x4b')](db[_0x40c2af('0x3c')][_0x40c2af('0x1a')]),_0x58da76[_0x40c2af('0x13')]=_[_0x40c2af('0x4b')](_0x13402a[_0x40c2af('0x13')]),_0x58da76['filters']=_[_0x40c2af('0x54')](_0x58da76[_0x40c2af('0x33')],_0x58da76[_0x40c2af('0x13')]),_0x2505fa[_0x40c2af('0x1e')]=_[_0x40c2af('0x54')](_0x58da76['model'],qs['fields'](_0x13402a[_0x40c2af('0x13')][_0x40c2af('0x3d')])),_0x2505fa['attributes']=_0x2505fa[_0x40c2af('0x1e')][_0x40c2af('0x55')]?_0x2505fa[_0x40c2af('0x1e')]:_0x58da76['model'],_0x13402a[_0x40c2af('0x13')][_0x40c2af('0x5b')]&&(_0x2505fa[_0x40c2af('0x65')]=[{'all':!![]}]),_0x2505fa=_[_0x40c2af('0x35')]({},_0x2505fa,_0x13402a[_0x40c2af('0x3e')]),db[_0x40c2af('0x3c')][_0x40c2af('0x5d')](_0x2505fa)[_0x40c2af('0x2d')](handleEntityNotFound(_0x532437,null))['then'](respondWithResult(_0x532437,null))[_0x40c2af('0x49')](handleError(_0x532437,null));},exports[_0x3d1777('0x23')]=function(_0x1d03f0,_0x3e701e){const _0x24dc17=_0x3d1777;return db['CmList']['create'](_0x1d03f0[_0x24dc17('0x27')],{})['then'](function(_0x3efb35){const _0x3c1680=_0x24dc17,_0xe34745=_0x1d03f0[_0x3c1680('0x3a')][_0x3c1680('0x32')]({'plain':!![]});if(!_0xe34745)throw new Error(_0x3c1680('0x2f'));if(_0xe34745[_0x3c1680('0x37')]==='user'){const _0x18cb17=_0x3efb35[_0x3c1680('0x32')]({'plain':!![]}),_0x802d27='Lists';return db[_0x3c1680('0x8')][_0x3c1680('0x5d')]({'where':{'name':_0x802d27,'userProfileId':_0xe34745[_0x3c1680('0x74')]},'raw':!![]})['then'](function(_0x2417da){const _0x539425=_0x3c1680;return _0x2417da&&_0x2417da[_0x539425('0x2a')]===0x0?db[_0x539425('0x50')][_0x539425('0x23')]({'name':_0x18cb17[_0x539425('0x26')],'resourceId':_0x18cb17['id'],'type':_0x2417da[_0x539425('0x26')],'sectionId':_0x2417da['id']},{})[_0x539425('0x2d')](function(){return _0x3efb35;}):_0x3efb35;})[_0x3c1680('0x49')](function(_0x469daa){const _0x5e65ba=_0x3c1680;logger[_0x5e65ba('0x5e')](_0x5e65ba('0x66'),_0x469daa);throw _0x469daa;});}return _0x3efb35;})[_0x24dc17('0x2d')](respondWithResult(_0x3e701e,0xc9))[_0x24dc17('0x49')](handleError(_0x3e701e,null));},exports[_0x3d1777('0x59')]=function(_0x1cc937,_0x9efb1){const _0x3aaf2c=_0x3d1777;return _0x1cc937['body']['id']&&delete _0x1cc937[_0x3aaf2c('0x27')]['id'],db[_0x3aaf2c('0x3c')]['findOne']({'where':{'id':_0x1cc937['params']['id']}})['then'](handleEntityNotFound(_0x9efb1,null))[_0x3aaf2c('0x2d')](saveUpdates(_0x1cc937[_0x3aaf2c('0x27')],null))[_0x3aaf2c('0x2d')](respondWithResult(_0x9efb1,null))[_0x3aaf2c('0x49')](handleError(_0x9efb1,null));},exports[_0x3d1777('0x3f')]=function(_0x1bf977,_0x4b3306){const _0x36f446=_0x3d1777;return db['CmList'][_0x36f446('0x5d')]({'where':{'id':_0x1bf977[_0x36f446('0x76')]['id']}})[_0x36f446('0x2d')](handleEntityNotFound(_0x4b3306,null))[_0x36f446('0x2d')](removeEntity(_0x4b3306,null))[_0x36f446('0x49')](handleError(_0x4b3306,null));},exports[_0x3d1777('0x25')]=function(_0x58e88a,_0x4c03af){const _0x27d43c=_0x3d1777;return db[_0x27d43c('0x3c')][_0x27d43c('0x25')]()['then'](respondWithResult(_0x4c03af,null))[_0x27d43c('0x49')](handleError(_0x4c03af,null));},exports[_0x3d1777('0x6e')]=function(_0x340384,_0x58034e){const _0x3e5c85=_0x3d1777;return _0x340384['body']['id']&&delete _0x340384['body']['id'],db[_0x3e5c85('0x3c')]['findOne']({'where':{'id':_0x340384[_0x3e5c85('0x76')]['id']}})[_0x3e5c85('0x2d')](handleEntityNotFound(_0x58034e,null))['then'](function(_0x35be55){const _0x51d69b=_0x3e5c85;if(_0x35be55)return _0x340384[_0x51d69b('0x27')]['ListId']=_0x35be55['id'],db[_0x51d69b('0x0')][_0x51d69b('0x23')](_0x340384[_0x51d69b('0x27')]);})[_0x3e5c85('0x2d')](respondWithResult(_0x58034e,null))[_0x3e5c85('0x49')](handleError(_0x58034e,null));},exports['getDispositions']=function(_0x2f304e,_0x33b0f5){const _0x520887=_0x3d1777;let _0x174b41={'raw':![],'where':{}};const _0x4080f6={},_0x13b4f4={'count':0x0,'rows':[]};return db[_0x520887('0x3c')]['findOne']({'where':{'id':_0x2f304e['params']['id']}})[_0x520887('0x2d')](handleEntityNotFound(_0x33b0f5,null))[_0x520887('0x2d')](function(_0x31fd59){const _0x4314ff=_0x520887;if(_0x31fd59)return _0x4080f6[_0x4314ff('0x33')]=_[_0x4314ff('0x4b')](db[_0x4314ff('0x0')]['rawAttributes']),_0x4080f6[_0x4314ff('0x13')]=_[_0x4314ff('0x4b')](_0x2f304e['query']),_0x4080f6[_0x4314ff('0x53')]=_[_0x4314ff('0x54')](_0x4080f6[_0x4314ff('0x33')],_0x4080f6[_0x4314ff('0x13')]),_0x174b41[_0x4314ff('0x1e')]=_[_0x4314ff('0x54')](_0x4080f6[_0x4314ff('0x33')],qs[_0x4314ff('0x3d')](_0x2f304e['query']['fields'])),_0x174b41[_0x4314ff('0x1e')]=_0x174b41[_0x4314ff('0x1e')][_0x4314ff('0x55')]?_0x174b41['attributes']:_0x4080f6['model'],typeof _0x2f304e[_0x4314ff('0x13')][_0x4314ff('0x46')]===_0x4314ff('0x24')&&(_0x174b41[_0x4314ff('0xb')]=qs[_0x4314ff('0xb')](_0x2f304e[_0x4314ff('0x13')]['limit']),_0x174b41['offset']=qs[_0x4314ff('0x39')](_0x2f304e[_0x4314ff('0x13')][_0x4314ff('0x39')])),_0x174b41[_0x4314ff('0x18')]=qs[_0x4314ff('0x5f')](_0x2f304e['query'][_0x4314ff('0x5f')]),_0x174b41[_0x4314ff('0x7b')]=qs[_0x4314ff('0x53')](_['pick'](_0x2f304e['query'],_0x4080f6[_0x4314ff('0x53')])),_0x174b41[_0x4314ff('0x7b')][_0x4314ff('0x9')]=_0x31fd59['id'],_0x2f304e[_0x4314ff('0x13')][_0x4314ff('0x62')]&&(_0x174b41[_0x4314ff('0x7b')]=_[_0x4314ff('0x35')](_0x174b41[_0x4314ff('0x7b')],{[Op['or']]:_[_0x4314ff('0x44')](_0x174b41['attributes'],function(_0x318f03){const _0x2675b0=_0x4314ff,_0x569fe8={};return _0x569fe8[_0x318f03]={[Op[_0x2675b0('0x34')]]:'%'+_0x2f304e[_0x2675b0('0x13')][_0x2675b0('0x62')]+'%'},_0x569fe8;})})),_0x174b41=_['merge']({},_0x174b41,_0x2f304e[_0x4314ff('0x3e')]),db['Disposition'][_0x4314ff('0x15')]({'where':_0x174b41[_0x4314ff('0x7b')]})[_0x4314ff('0x2d')](function(_0x26a280){const _0x5ef237=_0x4314ff;return _0x13b4f4[_0x5ef237('0x15')]=_0x26a280,_0x2f304e[_0x5ef237('0x13')][_0x5ef237('0x5b')]&&(_0x174b41[_0x5ef237('0x65')]=[{'all':!![]}]),db['Disposition'][_0x5ef237('0x42')](_0x174b41);})['then'](function(_0x3817d7){const _0x4c46a7=_0x4314ff;return _0x13b4f4[_0x4c46a7('0x58')]=_0x3817d7,_0x13b4f4;});})[_0x520887('0x2d')](respondWithFilteredResult(_0x33b0f5,_0x174b41))['catch'](handleError(_0x33b0f5,null));},exports['removeDispositions']=function(_0x206bb3,_0x36288e){const _0x322576=_0x3d1777;return db[_0x322576('0x3c')][_0x322576('0x5d')]({'where':{'id':_0x206bb3[_0x322576('0x76')]['id']}})[_0x322576('0x2d')](handleEntityNotFound(_0x36288e,null))[_0x322576('0x2d')](function(_0x5b25b2){if(_0x5b25b2)return _0x5b25b2['removeDispositions'](_0x206bb3['query']['ids']);})[_0x322576('0x2d')](respondWithStatusCode(_0x36288e,null))[_0x322576('0x49')](handleError(_0x36288e,null));},exports[_0x3d1777('0x79')]=function(_0x5dcf33,_0x2b5c16){const _0x23efb8=_0x3d1777;return db[_0x23efb8('0x3c')]['findOne']({'where':{'id':_0x5dcf33[_0x23efb8('0x76')]['id']}})[_0x23efb8('0x2d')](handleEntityNotFound(_0x2b5c16,null))[_0x23efb8('0x2d')](function(_0x582094){const _0x327ae1=_0x23efb8;if(_0x582094){const _0x510274=[],_0x459d8b={'success':[],'errors':[]};return db[_0x327ae1('0x6c')][_0x327ae1('0x25')]()['then'](function(_0x61a1fd){const _0x494bd2=_0x327ae1;_0x5dcf33[_0x494bd2('0x27')][_0x494bd2('0x1c')]&&_[_0x494bd2('0x4')](_0x5dcf33[_0x494bd2('0x27')][_0x494bd2('0x1c')])?_0x5dcf33[_0x494bd2('0x27')][_0x494bd2('0x1c')]['length']?_0x5dcf33[_0x494bd2('0x27')][_0x494bd2('0x1c')]=_0x5dcf33[_0x494bd2('0x27')]['tags'][_0x494bd2('0xa')](';')+';':_0x5dcf33['body']['tags']=null:_0x5dcf33[_0x494bd2('0x27')][_0x494bd2('0x1c')]=null;if(_0x5dcf33['body']&&_[_0x494bd2('0x4')](_0x5dcf33[_0x494bd2('0x27')])){for(let _0x249bd6=0x0;_0x249bd6<_0x5dcf33[_0x494bd2('0x27')][_0x494bd2('0x55')];_0x249bd6+=0x1){_0x5dcf33[_0x494bd2('0x27')][_0x249bd6]['ListId']=_0x5dcf33[_0x494bd2('0x76')]['id'],_0x510274[_0x494bd2('0x19')](_0x5dcf33[_0x494bd2('0x27')][_0x249bd6]);}return Promise[_0x494bd2('0x3b')](_0x510274,function(_0x32a483){const _0x2c96ad=_0x494bd2;return db[_0x2c96ad('0x6c')][_0x2c96ad('0x23')](_[_0x2c96ad('0x71')](_0x32a483,['ids','id'])||{},{'fields':_[_0x2c96ad('0x4b')](_0x61a1fd),'raw':!![]})['then'](function(_0x360576){const _0x502157=_0x2c96ad;_0x459d8b['success'][_0x502157('0x19')](_0x360576[_0x502157('0x10')]);})['catch'](function(_0x2fc252){const _0xc55266=_0x2c96ad;_0x459d8b[_0xc55266('0x73')][_0xc55266('0x19')]({'data':_0x32a483,'error':_0x2fc252[_0xc55266('0x3')]});});})[_0x494bd2('0x2d')](function(){return _0x459d8b;})[_0x494bd2('0x49')](function(_0x5d2f0b){return _0x5d2f0b;});}else _0x2b5c16[_0x494bd2('0x6f')](0x190)[_0x494bd2('0x51')]({'message':'Malformed\x20request\x20syntax'});});}})[_0x23efb8('0x2d')](respondWithResult(_0x2b5c16,null))[_0x23efb8('0x49')](handleError(_0x2b5c16,null));},exports[_0x3d1777('0x31')]=function(_0x319cc5,_0x3d0e09){const _0x49e40e=_0x3d1777;let _0x36ed9e;return db['CmList'][_0x49e40e('0x5d')]({'where':{'id':_0x319cc5['params']['id']},'include':[{'model':db[_0x49e40e('0x61')],'as':'CustomFields'}]})['then'](handleEntityNotFound(_0x3d0e09,null))[_0x49e40e('0x2d')](function(_0x1cabcf){const _0x1339c7=_0x49e40e;if(_0x1cabcf)return _0x36ed9e=_0x1cabcf,db[_0x1339c7('0x6c')][_0x1339c7('0x1a')];})[_0x49e40e('0x2d')](function(_0x582f9e){const _0x109c40=_0x49e40e;if(_0x582f9e){let _0x5dc97f={};const _0x30899c={};return _0x30899c[_0x109c40('0x33')]=_['concat'](_['keys'](_0x582f9e),_[_0x109c40('0x44')](_0x36ed9e['CustomFields'],function(_0x20fa05){const _0x1a0bc3=_0x109c40;return util['format'](_0x1a0bc3('0x57'),_0x20fa05['id']);})),_0x30899c['query']=_[_0x109c40('0x4b')](_0x319cc5['query']),_0x30899c[_0x109c40('0x53')]=_['intersection'](_0x30899c[_0x109c40('0x33')],_0x30899c[_0x109c40('0x13')]),_0x5dc97f[_0x109c40('0x1e')]=_[_0x109c40('0x54')](_0x30899c[_0x109c40('0x33')],qs[_0x109c40('0x3d')](_0x319cc5[_0x109c40('0x13')][_0x109c40('0x3d')])),_0x5dc97f['attributes']=_0x5dc97f[_0x109c40('0x1e')][_0x109c40('0x55')]?_0x5dc97f[_0x109c40('0x1e')]:_0x30899c[_0x109c40('0x33')],typeof _0x319cc5['query'][_0x109c40('0x46')]===_0x109c40('0x24')&&(_0x5dc97f[_0x109c40('0xb')]=qs[_0x109c40('0xb')](_0x319cc5['query'][_0x109c40('0xb')]),_0x5dc97f['offset']=qs[_0x109c40('0x39')](_0x319cc5[_0x109c40('0x13')][_0x109c40('0x39')])),_0x5dc97f['order']=qs[_0x109c40('0x5f')](_0x319cc5[_0x109c40('0x13')][_0x109c40('0x5f')]),_0x5dc97f[_0x109c40('0x7b')]=qs[_0x109c40('0x53')](_[_0x109c40('0x6a')](_0x319cc5['query'],_0x30899c[_0x109c40('0x53')])),_0x5dc97f[_0x109c40('0x6')]=!![],_0x319cc5[_0x109c40('0x13')]['filter']&&(_0x5dc97f[_0x109c40('0x7b')]=_[_0x109c40('0x35')](_0x5dc97f[_0x109c40('0x7b')],{[Op['or']]:_['map'](_0x5dc97f['attributes'],function(_0xc6399e){const _0x529ce4=_0x109c40,_0x560fd7={};return _0x560fd7[_0xc6399e]={[Op[_0x529ce4('0x34')]]:'%'+_0x319cc5[_0x529ce4('0x13')][_0x529ce4('0x62')]+'%'},_0x560fd7;})})),_0x5dc97f=_[_0x109c40('0x35')]({},_0x5dc97f,_0x319cc5[_0x109c40('0x3e')]),_0x36ed9e[_0x109c40('0x31')](_0x5dc97f);}})[_0x49e40e('0x2d')](respondWithResult(_0x3d0e09,null))[_0x49e40e('0x49')](handleError(_0x3d0e09,null));},exports['getContactsCsv']=function(_0x19e726,_0x2aaca2){const _0x2cd8d8=_0x3d1777;let _0x13c13a;return db[_0x2cd8d8('0x3c')][_0x2cd8d8('0x5d')]({'where':{'id':_0x19e726[_0x2cd8d8('0x76')]['id']},'include':[{'model':db['CmCustomField'],'as':_0x2cd8d8('0x4e')}]})[_0x2cd8d8('0x2d')](handleEntityNotFound(_0x2aaca2,null))[_0x2cd8d8('0x2d')](function(_0x1a2d31){const _0x2ec6a0=_0x2cd8d8;if(_0x1a2d31)return _0x13c13a=_0x1a2d31,db['CmContact'][_0x2ec6a0('0x1a')];})['then'](function(_0x4c9faa){const _0x4b4ed3=_0x2cd8d8;if(_0x4c9faa){let _0x5ae849={};const _0x11ab80={};return _0x11ab80['model']=_[_0x4b4ed3('0x11')](_[_0x4b4ed3('0x4b')](_0x4c9faa),_[_0x4b4ed3('0x44')](_0x13c13a[_0x4b4ed3('0x4e')],function(_0x538ad1){const _0x1ae602=_0x4b4ed3;return util[_0x1ae602('0x78')](_0x1ae602('0x57'),_0x538ad1['id']);})),_0x11ab80['query']=_['keys'](_0x19e726[_0x4b4ed3('0x13')]),_0x11ab80[_0x4b4ed3('0x53')]=_[_0x4b4ed3('0x54')](_0x11ab80[_0x4b4ed3('0x33')],_0x11ab80[_0x4b4ed3('0x13')]),_0x5ae849[_0x4b4ed3('0x1e')]=_[_0x4b4ed3('0x54')](_0x11ab80['model'],qs['fields'](_0x19e726['query'][_0x4b4ed3('0x3d')])),_0x5ae849[_0x4b4ed3('0x1e')]=_0x5ae849[_0x4b4ed3('0x1e')][_0x4b4ed3('0x55')]?_0x5ae849[_0x4b4ed3('0x1e')]:_0x11ab80[_0x4b4ed3('0x33')],typeof _0x19e726['query'][_0x4b4ed3('0x46')]===_0x4b4ed3('0x24')&&(_0x5ae849['limit']=qs[_0x4b4ed3('0xb')](_0x19e726[_0x4b4ed3('0x13')]['limit']),_0x5ae849[_0x4b4ed3('0x39')]=qs[_0x4b4ed3('0x39')](_0x19e726['query'][_0x4b4ed3('0x39')])),_0x5ae849[_0x4b4ed3('0x18')]=qs[_0x4b4ed3('0x5f')](_0x19e726[_0x4b4ed3('0x13')][_0x4b4ed3('0x5f')]),_0x5ae849[_0x4b4ed3('0x7b')]=qs[_0x4b4ed3('0x53')](_[_0x4b4ed3('0x6a')](_0x19e726[_0x4b4ed3('0x13')],_0x11ab80[_0x4b4ed3('0x53')])),_0x5ae849[_0x4b4ed3('0x6')]=!![],_0x19e726[_0x4b4ed3('0x13')][_0x4b4ed3('0x62')]&&(_0x5ae849[_0x4b4ed3('0x7b')]=_[_0x4b4ed3('0x35')](_0x5ae849['where'],{[Op['or']]:_[_0x4b4ed3('0x44')](_0x5ae849[_0x4b4ed3('0x1e')],function(_0x22f842){const _0x57316d=_0x4b4ed3,_0x4d9a97={};return _0x4d9a97[_0x22f842]={[Op[_0x57316d('0x34')]]:'%'+_0x19e726[_0x57316d('0x13')][_0x57316d('0x62')]+'%'},_0x4d9a97;})})),_0x5ae849=_[_0x4b4ed3('0x35')]({},_0x5ae849,_0x19e726['options']),_0x13c13a[_0x4b4ed3('0x31')](_0x5ae849);}})['then'](function(_0x308dae){const _0x52743e=_0x2cd8d8;if(!_['isEmpty'](_0x308dae)){const _0x1054ae=toCsv(_0x308dae),_0x4e217c=Date[_0x52743e('0x6d')]();return fs['writeFileSync'](util[_0x52743e('0x78')](_0x52743e('0x40'),_0x13c13a['id'],_0x4e217c),_0x1054ae),_0x2aaca2[_0x52743e('0x2e')]('Content-disposition',_0x52743e('0x5c')+util[_0x52743e('0x78')](_0x52743e('0x2c'),_0x13c13a['id'],_0x4e217c)),_0x2aaca2['setHeader'](_0x52743e('0x7a'),_0x52743e('0x1d')),_0x2aaca2[_0x52743e('0x2b')](util[_0x52743e('0x78')](_0x52743e('0x40'),_0x13c13a['id'],_0x4e217c));}else return _0x2aaca2[_0x52743e('0x64')](0xcc);})[_0x2cd8d8('0x49')](handleError(_0x2aaca2,null));},exports[_0x3d1777('0x4f')]=function(_0x470370,_0x30bd2b){const _0x56536e=_0x3d1777;let _0x149384;return delete _0x470370[_0x56536e('0x27')]['id'],db[_0x56536e('0x3c')][_0x56536e('0x5d')]({'where':{'id':_0x470370[_0x56536e('0x76')]['id']}})[_0x56536e('0x2d')](handleEntityNotFound(_0x30bd2b,null))[_0x56536e('0x2d')](function(_0x2ea6e4){const _0x2d550e=_0x56536e;if(_0x2ea6e4)return db[_0x2d550e('0x47')][_0x2d550e('0x6b')](function(_0x30f6dd){const _0x3e48e1=_0x2d550e;return db[_0x3e48e1('0x61')][_0x3e48e1('0x23')](_0x470370['body'],{'transaction':_0x30f6dd})['then'](function(_0x32ad2d){const _0x3e982e=_0x3e48e1;return _0x149384=_0x32ad2d,_0x2ea6e4[_0x3e982e('0x20')](_0x32ad2d,{'transaction':_0x30f6dd});})[_0x3e48e1('0x2d')](function(){const _0x4858b6=_0x3e48e1,_0x522ab2={'type':db[_0x4858b6('0x38')][_0x4858b6('0x4c')],'transaction':_0x30f6dd};switch(_0x470370[_0x4858b6('0x27')]['type']){case _0x4858b6('0x75'):_0x522ab2[_0x4858b6('0xd')]=db[_0x4858b6('0x38')]['TEXT'];break;case _0x4858b6('0x12'):_0x522ab2['type']=db[_0x4858b6('0x38')][_0x4858b6('0xe')];break;case _0x4858b6('0x1f'):_0x522ab2[_0x4858b6('0xd')]=db[_0x4858b6('0x38')][_0x4858b6('0x14')],_0x522ab2[_0x4858b6('0x68')]=![];break;default:}return db[_0x4858b6('0x47')][_0x4858b6('0x7c')]['addColumn'](_0x4858b6('0x29'),util[_0x4858b6('0x78')]('cf_%s',_0x149384['id']),_0x522ab2);})[_0x3e48e1('0x2d')](function(){return _0x149384;});});})[_0x56536e('0x2d')](respondWithResult(_0x30bd2b,null))[_0x56536e('0x49')](handleError(_0x30bd2b,null));},exports[_0x3d1777('0x21')]=function(_0x26d392,_0x44b720){const _0x2213be=_0x3d1777;let _0x11151a={};const _0x58664d={};return db[_0x2213be('0x3c')][_0x2213be('0x5d')]({'where':{'id':_0x26d392[_0x2213be('0x76')]['id']}})['then'](handleEntityNotFound(_0x44b720,null))[_0x2213be('0x2d')](function(_0x5e2b40){const _0xf1adb9=_0x2213be;if(_0x5e2b40)return _0x58664d[_0xf1adb9('0x33')]=_[_0xf1adb9('0x4b')](db['CmCustomField'][_0xf1adb9('0x1a')]),_0x58664d[_0xf1adb9('0x13')]=_['keys'](_0x26d392[_0xf1adb9('0x13')]),_0x58664d['filters']=_['intersection'](_0x58664d[_0xf1adb9('0x33')],_0x58664d['query']),_0x11151a['attributes']=_[_0xf1adb9('0x54')](_0x58664d[_0xf1adb9('0x33')],qs[_0xf1adb9('0x3d')](_0x26d392[_0xf1adb9('0x13')][_0xf1adb9('0x3d')])),_0x11151a['attributes']=_0x11151a[_0xf1adb9('0x1e')][_0xf1adb9('0x55')]?_0x11151a[_0xf1adb9('0x1e')]:_0x58664d[_0xf1adb9('0x33')],_0x11151a['order']=qs[_0xf1adb9('0x5f')](_0x26d392['query'][_0xf1adb9('0x5f')]),_0x11151a['where']=qs['filters'](_['pick'](_0x26d392[_0xf1adb9('0x13')],_0x58664d['filters'])),_0x11151a[_0xf1adb9('0x7b')]=_[_0xf1adb9('0x35')](_0x11151a[_0xf1adb9('0x7b')],{[Op['or']]:[{'ListId':_0x5e2b40['id']},{'ListId':null}]}),_0x26d392[_0xf1adb9('0x13')][_0xf1adb9('0x62')]&&(_0x11151a[_0xf1adb9('0x7b')]=_[_0xf1adb9('0x35')](_0x11151a[_0xf1adb9('0x7b')],{[Op['or']]:_[_0xf1adb9('0x44')](_0x11151a[_0xf1adb9('0x1e')],function(_0x2b4a3d){const _0x4e8e57=_0xf1adb9,_0x204880={};return _0x204880[_0x2b4a3d]={[Op[_0x4e8e57('0x34')]]:'%'+_0x26d392['query'][_0x4e8e57('0x62')]+'%'},_0x204880;})})),_0x11151a=_[_0xf1adb9('0x35')]({},_0x11151a,_0x26d392['options']),db[_0xf1adb9('0x61')]['findAndCountAll'](_0x11151a);})[_0x2213be('0x2d')](respondWithResult(_0x44b720,null))['catch'](handleError(_0x44b720,null));},exports[_0x3d1777('0x60')]=function(_0x37ff0b,_0x7c9287){const _0xacc6b1=_0x3d1777;return db[_0xacc6b1('0x3c')]['findOne']({'where':{'id':_0x37ff0b[_0xacc6b1('0x76')]['id']}})[_0xacc6b1('0x2d')](function(_0x452ad4){const _0x54ffc3=_0xacc6b1;if(_0x452ad4)return _0x452ad4[_0x54ffc3('0x60')](_0x37ff0b['body']['ids'],{'through':_[_0x54ffc3('0x71')](_0x37ff0b[_0x54ffc3('0x27')],[_0x54ffc3('0xf'),'id'])})[_0x54ffc3('0x2d')](function(_0x10a7e8){const _0x3f4b1e=_0x54ffc3;for(let _0x4cf6b0=0x0;_0x4cf6b0<_0x37ff0b[_0x3f4b1e('0x27')][_0x3f4b1e('0xf')]['length'];_0x4cf6b0+=0x1){socket[_0x3f4b1e('0x7')](_0x3f4b1e('0x4a'),{'UserId':_0x37ff0b[_0x3f4b1e('0x27')][_0x3f4b1e('0xf')][_0x4cf6b0],'CmListId':_0x37ff0b[_0x3f4b1e('0x76')]['id']});}return _0x10a7e8;});})[_0xacc6b1('0x2d')](respondWithResult(_0x7c9287,null))[_0xacc6b1('0x49')](handleError(_0x7c9287,null));},exports['removeAgents']=function(_0x252cdb,_0x2ed74d){const _0x54c352=_0x3d1777;return db['CmList'][_0x54c352('0x5d')]({'where':{'id':_0x252cdb[_0x54c352('0x76')]['id']}})[_0x54c352('0x2d')](handleEntityNotFound(_0x2ed74d,null))[_0x54c352('0x2d')](function(_0x1d9fce){const _0x4518dd=_0x54c352;if(_0x1d9fce)return _0x1d9fce[_0x4518dd('0x28')](_0x252cdb[_0x4518dd('0x13')]['ids'])[_0x4518dd('0x2d')](function(){const _0x21cf8d=_0x4518dd;if(_[_0x21cf8d('0x4')](_0x252cdb['query'][_0x21cf8d('0xf')]))for(let _0x384efe=0x0;_0x384efe<_0x252cdb[_0x21cf8d('0x13')][_0x21cf8d('0xf')][_0x21cf8d('0x55')];_0x384efe+=0x1){socket[_0x21cf8d('0x7')]('userCmList:remove',{'UserId':Number(_0x252cdb[_0x21cf8d('0x13')][_0x21cf8d('0xf')][_0x384efe]),'CmListId':Number(_0x252cdb[_0x21cf8d('0x76')]['id'])});}else socket[_0x21cf8d('0x7')](_0x21cf8d('0x22'),{'UserId':Number(_0x252cdb[_0x21cf8d('0x13')][_0x21cf8d('0xf')]),'CmListId':Number(_0x252cdb[_0x21cf8d('0x76')]['id'])});});})[_0x54c352('0x2d')](respondWithStatusCode(_0x2ed74d,null))[_0x54c352('0x49')](handleError(_0x2ed74d,null));},exports[_0x3d1777('0x43')]=function(_0x1aa027,_0x5ac335){const _0x426537=_0x3d1777;let _0x454dca={};const _0x2c265c={};let _0x4bf7f3,_0x3892bf;return db['CmList'][_0x426537('0x5d')]({'where':{'id':_0x1aa027[_0x426537('0x76')]['id']}})['then'](handleEntityNotFound(_0x5ac335,null))[_0x426537('0x2d')](function(_0x31e06d){const _0xc41e1f=_0x426537;if(_0x31e06d)return _0x4bf7f3=_0x31e06d,_0x2c265c['model']=_[_0xc41e1f('0x4b')](db[_0xc41e1f('0x2')][_0xc41e1f('0x1a')]),_0x2c265c[_0xc41e1f('0x13')]=_[_0xc41e1f('0x4b')](_0x1aa027[_0xc41e1f('0x13')]),_0x2c265c['filters']=_[_0xc41e1f('0x54')](_0x2c265c[_0xc41e1f('0x33')],_0x2c265c['query']),_0x454dca[_0xc41e1f('0x1e')]=_[_0xc41e1f('0x54')](_0x2c265c['model'],qs[_0xc41e1f('0x3d')](_0x1aa027[_0xc41e1f('0x13')][_0xc41e1f('0x3d')])),_0x454dca['attributes']=_0x454dca[_0xc41e1f('0x1e')][_0xc41e1f('0x55')]?_0x454dca[_0xc41e1f('0x1e')]:_0x2c265c['model'],_0x454dca[_0xc41e1f('0x18')]=qs['sort'](_0x1aa027['query']['sort']),_0x454dca[_0xc41e1f('0x7b')]=qs['filters'](_[_0xc41e1f('0x6a')](_0x1aa027['query'],_0x2c265c[_0xc41e1f('0x53')])),_0x1aa027[_0xc41e1f('0x13')]['filter']&&(_0x454dca['where']=_[_0xc41e1f('0x35')](_0x454dca[_0xc41e1f('0x7b')],{[Op['or']]:_['map'](_0x454dca['attributes'],function(_0x3583af){const _0x1ff81b=_0xc41e1f,_0x152c18={};return _0x152c18[_0x3583af]={[Op[_0x1ff81b('0x34')]]:'%'+_0x1aa027[_0x1ff81b('0x13')]['filter']+'%'},_0x152c18;})})),_0x454dca=_[_0xc41e1f('0x35')]({},_0x454dca,_0x1aa027[_0xc41e1f('0x3e')]),_0x4bf7f3[_0xc41e1f('0x43')](_0x454dca);})[_0x426537('0x2d')](function(_0x12f2fe){const _0x2df0a6=_0x426537;if(_0x12f2fe)return _0x3892bf=_0x12f2fe[_0x2df0a6('0x55')],typeof _0x1aa027[_0x2df0a6('0x13')][_0x2df0a6('0x46')]==='undefined'&&(_0x454dca[_0x2df0a6('0xb')]=qs[_0x2df0a6('0xb')](_0x1aa027[_0x2df0a6('0x13')]['limit']),_0x454dca['offset']=qs['offset'](_0x1aa027[_0x2df0a6('0x13')][_0x2df0a6('0x39')])),_0x4bf7f3[_0x2df0a6('0x43')](_0x454dca);})['then'](function(_0x248752){if(_0x248752)return _0x248752?{'count':_0x3892bf,'rows':_0x248752}:null;})[_0x426537('0x2d')](respondWithResult(_0x5ac335,null))['catch'](handleError(_0x5ac335,null));};