Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / squareRecording / squareRecording.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 _0xf270=['zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','send','index','map','SquareRecording','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','show','params','length','create','body','find','catch','download','../../components/encryptor','uniqueid','savePath','filename','format','existsSync','decryptFile','secrets','recording','Sequelize','ValidationError','SquareRecording\x20not\x20found','extname','message','Not\x20found','isNil','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','eml-format','rimraf'];(function(_0x5341ff,_0x1de6df){var _0x53be58=function(_0x4da0da){while(--_0x4da0da){_0x5341ff['push'](_0x5341ff['shift']());}};_0x53be58(++_0x1de6df);}(_0xf270,0x1ed));var _0x0f27=function(_0xd93b26,_0x12bbf2){_0xd93b26=_0xd93b26-0x0;var _0x25f668=_0xf270[_0xd93b26];return _0x25f668;};'use strict';var emlformat=require(_0x0f27('0x0'));var rimraf=require(_0x0f27('0x1'));var zipdir=require(_0x0f27('0x2'));var jsonpatch=require(_0x0f27('0x3'));var rp=require('request-promise');var moment=require(_0x0f27('0x4'));var BPromise=require(_0x0f27('0x5'));var Mustache=require(_0x0f27('0x6'));var util=require(_0x0f27('0x7'));var path=require(_0x0f27('0x8'));var sox=require(_0x0f27('0x9'));var csv=require(_0x0f27('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x0f27('0xb'));var _=require(_0x0f27('0xc'));var squel=require(_0x0f27('0xd'));var crypto=require(_0x0f27('0xe'));var jsforce=require(_0x0f27('0xf'));var deskjs=require(_0x0f27('0x10'));var toCsv=require('to-csv');var querystring=require(_0x0f27('0x11'));var Papa=require(_0x0f27('0x12'));var Redis=require('ioredis');var authService=require(_0x0f27('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x0f27('0x14'))(_0x0f27('0x15'));var utils=require(_0x0f27('0x16'));var config=require(_0x0f27('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x0f27('0x18'))['db'];function respondWithStatusCode(_0x15c19a,_0xd47fb6){_0xd47fb6=_0xd47fb6||0xcc;return function(_0x5b0d89){if(_0x5b0d89){return _0x15c19a[_0x0f27('0x19')](_0xd47fb6);}return _0x15c19a[_0x0f27('0x1a')](_0xd47fb6)[_0x0f27('0x1b')]();};}function respondWithResult(_0x550cdc,_0x4830cb){_0x4830cb=_0x4830cb||0xc8;return function(_0xf5aef2){if(_0xf5aef2){return _0x550cdc[_0x0f27('0x1a')](_0x4830cb)[_0x0f27('0x1c')](_0xf5aef2);}};}function respondWithFilteredResult(_0x415373,_0x3a5034){return function(_0x211084){if(_0x211084){var _0x2d6700=typeof _0x3a5034[_0x0f27('0x1d')]===_0x0f27('0x1e')&&typeof _0x3a5034['limit']==='undefined';var _0x2ce502=_0x211084[_0x0f27('0x1f')];var _0x566b20=_0x2d6700?0x0:_0x3a5034['offset'];var _0x47fff5=_0x2d6700?_0x211084[_0x0f27('0x1f')]:_0x3a5034[_0x0f27('0x1d')]+_0x3a5034['limit'];var _0x201f89;if(_0x47fff5>=_0x2ce502){_0x47fff5=_0x2ce502;_0x201f89=0xc8;}else{_0x201f89=0xce;}_0x415373[_0x0f27('0x1a')](_0x201f89);return _0x415373['set'](_0x0f27('0x20'),_0x566b20+'-'+_0x47fff5+'/'+_0x2ce502)[_0x0f27('0x1c')](_0x211084);}return null;};}function patchUpdates(_0x206b7f){return function(_0x26d44d){try{jsonpatch[_0x0f27('0x21')](_0x26d44d,_0x206b7f,!![]);}catch(_0x5a98c6){return BPromise[_0x0f27('0x22')](_0x5a98c6);}return _0x26d44d[_0x0f27('0x23')]();};}function saveUpdates(_0x14e19a,_0xfbed17){return function(_0x468775){if(_0x468775){return _0x468775[_0x0f27('0x24')](_0x14e19a)['then'](function(_0x5df79b){return _0x5df79b;});}return null;};}function removeEntity(_0x343323,_0xa39a56){return function(_0x2a4164){if(_0x2a4164){return _0x2a4164[_0x0f27('0x25')]()[_0x0f27('0x26')](function(){_0x343323[_0x0f27('0x1a')](0xcc)[_0x0f27('0x1b')]();});}};}function handleEntityNotFound(_0x4600a8,_0x1d8890){return function(_0x42dd47){if(!_0x42dd47){_0x4600a8[_0x0f27('0x19')](0x194);}return _0x42dd47;};}function handleError(_0x4dcf45,_0x3070af){_0x3070af=_0x3070af||0x1f4;return function(_0x3dce7e){logger[_0x0f27('0x27')](_0x3dce7e[_0x0f27('0x28')]);if(_0x3dce7e[_0x0f27('0x29')]){delete _0x3dce7e[_0x0f27('0x29')];}_0x4dcf45[_0x0f27('0x1a')](_0x3070af)[_0x0f27('0x2a')](_0x3dce7e);};}exports[_0x0f27('0x2b')]=function(_0xde72b7,_0x5502f6){var _0x2b25aa={},_0x509c63={},_0x1335e2={'count':0x0,'rows':[]};var _0x3731d1=_[_0x0f27('0x2c')](db[_0x0f27('0x2d')][_0x0f27('0x2e')],function(_0x35b3c7){return{'name':_0x35b3c7[_0x0f27('0x2f')],'type':_0x35b3c7[_0x0f27('0x30')][_0x0f27('0x31')]};});_0x509c63[_0x0f27('0x32')]=_[_0x0f27('0x2c')](_0x3731d1,_0x0f27('0x29'));_0x509c63[_0x0f27('0x33')]=_[_0x0f27('0x34')](_0xde72b7['query']);_0x509c63[_0x0f27('0x35')]=_[_0x0f27('0x36')](_0x509c63[_0x0f27('0x32')],_0x509c63['query']);_0x2b25aa[_0x0f27('0x37')]=_[_0x0f27('0x36')](_0x509c63[_0x0f27('0x32')],qs[_0x0f27('0x38')](_0xde72b7[_0x0f27('0x33')][_0x0f27('0x38')]));_0x2b25aa[_0x0f27('0x37')]=_0x2b25aa[_0x0f27('0x37')]['length']?_0x2b25aa[_0x0f27('0x37')]:_0x509c63['model'];if(!_0xde72b7[_0x0f27('0x33')][_0x0f27('0x39')]('nolimit')){_0x2b25aa[_0x0f27('0x3a')]=qs[_0x0f27('0x3a')](_0xde72b7[_0x0f27('0x33')]['limit']);_0x2b25aa[_0x0f27('0x1d')]=qs[_0x0f27('0x1d')](_0xde72b7[_0x0f27('0x33')][_0x0f27('0x1d')]);}_0x2b25aa[_0x0f27('0x3b')]=qs[_0x0f27('0x3c')](_0xde72b7[_0x0f27('0x33')][_0x0f27('0x3c')]);_0x2b25aa[_0x0f27('0x3d')]=qs[_0x0f27('0x35')](_[_0x0f27('0x3e')](_0xde72b7[_0x0f27('0x33')],_0x509c63[_0x0f27('0x35')]),_0x3731d1);if(_0xde72b7[_0x0f27('0x33')][_0x0f27('0x3f')]){_0x2b25aa[_0x0f27('0x3d')]=_[_0x0f27('0x40')](_0x2b25aa[_0x0f27('0x3d')],{'$or':_['map'](_0x3731d1,function(_0x1bb37b){if(_0x1bb37b[_0x0f27('0x30')]!==_0x0f27('0x41')){var _0x28b12b={};_0x28b12b[_0x1bb37b['name']]={'$like':'%'+_0xde72b7['query'][_0x0f27('0x3f')]+'%'};return _0x28b12b;}})});}_0x2b25aa=_[_0x0f27('0x40')]({},_0x2b25aa,_0xde72b7[_0x0f27('0x42')]);var _0x353ff={'where':_0x2b25aa[_0x0f27('0x3d')]};return db[_0x0f27('0x2d')]['count'](_0x353ff)['then'](function(_0x37b08f){_0x1335e2[_0x0f27('0x1f')]=_0x37b08f;if(_0xde72b7['query'][_0x0f27('0x43')]){_0x2b25aa[_0x0f27('0x44')]=[{'all':!![]}];}return db[_0x0f27('0x2d')]['findAll'](_0x2b25aa);})['then'](function(_0x2c8c86){_0x1335e2[_0x0f27('0x45')]=_0x2c8c86;return _0x1335e2;})['then'](respondWithFilteredResult(_0x5502f6,_0x2b25aa))['catch'](handleError(_0x5502f6,null));};exports[_0x0f27('0x46')]=function(_0x458e09,_0x481965){var _0x4b78e2={'raw':!![],'where':{'id':_0x458e09[_0x0f27('0x47')]['id']}},_0x571310={};_0x571310[_0x0f27('0x32')]=_['keys'](db[_0x0f27('0x2d')][_0x0f27('0x2e')]);_0x571310[_0x0f27('0x33')]=_[_0x0f27('0x34')](_0x458e09[_0x0f27('0x33')]);_0x571310[_0x0f27('0x35')]=_[_0x0f27('0x36')](_0x571310[_0x0f27('0x32')],_0x571310[_0x0f27('0x33')]);_0x4b78e2['attributes']=_[_0x0f27('0x36')](_0x571310[_0x0f27('0x32')],qs[_0x0f27('0x38')](_0x458e09[_0x0f27('0x33')]['fields']));_0x4b78e2['attributes']=_0x4b78e2[_0x0f27('0x37')][_0x0f27('0x48')]?_0x4b78e2[_0x0f27('0x37')]:_0x571310[_0x0f27('0x32')];if(_0x458e09[_0x0f27('0x33')]['includeAll']){_0x4b78e2['include']=[{'all':!![]}];}_0x4b78e2=_[_0x0f27('0x40')]({},_0x4b78e2,_0x458e09[_0x0f27('0x42')]);return db[_0x0f27('0x2d')]['find'](_0x4b78e2)[_0x0f27('0x26')](handleEntityNotFound(_0x481965,null))[_0x0f27('0x26')](respondWithResult(_0x481965,null))['catch'](handleError(_0x481965,null));};exports[_0x0f27('0x49')]=function(_0x283e01,_0x55bc8f){return db[_0x0f27('0x2d')][_0x0f27('0x49')](_0x283e01[_0x0f27('0x4a')],{})[_0x0f27('0x26')](respondWithResult(_0x55bc8f,0xc9))['catch'](handleError(_0x55bc8f,null));};exports[_0x0f27('0x24')]=function(_0x5c1671,_0x3ef7d5){if(_0x5c1671[_0x0f27('0x4a')]['id']){delete _0x5c1671[_0x0f27('0x4a')]['id'];}return db[_0x0f27('0x2d')][_0x0f27('0x4b')]({'where':{'id':_0x5c1671[_0x0f27('0x47')]['id']}})['then'](handleEntityNotFound(_0x3ef7d5,null))[_0x0f27('0x26')](saveUpdates(_0x5c1671[_0x0f27('0x4a')],null))[_0x0f27('0x26')](respondWithResult(_0x3ef7d5,null))[_0x0f27('0x4c')](handleError(_0x3ef7d5,null));};exports[_0x0f27('0x4d')]=function(_0x5f228b,_0x3a3980,_0x2592cb){var _0x557441=require(_0x0f27('0x4e'));var _0x585421=![];var _0x5e9bac={};if(_0x5f228b['query'][_0x0f27('0x30')]&&_0x5f228b['query']['type']===_0x0f27('0x4f')){_0x5e9bac[_0x0f27('0x4f')]=_0x5f228b['params']['id'];}else{_0x5e9bac['id']=_0x5f228b[_0x0f27('0x47')]['id'];}return db[_0x0f27('0x2d')][_0x0f27('0x4b')]({'where':_0x5e9bac,'attributes':['id',_0x0f27('0x50'),_0x0f27('0x51')],'raw':!![]})[_0x0f27('0x26')](handleEntityNotFound(_0x3a3980,null))[_0x0f27('0x26')](function(_0x472888){if(_0x472888){var _0x24600a=_0x472888[_0x0f27('0x50')];var _0x474323=util[_0x0f27('0x52')]('%s.cypher',_0x24600a);if(fs[_0x0f27('0x53')](_0x474323)){_0x585421=!![];return _0x557441[_0x0f27('0x54')](_0x474323,_0x24600a,config[_0x0f27('0x55')][_0x0f27('0x56')])[_0x0f27('0x26')](function(){return _0x472888;});}return _0x472888;}})[_0x0f27('0x26')](function(_0x5bb932){if(_0x5bb932){var _0x2a9497=_0x5bb932['savePath'];if(!fs[_0x0f27('0x53')](_0x2a9497)){throw new db[(_0x0f27('0x57'))][(_0x0f27('0x58'))](_0x0f27('0x59'));}if(_0x5bb932[_0x0f27('0x51')]){return _0x3a3980['download'](_0x2a9497,_0x5bb932[_0x0f27('0x51')]+path[_0x0f27('0x5a')](_0x2a9497),function(){if(_0x585421){fs['unlink'](_0x2a9497);}});}else{return _0x3a3980['download'](_0x2a9497,function(_0x4a1da8){if(_0x585421){fs['unlink'](_0x2a9497);}});}}})[_0x0f27('0x4c')](function(_0x4d74ac){if(_0x4d74ac[_0x0f27('0x5b')]==='SquareRecording\x20not\x20found'){_0x3a3980[_0x0f27('0x1a')](0x194)[_0x0f27('0x2a')](_0x0f27('0x5c'));}else{return handleError(_0x3a3980,null);}});};exports[_0x0f27('0x25')]=function(_0x136504,_0x19b5b6){return db['SquareRecording'][_0x0f27('0x4b')]({'where':{'id':_0x136504[_0x0f27('0x47')]['id']}})[_0x0f27('0x26')](function(_0x4632e5){if(_[_0x0f27('0x5d')](_0x4632e5)){throw new ReferenceError('Entity\x20not\x20found');}return _0x4632e5;})[_0x0f27('0x26')](function(_0x3b2ee7){var _0x54b1a7=_0x3b2ee7[_0x0f27('0x50')];logger[_0x0f27('0x5e')](_0x0f27('0x5f'),_0x54b1a7);if(!_['isNil'](_0x3b2ee7['savePath'])&&fs[_0x0f27('0x53')](_0x54b1a7)){logger[_0x0f27('0x5e')](_0x0f27('0x60')+_0x54b1a7+_0x0f27('0x61'));fs['unlinkSync'](_0x54b1a7);}_0x54b1a7=_0x54b1a7+'.cypher';if(!_[_0x0f27('0x5d')](_0x3b2ee7[_0x0f27('0x50')])&&fs[_0x0f27('0x53')](_0x54b1a7)){logger[_0x0f27('0x5e')]('File:\x20\x22'+_0x54b1a7+_0x0f27('0x61'));fs[_0x0f27('0x62')](_0x54b1a7);}return _0x3b2ee7;})['then'](function(_0x3970e7){if(!_0x3970e7)throw new InternalError();return _0x3970e7[_0x0f27('0x25')]();})[_0x0f27('0x26')](function(){_0x19b5b6['status'](0xcc)[_0x0f27('0x1b')]();})[_0x0f27('0x4c')](handleError(_0x19b5b6,null));};