Built motion from commit 511216ff.|2.6.34
[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 _0x088f=['.cypher','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','count','set','Content-Range','apply','update','then','destroy','error','name','send','index','map','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','SquareRecording','includeAll','include','findAll','rows','show','params','find','catch','create','body','download','uniqueid','savePath','filename','format','%s.cypher','existsSync','decryptFile','secrets','recording','Sequelize','SquareRecording\x20not\x20found','unlink','message','isNil','Entity\x20not\x20found','info','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync'];(function(_0x21df92,_0x3e7d13){var _0x3a40e0=function(_0x1c8f9a){while(--_0x1c8f9a){_0x21df92['push'](_0x21df92['shift']());}};_0x3a40e0(++_0x3e7d13);}(_0x088f,0x185));var _0xf088=function(_0xc64fa7,_0x974362){_0xc64fa7=_0xc64fa7-0x0;var _0x4d0168=_0x088f[_0xc64fa7];return _0x4d0168;};'use strict';var emlformat=require(_0xf088('0x0'));var rimraf=require(_0xf088('0x1'));var zipdir=require(_0xf088('0x2'));var jsonpatch=require(_0xf088('0x3'));var rp=require('request-promise');var moment=require(_0xf088('0x4'));var BPromise=require(_0xf088('0x5'));var Mustache=require('mustache');var util=require(_0xf088('0x6'));var path=require(_0xf088('0x7'));var sox=require(_0xf088('0x8'));var csv=require(_0xf088('0x9'));var ejs=require(_0xf088('0xa'));var fs=require('fs');var fs_extra=require(_0xf088('0xb'));var _=require(_0xf088('0xc'));var squel=require(_0xf088('0xd'));var crypto=require(_0xf088('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xf088('0xf'));var toCsv=require(_0xf088('0x9'));var querystring=require('querystring');var Papa=require(_0xf088('0x10'));var Redis=require(_0xf088('0x11'));var authService=require(_0xf088('0x12'));var qs=require(_0xf088('0x13'));var as=require(_0xf088('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf088('0x15'))(_0xf088('0x16'));var utils=require(_0xf088('0x17'));var config=require(_0xf088('0x18'));var licenseUtil=require(_0xf088('0x19'));var db=require(_0xf088('0x1a'))['db'];function respondWithStatusCode(_0x4a1d5b,_0x845b57){_0x845b57=_0x845b57||0xcc;return function(_0x481867){if(_0x481867){return _0x4a1d5b[_0xf088('0x1b')](_0x845b57);}return _0x4a1d5b[_0xf088('0x1c')](_0x845b57)['end']();};}function respondWithResult(_0x7a16d9,_0x4170d2){_0x4170d2=_0x4170d2||0xc8;return function(_0x4066e9){if(_0x4066e9){return _0x7a16d9[_0xf088('0x1c')](_0x4170d2)[_0xf088('0x1d')](_0x4066e9);}};}function respondWithFilteredResult(_0x7d84b3,_0x15f6f8){return function(_0x1dcbe1){if(_0x1dcbe1){var _0x561cf3=typeof _0x15f6f8[_0xf088('0x1e')]==='undefined'&&typeof _0x15f6f8[_0xf088('0x1f')]==='undefined';var _0x5bc653=_0x1dcbe1[_0xf088('0x20')];var _0x2c67ee=_0x561cf3?0x0:_0x15f6f8[_0xf088('0x1e')];var _0x3da8ee=_0x561cf3?_0x1dcbe1[_0xf088('0x20')]:_0x15f6f8[_0xf088('0x1e')]+_0x15f6f8['limit'];var _0x561a24;if(_0x3da8ee>=_0x5bc653){_0x3da8ee=_0x5bc653;_0x561a24=0xc8;}else{_0x561a24=0xce;}_0x7d84b3['status'](_0x561a24);return _0x7d84b3[_0xf088('0x21')](_0xf088('0x22'),_0x2c67ee+'-'+_0x3da8ee+'/'+_0x5bc653)[_0xf088('0x1d')](_0x1dcbe1);}return null;};}function patchUpdates(_0x1821a4){return function(_0x3fdcc6){try{jsonpatch[_0xf088('0x23')](_0x3fdcc6,_0x1821a4,!![]);}catch(_0x39ced0){return BPromise['reject'](_0x39ced0);}return _0x3fdcc6['save']();};}function saveUpdates(_0x15f999,_0x11c968){return function(_0x2a8bfa){if(_0x2a8bfa){return _0x2a8bfa[_0xf088('0x24')](_0x15f999)[_0xf088('0x25')](function(_0x1a4da3){return _0x1a4da3;});}return null;};}function removeEntity(_0x57e1cc,_0x43e6b1){return function(_0x46aa8c){if(_0x46aa8c){return _0x46aa8c[_0xf088('0x26')]()[_0xf088('0x25')](function(){_0x57e1cc[_0xf088('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3060a1,_0x1fdb83){return function(_0x1b09fc){if(!_0x1b09fc){_0x3060a1[_0xf088('0x1b')](0x194);}return _0x1b09fc;};}function handleError(_0x25657c,_0x1776fd){_0x1776fd=_0x1776fd||0x1f4;return function(_0x3a4900){logger[_0xf088('0x27')](_0x3a4900['stack']);if(_0x3a4900[_0xf088('0x28')]){delete _0x3a4900['name'];}_0x25657c[_0xf088('0x1c')](_0x1776fd)[_0xf088('0x29')](_0x3a4900);};}exports[_0xf088('0x2a')]=function(_0x37755c,_0x43a71c){var _0x339eb5={},_0x20bce3={},_0x23a4af={'count':0x0,'rows':[]};var _0x1628c3=_[_0xf088('0x2b')](db['SquareRecording'][_0xf088('0x2c')],function(_0x4cccaf){return{'name':_0x4cccaf[_0xf088('0x2d')],'type':_0x4cccaf[_0xf088('0x2e')][_0xf088('0x2f')]};});_0x20bce3['model']=_[_0xf088('0x2b')](_0x1628c3,_0xf088('0x28'));_0x20bce3[_0xf088('0x30')]=_[_0xf088('0x31')](_0x37755c[_0xf088('0x30')]);_0x20bce3[_0xf088('0x32')]=_[_0xf088('0x33')](_0x20bce3[_0xf088('0x34')],_0x20bce3[_0xf088('0x30')]);_0x339eb5[_0xf088('0x35')]=_[_0xf088('0x33')](_0x20bce3['model'],qs[_0xf088('0x36')](_0x37755c[_0xf088('0x30')][_0xf088('0x36')]));_0x339eb5[_0xf088('0x35')]=_0x339eb5[_0xf088('0x35')][_0xf088('0x37')]?_0x339eb5[_0xf088('0x35')]:_0x20bce3[_0xf088('0x34')];if(!_0x37755c['query']['hasOwnProperty'](_0xf088('0x38'))){_0x339eb5[_0xf088('0x1f')]=qs[_0xf088('0x1f')](_0x37755c[_0xf088('0x30')][_0xf088('0x1f')]);_0x339eb5[_0xf088('0x1e')]=qs[_0xf088('0x1e')](_0x37755c['query'][_0xf088('0x1e')]);}_0x339eb5[_0xf088('0x39')]=qs[_0xf088('0x3a')](_0x37755c[_0xf088('0x30')][_0xf088('0x3a')]);_0x339eb5[_0xf088('0x3b')]=qs['filters'](_[_0xf088('0x3c')](_0x37755c[_0xf088('0x30')],_0x20bce3[_0xf088('0x32')]),_0x1628c3);if(_0x37755c[_0xf088('0x30')][_0xf088('0x3d')]){_0x339eb5[_0xf088('0x3b')]=_['merge'](_0x339eb5[_0xf088('0x3b')],{'$or':_[_0xf088('0x2b')](_0x1628c3,function(_0x3dc90e){if(_0x3dc90e[_0xf088('0x2e')]!==_0xf088('0x3e')){var _0x3e09a7={};_0x3e09a7[_0x3dc90e[_0xf088('0x28')]]={'$like':'%'+_0x37755c[_0xf088('0x30')]['filter']+'%'};return _0x3e09a7;}})});}_0x339eb5=_[_0xf088('0x3f')]({},_0x339eb5,_0x37755c[_0xf088('0x40')]);var _0x84fc54={'where':_0x339eb5[_0xf088('0x3b')]};return db[_0xf088('0x41')][_0xf088('0x20')](_0x84fc54)['then'](function(_0x4abfd2){_0x23a4af['count']=_0x4abfd2;if(_0x37755c[_0xf088('0x30')][_0xf088('0x42')]){_0x339eb5[_0xf088('0x43')]=[{'all':!![]}];}return db['SquareRecording'][_0xf088('0x44')](_0x339eb5);})['then'](function(_0x177838){_0x23a4af[_0xf088('0x45')]=_0x177838;return _0x23a4af;})[_0xf088('0x25')](respondWithFilteredResult(_0x43a71c,_0x339eb5))['catch'](handleError(_0x43a71c,null));};exports[_0xf088('0x46')]=function(_0x30e79e,_0x3f1892){var _0x28e145={'raw':!![],'where':{'id':_0x30e79e[_0xf088('0x47')]['id']}},_0x35708c={};_0x35708c[_0xf088('0x34')]=_[_0xf088('0x31')](db[_0xf088('0x41')][_0xf088('0x2c')]);_0x35708c[_0xf088('0x30')]=_['keys'](_0x30e79e[_0xf088('0x30')]);_0x35708c[_0xf088('0x32')]=_[_0xf088('0x33')](_0x35708c[_0xf088('0x34')],_0x35708c['query']);_0x28e145[_0xf088('0x35')]=_['intersection'](_0x35708c['model'],qs['fields'](_0x30e79e[_0xf088('0x30')][_0xf088('0x36')]));_0x28e145['attributes']=_0x28e145[_0xf088('0x35')][_0xf088('0x37')]?_0x28e145[_0xf088('0x35')]:_0x35708c['model'];if(_0x30e79e[_0xf088('0x30')]['includeAll']){_0x28e145[_0xf088('0x43')]=[{'all':!![]}];}_0x28e145=_[_0xf088('0x3f')]({},_0x28e145,_0x30e79e['options']);return db[_0xf088('0x41')][_0xf088('0x48')](_0x28e145)[_0xf088('0x25')](handleEntityNotFound(_0x3f1892,null))[_0xf088('0x25')](respondWithResult(_0x3f1892,null))[_0xf088('0x49')](handleError(_0x3f1892,null));};exports[_0xf088('0x4a')]=function(_0x5c296a,_0x3a7dab){return db['SquareRecording'][_0xf088('0x4a')](_0x5c296a[_0xf088('0x4b')],{})[_0xf088('0x25')](respondWithResult(_0x3a7dab,0xc9))[_0xf088('0x49')](handleError(_0x3a7dab,null));};exports[_0xf088('0x24')]=function(_0x2e4de3,_0x5de993){if(_0x2e4de3[_0xf088('0x4b')]['id']){delete _0x2e4de3['body']['id'];}return db[_0xf088('0x41')][_0xf088('0x48')]({'where':{'id':_0x2e4de3[_0xf088('0x47')]['id']}})[_0xf088('0x25')](handleEntityNotFound(_0x5de993,null))['then'](saveUpdates(_0x2e4de3[_0xf088('0x4b')],null))[_0xf088('0x25')](respondWithResult(_0x5de993,null))[_0xf088('0x49')](handleError(_0x5de993,null));};exports[_0xf088('0x4c')]=function(_0x1da433,_0x489376,_0x2fbe90){var _0x5275be=require('../../components/encryptor');var _0x549701=![];var _0x1031ce={};if(_0x1da433[_0xf088('0x30')][_0xf088('0x2e')]&&_0x1da433[_0xf088('0x30')][_0xf088('0x2e')]===_0xf088('0x4d')){_0x1031ce[_0xf088('0x4d')]=_0x1da433[_0xf088('0x47')]['id'];}else{_0x1031ce['id']=_0x1da433[_0xf088('0x47')]['id'];}return db[_0xf088('0x41')][_0xf088('0x48')]({'where':_0x1031ce,'attributes':['id',_0xf088('0x4e'),_0xf088('0x4f')],'raw':!![]})['then'](handleEntityNotFound(_0x489376,null))['then'](function(_0x314f1a){if(_0x314f1a){var _0x35aeec=_0x314f1a['savePath'];var _0x501442=util[_0xf088('0x50')](_0xf088('0x51'),_0x35aeec);if(fs[_0xf088('0x52')](_0x501442)){_0x549701=!![];return _0x5275be[_0xf088('0x53')](_0x501442,_0x35aeec,config[_0xf088('0x54')][_0xf088('0x55')])['then'](function(){return _0x314f1a;});}return _0x314f1a;}})[_0xf088('0x25')](function(_0x563cd8){if(_0x563cd8){var _0x2dc436=_0x563cd8[_0xf088('0x4e')];if(!fs[_0xf088('0x52')](_0x2dc436)){throw new db[(_0xf088('0x56'))]['ValidationError'](_0xf088('0x57'));}if(_0x563cd8[_0xf088('0x4f')]){return _0x489376[_0xf088('0x4c')](_0x2dc436,_0x563cd8[_0xf088('0x4f')]+path['extname'](_0x2dc436),function(){if(_0x549701){fs[_0xf088('0x58')](_0x2dc436);}});}else{return _0x489376['download'](_0x2dc436,function(_0x3cb082){if(_0x549701){fs[_0xf088('0x58')](_0x2dc436);}});}}})[_0xf088('0x49')](function(_0x4083e7){if(_0x4083e7[_0xf088('0x59')]==='SquareRecording\x20not\x20found'){_0x489376[_0xf088('0x1c')](0x194)[_0xf088('0x29')]('Not\x20found');}else{return handleError(_0x489376,null);}});};exports['destroy']=function(_0x2d8e28,_0x4959b6){return db[_0xf088('0x41')]['find']({'where':{'id':_0x2d8e28['params']['id']}})[_0xf088('0x25')](function(_0x16183f){if(_[_0xf088('0x5a')](_0x16183f)){throw new ReferenceError(_0xf088('0x5b'));}return _0x16183f;})[_0xf088('0x25')](function(_0x2935ad){var _0x1cc33f=_0x2935ad['savePath'];logger[_0xf088('0x5c')]('cancellazione\x20fisica\x20documento\x20%s',_0x1cc33f);if(!_['isNil'](_0x2935ad[_0xf088('0x4e')])&&fs['existsSync'](_0x1cc33f)){logger[_0xf088('0x5c')](_0xf088('0x5d')+_0x1cc33f+_0xf088('0x5e'));fs[_0xf088('0x5f')](_0x1cc33f);}_0x1cc33f=_0x1cc33f+_0xf088('0x60');if(!_[_0xf088('0x5a')](_0x2935ad[_0xf088('0x4e')])&&fs['existsSync'](_0x1cc33f)){logger[_0xf088('0x5c')](_0xf088('0x5d')+_0x1cc33f+_0xf088('0x5e'));fs[_0xf088('0x5f')](_0x1cc33f);}return _0x2935ad;})[_0xf088('0x25')](function(_0x13b5cb){if(!_0x13b5cb)throw new InternalError();return _0x13b5cb[_0xf088('0x26')]();})[_0xf088('0x25')](function(){_0x4959b6[_0xf088('0x1c')](0xcc)['end']();})[_0xf088('0x49')](handleError(_0x4959b6,null));};