aa697529cd39e17ce09f09d3f8f5347d396e2b64
[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 _0xeab9=['eml-format','rimraf','zip-dir','fast-json-patch','bluebird','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','save','update','then','sendStatus','error','stack','name','send','index','VoiceMailMessage','rawAttributes','fieldName','type','key','model','differenceBy','map','query','keys','filters','intersection','fields','attributes','hasOwnProperty','order','sort','where','pick','VIRTUAL','filter','merge','options','rows','catch','params','length','includeAll','create','body','find','destroy','download','recording','msg_id','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','audio/wav','attachment','Content-Disposition','set'];(function(_0x3452c7,_0x395c6f){var _0x4b490f=function(_0x4cacf1){while(--_0x4cacf1){_0x3452c7['push'](_0x3452c7['shift']());}};_0x4b490f(++_0x395c6f);}(_0xeab9,0x1ec));var _0x9eab=function(_0x1756f3,_0x60f2ce){_0x1756f3=_0x1756f3-0x0;var _0x2795f1=_0xeab9[_0x1756f3];return _0x2795f1;};'use strict';var emlformat=require(_0x9eab('0x0'));var rimraf=require(_0x9eab('0x1'));var zipdir=require(_0x9eab('0x2'));var jsonpatch=require(_0x9eab('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x9eab('0x4'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x9eab('0x5'));var csv=require('to-csv');var ejs=require(_0x9eab('0x6'));var fs=require('fs');var fs_extra=require(_0x9eab('0x7'));var _=require('lodash');var squel=require(_0x9eab('0x8'));var crypto=require(_0x9eab('0x9'));var jsforce=require(_0x9eab('0xa'));var deskjs=require(_0x9eab('0xb'));var toCsv=require(_0x9eab('0xc'));var querystring=require(_0x9eab('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x9eab('0xe'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9eab('0xf'));var logger=require(_0x9eab('0x10'))(_0x9eab('0x11'));var utils=require(_0x9eab('0x12'));var config=require(_0x9eab('0x13'));var licenseUtil=require('../../config/license/util');var db=require(_0x9eab('0x14'))['db'];function respondWithStatusCode(_0x200497,_0x2de9b3){_0x2de9b3=_0x2de9b3||0xcc;return function(_0x205432){if(_0x205432){return _0x200497['sendStatus'](_0x2de9b3);}return _0x200497[_0x9eab('0x15')](_0x2de9b3)[_0x9eab('0x16')]();};}function respondWithResult(_0x440de,_0xc76f88){_0xc76f88=_0xc76f88||0xc8;return function(_0xed679b){if(_0xed679b){return _0x440de[_0x9eab('0x15')](_0xc76f88)[_0x9eab('0x17')](_0xed679b);}};}function respondWithFilteredResult(_0x21cbce,_0x2c0ab9){return function(_0xf278a1){if(_0xf278a1){var _0x5bb556=typeof _0x2c0ab9[_0x9eab('0x18')]===_0x9eab('0x19')&&typeof _0x2c0ab9[_0x9eab('0x1a')]===_0x9eab('0x19');var _0x4a5235=_0xf278a1['count'];var _0x5a9f99=_0x5bb556?0x0:_0x2c0ab9['offset'];var _0x52f56a=_0x5bb556?_0xf278a1[_0x9eab('0x1b')]:_0x2c0ab9[_0x9eab('0x18')]+_0x2c0ab9[_0x9eab('0x1a')];var _0xe895e3;if(_0x52f56a>=_0x4a5235){_0x52f56a=_0x4a5235;_0xe895e3=0xc8;}else{_0xe895e3=0xce;}_0x21cbce[_0x9eab('0x15')](_0xe895e3);return _0x21cbce['set'](_0x9eab('0x1c'),_0x5a9f99+'-'+_0x52f56a+'/'+_0x4a5235)[_0x9eab('0x17')](_0xf278a1);}return null;};}function patchUpdates(_0x22fb9b){return function(_0x34aa74){try{jsonpatch[_0x9eab('0x1d')](_0x34aa74,_0x22fb9b,!![]);}catch(_0x451635){return BPromise[_0x9eab('0x1e')](_0x451635);}return _0x34aa74[_0x9eab('0x1f')]();};}function saveUpdates(_0x2abd5f,_0x711c90){return function(_0x505bbd){if(_0x505bbd){return _0x505bbd[_0x9eab('0x20')](_0x2abd5f)[_0x9eab('0x21')](function(_0x4701d9){return _0x4701d9;});}return null;};}function removeEntity(_0x309642,_0xe6fa1c){return function(_0x2e1b53){if(_0x2e1b53){return _0x2e1b53['destroy']()[_0x9eab('0x21')](function(){_0x309642['status'](0xcc)[_0x9eab('0x16')]();});}};}function handleEntityNotFound(_0x1171eb,_0x17f425){return function(_0x32c9c1){if(!_0x32c9c1){_0x1171eb[_0x9eab('0x22')](0x194);}return _0x32c9c1;};}function handleError(_0x1272ea,_0x18a10e){_0x18a10e=_0x18a10e||0x1f4;return function(_0x3ebff0){logger[_0x9eab('0x23')](_0x3ebff0[_0x9eab('0x24')]);if(_0x3ebff0[_0x9eab('0x25')]){delete _0x3ebff0[_0x9eab('0x25')];}_0x1272ea[_0x9eab('0x15')](_0x18a10e)[_0x9eab('0x26')](_0x3ebff0);};}exports[_0x9eab('0x27')]=function(_0x2695b4,_0x1e0dee){var _0x129448={},_0x1d0c49={},_0x262bee={'count':0x0,'rows':[]};var _0x22d0e4=_['map'](db[_0x9eab('0x28')][_0x9eab('0x29')],function(_0x38771f){return{'name':_0x38771f[_0x9eab('0x2a')],'type':_0x38771f[_0x9eab('0x2b')][_0x9eab('0x2c')]};});_0x1d0c49[_0x9eab('0x2d')]=_[_0x9eab('0x2e')](_[_0x9eab('0x2f')](_0x22d0e4,_0x9eab('0x25')),[_0x9eab('0x25')]);_0x1d0c49[_0x9eab('0x30')]=_[_0x9eab('0x31')](_0x2695b4[_0x9eab('0x30')]);_0x1d0c49[_0x9eab('0x32')]=_[_0x9eab('0x33')](_0x1d0c49[_0x9eab('0x2d')],_0x1d0c49['query']);_0x129448['attributes']=_['intersection'](_0x1d0c49[_0x9eab('0x2d')],qs['fields'](_0x2695b4[_0x9eab('0x30')][_0x9eab('0x34')]));_0x129448['attributes']=_0x129448[_0x9eab('0x35')]['length']?_0x129448[_0x9eab('0x35')]:_0x1d0c49['model'];if(!_0x2695b4['query'][_0x9eab('0x36')]('nolimit')){_0x129448[_0x9eab('0x1a')]=qs['limit'](_0x2695b4[_0x9eab('0x30')]['limit']);_0x129448[_0x9eab('0x18')]=qs['offset'](_0x2695b4[_0x9eab('0x30')][_0x9eab('0x18')]);}_0x129448[_0x9eab('0x37')]=qs[_0x9eab('0x38')](_0x2695b4[_0x9eab('0x30')][_0x9eab('0x38')]);_0x129448[_0x9eab('0x39')]=qs['filters'](_[_0x9eab('0x3a')](_0x2695b4[_0x9eab('0x30')],_0x1d0c49[_0x9eab('0x32')]),_0x22d0e4);if(_0x2695b4['query']['filter']){_0x129448['where']=_['merge'](_0x129448[_0x9eab('0x39')],{'$or':_['map'](_0x22d0e4,function(_0x18eca9){if(_0x18eca9[_0x9eab('0x2b')]!==_0x9eab('0x3b')){var _0xcb8302={};_0xcb8302[_0x18eca9[_0x9eab('0x25')]]={'$like':'%'+_0x2695b4[_0x9eab('0x30')][_0x9eab('0x3c')]+'%'};return _0xcb8302;}})});}_0x129448=_[_0x9eab('0x3d')]({},_0x129448,_0x2695b4[_0x9eab('0x3e')]);var _0x2537a0={'where':_0x129448[_0x9eab('0x39')]};return db[_0x9eab('0x28')][_0x9eab('0x1b')](_0x2537a0)[_0x9eab('0x21')](function(_0x4c180b){_0x262bee['count']=_0x4c180b;if(_0x2695b4['query']['includeAll']){_0x129448['include']=[{'all':!![]}];}return db['VoiceMailMessage']['findAll'](_0x129448);})[_0x9eab('0x21')](function(_0x373a5d){_0x262bee[_0x9eab('0x3f')]=_0x373a5d;return _0x262bee;})['then'](respondWithFilteredResult(_0x1e0dee,_0x129448))[_0x9eab('0x40')](handleError(_0x1e0dee,null));};exports['show']=function(_0x429c41,_0x1db12a){var _0x23f9e8={'raw':!![],'where':{'id':_0x429c41[_0x9eab('0x41')]['id']}},_0x47fac8={};_0x47fac8['model']=_['keys'](db[_0x9eab('0x28')][_0x9eab('0x29')]);_0x47fac8[_0x9eab('0x30')]=_[_0x9eab('0x31')](_0x429c41['query']);_0x47fac8[_0x9eab('0x32')]=_[_0x9eab('0x33')](_0x47fac8[_0x9eab('0x2d')],_0x47fac8[_0x9eab('0x30')]);_0x23f9e8['attributes']=_[_0x9eab('0x33')](_0x47fac8[_0x9eab('0x2d')],qs[_0x9eab('0x34')](_0x429c41[_0x9eab('0x30')]['fields']));_0x23f9e8[_0x9eab('0x35')]=_0x23f9e8['attributes'][_0x9eab('0x42')]?_0x23f9e8[_0x9eab('0x35')]:_0x47fac8['model'];if(_0x429c41['query'][_0x9eab('0x43')]){_0x23f9e8['include']=[{'all':!![]}];}_0x23f9e8=_[_0x9eab('0x3d')]({},_0x23f9e8,_0x429c41[_0x9eab('0x3e')]);return db['VoiceMailMessage']['find'](_0x23f9e8)[_0x9eab('0x21')](handleEntityNotFound(_0x1db12a,null))[_0x9eab('0x21')](respondWithResult(_0x1db12a,null))['catch'](handleError(_0x1db12a,null));};exports['create']=function(_0x4bfafe,_0x362f75){return db[_0x9eab('0x28')][_0x9eab('0x44')](_0x4bfafe[_0x9eab('0x45')],{})[_0x9eab('0x21')](respondWithResult(_0x362f75,0xc9))[_0x9eab('0x40')](handleError(_0x362f75,null));};exports['update']=function(_0x2153d1,_0x263169){if(_0x2153d1[_0x9eab('0x45')]['id']){delete _0x2153d1[_0x9eab('0x45')]['id'];}return db[_0x9eab('0x28')][_0x9eab('0x46')]({'where':{'id':_0x2153d1[_0x9eab('0x41')]['id']}})['then'](handleEntityNotFound(_0x263169,null))[_0x9eab('0x21')](saveUpdates(_0x2153d1[_0x9eab('0x45')],null))[_0x9eab('0x21')](respondWithResult(_0x263169,null))[_0x9eab('0x40')](handleError(_0x263169,null));};exports[_0x9eab('0x47')]=function(_0x5af91e,_0x569961){return db[_0x9eab('0x28')][_0x9eab('0x46')]({'where':{'id':_0x5af91e[_0x9eab('0x41')]['id']}})[_0x9eab('0x21')](handleEntityNotFound(_0x569961,null))[_0x9eab('0x21')](removeEntity(_0x569961,null))[_0x9eab('0x40')](handleError(_0x569961,null));};exports[_0x9eab('0x48')]=function(_0xce094c,_0x1f86ca,_0xe55833){return db[_0x9eab('0x28')]['find']({'where':{'id':_0xce094c['params']['id']},'attributes':['id',_0x9eab('0x49'),_0x9eab('0x4a')]})[_0x9eab('0x21')](handleEntityNotFound(_0x1f86ca,null))[_0x9eab('0x21')](function(_0x107f15){if(_0x107f15){if(!_0x107f15[_0x9eab('0x49')]){throw new db[(_0x9eab('0x4b'))][(_0x9eab('0x4c'))](_0x9eab('0x4d'));}var _0x2746b8={'Content-Type':_0x9eab('0x4e'),'Content-Disposition':_0x9eab('0x4f')};if(_0x107f15[_0x9eab('0x4a')]){_0x2746b8[_0x9eab('0x50')]='attachment;\x20filename=\x22'+_0x107f15[_0x9eab('0x4a')]+'.wav\x22';}_0x1f86ca[_0x9eab('0x51')](_0x2746b8);return _0x1f86ca['send'](new Buffer(_0x107f15[_0x9eab('0x49')]));}})[_0x9eab('0x40')](handleError(_0x1f86ca,null));};