Built motion from commit f738f9592c388b9f9eb3948f400a5c9d717a3561. Version 3.0.0...
[motion-next.git] / server / api / voiceContext / voiceContext.controller.js
1 const a861_0x4a3c=['http','error','name','include','/etc/asterisk/extensions_xcally_contexts.conf','body','jayson/promise','type','path','pick','VoiceContext','fields','nolimit','stack','rows','sort','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','then','attributes','get','VoiceContext,\x20%s,\x20%s,\x20%s','set','../../config/logger','end','api','rawAttributes','lodash','fieldName','options','params','update','offset','destroy','autoAssociation','root','Content-Range','limit','merge','status','json','../../config/environment','key','UserProfileSection','intersection','Reload','keys','where','info','count','client','message','map','send','model','render','../../components/parsers/qs','filters','userProfileId','filter','VIRTUAL','ejs','index','create','debug','UserProfileResource','show','readFileSync','request\x20sent','VoiceContext,\x20%s,\x20%s','Unable\x20to\x20retrieve\x20the\x20current\x20user','../../mysqldb','catch','stringify','Contexts','writeFileSync','sequelize','utf8','includeAll','code','like','order','files/templates/context.ejs','chan_sip.so','findAll','join','user','query','request','findOne'];(function(_0x124ae4,_0x430c65){const _0x4a3c48=function(_0x59dceb){while(--_0x59dceb){_0x124ae4['push'](_0x124ae4['shift']());}};_0x4a3c48(++_0x430c65);}(a861_0x4a3c,0xe7));const a861_0x59dc=function(_0x124ae4,_0x430c65){_0x124ae4=_0x124ae4-0x1bd;let _0x4a3c48=a861_0x4a3c[_0x124ae4];return _0x4a3c48;};const a861_0x5b1b95=a861_0x59dc;'use strict';const path=require(a861_0x5b1b95(0x1e9)),ejs=require(a861_0x5b1b95(0x1c4)),fs=require('fs'),_=require(a861_0x5b1b95(0x1fb)),qs=require(a861_0x5b1b95(0x1bf)),logger=require(a861_0x5b1b95(0x1f7))(a861_0x5b1b95(0x1f9)),config=require(a861_0x5b1b95(0x209)),{db}=require(a861_0x5b1b95(0x1ce)),{Op}=require(a861_0x5b1b95(0x1d3)),jayson=require(a861_0x5b1b95(0x1e7)),client=jayson[a861_0x5b1b95(0x212)][a861_0x5b1b95(0x1e1)]({'port':0x232a});function respondWithRpcPromise(_0x1a913a,_0x25d078,_0x146831,_0x220862){return new Promise(function(_0xa4b923,_0x326532){const _0x21d27d=a861_0x59dc,_0x114b99=_0x220862||client;return _0x114b99[_0x21d27d(0x1df)](_0x1a913a,_0x146831)['then'](function(_0x4676fe){const _0x544278=_0x21d27d;logger[_0x544278(0x210)](_0x544278(0x1cc),_0x25d078,'request\x20sent'),logger[_0x544278(0x1c7)](_0x544278(0x1f5),_0x25d078,_0x544278(0x1cb),JSON[_0x544278(0x1d0)](_0x4676fe));if(_0x4676fe['error']){if(_0x4676fe[_0x544278(0x1e2)][_0x544278(0x1d6)]===0x1f4)return logger[_0x544278(0x1e2)](_0x544278(0x1cc),_0x25d078,_0x4676fe[_0x544278(0x1e2)][_0x544278(0x213)]),_0x326532(_0x4676fe[_0x544278(0x1e2)][_0x544278(0x213)]);return logger['error']('VoiceContext,\x20%s,\x20%s',_0x25d078,_0x4676fe[_0x544278(0x1e2)][_0x544278(0x213)]),_0xa4b923(_0x4676fe[_0x544278(0x1e2)]['message']);}else logger[_0x544278(0x210)](_0x544278(0x1cc),_0x25d078,'request\x20sent'),_0xa4b923(_0x4676fe['result'][_0x544278(0x213)]);})[_0x21d27d(0x1cf)](function(_0x31f20e){const _0x52ac82=_0x21d27d;logger[_0x52ac82(0x1e2)](_0x52ac82(0x1cc),_0x25d078,_0x31f20e),_0x326532(_0x31f20e);});});}function respondWithResult(_0x5eb9f8,_0x30c9c0){return _0x30c9c0=_0x30c9c0||0xc8,function(_0x52e093){const _0x18ef9a=a861_0x59dc;if(_0x52e093)return _0x5eb9f8[_0x18ef9a(0x207)](_0x30c9c0)[_0x18ef9a(0x208)](_0x52e093);};}function respondWithFilteredResult(_0x26df10,_0x4e13b8){return function(_0x3fe9e8){const _0x42e452=a861_0x59dc;if(_0x3fe9e8){const _0x2f7132=_0x3fe9e8[_0x42e452(0x211)],_0x14b059=_0x4e13b8['offset'];let _0x53da81=_0x4e13b8[_0x42e452(0x200)]+_0x4e13b8[_0x42e452(0x205)],_0x4802c9;return _0x53da81>=_0x2f7132?(_0x53da81=_0x2f7132,_0x4802c9=0xc8):_0x4802c9=0xce,_0x26df10['status'](_0x4802c9),_0x26df10[_0x42e452(0x1f6)](_0x42e452(0x204),_0x14b059+'-'+_0x53da81+'/'+_0x2f7132)[_0x42e452(0x208)](_0x3fe9e8);}return null;};}function saveUpdates(_0x3c2a78){return function(_0xd017e0){const _0x4c840f=a861_0x59dc;if(_0xd017e0)return _0xd017e0[_0x4c840f(0x1ff)](_0x3c2a78)[_0x4c840f(0x1f2)](function(_0x32143f){return _0x32143f;});return null;};}function removeEntity(_0x2d1fbe){return function(_0x1e8fe8){const _0x2fa0a6=a861_0x59dc;if(_0x1e8fe8)return _0x1e8fe8[_0x2fa0a6(0x201)]()[_0x2fa0a6(0x1f2)](function(){const _0x1fcc9f=_0x2fa0a6,_0x1ac418=_0x1e8fe8[_0x1fcc9f(0x1f4)]({'plain':!![]}),_0x323b80=_0x1fcc9f(0x1d1);return db[_0x1fcc9f(0x1c8)][_0x1fcc9f(0x201)]({'where':{'type':_0x323b80,'resourceId':_0x1ac418['id']}})[_0x1fcc9f(0x1f2)](function(){return _0x1e8fe8;});})[_0x2fa0a6(0x1f2)](function(){const _0x6de5e3=_0x2fa0a6;_0x2d1fbe['status'](0xcc)[_0x6de5e3(0x1f8)]();});};}function handleEntityNotFound(_0x583bfc){return function(_0x45c9ef){return!_0x45c9ef&&_0x583bfc['sendStatus'](0x194),_0x45c9ef;};}function handleError(_0x113411,_0x7702c1){return _0x7702c1=_0x7702c1||0x1f4,function(_0x409a61){const _0xbf36f4=a861_0x59dc;logger[_0xbf36f4(0x1e2)](_0x409a61[_0xbf36f4(0x1ee)]),_0x409a61['name']&&delete _0x409a61[_0xbf36f4(0x1e3)],_0x113411['status'](_0x7702c1)[_0xbf36f4(0x215)](_0x409a61);};}exports[a861_0x5b1b95(0x1c5)]=function(_0x2d6e95,_0x15fff2){const _0x394a19=a861_0x5b1b95;let _0x385832={};const _0x3bb237={},_0x46c392={'count':0x0,'rows':[]},_0x187336=_['map'](db[_0x394a19(0x1eb)]['rawAttributes'],function(_0x31fa35){const _0x1928ef=_0x394a19;return{'name':_0x31fa35[_0x1928ef(0x1fc)],'type':_0x31fa35[_0x1928ef(0x1e8)][_0x1928ef(0x20a)]};});_0x3bb237[_0x394a19(0x1bd)]=_[_0x394a19(0x214)](_0x187336,_0x394a19(0x1e3)),_0x3bb237['query']=_['keys'](_0x2d6e95[_0x394a19(0x1de)]),_0x3bb237['filters']=_[_0x394a19(0x20c)](_0x3bb237[_0x394a19(0x1bd)],_0x3bb237[_0x394a19(0x1de)]),_0x385832[_0x394a19(0x1f3)]=_[_0x394a19(0x20c)](_0x3bb237[_0x394a19(0x1bd)],qs[_0x394a19(0x1ec)](_0x2d6e95[_0x394a19(0x1de)][_0x394a19(0x1ec)])),_0x385832[_0x394a19(0x1f3)]=_0x385832[_0x394a19(0x1f3)]['length']?_0x385832[_0x394a19(0x1f3)]:_0x3bb237['model'];typeof _0x2d6e95[_0x394a19(0x1de)][_0x394a19(0x1ed)]==='undefined'&&(_0x385832['limit']=qs['limit'](_0x2d6e95[_0x394a19(0x1de)][_0x394a19(0x205)]),_0x385832[_0x394a19(0x200)]=qs[_0x394a19(0x200)](_0x2d6e95[_0x394a19(0x1de)][_0x394a19(0x200)]));_0x385832[_0x394a19(0x1d8)]=qs[_0x394a19(0x1f0)](_0x2d6e95[_0x394a19(0x1de)][_0x394a19(0x1f0)]),_0x385832['where']=qs['filters'](_[_0x394a19(0x1ea)](_0x2d6e95['query'],_0x3bb237[_0x394a19(0x1c0)]),_0x187336);_0x2d6e95[_0x394a19(0x1de)][_0x394a19(0x1c2)]&&(_0x385832[_0x394a19(0x20f)]=_['merge'](_0x385832[_0x394a19(0x20f)],{[Op['or']]:_['map'](_0x187336,function(_0x174532){const _0x408051=_0x394a19;if(_0x174532[_0x408051(0x1e8)]!==_0x408051(0x1c3)){const _0x568471={};return _0x568471[_0x174532[_0x408051(0x1e3)]]={[Op[_0x408051(0x1d7)]]:'%'+_0x2d6e95['query']['filter']+'%'},_0x568471;}})}));_0x385832=_[_0x394a19(0x206)]({},_0x385832,_0x2d6e95[_0x394a19(0x1fd)]);const _0x435555={'where':_0x385832[_0x394a19(0x20f)]};return db[_0x394a19(0x1eb)][_0x394a19(0x211)](_0x435555)[_0x394a19(0x1f2)](function(_0x269ce8){const _0x5b40a1=_0x394a19;return _0x46c392['count']=_0x269ce8,_0x2d6e95[_0x5b40a1(0x1de)][_0x5b40a1(0x1d5)]&&(_0x385832[_0x5b40a1(0x1e4)]=[{'all':!![]}]),db['VoiceContext']['findAll'](_0x385832);})[_0x394a19(0x1f2)](function(_0x29d124){const _0x211405=_0x394a19;return _0x46c392[_0x211405(0x1ef)]=_0x29d124,_0x46c392;})[_0x394a19(0x1f2)](respondWithFilteredResult(_0x15fff2,_0x385832))[_0x394a19(0x1cf)](handleError(_0x15fff2,null));},exports[a861_0x5b1b95(0x1c9)]=function(_0x532ec7,_0xed3f1d){const _0x4310f1=a861_0x5b1b95;let _0x3d397a={'raw':![],'where':{'id':_0x532ec7[_0x4310f1(0x1fe)]['id']}};const _0x4829e4={};return _0x4829e4['model']=_[_0x4310f1(0x20e)](db[_0x4310f1(0x1eb)][_0x4310f1(0x1fa)]),_0x4829e4['query']=_[_0x4310f1(0x20e)](_0x532ec7[_0x4310f1(0x1de)]),_0x4829e4[_0x4310f1(0x1c0)]=_[_0x4310f1(0x20c)](_0x4829e4['model'],_0x4829e4['query']),_0x3d397a['attributes']=_[_0x4310f1(0x20c)](_0x4829e4['model'],qs[_0x4310f1(0x1ec)](_0x532ec7[_0x4310f1(0x1de)][_0x4310f1(0x1ec)])),_0x3d397a[_0x4310f1(0x1f3)]=_0x3d397a['attributes']['length']?_0x3d397a['attributes']:_0x4829e4['model'],_0x532ec7[_0x4310f1(0x1de)][_0x4310f1(0x1d5)]&&(_0x3d397a[_0x4310f1(0x1e4)]=[{'all':!![]}]),_0x3d397a=_[_0x4310f1(0x206)]({},_0x3d397a,_0x532ec7[_0x4310f1(0x1fd)]),db[_0x4310f1(0x1eb)][_0x4310f1(0x1e0)](_0x3d397a)[_0x4310f1(0x1f2)](handleEntityNotFound(_0xed3f1d,null))[_0x4310f1(0x1f2)](respondWithResult(_0xed3f1d,null))[_0x4310f1(0x1cf)](handleError(_0xed3f1d,null));},exports[a861_0x5b1b95(0x1c6)]=function(_0x256716,_0x88ba94){const _0x5765fc=a861_0x5b1b95;let _0x4381f9;return db['VoiceContext']['create'](_0x256716[_0x5765fc(0x1e6)],{'raw':!![]})['then'](function(_0xec06f5){const _0x4ed36f=_0x5765fc;return _0x4381f9=_0xec06f5,db['VoiceContext'][_0x4ed36f(0x1db)]({'raw':!![]});})[_0x5765fc(0x1f2)](function(_0x5e7071){const _0x5e1c58=_0x5765fc,_0x4a342d=fs[_0x5e1c58(0x1ca)](path['join'](config[_0x5e1c58(0x203)],_0x5e1c58(0x1d9)),_0x5e1c58(0x1d4)),_0x2aeefc=ejs[_0x5e1c58(0x1be)](_0x4a342d,{'contexts':_0x5e7071||[]});fs[_0x5e1c58(0x1d2)](_0x5e1c58(0x1e5),_0x2aeefc);})[_0x5765fc(0x1f2)](function(){const _0x53d5bb=_0x5765fc;return respondWithRpcPromise(_0x53d5bb(0x20d),_0x53d5bb(0x1c6),{'module':'chan_sip.so'});})[_0x5765fc(0x1f2)](function(){const _0x5c08cf=_0x5765fc,_0x4a4279=_0x256716['user'][_0x5c08cf(0x1f4)]({'plain':!![]});if(!_0x4a4279)throw new Error(_0x5c08cf(0x1cd));if(_0x4a4279['role']===_0x5c08cf(0x1dd)){const _0x1206a2=_0x4381f9[_0x5c08cf(0x1f4)]({'plain':!![]});return db[_0x5c08cf(0x20b)][_0x5c08cf(0x1e0)]({'where':{'name':_0x5c08cf(0x1d1),'userProfileId':_0x4a4279[_0x5c08cf(0x1c1)]},'raw':!![]})['then'](function(_0xca5eb7){const _0x386b1f=_0x5c08cf;return _0xca5eb7&&_0xca5eb7[_0x386b1f(0x202)]===0x0?db[_0x386b1f(0x1c8)]['create']({'name':_0x1206a2[_0x386b1f(0x1e3)],'resourceId':_0x1206a2['id'],'type':_0xca5eb7[_0x386b1f(0x1e3)],'sectionId':_0xca5eb7['id']},{})[_0x386b1f(0x1f2)](function(){return _0x4381f9;}):_0x4381f9;})[_0x5c08cf(0x1cf)](function(_0x44c7e5){const _0x5b0ecb=_0x5c08cf;logger['error'](_0x5b0ecb(0x1f1),_0x44c7e5);throw _0x44c7e5;});}return _0x4381f9;})[_0x5765fc(0x1f2)](respondWithResult(_0x88ba94,0xc9))[_0x5765fc(0x1cf)](handleError(_0x88ba94,null));},exports['update']=function(_0xb8a186,_0xfa4280){const _0x754aae=a861_0x5b1b95;let _0x4db40b;return db[_0x754aae(0x1eb)][_0x754aae(0x1e0)]({'where':{'id':_0xb8a186[_0x754aae(0x1fe)]['id']}})[_0x754aae(0x1f2)](handleEntityNotFound(_0xfa4280,null))[_0x754aae(0x1f2)](saveUpdates(_0xb8a186[_0x754aae(0x1e6)],null))[_0x754aae(0x1f2)](function(_0x369601){const _0x34f367=_0x754aae;if(_0x369601)return _0x4db40b=_0x369601,db[_0x34f367(0x1eb)][_0x34f367(0x1db)]({'raw':!![]});})[_0x754aae(0x1f2)](function(_0x1256c8){const _0x3c08f8=_0x754aae,_0x4ee735=fs[_0x3c08f8(0x1ca)](path[_0x3c08f8(0x1dc)](config[_0x3c08f8(0x203)],'files/templates/context.ejs'),_0x3c08f8(0x1d4)),_0x5f3e63=ejs['render'](_0x4ee735,{'contexts':_0x1256c8||[]});fs['writeFileSync'](_0x3c08f8(0x1e5),_0x5f3e63);})[_0x754aae(0x1f2)](function(){const _0x5f4226=_0x754aae;return respondWithRpcPromise(_0x5f4226(0x20d),_0x5f4226(0x1ff),{'module':_0x5f4226(0x1da)});})[_0x754aae(0x1f2)](function(){return _0x4db40b;})[_0x754aae(0x1f2)](respondWithResult(_0xfa4280,null))[_0x754aae(0x1cf)](handleError(_0xfa4280,null));},exports[a861_0x5b1b95(0x201)]=function(_0x49a90d,_0x1b4ce0){const _0x222ef1=a861_0x5b1b95;return db[_0x222ef1(0x1eb)][_0x222ef1(0x1e0)]({'where':{'id':_0x49a90d[_0x222ef1(0x1fe)]['id']}})[_0x222ef1(0x1f2)](handleEntityNotFound(_0x1b4ce0,null))[_0x222ef1(0x1f2)](removeEntity(_0x1b4ce0,null))[_0x222ef1(0x1f2)](function(){const _0x39cf27=_0x222ef1;return db[_0x39cf27(0x1eb)][_0x39cf27(0x1db)]({'raw':!![]});})[_0x222ef1(0x1f2)](function(_0x4b9130){const _0x5898aa=_0x222ef1,_0x17fe2a=fs['readFileSync'](path[_0x5898aa(0x1dc)](config['root'],_0x5898aa(0x1d9)),_0x5898aa(0x1d4)),_0x3b7be5=ejs[_0x5898aa(0x1be)](_0x17fe2a,{'contexts':_0x4b9130});return fs[_0x5898aa(0x1d2)](_0x5898aa(0x1e5),_0x3b7be5),respondWithRpcPromise(_0x5898aa(0x20d),_0x5898aa(0x201),{'module':_0x5898aa(0x1da)});})[_0x222ef1(0x1cf)](handleError(_0x1b4ce0,null));};