Built motion from commit 9e1ec266.|2.6.28
[motion2.git] / server / api / voiceMailMessage / voiceMailMessage.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf483=['intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','keys','options','create','find','body','download','recording','msg_id','Sequelize','ValidationError','Content-Disposition','attachment;\x20filename=\x22','.wav\x22','rimraf','zip-dir','fast-json-patch','bluebird','util','path','sox','to-csv','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','json','offset','undefined','limit','count','status','set','apply','update','then','destroy','error','stack','name','send','index','map','VoiceMailMessage','rawAttributes','fieldName','type','key','model','differenceBy','query','filters'];(function(_0x4799bf,_0x145838){var _0x436ef4=function(_0x1c0a40){while(--_0x1c0a40){_0x4799bf['push'](_0x4799bf['shift']());}};_0x436ef4(++_0x145838);}(_0xf483,0xc6));var _0x3f48=function(_0x4e76da,_0x291b71){_0x4e76da=_0x4e76da-0x0;var _0x5f14e8=_0xf483[_0x4e76da];return _0x5f14e8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3f48('0x0'));var zipdir=require(_0x3f48('0x1'));var jsonpatch=require(_0x3f48('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x3f48('0x3'));var Mustache=require('mustache');var util=require(_0x3f48('0x4'));var path=require(_0x3f48('0x5'));var sox=require(_0x3f48('0x6'));var csv=require(_0x3f48('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x3f48('0x8'));var squel=require(_0x3f48('0x9'));var crypto=require(_0x3f48('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x3f48('0xb'));var toCsv=require(_0x3f48('0x7'));var querystring=require(_0x3f48('0xc'));var Papa=require(_0x3f48('0xd'));var Redis=require(_0x3f48('0xe'));var authService=require(_0x3f48('0xf'));var qs=require(_0x3f48('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x3f48('0x11'));var logger=require(_0x3f48('0x12'))(_0x3f48('0x13'));var utils=require(_0x3f48('0x14'));var config=require(_0x3f48('0x15'));var licenseUtil=require(_0x3f48('0x16'));var db=require(_0x3f48('0x17'))['db'];function respondWithStatusCode(_0x4e7cbd,_0x2c72ae){_0x2c72ae=_0x2c72ae||0xcc;return function(_0x41868a){if(_0x41868a){return _0x4e7cbd[_0x3f48('0x18')](_0x2c72ae);}return _0x4e7cbd['status'](_0x2c72ae)['end']();};}function respondWithResult(_0x117748,_0x2c0ae2){_0x2c0ae2=_0x2c0ae2||0xc8;return function(_0x47782f){if(_0x47782f){return _0x117748['status'](_0x2c0ae2)[_0x3f48('0x19')](_0x47782f);}};}function respondWithFilteredResult(_0x3cc4e1,_0x3370f0){return function(_0x31d242){if(_0x31d242){var _0x587742=typeof _0x3370f0[_0x3f48('0x1a')]===_0x3f48('0x1b')&&typeof _0x3370f0[_0x3f48('0x1c')]===_0x3f48('0x1b');var _0x5560c9=_0x31d242[_0x3f48('0x1d')];var _0xab77a0=_0x587742?0x0:_0x3370f0['offset'];var _0x388592=_0x587742?_0x31d242[_0x3f48('0x1d')]:_0x3370f0[_0x3f48('0x1a')]+_0x3370f0['limit'];var _0x2091a9;if(_0x388592>=_0x5560c9){_0x388592=_0x5560c9;_0x2091a9=0xc8;}else{_0x2091a9=0xce;}_0x3cc4e1[_0x3f48('0x1e')](_0x2091a9);return _0x3cc4e1[_0x3f48('0x1f')]('Content-Range',_0xab77a0+'-'+_0x388592+'/'+_0x5560c9)['json'](_0x31d242);}return null;};}function patchUpdates(_0x15e4d3){return function(_0x297473){try{jsonpatch[_0x3f48('0x20')](_0x297473,_0x15e4d3,!![]);}catch(_0x49b4a0){return BPromise['reject'](_0x49b4a0);}return _0x297473['save']();};}function saveUpdates(_0x56c9e2,_0x1f20a3){return function(_0x5aab11){if(_0x5aab11){return _0x5aab11[_0x3f48('0x21')](_0x56c9e2)[_0x3f48('0x22')](function(_0x3ffb16){return _0x3ffb16;});}return null;};}function removeEntity(_0x3c6686,_0xc650ec){return function(_0x5dd953){if(_0x5dd953){return _0x5dd953[_0x3f48('0x23')]()[_0x3f48('0x22')](function(){_0x3c6686[_0x3f48('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x263f74,_0x111dba){return function(_0x622ef3){if(!_0x622ef3){_0x263f74[_0x3f48('0x18')](0x194);}return _0x622ef3;};}function handleError(_0x2d2165,_0x59dd5e){_0x59dd5e=_0x59dd5e||0x1f4;return function(_0x4e97e7){logger[_0x3f48('0x24')](_0x4e97e7[_0x3f48('0x25')]);if(_0x4e97e7[_0x3f48('0x26')]){delete _0x4e97e7[_0x3f48('0x26')];}_0x2d2165['status'](_0x59dd5e)[_0x3f48('0x27')](_0x4e97e7);};}exports[_0x3f48('0x28')]=function(_0xd808ad,_0x12a031){var _0x5a4b10={},_0x53fccd={},_0x809fa4={'count':0x0,'rows':[]};var _0x29f9be=_[_0x3f48('0x29')](db[_0x3f48('0x2a')][_0x3f48('0x2b')],function(_0x36c36b){return{'name':_0x36c36b[_0x3f48('0x2c')],'type':_0x36c36b[_0x3f48('0x2d')][_0x3f48('0x2e')]};});_0x53fccd[_0x3f48('0x2f')]=_[_0x3f48('0x30')](_['map'](_0x29f9be,_0x3f48('0x26')),[_0x3f48('0x26')]);_0x53fccd[_0x3f48('0x31')]=_['keys'](_0xd808ad[_0x3f48('0x31')]);_0x53fccd[_0x3f48('0x32')]=_[_0x3f48('0x33')](_0x53fccd[_0x3f48('0x2f')],_0x53fccd[_0x3f48('0x31')]);_0x5a4b10[_0x3f48('0x34')]=_['intersection'](_0x53fccd[_0x3f48('0x2f')],qs[_0x3f48('0x35')](_0xd808ad[_0x3f48('0x31')][_0x3f48('0x35')]));_0x5a4b10[_0x3f48('0x34')]=_0x5a4b10[_0x3f48('0x34')][_0x3f48('0x36')]?_0x5a4b10[_0x3f48('0x34')]:_0x53fccd['model'];if(!_0xd808ad[_0x3f48('0x31')][_0x3f48('0x37')](_0x3f48('0x38'))){_0x5a4b10[_0x3f48('0x1c')]=qs[_0x3f48('0x1c')](_0xd808ad[_0x3f48('0x31')][_0x3f48('0x1c')]);_0x5a4b10['offset']=qs['offset'](_0xd808ad[_0x3f48('0x31')][_0x3f48('0x1a')]);}_0x5a4b10[_0x3f48('0x39')]=qs['sort'](_0xd808ad[_0x3f48('0x31')][_0x3f48('0x3a')]);_0x5a4b10['where']=qs['filters'](_['pick'](_0xd808ad[_0x3f48('0x31')],_0x53fccd[_0x3f48('0x32')]),_0x29f9be);if(_0xd808ad[_0x3f48('0x31')][_0x3f48('0x3b')]){_0x5a4b10[_0x3f48('0x3c')]=_[_0x3f48('0x3d')](_0x5a4b10['where'],{'$or':_[_0x3f48('0x29')](_0x29f9be,function(_0x1d5828){if(_0x1d5828[_0x3f48('0x2d')]!==_0x3f48('0x3e')){var _0x53f4a0={};_0x53f4a0[_0x1d5828[_0x3f48('0x26')]]={'$like':'%'+_0xd808ad[_0x3f48('0x31')][_0x3f48('0x3b')]+'%'};return _0x53f4a0;}})});}_0x5a4b10=_[_0x3f48('0x3d')]({},_0x5a4b10,_0xd808ad['options']);var _0x2d883e={'where':_0x5a4b10['where']};return db['VoiceMailMessage']['count'](_0x2d883e)[_0x3f48('0x22')](function(_0x50c718){_0x809fa4[_0x3f48('0x1d')]=_0x50c718;if(_0xd808ad[_0x3f48('0x31')][_0x3f48('0x3f')]){_0x5a4b10[_0x3f48('0x40')]=[{'all':!![]}];}return db[_0x3f48('0x2a')][_0x3f48('0x41')](_0x5a4b10);})[_0x3f48('0x22')](function(_0x10b4a2){_0x809fa4[_0x3f48('0x42')]=_0x10b4a2;return _0x809fa4;})['then'](respondWithFilteredResult(_0x12a031,_0x5a4b10))[_0x3f48('0x43')](handleError(_0x12a031,null));};exports[_0x3f48('0x44')]=function(_0x232c83,_0xad9acb){var _0x10931c={'raw':!![],'where':{'id':_0x232c83[_0x3f48('0x45')]['id']}},_0x61f78e={};_0x61f78e[_0x3f48('0x2f')]=_[_0x3f48('0x46')](db['VoiceMailMessage'][_0x3f48('0x2b')]);_0x61f78e[_0x3f48('0x31')]=_['keys'](_0x232c83[_0x3f48('0x31')]);_0x61f78e[_0x3f48('0x32')]=_[_0x3f48('0x33')](_0x61f78e[_0x3f48('0x2f')],_0x61f78e[_0x3f48('0x31')]);_0x10931c['attributes']=_[_0x3f48('0x33')](_0x61f78e[_0x3f48('0x2f')],qs[_0x3f48('0x35')](_0x232c83[_0x3f48('0x31')]['fields']));_0x10931c[_0x3f48('0x34')]=_0x10931c[_0x3f48('0x34')][_0x3f48('0x36')]?_0x10931c[_0x3f48('0x34')]:_0x61f78e[_0x3f48('0x2f')];if(_0x232c83[_0x3f48('0x31')][_0x3f48('0x3f')]){_0x10931c['include']=[{'all':!![]}];}_0x10931c=_[_0x3f48('0x3d')]({},_0x10931c,_0x232c83[_0x3f48('0x47')]);return db['VoiceMailMessage']['find'](_0x10931c)[_0x3f48('0x22')](handleEntityNotFound(_0xad9acb,null))[_0x3f48('0x22')](respondWithResult(_0xad9acb,null))[_0x3f48('0x43')](handleError(_0xad9acb,null));};exports['create']=function(_0x4c54c6,_0x5cb9af){return db['VoiceMailMessage'][_0x3f48('0x48')](_0x4c54c6['body'],{})[_0x3f48('0x22')](respondWithResult(_0x5cb9af,0xc9))['catch'](handleError(_0x5cb9af,null));};exports[_0x3f48('0x21')]=function(_0x413bc3,_0x129127){if(_0x413bc3['body']['id']){delete _0x413bc3['body']['id'];}return db[_0x3f48('0x2a')][_0x3f48('0x49')]({'where':{'id':_0x413bc3[_0x3f48('0x45')]['id']}})[_0x3f48('0x22')](handleEntityNotFound(_0x129127,null))['then'](saveUpdates(_0x413bc3[_0x3f48('0x4a')],null))[_0x3f48('0x22')](respondWithResult(_0x129127,null))[_0x3f48('0x43')](handleError(_0x129127,null));};exports[_0x3f48('0x23')]=function(_0x1fa5e0,_0x38d7b9){return db['VoiceMailMessage']['find']({'where':{'id':_0x1fa5e0[_0x3f48('0x45')]['id']}})['then'](handleEntityNotFound(_0x38d7b9,null))[_0x3f48('0x22')](removeEntity(_0x38d7b9,null))[_0x3f48('0x43')](handleError(_0x38d7b9,null));};exports[_0x3f48('0x4b')]=function(_0x24566d,_0x3ab75d,_0x1742f0){return db['VoiceMailMessage'][_0x3f48('0x49')]({'where':{'id':_0x24566d['params']['id']},'attributes':['id',_0x3f48('0x4c'),_0x3f48('0x4d')]})['then'](handleEntityNotFound(_0x3ab75d,null))[_0x3f48('0x22')](function(_0x422c19){if(_0x422c19){if(!_0x422c19[_0x3f48('0x4c')]){throw new db[(_0x3f48('0x4e'))][(_0x3f48('0x4f'))]('VoiceMailMessage\x20not\x20found');}var _0x519f99={'Content-Type':'audio/wav','Content-Disposition':'attachment'};if(_0x422c19[_0x3f48('0x4d')]){_0x519f99[_0x3f48('0x50')]=_0x3f48('0x51')+_0x422c19['msg_id']+_0x3f48('0x52');}_0x3ab75d[_0x3f48('0x1f')](_0x519f99);return _0x3ab75d[_0x3f48('0x27')](new Buffer(_0x422c19[_0x3f48('0x4c')]));}})[_0x3f48('0x43')](handleError(_0x3ab75d,null));};