Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / api / voiceContext / voiceContext.controller.js
index 7516238..65c896d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0439=['catch','show','params','keys','intersection','options','find','create','body','findAll','readFileSync','join','root','server/files/templates/context.ejs','utf8','render','writeFileSync','/etc/asterisk/extensions_xcally_contexts.conf','Reload','chan_sip.so','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','autoAssociation','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','../../mysqldb','jayson/promise','client','http','then','info','VoiceContext,\x20%s,\x20%s','request\x20sent','debug','VoiceContext,\x20%s,\x20%s,\x20%s','stringify','error','message','result','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','Contexts','UserProfileResource','destroy','name','index','map','VoiceContext','rawAttributes','fieldName','type','key','model','query','filters','attributes','fields','length','order','sort','where','filter','merge','VIRTUAL','include','rows'];(function(_0x1e9191,_0x3ce8bf){var _0x358c98=function(_0x36792b){while(--_0x36792b){_0x1e9191['push'](_0x1e9191['shift']());}};_0x358c98(++_0x3ce8bf);}(_0x0439,0xdd));var _0x9043=function(_0x271d02,_0x5cd222){_0x271d02=_0x271d02-0x0;var _0x14112d=_0x0439[_0x271d02];return _0x14112d;};'use strict';var pdf=require(_0x9043('0x0'));var emlformat=require(_0x9043('0x1'));var rimraf=require(_0x9043('0x2'));var zipdir=require(_0x9043('0x3'));var jsonpatch=require(_0x9043('0x4'));var rp=require(_0x9043('0x5'));var moment=require(_0x9043('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x9043('0x7'));var util=require(_0x9043('0x8'));var path=require(_0x9043('0x9'));var sox=require('sox');var csv=require(_0x9043('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x9043('0xb'));var crypto=require(_0x9043('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x9043('0xd'));var toCsv=require('to-csv');var querystring=require(_0x9043('0xe'));var Papa=require(_0x9043('0xf'));var Redis=require('ioredis');var authService=require(_0x9043('0x10'));var qs=require(_0x9043('0x11'));var as=require(_0x9043('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x9043('0x13'));var utils=require(_0x9043('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x9043('0x15'));var db=require(_0x9043('0x16'))['db'];var jayson=require(_0x9043('0x17'));var client=jayson[_0x9043('0x18')][_0x9043('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x39941f,_0x54c4e2,_0x141ec7,_0xf3f958){return new BPromise(function(_0x48b142,_0x18f916){var _0xe65772=_0xf3f958||client;return _0xe65772['request'](_0x39941f,_0x141ec7)[_0x9043('0x1a')](function(_0x1c2473){logger[_0x9043('0x1b')](_0x9043('0x1c'),_0x54c4e2,_0x9043('0x1d'));logger[_0x9043('0x1e')](_0x9043('0x1f'),_0x54c4e2,_0x9043('0x1d'),JSON[_0x9043('0x20')](_0x1c2473));if(_0x1c2473[_0x9043('0x21')]){if(_0x1c2473['error']['code']===0x1f4){logger['error'](_0x9043('0x1c'),_0x54c4e2,_0x1c2473[_0x9043('0x21')][_0x9043('0x22')]);return _0x18f916(_0x1c2473[_0x9043('0x21')]['message']);}logger[_0x9043('0x21')]('VoiceContext,\x20%s,\x20%s',_0x54c4e2,_0x1c2473['error'][_0x9043('0x22')]);return _0x48b142(_0x1c2473[_0x9043('0x21')][_0x9043('0x22')]);}else{logger[_0x9043('0x1b')](_0x9043('0x1c'),_0x54c4e2,_0x9043('0x1d'));_0x48b142(_0x1c2473[_0x9043('0x23')][_0x9043('0x22')]);}})['catch'](function(_0x187ad5){logger[_0x9043('0x21')](_0x9043('0x1c'),_0x54c4e2,_0x187ad5);_0x18f916(_0x187ad5);});});}function respondWithStatusCode(_0x5506bf,_0x18727f){_0x18727f=_0x18727f||0xcc;return function(_0x3c4fa4){if(_0x3c4fa4){return _0x5506bf[_0x9043('0x24')](_0x18727f);}return _0x5506bf[_0x9043('0x25')](_0x18727f)[_0x9043('0x26')]();};}function respondWithResult(_0x47b7f5,_0x16caf2){_0x16caf2=_0x16caf2||0xc8;return function(_0xca0bb1){if(_0xca0bb1){return _0x47b7f5[_0x9043('0x25')](_0x16caf2)[_0x9043('0x27')](_0xca0bb1);}};}function respondWithFilteredResult(_0x2003c3,_0x13e8dd){return function(_0x5f4975){if(_0x5f4975){var _0x25128c=_0x5f4975[_0x9043('0x28')],_0x5ca490=_0x13e8dd[_0x9043('0x29')],_0x45bec7=_0x13e8dd['offset']+_0x13e8dd[_0x9043('0x2a')],_0x2bcf73;if(_0x45bec7>=_0x25128c){_0x45bec7=_0x25128c;_0x2bcf73=0xc8;}else{_0x2bcf73=0xce;}_0x2003c3[_0x9043('0x25')](_0x2bcf73);return _0x2003c3[_0x9043('0x2b')](_0x9043('0x2c'),_0x5ca490+'-'+_0x45bec7+'/'+_0x25128c)[_0x9043('0x27')](_0x5f4975);}return null;};}function patchUpdates(_0x590357){return function(_0x352934){try{jsonpatch[_0x9043('0x2d')](_0x352934,_0x590357,!![]);}catch(_0xeaca86){return BPromise['reject'](_0xeaca86);}return _0x352934[_0x9043('0x2e')]();};}function saveUpdates(_0x16e8b8,_0x485b2c){return function(_0x243eee){if(_0x243eee){return _0x243eee[_0x9043('0x2f')](_0x16e8b8)['then'](function(_0x21eb3d){return _0x21eb3d;});}return null;};}function removeEntity(_0x339bc0,_0x414320){return function(_0x3e8a78){if(_0x3e8a78){return _0x3e8a78['destroy']()[_0x9043('0x1a')](function(){var _0x321b9a=_0x3e8a78['get']({'plain':!![]});var _0x4e2c29=_0x9043('0x30');return db[_0x9043('0x31')][_0x9043('0x32')]({'where':{'type':_0x4e2c29,'resourceId':_0x321b9a['id']}})[_0x9043('0x1a')](function(){return _0x3e8a78;});})[_0x9043('0x1a')](function(){_0x339bc0[_0x9043('0x25')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5b0e2e,_0x286b42){return function(_0x446956){if(!_0x446956){_0x5b0e2e[_0x9043('0x24')](0x194);}return _0x446956;};}function handleError(_0x119133,_0x154802){_0x154802=_0x154802||0x1f4;return function(_0x12a037){logger[_0x9043('0x21')](_0x12a037['stack']);if(_0x12a037[_0x9043('0x33')]){delete _0x12a037['name'];}_0x119133[_0x9043('0x25')](_0x154802)['send'](_0x12a037);};}exports[_0x9043('0x34')]=function(_0x4037a3,_0x4dfe26){var _0x4eefe0={},_0x20e145={},_0x2c8697={'count':0x0,'rows':[]};var _0x307bf0=_[_0x9043('0x35')](db[_0x9043('0x36')][_0x9043('0x37')],function(_0x3a9fe2){return{'name':_0x3a9fe2[_0x9043('0x38')],'type':_0x3a9fe2[_0x9043('0x39')][_0x9043('0x3a')]};});_0x20e145[_0x9043('0x3b')]=_[_0x9043('0x35')](_0x307bf0,'name');_0x20e145[_0x9043('0x3c')]=_['keys'](_0x4037a3[_0x9043('0x3c')]);_0x20e145[_0x9043('0x3d')]=_['intersection'](_0x20e145[_0x9043('0x3b')],_0x20e145[_0x9043('0x3c')]);_0x4eefe0[_0x9043('0x3e')]=_['intersection'](_0x20e145[_0x9043('0x3b')],qs[_0x9043('0x3f')](_0x4037a3[_0x9043('0x3c')][_0x9043('0x3f')]));_0x4eefe0[_0x9043('0x3e')]=_0x4eefe0[_0x9043('0x3e')][_0x9043('0x40')]?_0x4eefe0[_0x9043('0x3e')]:_0x20e145['model'];if(!_0x4037a3[_0x9043('0x3c')]['hasOwnProperty']('nolimit')){_0x4eefe0[_0x9043('0x2a')]=qs['limit'](_0x4037a3[_0x9043('0x3c')]['limit']);_0x4eefe0[_0x9043('0x29')]=qs[_0x9043('0x29')](_0x4037a3[_0x9043('0x3c')][_0x9043('0x29')]);}_0x4eefe0[_0x9043('0x41')]=qs[_0x9043('0x42')](_0x4037a3['query'][_0x9043('0x42')]);_0x4eefe0[_0x9043('0x43')]=qs[_0x9043('0x3d')](_['pick'](_0x4037a3[_0x9043('0x3c')],_0x20e145[_0x9043('0x3d')]),_0x307bf0);if(_0x4037a3['query'][_0x9043('0x44')]){_0x4eefe0['where']=_[_0x9043('0x45')](_0x4eefe0[_0x9043('0x43')],{'$or':_['map'](_0x307bf0,function(_0x489df1){if(_0x489df1[_0x9043('0x39')]!==_0x9043('0x46')){var _0x36b2d6={};_0x36b2d6[_0x489df1[_0x9043('0x33')]]={'$like':'%'+_0x4037a3['query'][_0x9043('0x44')]+'%'};return _0x36b2d6;}})});}_0x4eefe0=_[_0x9043('0x45')]({},_0x4eefe0,_0x4037a3['options']);var _0x526cc7={'where':_0x4eefe0[_0x9043('0x43')]};return db[_0x9043('0x36')]['count'](_0x526cc7)[_0x9043('0x1a')](function(_0x140284){_0x2c8697[_0x9043('0x28')]=_0x140284;if(_0x4037a3[_0x9043('0x3c')]['includeAll']){_0x4eefe0[_0x9043('0x47')]=[{'all':!![]}];}return db[_0x9043('0x36')]['findAll'](_0x4eefe0);})[_0x9043('0x1a')](function(_0x13972d){_0x2c8697[_0x9043('0x48')]=_0x13972d;return _0x2c8697;})[_0x9043('0x1a')](respondWithFilteredResult(_0x4dfe26,_0x4eefe0))[_0x9043('0x49')](handleError(_0x4dfe26,null));};exports[_0x9043('0x4a')]=function(_0x6f909a,_0x370821){var _0x3d7c69={'raw':![],'where':{'id':_0x6f909a[_0x9043('0x4b')]['id']}},_0x45c3d3={};_0x45c3d3[_0x9043('0x3b')]=_[_0x9043('0x4c')](db[_0x9043('0x36')]['rawAttributes']);_0x45c3d3[_0x9043('0x3c')]=_[_0x9043('0x4c')](_0x6f909a['query']);_0x45c3d3[_0x9043('0x3d')]=_[_0x9043('0x4d')](_0x45c3d3[_0x9043('0x3b')],_0x45c3d3['query']);_0x3d7c69['attributes']=_[_0x9043('0x4d')](_0x45c3d3[_0x9043('0x3b')],qs[_0x9043('0x3f')](_0x6f909a[_0x9043('0x3c')]['fields']));_0x3d7c69[_0x9043('0x3e')]=_0x3d7c69[_0x9043('0x3e')][_0x9043('0x40')]?_0x3d7c69[_0x9043('0x3e')]:_0x45c3d3['model'];if(_0x6f909a[_0x9043('0x3c')]['includeAll']){_0x3d7c69['include']=[{'all':!![]}];}_0x3d7c69=_[_0x9043('0x45')]({},_0x3d7c69,_0x6f909a[_0x9043('0x4e')]);return db[_0x9043('0x36')][_0x9043('0x4f')](_0x3d7c69)[_0x9043('0x1a')](handleEntityNotFound(_0x370821,null))[_0x9043('0x1a')](respondWithResult(_0x370821,null))[_0x9043('0x49')](handleError(_0x370821,null));};exports[_0x9043('0x50')]=function(_0x219de6,_0x3f9906,_0x156a6d){var _0x2f3b6a;return db[_0x9043('0x36')][_0x9043('0x50')](_0x219de6[_0x9043('0x51')],{'raw':!![]})['then'](function(_0x4c02eb){_0x2f3b6a=_0x4c02eb;return db[_0x9043('0x36')][_0x9043('0x52')]({'raw':!![]});})['then'](function(_0x382888){var _0x52a955=fs[_0x9043('0x53')](path[_0x9043('0x54')](config[_0x9043('0x55')],_0x9043('0x56')),_0x9043('0x57'));var _0x3bb098=ejs[_0x9043('0x58')](_0x52a955,{'contexts':_0x382888||[]});fs[_0x9043('0x59')](_0x9043('0x5a'),_0x3bb098);})[_0x9043('0x1a')](function(){return respondWithRpcPromise(_0x9043('0x5b'),'create',{'module':_0x9043('0x5c')});})[_0x9043('0x1a')](function(){var _0x2e5727=_0x219de6[_0x9043('0x5d')]['get']({'plain':!![]});if(!_0x2e5727)throw new Error(_0x9043('0x5e'));if(_0x2e5727[_0x9043('0x5f')]===_0x9043('0x5d')){var _0x329465=_0x2f3b6a[_0x9043('0x60')]({'plain':!![]});return db['UserProfileSection'][_0x9043('0x4f')]({'where':{'name':_0x9043('0x30'),'userProfileId':_0x2e5727['userProfileId']},'raw':!![]})[_0x9043('0x1a')](function(_0x22de5a){if(_0x22de5a&&_0x22de5a[_0x9043('0x61')]===0x0){return db[_0x9043('0x31')][_0x9043('0x50')]({'name':_0x329465[_0x9043('0x33')],'resourceId':_0x329465['id'],'type':_0x22de5a['name'],'sectionId':_0x22de5a['id']},{})['then'](function(){return _0x2f3b6a;});}else{return _0x2f3b6a;}})['catch'](function(_0x48ecc4){logger[_0x9043('0x21')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x48ecc4);throw _0x48ecc4;});}return _0x2f3b6a;})[_0x9043('0x1a')](respondWithResult(_0x3f9906,0xc9))[_0x9043('0x49')](handleError(_0x3f9906,null));};exports[_0x9043('0x2f')]=function(_0x5971a5,_0x419408,_0x125698){var _0xd60134;return db[_0x9043('0x36')][_0x9043('0x4f')]({'where':{'id':_0x5971a5[_0x9043('0x4b')]['id']}})[_0x9043('0x1a')](handleEntityNotFound(_0x419408,null))[_0x9043('0x1a')](saveUpdates(_0x5971a5[_0x9043('0x51')],null))['then'](function(_0x3b9b62){if(_0x3b9b62){_0xd60134=_0x3b9b62;return db[_0x9043('0x36')][_0x9043('0x52')]({'raw':!![]});}})[_0x9043('0x1a')](function(_0x466fc1){var _0x2154e7=fs[_0x9043('0x53')](path[_0x9043('0x54')](config['root'],_0x9043('0x56')),'utf8');var _0x433c46=ejs[_0x9043('0x58')](_0x2154e7,{'contexts':_0x466fc1||[]});fs['writeFileSync']('/etc/asterisk/extensions_xcally_contexts.conf',_0x433c46);})['then'](function(){return respondWithRpcPromise(_0x9043('0x5b'),_0x9043('0x2f'),{'module':'chan_sip.so'});})[_0x9043('0x1a')](function(){return _0xd60134;})[_0x9043('0x1a')](respondWithResult(_0x419408,null))['catch'](handleError(_0x419408,null));};exports['destroy']=function(_0x4b935f,_0x306f54,_0x3c8e22){var _0x547f80;return db['VoiceContext'][_0x9043('0x4f')]({'where':{'id':_0x4b935f[_0x9043('0x4b')]['id']}})[_0x9043('0x1a')](handleEntityNotFound(_0x306f54,null))[_0x9043('0x1a')](removeEntity(_0x306f54,null))[_0x9043('0x1a')](function(){return db[_0x9043('0x36')][_0x9043('0x52')]({'raw':!![]});})[_0x9043('0x1a')](function(_0x32a82b){var _0x1696bc=fs['readFileSync'](path[_0x9043('0x54')](config[_0x9043('0x55')],_0x9043('0x56')),'utf8');var _0x588e74=ejs[_0x9043('0x58')](_0x1696bc,{'contexts':_0x32a82b});fs[_0x9043('0x59')](_0x9043('0x5a'),_0x588e74);return respondWithRpcPromise('Reload','destroy',{'module':_0x9043('0x5c')});})[_0x9043('0x49')](handleError(_0x306f54,null));};
\ No newline at end of file
+var _0x1dc1=['where','options','includeAll','include','findAll','show','rawAttributes','merge','find','create','readFileSync','join','root','server/files/templates/context.ejs','utf8','render','writeFileSync','/etc/asterisk/extensions_xcally_contexts.conf','Reload','chan_sip.so','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','client','http','request','then','info','VoiceContext,\x20%s,\x20%s','request\x20sent','VoiceContext,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','destroy','get','UserProfileResource','name','send','index','map','VoiceContext','fieldName','type','keys','intersection','model','query','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter'];(function(_0x413feb,_0x10477f){var _0x40ee88=function(_0x32a3f6){while(--_0x32a3f6){_0x413feb['push'](_0x413feb['shift']());}};_0x40ee88(++_0x10477f);}(_0x1dc1,0xe5));var _0x11dc=function(_0x3fdaec,_0x17c64d){_0x3fdaec=_0x3fdaec-0x0;var _0x2e3cb3=_0x1dc1[_0x3fdaec];return _0x2e3cb3;};'use strict';var emlformat=require(_0x11dc('0x0'));var rimraf=require(_0x11dc('0x1'));var zipdir=require(_0x11dc('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x11dc('0x3'));var moment=require(_0x11dc('0x4'));var BPromise=require(_0x11dc('0x5'));var Mustache=require(_0x11dc('0x6'));var util=require(_0x11dc('0x7'));var path=require(_0x11dc('0x8'));var sox=require(_0x11dc('0x9'));var csv=require(_0x11dc('0xa'));var ejs=require(_0x11dc('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x11dc('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x11dc('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x11dc('0xa'));var querystring=require(_0x11dc('0xe'));var Papa=require(_0x11dc('0xf'));var Redis=require(_0x11dc('0x10'));var authService=require(_0x11dc('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x11dc('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x11dc('0x13'))(_0x11dc('0x14'));var utils=require(_0x11dc('0x15'));var config=require(_0x11dc('0x16'));var licenseUtil=require(_0x11dc('0x17'));var db=require(_0x11dc('0x18'))['db'];var jayson=require(_0x11dc('0x19'));var client=jayson[_0x11dc('0x1a')][_0x11dc('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x5ec7f4,_0x46a20f,_0x8d17c0,_0x10b427){return new BPromise(function(_0x368470,_0x1e1e0b){var _0x145b66=_0x10b427||client;return _0x145b66[_0x11dc('0x1c')](_0x5ec7f4,_0x8d17c0)[_0x11dc('0x1d')](function(_0x5edeb8){logger[_0x11dc('0x1e')](_0x11dc('0x1f'),_0x46a20f,_0x11dc('0x20'));logger['debug'](_0x11dc('0x21'),_0x46a20f,_0x11dc('0x20'),JSON[_0x11dc('0x22')](_0x5edeb8));if(_0x5edeb8[_0x11dc('0x23')]){if(_0x5edeb8['error']['code']===0x1f4){logger['error'](_0x11dc('0x1f'),_0x46a20f,_0x5edeb8['error'][_0x11dc('0x24')]);return _0x1e1e0b(_0x5edeb8[_0x11dc('0x23')][_0x11dc('0x24')]);}logger['error'](_0x11dc('0x1f'),_0x46a20f,_0x5edeb8[_0x11dc('0x23')][_0x11dc('0x24')]);return _0x368470(_0x5edeb8[_0x11dc('0x23')][_0x11dc('0x24')]);}else{logger['info']('VoiceContext,\x20%s,\x20%s',_0x46a20f,'request\x20sent');_0x368470(_0x5edeb8['result'][_0x11dc('0x24')]);}})[_0x11dc('0x25')](function(_0x4a1493){logger[_0x11dc('0x23')](_0x11dc('0x1f'),_0x46a20f,_0x4a1493);_0x1e1e0b(_0x4a1493);});});}function respondWithStatusCode(_0x312677,_0x1f9570){_0x1f9570=_0x1f9570||0xcc;return function(_0x4a9874){if(_0x4a9874){return _0x312677[_0x11dc('0x26')](_0x1f9570);}return _0x312677[_0x11dc('0x27')](_0x1f9570)[_0x11dc('0x28')]();};}function respondWithResult(_0x5124dc,_0x39630f){_0x39630f=_0x39630f||0xc8;return function(_0x5a35e5){if(_0x5a35e5){return _0x5124dc[_0x11dc('0x27')](_0x39630f)[_0x11dc('0x29')](_0x5a35e5);}};}function respondWithFilteredResult(_0x41bfca,_0x49bcc0){return function(_0x27bd74){if(_0x27bd74){var _0x40d192=typeof _0x49bcc0[_0x11dc('0x2a')]===_0x11dc('0x2b')&&typeof _0x49bcc0[_0x11dc('0x2c')]===_0x11dc('0x2b');var _0x2284c6=_0x27bd74['count'];var _0x172b43=_0x40d192?0x0:_0x49bcc0['offset'];var _0x4ee65d=_0x40d192?_0x27bd74[_0x11dc('0x2d')]:_0x49bcc0[_0x11dc('0x2a')]+_0x49bcc0[_0x11dc('0x2c')];var _0x2b43c6;if(_0x4ee65d>=_0x2284c6){_0x4ee65d=_0x2284c6;_0x2b43c6=0xc8;}else{_0x2b43c6=0xce;}_0x41bfca[_0x11dc('0x27')](_0x2b43c6);return _0x41bfca[_0x11dc('0x2e')](_0x11dc('0x2f'),_0x172b43+'-'+_0x4ee65d+'/'+_0x2284c6)[_0x11dc('0x29')](_0x27bd74);}return null;};}function patchUpdates(_0x4bc37c){return function(_0x7b74bf){try{jsonpatch['apply'](_0x7b74bf,_0x4bc37c,!![]);}catch(_0x1bf016){return BPromise[_0x11dc('0x30')](_0x1bf016);}return _0x7b74bf[_0x11dc('0x31')]();};}function saveUpdates(_0x294819,_0xa0f6f8){return function(_0x35283a){if(_0x35283a){return _0x35283a['update'](_0x294819)[_0x11dc('0x1d')](function(_0x1d7242){return _0x1d7242;});}return null;};}function removeEntity(_0x6cff2d,_0x3ace28){return function(_0x3ecaa2){if(_0x3ecaa2){return _0x3ecaa2[_0x11dc('0x32')]()[_0x11dc('0x1d')](function(){var _0xcae523=_0x3ecaa2[_0x11dc('0x33')]({'plain':!![]});var _0x1773d1='Contexts';return db[_0x11dc('0x34')][_0x11dc('0x32')]({'where':{'type':_0x1773d1,'resourceId':_0xcae523['id']}})[_0x11dc('0x1d')](function(){return _0x3ecaa2;});})[_0x11dc('0x1d')](function(){_0x6cff2d[_0x11dc('0x27')](0xcc)[_0x11dc('0x28')]();});}};}function handleEntityNotFound(_0x2dd461,_0x42d7f6){return function(_0x55a9ab){if(!_0x55a9ab){_0x2dd461[_0x11dc('0x26')](0x194);}return _0x55a9ab;};}function handleError(_0x1fab53,_0xa9a9d4){_0xa9a9d4=_0xa9a9d4||0x1f4;return function(_0x51fc3e){logger[_0x11dc('0x23')](_0x51fc3e['stack']);if(_0x51fc3e[_0x11dc('0x35')]){delete _0x51fc3e[_0x11dc('0x35')];}_0x1fab53[_0x11dc('0x27')](_0xa9a9d4)[_0x11dc('0x36')](_0x51fc3e);};}exports[_0x11dc('0x37')]=function(_0x3abd51,_0x512e7f){var _0x5aae23={},_0x1839f3={},_0x2daa1f={'count':0x0,'rows':[]};var _0xebce1=_[_0x11dc('0x38')](db[_0x11dc('0x39')]['rawAttributes'],function(_0xcc0f06){return{'name':_0xcc0f06[_0x11dc('0x3a')],'type':_0xcc0f06[_0x11dc('0x3b')]['key']};});_0x1839f3['model']=_[_0x11dc('0x38')](_0xebce1,_0x11dc('0x35'));_0x1839f3['query']=_[_0x11dc('0x3c')](_0x3abd51['query']);_0x1839f3['filters']=_[_0x11dc('0x3d')](_0x1839f3[_0x11dc('0x3e')],_0x1839f3[_0x11dc('0x3f')]);_0x5aae23[_0x11dc('0x40')]=_[_0x11dc('0x3d')](_0x1839f3[_0x11dc('0x3e')],qs[_0x11dc('0x41')](_0x3abd51[_0x11dc('0x3f')]['fields']));_0x5aae23[_0x11dc('0x40')]=_0x5aae23[_0x11dc('0x40')][_0x11dc('0x42')]?_0x5aae23[_0x11dc('0x40')]:_0x1839f3[_0x11dc('0x3e')];if(!_0x3abd51['query'][_0x11dc('0x43')](_0x11dc('0x44'))){_0x5aae23[_0x11dc('0x2c')]=qs[_0x11dc('0x2c')](_0x3abd51[_0x11dc('0x3f')][_0x11dc('0x2c')]);_0x5aae23[_0x11dc('0x2a')]=qs[_0x11dc('0x2a')](_0x3abd51[_0x11dc('0x3f')][_0x11dc('0x2a')]);}_0x5aae23[_0x11dc('0x45')]=qs[_0x11dc('0x46')](_0x3abd51[_0x11dc('0x3f')][_0x11dc('0x46')]);_0x5aae23['where']=qs[_0x11dc('0x47')](_[_0x11dc('0x48')](_0x3abd51['query'],_0x1839f3[_0x11dc('0x47')]),_0xebce1);if(_0x3abd51[_0x11dc('0x3f')][_0x11dc('0x49')]){_0x5aae23[_0x11dc('0x4a')]=_['merge'](_0x5aae23[_0x11dc('0x4a')],{'$or':_[_0x11dc('0x38')](_0xebce1,function(_0x39ce7b){if(_0x39ce7b[_0x11dc('0x3b')]!=='VIRTUAL'){var _0x4af9b6={};_0x4af9b6[_0x39ce7b[_0x11dc('0x35')]]={'$like':'%'+_0x3abd51[_0x11dc('0x3f')]['filter']+'%'};return _0x4af9b6;}})});}_0x5aae23=_['merge']({},_0x5aae23,_0x3abd51[_0x11dc('0x4b')]);var _0x66d235={'where':_0x5aae23[_0x11dc('0x4a')]};return db[_0x11dc('0x39')]['count'](_0x66d235)['then'](function(_0xf97c29){_0x2daa1f[_0x11dc('0x2d')]=_0xf97c29;if(_0x3abd51['query'][_0x11dc('0x4c')]){_0x5aae23[_0x11dc('0x4d')]=[{'all':!![]}];}return db[_0x11dc('0x39')][_0x11dc('0x4e')](_0x5aae23);})[_0x11dc('0x1d')](function(_0x32c856){_0x2daa1f['rows']=_0x32c856;return _0x2daa1f;})[_0x11dc('0x1d')](respondWithFilteredResult(_0x512e7f,_0x5aae23))[_0x11dc('0x25')](handleError(_0x512e7f,null));};exports[_0x11dc('0x4f')]=function(_0x3e2c89,_0x43cce8){var _0x30fffa={'raw':![],'where':{'id':_0x3e2c89['params']['id']}},_0x5159fb={};_0x5159fb[_0x11dc('0x3e')]=_[_0x11dc('0x3c')](db[_0x11dc('0x39')][_0x11dc('0x50')]);_0x5159fb[_0x11dc('0x3f')]=_['keys'](_0x3e2c89[_0x11dc('0x3f')]);_0x5159fb['filters']=_['intersection'](_0x5159fb['model'],_0x5159fb['query']);_0x30fffa[_0x11dc('0x40')]=_['intersection'](_0x5159fb[_0x11dc('0x3e')],qs['fields'](_0x3e2c89[_0x11dc('0x3f')][_0x11dc('0x41')]));_0x30fffa[_0x11dc('0x40')]=_0x30fffa[_0x11dc('0x40')]['length']?_0x30fffa[_0x11dc('0x40')]:_0x5159fb[_0x11dc('0x3e')];if(_0x3e2c89[_0x11dc('0x3f')]['includeAll']){_0x30fffa[_0x11dc('0x4d')]=[{'all':!![]}];}_0x30fffa=_[_0x11dc('0x51')]({},_0x30fffa,_0x3e2c89[_0x11dc('0x4b')]);return db[_0x11dc('0x39')][_0x11dc('0x52')](_0x30fffa)['then'](handleEntityNotFound(_0x43cce8,null))[_0x11dc('0x1d')](respondWithResult(_0x43cce8,null))[_0x11dc('0x25')](handleError(_0x43cce8,null));};exports['create']=function(_0x4f87ae,_0x55f67f,_0xf7d446){var _0x88d55a;return db[_0x11dc('0x39')][_0x11dc('0x53')](_0x4f87ae['body'],{'raw':!![]})['then'](function(_0x51dd02){_0x88d55a=_0x51dd02;return db[_0x11dc('0x39')]['findAll']({'raw':!![]});})[_0x11dc('0x1d')](function(_0x1f4f91){var _0x3f73cf=fs[_0x11dc('0x54')](path[_0x11dc('0x55')](config[_0x11dc('0x56')],_0x11dc('0x57')),_0x11dc('0x58'));var _0xc9ee2f=ejs[_0x11dc('0x59')](_0x3f73cf,{'contexts':_0x1f4f91||[]});fs[_0x11dc('0x5a')](_0x11dc('0x5b'),_0xc9ee2f);})['then'](function(){return respondWithRpcPromise(_0x11dc('0x5c'),_0x11dc('0x53'),{'module':_0x11dc('0x5d')});})[_0x11dc('0x1d')](function(){var _0x2bd7bb=_0x4f87ae['user'][_0x11dc('0x33')]({'plain':!![]});if(!_0x2bd7bb)throw new Error(_0x11dc('0x5e'));if(_0x2bd7bb[_0x11dc('0x5f')]===_0x11dc('0x60')){var _0x5423cb=_0x88d55a['get']({'plain':!![]});return db['UserProfileSection'][_0x11dc('0x52')]({'where':{'name':'Contexts','userProfileId':_0x2bd7bb['userProfileId']},'raw':!![]})[_0x11dc('0x1d')](function(_0x33a97a){if(_0x33a97a&&_0x33a97a[_0x11dc('0x61')]===0x0){return db['UserProfileResource']['create']({'name':_0x5423cb[_0x11dc('0x35')],'resourceId':_0x5423cb['id'],'type':_0x33a97a['name'],'sectionId':_0x33a97a['id']},{})['then'](function(){return _0x88d55a;});}else{return _0x88d55a;}})[_0x11dc('0x25')](function(_0x470e28){logger[_0x11dc('0x23')](_0x11dc('0x62'),_0x470e28);throw _0x470e28;});}return _0x88d55a;})['then'](respondWithResult(_0x55f67f,0xc9))[_0x11dc('0x25')](handleError(_0x55f67f,null));};exports[_0x11dc('0x63')]=function(_0x53e4fe,_0x448e21,_0x2fa644){var _0x1655d4;return db[_0x11dc('0x39')][_0x11dc('0x52')]({'where':{'id':_0x53e4fe[_0x11dc('0x64')]['id']}})[_0x11dc('0x1d')](handleEntityNotFound(_0x448e21,null))[_0x11dc('0x1d')](saveUpdates(_0x53e4fe['body'],null))[_0x11dc('0x1d')](function(_0x3243b6){if(_0x3243b6){_0x1655d4=_0x3243b6;return db['VoiceContext'][_0x11dc('0x4e')]({'raw':!![]});}})['then'](function(_0x71b57b){var _0x2cd9b5=fs[_0x11dc('0x54')](path[_0x11dc('0x55')](config['root'],'server/files/templates/context.ejs'),_0x11dc('0x58'));var _0xe8eae0=ejs[_0x11dc('0x59')](_0x2cd9b5,{'contexts':_0x71b57b||[]});fs[_0x11dc('0x5a')](_0x11dc('0x5b'),_0xe8eae0);})[_0x11dc('0x1d')](function(){return respondWithRpcPromise(_0x11dc('0x5c'),'update',{'module':'chan_sip.so'});})[_0x11dc('0x1d')](function(){return _0x1655d4;})['then'](respondWithResult(_0x448e21,null))['catch'](handleError(_0x448e21,null));};exports[_0x11dc('0x32')]=function(_0x3c0384,_0x4c5089,_0x5733f1){var _0x7ab070;return db[_0x11dc('0x39')][_0x11dc('0x52')]({'where':{'id':_0x3c0384[_0x11dc('0x64')]['id']}})['then'](handleEntityNotFound(_0x4c5089,null))['then'](removeEntity(_0x4c5089,null))[_0x11dc('0x1d')](function(){return db[_0x11dc('0x39')][_0x11dc('0x4e')]({'raw':!![]});})[_0x11dc('0x1d')](function(_0x28ed02){var _0x16db27=fs['readFileSync'](path[_0x11dc('0x55')](config[_0x11dc('0x56')],_0x11dc('0x57')),_0x11dc('0x58'));var _0x2bbb9c=ejs['render'](_0x16db27,{'contexts':_0x28ed02});fs[_0x11dc('0x5a')](_0x11dc('0x5b'),_0x2bbb9c);return respondWithRpcPromise('Reload',_0x11dc('0x32'),{'module':_0x11dc('0x5d')});})['catch'](handleError(_0x4c5089,null));};
\ No newline at end of file