Built motion from commit ecb45b58.|2.6.31
[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 _0x8fb9=['undefined','limit','count','set','Content-Range','json','reject','save','then','destroy','error','name','send','index','map','IntegrationReport','rawAttributes','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','length','create','body','find','params','describe','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset'];(function(_0x4f4762,_0x50a03e){var _0x574b86=function(_0x21161e){while(--_0x21161e){_0x4f4762['push'](_0x4f4762['shift']());}};_0x574b86(++_0x50a03e);}(_0x8fb9,0xc3));var _0x98fb=function(_0x126fb9,_0x122c59){_0x126fb9=_0x126fb9-0x0;var _0xc8a3b1=_0x8fb9[_0x126fb9];return _0xc8a3b1;};'use strict';var emlformat=require(_0x98fb('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x98fb('0x1'));var jsonpatch=require(_0x98fb('0x2'));var rp=require('request-promise');var moment=require(_0x98fb('0x3'));var BPromise=require(_0x98fb('0x4'));var Mustache=require(_0x98fb('0x5'));var util=require(_0x98fb('0x6'));var path=require(_0x98fb('0x7'));var sox=require(_0x98fb('0x8'));var csv=require(_0x98fb('0x9'));var ejs=require(_0x98fb('0xa'));var fs=require('fs');var fs_extra=require(_0x98fb('0xb'));var _=require('lodash');var squel=require(_0x98fb('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x98fb('0xd'));var toCsv=require(_0x98fb('0x9'));var querystring=require(_0x98fb('0xe'));var Papa=require(_0x98fb('0xf'));var Redis=require(_0x98fb('0x10'));var authService=require(_0x98fb('0x11'));var qs=require(_0x98fb('0x12'));var as=require(_0x98fb('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x98fb('0x14'))(_0x98fb('0x15'));var utils=require(_0x98fb('0x16'));var config=require(_0x98fb('0x17'));var licenseUtil=require(_0x98fb('0x18'));var db=require(_0x98fb('0x19'))['db'];function respondWithStatusCode(_0x57dd70,_0x450d64){_0x450d64=_0x450d64||0xcc;return function(_0x7a4509){if(_0x7a4509){return _0x57dd70[_0x98fb('0x1a')](_0x450d64);}return _0x57dd70[_0x98fb('0x1b')](_0x450d64)[_0x98fb('0x1c')]();};}function respondWithResult(_0x1d7f3c,_0x55c7a8){_0x55c7a8=_0x55c7a8||0xc8;return function(_0x580fd3){if(_0x580fd3){return _0x1d7f3c[_0x98fb('0x1b')](_0x55c7a8)['json'](_0x580fd3);}};}function respondWithFilteredResult(_0x37e28a,_0x1b9c0e){return function(_0x212ab3){if(_0x212ab3){var _0x3a0c68=typeof _0x1b9c0e[_0x98fb('0x1d')]===_0x98fb('0x1e')&&typeof _0x1b9c0e[_0x98fb('0x1f')]===_0x98fb('0x1e');var _0x547b51=_0x212ab3[_0x98fb('0x20')];var _0x1f8343=_0x3a0c68?0x0:_0x1b9c0e[_0x98fb('0x1d')];var _0x2c12a3=_0x3a0c68?_0x212ab3[_0x98fb('0x20')]:_0x1b9c0e[_0x98fb('0x1d')]+_0x1b9c0e[_0x98fb('0x1f')];var _0x19d3bf;if(_0x2c12a3>=_0x547b51){_0x2c12a3=_0x547b51;_0x19d3bf=0xc8;}else{_0x19d3bf=0xce;}_0x37e28a['status'](_0x19d3bf);return _0x37e28a[_0x98fb('0x21')](_0x98fb('0x22'),_0x1f8343+'-'+_0x2c12a3+'/'+_0x547b51)[_0x98fb('0x23')](_0x212ab3);}return null;};}function patchUpdates(_0x50dc32){return function(_0x520502){try{jsonpatch['apply'](_0x520502,_0x50dc32,!![]);}catch(_0xeabef9){return BPromise[_0x98fb('0x24')](_0xeabef9);}return _0x520502[_0x98fb('0x25')]();};}function saveUpdates(_0xa0ce8f,_0x35c276){return function(_0x37882a){if(_0x37882a){return _0x37882a['update'](_0xa0ce8f)[_0x98fb('0x26')](function(_0x326c52){return _0x326c52;});}return null;};}function removeEntity(_0x16d7d9,_0x4e09d2){return function(_0x50bb9f){if(_0x50bb9f){return _0x50bb9f[_0x98fb('0x27')]()[_0x98fb('0x26')](function(){_0x16d7d9[_0x98fb('0x1b')](0xcc)[_0x98fb('0x1c')]();});}};}function handleEntityNotFound(_0x3641f4,_0x153371){return function(_0x11e763){if(!_0x11e763){_0x3641f4[_0x98fb('0x1a')](0x194);}return _0x11e763;};}function handleError(_0x1778b0,_0x1307a9){_0x1307a9=_0x1307a9||0x1f4;return function(_0x1ebcd9){logger[_0x98fb('0x28')](_0x1ebcd9['stack']);if(_0x1ebcd9[_0x98fb('0x29')]){delete _0x1ebcd9[_0x98fb('0x29')];}_0x1778b0[_0x98fb('0x1b')](_0x1307a9)[_0x98fb('0x2a')](_0x1ebcd9);};}exports[_0x98fb('0x2b')]=function(_0x50b8f9,_0x267959){var _0x222fb3={},_0x227345={},_0x1d33a0={'count':0x0,'rows':[]};var _0x46644c=_[_0x98fb('0x2c')](db[_0x98fb('0x2d')][_0x98fb('0x2e')],function(_0x2809d7){return{'name':_0x2809d7['fieldName'],'type':_0x2809d7[_0x98fb('0x2f')]['key']};});_0x227345[_0x98fb('0x30')]=_[_0x98fb('0x2c')](_0x46644c,_0x98fb('0x29'));_0x227345[_0x98fb('0x31')]=_[_0x98fb('0x32')](_0x50b8f9[_0x98fb('0x31')]);_0x227345[_0x98fb('0x33')]=_[_0x98fb('0x34')](_0x227345['model'],_0x227345[_0x98fb('0x31')]);_0x222fb3[_0x98fb('0x35')]=_['intersection'](_0x227345[_0x98fb('0x30')],qs[_0x98fb('0x36')](_0x50b8f9[_0x98fb('0x31')][_0x98fb('0x36')]));_0x222fb3['attributes']=_0x222fb3[_0x98fb('0x35')]['length']?_0x222fb3[_0x98fb('0x35')]:_0x227345[_0x98fb('0x30')];if(!_0x50b8f9['query'][_0x98fb('0x37')](_0x98fb('0x38'))){_0x222fb3[_0x98fb('0x1f')]=qs['limit'](_0x50b8f9[_0x98fb('0x31')][_0x98fb('0x1f')]);_0x222fb3[_0x98fb('0x1d')]=qs[_0x98fb('0x1d')](_0x50b8f9[_0x98fb('0x31')][_0x98fb('0x1d')]);}_0x222fb3[_0x98fb('0x39')]=qs['sort'](_0x50b8f9['query']['sort']);_0x222fb3[_0x98fb('0x3a')]=qs['filters'](_[_0x98fb('0x3b')](_0x50b8f9[_0x98fb('0x31')],_0x227345[_0x98fb('0x33')]),_0x46644c);if(_0x50b8f9[_0x98fb('0x31')][_0x98fb('0x3c')]){_0x222fb3[_0x98fb('0x3a')]=_[_0x98fb('0x3d')](_0x222fb3[_0x98fb('0x3a')],{'$or':_[_0x98fb('0x2c')](_0x46644c,function(_0x55f983){if(_0x55f983[_0x98fb('0x2f')]!==_0x98fb('0x3e')){var _0x585c6a={};_0x585c6a[_0x55f983[_0x98fb('0x29')]]={'$like':'%'+_0x50b8f9[_0x98fb('0x31')][_0x98fb('0x3c')]+'%'};return _0x585c6a;}})});}_0x222fb3=_[_0x98fb('0x3d')]({},_0x222fb3,_0x50b8f9[_0x98fb('0x3f')]);var _0x5b3737={'where':_0x222fb3[_0x98fb('0x3a')]};return db[_0x98fb('0x2d')][_0x98fb('0x20')](_0x5b3737)[_0x98fb('0x26')](function(_0x3e484e){_0x1d33a0[_0x98fb('0x20')]=_0x3e484e;if(_0x50b8f9[_0x98fb('0x31')][_0x98fb('0x40')]){_0x222fb3[_0x98fb('0x41')]=[{'all':!![]}];}return db['IntegrationReport'][_0x98fb('0x42')](_0x222fb3);})['then'](function(_0x427f59){_0x1d33a0['rows']=_0x427f59;return _0x1d33a0;})['then'](respondWithFilteredResult(_0x267959,_0x222fb3))[_0x98fb('0x43')](handleError(_0x267959,null));};exports[_0x98fb('0x44')]=function(_0x210480,_0x3d1bdc){var _0xc80fe4={'raw':![],'where':{'id':_0x210480['params']['id']}},_0x43f877={};_0x43f877[_0x98fb('0x30')]=_[_0x98fb('0x32')](db[_0x98fb('0x2d')]['rawAttributes']);_0x43f877[_0x98fb('0x31')]=_['keys'](_0x210480[_0x98fb('0x31')]);_0x43f877['filters']=_[_0x98fb('0x34')](_0x43f877[_0x98fb('0x30')],_0x43f877[_0x98fb('0x31')]);_0xc80fe4[_0x98fb('0x35')]=_[_0x98fb('0x34')](_0x43f877[_0x98fb('0x30')],qs[_0x98fb('0x36')](_0x210480[_0x98fb('0x31')]['fields']));_0xc80fe4[_0x98fb('0x35')]=_0xc80fe4[_0x98fb('0x35')][_0x98fb('0x45')]?_0xc80fe4['attributes']:_0x43f877[_0x98fb('0x30')];if(_0x210480[_0x98fb('0x31')][_0x98fb('0x40')]){_0xc80fe4['include']=[{'all':!![]}];}_0xc80fe4=_[_0x98fb('0x3d')]({},_0xc80fe4,_0x210480[_0x98fb('0x3f')]);return db['IntegrationReport']['find'](_0xc80fe4)[_0x98fb('0x26')](handleEntityNotFound(_0x3d1bdc,null))[_0x98fb('0x26')](respondWithResult(_0x3d1bdc,null))[_0x98fb('0x43')](handleError(_0x3d1bdc,null));};exports['create']=function(_0x4221f5,_0x4ac646){return db[_0x98fb('0x2d')][_0x98fb('0x46')](_0x4221f5[_0x98fb('0x47')],{})['then'](respondWithResult(_0x4ac646,0xc9))['catch'](handleError(_0x4ac646,null));};exports['update']=function(_0x4db81e,_0x3c53df){if(_0x4db81e[_0x98fb('0x47')]['id']){delete _0x4db81e[_0x98fb('0x47')]['id'];}return db[_0x98fb('0x2d')][_0x98fb('0x48')]({'where':{'id':_0x4db81e['params']['id']}})[_0x98fb('0x26')](handleEntityNotFound(_0x3c53df,null))[_0x98fb('0x26')](saveUpdates(_0x4db81e[_0x98fb('0x47')],null))[_0x98fb('0x26')](respondWithResult(_0x3c53df,null))[_0x98fb('0x43')](handleError(_0x3c53df,null));};exports['destroy']=function(_0x42baaf,_0x525033){return db[_0x98fb('0x2d')]['find']({'where':{'id':_0x42baaf[_0x98fb('0x49')]['id']}})[_0x98fb('0x26')](handleEntityNotFound(_0x525033,null))[_0x98fb('0x26')](removeEntity(_0x525033,null))[_0x98fb('0x43')](handleError(_0x525033,null));};exports[_0x98fb('0x4a')]=function(_0x10a118,_0x1196de){return db['IntegrationReport'][_0x98fb('0x4a')]()[_0x98fb('0x26')](respondWithResult(_0x1196de,null))[_0x98fb('0x43')](handleError(_0x1196de,null));};