Built motion from commit (unavailable).|2.5.5
[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 _0xfc3d=['api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','save','update','then','error','stack','send','index','map','IntegrationReport','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','filter','merge','VIRTUAL','options','count','includeAll','rows','catch','params','include','find','create','body','destroy','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger'];(function(_0x3f5e81,_0x4555ba){var _0x3b4997=function(_0x1004a2){while(--_0x1004a2){_0x3f5e81['push'](_0x3f5e81['shift']());}};_0x3b4997(++_0x4555ba);}(_0xfc3d,0xc3));var _0xdfc3=function(_0x22cfd3,_0x9b3cab){_0x22cfd3=_0x22cfd3-0x0;var _0x4bdb73=_0xfc3d[_0x22cfd3];return _0x4bdb73;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xdfc3('0x0'));var rimraf=require(_0xdfc3('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xdfc3('0x2'));var rp=require(_0xdfc3('0x3'));var moment=require(_0xdfc3('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xdfc3('0x5'));var util=require('util');var path=require(_0xdfc3('0x6'));var sox=require(_0xdfc3('0x7'));var csv=require(_0xdfc3('0x8'));var ejs=require(_0xdfc3('0x9'));var fs=require('fs');var _=require(_0xdfc3('0xa'));var squel=require(_0xdfc3('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xdfc3('0xc'));var toCsv=require(_0xdfc3('0x8'));var querystring=require('querystring');var Papa=require(_0xdfc3('0xd'));var Redis=require('ioredis');var authService=require(_0xdfc3('0xe'));var qs=require(_0xdfc3('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xdfc3('0x10'));var logger=require(_0xdfc3('0x11'))(_0xdfc3('0x12'));var utils=require(_0xdfc3('0x13'));var config=require(_0xdfc3('0x14'));var licenseUtil=require(_0xdfc3('0x15'));var db=require(_0xdfc3('0x16'))['db'];function respondWithStatusCode(_0x5b7d18,_0x307c18){_0x307c18=_0x307c18||0xcc;return function(_0x533078){if(_0x533078){return _0x5b7d18[_0xdfc3('0x17')](_0x307c18);}return _0x5b7d18[_0xdfc3('0x18')](_0x307c18)[_0xdfc3('0x19')]();};}function respondWithResult(_0x30a41a,_0x4f77db){_0x4f77db=_0x4f77db||0xc8;return function(_0x2b97fb){if(_0x2b97fb){return _0x30a41a[_0xdfc3('0x18')](_0x4f77db)[_0xdfc3('0x1a')](_0x2b97fb);}};}function respondWithFilteredResult(_0x3e174d,_0x3c1976){return function(_0xd3cce0){if(_0xd3cce0){var _0xe01b6d=_0xd3cce0['count'],_0x74934c=_0x3c1976[_0xdfc3('0x1b')],_0x127cb7=_0x3c1976[_0xdfc3('0x1b')]+_0x3c1976[_0xdfc3('0x1c')],_0x15cf68;if(_0x127cb7>=_0xe01b6d){_0x127cb7=_0xe01b6d;_0x15cf68=0xc8;}else{_0x15cf68=0xce;}_0x3e174d['status'](_0x15cf68);return _0x3e174d[_0xdfc3('0x1d')](_0xdfc3('0x1e'),_0x74934c+'-'+_0x127cb7+'/'+_0xe01b6d)[_0xdfc3('0x1a')](_0xd3cce0);}return null;};}function patchUpdates(_0x3593b8){return function(_0x593228){try{jsonpatch[_0xdfc3('0x1f')](_0x593228,_0x3593b8,!![]);}catch(_0x2ff5eb){return BPromise['reject'](_0x2ff5eb);}return _0x593228[_0xdfc3('0x20')]();};}function saveUpdates(_0xb456ab,_0x5450ea){return function(_0x395ddc){if(_0x395ddc){return _0x395ddc[_0xdfc3('0x21')](_0xb456ab)['then'](function(_0x499255){return _0x499255;});}return null;};}function removeEntity(_0x2a026c,_0x200f94){return function(_0xfde286){if(_0xfde286){return _0xfde286['destroy']()[_0xdfc3('0x22')](function(){_0x2a026c[_0xdfc3('0x18')](0xcc)[_0xdfc3('0x19')]();});}};}function handleEntityNotFound(_0x5a67c6,_0x52aecb){return function(_0x3754b7){if(!_0x3754b7){_0x5a67c6['sendStatus'](0x194);}return _0x3754b7;};}function handleError(_0x57993d,_0x39c103){_0x39c103=_0x39c103||0x1f4;return function(_0x478230){logger[_0xdfc3('0x23')](_0x478230[_0xdfc3('0x24')]);if(_0x478230['name']){delete _0x478230['name'];}_0x57993d[_0xdfc3('0x18')](_0x39c103)[_0xdfc3('0x25')](_0x478230);};}exports[_0xdfc3('0x26')]=function(_0x3f2017,_0x5af10c){var _0x43a9e9={},_0x5bfb78={},_0x46e556={'count':0x0,'rows':[]};var _0x379f40=_[_0xdfc3('0x27')](db[_0xdfc3('0x28')]['rawAttributes'],function(_0x554866){return{'name':_0x554866[_0xdfc3('0x29')],'type':_0x554866[_0xdfc3('0x2a')][_0xdfc3('0x2b')]};});_0x5bfb78[_0xdfc3('0x2c')]=_[_0xdfc3('0x27')](_0x379f40,'name');_0x5bfb78[_0xdfc3('0x2d')]=_[_0xdfc3('0x2e')](_0x3f2017[_0xdfc3('0x2d')]);_0x5bfb78[_0xdfc3('0x2f')]=_[_0xdfc3('0x30')](_0x5bfb78[_0xdfc3('0x2c')],_0x5bfb78[_0xdfc3('0x2d')]);_0x43a9e9[_0xdfc3('0x31')]=_['intersection'](_0x5bfb78['model'],qs[_0xdfc3('0x32')](_0x3f2017[_0xdfc3('0x2d')][_0xdfc3('0x32')]));_0x43a9e9['attributes']=_0x43a9e9[_0xdfc3('0x31')][_0xdfc3('0x33')]?_0x43a9e9[_0xdfc3('0x31')]:_0x5bfb78[_0xdfc3('0x2c')];if(!_0x3f2017[_0xdfc3('0x2d')]['hasOwnProperty'](_0xdfc3('0x34'))){_0x43a9e9['limit']=qs[_0xdfc3('0x1c')](_0x3f2017['query'][_0xdfc3('0x1c')]);_0x43a9e9[_0xdfc3('0x1b')]=qs[_0xdfc3('0x1b')](_0x3f2017[_0xdfc3('0x2d')][_0xdfc3('0x1b')]);}_0x43a9e9[_0xdfc3('0x35')]=qs[_0xdfc3('0x36')](_0x3f2017['query'][_0xdfc3('0x36')]);_0x43a9e9[_0xdfc3('0x37')]=qs['filters'](_['pick'](_0x3f2017['query'],_0x5bfb78[_0xdfc3('0x2f')]),_0x379f40);if(_0x3f2017[_0xdfc3('0x2d')][_0xdfc3('0x38')]){_0x43a9e9[_0xdfc3('0x37')]=_[_0xdfc3('0x39')](_0x43a9e9[_0xdfc3('0x37')],{'$or':_['map'](_0x379f40,function(_0xd505b6){if(_0xd505b6[_0xdfc3('0x2a')]!==_0xdfc3('0x3a')){var _0x3b8c8={};_0x3b8c8[_0xd505b6['name']]={'$like':'%'+_0x3f2017[_0xdfc3('0x2d')][_0xdfc3('0x38')]+'%'};return _0x3b8c8;}})});}_0x43a9e9=_[_0xdfc3('0x39')]({},_0x43a9e9,_0x3f2017[_0xdfc3('0x3b')]);var _0x1d40ce={'where':_0x43a9e9[_0xdfc3('0x37')]};return db[_0xdfc3('0x28')]['count'](_0x1d40ce)[_0xdfc3('0x22')](function(_0x589a1d){_0x46e556[_0xdfc3('0x3c')]=_0x589a1d;if(_0x3f2017['query'][_0xdfc3('0x3d')]){_0x43a9e9['include']=[{'all':!![]}];}return db[_0xdfc3('0x28')]['findAll'](_0x43a9e9);})[_0xdfc3('0x22')](function(_0x34b459){_0x46e556[_0xdfc3('0x3e')]=_0x34b459;return _0x46e556;})[_0xdfc3('0x22')](respondWithFilteredResult(_0x5af10c,_0x43a9e9))[_0xdfc3('0x3f')](handleError(_0x5af10c,null));};exports['show']=function(_0x518a94,_0x13fb7c){var _0x559893={'raw':![],'where':{'id':_0x518a94[_0xdfc3('0x40')]['id']}},_0x53c948={};_0x53c948[_0xdfc3('0x2c')]=_[_0xdfc3('0x2e')](db[_0xdfc3('0x28')]['rawAttributes']);_0x53c948[_0xdfc3('0x2d')]=_[_0xdfc3('0x2e')](_0x518a94[_0xdfc3('0x2d')]);_0x53c948['filters']=_['intersection'](_0x53c948[_0xdfc3('0x2c')],_0x53c948[_0xdfc3('0x2d')]);_0x559893[_0xdfc3('0x31')]=_['intersection'](_0x53c948['model'],qs[_0xdfc3('0x32')](_0x518a94['query'][_0xdfc3('0x32')]));_0x559893[_0xdfc3('0x31')]=_0x559893['attributes'][_0xdfc3('0x33')]?_0x559893['attributes']:_0x53c948[_0xdfc3('0x2c')];if(_0x518a94['query'][_0xdfc3('0x3d')]){_0x559893[_0xdfc3('0x41')]=[{'all':!![]}];}_0x559893=_[_0xdfc3('0x39')]({},_0x559893,_0x518a94[_0xdfc3('0x3b')]);return db['IntegrationReport'][_0xdfc3('0x42')](_0x559893)[_0xdfc3('0x22')](handleEntityNotFound(_0x13fb7c,null))[_0xdfc3('0x22')](respondWithResult(_0x13fb7c,null))[_0xdfc3('0x3f')](handleError(_0x13fb7c,null));};exports[_0xdfc3('0x43')]=function(_0x28f4e2,_0x5e7618){return db[_0xdfc3('0x28')][_0xdfc3('0x43')](_0x28f4e2[_0xdfc3('0x44')],{})[_0xdfc3('0x22')](respondWithResult(_0x5e7618,0xc9))['catch'](handleError(_0x5e7618,null));};exports[_0xdfc3('0x21')]=function(_0x537532,_0x4db5b8){if(_0x537532[_0xdfc3('0x44')]['id']){delete _0x537532[_0xdfc3('0x44')]['id'];}return db['IntegrationReport'][_0xdfc3('0x42')]({'where':{'id':_0x537532['params']['id']}})[_0xdfc3('0x22')](handleEntityNotFound(_0x4db5b8,null))[_0xdfc3('0x22')](saveUpdates(_0x537532[_0xdfc3('0x44')],null))['then'](respondWithResult(_0x4db5b8,null))[_0xdfc3('0x3f')](handleError(_0x4db5b8,null));};exports[_0xdfc3('0x45')]=function(_0x5a45e1,_0x1bc0b8){return db['IntegrationReport'][_0xdfc3('0x42')]({'where':{'id':_0x5a45e1['params']['id']}})['then'](handleEntityNotFound(_0x1bc0b8,null))[_0xdfc3('0x22')](removeEntity(_0x1bc0b8,null))['catch'](handleError(_0x1bc0b8,null));};exports[_0xdfc3('0x46')]=function(_0x4fc9d9,_0x2ac429){return db['IntegrationReport'][_0xdfc3('0x46')]()[_0xdfc3('0x22')](respondWithResult(_0x2ac429,null))['catch'](handleError(_0x2ac429,null));};