Built motion from commit da617fac.|2.6.6
[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 _0x61fb=['end','json','offset','undefined','count','limit','set','apply','reject','save','then','error','stack','name','send','index','IntegrationReport','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','map','VIRTUAL','merge','includeAll','show','params','include','options','catch','create','find','body','destroy','describe','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','status'];(function(_0x53e999,_0xc7195b){var _0x3fa453=function(_0x5a6b86){while(--_0x5a6b86){_0x53e999['push'](_0x53e999['shift']());}};_0x3fa453(++_0xc7195b);}(_0x61fb,0x1b2));var _0xb61f=function(_0x2b95ae,_0xa0a178){_0x2b95ae=_0x2b95ae-0x0;var _0x36ffbd=_0x61fb[_0x2b95ae];return _0x36ffbd;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb61f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb61f('0x1'));var rp=require(_0xb61f('0x2'));var moment=require(_0xb61f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xb61f('0x4'));var util=require(_0xb61f('0x5'));var path=require(_0xb61f('0x6'));var sox=require(_0xb61f('0x7'));var csv=require(_0xb61f('0x8'));var ejs=require(_0xb61f('0x9'));var fs=require('fs');var fs_extra=require(_0xb61f('0xa'));var _=require(_0xb61f('0xb'));var squel=require(_0xb61f('0xc'));var crypto=require(_0xb61f('0xd'));var jsforce=require(_0xb61f('0xe'));var deskjs=require(_0xb61f('0xf'));var toCsv=require(_0xb61f('0x8'));var querystring=require('querystring');var Papa=require(_0xb61f('0x10'));var Redis=require(_0xb61f('0x11'));var authService=require(_0xb61f('0x12'));var qs=require(_0xb61f('0x13'));var as=require(_0xb61f('0x14'));var hardwareService=require(_0xb61f('0x15'));var logger=require(_0xb61f('0x16'))(_0xb61f('0x17'));var utils=require('../../config/utils');var config=require(_0xb61f('0x18'));var licenseUtil=require(_0xb61f('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3e597c,_0x3fc7a4){_0x3fc7a4=_0x3fc7a4||0xcc;return function(_0x3241de){if(_0x3241de){return _0x3e597c[_0xb61f('0x1a')](_0x3fc7a4);}return _0x3e597c[_0xb61f('0x1b')](_0x3fc7a4)[_0xb61f('0x1c')]();};}function respondWithResult(_0x12ef5e,_0x470c5e){_0x470c5e=_0x470c5e||0xc8;return function(_0xab0c3b){if(_0xab0c3b){return _0x12ef5e['status'](_0x470c5e)[_0xb61f('0x1d')](_0xab0c3b);}};}function respondWithFilteredResult(_0x5e93da,_0x4f340c){return function(_0x1cffcd){if(_0x1cffcd){var _0x364b55=typeof _0x4f340c[_0xb61f('0x1e')]===_0xb61f('0x1f')&&typeof _0x4f340c['limit']==='undefined';var _0x394360=_0x1cffcd[_0xb61f('0x20')];var _0x466385=_0x364b55?0x0:_0x4f340c['offset'];var _0x272024=_0x364b55?_0x1cffcd[_0xb61f('0x20')]:_0x4f340c[_0xb61f('0x1e')]+_0x4f340c[_0xb61f('0x21')];var _0x2ba024;if(_0x272024>=_0x394360){_0x272024=_0x394360;_0x2ba024=0xc8;}else{_0x2ba024=0xce;}_0x5e93da[_0xb61f('0x1b')](_0x2ba024);return _0x5e93da[_0xb61f('0x22')]('Content-Range',_0x466385+'-'+_0x272024+'/'+_0x394360)[_0xb61f('0x1d')](_0x1cffcd);}return null;};}function patchUpdates(_0x2798c6){return function(_0x3609cf){try{jsonpatch[_0xb61f('0x23')](_0x3609cf,_0x2798c6,!![]);}catch(_0x37f7bf){return BPromise[_0xb61f('0x24')](_0x37f7bf);}return _0x3609cf[_0xb61f('0x25')]();};}function saveUpdates(_0x303147,_0x465646){return function(_0x2c81eb){if(_0x2c81eb){return _0x2c81eb['update'](_0x303147)[_0xb61f('0x26')](function(_0x4b0546){return _0x4b0546;});}return null;};}function removeEntity(_0x4bd283,_0x39bbea){return function(_0x5a1679){if(_0x5a1679){return _0x5a1679['destroy']()[_0xb61f('0x26')](function(){_0x4bd283[_0xb61f('0x1b')](0xcc)[_0xb61f('0x1c')]();});}};}function handleEntityNotFound(_0x3a1be8,_0xc58937){return function(_0x482789){if(!_0x482789){_0x3a1be8[_0xb61f('0x1a')](0x194);}return _0x482789;};}function handleError(_0x28cee6,_0x2b2449){_0x2b2449=_0x2b2449||0x1f4;return function(_0x4e8da8){logger[_0xb61f('0x27')](_0x4e8da8[_0xb61f('0x28')]);if(_0x4e8da8[_0xb61f('0x29')]){delete _0x4e8da8[_0xb61f('0x29')];}_0x28cee6[_0xb61f('0x1b')](_0x2b2449)[_0xb61f('0x2a')](_0x4e8da8);};}exports[_0xb61f('0x2b')]=function(_0x9aa4e1,_0x306345){var _0x22f8c8={},_0x1ad1b9={},_0x553c17={'count':0x0,'rows':[]};var _0x42f697=_['map'](db[_0xb61f('0x2c')][_0xb61f('0x2d')],function(_0x2098e0){return{'name':_0x2098e0[_0xb61f('0x2e')],'type':_0x2098e0[_0xb61f('0x2f')][_0xb61f('0x30')]};});_0x1ad1b9[_0xb61f('0x31')]=_['map'](_0x42f697,_0xb61f('0x29'));_0x1ad1b9['query']=_[_0xb61f('0x32')](_0x9aa4e1[_0xb61f('0x33')]);_0x1ad1b9[_0xb61f('0x34')]=_[_0xb61f('0x35')](_0x1ad1b9[_0xb61f('0x31')],_0x1ad1b9[_0xb61f('0x33')]);_0x22f8c8[_0xb61f('0x36')]=_[_0xb61f('0x35')](_0x1ad1b9[_0xb61f('0x31')],qs[_0xb61f('0x37')](_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x37')]));_0x22f8c8['attributes']=_0x22f8c8[_0xb61f('0x36')][_0xb61f('0x38')]?_0x22f8c8[_0xb61f('0x36')]:_0x1ad1b9['model'];if(!_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x39')](_0xb61f('0x3a'))){_0x22f8c8[_0xb61f('0x21')]=qs[_0xb61f('0x21')](_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x21')]);_0x22f8c8[_0xb61f('0x1e')]=qs[_0xb61f('0x1e')](_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x1e')]);}_0x22f8c8[_0xb61f('0x3b')]=qs[_0xb61f('0x3c')](_0x9aa4e1[_0xb61f('0x33')]['sort']);_0x22f8c8[_0xb61f('0x3d')]=qs[_0xb61f('0x34')](_['pick'](_0x9aa4e1['query'],_0x1ad1b9['filters']),_0x42f697);if(_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x3e')]){_0x22f8c8[_0xb61f('0x3d')]=_['merge'](_0x22f8c8[_0xb61f('0x3d')],{'$or':_[_0xb61f('0x3f')](_0x42f697,function(_0x3cc096){if(_0x3cc096[_0xb61f('0x2f')]!==_0xb61f('0x40')){var _0x108da2={};_0x108da2[_0x3cc096['name']]={'$like':'%'+_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x3e')]+'%'};return _0x108da2;}})});}_0x22f8c8=_[_0xb61f('0x41')]({},_0x22f8c8,_0x9aa4e1['options']);var _0x3fb4c4={'where':_0x22f8c8[_0xb61f('0x3d')]};return db['IntegrationReport'][_0xb61f('0x20')](_0x3fb4c4)[_0xb61f('0x26')](function(_0xf76553){_0x553c17[_0xb61f('0x20')]=_0xf76553;if(_0x9aa4e1[_0xb61f('0x33')][_0xb61f('0x42')]){_0x22f8c8['include']=[{'all':!![]}];}return db[_0xb61f('0x2c')]['findAll'](_0x22f8c8);})[_0xb61f('0x26')](function(_0x3a194f){_0x553c17['rows']=_0x3a194f;return _0x553c17;})[_0xb61f('0x26')](respondWithFilteredResult(_0x306345,_0x22f8c8))['catch'](handleError(_0x306345,null));};exports[_0xb61f('0x43')]=function(_0x47a96b,_0x37e814){var _0x5c1796={'raw':![],'where':{'id':_0x47a96b[_0xb61f('0x44')]['id']}},_0x437dbe={};_0x437dbe[_0xb61f('0x31')]=_[_0xb61f('0x32')](db[_0xb61f('0x2c')]['rawAttributes']);_0x437dbe[_0xb61f('0x33')]=_[_0xb61f('0x32')](_0x47a96b['query']);_0x437dbe[_0xb61f('0x34')]=_[_0xb61f('0x35')](_0x437dbe[_0xb61f('0x31')],_0x437dbe['query']);_0x5c1796[_0xb61f('0x36')]=_[_0xb61f('0x35')](_0x437dbe[_0xb61f('0x31')],qs[_0xb61f('0x37')](_0x47a96b['query'][_0xb61f('0x37')]));_0x5c1796[_0xb61f('0x36')]=_0x5c1796['attributes']['length']?_0x5c1796[_0xb61f('0x36')]:_0x437dbe['model'];if(_0x47a96b['query'][_0xb61f('0x42')]){_0x5c1796[_0xb61f('0x45')]=[{'all':!![]}];}_0x5c1796=_[_0xb61f('0x41')]({},_0x5c1796,_0x47a96b[_0xb61f('0x46')]);return db['IntegrationReport']['find'](_0x5c1796)[_0xb61f('0x26')](handleEntityNotFound(_0x37e814,null))[_0xb61f('0x26')](respondWithResult(_0x37e814,null))[_0xb61f('0x47')](handleError(_0x37e814,null));};exports[_0xb61f('0x48')]=function(_0x158e8c,_0x49acee){return db['IntegrationReport'][_0xb61f('0x48')](_0x158e8c['body'],{})[_0xb61f('0x26')](respondWithResult(_0x49acee,0xc9))[_0xb61f('0x47')](handleError(_0x49acee,null));};exports['update']=function(_0x51b93b,_0x18e649){if(_0x51b93b['body']['id']){delete _0x51b93b['body']['id'];}return db['IntegrationReport'][_0xb61f('0x49')]({'where':{'id':_0x51b93b[_0xb61f('0x44')]['id']}})[_0xb61f('0x26')](handleEntityNotFound(_0x18e649,null))[_0xb61f('0x26')](saveUpdates(_0x51b93b[_0xb61f('0x4a')],null))[_0xb61f('0x26')](respondWithResult(_0x18e649,null))[_0xb61f('0x47')](handleError(_0x18e649,null));};exports[_0xb61f('0x4b')]=function(_0x168886,_0xb1e475){return db[_0xb61f('0x2c')][_0xb61f('0x49')]({'where':{'id':_0x168886[_0xb61f('0x44')]['id']}})[_0xb61f('0x26')](handleEntityNotFound(_0xb1e475,null))['then'](removeEntity(_0xb1e475,null))[_0xb61f('0x47')](handleError(_0xb1e475,null));};exports[_0xb61f('0x4c')]=function(_0x3369fb,_0x231403){return db[_0xb61f('0x2c')][_0xb61f('0x4c')]()[_0xb61f('0x26')](respondWithResult(_0x231403,null))[_0xb61f('0x47')](handleError(_0x231403,null));};