Built motion from commit 129fb4d95212661e48f0db455e75d668addbaddf. Version 3.0.0...
[motion-next.git] / server / api / notification / notification.controller.js
index 9d1422d..acca12e 100644 (file)
@@ -1 +1 @@
-const a461_0x9a48=['fullname','undefined','mailqueue','sequelize','TemplateId','error','status','smsqueue','findOne','recipientsId','body','replace','Invalid\x20model\x20in\x20\x27recipients\x27\x20object','recipientsDescription','stack','map','includes','Notification','./notification.socket','Invalid\x20\x27TemplateId\x27\x20parameter','Template','user','Must\x20specify\x20at\x20least\x20one\x20argument\x20for\x20\x27text\x27\x20or\x20\x27TemplateId\x27','User','some','getAgents','openchannelqueue','voicequeue','text','lodash','Missing\x20\x27view\x27\x20parameter','ids','SenderId','recipient','render','push','team','json','flatten','senderName','startCase','view','chatqueue','join','../../rediscache','then','../../config/logger','name','Missing\x20\x27recipients\x27\x20parameter','model','Invalid\x20\x27recipients\x27\x20object','api','notification:send','register','catch','queue','transaction','all','create','recipients','forEach','union','faxqueue','beep'];(function(_0x5a288f,_0x9a48cc){const _0x5c31ce=function(_0x1084c9){while(--_0x1084c9){_0x5a288f['push'](_0x5a288f['shift']());}};_0x5c31ce(++_0x9a48cc);}(a461_0x9a48,0xc2));const a461_0x5c31=function(_0x5a288f,_0x9a48cc){_0x5a288f=_0x5a288f-0x0;let _0x5c31ce=a461_0x9a48[_0x5a288f];return _0x5c31ce;};const _0x306323=a461_0x5c31;'use strict';const Mustache=require('mustache'),_=require(_0x306323('0x1b')),logger=require(_0x306323('0x2c'))(_0x306323('0x31')),{getSocket}=require(_0x306323('0x2a')),socket=getSocket(),db=require('../../mysqldb')['db'],{ValidationError}=require(_0x306323('0x1'));require(_0x306323('0x10'))[_0x306323('0x33')](socket);function respondWithResult(_0x1084c9,_0x16227e){return _0x16227e=_0x16227e||0xc8,function(_0xed2c7){const _0x33ab92=a461_0x5c31;if(_0xed2c7)return _0x1084c9[_0x33ab92('0x4')](_0x16227e)[_0x33ab92('0x23')](_0xed2c7);};}function handleError(_0x441e5c,_0x31d6c8){return _0x31d6c8=_0x31d6c8||0x1f4,function(_0x17d191){const _0x59a384=a461_0x5c31;logger[_0x59a384('0x3')](_0x17d191[_0x59a384('0xc')]),_0x17d191[_0x59a384('0x2d')]&&delete _0x17d191[_0x59a384('0x2d')],_0x441e5c[_0x59a384('0x4')](_0x31d6c8)['send'](_0x17d191);};}exports['sendNotification']=function(_0x5eb7b2,_0x53914e){const _0x231290=_0x306323;let _0x31ed6e=[];if(typeof _0x5eb7b2['body'][_0x231290('0x1a')]===_0x231290('0x3f')&&typeof _0x5eb7b2['body'][_0x231290('0x2')]===_0x231290('0x3f'))throw new ValidationError(_0x231290('0x14'));else{if(typeof _0x5eb7b2[_0x231290('0x8')][_0x231290('0x2')]!==_0x231290('0x3f')&&typeof _0x5eb7b2['body']['view']==='undefined')throw new ValidationError(_0x231290('0x1c'));if(typeof _0x5eb7b2['body'][_0x231290('0x39')]==='undefined')throw new ValidationError(_0x231290('0x2e'));else{try{_0x31ed6e=JSON['parse'](_0x5eb7b2[_0x231290('0x8')][_0x231290('0x39')]);}catch(_0x5f2d86){logger[_0x231290('0x3')](_0x5f2d86);throw new ValidationError(_0x231290('0x30'));}const _0x1b9957=[_0x231290('0x28'),_0x231290('0x3c'),_0x231290('0x0'),_0x231290('0x18'),_0x231290('0x5'),_0x231290('0x19'),'whatsappqueue',_0x231290('0x22'),_0x231290('0x13')];if(_[_0x231290('0x16')](_0x31ed6e,function(_0x3ea75e){const _0x1d6f60=_0x231290;return!_[_0x1d6f60('0xe')](_0x1b9957,_0x3ea75e['model']['toLowerCase']());}))throw new ValidationError(_0x231290('0xa'));}}const _0xd21338={};return _0xd21338['senderName']=_0x5eb7b2[_0x231290('0x8')][_0x231290('0x25')]?_0x5eb7b2[_0x231290('0x8')]['senderName']:_0x5eb7b2[_0x231290('0x13')][_0x231290('0x3e')],_0xd21338[_0x231290('0xb')]=_['isEmpty'](_0x5eb7b2[_0x231290('0x8')][_0x231290('0xb')])?null:_0x5eb7b2[_0x231290('0x8')][_0x231290('0xb')],_0xd21338[_0x231290('0x3d')]=_0x5eb7b2['body'][_0x231290('0x3d')]||![],_0xd21338[_0x231290('0x1e')]=_0x5eb7b2[_0x231290('0x13')]['id'],getContent(_0x5eb7b2['body'])[_0x231290('0x2b')](function(_0x595d17){return _0xd21338['body']=_0x595d17,getRecipients(_0x31ed6e);})[_0x231290('0x2b')](function(_0x130bc2){const _0x569088=_0x231290;return _0xd21338[_0x569088('0x7')]=_['sortBy'](_0x130bc2)[_0x569088('0x29')](','),db[_0x569088('0x1')][_0x569088('0x36')](function(_0x4bada7){const _0x276876=_0x569088;return db[_0x276876('0xf')][_0x276876('0x38')](_0xd21338,{'raw':!![],'transaction':_0x4bada7})[_0x276876('0x2b')](function(_0x33ab9a){const _0x1ec77f=_0x276876,_0x332055={'sender':_0xd21338['senderName'],'description':_0xd21338['recipientsDescription'],'content':_0xd21338['body'],'beep':_0xd21338[_0x1ec77f('0x3d')]};return _0x130bc2[_0x1ec77f('0x3a')](function(_0x5b3e98){const _0x2d3ec6=_0x1ec77f;_0x332055[_0x2d3ec6('0x1f')]=_0x5b3e98,socket['emit'](_0x2d3ec6('0x32'),_0x332055);}),_0x33ab9a;});});})[_0x231290('0x2b')](respondWithResult(_0x53914e,0xc9))['catch'](handleError(_0x53914e,null));};function getContent(_0x1805a3){return new Promise(function(_0x52904b,_0x38819f){const _0x56410c=a461_0x5c31;if(_0x1805a3[_0x56410c('0x1a')]){_0x52904b(_0x1805a3['text']);return;}return db[_0x56410c('0x12')][_0x56410c('0x6')]({'attributes':['html'],'where':{'id':_0x1805a3[_0x56410c('0x2')]},'raw':!![]})[_0x56410c('0x2b')](function(_0x1124c4){const _0x53b0b8=_0x56410c;if(!_0x1124c4)throw new ValidationError(_0x53b0b8('0x11'));const _0x453abc=Mustache[_0x53b0b8('0x20')](_0x1124c4['html'],_0x1805a3[_0x53b0b8('0x27')]);_0x52904b(_0x453abc);})['catch'](function(_0x2bbe30){_0x38819f(_0x2bbe30);});});}function getRecipients(_0x2dd494){return new Promise(function(_0x5e178a,_0x36c6c5){const _0x21ba4f=a461_0x5c31;let _0x34c9dd=[];const _0x5e111f=[];return _0x2dd494[_0x21ba4f('0x3a')](function(_0x9b5a23){const _0x404cf8=_0x21ba4f;let _0x1e5c70=_[_0x404cf8('0x26')](_0x9b5a23[_0x404cf8('0x2f')]['toLowerCase']());if(_0x1e5c70===_0x404cf8('0x15'))_0x34c9dd=_[_0x404cf8('0x3b')](_0x34c9dd,_0x9b5a23[_0x404cf8('0x1d')]);else{if(_['includes'](_0x1e5c70,_0x404cf8('0x35')))_0x1e5c70=_0x1e5c70[_0x404cf8('0x9')](_0x404cf8('0x35'),'Queue');_0x9b5a23[_0x404cf8('0x1d')][_0x404cf8('0x3a')](function(_0x56757e){const _0x28aae1=_0x404cf8;_0x5e111f[_0x28aae1('0x21')](getAgents(_0x1e5c70,_0x56757e));});}}),Promise[_0x21ba4f('0x37')](_0x5e111f)[_0x21ba4f('0x2b')](function(_0x27b010){const _0x1e6f0f=_0x21ba4f;_0x34c9dd=_[_0x1e6f0f('0x3b')](_0x34c9dd,_[_0x1e6f0f('0x24')](_0x27b010)),_0x5e178a(_0x34c9dd);})[_0x21ba4f('0x34')](function(_0x2ec994){_0x36c6c5(_0x2ec994);});});}function getAgents(_0x5312a6,_0x4c5da5){return new Promise(function(_0x57e1ee,_0x3c9501){const _0x4cb765=a461_0x5c31;return db[_0x5312a6][_0x4cb765('0x6')]({'where':{'id':_0x4c5da5}})[_0x4cb765('0x2b')](function(_0x3f9a94){const _0x103c73=_0x4cb765;return _0x3f9a94[_0x103c73('0x17')]({'attributes':['id'],'raw':!![]})[_0x103c73('0x2b')](function(_0x47b167){const _0x563a1d=_0x103c73,_0x1e7543=_[_0x563a1d('0xd')](_0x47b167,'id');_0x57e1ee(_0x1e7543);});})[_0x4cb765('0x34')](function(_0x7fb7b4){_0x3c9501(_0x7fb7b4);});});}
\ No newline at end of file
+const a555_0x54c6=['chatqueue','senderName','Missing\x20\x27recipients\x27\x20parameter','getAgents','voicequeue','beep','all','then','join','includes','body','TemplateId','toLowerCase','transaction','faxqueue','text','mustache','union','api','../../rediscache','undefined','view','forEach','Must\x20specify\x20at\x20least\x20one\x20argument\x20for\x20\x27text\x27\x20or\x20\x27TemplateId\x27','../../config/logger','push','some','isEmpty','queue','name','user','Invalid\x20\x27recipients\x27\x20object','model','findOne','html','catch','recipients','sequelize','replace','Missing\x20\x27view\x27\x20parameter','whatsappqueue','recipient','startCase','recipientsId','flatten','SenderId','mailqueue','recipientsDescription','Template','status','send','map','smsqueue','error','render','create','sendNotification'];(function(_0x542a4f,_0x1d468d){const _0x54c6e2=function(_0x2e6ab6){while(--_0x2e6ab6){_0x542a4f['push'](_0x542a4f['shift']());}};_0x54c6e2(++_0x1d468d);}(a555_0x54c6,0x1de));const a555_0x2e6a=function(_0x542a4f,_0x1d468d){_0x542a4f=_0x542a4f-0x89;let _0x54c6e2=a555_0x54c6[_0x542a4f];return _0x54c6e2;};const a555_0x574ff3=a555_0x2e6a;'use strict';const Mustache=require(a555_0x574ff3(0xbc)),_=require('lodash'),logger=require(a555_0x574ff3(0x8b))(a555_0x574ff3(0xbe)),{getSocket}=require(a555_0x574ff3(0xbf)),socket=getSocket(),{db}=require('../../mysqldb'),{ValidationError}=require('sequelize');require('./notification.socket')['register'](socket);function respondWithResult(_0x47c5b7,_0x37652a){return _0x37652a=_0x37652a||0xc8,function(_0x343ee8){const _0x286f8e=a555_0x2e6a;if(_0x343ee8)return _0x47c5b7[_0x286f8e(0xa4)](_0x37652a)['json'](_0x343ee8);};}function handleError(_0x5d0f60,_0x253677){return _0x253677=_0x253677||0x1f4,function(_0x3c7982){const _0x152126=a555_0x2e6a;logger[_0x152126(0xa8)](_0x3c7982['stack']),_0x3c7982[_0x152126(0x90)]&&delete _0x3c7982[_0x152126(0x90)],_0x5d0f60['status'](_0x253677)[_0x152126(0xa5)](_0x3c7982);};}exports[a555_0x574ff3(0xab)]=function(_0x3aba72,_0x1613d2){const _0x161ffa=a555_0x574ff3;let _0x20d4ed=[];if(typeof _0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0xbb)]===_0x161ffa(0xc0)&&typeof _0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0xb7)]===_0x161ffa(0xc0))throw new ValidationError(_0x161ffa(0x8a));else{if(typeof _0x3aba72[_0x161ffa(0xb6)]['TemplateId']!==_0x161ffa(0xc0)&&typeof _0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0xc1)]===_0x161ffa(0xc0))throw new ValidationError(_0x161ffa(0x9a));if(typeof _0x3aba72['body'][_0x161ffa(0x97)]===_0x161ffa(0xc0))throw new ValidationError(_0x161ffa(0xae));else{try{_0x20d4ed=JSON['parse'](_0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0x97)]);}catch(_0x4ad470){logger[_0x161ffa(0xa8)](_0x4ad470);throw new ValidationError(_0x161ffa(0x92));}const _0x453232=[_0x161ffa(0xac),_0x161ffa(0xba),_0x161ffa(0xa1),'openchannelqueue',_0x161ffa(0xa7),_0x161ffa(0xb0),_0x161ffa(0x9b),'team',_0x161ffa(0x91)];if(_[_0x161ffa(0x8d)](_0x20d4ed,function(_0x3949a4){const _0xf838e3=_0x161ffa;return!_[_0xf838e3(0xb5)](_0x453232,_0x3949a4[_0xf838e3(0x93)][_0xf838e3(0xb8)]());}))throw new ValidationError('Invalid\x20model\x20in\x20\x27recipients\x27\x20object');}}const _0x35d1a7={};return _0x35d1a7[_0x161ffa(0xad)]=_0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0xad)]?_0x3aba72['body'][_0x161ffa(0xad)]:_0x3aba72[_0x161ffa(0x91)]['fullname'],_0x35d1a7[_0x161ffa(0xa2)]=_[_0x161ffa(0x8e)](_0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0xa2)])?null:_0x3aba72[_0x161ffa(0xb6)][_0x161ffa(0xa2)],_0x35d1a7[_0x161ffa(0xb1)]=_0x3aba72['body'][_0x161ffa(0xb1)]||![],_0x35d1a7[_0x161ffa(0xa0)]=_0x3aba72[_0x161ffa(0x91)]['id'],getContent(_0x3aba72['body'])['then'](function(_0x2fa347){const _0x2c8d4b=_0x161ffa;return _0x35d1a7[_0x2c8d4b(0xb6)]=_0x2fa347,getRecipients(_0x20d4ed);})[_0x161ffa(0xb3)](function(_0x2ba848){const _0x20d195=_0x161ffa;return _0x35d1a7[_0x20d195(0x9e)]=_['sortBy'](_0x2ba848)[_0x20d195(0xb4)](','),db[_0x20d195(0x98)][_0x20d195(0xb9)](function(_0x44a4c1){const _0x455e0b=_0x20d195;return db['Notification'][_0x455e0b(0xaa)](_0x35d1a7,{'raw':!![],'transaction':_0x44a4c1})['then'](function(_0x1bf761){const _0x2ec2d5=_0x455e0b,_0x5e5835={'sender':_0x35d1a7[_0x2ec2d5(0xad)],'description':_0x35d1a7[_0x2ec2d5(0xa2)],'content':_0x35d1a7[_0x2ec2d5(0xb6)],'beep':_0x35d1a7[_0x2ec2d5(0xb1)]};return _0x2ba848[_0x2ec2d5(0x89)](function(_0x1eb385){const _0x469066=_0x2ec2d5;_0x5e5835[_0x469066(0x9c)]=_0x1eb385,socket['emit']('notification:send',_0x5e5835);}),_0x1bf761;});});})['then'](respondWithResult(_0x1613d2,0xc9))[_0x161ffa(0x96)](handleError(_0x1613d2,null));};function getContent(_0x4efeb1){return new Promise(function(_0x5d227e,_0x3ab44e){const _0x168fe3=a555_0x2e6a;if(_0x4efeb1[_0x168fe3(0xbb)]){_0x5d227e(_0x4efeb1[_0x168fe3(0xbb)]);return;}return db[_0x168fe3(0xa3)][_0x168fe3(0x94)]({'attributes':['html'],'where':{'id':_0x4efeb1[_0x168fe3(0xb7)]},'raw':!![]})['then'](function(_0x5c9d7c){const _0x3c60ab=_0x168fe3;if(!_0x5c9d7c)throw new ValidationError('Invalid\x20\x27TemplateId\x27\x20parameter');const _0x2e287d=Mustache[_0x3c60ab(0xa9)](_0x5c9d7c[_0x3c60ab(0x95)],_0x4efeb1[_0x3c60ab(0xc1)]);_0x5d227e(_0x2e287d);})['catch'](function(_0x44b6dc){_0x3ab44e(_0x44b6dc);});});}function getRecipients(_0x2c5620){return new Promise(function(_0x1f4334,_0x2e0d30){const _0xde898a=a555_0x2e6a;let _0x4f34bf=[];const _0x5c4b09=[];return _0x2c5620[_0xde898a(0x89)](function(_0x27a8f1){const _0x560ee3=_0xde898a;let _0x555723=_[_0x560ee3(0x9d)](_0x27a8f1[_0x560ee3(0x93)]['toLowerCase']());if(_0x555723==='User')_0x4f34bf=_[_0x560ee3(0xbd)](_0x4f34bf,_0x27a8f1['ids']);else{if(_[_0x560ee3(0xb5)](_0x555723,_0x560ee3(0x8f)))_0x555723=_0x555723[_0x560ee3(0x99)](_0x560ee3(0x8f),'Queue');_0x27a8f1['ids']['forEach'](function(_0x4c1874){const _0x467981=_0x560ee3;_0x5c4b09[_0x467981(0x8c)](getAgents(_0x555723,_0x4c1874));});}}),Promise[_0xde898a(0xb2)](_0x5c4b09)['then'](function(_0x25914a){const _0x5e797e=_0xde898a;_0x4f34bf=_[_0x5e797e(0xbd)](_0x4f34bf,_[_0x5e797e(0x9f)](_0x25914a)),_0x1f4334(_0x4f34bf);})['catch'](function(_0x1b592c){_0x2e0d30(_0x1b592c);});});}function getAgents(_0x24528d,_0x129ffc){return new Promise(function(_0x58264d,_0x270afa){const _0x514e19=a555_0x2e6a;return db[_0x24528d][_0x514e19(0x94)]({'where':{'id':_0x129ffc}})[_0x514e19(0xb3)](function(_0x38a62e){const _0x2381f1=_0x514e19;return _0x38a62e[_0x2381f1(0xaf)]({'attributes':['id'],'raw':!![]})[_0x2381f1(0xb3)](function(_0x205dd5){const _0x335cc2=_0x2381f1,_0x219afb=_[_0x335cc2(0xa6)](_0x205dd5,'id');_0x58264d(_0x219afb);});})['catch'](function(_0x110187){_0x270afa(_0x110187);});});}
\ No newline at end of file