Built motion from commit 9d0783e6.|2.6.13
[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 _0xe72e=['util','path','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','status','end','offset','undefined','limit','count','Content-Range','apply','reject','save','update','destroy','then','sendStatus','error','stack','name','send','index','map','IntegrationReport','rawAttributes','key','model','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','filters','pick','filter','type','VIRTUAL','merge','options','include','findAll','rows','catch','show','params','length','includeAll','create','body','find','describe','eml-format','zip-dir','fast-json-patch'];(function(_0x42146d,_0x5daba1){var _0x354548=function(_0x4cc1bb){while(--_0x4cc1bb){_0x42146d['push'](_0x42146d['shift']());}};_0x354548(++_0x5daba1);}(_0xe72e,0x16f));var _0xee72=function(_0x47678c,_0x4a41b7){_0x47678c=_0x47678c-0x0;var _0x24603c=_0xe72e[_0x47678c];return _0x24603c;};'use strict';var emlformat=require(_0xee72('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xee72('0x1'));var jsonpatch=require(_0xee72('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xee72('0x3'));var path=require(_0xee72('0x4'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xee72('0x5'));var fs=require('fs');var fs_extra=require(_0xee72('0x6'));var _=require(_0xee72('0x7'));var squel=require(_0xee72('0x8'));var crypto=require(_0xee72('0x9'));var jsforce=require(_0xee72('0xa'));var deskjs=require(_0xee72('0xb'));var toCsv=require('to-csv');var querystring=require(_0xee72('0xc'));var Papa=require(_0xee72('0xd'));var Redis=require(_0xee72('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xee72('0xf'));var as=require(_0xee72('0x10'));var hardwareService=require(_0xee72('0x11'));var logger=require(_0xee72('0x12'))('api');var utils=require(_0xee72('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0xee72('0x14'));var db=require(_0xee72('0x15'))['db'];function respondWithStatusCode(_0x1babb6,_0x5bde5b){_0x5bde5b=_0x5bde5b||0xcc;return function(_0x4ae661){if(_0x4ae661){return _0x1babb6['sendStatus'](_0x5bde5b);}return _0x1babb6[_0xee72('0x16')](_0x5bde5b)[_0xee72('0x17')]();};}function respondWithResult(_0x2a74d2,_0x16e3a3){_0x16e3a3=_0x16e3a3||0xc8;return function(_0x39508a){if(_0x39508a){return _0x2a74d2['status'](_0x16e3a3)['json'](_0x39508a);}};}function respondWithFilteredResult(_0x2b4cfb,_0x291eeb){return function(_0x490088){if(_0x490088){var _0x1c0edb=typeof _0x291eeb[_0xee72('0x18')]===_0xee72('0x19')&&typeof _0x291eeb[_0xee72('0x1a')]==='undefined';var _0x4ba896=_0x490088['count'];var _0x738235=_0x1c0edb?0x0:_0x291eeb[_0xee72('0x18')];var _0x2c3a61=_0x1c0edb?_0x490088[_0xee72('0x1b')]:_0x291eeb[_0xee72('0x18')]+_0x291eeb[_0xee72('0x1a')];var _0x58abd3;if(_0x2c3a61>=_0x4ba896){_0x2c3a61=_0x4ba896;_0x58abd3=0xc8;}else{_0x58abd3=0xce;}_0x2b4cfb['status'](_0x58abd3);return _0x2b4cfb['set'](_0xee72('0x1c'),_0x738235+'-'+_0x2c3a61+'/'+_0x4ba896)['json'](_0x490088);}return null;};}function patchUpdates(_0x557f06){return function(_0xe35621){try{jsonpatch[_0xee72('0x1d')](_0xe35621,_0x557f06,!![]);}catch(_0x1715a1){return BPromise[_0xee72('0x1e')](_0x1715a1);}return _0xe35621[_0xee72('0x1f')]();};}function saveUpdates(_0x455d6b,_0x519316){return function(_0x2b13e6){if(_0x2b13e6){return _0x2b13e6[_0xee72('0x20')](_0x455d6b)['then'](function(_0x292b3c){return _0x292b3c;});}return null;};}function removeEntity(_0x16471a,_0x158322){return function(_0x45797c){if(_0x45797c){return _0x45797c[_0xee72('0x21')]()[_0xee72('0x22')](function(){_0x16471a['status'](0xcc)[_0xee72('0x17')]();});}};}function handleEntityNotFound(_0x320f1d,_0xa0db10){return function(_0x2d7004){if(!_0x2d7004){_0x320f1d[_0xee72('0x23')](0x194);}return _0x2d7004;};}function handleError(_0x162f77,_0x347b86){_0x347b86=_0x347b86||0x1f4;return function(_0x4e0a94){logger[_0xee72('0x24')](_0x4e0a94[_0xee72('0x25')]);if(_0x4e0a94[_0xee72('0x26')]){delete _0x4e0a94[_0xee72('0x26')];}_0x162f77[_0xee72('0x16')](_0x347b86)[_0xee72('0x27')](_0x4e0a94);};}exports[_0xee72('0x28')]=function(_0x15f895,_0x38b68a){var _0x403b61={},_0x1e9bb3={},_0x25b803={'count':0x0,'rows':[]};var _0x126cd9=_[_0xee72('0x29')](db[_0xee72('0x2a')][_0xee72('0x2b')],function(_0xbeb7ba){return{'name':_0xbeb7ba['fieldName'],'type':_0xbeb7ba['type'][_0xee72('0x2c')]};});_0x1e9bb3[_0xee72('0x2d')]=_[_0xee72('0x29')](_0x126cd9,'name');_0x1e9bb3['query']=_[_0xee72('0x2e')](_0x15f895[_0xee72('0x2f')]);_0x1e9bb3['filters']=_[_0xee72('0x30')](_0x1e9bb3[_0xee72('0x2d')],_0x1e9bb3[_0xee72('0x2f')]);_0x403b61[_0xee72('0x31')]=_['intersection'](_0x1e9bb3[_0xee72('0x2d')],qs[_0xee72('0x32')](_0x15f895['query'][_0xee72('0x32')]));_0x403b61[_0xee72('0x31')]=_0x403b61['attributes']['length']?_0x403b61[_0xee72('0x31')]:_0x1e9bb3[_0xee72('0x2d')];if(!_0x15f895[_0xee72('0x2f')][_0xee72('0x33')](_0xee72('0x34'))){_0x403b61[_0xee72('0x1a')]=qs[_0xee72('0x1a')](_0x15f895[_0xee72('0x2f')][_0xee72('0x1a')]);_0x403b61[_0xee72('0x18')]=qs['offset'](_0x15f895['query'][_0xee72('0x18')]);}_0x403b61['order']=qs[_0xee72('0x35')](_0x15f895[_0xee72('0x2f')][_0xee72('0x35')]);_0x403b61[_0xee72('0x36')]=qs[_0xee72('0x37')](_[_0xee72('0x38')](_0x15f895[_0xee72('0x2f')],_0x1e9bb3['filters']),_0x126cd9);if(_0x15f895[_0xee72('0x2f')][_0xee72('0x39')]){_0x403b61[_0xee72('0x36')]=_['merge'](_0x403b61[_0xee72('0x36')],{'$or':_['map'](_0x126cd9,function(_0x1efc73){if(_0x1efc73[_0xee72('0x3a')]!==_0xee72('0x3b')){var _0x5107e7={};_0x5107e7[_0x1efc73[_0xee72('0x26')]]={'$like':'%'+_0x15f895[_0xee72('0x2f')]['filter']+'%'};return _0x5107e7;}})});}_0x403b61=_[_0xee72('0x3c')]({},_0x403b61,_0x15f895[_0xee72('0x3d')]);var _0x5a3234={'where':_0x403b61[_0xee72('0x36')]};return db[_0xee72('0x2a')][_0xee72('0x1b')](_0x5a3234)[_0xee72('0x22')](function(_0x43f56a){_0x25b803['count']=_0x43f56a;if(_0x15f895[_0xee72('0x2f')]['includeAll']){_0x403b61[_0xee72('0x3e')]=[{'all':!![]}];}return db[_0xee72('0x2a')][_0xee72('0x3f')](_0x403b61);})[_0xee72('0x22')](function(_0x59bd4b){_0x25b803[_0xee72('0x40')]=_0x59bd4b;return _0x25b803;})['then'](respondWithFilteredResult(_0x38b68a,_0x403b61))[_0xee72('0x41')](handleError(_0x38b68a,null));};exports[_0xee72('0x42')]=function(_0x381b59,_0x1f00ed){var _0x43df3a={'raw':![],'where':{'id':_0x381b59[_0xee72('0x43')]['id']}},_0x56d28d={};_0x56d28d['model']=_[_0xee72('0x2e')](db[_0xee72('0x2a')][_0xee72('0x2b')]);_0x56d28d['query']=_[_0xee72('0x2e')](_0x381b59[_0xee72('0x2f')]);_0x56d28d[_0xee72('0x37')]=_['intersection'](_0x56d28d[_0xee72('0x2d')],_0x56d28d[_0xee72('0x2f')]);_0x43df3a['attributes']=_[_0xee72('0x30')](_0x56d28d[_0xee72('0x2d')],qs[_0xee72('0x32')](_0x381b59[_0xee72('0x2f')]['fields']));_0x43df3a['attributes']=_0x43df3a['attributes'][_0xee72('0x44')]?_0x43df3a[_0xee72('0x31')]:_0x56d28d['model'];if(_0x381b59[_0xee72('0x2f')][_0xee72('0x45')]){_0x43df3a[_0xee72('0x3e')]=[{'all':!![]}];}_0x43df3a=_[_0xee72('0x3c')]({},_0x43df3a,_0x381b59[_0xee72('0x3d')]);return db['IntegrationReport']['find'](_0x43df3a)['then'](handleEntityNotFound(_0x1f00ed,null))[_0xee72('0x22')](respondWithResult(_0x1f00ed,null))['catch'](handleError(_0x1f00ed,null));};exports['create']=function(_0x595b30,_0x49fdcd){return db[_0xee72('0x2a')][_0xee72('0x46')](_0x595b30[_0xee72('0x47')],{})[_0xee72('0x22')](respondWithResult(_0x49fdcd,0xc9))['catch'](handleError(_0x49fdcd,null));};exports[_0xee72('0x20')]=function(_0x55eb89,_0xdf5c82){if(_0x55eb89[_0xee72('0x47')]['id']){delete _0x55eb89[_0xee72('0x47')]['id'];}return db['IntegrationReport'][_0xee72('0x48')]({'where':{'id':_0x55eb89['params']['id']}})['then'](handleEntityNotFound(_0xdf5c82,null))['then'](saveUpdates(_0x55eb89[_0xee72('0x47')],null))['then'](respondWithResult(_0xdf5c82,null))[_0xee72('0x41')](handleError(_0xdf5c82,null));};exports[_0xee72('0x21')]=function(_0x28ac30,_0x38f8e7){return db[_0xee72('0x2a')][_0xee72('0x48')]({'where':{'id':_0x28ac30[_0xee72('0x43')]['id']}})[_0xee72('0x22')](handleEntityNotFound(_0x38f8e7,null))[_0xee72('0x22')](removeEntity(_0x38f8e7,null))['catch'](handleError(_0x38f8e7,null));};exports[_0xee72('0x49')]=function(_0x5d25b1,_0x38c319){return db[_0xee72('0x2a')][_0xee72('0x49')]()[_0xee72('0x22')](respondWithResult(_0x38c319,null))[_0xee72('0x41')](handleError(_0x38c319,null));};