Built motion from commit (unavailable).|2.5.2
[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 _0xaaf7=['%s.cypher','existsSync','decryptFile','secrets','recording','Sequelize','ValidationError','SquareRecording\x20not\x20found','extname','unlink','message','send','Not\x20found','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','name','index','map','SquareRecording','rawAttributes','type','key','query','keys','filters','model','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','body','find','download','uniqueid','savePath','filename','format'];(function(_0x1ba7d1,_0xca732d){var _0x468c50=function(_0x4fe2ab){while(--_0x4fe2ab){_0x1ba7d1['push'](_0x1ba7d1['shift']());}};_0x468c50(++_0xca732d);}(_0xaaf7,0x77));var _0x7aaf=function(_0x4a8bc2,_0x4128e0){_0x4a8bc2=_0x4a8bc2-0x0;var _0x587b68=_0xaaf7[_0x4a8bc2];return _0x587b68;};'use strict';var pdf=require(_0x7aaf('0x0'));var emlformat=require(_0x7aaf('0x1'));var rimraf=require(_0x7aaf('0x2'));var zipdir=require(_0x7aaf('0x3'));var jsonpatch=require(_0x7aaf('0x4'));var rp=require(_0x7aaf('0x5'));var moment=require('moment');var BPromise=require(_0x7aaf('0x6'));var Mustache=require(_0x7aaf('0x7'));var util=require('util');var path=require(_0x7aaf('0x8'));var sox=require(_0x7aaf('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x7aaf('0xa'));var squel=require(_0x7aaf('0xb'));var crypto=require(_0x7aaf('0xc'));var jsforce=require(_0x7aaf('0xd'));var deskjs=require(_0x7aaf('0xe'));var toCsv=require(_0x7aaf('0xf'));var querystring=require(_0x7aaf('0x10'));var Papa=require(_0x7aaf('0x11'));var Redis=require(_0x7aaf('0x12'));var authService=require(_0x7aaf('0x13'));var qs=require(_0x7aaf('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x7aaf('0x15'));var logger=require(_0x7aaf('0x16'))('api');var utils=require(_0x7aaf('0x17'));var config=require(_0x7aaf('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x413657,_0x43a223){_0x43a223=_0x43a223||0xcc;return function(_0x49df22){if(_0x49df22){return _0x413657[_0x7aaf('0x19')](_0x43a223);}return _0x413657[_0x7aaf('0x1a')](_0x43a223)[_0x7aaf('0x1b')]();};}function respondWithResult(_0x3886da,_0x491567){_0x491567=_0x491567||0xc8;return function(_0x492ed0){if(_0x492ed0){return _0x3886da[_0x7aaf('0x1a')](_0x491567)[_0x7aaf('0x1c')](_0x492ed0);}};}function respondWithFilteredResult(_0x299c08,_0x33641a){return function(_0x486105){if(_0x486105){var _0x43c78b=_0x486105['count'],_0x1a41be=_0x33641a[_0x7aaf('0x1d')],_0x98e81=_0x33641a['offset']+_0x33641a[_0x7aaf('0x1e')],_0xc8ca4a;if(_0x98e81>=_0x43c78b){_0x98e81=_0x43c78b;_0xc8ca4a=0xc8;}else{_0xc8ca4a=0xce;}_0x299c08[_0x7aaf('0x1a')](_0xc8ca4a);return _0x299c08[_0x7aaf('0x1f')](_0x7aaf('0x20'),_0x1a41be+'-'+_0x98e81+'/'+_0x43c78b)[_0x7aaf('0x1c')](_0x486105);}return null;};}function patchUpdates(_0x5cf96d){return function(_0x162935){try{jsonpatch[_0x7aaf('0x21')](_0x162935,_0x5cf96d,!![]);}catch(_0xe968c1){return BPromise[_0x7aaf('0x22')](_0xe968c1);}return _0x162935[_0x7aaf('0x23')]();};}function saveUpdates(_0x74e7b5,_0x51a7c6){return function(_0xdfbd91){if(_0xdfbd91){return _0xdfbd91[_0x7aaf('0x24')](_0x74e7b5)[_0x7aaf('0x25')](function(_0x1f9014){return _0x1f9014;});}return null;};}function removeEntity(_0x544fd7,_0x425d8b){return function(_0x2a5518){if(_0x2a5518){return _0x2a5518[_0x7aaf('0x26')]()[_0x7aaf('0x25')](function(){_0x544fd7['status'](0xcc)[_0x7aaf('0x1b')]();});}};}function handleEntityNotFound(_0x84f2e7,_0x1f5d3f){return function(_0x5b7598){if(!_0x5b7598){_0x84f2e7[_0x7aaf('0x19')](0x194);}return _0x5b7598;};}function handleError(_0x3f7a55,_0x316ce7){_0x316ce7=_0x316ce7||0x1f4;return function(_0x4408e4){logger[_0x7aaf('0x27')](_0x4408e4['stack']);if(_0x4408e4[_0x7aaf('0x28')]){delete _0x4408e4[_0x7aaf('0x28')];}_0x3f7a55[_0x7aaf('0x1a')](_0x316ce7)['send'](_0x4408e4);};}exports[_0x7aaf('0x29')]=function(_0x42a81f,_0x4e06d8){var _0x54eb6e={},_0x2570c0={},_0x13809e={'count':0x0,'rows':[]};var _0xb6d81f=_[_0x7aaf('0x2a')](db[_0x7aaf('0x2b')][_0x7aaf('0x2c')],function(_0xfa3b05){return{'name':_0xfa3b05['fieldName'],'type':_0xfa3b05[_0x7aaf('0x2d')][_0x7aaf('0x2e')]};});_0x2570c0['model']=_[_0x7aaf('0x2a')](_0xb6d81f,'name');_0x2570c0[_0x7aaf('0x2f')]=_[_0x7aaf('0x30')](_0x42a81f[_0x7aaf('0x2f')]);_0x2570c0[_0x7aaf('0x31')]=_['intersection'](_0x2570c0[_0x7aaf('0x32')],_0x2570c0['query']);_0x54eb6e[_0x7aaf('0x33')]=_[_0x7aaf('0x34')](_0x2570c0[_0x7aaf('0x32')],qs[_0x7aaf('0x35')](_0x42a81f[_0x7aaf('0x2f')][_0x7aaf('0x35')]));_0x54eb6e[_0x7aaf('0x33')]=_0x54eb6e[_0x7aaf('0x33')][_0x7aaf('0x36')]?_0x54eb6e['attributes']:_0x2570c0['model'];if(!_0x42a81f['query'][_0x7aaf('0x37')]('nolimit')){_0x54eb6e['limit']=qs[_0x7aaf('0x1e')](_0x42a81f[_0x7aaf('0x2f')]['limit']);_0x54eb6e['offset']=qs[_0x7aaf('0x1d')](_0x42a81f['query'][_0x7aaf('0x1d')]);}_0x54eb6e[_0x7aaf('0x38')]=qs[_0x7aaf('0x39')](_0x42a81f[_0x7aaf('0x2f')][_0x7aaf('0x39')]);_0x54eb6e[_0x7aaf('0x3a')]=qs[_0x7aaf('0x31')](_[_0x7aaf('0x3b')](_0x42a81f[_0x7aaf('0x2f')],_0x2570c0[_0x7aaf('0x31')]),_0xb6d81f);if(_0x42a81f[_0x7aaf('0x2f')][_0x7aaf('0x3c')]){_0x54eb6e['where']=_[_0x7aaf('0x3d')](_0x54eb6e[_0x7aaf('0x3a')],{'$or':_[_0x7aaf('0x2a')](_0xb6d81f,function(_0x37c301){if(_0x37c301[_0x7aaf('0x2d')]!==_0x7aaf('0x3e')){var _0x2785ee={};_0x2785ee[_0x37c301[_0x7aaf('0x28')]]={'$like':'%'+_0x42a81f[_0x7aaf('0x2f')]['filter']+'%'};return _0x2785ee;}})});}_0x54eb6e=_[_0x7aaf('0x3d')]({},_0x54eb6e,_0x42a81f[_0x7aaf('0x3f')]);var _0x27010b={'where':_0x54eb6e[_0x7aaf('0x3a')]};return db['SquareRecording'][_0x7aaf('0x40')](_0x27010b)[_0x7aaf('0x25')](function(_0x1040b9){_0x13809e['count']=_0x1040b9;if(_0x42a81f['query'][_0x7aaf('0x41')]){_0x54eb6e[_0x7aaf('0x42')]=[{'all':!![]}];}return db['SquareRecording'][_0x7aaf('0x43')](_0x54eb6e);})['then'](function(_0x496688){_0x13809e[_0x7aaf('0x44')]=_0x496688;return _0x13809e;})[_0x7aaf('0x25')](respondWithFilteredResult(_0x4e06d8,_0x54eb6e))[_0x7aaf('0x45')](handleError(_0x4e06d8,null));};exports[_0x7aaf('0x46')]=function(_0x3d152b,_0x797c8b){var _0xf3caba={'raw':!![],'where':{'id':_0x3d152b[_0x7aaf('0x47')]['id']}},_0x458d70={};_0x458d70[_0x7aaf('0x32')]=_['keys'](db['SquareRecording']['rawAttributes']);_0x458d70[_0x7aaf('0x2f')]=_[_0x7aaf('0x30')](_0x3d152b[_0x7aaf('0x2f')]);_0x458d70[_0x7aaf('0x31')]=_[_0x7aaf('0x34')](_0x458d70[_0x7aaf('0x32')],_0x458d70[_0x7aaf('0x2f')]);_0xf3caba[_0x7aaf('0x33')]=_[_0x7aaf('0x34')](_0x458d70['model'],qs[_0x7aaf('0x35')](_0x3d152b[_0x7aaf('0x2f')][_0x7aaf('0x35')]));_0xf3caba['attributes']=_0xf3caba[_0x7aaf('0x33')][_0x7aaf('0x36')]?_0xf3caba['attributes']:_0x458d70[_0x7aaf('0x32')];if(_0x3d152b[_0x7aaf('0x2f')][_0x7aaf('0x41')]){_0xf3caba[_0x7aaf('0x42')]=[{'all':!![]}];}_0xf3caba=_['merge']({},_0xf3caba,_0x3d152b[_0x7aaf('0x3f')]);return db[_0x7aaf('0x2b')]['find'](_0xf3caba)[_0x7aaf('0x25')](handleEntityNotFound(_0x797c8b,null))[_0x7aaf('0x25')](respondWithResult(_0x797c8b,null))[_0x7aaf('0x45')](handleError(_0x797c8b,null));};exports['create']=function(_0x5e82f0,_0x18ef77){return db[_0x7aaf('0x2b')]['create'](_0x5e82f0[_0x7aaf('0x48')],{})[_0x7aaf('0x25')](respondWithResult(_0x18ef77,0xc9))[_0x7aaf('0x45')](handleError(_0x18ef77,null));};exports[_0x7aaf('0x24')]=function(_0x150701,_0x3c19da){if(_0x150701[_0x7aaf('0x48')]['id']){delete _0x150701[_0x7aaf('0x48')]['id'];}return db[_0x7aaf('0x2b')][_0x7aaf('0x49')]({'where':{'id':_0x150701['params']['id']}})[_0x7aaf('0x25')](handleEntityNotFound(_0x3c19da,null))[_0x7aaf('0x25')](saveUpdates(_0x150701[_0x7aaf('0x48')],null))[_0x7aaf('0x25')](respondWithResult(_0x3c19da,null))[_0x7aaf('0x45')](handleError(_0x3c19da,null));};exports[_0x7aaf('0x4a')]=function(_0x2ac9ce,_0x10c8f7,_0x972aa4){var _0x286c20=require('../../components/encryptor');var _0x419c0c=![];var _0x372060={};if(_0x2ac9ce[_0x7aaf('0x2f')][_0x7aaf('0x2d')]&&_0x2ac9ce[_0x7aaf('0x2f')]['type']===_0x7aaf('0x4b')){_0x372060[_0x7aaf('0x4b')]=_0x2ac9ce[_0x7aaf('0x47')]['id'];}else{_0x372060['id']=_0x2ac9ce[_0x7aaf('0x47')]['id'];}return db[_0x7aaf('0x2b')][_0x7aaf('0x49')]({'where':_0x372060,'attributes':['id',_0x7aaf('0x4c'),_0x7aaf('0x4d')],'raw':!![]})[_0x7aaf('0x25')](handleEntityNotFound(_0x10c8f7,null))[_0x7aaf('0x25')](function(_0x2f6b19){if(_0x2f6b19){var _0x93a1cf=_0x2f6b19['savePath'];var _0x5e15fa=util[_0x7aaf('0x4e')](_0x7aaf('0x4f'),_0x93a1cf);if(fs[_0x7aaf('0x50')](_0x5e15fa)){_0x419c0c=!![];return _0x286c20[_0x7aaf('0x51')](_0x5e15fa,_0x93a1cf,config[_0x7aaf('0x52')][_0x7aaf('0x53')])[_0x7aaf('0x25')](function(){return _0x2f6b19;});}return _0x2f6b19;}})[_0x7aaf('0x25')](function(_0x2b8839){if(_0x2b8839){var _0x17dd45=_0x2b8839[_0x7aaf('0x4c')];if(!fs['existsSync'](_0x17dd45)){throw new db[(_0x7aaf('0x54'))][(_0x7aaf('0x55'))](_0x7aaf('0x56'));}if(_0x2b8839[_0x7aaf('0x4d')]){return _0x10c8f7[_0x7aaf('0x4a')](_0x17dd45,_0x2b8839[_0x7aaf('0x4d')]+path[_0x7aaf('0x57')](_0x17dd45),function(){if(_0x419c0c){fs[_0x7aaf('0x58')](_0x17dd45);}});}else{return _0x10c8f7['download'](_0x17dd45,function(_0x15a449){if(_0x419c0c){fs[_0x7aaf('0x58')](_0x17dd45);}});}}})[_0x7aaf('0x45')](function(_0x55af1d){if(_0x55af1d[_0x7aaf('0x59')]===_0x7aaf('0x56')){_0x10c8f7[_0x7aaf('0x1a')](0x194)[_0x7aaf('0x5a')](_0x7aaf('0x5b'));}else{return handleError(_0x10c8f7,null);}});};exports[_0x7aaf('0x26')]=function(_0x4a658f,_0x1f6f5b){return db[_0x7aaf('0x2b')][_0x7aaf('0x49')]({'where':{'id':_0x4a658f[_0x7aaf('0x47')]['id']}})[_0x7aaf('0x25')](function(_0x4996c6){if(!_0x4996c6)throw new ReferenceError(_0x7aaf('0x5c'));return _0x4996c6;})[_0x7aaf('0x25')](function(_0x49a193){var _0x12ed98=_0x49a193['savePath'];logger[_0x7aaf('0x5d')](_0x7aaf('0x5e'),_0x12ed98);if(!_[_0x7aaf('0x5f')](_0x49a193[_0x7aaf('0x4c')])&&fs['existsSync'](_0x12ed98)){logger[_0x7aaf('0x5d')]('File:\x20\x22'+_0x12ed98+_0x7aaf('0x60'));fs[_0x7aaf('0x61')](_0x12ed98);}_0x12ed98=_0x12ed98+_0x7aaf('0x62');if(!_['isNil'](_0x49a193[_0x7aaf('0x4c')])&&fs['existsSync'](_0x12ed98)){logger[_0x7aaf('0x5d')]('File:\x20\x22'+_0x12ed98+_0x7aaf('0x60'));fs['unlinkSync'](_0x12ed98);}return _0x49a193;})[_0x7aaf('0x25')](function(_0x12739a){if(!_0x12739a)throw new InternalError();return _0x12739a[_0x7aaf('0x26')]();})[_0x7aaf('0x25')](function(){_0x1f6f5b[_0x7aaf('0x1a')](0xcc)[_0x7aaf('0x1b')]();})[_0x7aaf('0x45')](handleError(_0x1f6f5b,null));};