Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / smsQueue / smsQueue.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 _0xadb5=['%s/%s','pick','filter','getTeams','addTeams','ids','findAll','online','voicePause','interface','flatMap','Agents','sequelize','transaction','each','forEach','userSmsQueue:save','removeTeams','Team','field','tq.TeamId','from','team_has_sms_queues','join','ut.TeamId\x20=\x20tq.TeamId','SmsQueueId\x20=\x20?','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','all','union','compact','value','find','isEmpty','removeAgents','emit','userSmsQueue:remove','addAgents','omit','spread','isArray','getAgents','util','squel','ioredis','../../components/parsers/qs','api','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./smsQueue.socket','register','sendStatus','status','end','json','offset','limit','undefined','set','Content-Range','update','then','destroy','SmsQueues','UserProfileResource','error','stack','name','send','index','SmsQueue','rawAttributes','type','key','getOptions','where','count','include','query','rows','catch','show','model','keys','filters','fields','attributes','length','includeAll','options','create','user','get','role','autoAssociation','body','params','describe','getMembers','findOne','intersection','hasOwnProperty','nolimit','order','sort','SmsQueueId','merge','UserSmsQueue','User','findAndCountAll','map','UserId','agent','smsPause','updatedAt','createdAt','format'];(function(_0x2b55b5,_0x78505e){var _0x103d28=function(_0x5095a2){while(--_0x5095a2){_0x2b55b5['push'](_0x2b55b5['shift']());}};_0x103d28(++_0x78505e);}(_0xadb5,0xad));var _0x5adb=function(_0x1b3e9e,_0x299251){_0x1b3e9e=_0x1b3e9e-0x0;var _0x588359=_0xadb5[_0x1b3e9e];return _0x588359;};'use strict';var BPromise=require('bluebird');var util=require(_0x5adb('0x0'));var _=require('lodash');var squel=require(_0x5adb('0x1'));var Redis=require(_0x5adb('0x2'));var qs=require(_0x5adb('0x3'));var logger=require('../../config/logger')(_0x5adb('0x4'));var config=require(_0x5adb('0x5'));var db=require(_0x5adb('0x6'))['db'];config['redis']=_[_0x5adb('0x7')](config[_0x5adb('0x8')],{'host':_0x5adb('0x9'),'port':0x18eb});var socket=require(_0x5adb('0xa'))(new Redis(config[_0x5adb('0x8')]));require(_0x5adb('0xb'))[_0x5adb('0xc')](socket);function respondWithStatusCode(_0x6d1b45,_0x41261c){_0x41261c=_0x41261c||0xcc;return function(_0x7293ab){if(_0x7293ab){return _0x6d1b45[_0x5adb('0xd')](_0x41261c);}return _0x6d1b45[_0x5adb('0xe')](_0x41261c)[_0x5adb('0xf')]();};}function respondWithResult(_0x275428,_0x563d86){_0x563d86=_0x563d86||0xc8;return function(_0x4c268d){if(_0x4c268d){return _0x275428[_0x5adb('0xe')](_0x563d86)[_0x5adb('0x10')](_0x4c268d);}};}function respondWithFilteredResult(_0x82e67e,_0x53b772){return function(_0x29f0d5){if(_0x29f0d5){var _0x56012f=typeof _0x53b772[_0x5adb('0x11')]==='undefined'&&typeof _0x53b772[_0x5adb('0x12')]===_0x5adb('0x13');var _0x44abe3=_0x29f0d5['count'];var _0x2a545b=_0x56012f?0x0:_0x53b772[_0x5adb('0x11')];var _0xf82f72=_0x56012f?_0x29f0d5['count']:_0x53b772[_0x5adb('0x11')]+_0x53b772['limit'];var _0x367d82;if(_0xf82f72>=_0x44abe3){_0xf82f72=_0x44abe3;_0x367d82=0xc8;}else{_0x367d82=0xce;}_0x82e67e[_0x5adb('0xe')](_0x367d82);return _0x82e67e[_0x5adb('0x14')](_0x5adb('0x15'),_0x2a545b+'-'+_0xf82f72+'/'+_0x44abe3)[_0x5adb('0x10')](_0x29f0d5);}return null;};}function saveUpdates(_0x39d24d){return function(_0xa29dc){if(_0xa29dc){return _0xa29dc[_0x5adb('0x16')](_0x39d24d)[_0x5adb('0x17')](function(_0x529b65){return _0x529b65;});}return null;};}function removeEntity(_0x3fff62){return function(_0x5de028){if(_0x5de028){return _0x5de028[_0x5adb('0x18')]()['then'](function(){var _0x3ef465=_0x5de028['get']({'plain':!![]});var _0x5e218c=_0x5adb('0x19');return db[_0x5adb('0x1a')][_0x5adb('0x18')]({'where':{'type':_0x5e218c,'resourceId':_0x3ef465['id']}})[_0x5adb('0x17')](function(){return _0x5de028;});})[_0x5adb('0x17')](function(){_0x3fff62['status'](0xcc)[_0x5adb('0xf')]();});}};}function handleEntityNotFound(_0x5c296e){return function(_0x4e9f16){if(!_0x4e9f16){_0x5c296e[_0x5adb('0xd')](0x194);}return _0x4e9f16;};}function handleError(_0x379b33,_0x1a38d3){_0x1a38d3=_0x1a38d3||0x1f4;return function(_0x1a8014){logger[_0x5adb('0x1b')](_0x1a8014[_0x5adb('0x1c')]);if(_0x1a8014[_0x5adb('0x1d')]){delete _0x1a8014['name'];}_0x379b33[_0x5adb('0xe')](_0x1a38d3)[_0x5adb('0x1e')](_0x1a8014);};}exports[_0x5adb('0x1f')]=function(_0x3839fb,_0xeb556c){var _0x49f203={};var _0x2fee18={'count':0x0,'rows':[]};var _0x2e1e63=_['map'](db[_0x5adb('0x20')][_0x5adb('0x21')],function(_0x1a0acd){return{'name':_0x1a0acd['fieldName'],'type':_0x1a0acd[_0x5adb('0x22')][_0x5adb('0x23')]};});_0x49f203=qs[_0x5adb('0x24')](_0x2e1e63,_0x3839fb);var _0x2c64a3={'where':_0x49f203[_0x5adb('0x25')]};return db[_0x5adb('0x20')]['count'](_0x2c64a3)['then'](function(_0x5d457e){_0x2fee18[_0x5adb('0x26')]=_0x5d457e;_0x49f203[_0x5adb('0x27')]=qs[_0x5adb('0x27')](_0x3839fb[_0x5adb('0x28')]);return db[_0x5adb('0x20')]['findAll'](_0x49f203);})[_0x5adb('0x17')](function(_0x34b793){_0x2fee18[_0x5adb('0x29')]=_0x34b793;return _0x2fee18;})[_0x5adb('0x17')](respondWithFilteredResult(_0xeb556c,_0x49f203))[_0x5adb('0x2a')](handleError(_0xeb556c,null));};exports[_0x5adb('0x2b')]=function(_0x28190d,_0x28bf1f){var _0x138bf6={'raw':!![],'where':{'id':_0x28190d['params']['id']}},_0x260295={};_0x260295[_0x5adb('0x2c')]=_['keys'](db[_0x5adb('0x20')][_0x5adb('0x21')]);_0x260295['query']=_[_0x5adb('0x2d')](_0x28190d[_0x5adb('0x28')]);_0x260295[_0x5adb('0x2e')]=_['intersection'](_0x260295[_0x5adb('0x2c')],_0x260295[_0x5adb('0x28')]);_0x138bf6['attributes']=_['intersection'](_0x260295[_0x5adb('0x2c')],qs['fields'](_0x28190d[_0x5adb('0x28')][_0x5adb('0x2f')]));_0x138bf6[_0x5adb('0x30')]=_0x138bf6[_0x5adb('0x30')][_0x5adb('0x31')]?_0x138bf6['attributes']:_0x260295[_0x5adb('0x2c')];if(_0x28190d[_0x5adb('0x28')][_0x5adb('0x32')]){_0x138bf6['include']=[{'all':!![]}];}_0x138bf6=_['merge']({},_0x138bf6,_0x28190d[_0x5adb('0x33')]);return db[_0x5adb('0x20')]['find'](_0x138bf6)[_0x5adb('0x17')](handleEntityNotFound(_0x28bf1f,null))['then'](respondWithResult(_0x28bf1f,null))[_0x5adb('0x2a')](handleError(_0x28bf1f,null));};exports['create']=function(_0x11cb37,_0x4d052f){return db[_0x5adb('0x20')][_0x5adb('0x34')](_0x11cb37['body'],{})[_0x5adb('0x17')](function(_0x5a6a79){var _0xadbe37=_0x11cb37[_0x5adb('0x35')][_0x5adb('0x36')]({'plain':!![]});if(!_0xadbe37)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0xadbe37[_0x5adb('0x37')]===_0x5adb('0x35')){var _0xcdaf8e=_0x5a6a79[_0x5adb('0x36')]({'plain':!![]});var _0x22aa95='SmsQueues';return db['UserProfileSection']['find']({'where':{'name':_0x22aa95,'userProfileId':_0xadbe37['userProfileId']},'raw':!![]})[_0x5adb('0x17')](function(_0x2fbe14){if(_0x2fbe14&&_0x2fbe14[_0x5adb('0x38')]===0x0){return db[_0x5adb('0x1a')][_0x5adb('0x34')]({'name':_0xcdaf8e[_0x5adb('0x1d')],'resourceId':_0xcdaf8e['id'],'type':_0x2fbe14[_0x5adb('0x1d')],'sectionId':_0x2fbe14['id']},{})[_0x5adb('0x17')](function(){return _0x5a6a79;});}else{return _0x5a6a79;}})['catch'](function(_0x53f2c6){logger[_0x5adb('0x1b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x53f2c6);throw _0x53f2c6;});}return _0x5a6a79;})[_0x5adb('0x17')](respondWithResult(_0x4d052f,0xc9))[_0x5adb('0x2a')](handleError(_0x4d052f,null));};exports[_0x5adb('0x16')]=function(_0x121714,_0xdfecfd){if(_0x121714['body']['id']){delete _0x121714[_0x5adb('0x39')]['id'];}return db[_0x5adb('0x20')]['find']({'where':{'id':_0x121714[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0xdfecfd,null))['then'](saveUpdates(_0x121714[_0x5adb('0x39')],null))[_0x5adb('0x17')](respondWithResult(_0xdfecfd,null))[_0x5adb('0x2a')](handleError(_0xdfecfd,null));};exports[_0x5adb('0x18')]=function(_0xea3307,_0x4362ec){return db[_0x5adb('0x20')]['find']({'where':{'id':_0xea3307['params']['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x4362ec,null))[_0x5adb('0x17')](removeEntity(_0x4362ec,null))[_0x5adb('0x2a')](handleError(_0x4362ec,null));};exports[_0x5adb('0x3b')]=function(_0x57b8af,_0x507e48){return db[_0x5adb('0x20')][_0x5adb('0x3b')]()[_0x5adb('0x17')](respondWithResult(_0x507e48,null))[_0x5adb('0x2a')](handleError(_0x507e48,null));};exports[_0x5adb('0x3c')]=function(_0x5358c0,_0x182cbc){var _0x437f52={'raw':!![],'where':{}},_0x5b574c={},_0x7786c4;return db[_0x5adb('0x20')][_0x5adb('0x3d')]({'where':{'id':_0x5358c0[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x182cbc,null))[_0x5adb('0x17')](function(_0x39840e){if(_0x39840e){_0x7786c4=_0x39840e[_0x5adb('0x36')]({'plain':!![]});_0x5b574c['model']=_[_0x5adb('0x2d')](db['UserSmsQueue']['rawAttributes']);_0x5b574c['query']=_[_0x5adb('0x2d')](_0x5358c0[_0x5adb('0x28')]);_0x5b574c[_0x5adb('0x2e')]=_['intersection'](_0x5b574c[_0x5adb('0x2c')],_0x5b574c['query']);_0x437f52[_0x5adb('0x30')]=_[_0x5adb('0x3e')](_0x5b574c[_0x5adb('0x2c')],qs['fields'](_0x5358c0[_0x5adb('0x28')]['fields']));_0x437f52[_0x5adb('0x30')]=_0x437f52[_0x5adb('0x30')]['length']?_0x437f52[_0x5adb('0x30')]:_0x5b574c[_0x5adb('0x2c')];if(!_0x5358c0[_0x5adb('0x28')][_0x5adb('0x3f')](_0x5adb('0x40'))){_0x437f52['limit']=qs[_0x5adb('0x12')](_0x5358c0[_0x5adb('0x28')][_0x5adb('0x12')]);_0x437f52[_0x5adb('0x11')]=qs['offset'](_0x5358c0[_0x5adb('0x28')][_0x5adb('0x11')]);}_0x437f52[_0x5adb('0x41')]=qs['sort'](_0x5358c0[_0x5adb('0x28')][_0x5adb('0x42')]);_0x437f52[_0x5adb('0x25')]=qs[_0x5adb('0x2e')](_['pick'](_0x5358c0[_0x5adb('0x28')],_0x5b574c[_0x5adb('0x2e')]));_0x437f52[_0x5adb('0x25')][_0x5adb('0x43')]=_0x39840e['id'];if(_0x5358c0[_0x5adb('0x28')]['filter']){_0x437f52[_0x5adb('0x25')]=_['merge'](_0x437f52[_0x5adb('0x25')],{'$or':_['map'](_0x437f52[_0x5adb('0x30')],function(_0x35df22){var _0x1a9358={};_0x1a9358[_0x35df22]={'$like':'%'+_0x5358c0[_0x5adb('0x28')]['filter']+'%'};return _0x1a9358;})});}_0x437f52=_[_0x5adb('0x44')]({},_0x437f52,_0x5358c0[_0x5adb('0x33')]);return db[_0x5adb('0x45')]['findAll'](_0x437f52);}})['then'](function(_0x4ddfdf){if(_0x4ddfdf){return db[_0x5adb('0x46')][_0x5adb('0x47')]({'where':{'id':_[_0x5adb('0x48')](_0x4ddfdf,_0x5adb('0x49')),'role':_0x5adb('0x4a')},'attributes':['id',_0x5adb('0x1d'),_0x5adb('0x4b'),_0x5adb('0x4c'),_0x5adb('0x4d')]});}})[_0x5adb('0x17')](function(_0x452767){if(_0x452767){return{'count':_0x452767[_0x5adb('0x26')],'rows':_[_0x5adb('0x48')](_0x452767['rows'],function(_0x49f4c8){return{'membername':_0x49f4c8[_0x5adb('0x1d')],'UserId':_0x49f4c8['id'],'queue_name':_0x7786c4[_0x5adb('0x1d')],'SmsQueueId':_0x7786c4['id'],'interface':util[_0x5adb('0x4e')](_0x5adb('0x4f'),'SIP',_0x49f4c8[_0x5adb('0x1d')]),'penalty':0x0,'paused':_0x49f4c8[_0x5adb('0x4b')],'createdAt':_0x49f4c8['createdAt'],'updatedAt':_0x49f4c8[_0x5adb('0x4c')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x5adb('0x17')](respondWithFilteredResult(_0x182cbc,_0x437f52))[_0x5adb('0x2a')](handleError(_0x182cbc,null));};exports['getTeams']=function(_0x30d185,_0x409357){var _0x19df2f={};var _0x30c92c={};var _0x330290;var _0x428019;return db['SmsQueue'][_0x5adb('0x3d')]({'where':{'id':_0x30d185[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x409357,null))['then'](function(_0xcd71d2){if(_0xcd71d2){_0x330290=_0xcd71d2;_0x30c92c[_0x5adb('0x2c')]=_[_0x5adb('0x2d')](db['Team'][_0x5adb('0x21')]);_0x30c92c['query']=_[_0x5adb('0x2d')](_0x30d185[_0x5adb('0x28')]);_0x30c92c[_0x5adb('0x2e')]=_['intersection'](_0x30c92c[_0x5adb('0x2c')],_0x30c92c[_0x5adb('0x28')]);_0x19df2f['attributes']=_[_0x5adb('0x3e')](_0x30c92c[_0x5adb('0x2c')],qs[_0x5adb('0x2f')](_0x30d185[_0x5adb('0x28')]['fields']));_0x19df2f[_0x5adb('0x30')]=_0x19df2f[_0x5adb('0x30')][_0x5adb('0x31')]?_0x19df2f[_0x5adb('0x30')]:_0x30c92c['model'];_0x19df2f['order']=qs[_0x5adb('0x42')](_0x30d185['query']['sort']);_0x19df2f['where']=qs[_0x5adb('0x2e')](_[_0x5adb('0x50')](_0x30d185['query'],_0x30c92c[_0x5adb('0x2e')]));if(_0x30d185[_0x5adb('0x28')][_0x5adb('0x51')]){_0x19df2f[_0x5adb('0x25')]=_[_0x5adb('0x44')](_0x19df2f[_0x5adb('0x25')],{'$or':_[_0x5adb('0x48')](_0x19df2f[_0x5adb('0x30')],function(_0x5240c1){var _0x4b9e80={};_0x4b9e80[_0x5240c1]={'$like':'%'+_0x30d185['query'][_0x5adb('0x51')]+'%'};return _0x4b9e80;})});}_0x19df2f=_[_0x5adb('0x44')]({},_0x19df2f,_0x30d185[_0x5adb('0x33')]);return _0x330290[_0x5adb('0x52')](_0x19df2f);}})[_0x5adb('0x17')](function(_0x2f6ef7){if(_0x2f6ef7){_0x428019=_0x2f6ef7[_0x5adb('0x31')];if(!_0x30d185[_0x5adb('0x28')]['hasOwnProperty']('nolimit')){_0x19df2f[_0x5adb('0x12')]=qs[_0x5adb('0x12')](_0x30d185[_0x5adb('0x28')][_0x5adb('0x12')]);_0x19df2f[_0x5adb('0x11')]=qs[_0x5adb('0x11')](_0x30d185[_0x5adb('0x28')][_0x5adb('0x11')]);}return _0x330290[_0x5adb('0x52')](_0x19df2f);}})[_0x5adb('0x17')](function(_0x484f3d){if(_0x484f3d){return _0x484f3d?{'count':_0x428019,'rows':_0x484f3d}:null;}})[_0x5adb('0x17')](respondWithResult(_0x409357,null))[_0x5adb('0x2a')](handleError(_0x409357,null));};exports[_0x5adb('0x53')]=function(_0x5d3aa4,_0x31f041){var _0xa1bd33=_0x5d3aa4['body'][_0x5adb('0x54')];return db['Team'][_0x5adb('0x55')]({'where':{'id':_0xa1bd33},'attributes':['id'],'include':[{'model':db[_0x5adb('0x46')],'as':'Agents','attributes':['id',_0x5adb('0x1d'),_0x5adb('0x56'),_0x5adb('0x57'),_0x5adb('0x58')],'raw':!![]}]})[_0x5adb('0x17')](function(_0x10f54a){if(_0x10f54a){var _0x3cee6c=_[_0x5adb('0x59')](_0x10f54a,function(_0x49a8a6){var _0x3786b4=_0x49a8a6[_0x5adb('0x36')]({'plain':!![]});return _0x3786b4[_0x5adb('0x5a')];});return db['SmsQueue']['find']({'where':{'id':_0x5d3aa4[_0x5adb('0x3a')]['id']}})['then'](function(_0x27d3d8){return db[_0x5adb('0x5b')][_0x5adb('0x5c')](function(_0x50600f){return _0x27d3d8[_0x5adb('0x53')](_0xa1bd33,{'transaction':_0x50600f})[_0x5adb('0x17')](function(){return BPromise[_0x5adb('0x5d')](_0x3cee6c,function(_0x3ecc56){return db[_0x5adb('0x45')]['findOrCreate']({'where':{'UserId':_0x3ecc56['id'],'SmsQueueId':_0x5d3aa4[_0x5adb('0x3a')]['id']},'transaction':_0x50600f});});})[_0x5adb('0x17')](function(){_0x3cee6c[_0x5adb('0x5e')](function(_0xe3d12d){socket['emit'](_0x5adb('0x5f'),{'UserId':_0xe3d12d['id'],'SmsQueueId':_0x27d3d8['id']});});});});});}})[_0x5adb('0x17')](respondWithStatusCode(_0x31f041,null))[_0x5adb('0x2a')](handleError(_0x31f041,null));};exports[_0x5adb('0x60')]=function(_0x15d4f1,_0x20faf6){return db[_0x5adb('0x61')]['findAll']({'where':{'id':_0x15d4f1[_0x5adb('0x28')][_0x5adb('0x54')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0x5adb('0x5a'),'attributes':['id'],'raw':!![]}]})[_0x5adb('0x17')](handleEntityNotFound(_0x20faf6,null))['then'](function(_0x462fa0){var _0x50f8ed=_[_0x5adb('0x48')](_0x462fa0,'id');var _0x268df2=[];var _0x4a2ebc=[];var _0x167432=squel['select']();_0x167432[_0x5adb('0x62')](_0x5adb('0x63'))[_0x5adb('0x64')](_0x5adb('0x65'),'tq')[_0x5adb('0x66')]('user_has_teams','ut',_0x5adb('0x67'))[_0x5adb('0x25')](_0x5adb('0x68'),_0x15d4f1[_0x5adb('0x3a')]['id']);for(var _0x47c631=0x0;_0x47c631<_0x462fa0['length'];_0x47c631+=0x1){let _0x3f3db9=_0x462fa0[_0x47c631];for(var _0x461a07=0x0;_0x461a07<_0x3f3db9[_0x5adb('0x5a')][_0x5adb('0x31')];_0x461a07+=0x1){let _0x277668=_0x3f3db9[_0x5adb('0x5a')][_0x461a07];var _0x31f5b2=_0x167432['clone']();_0x31f5b2[_0x5adb('0x25')](_0x5adb('0x69'),_0x277668['id']);_0x4a2ebc[_0x5adb('0x6a')](db[_0x5adb('0x5b')]['query'](_0x31f5b2[_0x5adb('0x6b')](),{'type':db[_0x5adb('0x5b')][_0x5adb('0x6c')][_0x5adb('0x6d')]})[_0x5adb('0x17')](function(_0x188cbd){if(_0x188cbd[_0x5adb('0x31')]===0x1){return _0x277668['id'];}else{var _0x2d1b65=_[_0x5adb('0x6e')](_['map'](_0x188cbd,_0x5adb('0x6f')),function(_0x456799){return _['includes'](_0x50f8ed,_0x456799);});if(_0x2d1b65){return _0x277668['id'];}}}));}}return BPromise[_0x5adb('0x70')](_0x4a2ebc)[_0x5adb('0x17')](function(_0x2b8915){_0x268df2=_(_0x268df2)[_0x5adb('0x71')](_0x2b8915)[_0x5adb('0x72')]()[_0x5adb('0x73')]();return db[_0x5adb('0x20')][_0x5adb('0x74')]({'where':{'id':_0x15d4f1['params']['id']}})[_0x5adb('0x17')](function(_0x2386c0){return db['sequelize'][_0x5adb('0x5c')](function(_0x58a26f){return _0x2386c0[_0x5adb('0x60')](_0x15d4f1['query']['ids'],{'transaction':_0x58a26f})[_0x5adb('0x17')](function(){if(!_[_0x5adb('0x75')](_0x268df2)){return _0x2386c0[_0x5adb('0x76')](_0x268df2,{'transaction':_0x58a26f});}})['then'](function(){_0x268df2[_0x5adb('0x5e')](function(_0x321c3a){socket[_0x5adb('0x77')](_0x5adb('0x78'),{'UserId':_0x321c3a,'SmsQueueId':_0x2386c0['id']});});});});});});})[_0x5adb('0x17')](respondWithStatusCode(_0x20faf6,null))[_0x5adb('0x2a')](handleError(_0x20faf6,null));};exports[_0x5adb('0x79')]=function(_0x463e84,_0x28bd33){return db[_0x5adb('0x20')][_0x5adb('0x74')]({'where':{'id':_0x463e84[_0x5adb('0x3a')]['id']}})['then'](handleEntityNotFound(_0x28bd33,null))['then'](function(_0x312463){if(_0x312463){return _0x312463[_0x5adb('0x79')](_0x463e84['body'][_0x5adb('0x54')],_[_0x5adb('0x7a')](_0x463e84[_0x5adb('0x39')],[_0x5adb('0x54'),'id'])||{})[_0x5adb('0x7b')](function(_0x24cd3b){for(var _0x15626b=0x0;_0x15626b<_0x463e84[_0x5adb('0x39')][_0x5adb('0x54')]['length'];_0x15626b+=0x1){socket[_0x5adb('0x77')](_0x5adb('0x5f'),{'UserId':Number(_0x463e84[_0x5adb('0x39')]['ids'][_0x15626b]),'SmsQueueId':Number(_0x463e84[_0x5adb('0x3a')]['id'])});}return _0x24cd3b;});}})[_0x5adb('0x17')](respondWithResult(_0x28bd33,null))[_0x5adb('0x2a')](handleError(_0x28bd33,null));};exports[_0x5adb('0x76')]=function(_0x64475f,_0x2a78f9){return db['SmsQueue'][_0x5adb('0x74')]({'where':{'id':_0x64475f[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x2a78f9,null))[_0x5adb('0x17')](function(_0x2c3af8){if(_0x2c3af8){return _0x2c3af8[_0x5adb('0x76')](_0x64475f[_0x5adb('0x28')][_0x5adb('0x54')])[_0x5adb('0x17')](function(){if(_[_0x5adb('0x7c')](_0x64475f['query'][_0x5adb('0x54')])){for(var _0x5b9565=0x0;_0x5b9565<_0x64475f[_0x5adb('0x28')][_0x5adb('0x54')][_0x5adb('0x31')];_0x5b9565+=0x1){socket[_0x5adb('0x77')](_0x5adb('0x78'),{'UserId':Number(_0x64475f['query']['ids'][_0x5b9565]),'SmsQueueId':Number(_0x64475f[_0x5adb('0x3a')]['id'])});}}else{socket[_0x5adb('0x77')](_0x5adb('0x78'),{'UserId':Number(_0x64475f[_0x5adb('0x28')][_0x5adb('0x54')]),'SmsQueueId':Number(_0x64475f[_0x5adb('0x3a')]['id'])});}});}})['then'](respondWithStatusCode(_0x2a78f9,null))['catch'](handleError(_0x2a78f9,null));};exports[_0x5adb('0x7d')]=function(_0xd5b95d,_0x9d80fd){var _0x4f5721={};var _0x542626={};var _0x227c17;var _0x5982a5;return db[_0x5adb('0x20')][_0x5adb('0x3d')]({'where':{'id':_0xd5b95d['params']['id']}})['then'](handleEntityNotFound(_0x9d80fd,null))[_0x5adb('0x17')](function(_0x4bb198){if(_0x4bb198){_0x227c17=_0x4bb198;_0x542626['model']=_[_0x5adb('0x2d')](db[_0x5adb('0x46')][_0x5adb('0x21')]);_0x542626[_0x5adb('0x28')]=_[_0x5adb('0x2d')](_0xd5b95d[_0x5adb('0x28')]);_0x542626[_0x5adb('0x2e')]=_[_0x5adb('0x3e')](_0x542626[_0x5adb('0x2c')],_0x542626[_0x5adb('0x28')]);_0x4f5721[_0x5adb('0x30')]=_[_0x5adb('0x3e')](_0x542626[_0x5adb('0x2c')],qs['fields'](_0xd5b95d[_0x5adb('0x28')]['fields']));_0x4f5721[_0x5adb('0x30')]=_0x4f5721[_0x5adb('0x30')][_0x5adb('0x31')]?_0x4f5721[_0x5adb('0x30')]:_0x542626[_0x5adb('0x2c')];_0x4f5721[_0x5adb('0x41')]=qs[_0x5adb('0x42')](_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x42')]);_0x4f5721[_0x5adb('0x25')]=qs[_0x5adb('0x2e')](_[_0x5adb('0x50')](_0xd5b95d['query'],_0x542626[_0x5adb('0x2e')]));if(_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x51')]){_0x4f5721[_0x5adb('0x25')]=_[_0x5adb('0x44')](_0x4f5721[_0x5adb('0x25')],{'$or':_[_0x5adb('0x48')](_0x4f5721[_0x5adb('0x30')],function(_0x57c160){var _0xe7ddc4={};_0xe7ddc4[_0x57c160]={'$like':'%'+_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x51')]+'%'};return _0xe7ddc4;})});}_0x4f5721=_['merge']({},_0x4f5721,_0xd5b95d[_0x5adb('0x33')]);return _0x227c17['getAgents'](_0x4f5721);}})[_0x5adb('0x17')](function(_0x50c3a3){if(_0x50c3a3){_0x5982a5=_0x50c3a3['length'];if(!_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x3f')](_0x5adb('0x40'))){_0x4f5721[_0x5adb('0x12')]=qs[_0x5adb('0x12')](_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x12')]);_0x4f5721[_0x5adb('0x11')]=qs[_0x5adb('0x11')](_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x11')]);}return _0x227c17[_0x5adb('0x7d')](_0x4f5721);}})['then'](function(_0x364da7){if(_0x364da7){return _0x364da7?{'count':_0x5982a5,'rows':_0x364da7}:null;}})['then'](respondWithResult(_0x9d80fd,null))[_0x5adb('0x2a')](handleError(_0x9d80fd,null));};