Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / integrationReport / integrationReport.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 _0xb569=['destroy','end','stack','name','index','map','rawAttributes','fieldName','type','query','filters','model','attributes','fields','sort','where','pick','merge','filter','options','IntegrationReport','includeAll','include','findAll','catch','show','keys','intersection','length','find','create','body','params','describe','zip-dir','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then'];(function(_0x25ac87,_0x3ceaa1){var _0x5d69aa=function(_0x217908){while(--_0x217908){_0x25ac87['push'](_0x25ac87['shift']());}};_0x5d69aa(++_0x3ceaa1);}(_0xb569,0x185));var _0x9b56=function(_0x4a6b41,_0x408a77){_0x4a6b41=_0x4a6b41-0x0;var _0x16d22b=_0xb569[_0x4a6b41];return _0x16d22b;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x9b56('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9b56('0x1'));var moment=require(_0x9b56('0x2'));var BPromise=require('bluebird');var Mustache=require(_0x9b56('0x3'));var util=require(_0x9b56('0x4'));var path=require(_0x9b56('0x5'));var sox=require(_0x9b56('0x6'));var csv=require(_0x9b56('0x7'));var ejs=require(_0x9b56('0x8'));var fs=require('fs');var fs_extra=require(_0x9b56('0x9'));var _=require('lodash');var squel=require(_0x9b56('0xa'));var crypto=require(_0x9b56('0xb'));var jsforce=require(_0x9b56('0xc'));var deskjs=require(_0x9b56('0xd'));var toCsv=require(_0x9b56('0x7'));var querystring=require('querystring');var Papa=require(_0x9b56('0xe'));var Redis=require(_0x9b56('0xf'));var authService=require(_0x9b56('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x9b56('0x11'));var hardwareService=require(_0x9b56('0x12'));var logger=require(_0x9b56('0x13'))(_0x9b56('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x9b56('0x15'));var db=require(_0x9b56('0x16'))['db'];function respondWithStatusCode(_0x17290c,_0x755ea5){_0x755ea5=_0x755ea5||0xcc;return function(_0x387d3f){if(_0x387d3f){return _0x17290c[_0x9b56('0x17')](_0x755ea5);}return _0x17290c[_0x9b56('0x18')](_0x755ea5)['end']();};}function respondWithResult(_0x3b9477,_0x145012){_0x145012=_0x145012||0xc8;return function(_0x42bcd2){if(_0x42bcd2){return _0x3b9477['status'](_0x145012)[_0x9b56('0x19')](_0x42bcd2);}};}function respondWithFilteredResult(_0x18e0bc,_0x299829){return function(_0x560cb7){if(_0x560cb7){var _0x174a43=typeof _0x299829[_0x9b56('0x1a')]===_0x9b56('0x1b')&&typeof _0x299829[_0x9b56('0x1c')]===_0x9b56('0x1b');var _0x2f0bfc=_0x560cb7[_0x9b56('0x1d')];var _0x195745=_0x174a43?0x0:_0x299829[_0x9b56('0x1a')];var _0x53d5e2=_0x174a43?_0x560cb7[_0x9b56('0x1d')]:_0x299829[_0x9b56('0x1a')]+_0x299829[_0x9b56('0x1c')];var _0x1d5c7a;if(_0x53d5e2>=_0x2f0bfc){_0x53d5e2=_0x2f0bfc;_0x1d5c7a=0xc8;}else{_0x1d5c7a=0xce;}_0x18e0bc[_0x9b56('0x18')](_0x1d5c7a);return _0x18e0bc[_0x9b56('0x1e')](_0x9b56('0x1f'),_0x195745+'-'+_0x53d5e2+'/'+_0x2f0bfc)[_0x9b56('0x19')](_0x560cb7);}return null;};}function patchUpdates(_0x5bec88){return function(_0x3a6771){try{jsonpatch[_0x9b56('0x20')](_0x3a6771,_0x5bec88,!![]);}catch(_0x167852){return BPromise[_0x9b56('0x21')](_0x167852);}return _0x3a6771[_0x9b56('0x22')]();};}function saveUpdates(_0x4be0df,_0x3cf5d9){return function(_0x55ceae){if(_0x55ceae){return _0x55ceae[_0x9b56('0x23')](_0x4be0df)[_0x9b56('0x24')](function(_0x1a78bf){return _0x1a78bf;});}return null;};}function removeEntity(_0x33f7e4,_0x5255b8){return function(_0x4fd605){if(_0x4fd605){return _0x4fd605[_0x9b56('0x25')]()[_0x9b56('0x24')](function(){_0x33f7e4[_0x9b56('0x18')](0xcc)[_0x9b56('0x26')]();});}};}function handleEntityNotFound(_0xa13fa4,_0x13f202){return function(_0x4c571f){if(!_0x4c571f){_0xa13fa4[_0x9b56('0x17')](0x194);}return _0x4c571f;};}function handleError(_0x53ac5b,_0x496ce5){_0x496ce5=_0x496ce5||0x1f4;return function(_0x2c705a){logger['error'](_0x2c705a[_0x9b56('0x27')]);if(_0x2c705a[_0x9b56('0x28')]){delete _0x2c705a[_0x9b56('0x28')];}_0x53ac5b[_0x9b56('0x18')](_0x496ce5)['send'](_0x2c705a);};}exports[_0x9b56('0x29')]=function(_0x3085b4,_0xa5a79){var _0xaffab9={},_0x4302be={},_0x1380c5={'count':0x0,'rows':[]};var _0x5862dc=_[_0x9b56('0x2a')](db['IntegrationReport'][_0x9b56('0x2b')],function(_0x43f843){return{'name':_0x43f843[_0x9b56('0x2c')],'type':_0x43f843[_0x9b56('0x2d')]['key']};});_0x4302be['model']=_[_0x9b56('0x2a')](_0x5862dc,'name');_0x4302be['query']=_['keys'](_0x3085b4[_0x9b56('0x2e')]);_0x4302be[_0x9b56('0x2f')]=_['intersection'](_0x4302be[_0x9b56('0x30')],_0x4302be['query']);_0xaffab9[_0x9b56('0x31')]=_['intersection'](_0x4302be[_0x9b56('0x30')],qs[_0x9b56('0x32')](_0x3085b4['query'][_0x9b56('0x32')]));_0xaffab9[_0x9b56('0x31')]=_0xaffab9[_0x9b56('0x31')]['length']?_0xaffab9[_0x9b56('0x31')]:_0x4302be['model'];if(!_0x3085b4['query']['hasOwnProperty']('nolimit')){_0xaffab9[_0x9b56('0x1c')]=qs['limit'](_0x3085b4[_0x9b56('0x2e')][_0x9b56('0x1c')]);_0xaffab9[_0x9b56('0x1a')]=qs[_0x9b56('0x1a')](_0x3085b4['query'][_0x9b56('0x1a')]);}_0xaffab9['order']=qs[_0x9b56('0x33')](_0x3085b4[_0x9b56('0x2e')][_0x9b56('0x33')]);_0xaffab9[_0x9b56('0x34')]=qs[_0x9b56('0x2f')](_[_0x9b56('0x35')](_0x3085b4[_0x9b56('0x2e')],_0x4302be[_0x9b56('0x2f')]),_0x5862dc);if(_0x3085b4['query']['filter']){_0xaffab9[_0x9b56('0x34')]=_[_0x9b56('0x36')](_0xaffab9['where'],{'$or':_['map'](_0x5862dc,function(_0x29cbe5){if(_0x29cbe5[_0x9b56('0x2d')]!=='VIRTUAL'){var _0x5c4a95={};_0x5c4a95[_0x29cbe5['name']]={'$like':'%'+_0x3085b4[_0x9b56('0x2e')][_0x9b56('0x37')]+'%'};return _0x5c4a95;}})});}_0xaffab9=_[_0x9b56('0x36')]({},_0xaffab9,_0x3085b4[_0x9b56('0x38')]);var _0x586cc2={'where':_0xaffab9[_0x9b56('0x34')]};return db[_0x9b56('0x39')][_0x9b56('0x1d')](_0x586cc2)[_0x9b56('0x24')](function(_0x2401f6){_0x1380c5[_0x9b56('0x1d')]=_0x2401f6;if(_0x3085b4[_0x9b56('0x2e')][_0x9b56('0x3a')]){_0xaffab9[_0x9b56('0x3b')]=[{'all':!![]}];}return db[_0x9b56('0x39')][_0x9b56('0x3c')](_0xaffab9);})[_0x9b56('0x24')](function(_0x4d5cfc){_0x1380c5['rows']=_0x4d5cfc;return _0x1380c5;})[_0x9b56('0x24')](respondWithFilteredResult(_0xa5a79,_0xaffab9))[_0x9b56('0x3d')](handleError(_0xa5a79,null));};exports[_0x9b56('0x3e')]=function(_0x2f157b,_0x4312be){var _0x30caec={'raw':![],'where':{'id':_0x2f157b['params']['id']}},_0x45a9a7={};_0x45a9a7[_0x9b56('0x30')]=_[_0x9b56('0x3f')](db[_0x9b56('0x39')][_0x9b56('0x2b')]);_0x45a9a7[_0x9b56('0x2e')]=_[_0x9b56('0x3f')](_0x2f157b['query']);_0x45a9a7[_0x9b56('0x2f')]=_['intersection'](_0x45a9a7[_0x9b56('0x30')],_0x45a9a7['query']);_0x30caec[_0x9b56('0x31')]=_[_0x9b56('0x40')](_0x45a9a7[_0x9b56('0x30')],qs[_0x9b56('0x32')](_0x2f157b[_0x9b56('0x2e')]['fields']));_0x30caec[_0x9b56('0x31')]=_0x30caec['attributes'][_0x9b56('0x41')]?_0x30caec['attributes']:_0x45a9a7[_0x9b56('0x30')];if(_0x2f157b[_0x9b56('0x2e')][_0x9b56('0x3a')]){_0x30caec['include']=[{'all':!![]}];}_0x30caec=_[_0x9b56('0x36')]({},_0x30caec,_0x2f157b['options']);return db[_0x9b56('0x39')][_0x9b56('0x42')](_0x30caec)[_0x9b56('0x24')](handleEntityNotFound(_0x4312be,null))[_0x9b56('0x24')](respondWithResult(_0x4312be,null))[_0x9b56('0x3d')](handleError(_0x4312be,null));};exports[_0x9b56('0x43')]=function(_0x45bf88,_0x31cfc3){return db['IntegrationReport'][_0x9b56('0x43')](_0x45bf88[_0x9b56('0x44')],{})[_0x9b56('0x24')](respondWithResult(_0x31cfc3,0xc9))['catch'](handleError(_0x31cfc3,null));};exports[_0x9b56('0x23')]=function(_0xed2dfc,_0x59e810){if(_0xed2dfc[_0x9b56('0x44')]['id']){delete _0xed2dfc[_0x9b56('0x44')]['id'];}return db['IntegrationReport'][_0x9b56('0x42')]({'where':{'id':_0xed2dfc[_0x9b56('0x45')]['id']}})[_0x9b56('0x24')](handleEntityNotFound(_0x59e810,null))['then'](saveUpdates(_0xed2dfc[_0x9b56('0x44')],null))[_0x9b56('0x24')](respondWithResult(_0x59e810,null))[_0x9b56('0x3d')](handleError(_0x59e810,null));};exports[_0x9b56('0x25')]=function(_0x105c89,_0x293841){return db[_0x9b56('0x39')][_0x9b56('0x42')]({'where':{'id':_0x105c89[_0x9b56('0x45')]['id']}})[_0x9b56('0x24')](handleEntityNotFound(_0x293841,null))[_0x9b56('0x24')](removeEntity(_0x293841,null))['catch'](handleError(_0x293841,null));};exports[_0x9b56('0x46')]=function(_0x32410f,_0x263148){return db[_0x9b56('0x39')][_0x9b56('0x46')]()['then'](respondWithResult(_0x263148,null))[_0x9b56('0x3d')](handleError(_0x263148,null));};