Built motion from commit 9e1399f3.|2.5.37
[motion2.git] / server / api / voiceMusicOnHold / voiceMusicOnHold.controller.js
index 86236f0..34eac2d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x139d=['query','keys','filters','intersection','fields','attributes','length','sort','pick','filter','where','merge','options','includeAll','include','catch','params','find','body','create','sequelize','transaction','mode','files','directory','server/files/moh','mkdirSync','0777','user','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','readdirSync','forEach','unlinkSync','join','rmdirSync','Sequelize','message','addSound','Sound','findOne','save_name','converted_format','createdAt','root','server/files/sounds/converted','basename','extname','format','%s.%s','ValidationError','removeSound','id2','getSounds','order','nolimit','eml-format','rimraf','request-promise','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','get','UserProfileResource','destroy','sendStatus','name','index','map','VoiceMusicOnHold','rawAttributes','fieldName','type','key','model'];(function(_0x42e8e7,_0x89a365){var _0x3d1515=function(_0x5d1521){while(--_0x5d1521){_0x42e8e7['push'](_0x42e8e7['shift']());}};_0x3d1515(++_0x89a365);}(_0x139d,0x170));var _0xd139=function(_0x4dd571,_0x182b31){_0x4dd571=_0x4dd571-0x0;var _0x236a5f=_0x139d[_0x4dd571];return _0x236a5f;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xd139('0x0'));var rimraf=require(_0xd139('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xd139('0x2'));var moment=require('moment');var BPromise=require(_0xd139('0x3'));var Mustache=require(_0xd139('0x4'));var util=require(_0xd139('0x5'));var path=require(_0xd139('0x6'));var sox=require('sox');var csv=require(_0xd139('0x7'));var ejs=require(_0xd139('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0xd139('0x9'));var crypto=require(_0xd139('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xd139('0xb'));var toCsv=require(_0xd139('0x7'));var querystring=require(_0xd139('0xc'));var Papa=require(_0xd139('0xd'));var Redis=require(_0xd139('0xe'));var authService=require(_0xd139('0xf'));var qs=require(_0xd139('0x10'));var as=require(_0xd139('0x11'));var hardwareService=require(_0xd139('0x12'));var logger=require(_0xd139('0x13'))('api');var utils=require(_0xd139('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xd139('0x15'))['db'];function respondWithStatusCode(_0x20a373,_0x581223){_0x581223=_0x581223||0xcc;return function(_0x3a481b){if(_0x3a481b){return _0x20a373['sendStatus'](_0x581223);}return _0x20a373[_0xd139('0x16')](_0x581223)[_0xd139('0x17')]();};}function respondWithResult(_0x49ef20,_0x42580f){_0x42580f=_0x42580f||0xc8;return function(_0x3a27e8){if(_0x3a27e8){return _0x49ef20['status'](_0x42580f)[_0xd139('0x18')](_0x3a27e8);}};}function respondWithFilteredResult(_0x43d9db,_0x3822c7){return function(_0x43c93e){if(_0x43c93e){var _0x243eb8=_0x43c93e[_0xd139('0x19')],_0xed36c6=_0x3822c7[_0xd139('0x1a')],_0x4c3a35=_0x3822c7[_0xd139('0x1a')]+_0x3822c7[_0xd139('0x1b')],_0x1627af;if(_0x4c3a35>=_0x243eb8){_0x4c3a35=_0x243eb8;_0x1627af=0xc8;}else{_0x1627af=0xce;}_0x43d9db[_0xd139('0x16')](_0x1627af);return _0x43d9db[_0xd139('0x1c')](_0xd139('0x1d'),_0xed36c6+'-'+_0x4c3a35+'/'+_0x243eb8)['json'](_0x43c93e);}return null;};}function patchUpdates(_0x49ae43){return function(_0x4abbd2){try{jsonpatch[_0xd139('0x1e')](_0x4abbd2,_0x49ae43,!![]);}catch(_0x426cac){return BPromise[_0xd139('0x1f')](_0x426cac);}return _0x4abbd2[_0xd139('0x20')]();};}function saveUpdates(_0x537b17,_0x3b9819){return function(_0x1f8faa){if(_0x1f8faa){return _0x1f8faa[_0xd139('0x21')](_0x537b17)[_0xd139('0x22')](function(_0x7d4235){return _0x7d4235;});}return null;};}function removeEntity(_0x2a8bdb,_0x131a95){return function(_0x250dd2){if(_0x250dd2){return _0x250dd2['destroy']()[_0xd139('0x22')](function(){var _0x1080f6=_0x250dd2[_0xd139('0x23')]({'plain':!![]});var _0x2370c1='MusicOnHolds';return db[_0xd139('0x24')][_0xd139('0x25')]({'where':{'type':_0x2370c1,'resourceId':_0x1080f6['id']}})[_0xd139('0x22')](function(){return _0x250dd2;});})[_0xd139('0x22')](function(){_0x2a8bdb['status'](0xcc)[_0xd139('0x17')]();});}};}function handleEntityNotFound(_0x219adf,_0x5a4044){return function(_0x15432b){if(!_0x15432b){_0x219adf[_0xd139('0x26')](0x194);}return _0x15432b;};}function handleError(_0x360f80,_0x4fc266){_0x4fc266=_0x4fc266||0x1f4;return function(_0x2016e6){logger['error'](_0x2016e6['stack']);if(_0x2016e6['name']){delete _0x2016e6[_0xd139('0x27')];}_0x360f80['status'](_0x4fc266)['send'](_0x2016e6);};}exports[_0xd139('0x28')]=function(_0x5a8bce,_0x239251){var _0x4c967c={},_0x116e24={},_0x2b0f9b={'count':0x0,'rows':[]};var _0x2d4201=_[_0xd139('0x29')](db[_0xd139('0x2a')][_0xd139('0x2b')],function(_0x1e0c71){return{'name':_0x1e0c71[_0xd139('0x2c')],'type':_0x1e0c71[_0xd139('0x2d')][_0xd139('0x2e')]};});_0x116e24[_0xd139('0x2f')]=_[_0xd139('0x29')](_0x2d4201,'name');_0x116e24[_0xd139('0x30')]=_[_0xd139('0x31')](_0x5a8bce[_0xd139('0x30')]);_0x116e24[_0xd139('0x32')]=_[_0xd139('0x33')](_0x116e24[_0xd139('0x2f')],_0x116e24[_0xd139('0x30')]);_0x4c967c['attributes']=_[_0xd139('0x33')](_0x116e24[_0xd139('0x2f')],qs[_0xd139('0x34')](_0x5a8bce[_0xd139('0x30')][_0xd139('0x34')]));_0x4c967c[_0xd139('0x35')]=_0x4c967c[_0xd139('0x35')][_0xd139('0x36')]?_0x4c967c[_0xd139('0x35')]:_0x116e24[_0xd139('0x2f')];if(!_0x5a8bce[_0xd139('0x30')]['hasOwnProperty']('nolimit')){_0x4c967c[_0xd139('0x1b')]=qs[_0xd139('0x1b')](_0x5a8bce[_0xd139('0x30')][_0xd139('0x1b')]);_0x4c967c[_0xd139('0x1a')]=qs['offset'](_0x5a8bce[_0xd139('0x30')]['offset']);}_0x4c967c['order']=qs[_0xd139('0x37')](_0x5a8bce[_0xd139('0x30')][_0xd139('0x37')]);_0x4c967c['where']=qs[_0xd139('0x32')](_[_0xd139('0x38')](_0x5a8bce['query'],_0x116e24['filters']),_0x2d4201);if(_0x5a8bce[_0xd139('0x30')][_0xd139('0x39')]){_0x4c967c[_0xd139('0x3a')]=_[_0xd139('0x3b')](_0x4c967c[_0xd139('0x3a')],{'$or':_[_0xd139('0x29')](_0x2d4201,function(_0x111c4c){if(_0x111c4c[_0xd139('0x2d')]!=='VIRTUAL'){var _0x561582={};_0x561582[_0x111c4c[_0xd139('0x27')]]={'$like':'%'+_0x5a8bce[_0xd139('0x30')][_0xd139('0x39')]+'%'};return _0x561582;}})});}_0x4c967c=_[_0xd139('0x3b')]({},_0x4c967c,_0x5a8bce[_0xd139('0x3c')]);var _0x21fb37={'where':_0x4c967c[_0xd139('0x3a')]};return db[_0xd139('0x2a')][_0xd139('0x19')](_0x21fb37)[_0xd139('0x22')](function(_0x1a8c7d){_0x2b0f9b[_0xd139('0x19')]=_0x1a8c7d;if(_0x5a8bce['query'][_0xd139('0x3d')]){_0x4c967c[_0xd139('0x3e')]=[{'all':!![]}];}return db['VoiceMusicOnHold']['findAll'](_0x4c967c);})[_0xd139('0x22')](function(_0x5fde87){_0x2b0f9b['rows']=_0x5fde87;return _0x2b0f9b;})[_0xd139('0x22')](respondWithFilteredResult(_0x239251,_0x4c967c))[_0xd139('0x3f')](handleError(_0x239251,null));};exports['show']=function(_0x4150ea,_0x434523){var _0x2f14c7={'raw':![],'where':{'id':_0x4150ea[_0xd139('0x40')]['id']}},_0x1699ab={};_0x1699ab[_0xd139('0x2f')]=_['keys'](db[_0xd139('0x2a')]['rawAttributes']);_0x1699ab[_0xd139('0x30')]=_[_0xd139('0x31')](_0x4150ea['query']);_0x1699ab[_0xd139('0x32')]=_[_0xd139('0x33')](_0x1699ab[_0xd139('0x2f')],_0x1699ab[_0xd139('0x30')]);_0x2f14c7[_0xd139('0x35')]=_[_0xd139('0x33')](_0x1699ab[_0xd139('0x2f')],qs[_0xd139('0x34')](_0x4150ea['query'][_0xd139('0x34')]));_0x2f14c7[_0xd139('0x35')]=_0x2f14c7[_0xd139('0x35')]['length']?_0x2f14c7[_0xd139('0x35')]:_0x1699ab[_0xd139('0x2f')];if(_0x4150ea[_0xd139('0x30')]['includeAll']){_0x2f14c7['include']=[{'all':!![]}];}_0x2f14c7=_[_0xd139('0x3b')]({},_0x2f14c7,_0x4150ea['options']);return db[_0xd139('0x2a')][_0xd139('0x41')](_0x2f14c7)[_0xd139('0x22')](handleEntityNotFound(_0x434523,null))[_0xd139('0x22')](respondWithResult(_0x434523,null))['catch'](handleError(_0x434523,null));};exports[_0xd139('0x21')]=function(_0x40ed77,_0x102cfa){if(_0x40ed77[_0xd139('0x42')]['id']){delete _0x40ed77[_0xd139('0x42')]['id'];}return db['VoiceMusicOnHold']['find']({'where':{'id':_0x40ed77[_0xd139('0x40')]['id']}})['then'](handleEntityNotFound(_0x102cfa,null))[_0xd139('0x22')](saveUpdates(_0x40ed77[_0xd139('0x42')],null))[_0xd139('0x22')](respondWithResult(_0x102cfa,null))[_0xd139('0x3f')](handleError(_0x102cfa,null));};exports[_0xd139('0x43')]=function(_0x842671,_0x3ef91e,_0xdd1935){return db[_0xd139('0x44')][_0xd139('0x45')](function(_0x1d5348){if(_0x842671[_0xd139('0x42')][_0xd139('0x46')]===_0xd139('0x47')){_0x842671[_0xd139('0x42')][_0xd139('0x48')]=path['join'](config['root'],_0xd139('0x49'),_0x842671[_0xd139('0x42')]['name']);}return db['VoiceMusicOnHold']['create'](_0x842671[_0xd139('0x42')],{'transaction':_0x1d5348})[_0xd139('0x22')](function(_0x142514){if(_0x842671['body'][_0xd139('0x46')]===_0xd139('0x47')){fs[_0xd139('0x4a')](_0x142514[_0xd139('0x48')],parseInt(_0xd139('0x4b'),0x8));}var _0x265b92=_0x842671[_0xd139('0x4c')][_0xd139('0x23')]({'plain':!![]});if(!_0x265b92)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x265b92['role']===_0xd139('0x4c')){var _0x161aac=_0x142514[_0xd139('0x23')]({'plain':!![]});return db['UserProfileSection'][_0xd139('0x41')]({'where':{'name':'MusicOnHolds','userProfileId':_0x265b92[_0xd139('0x4d')]},'raw':!![]})[_0xd139('0x22')](function(_0x190947){if(_0x190947&&_0x190947['autoAssociation']===0x0){return db[_0xd139('0x24')]['create']({'name':_0x161aac[_0xd139('0x27')],'resourceId':_0x161aac['id'],'type':_0x190947[_0xd139('0x27')],'sectionId':_0x190947['id']},{})[_0xd139('0x22')](function(){return _0x142514;});}else{return _0x142514;}})[_0xd139('0x3f')](function(_0x43ce04){logger['error'](_0xd139('0x4e'),_0x43ce04);});}return _0x142514;});})[_0xd139('0x22')](respondWithResult(_0x3ef91e,0xc9))[_0xd139('0x3f')](handleError(_0x3ef91e,null));};exports[_0xd139('0x25')]=function(_0x374233,_0x25ce2e,_0x475f5d){var _0x3b12c5;return db['VoiceMusicOnHold'][_0xd139('0x41')]({'where':{'id':_0x374233[_0xd139('0x40')]['id']}})[_0xd139('0x22')](function(_0x544088){if(_0x544088){return db[_0xd139('0x44')][_0xd139('0x45')](function(_0x310639){return _0x544088[_0xd139('0x25')]({'transaction':_0x310639,'raw':!![]})[_0xd139('0x22')](function(_0x30af5f){if(_0x30af5f[_0xd139('0x48')]){fs[_0xd139('0x4f')](_0x30af5f['directory'])[_0xd139('0x50')](function(_0x5de8a8){fs[_0xd139('0x51')](path[_0xd139('0x52')](_0x30af5f[_0xd139('0x48')],_0x5de8a8));});fs[_0xd139('0x53')](_0x30af5f[_0xd139('0x48')]);}return _0x30af5f;});})[_0xd139('0x3f')](function(_0x57d657){throw new db[(_0xd139('0x54'))]['ValidationError'](_0x57d657[_0xd139('0x55')]);});}})['then'](handleEntityNotFound(_0x25ce2e,null))[_0xd139('0x22')](removeEntity(_0x25ce2e,null))[_0xd139('0x3f')](handleError(_0x25ce2e,null));};exports[_0xd139('0x56')]=function(_0x1e2727,_0x5f41f0,_0x575c47){return db['sequelize'][_0xd139('0x45')](function(_0x366382){var _0x340c54;return db[_0xd139('0x2a')]['find']({'where':{'id':_0x1e2727[_0xd139('0x40')]['id']}})[_0xd139('0x22')](function(_0x3feceb){if(_0x3feceb){_0x340c54=_0x3feceb;return _0x3feceb[_0xd139('0x56')](_0x1e2727[_0xd139('0x42')]['id'],{'transaction':_0x366382});}})[_0xd139('0x22')](function(_0x2fb518){if(_0x2fb518){return db[_0xd139('0x57')][_0xd139('0x58')]({'where':{'id':_0x1e2727[_0xd139('0x42')]['id']},'attributes':['id',_0xd139('0x27'),_0xd139('0x59'),_0xd139('0x5a'),_0xd139('0x5b')],'raw':!![]});}})['then'](function(_0x539786){if(_0x539786){var _0x2a5d87=path['join'](config[_0xd139('0x5c')],_0xd139('0x5d'),util['format']('%s.%s',path[_0xd139('0x5e')](_0x539786[_0xd139('0x59')],path[_0xd139('0x5f')](_0x539786[_0xd139('0x59')])),_0x539786['converted_format']));var _0x3cd4c9=path['join'](config[_0xd139('0x5c')],_0xd139('0x49'),_0x340c54[_0xd139('0x27')],util[_0xd139('0x60')](_0xd139('0x61'),_0x539786[_0xd139('0x27')],_0x539786[_0xd139('0x5a')]));fs['symlinkSync'](_0x2a5d87,_0x3cd4c9);return _0x539786;}})[_0xd139('0x3f')](function(_0x344d54){throw new db[(_0xd139('0x54'))][(_0xd139('0x62'))](_0x344d54[_0xd139('0x55')]);});})[_0xd139('0x22')](handleEntityNotFound(_0x5f41f0,null))[_0xd139('0x22')](respondWithResult(_0x5f41f0,0xc9))[_0xd139('0x3f')](handleError(_0x5f41f0,null));};exports[_0xd139('0x63')]=function(_0x43f758,_0x3ab618,_0x3eae28){return db[_0xd139('0x44')][_0xd139('0x45')](function(_0x3a460d){var _0x3ed4c5;return db[_0xd139('0x2a')][_0xd139('0x58')]({'where':{'id':_0x43f758[_0xd139('0x40')]['id']}})[_0xd139('0x22')](handleEntityNotFound(_0x3ab618,null))[_0xd139('0x22')](function(_0x4f2394){if(_0x4f2394){_0x3ed4c5=_0x4f2394;return _0x4f2394['removeSound'](_0x43f758[_0xd139('0x40')][_0xd139('0x64')]);}})[_0xd139('0x22')](function(_0x25845e){if(_0x25845e){return db[_0xd139('0x57')][_0xd139('0x58')]({'where':{'id':_0x43f758[_0xd139('0x40')][_0xd139('0x64')]},'attributes':['id',_0xd139('0x27'),'save_name',_0xd139('0x5a'),_0xd139('0x5b')],'raw':!![]});}})['then'](function(_0x2aeef5){if(_0x2aeef5){fs['unlinkSync'](path['join'](_0x3ed4c5[_0xd139('0x48')],util[_0xd139('0x60')](_0xd139('0x61'),_0x2aeef5['name'],_0x2aeef5[_0xd139('0x5a')])));return _0x2aeef5;}})[_0xd139('0x3f')](function(_0x346167){throw new db[(_0xd139('0x54'))]['ValidationError'](_0x346167[_0xd139('0x55')]);});})[_0xd139('0x22')](handleEntityNotFound(_0x3ab618,null))['then'](respondWithStatusCode(_0x3ab618,0xcc))[_0xd139('0x3f')](handleError(_0x3ab618,null));};exports[_0xd139('0x65')]=function(_0x488c64,_0xe0f131,_0x5a9776){var _0x4a77d0={};var _0x519cb9={};var _0x362ca3;var _0x1ad9b9;return db['VoiceMusicOnHold'][_0xd139('0x58')]({'where':{'id':_0x488c64[_0xd139('0x40')]['id']}})['then'](handleEntityNotFound(_0xe0f131,null))[_0xd139('0x22')](function(_0x226fb4){if(_0x226fb4){_0x362ca3=_0x226fb4;_0x519cb9[_0xd139('0x2f')]=_['keys'](db[_0xd139('0x57')][_0xd139('0x2b')]);_0x519cb9[_0xd139('0x30')]=_['keys'](_0x488c64[_0xd139('0x30')]);_0x519cb9[_0xd139('0x32')]=_['intersection'](_0x519cb9['model'],_0x519cb9['query']);_0x4a77d0['attributes']=_[_0xd139('0x33')](_0x519cb9[_0xd139('0x2f')],qs[_0xd139('0x34')](_0x488c64[_0xd139('0x30')][_0xd139('0x34')]));_0x4a77d0[_0xd139('0x35')]=_0x4a77d0[_0xd139('0x35')][_0xd139('0x36')]?_0x4a77d0['attributes']:_0x519cb9[_0xd139('0x2f')];_0x4a77d0[_0xd139('0x66')]=qs[_0xd139('0x37')](_0x488c64['query']['sort']);_0x4a77d0[_0xd139('0x3a')]=qs['filters'](_['pick'](_0x488c64['query'],_0x519cb9[_0xd139('0x32')]));if(_0x488c64['query'][_0xd139('0x39')]){_0x4a77d0[_0xd139('0x3a')]=_[_0xd139('0x3b')](_0x4a77d0[_0xd139('0x3a')],{'$or':_[_0xd139('0x29')](_0x4a77d0['attributes'],function(_0x345c57){var _0xc334bb={};_0xc334bb[_0x345c57]={'$like':'%'+_0x488c64[_0xd139('0x30')][_0xd139('0x39')]+'%'};return _0xc334bb;})});}_0x4a77d0=_[_0xd139('0x3b')]({},_0x4a77d0,_0x488c64['options']);return _0x362ca3['getSounds'](_0x4a77d0);}})['then'](function(_0x2f55a2){if(_0x2f55a2){_0x1ad9b9=_0x2f55a2[_0xd139('0x36')];if(!_0x488c64[_0xd139('0x30')]['hasOwnProperty'](_0xd139('0x67'))){_0x4a77d0[_0xd139('0x1b')]=qs[_0xd139('0x1b')](_0x488c64['query'][_0xd139('0x1b')]);_0x4a77d0['offset']=qs['offset'](_0x488c64['query']['offset']);}return _0x362ca3[_0xd139('0x65')](_0x4a77d0);}})[_0xd139('0x22')](function(_0x368362){if(_0x368362){return _0x368362?{'count':_0x1ad9b9,'rows':_0x368362}:null;}})[_0xd139('0x22')](respondWithResult(_0xe0f131,null))[_0xd139('0x3f')](handleError(_0xe0f131,null));};
\ No newline at end of file
+var _0x5f2f=['Sequelize','addSound','transaction','Sound','findOne','save_name','converted_format','createdAt','root','server/files/sounds/converted','%s.%s','basename','extname','format','symlinkSync','ValidationError','message','removeSound','id2','rawAttributes','order','getSounds','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','then','UserProfileResource','destroy','error','stack','name','send','index','map','VoiceMusicOnHold','fieldName','type','key','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','catch','show','params','update','body','sequelize','files','directory','join','server/files/moh','mode','mkdirSync','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','readdirSync','forEach','unlinkSync','rmdirSync'];(function(_0x286956,_0x18f551){var _0x37a4cb=function(_0x15a3b5){while(--_0x15a3b5){_0x286956['push'](_0x286956['shift']());}};_0x37a4cb(++_0x18f551);}(_0x5f2f,0x16c));var _0xf5f2=function(_0x21497a,_0x5287c1){_0x21497a=_0x21497a-0x0;var _0x1612a3=_0x5f2f[_0x21497a];return _0x1612a3;};'use strict';var emlformat=require(_0xf5f2('0x0'));var rimraf=require(_0xf5f2('0x1'));var zipdir=require(_0xf5f2('0x2'));var jsonpatch=require(_0xf5f2('0x3'));var rp=require(_0xf5f2('0x4'));var moment=require(_0xf5f2('0x5'));var BPromise=require(_0xf5f2('0x6'));var Mustache=require(_0xf5f2('0x7'));var util=require(_0xf5f2('0x8'));var path=require(_0xf5f2('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf5f2('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf5f2('0xb'));var squel=require('squel');var crypto=require(_0xf5f2('0xc'));var jsforce=require(_0xf5f2('0xd'));var deskjs=require(_0xf5f2('0xe'));var toCsv=require('to-csv');var querystring=require(_0xf5f2('0xf'));var Papa=require('papaparse');var Redis=require(_0xf5f2('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xf5f2('0x11'));var as=require(_0xf5f2('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf5f2('0x13'))('api');var utils=require('../../config/utils');var config=require(_0xf5f2('0x14'));var licenseUtil=require(_0xf5f2('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x12449e,_0x49180d){_0x49180d=_0x49180d||0xcc;return function(_0x1166b6){if(_0x1166b6){return _0x12449e[_0xf5f2('0x16')](_0x49180d);}return _0x12449e[_0xf5f2('0x17')](_0x49180d)[_0xf5f2('0x18')]();};}function respondWithResult(_0x4d84bb,_0x338cc9){_0x338cc9=_0x338cc9||0xc8;return function(_0x46559f){if(_0x46559f){return _0x4d84bb[_0xf5f2('0x17')](_0x338cc9)[_0xf5f2('0x19')](_0x46559f);}};}function respondWithFilteredResult(_0x2d6242,_0x59c1de){return function(_0x325189){if(_0x325189){var _0x2f98db=typeof _0x59c1de[_0xf5f2('0x1a')]===_0xf5f2('0x1b')&&typeof _0x59c1de[_0xf5f2('0x1c')]===_0xf5f2('0x1b');var _0x230775=_0x325189[_0xf5f2('0x1d')];var _0x1af0ca=_0x2f98db?0x0:_0x59c1de[_0xf5f2('0x1a')];var _0x5e7208=_0x2f98db?_0x325189[_0xf5f2('0x1d')]:_0x59c1de[_0xf5f2('0x1a')]+_0x59c1de['limit'];var _0x91f0;if(_0x5e7208>=_0x230775){_0x5e7208=_0x230775;_0x91f0=0xc8;}else{_0x91f0=0xce;}_0x2d6242['status'](_0x91f0);return _0x2d6242[_0xf5f2('0x1e')](_0xf5f2('0x1f'),_0x1af0ca+'-'+_0x5e7208+'/'+_0x230775)['json'](_0x325189);}return null;};}function patchUpdates(_0x540c8c){return function(_0x4cec2f){try{jsonpatch[_0xf5f2('0x20')](_0x4cec2f,_0x540c8c,!![]);}catch(_0x3cf523){return BPromise[_0xf5f2('0x21')](_0x3cf523);}return _0x4cec2f['save']();};}function saveUpdates(_0x16053c,_0x519c7e){return function(_0x1a22e1){if(_0x1a22e1){return _0x1a22e1['update'](_0x16053c)[_0xf5f2('0x22')](function(_0x43ddd4){return _0x43ddd4;});}return null;};}function removeEntity(_0x3cbff3,_0x599df4){return function(_0x24b2a0){if(_0x24b2a0){return _0x24b2a0['destroy']()[_0xf5f2('0x22')](function(){var _0x535aa3=_0x24b2a0['get']({'plain':!![]});var _0x1d00fa='MusicOnHolds';return db[_0xf5f2('0x23')][_0xf5f2('0x24')]({'where':{'type':_0x1d00fa,'resourceId':_0x535aa3['id']}})[_0xf5f2('0x22')](function(){return _0x24b2a0;});})['then'](function(){_0x3cbff3['status'](0xcc)[_0xf5f2('0x18')]();});}};}function handleEntityNotFound(_0xd703f9,_0x4b4b75){return function(_0x375a82){if(!_0x375a82){_0xd703f9[_0xf5f2('0x16')](0x194);}return _0x375a82;};}function handleError(_0x52e7ce,_0x5eaa5c){_0x5eaa5c=_0x5eaa5c||0x1f4;return function(_0xaff83d){logger[_0xf5f2('0x25')](_0xaff83d[_0xf5f2('0x26')]);if(_0xaff83d[_0xf5f2('0x27')]){delete _0xaff83d[_0xf5f2('0x27')];}_0x52e7ce[_0xf5f2('0x17')](_0x5eaa5c)[_0xf5f2('0x28')](_0xaff83d);};}exports[_0xf5f2('0x29')]=function(_0x2f12bc,_0x48e498){var _0x44228f={},_0xd8a3e={},_0x386a8d={'count':0x0,'rows':[]};var _0x57e517=_[_0xf5f2('0x2a')](db[_0xf5f2('0x2b')]['rawAttributes'],function(_0x40d6b8){return{'name':_0x40d6b8[_0xf5f2('0x2c')],'type':_0x40d6b8[_0xf5f2('0x2d')][_0xf5f2('0x2e')]};});_0xd8a3e[_0xf5f2('0x2f')]=_[_0xf5f2('0x2a')](_0x57e517,_0xf5f2('0x27'));_0xd8a3e['query']=_[_0xf5f2('0x30')](_0x2f12bc[_0xf5f2('0x31')]);_0xd8a3e[_0xf5f2('0x32')]=_[_0xf5f2('0x33')](_0xd8a3e[_0xf5f2('0x2f')],_0xd8a3e[_0xf5f2('0x31')]);_0x44228f['attributes']=_[_0xf5f2('0x33')](_0xd8a3e[_0xf5f2('0x2f')],qs[_0xf5f2('0x34')](_0x2f12bc[_0xf5f2('0x31')]['fields']));_0x44228f[_0xf5f2('0x35')]=_0x44228f[_0xf5f2('0x35')][_0xf5f2('0x36')]?_0x44228f['attributes']:_0xd8a3e['model'];if(!_0x2f12bc[_0xf5f2('0x31')][_0xf5f2('0x37')](_0xf5f2('0x38'))){_0x44228f[_0xf5f2('0x1c')]=qs[_0xf5f2('0x1c')](_0x2f12bc['query'][_0xf5f2('0x1c')]);_0x44228f[_0xf5f2('0x1a')]=qs[_0xf5f2('0x1a')](_0x2f12bc[_0xf5f2('0x31')][_0xf5f2('0x1a')]);}_0x44228f['order']=qs[_0xf5f2('0x39')](_0x2f12bc[_0xf5f2('0x31')][_0xf5f2('0x39')]);delete _0x2f12bc[_0xf5f2('0x31')][_0xf5f2('0x39')];_0x44228f[_0xf5f2('0x3a')]=qs[_0xf5f2('0x32')](_[_0xf5f2('0x3b')](_0x2f12bc[_0xf5f2('0x31')],_0xd8a3e[_0xf5f2('0x32')]),_0x57e517);if(_0x2f12bc[_0xf5f2('0x31')][_0xf5f2('0x3c')]){_0x44228f[_0xf5f2('0x3a')]=_['merge'](_0x44228f[_0xf5f2('0x3a')],{'$or':_[_0xf5f2('0x2a')](_0x57e517,function(_0x515693){if(_0x515693[_0xf5f2('0x2d')]!=='VIRTUAL'){var _0xe74338={};_0xe74338[_0x515693[_0xf5f2('0x27')]]={'$like':'%'+_0x2f12bc[_0xf5f2('0x31')][_0xf5f2('0x3c')]+'%'};return _0xe74338;}})});}_0x44228f=_[_0xf5f2('0x3d')]({},_0x44228f,_0x2f12bc[_0xf5f2('0x3e')]);var _0xa35467={'where':_0x44228f[_0xf5f2('0x3a')]};return db[_0xf5f2('0x2b')][_0xf5f2('0x1d')](_0xa35467)[_0xf5f2('0x22')](function(_0x59d866){_0x386a8d[_0xf5f2('0x1d')]=_0x59d866;if(_0x2f12bc['query'][_0xf5f2('0x3f')]){_0x44228f[_0xf5f2('0x40')]=[{'all':!![]}];}return db[_0xf5f2('0x2b')][_0xf5f2('0x41')](_0x44228f);})[_0xf5f2('0x22')](function(_0x3b634f){_0x386a8d[_0xf5f2('0x42')]=_0x3b634f;return _0x386a8d;})[_0xf5f2('0x22')](respondWithFilteredResult(_0x48e498,_0x44228f))[_0xf5f2('0x43')](handleError(_0x48e498,null));};exports[_0xf5f2('0x44')]=function(_0xda652c,_0x7dae71){var _0x3d568a={'raw':![],'where':{'id':_0xda652c[_0xf5f2('0x45')]['id']}},_0x2b7edc={};_0x2b7edc[_0xf5f2('0x2f')]=_[_0xf5f2('0x30')](db[_0xf5f2('0x2b')]['rawAttributes']);_0x2b7edc[_0xf5f2('0x31')]=_['keys'](_0xda652c[_0xf5f2('0x31')]);_0x2b7edc[_0xf5f2('0x32')]=_[_0xf5f2('0x33')](_0x2b7edc['model'],_0x2b7edc[_0xf5f2('0x31')]);_0x3d568a[_0xf5f2('0x35')]=_[_0xf5f2('0x33')](_0x2b7edc[_0xf5f2('0x2f')],qs['fields'](_0xda652c[_0xf5f2('0x31')][_0xf5f2('0x34')]));_0x3d568a[_0xf5f2('0x35')]=_0x3d568a[_0xf5f2('0x35')]['length']?_0x3d568a[_0xf5f2('0x35')]:_0x2b7edc[_0xf5f2('0x2f')];if(_0xda652c[_0xf5f2('0x31')]['includeAll']){_0x3d568a[_0xf5f2('0x40')]=[{'all':!![]}];}_0x3d568a=_['merge']({},_0x3d568a,_0xda652c[_0xf5f2('0x3e')]);return db[_0xf5f2('0x2b')]['find'](_0x3d568a)['then'](handleEntityNotFound(_0x7dae71,null))['then'](respondWithResult(_0x7dae71,null))[_0xf5f2('0x43')](handleError(_0x7dae71,null));};exports[_0xf5f2('0x46')]=function(_0x2d055e,_0x20dfeb){if(_0x2d055e[_0xf5f2('0x47')]['id']){delete _0x2d055e[_0xf5f2('0x47')]['id'];}return db['VoiceMusicOnHold']['find']({'where':{'id':_0x2d055e['params']['id']}})[_0xf5f2('0x22')](handleEntityNotFound(_0x20dfeb,null))[_0xf5f2('0x22')](saveUpdates(_0x2d055e[_0xf5f2('0x47')],null))['then'](respondWithResult(_0x20dfeb,null))[_0xf5f2('0x43')](handleError(_0x20dfeb,null));};exports['create']=function(_0x324cfd,_0x16cf7e,_0x2448d8){return db[_0xf5f2('0x48')]['transaction'](function(_0x15b57a){if(_0x324cfd['body']['mode']===_0xf5f2('0x49')){_0x324cfd[_0xf5f2('0x47')][_0xf5f2('0x4a')]=path[_0xf5f2('0x4b')](config['root'],_0xf5f2('0x4c'),_0x324cfd[_0xf5f2('0x47')][_0xf5f2('0x27')]);}return db[_0xf5f2('0x2b')]['create'](_0x324cfd[_0xf5f2('0x47')],{'transaction':_0x15b57a})[_0xf5f2('0x22')](function(_0x58a4d2){if(_0x324cfd[_0xf5f2('0x47')][_0xf5f2('0x4d')]===_0xf5f2('0x49')){fs[_0xf5f2('0x4e')](_0x58a4d2[_0xf5f2('0x4a')],parseInt('0777',0x8));}var _0x30a65f=_0x324cfd[_0xf5f2('0x4f')][_0xf5f2('0x50')]({'plain':!![]});if(!_0x30a65f)throw new Error(_0xf5f2('0x51'));if(_0x30a65f[_0xf5f2('0x52')]===_0xf5f2('0x4f')){var _0x18d2b3=_0x58a4d2[_0xf5f2('0x50')]({'plain':!![]});return db[_0xf5f2('0x53')][_0xf5f2('0x54')]({'where':{'name':'MusicOnHolds','userProfileId':_0x30a65f[_0xf5f2('0x55')]},'raw':!![]})[_0xf5f2('0x22')](function(_0x2f43be){if(_0x2f43be&&_0x2f43be['autoAssociation']===0x0){return db['UserProfileResource'][_0xf5f2('0x56')]({'name':_0x18d2b3['name'],'resourceId':_0x18d2b3['id'],'type':_0x2f43be[_0xf5f2('0x27')],'sectionId':_0x2f43be['id']},{})[_0xf5f2('0x22')](function(){return _0x58a4d2;});}else{return _0x58a4d2;}})[_0xf5f2('0x43')](function(_0x3e71e7){logger[_0xf5f2('0x25')](_0xf5f2('0x57'),_0x3e71e7);});}return _0x58a4d2;});})['then'](respondWithResult(_0x16cf7e,0xc9))[_0xf5f2('0x43')](handleError(_0x16cf7e,null));};exports[_0xf5f2('0x24')]=function(_0x451023,_0x554c6f,_0x2da0c4){var _0x209a6b;return db[_0xf5f2('0x2b')][_0xf5f2('0x54')]({'where':{'id':_0x451023[_0xf5f2('0x45')]['id']}})[_0xf5f2('0x22')](function(_0x425caa){if(_0x425caa){return db[_0xf5f2('0x48')]['transaction'](function(_0x510434){return _0x425caa['destroy']({'transaction':_0x510434,'raw':!![]})[_0xf5f2('0x22')](function(_0x58f547){if(_0x58f547[_0xf5f2('0x4a')]){fs[_0xf5f2('0x58')](_0x58f547[_0xf5f2('0x4a')])[_0xf5f2('0x59')](function(_0x59b624){fs[_0xf5f2('0x5a')](path['join'](_0x58f547[_0xf5f2('0x4a')],_0x59b624));});fs[_0xf5f2('0x5b')](_0x58f547[_0xf5f2('0x4a')]);}return _0x58f547;});})[_0xf5f2('0x43')](function(_0x1ba864){throw new db[(_0xf5f2('0x5c'))]['ValidationError'](_0x1ba864['message']);});}})['then'](handleEntityNotFound(_0x554c6f,null))['then'](removeEntity(_0x554c6f,null))['catch'](handleError(_0x554c6f,null));};exports[_0xf5f2('0x5d')]=function(_0x41e54d,_0x16a767,_0x4a910a){return db['sequelize'][_0xf5f2('0x5e')](function(_0xd3c4e8){var _0x17cc6d;return db[_0xf5f2('0x2b')]['find']({'where':{'id':_0x41e54d[_0xf5f2('0x45')]['id']}})[_0xf5f2('0x22')](function(_0x42d9df){if(_0x42d9df){_0x17cc6d=_0x42d9df;return _0x42d9df[_0xf5f2('0x5d')](_0x41e54d[_0xf5f2('0x47')]['id'],{'transaction':_0xd3c4e8});}})[_0xf5f2('0x22')](function(_0x430d81){if(_0x430d81){return db[_0xf5f2('0x5f')][_0xf5f2('0x60')]({'where':{'id':_0x41e54d[_0xf5f2('0x47')]['id']},'attributes':['id','name',_0xf5f2('0x61'),_0xf5f2('0x62'),_0xf5f2('0x63')],'raw':!![]});}})[_0xf5f2('0x22')](function(_0x2669c1){if(_0x2669c1){var _0x2efa59=path[_0xf5f2('0x4b')](config[_0xf5f2('0x64')],_0xf5f2('0x65'),util['format'](_0xf5f2('0x66'),path[_0xf5f2('0x67')](_0x2669c1[_0xf5f2('0x61')],path[_0xf5f2('0x68')](_0x2669c1['save_name'])),_0x2669c1[_0xf5f2('0x62')]));var _0x4cf3bc=path['join'](config[_0xf5f2('0x64')],_0xf5f2('0x4c'),_0x17cc6d[_0xf5f2('0x27')],util[_0xf5f2('0x69')](_0xf5f2('0x66'),_0x2669c1['name'],_0x2669c1['converted_format']));fs[_0xf5f2('0x6a')](_0x2efa59,_0x4cf3bc);return _0x2669c1;}})[_0xf5f2('0x43')](function(_0x2cd39d){throw new db[(_0xf5f2('0x5c'))][(_0xf5f2('0x6b'))](_0x2cd39d[_0xf5f2('0x6c')]);});})['then'](handleEntityNotFound(_0x16a767,null))[_0xf5f2('0x22')](respondWithResult(_0x16a767,0xc9))[_0xf5f2('0x43')](handleError(_0x16a767,null));};exports[_0xf5f2('0x6d')]=function(_0x22c0dc,_0x569530,_0x448d38){return db[_0xf5f2('0x48')][_0xf5f2('0x5e')](function(_0x525b2d){var _0x3d9407;return db[_0xf5f2('0x2b')][_0xf5f2('0x60')]({'where':{'id':_0x22c0dc[_0xf5f2('0x45')]['id']}})['then'](handleEntityNotFound(_0x569530,null))[_0xf5f2('0x22')](function(_0x12681e){if(_0x12681e){_0x3d9407=_0x12681e;return _0x12681e['removeSound'](_0x22c0dc[_0xf5f2('0x45')][_0xf5f2('0x6e')]);}})[_0xf5f2('0x22')](function(_0x21c2d4){if(_0x21c2d4){return db[_0xf5f2('0x5f')][_0xf5f2('0x60')]({'where':{'id':_0x22c0dc['params']['id2']},'attributes':['id',_0xf5f2('0x27'),_0xf5f2('0x61'),_0xf5f2('0x62'),_0xf5f2('0x63')],'raw':!![]});}})[_0xf5f2('0x22')](function(_0x5280ee){if(_0x5280ee){fs[_0xf5f2('0x5a')](path[_0xf5f2('0x4b')](_0x3d9407['directory'],util[_0xf5f2('0x69')](_0xf5f2('0x66'),_0x5280ee[_0xf5f2('0x27')],_0x5280ee['converted_format'])));return _0x5280ee;}})[_0xf5f2('0x43')](function(_0x5e89ad){throw new db[(_0xf5f2('0x5c'))][(_0xf5f2('0x6b'))](_0x5e89ad[_0xf5f2('0x6c')]);});})[_0xf5f2('0x22')](handleEntityNotFound(_0x569530,null))[_0xf5f2('0x22')](respondWithStatusCode(_0x569530,0xcc))[_0xf5f2('0x43')](handleError(_0x569530,null));};exports['getSounds']=function(_0x496779,_0x201b05,_0x5e4972){var _0x295463={};var _0x41b593={};var _0x8ca3e2;var _0x3d4280;return db['VoiceMusicOnHold'][_0xf5f2('0x60')]({'where':{'id':_0x496779[_0xf5f2('0x45')]['id']}})[_0xf5f2('0x22')](handleEntityNotFound(_0x201b05,null))[_0xf5f2('0x22')](function(_0x56add3){if(_0x56add3){_0x8ca3e2=_0x56add3;_0x41b593[_0xf5f2('0x2f')]=_['keys'](db['Sound'][_0xf5f2('0x6f')]);_0x41b593[_0xf5f2('0x31')]=_[_0xf5f2('0x30')](_0x496779[_0xf5f2('0x31')]);_0x41b593[_0xf5f2('0x32')]=_['intersection'](_0x41b593[_0xf5f2('0x2f')],_0x41b593[_0xf5f2('0x31')]);_0x295463[_0xf5f2('0x35')]=_['intersection'](_0x41b593['model'],qs['fields'](_0x496779[_0xf5f2('0x31')]['fields']));_0x295463[_0xf5f2('0x35')]=_0x295463['attributes'][_0xf5f2('0x36')]?_0x295463[_0xf5f2('0x35')]:_0x41b593[_0xf5f2('0x2f')];_0x295463[_0xf5f2('0x70')]=qs[_0xf5f2('0x39')](_0x496779['query']['sort']);_0x295463[_0xf5f2('0x3a')]=qs[_0xf5f2('0x32')](_[_0xf5f2('0x3b')](_0x496779[_0xf5f2('0x31')],_0x41b593[_0xf5f2('0x32')]));if(_0x496779[_0xf5f2('0x31')]['filter']){_0x295463[_0xf5f2('0x3a')]=_['merge'](_0x295463[_0xf5f2('0x3a')],{'$or':_[_0xf5f2('0x2a')](_0x295463['attributes'],function(_0x4d05d5){var _0x3a8a69={};_0x3a8a69[_0x4d05d5]={'$like':'%'+_0x496779[_0xf5f2('0x31')][_0xf5f2('0x3c')]+'%'};return _0x3a8a69;})});}_0x295463=_[_0xf5f2('0x3d')]({},_0x295463,_0x496779['options']);return _0x8ca3e2[_0xf5f2('0x71')](_0x295463);}})[_0xf5f2('0x22')](function(_0x1c5835){if(_0x1c5835){_0x3d4280=_0x1c5835[_0xf5f2('0x36')];if(!_0x496779['query'][_0xf5f2('0x37')](_0xf5f2('0x38'))){_0x295463[_0xf5f2('0x1c')]=qs['limit'](_0x496779[_0xf5f2('0x31')][_0xf5f2('0x1c')]);_0x295463['offset']=qs[_0xf5f2('0x1a')](_0x496779[_0xf5f2('0x31')][_0xf5f2('0x1a')]);}return _0x8ca3e2[_0xf5f2('0x71')](_0x295463);}})[_0xf5f2('0x22')](function(_0x2a4d0e){if(_0x2a4d0e){return _0x2a4d0e?{'count':_0x3d4280,'rows':_0x2a4d0e}:null;}})[_0xf5f2('0x22')](respondWithResult(_0x201b05,null))[_0xf5f2('0x43')](handleError(_0x201b05,null));};
\ No newline at end of file