20ad4db5320ada2ce61ec9dc4194607cae1d16d7
[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 _0xff19=['VoiceMailMessage\x20not\x20found','Content-Disposition','.wav\x22','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','undefined','count','set','Content-Range','reject','save','update','then','sendStatus','stack','name','send','index','map','VoiceMailMessage','fieldName','type','key','differenceBy','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','pick','merge','VIRTUAL','options','includeAll','include','findAll','show','params','rawAttributes','keys','find','catch','create','body','destroy','msg_id','recording','Sequelize'];(function(_0x66ee22,_0x3fced6){var _0x7a8f76=function(_0x3ed427){while(--_0x3ed427){_0x66ee22['push'](_0x66ee22['shift']());}};_0x7a8f76(++_0x3fced6);}(_0xff19,0x1ef));var _0x9ff1=function(_0x55eb1d,_0x416562){_0x55eb1d=_0x55eb1d-0x0;var _0x3080f4=_0xff19[_0x55eb1d];return _0x3080f4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9ff1('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9ff1('0x1'));var rp=require(_0x9ff1('0x2'));var moment=require(_0x9ff1('0x3'));var BPromise=require(_0x9ff1('0x4'));var Mustache=require('mustache');var util=require(_0x9ff1('0x5'));var path=require(_0x9ff1('0x6'));var sox=require(_0x9ff1('0x7'));var csv=require('to-csv');var ejs=require(_0x9ff1('0x8'));var fs=require('fs');var fs_extra=require(_0x9ff1('0x9'));var _=require('lodash');var squel=require(_0x9ff1('0xa'));var crypto=require(_0x9ff1('0xb'));var jsforce=require(_0x9ff1('0xc'));var deskjs=require(_0x9ff1('0xd'));var toCsv=require(_0x9ff1('0xe'));var querystring=require(_0x9ff1('0xf'));var Papa=require('papaparse');var Redis=require(_0x9ff1('0x10'));var authService=require(_0x9ff1('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x9ff1('0x12'));var hardwareService=require(_0x9ff1('0x13'));var logger=require(_0x9ff1('0x14'))(_0x9ff1('0x15'));var utils=require(_0x9ff1('0x16'));var config=require(_0x9ff1('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x9ff1('0x18'))['db'];function respondWithStatusCode(_0xdd124a,_0x36fe9d){_0x36fe9d=_0x36fe9d||0xcc;return function(_0x2ab5b7){if(_0x2ab5b7){return _0xdd124a['sendStatus'](_0x36fe9d);}return _0xdd124a[_0x9ff1('0x19')](_0x36fe9d)[_0x9ff1('0x1a')]();};}function respondWithResult(_0x46d40e,_0x53e53a){_0x53e53a=_0x53e53a||0xc8;return function(_0x17a900){if(_0x17a900){return _0x46d40e[_0x9ff1('0x19')](_0x53e53a)[_0x9ff1('0x1b')](_0x17a900);}};}function respondWithFilteredResult(_0x42d7c1,_0x23db54){return function(_0x15127d){if(_0x15127d){var _0x6bec8=typeof _0x23db54[_0x9ff1('0x1c')]===_0x9ff1('0x1d')&&typeof _0x23db54['limit']==='undefined';var _0x5ad7dd=_0x15127d[_0x9ff1('0x1e')];var _0x41f917=_0x6bec8?0x0:_0x23db54[_0x9ff1('0x1c')];var _0x3cec5a=_0x6bec8?_0x15127d[_0x9ff1('0x1e')]:_0x23db54[_0x9ff1('0x1c')]+_0x23db54['limit'];var _0x71f5c8;if(_0x3cec5a>=_0x5ad7dd){_0x3cec5a=_0x5ad7dd;_0x71f5c8=0xc8;}else{_0x71f5c8=0xce;}_0x42d7c1['status'](_0x71f5c8);return _0x42d7c1[_0x9ff1('0x1f')](_0x9ff1('0x20'),_0x41f917+'-'+_0x3cec5a+'/'+_0x5ad7dd)[_0x9ff1('0x1b')](_0x15127d);}return null;};}function patchUpdates(_0x5d05d6){return function(_0x3f397a){try{jsonpatch['apply'](_0x3f397a,_0x5d05d6,!![]);}catch(_0x59155d){return BPromise[_0x9ff1('0x21')](_0x59155d);}return _0x3f397a[_0x9ff1('0x22')]();};}function saveUpdates(_0x3421b7,_0x3a7096){return function(_0x3991cf){if(_0x3991cf){return _0x3991cf[_0x9ff1('0x23')](_0x3421b7)[_0x9ff1('0x24')](function(_0x3f1e2d){return _0x3f1e2d;});}return null;};}function removeEntity(_0x2c2835,_0x47ac05){return function(_0x432e06){if(_0x432e06){return _0x432e06['destroy']()[_0x9ff1('0x24')](function(){_0x2c2835['status'](0xcc)[_0x9ff1('0x1a')]();});}};}function handleEntityNotFound(_0x230271,_0x1bab02){return function(_0x28fdad){if(!_0x28fdad){_0x230271[_0x9ff1('0x25')](0x194);}return _0x28fdad;};}function handleError(_0x171ee3,_0x38d43c){_0x38d43c=_0x38d43c||0x1f4;return function(_0x2f2e8c){logger['error'](_0x2f2e8c[_0x9ff1('0x26')]);if(_0x2f2e8c[_0x9ff1('0x27')]){delete _0x2f2e8c['name'];}_0x171ee3[_0x9ff1('0x19')](_0x38d43c)[_0x9ff1('0x28')](_0x2f2e8c);};}exports[_0x9ff1('0x29')]=function(_0x46c9b8,_0x1439ba){var _0x19b8c2={},_0x9546e2={},_0x5c9685={'count':0x0,'rows':[]};var _0x3e8a34=_[_0x9ff1('0x2a')](db[_0x9ff1('0x2b')]['rawAttributes'],function(_0x125f39){return{'name':_0x125f39[_0x9ff1('0x2c')],'type':_0x125f39[_0x9ff1('0x2d')][_0x9ff1('0x2e')]};});_0x9546e2['model']=_[_0x9ff1('0x2f')](_[_0x9ff1('0x2a')](_0x3e8a34,_0x9ff1('0x27')),[_0x9ff1('0x27')]);_0x9546e2['query']=_['keys'](_0x46c9b8[_0x9ff1('0x30')]);_0x9546e2[_0x9ff1('0x31')]=_[_0x9ff1('0x32')](_0x9546e2[_0x9ff1('0x33')],_0x9546e2['query']);_0x19b8c2[_0x9ff1('0x34')]=_[_0x9ff1('0x32')](_0x9546e2[_0x9ff1('0x33')],qs[_0x9ff1('0x35')](_0x46c9b8['query']['fields']));_0x19b8c2[_0x9ff1('0x34')]=_0x19b8c2['attributes'][_0x9ff1('0x36')]?_0x19b8c2['attributes']:_0x9546e2[_0x9ff1('0x33')];if(!_0x46c9b8['query'][_0x9ff1('0x37')](_0x9ff1('0x38'))){_0x19b8c2['limit']=qs['limit'](_0x46c9b8[_0x9ff1('0x30')][_0x9ff1('0x39')]);_0x19b8c2['offset']=qs[_0x9ff1('0x1c')](_0x46c9b8[_0x9ff1('0x30')]['offset']);}_0x19b8c2['order']=qs[_0x9ff1('0x3a')](_0x46c9b8[_0x9ff1('0x30')]['sort']);_0x19b8c2[_0x9ff1('0x3b')]=qs[_0x9ff1('0x31')](_[_0x9ff1('0x3c')](_0x46c9b8[_0x9ff1('0x30')],_0x9546e2[_0x9ff1('0x31')]),_0x3e8a34);if(_0x46c9b8[_0x9ff1('0x30')]['filter']){_0x19b8c2[_0x9ff1('0x3b')]=_[_0x9ff1('0x3d')](_0x19b8c2['where'],{'$or':_[_0x9ff1('0x2a')](_0x3e8a34,function(_0x48ba96){if(_0x48ba96[_0x9ff1('0x2d')]!==_0x9ff1('0x3e')){var _0x470f3c={};_0x470f3c[_0x48ba96[_0x9ff1('0x27')]]={'$like':'%'+_0x46c9b8['query']['filter']+'%'};return _0x470f3c;}})});}_0x19b8c2=_[_0x9ff1('0x3d')]({},_0x19b8c2,_0x46c9b8[_0x9ff1('0x3f')]);var _0x31ad92={'where':_0x19b8c2[_0x9ff1('0x3b')]};return db[_0x9ff1('0x2b')][_0x9ff1('0x1e')](_0x31ad92)[_0x9ff1('0x24')](function(_0x586a29){_0x5c9685[_0x9ff1('0x1e')]=_0x586a29;if(_0x46c9b8['query'][_0x9ff1('0x40')]){_0x19b8c2[_0x9ff1('0x41')]=[{'all':!![]}];}return db[_0x9ff1('0x2b')][_0x9ff1('0x42')](_0x19b8c2);})['then'](function(_0x33947c){_0x5c9685['rows']=_0x33947c;return _0x5c9685;})[_0x9ff1('0x24')](respondWithFilteredResult(_0x1439ba,_0x19b8c2))['catch'](handleError(_0x1439ba,null));};exports[_0x9ff1('0x43')]=function(_0x730009,_0x186051){var _0x479aae={'raw':!![],'where':{'id':_0x730009[_0x9ff1('0x44')]['id']}},_0x59b0cd={};_0x59b0cd['model']=_['keys'](db[_0x9ff1('0x2b')][_0x9ff1('0x45')]);_0x59b0cd[_0x9ff1('0x30')]=_[_0x9ff1('0x46')](_0x730009[_0x9ff1('0x30')]);_0x59b0cd[_0x9ff1('0x31')]=_[_0x9ff1('0x32')](_0x59b0cd[_0x9ff1('0x33')],_0x59b0cd[_0x9ff1('0x30')]);_0x479aae[_0x9ff1('0x34')]=_['intersection'](_0x59b0cd[_0x9ff1('0x33')],qs['fields'](_0x730009[_0x9ff1('0x30')][_0x9ff1('0x35')]));_0x479aae['attributes']=_0x479aae[_0x9ff1('0x34')][_0x9ff1('0x36')]?_0x479aae['attributes']:_0x59b0cd[_0x9ff1('0x33')];if(_0x730009[_0x9ff1('0x30')][_0x9ff1('0x40')]){_0x479aae[_0x9ff1('0x41')]=[{'all':!![]}];}_0x479aae=_[_0x9ff1('0x3d')]({},_0x479aae,_0x730009[_0x9ff1('0x3f')]);return db['VoiceMailMessage'][_0x9ff1('0x47')](_0x479aae)[_0x9ff1('0x24')](handleEntityNotFound(_0x186051,null))[_0x9ff1('0x24')](respondWithResult(_0x186051,null))[_0x9ff1('0x48')](handleError(_0x186051,null));};exports[_0x9ff1('0x49')]=function(_0x450a0b,_0x51c397){return db[_0x9ff1('0x2b')]['create'](_0x450a0b['body'],{})[_0x9ff1('0x24')](respondWithResult(_0x51c397,0xc9))['catch'](handleError(_0x51c397,null));};exports[_0x9ff1('0x23')]=function(_0x3f2ac7,_0x79d6af){if(_0x3f2ac7[_0x9ff1('0x4a')]['id']){delete _0x3f2ac7[_0x9ff1('0x4a')]['id'];}return db[_0x9ff1('0x2b')][_0x9ff1('0x47')]({'where':{'id':_0x3f2ac7[_0x9ff1('0x44')]['id']}})[_0x9ff1('0x24')](handleEntityNotFound(_0x79d6af,null))['then'](saveUpdates(_0x3f2ac7[_0x9ff1('0x4a')],null))[_0x9ff1('0x24')](respondWithResult(_0x79d6af,null))['catch'](handleError(_0x79d6af,null));};exports[_0x9ff1('0x4b')]=function(_0x24a5b0,_0x52acda){return db[_0x9ff1('0x2b')][_0x9ff1('0x47')]({'where':{'id':_0x24a5b0['params']['id']}})[_0x9ff1('0x24')](handleEntityNotFound(_0x52acda,null))[_0x9ff1('0x24')](removeEntity(_0x52acda,null))[_0x9ff1('0x48')](handleError(_0x52acda,null));};exports['download']=function(_0x3bfdf3,_0x283205,_0x3b22d6){return db['VoiceMailMessage'][_0x9ff1('0x47')]({'where':{'id':_0x3bfdf3[_0x9ff1('0x44')]['id']},'attributes':['id','recording',_0x9ff1('0x4c')]})[_0x9ff1('0x24')](handleEntityNotFound(_0x283205,null))['then'](function(_0x3b8043){if(_0x3b8043){if(!_0x3b8043[_0x9ff1('0x4d')]){throw new db[(_0x9ff1('0x4e'))]['ValidationError'](_0x9ff1('0x4f'));}var _0x27bbd8={'Content-Type':'audio/wav','Content-Disposition':'attachment'};if(_0x3b8043[_0x9ff1('0x4c')]){_0x27bbd8[_0x9ff1('0x50')]='attachment;\x20filename=\x22'+_0x3b8043['msg_id']+_0x9ff1('0x51');}_0x283205[_0x9ff1('0x1f')](_0x27bbd8);return _0x283205[_0x9ff1('0x28')](new Buffer(_0x3b8043['recording']));}})[_0x9ff1('0x48')](handleError(_0x283205,null));};