Built motion from commit bfc7a72f7045b27461c9a5d1f71c1a658cfd0b8b. Version 3.0.0...
[motion-next.git] / server / api / notification / notification.controller.js
index d38eb02..94091f9 100644 (file)
@@ -1 +1 @@
-const a461_0x2c52=['includes','whatsappqueue','../../config/logger','openchannelqueue','body','Notification','union','parse','render','fullname','view','sendNotification','../../mysqldb','text','TemplateId','recipient','recipients','all','Must\x20specify\x20at\x20least\x20one\x20argument\x20for\x20\x27text\x27\x20or\x20\x27TemplateId\x27','User','transaction','catch','faxqueue','startCase','name','flatten','senderName','forEach','model','sequelize','lodash','Missing\x20\x27view\x27\x20parameter','../../rediscache','register','Template','map','Invalid\x20\x27recipients\x27\x20object','Invalid\x20model\x20in\x20\x27recipients\x27\x20object','html','stack','some','isEmpty','getAgents','Invalid\x20\x27TemplateId\x27\x20parameter','notification:send','queue','recipientsDescription','findOne','beep','status','json','emit','api','toLowerCase','then','undefined','recipientsId','send','user','join','create','SenderId','voicequeue','Queue'];(function(_0x488336,_0x2c524b){const _0x1a0958=function(_0x20dcea){while(--_0x20dcea){_0x488336['push'](_0x488336['shift']());}};_0x1a0958(++_0x2c524b);}(a461_0x2c52,0xdc));const a461_0x1a09=function(_0x488336,_0x2c524b){_0x488336=_0x488336-0x0;let _0x1a0958=a461_0x2c52[_0x488336];return _0x1a0958;};const _0x1d18ce=a461_0x1a09;'use strict';const Mustache=require('mustache'),_=require(_0x1d18ce('0x2')),logger=require(_0x1d18ce('0x26'))(_0x1d18ce('0x18')),{getSocket}=require(_0x1d18ce('0x4')),socket=getSocket(),db=require(_0x1d18ce('0x30'))['db'],{ValidationError}=require('sequelize');require('./notification.socket')[_0x1d18ce('0x5')](socket);function respondWithResult(_0x20dcea,_0x299d7a){return _0x299d7a=_0x299d7a||0xc8,function(_0x33cb9a){const _0x40b8e5=a461_0x1a09;if(_0x33cb9a)return _0x20dcea[_0x40b8e5('0x15')](_0x299d7a)[_0x40b8e5('0x16')](_0x33cb9a);};}function handleError(_0x489a1a,_0x3253bb){return _0x3253bb=_0x3253bb||0x1f4,function(_0x2cfaf1){const _0x587db6=a461_0x1a09;logger['error'](_0x2cfaf1[_0x587db6('0xb')]),_0x2cfaf1[_0x587db6('0x3c')]&&delete _0x2cfaf1['name'],_0x489a1a['status'](_0x3253bb)[_0x587db6('0x1d')](_0x2cfaf1);};}exports[_0x1d18ce('0x2f')]=function(_0x18fcbb,_0x150391){const _0x235d46=_0x1d18ce;let _0x30b309=[];if(typeof _0x18fcbb[_0x235d46('0x28')][_0x235d46('0x31')]==='undefined'&&typeof _0x18fcbb[_0x235d46('0x28')][_0x235d46('0x32')]===_0x235d46('0x1b'))throw new ValidationError(_0x235d46('0x36'));else{if(typeof _0x18fcbb[_0x235d46('0x28')][_0x235d46('0x32')]!==_0x235d46('0x1b')&&typeof _0x18fcbb[_0x235d46('0x28')]['view']===_0x235d46('0x1b'))throw new ValidationError(_0x235d46('0x3'));if(typeof _0x18fcbb[_0x235d46('0x28')][_0x235d46('0x34')]===_0x235d46('0x1b'))throw new ValidationError('Missing\x20\x27recipients\x27\x20parameter');else{try{_0x30b309=JSON[_0x235d46('0x2b')](_0x18fcbb[_0x235d46('0x28')][_0x235d46('0x34')]);}catch(_0x928df5){logger['error'](_0x928df5);throw new ValidationError(_0x235d46('0x8'));}const _0x3ef8f7=['chatqueue',_0x235d46('0x3a'),'mailqueue',_0x235d46('0x27'),'smsqueue',_0x235d46('0x22'),_0x235d46('0x25'),'team',_0x235d46('0x1e')];if(_[_0x235d46('0xc')](_0x30b309,function(_0x8ac7b8){const _0x4c186d=_0x235d46;return!_['includes'](_0x3ef8f7,_0x8ac7b8['model'][_0x4c186d('0x19')]());}))throw new ValidationError(_0x235d46('0x9'));}}const _0x5f48a1={};return _0x5f48a1[_0x235d46('0x3e')]=_0x18fcbb[_0x235d46('0x28')][_0x235d46('0x3e')]?_0x18fcbb[_0x235d46('0x28')]['senderName']:_0x18fcbb['user'][_0x235d46('0x2d')],_0x5f48a1[_0x235d46('0x12')]=_[_0x235d46('0xd')](_0x18fcbb[_0x235d46('0x28')][_0x235d46('0x12')])?null:_0x18fcbb['body']['recipientsDescription'],_0x5f48a1[_0x235d46('0x14')]=_0x18fcbb[_0x235d46('0x28')][_0x235d46('0x14')]||![],_0x5f48a1[_0x235d46('0x21')]=_0x18fcbb[_0x235d46('0x1e')]['id'],getContent(_0x18fcbb[_0x235d46('0x28')])[_0x235d46('0x1a')](function(_0x27a35b){const _0x416ba7=_0x235d46;return _0x5f48a1[_0x416ba7('0x28')]=_0x27a35b,getRecipients(_0x30b309);})['then'](function(_0x810cf9){const _0x3184ca=_0x235d46;return _0x5f48a1[_0x3184ca('0x1c')]=_['sortBy'](_0x810cf9)[_0x3184ca('0x1f')](','),db[_0x3184ca('0x1')][_0x3184ca('0x38')](function(_0x3040a8){const _0x43e40e=_0x3184ca;return db[_0x43e40e('0x29')][_0x43e40e('0x20')](_0x5f48a1,{'raw':!![],'transaction':_0x3040a8})[_0x43e40e('0x1a')](function(_0x7f4f08){const _0x178b0b=_0x43e40e,_0x3e506f={'sender':_0x5f48a1[_0x178b0b('0x3e')],'description':_0x5f48a1[_0x178b0b('0x12')],'content':_0x5f48a1[_0x178b0b('0x28')],'beep':_0x5f48a1['beep']};return _0x810cf9['forEach'](function(_0x2c871d){const _0xe9215a=_0x178b0b;_0x3e506f[_0xe9215a('0x33')]=_0x2c871d,socket[_0xe9215a('0x17')](_0xe9215a('0x10'),_0x3e506f);}),_0x7f4f08;});});})[_0x235d46('0x1a')](respondWithResult(_0x150391,0xc9))[_0x235d46('0x39')](handleError(_0x150391,null));};function getContent(_0x37a2f3){return new Promise(function(_0x1393ad,_0x4976df){const _0x486feb=a461_0x1a09;if(_0x37a2f3[_0x486feb('0x31')]){_0x1393ad(_0x37a2f3[_0x486feb('0x31')]);return;}return db[_0x486feb('0x6')]['findOne']({'attributes':[_0x486feb('0xa')],'where':{'id':_0x37a2f3['TemplateId']},'raw':!![]})[_0x486feb('0x1a')](function(_0xb96198){const _0x420352=_0x486feb;if(!_0xb96198)throw new ValidationError(_0x420352('0xf'));const _0xde65aa=Mustache[_0x420352('0x2c')](_0xb96198['html'],_0x37a2f3[_0x420352('0x2e')]);_0x1393ad(_0xde65aa);})['catch'](function(_0x3356f8){_0x4976df(_0x3356f8);});});}function getRecipients(_0x2bbebf){return new Promise(function(_0x537461,_0x40d39a){const _0x14dae3=a461_0x1a09;let _0x4d4766=[];const _0x194982=[];return _0x2bbebf['forEach'](function(_0x40ac5b){const _0x38d017=a461_0x1a09;let _0x526a41=_[_0x38d017('0x3b')](_0x40ac5b[_0x38d017('0x0')]['toLowerCase']());if(_0x526a41===_0x38d017('0x37'))_0x4d4766=_[_0x38d017('0x2a')](_0x4d4766,_0x40ac5b['ids']);else{if(_[_0x38d017('0x24')](_0x526a41,_0x38d017('0x11')))_0x526a41=_0x526a41['replace'](_0x38d017('0x11'),_0x38d017('0x23'));_0x40ac5b['ids'][_0x38d017('0x3f')](function(_0x67eb96){_0x194982['push'](getAgents(_0x526a41,_0x67eb96));});}}),Promise[_0x14dae3('0x35')](_0x194982)['then'](function(_0xebc0f){const _0x399df6=_0x14dae3;_0x4d4766=_[_0x399df6('0x2a')](_0x4d4766,_[_0x399df6('0x3d')](_0xebc0f)),_0x537461(_0x4d4766);})[_0x14dae3('0x39')](function(_0x40634a){_0x40d39a(_0x40634a);});});}function getAgents(_0x4ce071,_0x3e2ada){return new Promise(function(_0x49c21c,_0x2c6420){const _0xc0c979=a461_0x1a09;return db[_0x4ce071][_0xc0c979('0x13')]({'where':{'id':_0x3e2ada}})[_0xc0c979('0x1a')](function(_0x1690bf){const _0x5b7a97=_0xc0c979;return _0x1690bf[_0x5b7a97('0xe')]({'attributes':['id'],'raw':!![]})[_0x5b7a97('0x1a')](function(_0x4d43f8){const _0x5b4e66=_0x5b7a97,_0x1065b2=_[_0x5b4e66('0x7')](_0x4d43f8,'id');_0x49c21c(_0x1065b2);});})[_0xc0c979('0x39')](function(_0x1f4b77){_0x2c6420(_0x1f4b77);});});}
\ No newline at end of file
+const a461_0x39fc=['union','some','Invalid\x20\x27TemplateId\x27\x20parameter','senderName','openchannelqueue','register','chatqueue','Notification','status','forEach','./notification.socket','flatten','TemplateId','Template','join','recipientsId','undefined','html','emit','then','fullname','../../rediscache','Queue','lodash','../../config/logger','findOne','body','Missing\x20\x27recipients\x27\x20parameter','queue','name','SenderId','mailqueue','json','smsqueue','user','sendNotification','recipientsDescription','error','includes','sortBy','ids','catch','model','startCase','replace','getAgents','Invalid\x20\x27recipients\x27\x20object','Missing\x20\x27view\x27\x20parameter','mustache','api','transaction','Invalid\x20model\x20in\x20\x27recipients\x27\x20object','toLowerCase','../../mysqldb','sequelize','text','beep','render'];(function(_0x4a1e41,_0x39fcb4){const _0x3f5ad2=function(_0x17c98c){while(--_0x17c98c){_0x4a1e41['push'](_0x4a1e41['shift']());}};_0x3f5ad2(++_0x39fcb4);}(a461_0x39fc,0x168));const a461_0x3f5a=function(_0x4a1e41,_0x39fcb4){_0x4a1e41=_0x4a1e41-0x0;let _0x3f5ad2=a461_0x39fc[_0x4a1e41];return _0x3f5ad2;};const _0x4e9fe3=a461_0x3f5a;'use strict';const Mustache=require(_0x4e9fe3('0x24')),_=require(_0x4e9fe3('0xb')),logger=require(_0x4e9fe3('0xc'))(_0x4e9fe3('0x25')),{getSocket}=require(_0x4e9fe3('0x9')),socket=getSocket(),db=require(_0x4e9fe3('0x29'))['db'],{ValidationError}=require(_0x4e9fe3('0x2a'));require(_0x4e9fe3('0x38'))[_0x4e9fe3('0x33')](socket);function respondWithResult(_0x17c98c,_0x94eb2b){return _0x94eb2b=_0x94eb2b||0xc8,function(_0x5104c7){const _0x28838c=a461_0x3f5a;if(_0x5104c7)return _0x17c98c[_0x28838c('0x36')](_0x94eb2b)[_0x28838c('0x14')](_0x5104c7);};}function handleError(_0x5418a2,_0x3685de){return _0x3685de=_0x3685de||0x1f4,function(_0x29eedf){const _0x31c281=a461_0x3f5a;logger[_0x31c281('0x19')](_0x29eedf['stack']),_0x29eedf[_0x31c281('0x11')]&&delete _0x29eedf['name'],_0x5418a2[_0x31c281('0x36')](_0x3685de)['send'](_0x29eedf);};}exports[_0x4e9fe3('0x17')]=function(_0x1ec10f,_0x5598ba){const _0x3e753f=_0x4e9fe3;let _0x350bb9=[];if(typeof _0x1ec10f[_0x3e753f('0xe')][_0x3e753f('0x2b')]===_0x3e753f('0x4')&&typeof _0x1ec10f['body'][_0x3e753f('0x0')]===_0x3e753f('0x4'))throw new ValidationError('Must\x20specify\x20at\x20least\x20one\x20argument\x20for\x20\x27text\x27\x20or\x20\x27TemplateId\x27');else{if(typeof _0x1ec10f[_0x3e753f('0xe')]['TemplateId']!==_0x3e753f('0x4')&&typeof _0x1ec10f[_0x3e753f('0xe')]['view']==='undefined')throw new ValidationError(_0x3e753f('0x23'));if(typeof _0x1ec10f['body']['recipients']===_0x3e753f('0x4'))throw new ValidationError(_0x3e753f('0xf'));else{try{_0x350bb9=JSON['parse'](_0x1ec10f['body']['recipients']);}catch(_0x219bdd){logger[_0x3e753f('0x19')](_0x219bdd);throw new ValidationError(_0x3e753f('0x22'));}const _0x4f9565=[_0x3e753f('0x34'),'faxqueue',_0x3e753f('0x13'),_0x3e753f('0x32'),_0x3e753f('0x15'),'voicequeue','whatsappqueue','team',_0x3e753f('0x16')];if(_[_0x3e753f('0x2f')](_0x350bb9,function(_0x4a1e84){const _0x1a858a=_0x3e753f;return!_[_0x1a858a('0x1a')](_0x4f9565,_0x4a1e84[_0x1a858a('0x1e')][_0x1a858a('0x28')]());}))throw new ValidationError(_0x3e753f('0x27'));}}const _0x5c7428={};return _0x5c7428[_0x3e753f('0x31')]=_0x1ec10f[_0x3e753f('0xe')][_0x3e753f('0x31')]?_0x1ec10f[_0x3e753f('0xe')][_0x3e753f('0x31')]:_0x1ec10f[_0x3e753f('0x16')][_0x3e753f('0x8')],_0x5c7428[_0x3e753f('0x18')]=_['isEmpty'](_0x1ec10f['body'][_0x3e753f('0x18')])?null:_0x1ec10f[_0x3e753f('0xe')][_0x3e753f('0x18')],_0x5c7428['beep']=_0x1ec10f[_0x3e753f('0xe')][_0x3e753f('0x2c')]||![],_0x5c7428[_0x3e753f('0x12')]=_0x1ec10f[_0x3e753f('0x16')]['id'],getContent(_0x1ec10f[_0x3e753f('0xe')])[_0x3e753f('0x7')](function(_0xecf3dd){return _0x5c7428['body']=_0xecf3dd,getRecipients(_0x350bb9);})[_0x3e753f('0x7')](function(_0x4ae6af){const _0x1006ed=_0x3e753f;return _0x5c7428[_0x1006ed('0x3')]=_[_0x1006ed('0x1b')](_0x4ae6af)[_0x1006ed('0x2')](','),db[_0x1006ed('0x2a')][_0x1006ed('0x26')](function(_0x814fa5){const _0x485e85=_0x1006ed;return db[_0x485e85('0x35')]['create'](_0x5c7428,{'raw':!![],'transaction':_0x814fa5})[_0x485e85('0x7')](function(_0x50ed7b){const _0x5cb9fb=_0x485e85,_0x4bab53={'sender':_0x5c7428[_0x5cb9fb('0x31')],'description':_0x5c7428[_0x5cb9fb('0x18')],'content':_0x5c7428['body'],'beep':_0x5c7428[_0x5cb9fb('0x2c')]};return _0x4ae6af[_0x5cb9fb('0x37')](function(_0x3df941){const _0x402d86=_0x5cb9fb;_0x4bab53['recipient']=_0x3df941,socket[_0x402d86('0x6')]('notification:send',_0x4bab53);}),_0x50ed7b;});});})[_0x3e753f('0x7')](respondWithResult(_0x5598ba,0xc9))[_0x3e753f('0x1d')](handleError(_0x5598ba,null));};function getContent(_0x39d70f){return new Promise(function(_0x3e668c,_0x1070f4){const _0x24b563=a461_0x3f5a;if(_0x39d70f[_0x24b563('0x2b')]){_0x3e668c(_0x39d70f[_0x24b563('0x2b')]);return;}return db[_0x24b563('0x1')][_0x24b563('0xd')]({'attributes':[_0x24b563('0x5')],'where':{'id':_0x39d70f[_0x24b563('0x0')]},'raw':!![]})[_0x24b563('0x7')](function(_0x51c1c9){const _0xc0418b=_0x24b563;if(!_0x51c1c9)throw new ValidationError(_0xc0418b('0x30'));const _0x43cfde=Mustache[_0xc0418b('0x2d')](_0x51c1c9[_0xc0418b('0x5')],_0x39d70f['view']);_0x3e668c(_0x43cfde);})['catch'](function(_0x1ac212){_0x1070f4(_0x1ac212);});});}function getRecipients(_0x15784d){return new Promise(function(_0x4b5aa8,_0x52f9dc){const _0x3a3c32=a461_0x3f5a;let _0x1e1a7e=[];const _0x2fa05d=[];return _0x15784d[_0x3a3c32('0x37')](function(_0x41aab7){const _0x47c552=_0x3a3c32;let _0x3475ac=_[_0x47c552('0x1f')](_0x41aab7[_0x47c552('0x1e')][_0x47c552('0x28')]());if(_0x3475ac==='User')_0x1e1a7e=_[_0x47c552('0x2e')](_0x1e1a7e,_0x41aab7[_0x47c552('0x1c')]);else{if(_['includes'](_0x3475ac,'queue'))_0x3475ac=_0x3475ac[_0x47c552('0x20')](_0x47c552('0x10'),_0x47c552('0xa'));_0x41aab7[_0x47c552('0x1c')][_0x47c552('0x37')](function(_0x4368cf){_0x2fa05d['push'](getAgents(_0x3475ac,_0x4368cf));});}}),Promise['all'](_0x2fa05d)[_0x3a3c32('0x7')](function(_0x49bd3d){const _0xde6238=_0x3a3c32;_0x1e1a7e=_[_0xde6238('0x2e')](_0x1e1a7e,_[_0xde6238('0x39')](_0x49bd3d)),_0x4b5aa8(_0x1e1a7e);})[_0x3a3c32('0x1d')](function(_0x495226){_0x52f9dc(_0x495226);});});}function getAgents(_0x35614f,_0x4ae805){return new Promise(function(_0x10a059,_0x3660bd){const _0x3e2042=a461_0x3f5a;return db[_0x35614f][_0x3e2042('0xd')]({'where':{'id':_0x4ae805}})['then'](function(_0x1df7fb){const _0x31e197=_0x3e2042;return _0x1df7fb[_0x31e197('0x21')]({'attributes':['id'],'raw':!![]})[_0x31e197('0x7')](function(_0x1f277c){const _0x1630ee=_['map'](_0x1f277c,'id');_0x10a059(_0x1630ee);});})[_0x3e2042('0x1d')](function(_0x5771f2){_0x3660bd(_0x5771f2);});});}
\ No newline at end of file