Built motion from commit (unavailable).|2.5.11
[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 _0xb928=['destroy','stack','name','send','map','IntegrationReport','fieldName','type','key','model','query','keys','filters','intersection','attributes','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','then','include','findAll','rows','catch','show','params','rawAttributes','fields','length','includeAll','find','body','update','describe','html-pdf','eml-format','fast-json-patch','request-promise','moment','bluebird','util','path','lodash','squel','crypto','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save'];(function(_0x53c9aa,_0x4cca69){var _0x438826=function(_0x2357d1){while(--_0x2357d1){_0x53c9aa['push'](_0x53c9aa['shift']());}};_0x438826(++_0x4cca69);}(_0xb928,0xb0));var _0x8b92=function(_0x4551f6,_0x48151b){_0x4551f6=_0x4551f6-0x0;var _0x581dc2=_0xb928[_0x4551f6];return _0x581dc2;};'use strict';var pdf=require(_0x8b92('0x0'));var emlformat=require(_0x8b92('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x8b92('0x2'));var rp=require(_0x8b92('0x3'));var moment=require(_0x8b92('0x4'));var BPromise=require(_0x8b92('0x5'));var Mustache=require('mustache');var util=require(_0x8b92('0x6'));var path=require(_0x8b92('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x8b92('0x8'));var squel=require(_0x8b92('0x9'));var crypto=require(_0x8b92('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x8b92('0xb'));var Redis=require('ioredis');var authService=require(_0x8b92('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0x8b92('0xd'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x8b92('0xe'));var utils=require(_0x8b92('0xf'));var config=require(_0x8b92('0x10'));var licenseUtil=require(_0x8b92('0x11'));var db=require(_0x8b92('0x12'))['db'];function respondWithStatusCode(_0x1b2111,_0x3cf8ae){_0x3cf8ae=_0x3cf8ae||0xcc;return function(_0x37fb6a){if(_0x37fb6a){return _0x1b2111[_0x8b92('0x13')](_0x3cf8ae);}return _0x1b2111[_0x8b92('0x14')](_0x3cf8ae)[_0x8b92('0x15')]();};}function respondWithResult(_0x465d94,_0x46a0e5){_0x46a0e5=_0x46a0e5||0xc8;return function(_0x257f3d){if(_0x257f3d){return _0x465d94[_0x8b92('0x14')](_0x46a0e5)[_0x8b92('0x16')](_0x257f3d);}};}function respondWithFilteredResult(_0x21457f,_0x1d88c5){return function(_0xf915ca){if(_0xf915ca){var _0xfece68=_0xf915ca[_0x8b92('0x17')],_0x10b23f=_0x1d88c5[_0x8b92('0x18')],_0x3647af=_0x1d88c5[_0x8b92('0x18')]+_0x1d88c5[_0x8b92('0x19')],_0x27e17d;if(_0x3647af>=_0xfece68){_0x3647af=_0xfece68;_0x27e17d=0xc8;}else{_0x27e17d=0xce;}_0x21457f['status'](_0x27e17d);return _0x21457f[_0x8b92('0x1a')](_0x8b92('0x1b'),_0x10b23f+'-'+_0x3647af+'/'+_0xfece68)[_0x8b92('0x16')](_0xf915ca);}return null;};}function patchUpdates(_0x351928){return function(_0x7b63fd){try{jsonpatch[_0x8b92('0x1c')](_0x7b63fd,_0x351928,!![]);}catch(_0x520b0f){return BPromise[_0x8b92('0x1d')](_0x520b0f);}return _0x7b63fd[_0x8b92('0x1e')]();};}function saveUpdates(_0x26603a,_0x5f1df3){return function(_0x13dcdb){if(_0x13dcdb){return _0x13dcdb['update'](_0x26603a)['then'](function(_0x38511e){return _0x38511e;});}return null;};}function removeEntity(_0x5d3c18,_0x34c4a4){return function(_0x3f7986){if(_0x3f7986){return _0x3f7986[_0x8b92('0x1f')]()['then'](function(){_0x5d3c18[_0x8b92('0x14')](0xcc)[_0x8b92('0x15')]();});}};}function handleEntityNotFound(_0x33e83c,_0x5db2e4){return function(_0x12b069){if(!_0x12b069){_0x33e83c['sendStatus'](0x194);}return _0x12b069;};}function handleError(_0x478428,_0x507b97){_0x507b97=_0x507b97||0x1f4;return function(_0x3d0f95){logger['error'](_0x3d0f95[_0x8b92('0x20')]);if(_0x3d0f95[_0x8b92('0x21')]){delete _0x3d0f95['name'];}_0x478428[_0x8b92('0x14')](_0x507b97)[_0x8b92('0x22')](_0x3d0f95);};}exports['index']=function(_0x30aeba,_0xb73fbe){var _0x25dd68={},_0x614882={},_0xc06c43={'count':0x0,'rows':[]};var _0x568781=_[_0x8b92('0x23')](db[_0x8b92('0x24')]['rawAttributes'],function(_0x48e4a1){return{'name':_0x48e4a1[_0x8b92('0x25')],'type':_0x48e4a1[_0x8b92('0x26')][_0x8b92('0x27')]};});_0x614882[_0x8b92('0x28')]=_['map'](_0x568781,_0x8b92('0x21'));_0x614882[_0x8b92('0x29')]=_[_0x8b92('0x2a')](_0x30aeba[_0x8b92('0x29')]);_0x614882[_0x8b92('0x2b')]=_[_0x8b92('0x2c')](_0x614882['model'],_0x614882['query']);_0x25dd68['attributes']=_['intersection'](_0x614882[_0x8b92('0x28')],qs['fields'](_0x30aeba[_0x8b92('0x29')]['fields']));_0x25dd68[_0x8b92('0x2d')]=_0x25dd68[_0x8b92('0x2d')]['length']?_0x25dd68[_0x8b92('0x2d')]:_0x614882[_0x8b92('0x28')];if(!_0x30aeba[_0x8b92('0x29')][_0x8b92('0x2e')](_0x8b92('0x2f'))){_0x25dd68[_0x8b92('0x19')]=qs[_0x8b92('0x19')](_0x30aeba[_0x8b92('0x29')][_0x8b92('0x19')]);_0x25dd68[_0x8b92('0x18')]=qs[_0x8b92('0x18')](_0x30aeba['query'][_0x8b92('0x18')]);}_0x25dd68[_0x8b92('0x30')]=qs[_0x8b92('0x31')](_0x30aeba[_0x8b92('0x29')][_0x8b92('0x31')]);_0x25dd68[_0x8b92('0x32')]=qs[_0x8b92('0x2b')](_[_0x8b92('0x33')](_0x30aeba[_0x8b92('0x29')],_0x614882[_0x8b92('0x2b')]),_0x568781);if(_0x30aeba[_0x8b92('0x29')]['filter']){_0x25dd68[_0x8b92('0x32')]=_[_0x8b92('0x34')](_0x25dd68['where'],{'$or':_[_0x8b92('0x23')](_0x568781,function(_0x344174){if(_0x344174[_0x8b92('0x26')]!==_0x8b92('0x35')){var _0x3f5842={};_0x3f5842[_0x344174[_0x8b92('0x21')]]={'$like':'%'+_0x30aeba[_0x8b92('0x29')]['filter']+'%'};return _0x3f5842;}})});}_0x25dd68=_['merge']({},_0x25dd68,_0x30aeba['options']);var _0x1b3ff5={'where':_0x25dd68[_0x8b92('0x32')]};return db[_0x8b92('0x24')]['count'](_0x1b3ff5)[_0x8b92('0x36')](function(_0x2953b7){_0xc06c43[_0x8b92('0x17')]=_0x2953b7;if(_0x30aeba[_0x8b92('0x29')]['includeAll']){_0x25dd68[_0x8b92('0x37')]=[{'all':!![]}];}return db[_0x8b92('0x24')][_0x8b92('0x38')](_0x25dd68);})['then'](function(_0xc13cd1){_0xc06c43[_0x8b92('0x39')]=_0xc13cd1;return _0xc06c43;})[_0x8b92('0x36')](respondWithFilteredResult(_0xb73fbe,_0x25dd68))[_0x8b92('0x3a')](handleError(_0xb73fbe,null));};exports[_0x8b92('0x3b')]=function(_0x2c929f,_0x1be39f){var _0x3b8877={'raw':![],'where':{'id':_0x2c929f[_0x8b92('0x3c')]['id']}},_0x1433f3={};_0x1433f3[_0x8b92('0x28')]=_[_0x8b92('0x2a')](db['IntegrationReport'][_0x8b92('0x3d')]);_0x1433f3[_0x8b92('0x29')]=_[_0x8b92('0x2a')](_0x2c929f['query']);_0x1433f3[_0x8b92('0x2b')]=_[_0x8b92('0x2c')](_0x1433f3[_0x8b92('0x28')],_0x1433f3[_0x8b92('0x29')]);_0x3b8877[_0x8b92('0x2d')]=_[_0x8b92('0x2c')](_0x1433f3['model'],qs[_0x8b92('0x3e')](_0x2c929f[_0x8b92('0x29')][_0x8b92('0x3e')]));_0x3b8877[_0x8b92('0x2d')]=_0x3b8877[_0x8b92('0x2d')][_0x8b92('0x3f')]?_0x3b8877[_0x8b92('0x2d')]:_0x1433f3[_0x8b92('0x28')];if(_0x2c929f[_0x8b92('0x29')][_0x8b92('0x40')]){_0x3b8877[_0x8b92('0x37')]=[{'all':!![]}];}_0x3b8877=_[_0x8b92('0x34')]({},_0x3b8877,_0x2c929f['options']);return db[_0x8b92('0x24')][_0x8b92('0x41')](_0x3b8877)[_0x8b92('0x36')](handleEntityNotFound(_0x1be39f,null))[_0x8b92('0x36')](respondWithResult(_0x1be39f,null))['catch'](handleError(_0x1be39f,null));};exports['create']=function(_0x48aac8,_0x2aa8b4){return db[_0x8b92('0x24')]['create'](_0x48aac8[_0x8b92('0x42')],{})[_0x8b92('0x36')](respondWithResult(_0x2aa8b4,0xc9))['catch'](handleError(_0x2aa8b4,null));};exports[_0x8b92('0x43')]=function(_0x597610,_0x59e5aa){if(_0x597610[_0x8b92('0x42')]['id']){delete _0x597610['body']['id'];}return db[_0x8b92('0x24')][_0x8b92('0x41')]({'where':{'id':_0x597610[_0x8b92('0x3c')]['id']}})[_0x8b92('0x36')](handleEntityNotFound(_0x59e5aa,null))['then'](saveUpdates(_0x597610[_0x8b92('0x42')],null))[_0x8b92('0x36')](respondWithResult(_0x59e5aa,null))[_0x8b92('0x3a')](handleError(_0x59e5aa,null));};exports[_0x8b92('0x1f')]=function(_0x2ecee4,_0x46ea44){return db[_0x8b92('0x24')]['find']({'where':{'id':_0x2ecee4['params']['id']}})[_0x8b92('0x36')](handleEntityNotFound(_0x46ea44,null))[_0x8b92('0x36')](removeEntity(_0x46ea44,null))[_0x8b92('0x3a')](handleError(_0x46ea44,null));};exports[_0x8b92('0x44')]=function(_0x164a98,_0x1a5b49){return db['IntegrationReport'][_0x8b92('0x44')]()['then'](respondWithResult(_0x1a5b49,null))[_0x8b92('0x3a')](handleError(_0x1a5b49,null));};