Built motion from commit a61a4a20.|2.5.46
[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 _0xb30f=['offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','IntegrationReport','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','sort','where','filter','merge','map','options','include','findAll','rows','show','params','includeAll','find','create','body','catch','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json'];(function(_0x21cc96,_0x3d6a72){var _0x284f44=function(_0x436fb0){while(--_0x436fb0){_0x21cc96['push'](_0x21cc96['shift']());}};_0x284f44(++_0x3d6a72);}(_0xb30f,0x15f));var _0xfb30=function(_0x25568e,_0x15f6f1){_0x25568e=_0x25568e-0x0;var _0x32f381=_0xb30f[_0x25568e];return _0x32f381;};'use strict';var emlformat=require(_0xfb30('0x0'));var rimraf=require(_0xfb30('0x1'));var zipdir=require(_0xfb30('0x2'));var jsonpatch=require(_0xfb30('0x3'));var rp=require(_0xfb30('0x4'));var moment=require(_0xfb30('0x5'));var BPromise=require(_0xfb30('0x6'));var Mustache=require('mustache');var util=require(_0xfb30('0x7'));var path=require('path');var sox=require(_0xfb30('0x8'));var csv=require(_0xfb30('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xfb30('0xa'));var _=require(_0xfb30('0xb'));var squel=require(_0xfb30('0xc'));var crypto=require(_0xfb30('0xd'));var jsforce=require(_0xfb30('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xfb30('0x9'));var querystring=require('querystring');var Papa=require(_0xfb30('0xf'));var Redis=require(_0xfb30('0x10'));var authService=require(_0xfb30('0x11'));var qs=require(_0xfb30('0x12'));var as=require(_0xfb30('0x13'));var hardwareService=require(_0xfb30('0x14'));var logger=require(_0xfb30('0x15'))('api');var utils=require(_0xfb30('0x16'));var config=require(_0xfb30('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xfb30('0x18'))['db'];function respondWithStatusCode(_0x3dfdb5,_0x44540d){_0x44540d=_0x44540d||0xcc;return function(_0x344b64){if(_0x344b64){return _0x3dfdb5[_0xfb30('0x19')](_0x44540d);}return _0x3dfdb5[_0xfb30('0x1a')](_0x44540d)[_0xfb30('0x1b')]();};}function respondWithResult(_0x220d1c,_0x42f20d){_0x42f20d=_0x42f20d||0xc8;return function(_0x413827){if(_0x413827){return _0x220d1c[_0xfb30('0x1a')](_0x42f20d)[_0xfb30('0x1c')](_0x413827);}};}function respondWithFilteredResult(_0x4a0012,_0x1c2c47){return function(_0x2c8f87){if(_0x2c8f87){var _0x8d5e91=typeof _0x1c2c47[_0xfb30('0x1d')]===_0xfb30('0x1e')&&typeof _0x1c2c47[_0xfb30('0x1f')]===_0xfb30('0x1e');var _0x2c9842=_0x2c8f87[_0xfb30('0x20')];var _0xb3fa94=_0x8d5e91?0x0:_0x1c2c47[_0xfb30('0x1d')];var _0x3665e4=_0x8d5e91?_0x2c8f87[_0xfb30('0x20')]:_0x1c2c47[_0xfb30('0x1d')]+_0x1c2c47[_0xfb30('0x1f')];var _0x134590;if(_0x3665e4>=_0x2c9842){_0x3665e4=_0x2c9842;_0x134590=0xc8;}else{_0x134590=0xce;}_0x4a0012[_0xfb30('0x1a')](_0x134590);return _0x4a0012[_0xfb30('0x21')](_0xfb30('0x22'),_0xb3fa94+'-'+_0x3665e4+'/'+_0x2c9842)[_0xfb30('0x1c')](_0x2c8f87);}return null;};}function patchUpdates(_0x54acc2){return function(_0x539a14){try{jsonpatch[_0xfb30('0x23')](_0x539a14,_0x54acc2,!![]);}catch(_0x4668a7){return BPromise[_0xfb30('0x24')](_0x4668a7);}return _0x539a14[_0xfb30('0x25')]();};}function saveUpdates(_0x1111b3,_0x1f39bc){return function(_0x2ea33f){if(_0x2ea33f){return _0x2ea33f[_0xfb30('0x26')](_0x1111b3)[_0xfb30('0x27')](function(_0x1756f5){return _0x1756f5;});}return null;};}function removeEntity(_0x444989,_0x138092){return function(_0x593e33){if(_0x593e33){return _0x593e33[_0xfb30('0x28')]()[_0xfb30('0x27')](function(){_0x444989['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x389841,_0x173643){return function(_0x21121a){if(!_0x21121a){_0x389841[_0xfb30('0x19')](0x194);}return _0x21121a;};}function handleError(_0x4d5aff,_0x2befd4){_0x2befd4=_0x2befd4||0x1f4;return function(_0x3c2f4b){logger[_0xfb30('0x29')](_0x3c2f4b['stack']);if(_0x3c2f4b[_0xfb30('0x2a')]){delete _0x3c2f4b[_0xfb30('0x2a')];}_0x4d5aff['status'](_0x2befd4)[_0xfb30('0x2b')](_0x3c2f4b);};}exports[_0xfb30('0x2c')]=function(_0x19f486,_0x1144f2){var _0x5658d8={},_0x389650={},_0x3a5b27={'count':0x0,'rows':[]};var _0x4900cd=_['map'](db[_0xfb30('0x2d')][_0xfb30('0x2e')],function(_0x2d83b1){return{'name':_0x2d83b1[_0xfb30('0x2f')],'type':_0x2d83b1[_0xfb30('0x30')][_0xfb30('0x31')]};});_0x389650['model']=_['map'](_0x4900cd,_0xfb30('0x2a'));_0x389650[_0xfb30('0x32')]=_[_0xfb30('0x33')](_0x19f486[_0xfb30('0x32')]);_0x389650[_0xfb30('0x34')]=_[_0xfb30('0x35')](_0x389650[_0xfb30('0x36')],_0x389650[_0xfb30('0x32')]);_0x5658d8[_0xfb30('0x37')]=_['intersection'](_0x389650['model'],qs[_0xfb30('0x38')](_0x19f486[_0xfb30('0x32')]['fields']));_0x5658d8[_0xfb30('0x37')]=_0x5658d8[_0xfb30('0x37')][_0xfb30('0x39')]?_0x5658d8[_0xfb30('0x37')]:_0x389650[_0xfb30('0x36')];if(!_0x19f486[_0xfb30('0x32')][_0xfb30('0x3a')]('nolimit')){_0x5658d8['limit']=qs[_0xfb30('0x1f')](_0x19f486[_0xfb30('0x32')]['limit']);_0x5658d8[_0xfb30('0x1d')]=qs[_0xfb30('0x1d')](_0x19f486[_0xfb30('0x32')][_0xfb30('0x1d')]);}_0x5658d8['order']=qs[_0xfb30('0x3b')](_0x19f486[_0xfb30('0x32')][_0xfb30('0x3b')]);_0x5658d8[_0xfb30('0x3c')]=qs[_0xfb30('0x34')](_['pick'](_0x19f486[_0xfb30('0x32')],_0x389650['filters']),_0x4900cd);if(_0x19f486[_0xfb30('0x32')][_0xfb30('0x3d')]){_0x5658d8[_0xfb30('0x3c')]=_[_0xfb30('0x3e')](_0x5658d8['where'],{'$or':_[_0xfb30('0x3f')](_0x4900cd,function(_0x30e3d3){if(_0x30e3d3['type']!=='VIRTUAL'){var _0x6fa809={};_0x6fa809[_0x30e3d3[_0xfb30('0x2a')]]={'$like':'%'+_0x19f486[_0xfb30('0x32')][_0xfb30('0x3d')]+'%'};return _0x6fa809;}})});}_0x5658d8=_[_0xfb30('0x3e')]({},_0x5658d8,_0x19f486[_0xfb30('0x40')]);var _0x36e0bf={'where':_0x5658d8[_0xfb30('0x3c')]};return db[_0xfb30('0x2d')]['count'](_0x36e0bf)[_0xfb30('0x27')](function(_0x4b0426){_0x3a5b27[_0xfb30('0x20')]=_0x4b0426;if(_0x19f486[_0xfb30('0x32')]['includeAll']){_0x5658d8[_0xfb30('0x41')]=[{'all':!![]}];}return db['IntegrationReport'][_0xfb30('0x42')](_0x5658d8);})['then'](function(_0x5c0359){_0x3a5b27[_0xfb30('0x43')]=_0x5c0359;return _0x3a5b27;})['then'](respondWithFilteredResult(_0x1144f2,_0x5658d8))['catch'](handleError(_0x1144f2,null));};exports[_0xfb30('0x44')]=function(_0x24bcb1,_0x1c2906){var _0x620a36={'raw':![],'where':{'id':_0x24bcb1[_0xfb30('0x45')]['id']}},_0x13a8fe={};_0x13a8fe[_0xfb30('0x36')]=_[_0xfb30('0x33')](db['IntegrationReport'][_0xfb30('0x2e')]);_0x13a8fe[_0xfb30('0x32')]=_[_0xfb30('0x33')](_0x24bcb1['query']);_0x13a8fe[_0xfb30('0x34')]=_[_0xfb30('0x35')](_0x13a8fe[_0xfb30('0x36')],_0x13a8fe[_0xfb30('0x32')]);_0x620a36[_0xfb30('0x37')]=_[_0xfb30('0x35')](_0x13a8fe[_0xfb30('0x36')],qs[_0xfb30('0x38')](_0x24bcb1['query'][_0xfb30('0x38')]));_0x620a36[_0xfb30('0x37')]=_0x620a36['attributes']['length']?_0x620a36[_0xfb30('0x37')]:_0x13a8fe[_0xfb30('0x36')];if(_0x24bcb1[_0xfb30('0x32')][_0xfb30('0x46')]){_0x620a36[_0xfb30('0x41')]=[{'all':!![]}];}_0x620a36=_[_0xfb30('0x3e')]({},_0x620a36,_0x24bcb1['options']);return db[_0xfb30('0x2d')][_0xfb30('0x47')](_0x620a36)[_0xfb30('0x27')](handleEntityNotFound(_0x1c2906,null))[_0xfb30('0x27')](respondWithResult(_0x1c2906,null))['catch'](handleError(_0x1c2906,null));};exports[_0xfb30('0x48')]=function(_0x2c2207,_0x3d6b21){return db[_0xfb30('0x2d')][_0xfb30('0x48')](_0x2c2207[_0xfb30('0x49')],{})[_0xfb30('0x27')](respondWithResult(_0x3d6b21,0xc9))[_0xfb30('0x4a')](handleError(_0x3d6b21,null));};exports[_0xfb30('0x26')]=function(_0x589cce,_0x471783){if(_0x589cce['body']['id']){delete _0x589cce[_0xfb30('0x49')]['id'];}return db[_0xfb30('0x2d')][_0xfb30('0x47')]({'where':{'id':_0x589cce['params']['id']}})[_0xfb30('0x27')](handleEntityNotFound(_0x471783,null))[_0xfb30('0x27')](saveUpdates(_0x589cce[_0xfb30('0x49')],null))['then'](respondWithResult(_0x471783,null))[_0xfb30('0x4a')](handleError(_0x471783,null));};exports['destroy']=function(_0x425b6a,_0xee51ed){return db['IntegrationReport'][_0xfb30('0x47')]({'where':{'id':_0x425b6a[_0xfb30('0x45')]['id']}})['then'](handleEntityNotFound(_0xee51ed,null))[_0xfb30('0x27')](removeEntity(_0xee51ed,null))[_0xfb30('0x4a')](handleError(_0xee51ed,null));};exports[_0xfb30('0x4b')]=function(_0x41bf1b,_0x779cf1){return db[_0xfb30('0x2d')][_0xfb30('0x4b')]()[_0xfb30('0x27')](respondWithResult(_0x779cf1,null))['catch'](handleError(_0x779cf1,null));};