e9d0801ce7592e6d22d0e6324458a745768b3302
[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 _0xdfc2=['keys','intersection','includeAll','find','create','body','describe','eml-format','rimraf','zip-dir','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','limit','undefined','count','offset','set','Content-Range','reject','update','destroy','then','end','error','stack','name','send','index','map','IntegrationReport','rawAttributes','fieldName','type','key','model','query','filters','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','merge','VIRTUAL','options','include','findAll','rows','catch','show','params'];(function(_0x8aba54,_0x4dbeb1){var _0x3db7be=function(_0x4674bd){while(--_0x4674bd){_0x8aba54['push'](_0x8aba54['shift']());}};_0x3db7be(++_0x4dbeb1);}(_0xdfc2,0x1d5));var _0x2dfc=function(_0x126001,_0x4882e5){_0x126001=_0x126001-0x0;var _0x15c01f=_0xdfc2[_0x126001];return _0x15c01f;};'use strict';var emlformat=require(_0x2dfc('0x0'));var rimraf=require(_0x2dfc('0x1'));var zipdir=require(_0x2dfc('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x2dfc('0x3'));var Mustache=require(_0x2dfc('0x4'));var util=require(_0x2dfc('0x5'));var path=require(_0x2dfc('0x6'));var sox=require(_0x2dfc('0x7'));var csv=require(_0x2dfc('0x8'));var ejs=require(_0x2dfc('0x9'));var fs=require('fs');var fs_extra=require(_0x2dfc('0xa'));var _=require(_0x2dfc('0xb'));var squel=require(_0x2dfc('0xc'));var crypto=require(_0x2dfc('0xd'));var jsforce=require(_0x2dfc('0xe'));var deskjs=require(_0x2dfc('0xf'));var toCsv=require(_0x2dfc('0x8'));var querystring=require(_0x2dfc('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x2dfc('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x2dfc('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x2dfc('0x13'))(_0x2dfc('0x14'));var utils=require(_0x2dfc('0x15'));var config=require(_0x2dfc('0x16'));var licenseUtil=require(_0x2dfc('0x17'));var db=require(_0x2dfc('0x18'))['db'];function respondWithStatusCode(_0x23b80d,_0x3a5511){_0x3a5511=_0x3a5511||0xcc;return function(_0x2dde08){if(_0x2dde08){return _0x23b80d[_0x2dfc('0x19')](_0x3a5511);}return _0x23b80d['status'](_0x3a5511)['end']();};}function respondWithResult(_0x2c2821,_0x3fecf4){_0x3fecf4=_0x3fecf4||0xc8;return function(_0xdd673a){if(_0xdd673a){return _0x2c2821[_0x2dfc('0x1a')](_0x3fecf4)[_0x2dfc('0x1b')](_0xdd673a);}};}function respondWithFilteredResult(_0x5d3c31,_0x19ef81){return function(_0x15eb51){if(_0x15eb51){var _0x3d52e6=typeof _0x19ef81['offset']==='undefined'&&typeof _0x19ef81[_0x2dfc('0x1c')]===_0x2dfc('0x1d');var _0x20b566=_0x15eb51[_0x2dfc('0x1e')];var _0x3a71f0=_0x3d52e6?0x0:_0x19ef81[_0x2dfc('0x1f')];var _0x2f2645=_0x3d52e6?_0x15eb51[_0x2dfc('0x1e')]:_0x19ef81[_0x2dfc('0x1f')]+_0x19ef81['limit'];var _0x1cf906;if(_0x2f2645>=_0x20b566){_0x2f2645=_0x20b566;_0x1cf906=0xc8;}else{_0x1cf906=0xce;}_0x5d3c31[_0x2dfc('0x1a')](_0x1cf906);return _0x5d3c31[_0x2dfc('0x20')](_0x2dfc('0x21'),_0x3a71f0+'-'+_0x2f2645+'/'+_0x20b566)[_0x2dfc('0x1b')](_0x15eb51);}return null;};}function patchUpdates(_0x25f573){return function(_0x3756e3){try{jsonpatch['apply'](_0x3756e3,_0x25f573,!![]);}catch(_0x59c39a){return BPromise[_0x2dfc('0x22')](_0x59c39a);}return _0x3756e3['save']();};}function saveUpdates(_0x3d0c21,_0x19a173){return function(_0x3026f2){if(_0x3026f2){return _0x3026f2[_0x2dfc('0x23')](_0x3d0c21)['then'](function(_0x348410){return _0x348410;});}return null;};}function removeEntity(_0x1aa131,_0x4809d9){return function(_0x26d079){if(_0x26d079){return _0x26d079[_0x2dfc('0x24')]()[_0x2dfc('0x25')](function(){_0x1aa131['status'](0xcc)[_0x2dfc('0x26')]();});}};}function handleEntityNotFound(_0x3e6ae4,_0x463e05){return function(_0x884cb3){if(!_0x884cb3){_0x3e6ae4[_0x2dfc('0x19')](0x194);}return _0x884cb3;};}function handleError(_0x1f1c16,_0x50563d){_0x50563d=_0x50563d||0x1f4;return function(_0x1dcbff){logger[_0x2dfc('0x27')](_0x1dcbff[_0x2dfc('0x28')]);if(_0x1dcbff[_0x2dfc('0x29')]){delete _0x1dcbff[_0x2dfc('0x29')];}_0x1f1c16[_0x2dfc('0x1a')](_0x50563d)[_0x2dfc('0x2a')](_0x1dcbff);};}exports[_0x2dfc('0x2b')]=function(_0x295487,_0x3f6b74){var _0x3617c4={},_0x16a680={},_0x1377c9={'count':0x0,'rows':[]};var _0x68351=_[_0x2dfc('0x2c')](db[_0x2dfc('0x2d')][_0x2dfc('0x2e')],function(_0x236e80){return{'name':_0x236e80[_0x2dfc('0x2f')],'type':_0x236e80[_0x2dfc('0x30')][_0x2dfc('0x31')]};});_0x16a680[_0x2dfc('0x32')]=_[_0x2dfc('0x2c')](_0x68351,_0x2dfc('0x29'));_0x16a680['query']=_['keys'](_0x295487[_0x2dfc('0x33')]);_0x16a680[_0x2dfc('0x34')]=_['intersection'](_0x16a680['model'],_0x16a680[_0x2dfc('0x33')]);_0x3617c4[_0x2dfc('0x35')]=_['intersection'](_0x16a680[_0x2dfc('0x32')],qs[_0x2dfc('0x36')](_0x295487[_0x2dfc('0x33')]['fields']));_0x3617c4[_0x2dfc('0x35')]=_0x3617c4[_0x2dfc('0x35')][_0x2dfc('0x37')]?_0x3617c4[_0x2dfc('0x35')]:_0x16a680['model'];if(!_0x295487[_0x2dfc('0x33')][_0x2dfc('0x38')](_0x2dfc('0x39'))){_0x3617c4[_0x2dfc('0x1c')]=qs[_0x2dfc('0x1c')](_0x295487[_0x2dfc('0x33')][_0x2dfc('0x1c')]);_0x3617c4[_0x2dfc('0x1f')]=qs[_0x2dfc('0x1f')](_0x295487[_0x2dfc('0x33')][_0x2dfc('0x1f')]);}_0x3617c4['order']=qs[_0x2dfc('0x3a')](_0x295487[_0x2dfc('0x33')]['sort']);_0x3617c4[_0x2dfc('0x3b')]=qs[_0x2dfc('0x34')](_[_0x2dfc('0x3c')](_0x295487[_0x2dfc('0x33')],_0x16a680[_0x2dfc('0x34')]),_0x68351);if(_0x295487[_0x2dfc('0x33')]['filter']){_0x3617c4[_0x2dfc('0x3b')]=_[_0x2dfc('0x3d')](_0x3617c4['where'],{'$or':_['map'](_0x68351,function(_0x486cfd){if(_0x486cfd[_0x2dfc('0x30')]!==_0x2dfc('0x3e')){var _0x25b9fb={};_0x25b9fb[_0x486cfd[_0x2dfc('0x29')]]={'$like':'%'+_0x295487['query']['filter']+'%'};return _0x25b9fb;}})});}_0x3617c4=_[_0x2dfc('0x3d')]({},_0x3617c4,_0x295487[_0x2dfc('0x3f')]);var _0x4af558={'where':_0x3617c4[_0x2dfc('0x3b')]};return db[_0x2dfc('0x2d')][_0x2dfc('0x1e')](_0x4af558)[_0x2dfc('0x25')](function(_0x201eec){_0x1377c9['count']=_0x201eec;if(_0x295487['query']['includeAll']){_0x3617c4[_0x2dfc('0x40')]=[{'all':!![]}];}return db[_0x2dfc('0x2d')][_0x2dfc('0x41')](_0x3617c4);})[_0x2dfc('0x25')](function(_0x59f2fa){_0x1377c9[_0x2dfc('0x42')]=_0x59f2fa;return _0x1377c9;})['then'](respondWithFilteredResult(_0x3f6b74,_0x3617c4))[_0x2dfc('0x43')](handleError(_0x3f6b74,null));};exports[_0x2dfc('0x44')]=function(_0x5c4784,_0x50003b){var _0x5834d4={'raw':![],'where':{'id':_0x5c4784[_0x2dfc('0x45')]['id']}},_0x2ff032={};_0x2ff032['model']=_['keys'](db[_0x2dfc('0x2d')][_0x2dfc('0x2e')]);_0x2ff032[_0x2dfc('0x33')]=_[_0x2dfc('0x46')](_0x5c4784['query']);_0x2ff032[_0x2dfc('0x34')]=_[_0x2dfc('0x47')](_0x2ff032[_0x2dfc('0x32')],_0x2ff032[_0x2dfc('0x33')]);_0x5834d4[_0x2dfc('0x35')]=_['intersection'](_0x2ff032[_0x2dfc('0x32')],qs['fields'](_0x5c4784[_0x2dfc('0x33')][_0x2dfc('0x36')]));_0x5834d4[_0x2dfc('0x35')]=_0x5834d4[_0x2dfc('0x35')][_0x2dfc('0x37')]?_0x5834d4[_0x2dfc('0x35')]:_0x2ff032[_0x2dfc('0x32')];if(_0x5c4784['query'][_0x2dfc('0x48')]){_0x5834d4[_0x2dfc('0x40')]=[{'all':!![]}];}_0x5834d4=_[_0x2dfc('0x3d')]({},_0x5834d4,_0x5c4784[_0x2dfc('0x3f')]);return db[_0x2dfc('0x2d')][_0x2dfc('0x49')](_0x5834d4)[_0x2dfc('0x25')](handleEntityNotFound(_0x50003b,null))[_0x2dfc('0x25')](respondWithResult(_0x50003b,null))['catch'](handleError(_0x50003b,null));};exports[_0x2dfc('0x4a')]=function(_0x35b002,_0x383cad){return db[_0x2dfc('0x2d')][_0x2dfc('0x4a')](_0x35b002[_0x2dfc('0x4b')],{})[_0x2dfc('0x25')](respondWithResult(_0x383cad,0xc9))[_0x2dfc('0x43')](handleError(_0x383cad,null));};exports['update']=function(_0x57adf7,_0x506a66){if(_0x57adf7[_0x2dfc('0x4b')]['id']){delete _0x57adf7['body']['id'];}return db[_0x2dfc('0x2d')][_0x2dfc('0x49')]({'where':{'id':_0x57adf7[_0x2dfc('0x45')]['id']}})[_0x2dfc('0x25')](handleEntityNotFound(_0x506a66,null))[_0x2dfc('0x25')](saveUpdates(_0x57adf7[_0x2dfc('0x4b')],null))[_0x2dfc('0x25')](respondWithResult(_0x506a66,null))[_0x2dfc('0x43')](handleError(_0x506a66,null));};exports[_0x2dfc('0x24')]=function(_0x1cb354,_0x166cd1){return db[_0x2dfc('0x2d')][_0x2dfc('0x49')]({'where':{'id':_0x1cb354['params']['id']}})[_0x2dfc('0x25')](handleEntityNotFound(_0x166cd1,null))[_0x2dfc('0x25')](removeEntity(_0x166cd1,null))['catch'](handleError(_0x166cd1,null));};exports[_0x2dfc('0x4c')]=function(_0x17f605,_0x3b02d6){return db[_0x2dfc('0x2d')][_0x2dfc('0x4c')]()['then'](respondWithResult(_0x3b02d6,null))[_0x2dfc('0x43')](handleError(_0x3b02d6,null));};