e74026501cf90b6560548c41f9fdd313a27bc52c
[motion-next.git] / server / api / mailQueue / mailQueue.controller.js
1 const a505_0x4eef=['query','intersection','get','Agents','MailQueueId','offset','sendStatus','addAgents','value','attributes','count','format','squel','removeAgents','destroy','ut.UserId\x20=\x20?','keys','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','key','forEach','mailPause','clone','findAndCountAll','MailQueueId\x20=\x20?','join','ids','findOrCreate','toString','MailQueues','show','every','merge','sort','Content-Range','pick','json','order','ut.TeamId\x20=\x20tq.TeamId','describe','MailQueue','from','compact','user_has_teams','update','index','options','includeAll','../../components/parsers/qs','agent','set','where','../../mysqldb','status','filter','role','../../config/logger','removeTeams','createdAt','User','fields','rows','getMembers','./mailQueue.socket','VIRTUAL','emit','SIP','nolimit','getTeams','transaction','include','body','autoAssociation','fieldName','findAll','end','sequelize','TeamId','UserMailQueue','all','length','select','api','isArray','like','online','findOne','addTeams','catch','map','omit','params','userMailQueue:remove','union','rawAttributes','error','getAgents','updatedAt','Team','voicePause','filters','model','type','limit','undefined','lodash','UserProfileResource','then','create','name','register','util','isEmpty','stack'];(function(_0x2f1c94,_0x2457dc){const _0x4eef30=function(_0x3e9d66){while(--_0x3e9d66){_0x2f1c94['push'](_0x2f1c94['shift']());}};_0x4eef30(++_0x2457dc);}(a505_0x4eef,0x154));const a505_0x3e9d=function(_0x2f1c94,_0x2457dc){_0x2f1c94=_0x2f1c94-0x1e6;let _0x4eef30=a505_0x4eef[_0x2f1c94];return _0x4eef30;};const a505_0x4c7904=a505_0x3e9d;'use strict';const util=require(a505_0x4c7904(0x253)),_=require(a505_0x4c7904(0x24d)),squel=require(a505_0x4c7904(0x1f1)),qs=require(a505_0x4c7904(0x214)),logger=require(a505_0x4c7904(0x21c))(a505_0x4c7904(0x236)),{getSocket}=require('../../rediscache'),socket=getSocket(),{db}=require(a505_0x4c7904(0x218)),{Op,QueryTypes}=require(a505_0x4c7904(0x230));require(a505_0x4c7904(0x223))[a505_0x4c7904(0x252)](socket);function respondWithStatusCode(_0xe2692a,_0x2352d1){return _0x2352d1=_0x2352d1||0xcc,function(_0x55f00b){const _0x58c819=a505_0x3e9d;if(_0x55f00b)return _0xe2692a[_0x58c819(0x1eb)](_0x2352d1);return _0xe2692a[_0x58c819(0x219)](_0x2352d1)[_0x58c819(0x22f)]();};}function respondWithResult(_0x297936,_0x1d9809){return _0x1d9809=_0x1d9809||0xc8,function(_0x227899){const _0x5e9fd3=a505_0x3e9d;if(_0x227899)return _0x297936[_0x5e9fd3(0x219)](_0x1d9809)[_0x5e9fd3(0x208)](_0x227899);};}function respondWithFilteredResult(_0x57b19e,_0x290af2){return function(_0x27008c){const _0x2ef3fd=a505_0x3e9d;if(_0x27008c){const _0x5b3e9d=_0x27008c[_0x2ef3fd(0x1ef)],_0x4fd38a=_0x290af2[_0x2ef3fd(0x1ea)];let _0x1c8acb=_0x290af2[_0x2ef3fd(0x1ea)]+_0x290af2[_0x2ef3fd(0x24b)],_0x5411ea;return _0x1c8acb>=_0x5b3e9d?(_0x1c8acb=_0x5b3e9d,_0x5411ea=0xc8):_0x5411ea=0xce,_0x57b19e[_0x2ef3fd(0x219)](_0x5411ea),_0x57b19e[_0x2ef3fd(0x216)](_0x2ef3fd(0x206),_0x4fd38a+'-'+_0x1c8acb+'/'+_0x5b3e9d)['json'](_0x27008c);}return null;};}function saveUpdates(_0x17b4a6){return function(_0x538d6e){const _0x18511e=a505_0x3e9d;if(_0x538d6e)return _0x538d6e[_0x18511e(0x210)](_0x17b4a6)[_0x18511e(0x24f)](function(_0x5ab0a7){return _0x5ab0a7;});return null;};}function removeEntity(_0x55c756){return function(_0x4d187c){const _0x2c5f6b=a505_0x3e9d;if(_0x4d187c)return _0x4d187c['destroy']()[_0x2c5f6b(0x24f)](function(){const _0x4269b0=_0x2c5f6b,_0x517b8b=_0x4d187c[_0x4269b0(0x1e7)]({'plain':!![]}),_0x4b8d54=_0x4269b0(0x201);return db[_0x4269b0(0x24e)]['destroy']({'where':{'type':_0x4b8d54,'resourceId':_0x517b8b['id']}})['then'](function(){return _0x4d187c;});})[_0x2c5f6b(0x24f)](function(){const _0x5084bb=_0x2c5f6b;_0x55c756[_0x5084bb(0x219)](0xcc)[_0x5084bb(0x22f)]();});};}function handleEntityNotFound(_0x56401c){return function(_0x435d32){const _0x1623a3=a505_0x3e9d;return!_0x435d32&&_0x56401c[_0x1623a3(0x1eb)](0x194),_0x435d32;};}function handleError(_0x283250,_0x458f47){return _0x458f47=_0x458f47||0x1f4,function(_0x4084a0){const _0x43cd4d=a505_0x3e9d;logger['error'](_0x4084a0[_0x43cd4d(0x255)]),_0x4084a0[_0x43cd4d(0x251)]&&delete _0x4084a0[_0x43cd4d(0x251)],_0x283250[_0x43cd4d(0x219)](_0x458f47)['send'](_0x4084a0);};}exports[a505_0x4c7904(0x211)]=function(_0x5c6d78,_0x127fc1){const _0x2a8483=a505_0x4c7904;let _0xeacf4a={};const _0x1ce5ad={},_0x4d9e2f={'count':0x0,'rows':[]},_0x2337cb=_[_0x2a8483(0x23d)](db[_0x2a8483(0x20c)][_0x2a8483(0x242)],function(_0x25bf0e){const _0x2ca7b0=_0x2a8483;return{'name':_0x25bf0e[_0x2ca7b0(0x22d)],'type':_0x25bf0e['type'][_0x2ca7b0(0x1f7)]};});_0x1ce5ad['model']=_[_0x2a8483(0x23d)](_0x2337cb,_0x2a8483(0x251)),_0x1ce5ad['query']=_[_0x2a8483(0x1f5)](_0x5c6d78[_0x2a8483(0x256)]),_0x1ce5ad[_0x2a8483(0x248)]=_[_0x2a8483(0x1e6)](_0x1ce5ad[_0x2a8483(0x249)],_0x1ce5ad[_0x2a8483(0x256)]),_0xeacf4a[_0x2a8483(0x1ee)]=_[_0x2a8483(0x1e6)](_0x1ce5ad[_0x2a8483(0x249)],qs[_0x2a8483(0x220)](_0x5c6d78[_0x2a8483(0x256)][_0x2a8483(0x220)])),_0xeacf4a[_0x2a8483(0x1ee)]=_0xeacf4a['attributes'][_0x2a8483(0x234)]?_0xeacf4a['attributes']:_0x1ce5ad['model'];typeof _0x5c6d78[_0x2a8483(0x256)][_0x2a8483(0x227)]===_0x2a8483(0x24c)&&(_0xeacf4a['limit']=qs[_0x2a8483(0x24b)](_0x5c6d78[_0x2a8483(0x256)]['limit']),_0xeacf4a['offset']=qs[_0x2a8483(0x1ea)](_0x5c6d78[_0x2a8483(0x256)]['offset']));_0xeacf4a[_0x2a8483(0x209)]=qs[_0x2a8483(0x205)](_0x5c6d78[_0x2a8483(0x256)][_0x2a8483(0x205)]),_0xeacf4a['where']=qs[_0x2a8483(0x248)](_[_0x2a8483(0x207)](_0x5c6d78[_0x2a8483(0x256)],_0x1ce5ad['filters']),_0x2337cb);_0x5c6d78['query'][_0x2a8483(0x21a)]&&(_0xeacf4a['where']=_[_0x2a8483(0x204)](_0xeacf4a[_0x2a8483(0x217)],{[Op['or']]:_[_0x2a8483(0x23d)](_0x2337cb,function(_0x212abb){const _0x3c5941=_0x2a8483;if(_0x212abb[_0x3c5941(0x24a)]!==_0x3c5941(0x224)){const _0x81b9a6={};return _0x81b9a6[_0x212abb[_0x3c5941(0x251)]]={[Op[_0x3c5941(0x238)]]:'%'+_0x5c6d78[_0x3c5941(0x256)]['filter']+'%'},_0x81b9a6;}})}));_0xeacf4a=_[_0x2a8483(0x204)]({},_0xeacf4a,_0x5c6d78['options']);const _0x82b762={'where':_0xeacf4a['where']};return db[_0x2a8483(0x20c)]['count'](_0x82b762)['then'](function(_0x4092d1){const _0x4c7f76=_0x2a8483;return _0x4d9e2f[_0x4c7f76(0x1ef)]=_0x4092d1,_0x5c6d78['query'][_0x4c7f76(0x213)]&&(_0xeacf4a[_0x4c7f76(0x22a)]=[{'all':!![]}]),db[_0x4c7f76(0x20c)][_0x4c7f76(0x22e)](_0xeacf4a);})['then'](function(_0x4a9848){return _0x4d9e2f['rows']=_0x4a9848,_0x4d9e2f;})[_0x2a8483(0x24f)](respondWithFilteredResult(_0x127fc1,_0xeacf4a))[_0x2a8483(0x23c)](handleError(_0x127fc1,null));},exports[a505_0x4c7904(0x202)]=function(_0x362af5,_0x59751d){const _0x46ada7=a505_0x4c7904;let _0x1e30d7={'raw':!![],'where':{'id':_0x362af5[_0x46ada7(0x23f)]['id']}};const _0x13136b={};return _0x13136b[_0x46ada7(0x249)]=_['keys'](db['MailQueue'][_0x46ada7(0x242)]),_0x13136b[_0x46ada7(0x256)]=_['keys'](_0x362af5[_0x46ada7(0x256)]),_0x13136b[_0x46ada7(0x248)]=_[_0x46ada7(0x1e6)](_0x13136b[_0x46ada7(0x249)],_0x13136b[_0x46ada7(0x256)]),_0x1e30d7['attributes']=_[_0x46ada7(0x1e6)](_0x13136b[_0x46ada7(0x249)],qs[_0x46ada7(0x220)](_0x362af5[_0x46ada7(0x256)][_0x46ada7(0x220)])),_0x1e30d7[_0x46ada7(0x1ee)]=_0x1e30d7[_0x46ada7(0x1ee)][_0x46ada7(0x234)]?_0x1e30d7[_0x46ada7(0x1ee)]:_0x13136b[_0x46ada7(0x249)],_0x362af5['query']['includeAll']&&(_0x1e30d7[_0x46ada7(0x22a)]=[{'all':!![]}]),_0x1e30d7=_[_0x46ada7(0x204)]({},_0x1e30d7,_0x362af5[_0x46ada7(0x212)]),db[_0x46ada7(0x20c)][_0x46ada7(0x23a)](_0x1e30d7)[_0x46ada7(0x24f)](handleEntityNotFound(_0x59751d,null))[_0x46ada7(0x24f)](respondWithResult(_0x59751d,null))[_0x46ada7(0x23c)](handleError(_0x59751d,null));},exports[a505_0x4c7904(0x250)]=function(_0x3b81a9,_0x1abb19){const _0x4f077c=a505_0x4c7904;return db[_0x4f077c(0x20c)]['create'](_0x3b81a9[_0x4f077c(0x22b)],{})[_0x4f077c(0x24f)](function(_0x35cdb9){const _0x479448=_0x4f077c,_0x3aae7e=_0x3b81a9['user'][_0x479448(0x1e7)]({'plain':!![]});if(!_0x3aae7e)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3aae7e[_0x479448(0x21b)]==='user'){const _0x401f17=_0x35cdb9[_0x479448(0x1e7)]({'plain':!![]}),_0x3a173a=_0x479448(0x201);return db['UserProfileSection']['findOne']({'where':{'name':_0x3a173a,'userProfileId':_0x3aae7e['userProfileId']},'raw':!![]})['then'](function(_0x571fb5){const _0x5d7ffe=_0x479448;return _0x571fb5&&_0x571fb5[_0x5d7ffe(0x22c)]===0x0?db[_0x5d7ffe(0x24e)][_0x5d7ffe(0x250)]({'name':_0x401f17['name'],'resourceId':_0x401f17['id'],'type':_0x571fb5['name'],'sectionId':_0x571fb5['id']},{})[_0x5d7ffe(0x24f)](function(){return _0x35cdb9;}):_0x35cdb9;})['catch'](function(_0x520519){const _0x380dac=_0x479448;logger[_0x380dac(0x243)](_0x380dac(0x1f6),_0x520519);throw _0x520519;});}return _0x35cdb9;})[_0x4f077c(0x24f)](respondWithResult(_0x1abb19,0xc9))[_0x4f077c(0x23c)](handleError(_0x1abb19,null));},exports['update']=function(_0x3fc9f1,_0x1165fd){const _0x51c4b9=a505_0x4c7904;return _0x3fc9f1[_0x51c4b9(0x22b)]['id']&&delete _0x3fc9f1[_0x51c4b9(0x22b)]['id'],db['MailQueue'][_0x51c4b9(0x23a)]({'where':{'id':_0x3fc9f1[_0x51c4b9(0x23f)]['id']}})[_0x51c4b9(0x24f)](handleEntityNotFound(_0x1165fd,null))[_0x51c4b9(0x24f)](saveUpdates(_0x3fc9f1[_0x51c4b9(0x22b)],null))[_0x51c4b9(0x24f)](respondWithResult(_0x1165fd,null))[_0x51c4b9(0x23c)](handleError(_0x1165fd,null));},exports[a505_0x4c7904(0x1f3)]=function(_0x524bd5,_0x15016c){const _0x3c4b55=a505_0x4c7904;return db[_0x3c4b55(0x20c)][_0x3c4b55(0x23a)]({'where':{'id':_0x524bd5['params']['id']}})[_0x3c4b55(0x24f)](handleEntityNotFound(_0x15016c,null))['then'](removeEntity(_0x15016c,null))[_0x3c4b55(0x23c)](handleError(_0x15016c,null));},exports[a505_0x4c7904(0x20b)]=function(_0x199a86,_0x183026){const _0x56e762=a505_0x4c7904;return db['MailQueue'][_0x56e762(0x20b)]()[_0x56e762(0x24f)](respondWithResult(_0x183026,null))['catch'](handleError(_0x183026,null));},exports[a505_0x4c7904(0x222)]=function(_0x2e7630,_0x240d4e){const _0x19ee59=a505_0x4c7904;let _0x570158={'raw':!![],'where':{}};const _0x30293c={};let _0x209d0b;return db[_0x19ee59(0x20c)][_0x19ee59(0x23a)]({'where':{'id':_0x2e7630[_0x19ee59(0x23f)]['id']}})[_0x19ee59(0x24f)](handleEntityNotFound(_0x240d4e,null))['then'](function(_0x297c37){const _0x150b10=_0x19ee59;if(_0x297c37)return _0x209d0b=_0x297c37[_0x150b10(0x1e7)]({'plain':!![]}),_0x30293c[_0x150b10(0x249)]=_[_0x150b10(0x1f5)](db[_0x150b10(0x232)]['rawAttributes']),_0x30293c[_0x150b10(0x256)]=_[_0x150b10(0x1f5)](_0x2e7630['query']),_0x30293c['filters']=_[_0x150b10(0x1e6)](_0x30293c[_0x150b10(0x249)],_0x30293c[_0x150b10(0x256)]),_0x570158[_0x150b10(0x1ee)]=_['intersection'](_0x30293c[_0x150b10(0x249)],qs[_0x150b10(0x220)](_0x2e7630[_0x150b10(0x256)][_0x150b10(0x220)])),_0x570158[_0x150b10(0x1ee)]=_0x570158[_0x150b10(0x1ee)][_0x150b10(0x234)]?_0x570158[_0x150b10(0x1ee)]:_0x30293c[_0x150b10(0x249)],typeof _0x2e7630['query']['nolimit']===_0x150b10(0x24c)&&(_0x570158[_0x150b10(0x24b)]=qs[_0x150b10(0x24b)](_0x2e7630[_0x150b10(0x256)][_0x150b10(0x24b)]),_0x570158[_0x150b10(0x1ea)]=qs[_0x150b10(0x1ea)](_0x2e7630[_0x150b10(0x256)][_0x150b10(0x1ea)])),_0x570158[_0x150b10(0x209)]=qs[_0x150b10(0x205)](_0x2e7630[_0x150b10(0x256)][_0x150b10(0x205)]),_0x570158[_0x150b10(0x217)]=qs[_0x150b10(0x248)](_[_0x150b10(0x207)](_0x2e7630[_0x150b10(0x256)],_0x30293c[_0x150b10(0x248)])),_0x570158[_0x150b10(0x217)][_0x150b10(0x1e9)]=_0x297c37['id'],_0x2e7630[_0x150b10(0x256)]['filter']&&(_0x570158[_0x150b10(0x217)]=_['merge'](_0x570158['where'],{[Op['or']]:_['map'](_0x570158[_0x150b10(0x1ee)],function(_0x5eb686){const _0x470ae5=_0x150b10,_0x3380b2={};return _0x3380b2[_0x5eb686]={[Op['like']]:'%'+_0x2e7630[_0x470ae5(0x256)][_0x470ae5(0x21a)]+'%'},_0x3380b2;})})),_0x570158=_[_0x150b10(0x204)]({},_0x570158,_0x2e7630[_0x150b10(0x212)]),db[_0x150b10(0x232)][_0x150b10(0x22e)](_0x570158);})[_0x19ee59(0x24f)](function(_0x1cc7b7){const _0x215e7a=_0x19ee59;if(_0x1cc7b7)return db[_0x215e7a(0x21f)][_0x215e7a(0x1fb)]({'where':{'id':_[_0x215e7a(0x23d)](_0x1cc7b7,'UserId'),'role':_0x215e7a(0x215)},'attributes':['id',_0x215e7a(0x251),_0x215e7a(0x1f9),'updatedAt',_0x215e7a(0x21e)]});})[_0x19ee59(0x24f)](function(_0x4e7451){const _0x4e7fa2=_0x19ee59;return _0x4e7451?{'count':_0x4e7451[_0x4e7fa2(0x1ef)],'rows':_[_0x4e7fa2(0x23d)](_0x4e7451[_0x4e7fa2(0x221)],function(_0x18b290){const _0x11b28b=_0x4e7fa2;return{'membername':_0x18b290[_0x11b28b(0x251)],'UserId':_0x18b290['id'],'queue_name':_0x209d0b[_0x11b28b(0x251)],'MailQueueId':_0x209d0b['id'],'interface':util[_0x11b28b(0x1f0)]('%s/%s',_0x11b28b(0x226),_0x18b290[_0x11b28b(0x251)]),'penalty':0x0,'paused':_0x18b290[_0x11b28b(0x1f9)],'createdAt':_0x18b290[_0x11b28b(0x21e)],'updatedAt':_0x18b290[_0x11b28b(0x245)]};})}:{'count':0x0,'rows':[]};})[_0x19ee59(0x24f)](respondWithFilteredResult(_0x240d4e,_0x570158))[_0x19ee59(0x23c)](handleError(_0x240d4e,null));},exports[a505_0x4c7904(0x228)]=function(_0x3e81dd,_0xbd5d0){const _0x9e0c37=a505_0x4c7904;let _0x51b3bc={};const _0x4db4c2={};let _0x153d3e,_0x48aa22;return db[_0x9e0c37(0x20c)][_0x9e0c37(0x23a)]({'where':{'id':_0x3e81dd[_0x9e0c37(0x23f)]['id']}})[_0x9e0c37(0x24f)](handleEntityNotFound(_0xbd5d0,null))['then'](function(_0x141242){const _0x597d5e=_0x9e0c37;if(_0x141242)return _0x153d3e=_0x141242,_0x4db4c2['model']=_[_0x597d5e(0x1f5)](db[_0x597d5e(0x246)]['rawAttributes']),_0x4db4c2[_0x597d5e(0x256)]=_[_0x597d5e(0x1f5)](_0x3e81dd[_0x597d5e(0x256)]),_0x4db4c2['filters']=_[_0x597d5e(0x1e6)](_0x4db4c2['model'],_0x4db4c2[_0x597d5e(0x256)]),_0x51b3bc[_0x597d5e(0x1ee)]=_[_0x597d5e(0x1e6)](_0x4db4c2[_0x597d5e(0x249)],qs['fields'](_0x3e81dd[_0x597d5e(0x256)][_0x597d5e(0x220)])),_0x51b3bc['attributes']=_0x51b3bc[_0x597d5e(0x1ee)][_0x597d5e(0x234)]?_0x51b3bc['attributes']:_0x4db4c2['model'],_0x51b3bc[_0x597d5e(0x209)]=qs[_0x597d5e(0x205)](_0x3e81dd[_0x597d5e(0x256)][_0x597d5e(0x205)]),_0x51b3bc[_0x597d5e(0x217)]=qs[_0x597d5e(0x248)](_[_0x597d5e(0x207)](_0x3e81dd[_0x597d5e(0x256)],_0x4db4c2[_0x597d5e(0x248)])),_0x3e81dd['query'][_0x597d5e(0x21a)]&&(_0x51b3bc[_0x597d5e(0x217)]=_[_0x597d5e(0x204)](_0x51b3bc[_0x597d5e(0x217)],{[Op['or']]:_[_0x597d5e(0x23d)](_0x51b3bc['attributes'],function(_0x1deca0){const _0x21974d=_0x597d5e,_0x177f93={};return _0x177f93[_0x1deca0]={[Op[_0x21974d(0x238)]]:'%'+_0x3e81dd[_0x21974d(0x256)][_0x21974d(0x21a)]+'%'},_0x177f93;})})),_0x51b3bc=_[_0x597d5e(0x204)]({},_0x51b3bc,_0x3e81dd[_0x597d5e(0x212)]),_0x153d3e[_0x597d5e(0x228)](_0x51b3bc);})[_0x9e0c37(0x24f)](function(_0x263c91){const _0x175f75=_0x9e0c37;if(_0x263c91)return _0x48aa22=_0x263c91['length'],typeof _0x3e81dd[_0x175f75(0x256)][_0x175f75(0x227)]===_0x175f75(0x24c)&&(_0x51b3bc['limit']=qs[_0x175f75(0x24b)](_0x3e81dd['query']['limit']),_0x51b3bc['offset']=qs[_0x175f75(0x1ea)](_0x3e81dd['query']['offset'])),_0x153d3e['getTeams'](_0x51b3bc);})[_0x9e0c37(0x24f)](function(_0x2e6c97){if(_0x2e6c97)return _0x2e6c97?{'count':_0x48aa22,'rows':_0x2e6c97}:null;})[_0x9e0c37(0x24f)](respondWithResult(_0xbd5d0,null))[_0x9e0c37(0x23c)](handleError(_0xbd5d0,null));},exports['addTeams']=function(_0x2aec27,_0x4ee046){const _0x3fd68b=a505_0x4c7904,_0x5578bb=_0x2aec27[_0x3fd68b(0x22b)][_0x3fd68b(0x1fe)];return db[_0x3fd68b(0x246)]['findAll']({'where':{'id':_0x5578bb},'attributes':['id'],'include':[{'model':db['User'],'as':_0x3fd68b(0x1e8),'attributes':['id','name',_0x3fd68b(0x239),_0x3fd68b(0x247),'interface'],'raw':!![]}]})[_0x3fd68b(0x24f)](function(_0x433f60){const _0xeede7d=_0x3fd68b;if(_0x433f60){const _0x19feca=_['flatMap'](_0x433f60,function(_0x373553){const _0x46a247=a505_0x3e9d,_0x269e53=_0x373553[_0x46a247(0x1e7)]({'plain':!![]});return _0x269e53[_0x46a247(0x1e8)];});return db[_0xeede7d(0x20c)]['findOne']({'where':{'id':_0x2aec27[_0xeede7d(0x23f)]['id']}})[_0xeede7d(0x24f)](function(_0xfacc74){const _0x1d8570=_0xeede7d;return db[_0x1d8570(0x230)]['transaction'](function(_0x5cfc5b){const _0x5eb4ba=_0x1d8570;return _0xfacc74[_0x5eb4ba(0x23b)](_0x5578bb,{'transaction':_0x5cfc5b})['then'](function(){const _0x916d7=_0x5eb4ba;return Promise[_0x916d7(0x233)](_0x19feca[_0x916d7(0x23d)](_0x1c3323=>{const _0x489966=_0x916d7;return db[_0x489966(0x232)][_0x489966(0x1ff)]({'where':{'UserId':_0x1c3323['id'],'MailQueueId':_0x2aec27[_0x489966(0x23f)]['id']},'transaction':_0x5cfc5b});}));})[_0x5eb4ba(0x24f)](function(){_0x19feca['forEach'](function(_0x300316){socket['emit']('userMailQueue:save',{'UserId':_0x300316['id'],'MailQueueId':_0xfacc74['id']});});});});});}})[_0x3fd68b(0x24f)](respondWithStatusCode(_0x4ee046,null))[_0x3fd68b(0x23c)](handleError(_0x4ee046,null));},exports[a505_0x4c7904(0x21d)]=function(_0x4c6b85,_0xadfe8e){const _0x275c49=a505_0x4c7904;return db[_0x275c49(0x246)][_0x275c49(0x22e)]({'where':{'id':_0x4c6b85['query'][_0x275c49(0x1fe)]},'attributes':['id'],'include':[{'model':db[_0x275c49(0x21f)],'as':_0x275c49(0x1e8),'attributes':['id'],'raw':!![]}]})[_0x275c49(0x24f)](handleEntityNotFound(_0xadfe8e,null))[_0x275c49(0x24f)](function(_0x5024dd){const _0x465bb5=_0x275c49,_0x4681b7=_[_0x465bb5(0x23d)](_0x5024dd,'id');let _0x37e5b3=[];const _0x5d683a=[],_0x152965=squel[_0x465bb5(0x235)]();_0x152965['field']('tq.TeamId')[_0x465bb5(0x20d)]('team_has_mail_queues','tq')[_0x465bb5(0x1fd)](_0x465bb5(0x20f),'ut',_0x465bb5(0x20a))[_0x465bb5(0x217)](_0x465bb5(0x1fc),_0x4c6b85[_0x465bb5(0x23f)]['id']);for(let _0x25d16d=0x0;_0x25d16d<_0x5024dd[_0x465bb5(0x234)];_0x25d16d+=0x1){const _0x1fd27c=_0x5024dd[_0x25d16d];for(let _0x403a61=0x0;_0x403a61<_0x1fd27c[_0x465bb5(0x1e8)][_0x465bb5(0x234)];_0x403a61+=0x1){const _0xc386c8=_0x1fd27c[_0x465bb5(0x1e8)][_0x403a61],_0x4fc5d9=_0x152965[_0x465bb5(0x1fa)]();_0x4fc5d9[_0x465bb5(0x217)](_0x465bb5(0x1f4),_0xc386c8['id']),_0x5d683a['push'](db[_0x465bb5(0x230)][_0x465bb5(0x256)](_0x4fc5d9[_0x465bb5(0x200)](),{'type':QueryTypes['SELECT']})[_0x465bb5(0x24f)](function(_0x1bc254){const _0x200f1c=_0x465bb5;if(_0x1bc254[_0x200f1c(0x234)]===0x1)return _0xc386c8['id'];else{const _0x280526=_[_0x200f1c(0x203)](_[_0x200f1c(0x23d)](_0x1bc254,_0x200f1c(0x231)),function(_0x3a7e91){return _['includes'](_0x4681b7,_0x3a7e91);});if(_0x280526)return _0xc386c8['id'];}}));}}return Promise['all'](_0x5d683a)[_0x465bb5(0x24f)](function(_0x463a35){const _0x493a07=_0x465bb5;return _0x37e5b3=_(_0x37e5b3)[_0x493a07(0x241)](_0x463a35)[_0x493a07(0x20e)]()[_0x493a07(0x1ed)](),db[_0x493a07(0x20c)]['findOne']({'where':{'id':_0x4c6b85[_0x493a07(0x23f)]['id']}})['then'](function(_0x5f3862){const _0x4e5056=_0x493a07;return db[_0x4e5056(0x230)][_0x4e5056(0x229)](function(_0x11ccda){const _0x30279b=_0x4e5056;return _0x5f3862[_0x30279b(0x21d)](_0x4c6b85[_0x30279b(0x256)]['ids'],{'transaction':_0x11ccda})['then'](function(){const _0x15f238=_0x30279b;if(!_[_0x15f238(0x254)](_0x37e5b3))return _0x5f3862[_0x15f238(0x1f2)](_0x37e5b3,{'transaction':_0x11ccda});})[_0x30279b(0x24f)](function(){const _0x25b7b6=_0x30279b;_0x37e5b3[_0x25b7b6(0x1f8)](function(_0x61fde6){const _0x5d198f=_0x25b7b6;socket[_0x5d198f(0x225)](_0x5d198f(0x240),{'UserId':_0x61fde6,'MailQueueId':_0x5f3862['id']});});});});});});})[_0x275c49(0x24f)](respondWithStatusCode(_0xadfe8e,null))[_0x275c49(0x23c)](handleError(_0xadfe8e,null));},exports[a505_0x4c7904(0x1ec)]=function(_0x19db20,_0x4ba8c5){const _0x553452=a505_0x4c7904;return db['MailQueue']['findOne']({'where':{'id':_0x19db20['params']['id']}})[_0x553452(0x24f)](function(_0x34ca7d){const _0x9b41d9=_0x553452;if(_0x34ca7d)return _0x34ca7d[_0x9b41d9(0x1ec)](_0x19db20[_0x9b41d9(0x22b)][_0x9b41d9(0x1fe)],{'through':_[_0x9b41d9(0x23e)](_0x19db20[_0x9b41d9(0x22b)],['ids','id'])})['then'](function(_0xd296dd){const _0x28689b=_0x9b41d9;for(let _0x563a1d=0x0;_0x563a1d<_0x19db20[_0x28689b(0x22b)][_0x28689b(0x1fe)][_0x28689b(0x234)];_0x563a1d+=0x1){socket[_0x28689b(0x225)]('userMailQueue:save',{'UserId':_0x19db20['body']['ids'][_0x563a1d],'MailQueueId':_0x19db20['params']['id']});}return _0xd296dd;});})[_0x553452(0x24f)](respondWithResult(_0x4ba8c5,null))['catch'](handleError(_0x4ba8c5,null));},exports['removeAgents']=function(_0x57f0f4,_0x3f9553){const _0x3e92a1=a505_0x4c7904;return db['MailQueue'][_0x3e92a1(0x23a)]({'where':{'id':_0x57f0f4['params']['id']}})[_0x3e92a1(0x24f)](handleEntityNotFound(_0x3f9553,null))[_0x3e92a1(0x24f)](function(_0x3c7a47){const _0x198d70=_0x3e92a1;if(_0x3c7a47)return _0x3c7a47[_0x198d70(0x1f2)](_0x57f0f4['query'][_0x198d70(0x1fe)])[_0x198d70(0x24f)](function(){const _0x31f333=_0x198d70;if(_[_0x31f333(0x237)](_0x57f0f4[_0x31f333(0x256)][_0x31f333(0x1fe)]))for(let _0x3b2a06=0x0;_0x3b2a06<_0x57f0f4[_0x31f333(0x256)][_0x31f333(0x1fe)][_0x31f333(0x234)];_0x3b2a06+=0x1){socket[_0x31f333(0x225)](_0x31f333(0x240),{'UserId':Number(_0x57f0f4['query'][_0x31f333(0x1fe)][_0x3b2a06]),'MailQueueId':Number(_0x57f0f4[_0x31f333(0x23f)]['id'])});}else socket[_0x31f333(0x225)](_0x31f333(0x240),{'UserId':Number(_0x57f0f4[_0x31f333(0x256)][_0x31f333(0x1fe)]),'MailQueueId':Number(_0x57f0f4[_0x31f333(0x23f)]['id'])});});})[_0x3e92a1(0x24f)](respondWithStatusCode(_0x3f9553,null))[_0x3e92a1(0x23c)](handleError(_0x3f9553,null));},exports[a505_0x4c7904(0x244)]=function(_0x41a9df,_0x1e3626){const _0x21684a=a505_0x4c7904;let _0x3ca3ad={};const _0x14be41={};let _0x3469c8,_0x3e6d50;return db[_0x21684a(0x20c)][_0x21684a(0x23a)]({'where':{'id':_0x41a9df[_0x21684a(0x23f)]['id']}})[_0x21684a(0x24f)](handleEntityNotFound(_0x1e3626,null))[_0x21684a(0x24f)](function(_0x301e97){const _0x446b48=_0x21684a;if(_0x301e97)return _0x3469c8=_0x301e97,_0x14be41[_0x446b48(0x249)]=_[_0x446b48(0x1f5)](db[_0x446b48(0x21f)][_0x446b48(0x242)]),_0x14be41[_0x446b48(0x256)]=_['keys'](_0x41a9df[_0x446b48(0x256)]),_0x14be41[_0x446b48(0x248)]=_[_0x446b48(0x1e6)](_0x14be41[_0x446b48(0x249)],_0x14be41[_0x446b48(0x256)]),_0x3ca3ad['attributes']=_['intersection'](_0x14be41[_0x446b48(0x249)],qs[_0x446b48(0x220)](_0x41a9df[_0x446b48(0x256)]['fields'])),_0x3ca3ad[_0x446b48(0x1ee)]=_0x3ca3ad[_0x446b48(0x1ee)][_0x446b48(0x234)]?_0x3ca3ad[_0x446b48(0x1ee)]:_0x14be41[_0x446b48(0x249)],_0x3ca3ad[_0x446b48(0x209)]=qs[_0x446b48(0x205)](_0x41a9df[_0x446b48(0x256)][_0x446b48(0x205)]),_0x3ca3ad[_0x446b48(0x217)]=qs[_0x446b48(0x248)](_[_0x446b48(0x207)](_0x41a9df[_0x446b48(0x256)],_0x14be41[_0x446b48(0x248)])),_0x41a9df[_0x446b48(0x256)][_0x446b48(0x21a)]&&(_0x3ca3ad[_0x446b48(0x217)]=_[_0x446b48(0x204)](_0x3ca3ad['where'],{[Op['or']]:_[_0x446b48(0x23d)](_0x3ca3ad[_0x446b48(0x1ee)],function(_0x199112){const _0x1fb358=_0x446b48,_0x468215={};return _0x468215[_0x199112]={[Op[_0x1fb358(0x238)]]:'%'+_0x41a9df[_0x1fb358(0x256)][_0x1fb358(0x21a)]+'%'},_0x468215;})})),_0x3ca3ad=_[_0x446b48(0x204)]({},_0x3ca3ad,_0x41a9df[_0x446b48(0x212)]),_0x3469c8['getAgents'](_0x3ca3ad);})[_0x21684a(0x24f)](function(_0x323eae){const _0x106ba0=_0x21684a;if(_0x323eae)return _0x3e6d50=_0x323eae[_0x106ba0(0x234)],typeof _0x41a9df[_0x106ba0(0x256)][_0x106ba0(0x227)]==='undefined'&&(_0x3ca3ad['limit']=qs[_0x106ba0(0x24b)](_0x41a9df['query'][_0x106ba0(0x24b)]),_0x3ca3ad[_0x106ba0(0x1ea)]=qs[_0x106ba0(0x1ea)](_0x41a9df[_0x106ba0(0x256)]['offset'])),_0x3469c8['getAgents'](_0x3ca3ad);})[_0x21684a(0x24f)](function(_0x5172c5){if(_0x5172c5)return _0x5172c5?{'count':_0x3e6d50,'rows':_0x5172c5}:null;})['then'](respondWithResult(_0x1e3626,null))[_0x21684a(0x23c)](handleError(_0x1e3626,null));};