Built motion from commit 56b8093a.|2.6.29
[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 _0x9ff3=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','json','undefined','count','offset','limit','status','set','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','fieldName','key','model','differenceBy','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','order','pick','filter','where','merge','type','options','VoiceMailMessage','include','findAll','show','params','rawAttributes','find','create','catch','body','download','recording','msg_id','Sequelize','ValidationError','audio/wav','attachment','Content-Disposition','.wav\x22','rimraf','request-promise','moment','bluebird','mustache','util','sox','ejs','crypto','jsforce','desk.js','querystring','papaparse'];(function(_0x77df1,_0x291f5d){var _0x19e186=function(_0xaa8af2){while(--_0xaa8af2){_0x77df1['push'](_0x77df1['shift']());}};_0x19e186(++_0x291f5d);}(_0x9ff3,0x13b));var _0x39ff=function(_0x3c179b,_0x2d343c){_0x3c179b=_0x3c179b-0x0;var _0x494231=_0x9ff3[_0x3c179b];return _0x494231;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x39ff('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x39ff('0x1'));var moment=require(_0x39ff('0x2'));var BPromise=require(_0x39ff('0x3'));var Mustache=require(_0x39ff('0x4'));var util=require(_0x39ff('0x5'));var path=require('path');var sox=require(_0x39ff('0x6'));var csv=require('to-csv');var ejs=require(_0x39ff('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0x39ff('0x8'));var jsforce=require(_0x39ff('0x9'));var deskjs=require(_0x39ff('0xa'));var toCsv=require('to-csv');var querystring=require(_0x39ff('0xb'));var Papa=require(_0x39ff('0xc'));var Redis=require(_0x39ff('0xd'));var authService=require(_0x39ff('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x39ff('0xf'));var hardwareService=require(_0x39ff('0x10'));var logger=require(_0x39ff('0x11'))('api');var utils=require(_0x39ff('0x12'));var config=require(_0x39ff('0x13'));var licenseUtil=require(_0x39ff('0x14'));var db=require(_0x39ff('0x15'))['db'];function respondWithStatusCode(_0xf66e2f,_0x3373f6){_0x3373f6=_0x3373f6||0xcc;return function(_0x13ac16){if(_0x13ac16){return _0xf66e2f[_0x39ff('0x16')](_0x3373f6);}return _0xf66e2f['status'](_0x3373f6)[_0x39ff('0x17')]();};}function respondWithResult(_0x1220dd,_0x23e439){_0x23e439=_0x23e439||0xc8;return function(_0x20d13e){if(_0x20d13e){return _0x1220dd['status'](_0x23e439)[_0x39ff('0x18')](_0x20d13e);}};}function respondWithFilteredResult(_0x5638e6,_0x51fa83){return function(_0x370e08){if(_0x370e08){var _0x196972=typeof _0x51fa83['offset']==='undefined'&&typeof _0x51fa83['limit']===_0x39ff('0x19');var _0x1b017f=_0x370e08[_0x39ff('0x1a')];var _0x5c7e9d=_0x196972?0x0:_0x51fa83[_0x39ff('0x1b')];var _0x145ce8=_0x196972?_0x370e08[_0x39ff('0x1a')]:_0x51fa83[_0x39ff('0x1b')]+_0x51fa83[_0x39ff('0x1c')];var _0x2657e9;if(_0x145ce8>=_0x1b017f){_0x145ce8=_0x1b017f;_0x2657e9=0xc8;}else{_0x2657e9=0xce;}_0x5638e6[_0x39ff('0x1d')](_0x2657e9);return _0x5638e6[_0x39ff('0x1e')]('Content-Range',_0x5c7e9d+'-'+_0x145ce8+'/'+_0x1b017f)['json'](_0x370e08);}return null;};}function patchUpdates(_0x30db71){return function(_0x35e582){try{jsonpatch[_0x39ff('0x1f')](_0x35e582,_0x30db71,!![]);}catch(_0x26a74a){return BPromise[_0x39ff('0x20')](_0x26a74a);}return _0x35e582[_0x39ff('0x21')]();};}function saveUpdates(_0x414b37,_0x2fd951){return function(_0x4487ae){if(_0x4487ae){return _0x4487ae[_0x39ff('0x22')](_0x414b37)[_0x39ff('0x23')](function(_0x38b69a){return _0x38b69a;});}return null;};}function removeEntity(_0x42a801,_0x2be22a){return function(_0x415642){if(_0x415642){return _0x415642[_0x39ff('0x24')]()[_0x39ff('0x23')](function(){_0x42a801[_0x39ff('0x1d')](0xcc)[_0x39ff('0x17')]();});}};}function handleEntityNotFound(_0x36e654,_0xb403e7){return function(_0x359285){if(!_0x359285){_0x36e654[_0x39ff('0x16')](0x194);}return _0x359285;};}function handleError(_0x4d0321,_0x116359){_0x116359=_0x116359||0x1f4;return function(_0x75ea7b){logger[_0x39ff('0x25')](_0x75ea7b[_0x39ff('0x26')]);if(_0x75ea7b[_0x39ff('0x27')]){delete _0x75ea7b[_0x39ff('0x27')];}_0x4d0321[_0x39ff('0x1d')](_0x116359)[_0x39ff('0x28')](_0x75ea7b);};}exports[_0x39ff('0x29')]=function(_0x59ef87,_0x59d70a){var _0x3f6c11={},_0x1b8815={},_0x2aa1f1={'count':0x0,'rows':[]};var _0x4a1f98=_[_0x39ff('0x2a')](db['VoiceMailMessage']['rawAttributes'],function(_0x30d585){return{'name':_0x30d585[_0x39ff('0x2b')],'type':_0x30d585['type'][_0x39ff('0x2c')]};});_0x1b8815[_0x39ff('0x2d')]=_[_0x39ff('0x2e')](_[_0x39ff('0x2a')](_0x4a1f98,'name'),[_0x39ff('0x27')]);_0x1b8815['query']=_[_0x39ff('0x2f')](_0x59ef87['query']);_0x1b8815[_0x39ff('0x30')]=_[_0x39ff('0x31')](_0x1b8815['model'],_0x1b8815[_0x39ff('0x32')]);_0x3f6c11[_0x39ff('0x33')]=_[_0x39ff('0x31')](_0x1b8815['model'],qs['fields'](_0x59ef87['query'][_0x39ff('0x34')]));_0x3f6c11['attributes']=_0x3f6c11[_0x39ff('0x33')][_0x39ff('0x35')]?_0x3f6c11['attributes']:_0x1b8815[_0x39ff('0x2d')];if(!_0x59ef87[_0x39ff('0x32')][_0x39ff('0x36')](_0x39ff('0x37'))){_0x3f6c11[_0x39ff('0x1c')]=qs[_0x39ff('0x1c')](_0x59ef87[_0x39ff('0x32')][_0x39ff('0x1c')]);_0x3f6c11['offset']=qs['offset'](_0x59ef87['query'][_0x39ff('0x1b')]);}_0x3f6c11[_0x39ff('0x38')]=qs['sort'](_0x59ef87[_0x39ff('0x32')]['sort']);_0x3f6c11['where']=qs[_0x39ff('0x30')](_[_0x39ff('0x39')](_0x59ef87[_0x39ff('0x32')],_0x1b8815[_0x39ff('0x30')]),_0x4a1f98);if(_0x59ef87[_0x39ff('0x32')][_0x39ff('0x3a')]){_0x3f6c11[_0x39ff('0x3b')]=_[_0x39ff('0x3c')](_0x3f6c11['where'],{'$or':_['map'](_0x4a1f98,function(_0x4a7a84){if(_0x4a7a84[_0x39ff('0x3d')]!=='VIRTUAL'){var _0x4463ff={};_0x4463ff[_0x4a7a84[_0x39ff('0x27')]]={'$like':'%'+_0x59ef87[_0x39ff('0x32')][_0x39ff('0x3a')]+'%'};return _0x4463ff;}})});}_0x3f6c11=_[_0x39ff('0x3c')]({},_0x3f6c11,_0x59ef87[_0x39ff('0x3e')]);var _0x1763c6={'where':_0x3f6c11[_0x39ff('0x3b')]};return db[_0x39ff('0x3f')][_0x39ff('0x1a')](_0x1763c6)[_0x39ff('0x23')](function(_0x1d7ead){_0x2aa1f1[_0x39ff('0x1a')]=_0x1d7ead;if(_0x59ef87[_0x39ff('0x32')]['includeAll']){_0x3f6c11[_0x39ff('0x40')]=[{'all':!![]}];}return db[_0x39ff('0x3f')][_0x39ff('0x41')](_0x3f6c11);})['then'](function(_0x248012){_0x2aa1f1['rows']=_0x248012;return _0x2aa1f1;})['then'](respondWithFilteredResult(_0x59d70a,_0x3f6c11))['catch'](handleError(_0x59d70a,null));};exports[_0x39ff('0x42')]=function(_0x405926,_0x5c0685){var _0x1a8ace={'raw':!![],'where':{'id':_0x405926[_0x39ff('0x43')]['id']}},_0x3ab640={};_0x3ab640[_0x39ff('0x2d')]=_[_0x39ff('0x2f')](db[_0x39ff('0x3f')][_0x39ff('0x44')]);_0x3ab640[_0x39ff('0x32')]=_[_0x39ff('0x2f')](_0x405926[_0x39ff('0x32')]);_0x3ab640[_0x39ff('0x30')]=_['intersection'](_0x3ab640[_0x39ff('0x2d')],_0x3ab640[_0x39ff('0x32')]);_0x1a8ace[_0x39ff('0x33')]=_[_0x39ff('0x31')](_0x3ab640[_0x39ff('0x2d')],qs['fields'](_0x405926[_0x39ff('0x32')][_0x39ff('0x34')]));_0x1a8ace[_0x39ff('0x33')]=_0x1a8ace[_0x39ff('0x33')][_0x39ff('0x35')]?_0x1a8ace[_0x39ff('0x33')]:_0x3ab640['model'];if(_0x405926[_0x39ff('0x32')]['includeAll']){_0x1a8ace[_0x39ff('0x40')]=[{'all':!![]}];}_0x1a8ace=_[_0x39ff('0x3c')]({},_0x1a8ace,_0x405926[_0x39ff('0x3e')]);return db[_0x39ff('0x3f')][_0x39ff('0x45')](_0x1a8ace)['then'](handleEntityNotFound(_0x5c0685,null))[_0x39ff('0x23')](respondWithResult(_0x5c0685,null))['catch'](handleError(_0x5c0685,null));};exports['create']=function(_0x32db09,_0x1fd567){return db[_0x39ff('0x3f')][_0x39ff('0x46')](_0x32db09['body'],{})[_0x39ff('0x23')](respondWithResult(_0x1fd567,0xc9))[_0x39ff('0x47')](handleError(_0x1fd567,null));};exports[_0x39ff('0x22')]=function(_0x4df82f,_0x37a071){if(_0x4df82f[_0x39ff('0x48')]['id']){delete _0x4df82f[_0x39ff('0x48')]['id'];}return db[_0x39ff('0x3f')][_0x39ff('0x45')]({'where':{'id':_0x4df82f[_0x39ff('0x43')]['id']}})[_0x39ff('0x23')](handleEntityNotFound(_0x37a071,null))['then'](saveUpdates(_0x4df82f[_0x39ff('0x48')],null))[_0x39ff('0x23')](respondWithResult(_0x37a071,null))['catch'](handleError(_0x37a071,null));};exports[_0x39ff('0x24')]=function(_0x456f1d,_0x5a9040){return db[_0x39ff('0x3f')][_0x39ff('0x45')]({'where':{'id':_0x456f1d[_0x39ff('0x43')]['id']}})['then'](handleEntityNotFound(_0x5a9040,null))[_0x39ff('0x23')](removeEntity(_0x5a9040,null))[_0x39ff('0x47')](handleError(_0x5a9040,null));};exports[_0x39ff('0x49')]=function(_0x19250f,_0x3c5b7c,_0x35e8e8){return db[_0x39ff('0x3f')][_0x39ff('0x45')]({'where':{'id':_0x19250f[_0x39ff('0x43')]['id']},'attributes':['id',_0x39ff('0x4a'),_0x39ff('0x4b')]})['then'](handleEntityNotFound(_0x3c5b7c,null))[_0x39ff('0x23')](function(_0x111d0d){if(_0x111d0d){if(!_0x111d0d[_0x39ff('0x4a')]){throw new db[(_0x39ff('0x4c'))][(_0x39ff('0x4d'))]('VoiceMailMessage\x20not\x20found');}var _0x532bad={'Content-Type':_0x39ff('0x4e'),'Content-Disposition':_0x39ff('0x4f')};if(_0x111d0d['msg_id']){_0x532bad[_0x39ff('0x50')]='attachment;\x20filename=\x22'+_0x111d0d[_0x39ff('0x4b')]+_0x39ff('0x51');}_0x3c5b7c[_0x39ff('0x1e')](_0x532bad);return _0x3c5b7c[_0x39ff('0x28')](new Buffer(_0x111d0d[_0x39ff('0x4a')]));}})['catch'](handleError(_0x3c5b7c,null));};