Built motion from commit (unavailable).|2.5.1
[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 _0xf835=['status','count','offset','limit','Content-Range','json','reject','update','then','destroy','stack','name','send','map','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','includeAll','include','IntegrationReport','findAll','rows','catch','show','params','rawAttributes','keys','length','find','create','body','describe','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','end'];(function(_0x4588f1,_0x1dcfa0){var _0x147c88=function(_0x19d791){while(--_0x19d791){_0x4588f1['push'](_0x4588f1['shift']());}};_0x147c88(++_0x1dcfa0);}(_0xf835,0x149));var _0x5f83=function(_0x27b0bb,_0x1e9640){_0x27b0bb=_0x27b0bb-0x0;var _0x5174a1=_0xf835[_0x27b0bb];return _0x5174a1;};'use strict';var pdf=require(_0x5f83('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x5f83('0x1'));var zipdir=require(_0x5f83('0x2'));var jsonpatch=require(_0x5f83('0x3'));var rp=require(_0x5f83('0x4'));var moment=require(_0x5f83('0x5'));var BPromise=require(_0x5f83('0x6'));var Mustache=require('mustache');var util=require(_0x5f83('0x7'));var path=require(_0x5f83('0x8'));var sox=require(_0x5f83('0x9'));var csv=require(_0x5f83('0xa'));var ejs=require(_0x5f83('0xb'));var fs=require('fs');var _=require(_0x5f83('0xc'));var squel=require(_0x5f83('0xd'));var crypto=require('crypto');var jsforce=require(_0x5f83('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x5f83('0xa'));var querystring=require('querystring');var Papa=require(_0x5f83('0xf'));var Redis=require(_0x5f83('0x10'));var authService=require(_0x5f83('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x5f83('0x12'));var hardwareService=require(_0x5f83('0x13'));var logger=require(_0x5f83('0x14'))(_0x5f83('0x15'));var utils=require(_0x5f83('0x16'));var config=require('../../config/environment');var db=require(_0x5f83('0x17'))['db'];function respondWithStatusCode(_0x15bd44,_0x335b71){_0x335b71=_0x335b71||0xcc;return function(_0x33527a){if(_0x33527a){return _0x15bd44[_0x5f83('0x18')](_0x335b71);}return _0x15bd44['status'](_0x335b71)[_0x5f83('0x19')]();};}function respondWithResult(_0x54de10,_0x34ab95){_0x34ab95=_0x34ab95||0xc8;return function(_0x1aef4d){if(_0x1aef4d){return _0x54de10[_0x5f83('0x1a')](_0x34ab95)['json'](_0x1aef4d);}};}function respondWithFilteredResult(_0x522392,_0x5756d5){return function(_0xf1a58d){if(_0xf1a58d){var _0x2a0afa=_0xf1a58d[_0x5f83('0x1b')],_0x4d7f81=_0x5756d5[_0x5f83('0x1c')],_0x307f59=_0x5756d5['offset']+_0x5756d5[_0x5f83('0x1d')],_0x5b8f0e;if(_0x307f59>=_0x2a0afa){_0x307f59=_0x2a0afa;_0x5b8f0e=0xc8;}else{_0x5b8f0e=0xce;}_0x522392[_0x5f83('0x1a')](_0x5b8f0e);return _0x522392['set'](_0x5f83('0x1e'),_0x4d7f81+'-'+_0x307f59+'/'+_0x2a0afa)[_0x5f83('0x1f')](_0xf1a58d);}return null;};}function patchUpdates(_0x502a11){return function(_0x449fdc){try{jsonpatch['apply'](_0x449fdc,_0x502a11,!![]);}catch(_0x5433d9){return BPromise[_0x5f83('0x20')](_0x5433d9);}return _0x449fdc['save']();};}function saveUpdates(_0x307a97,_0xbbc960){return function(_0x55bc34){if(_0x55bc34){return _0x55bc34[_0x5f83('0x21')](_0x307a97)[_0x5f83('0x22')](function(_0x17cfa3){return _0x17cfa3;});}return null;};}function removeEntity(_0x56ab99,_0x52c4fa){return function(_0x1e6092){if(_0x1e6092){return _0x1e6092[_0x5f83('0x23')]()[_0x5f83('0x22')](function(){_0x56ab99[_0x5f83('0x1a')](0xcc)[_0x5f83('0x19')]();});}};}function handleEntityNotFound(_0x5b8899,_0x19fad0){return function(_0x1c8229){if(!_0x1c8229){_0x5b8899[_0x5f83('0x18')](0x194);}return _0x1c8229;};}function handleError(_0x121ba1,_0x4a9050){_0x4a9050=_0x4a9050||0x1f4;return function(_0x1f3b0b){logger['error'](_0x1f3b0b[_0x5f83('0x24')]);if(_0x1f3b0b[_0x5f83('0x25')]){delete _0x1f3b0b[_0x5f83('0x25')];}_0x121ba1[_0x5f83('0x1a')](_0x4a9050)[_0x5f83('0x26')](_0x1f3b0b);};}exports['index']=function(_0x563883,_0x5efe34){var _0x364854={},_0x2ee71a={},_0x5044c8={'count':0x0,'rows':[]};var _0x4f923e=_[_0x5f83('0x27')](db['IntegrationReport']['rawAttributes'],function(_0x480381){return{'name':_0x480381[_0x5f83('0x28')],'type':_0x480381[_0x5f83('0x29')][_0x5f83('0x2a')]};});_0x2ee71a[_0x5f83('0x2b')]=_[_0x5f83('0x27')](_0x4f923e,'name');_0x2ee71a[_0x5f83('0x2c')]=_['keys'](_0x563883[_0x5f83('0x2c')]);_0x2ee71a[_0x5f83('0x2d')]=_[_0x5f83('0x2e')](_0x2ee71a[_0x5f83('0x2b')],_0x2ee71a[_0x5f83('0x2c')]);_0x364854[_0x5f83('0x2f')]=_[_0x5f83('0x2e')](_0x2ee71a[_0x5f83('0x2b')],qs[_0x5f83('0x30')](_0x563883[_0x5f83('0x2c')][_0x5f83('0x30')]));_0x364854['attributes']=_0x364854[_0x5f83('0x2f')]['length']?_0x364854[_0x5f83('0x2f')]:_0x2ee71a[_0x5f83('0x2b')];if(!_0x563883[_0x5f83('0x2c')][_0x5f83('0x31')](_0x5f83('0x32'))){_0x364854[_0x5f83('0x1d')]=qs[_0x5f83('0x1d')](_0x563883[_0x5f83('0x2c')][_0x5f83('0x1d')]);_0x364854[_0x5f83('0x1c')]=qs[_0x5f83('0x1c')](_0x563883['query'][_0x5f83('0x1c')]);}_0x364854['order']=qs[_0x5f83('0x33')](_0x563883['query'][_0x5f83('0x33')]);_0x364854[_0x5f83('0x34')]=qs['filters'](_[_0x5f83('0x35')](_0x563883[_0x5f83('0x2c')],_0x2ee71a[_0x5f83('0x2d')]),_0x4f923e);if(_0x563883[_0x5f83('0x2c')][_0x5f83('0x36')]){_0x364854[_0x5f83('0x34')]=_['merge'](_0x364854[_0x5f83('0x34')],{'$or':_[_0x5f83('0x27')](_0x4f923e,function(_0x381a4b){if(_0x381a4b[_0x5f83('0x29')]!=='VIRTUAL'){var _0x3375ef={};_0x3375ef[_0x381a4b['name']]={'$like':'%'+_0x563883['query'][_0x5f83('0x36')]+'%'};return _0x3375ef;}})});}_0x364854=_[_0x5f83('0x37')]({},_0x364854,_0x563883['options']);var _0x2f02d8={'where':_0x364854[_0x5f83('0x34')]};return db['IntegrationReport'][_0x5f83('0x1b')](_0x2f02d8)['then'](function(_0x3a750a){_0x5044c8[_0x5f83('0x1b')]=_0x3a750a;if(_0x563883[_0x5f83('0x2c')][_0x5f83('0x38')]){_0x364854[_0x5f83('0x39')]=[{'all':!![]}];}return db[_0x5f83('0x3a')][_0x5f83('0x3b')](_0x364854);})[_0x5f83('0x22')](function(_0x59f947){_0x5044c8[_0x5f83('0x3c')]=_0x59f947;return _0x5044c8;})[_0x5f83('0x22')](respondWithFilteredResult(_0x5efe34,_0x364854))[_0x5f83('0x3d')](handleError(_0x5efe34,null));};exports[_0x5f83('0x3e')]=function(_0x7e6c9c,_0x57ecb8){var _0x41fc16={'raw':![],'where':{'id':_0x7e6c9c[_0x5f83('0x3f')]['id']}},_0x29d616={};_0x29d616[_0x5f83('0x2b')]=_['keys'](db[_0x5f83('0x3a')][_0x5f83('0x40')]);_0x29d616[_0x5f83('0x2c')]=_[_0x5f83('0x41')](_0x7e6c9c[_0x5f83('0x2c')]);_0x29d616[_0x5f83('0x2d')]=_[_0x5f83('0x2e')](_0x29d616[_0x5f83('0x2b')],_0x29d616[_0x5f83('0x2c')]);_0x41fc16[_0x5f83('0x2f')]=_[_0x5f83('0x2e')](_0x29d616['model'],qs[_0x5f83('0x30')](_0x7e6c9c[_0x5f83('0x2c')]['fields']));_0x41fc16[_0x5f83('0x2f')]=_0x41fc16[_0x5f83('0x2f')][_0x5f83('0x42')]?_0x41fc16[_0x5f83('0x2f')]:_0x29d616[_0x5f83('0x2b')];if(_0x7e6c9c[_0x5f83('0x2c')][_0x5f83('0x38')]){_0x41fc16[_0x5f83('0x39')]=[{'all':!![]}];}_0x41fc16=_[_0x5f83('0x37')]({},_0x41fc16,_0x7e6c9c['options']);return db[_0x5f83('0x3a')][_0x5f83('0x43')](_0x41fc16)['then'](handleEntityNotFound(_0x57ecb8,null))['then'](respondWithResult(_0x57ecb8,null))[_0x5f83('0x3d')](handleError(_0x57ecb8,null));};exports[_0x5f83('0x44')]=function(_0x3018e7,_0xfa8e87){return db['IntegrationReport'][_0x5f83('0x44')](_0x3018e7[_0x5f83('0x45')],{})[_0x5f83('0x22')](respondWithResult(_0xfa8e87,0xc9))[_0x5f83('0x3d')](handleError(_0xfa8e87,null));};exports[_0x5f83('0x21')]=function(_0x1fff5c,_0x48f7c7){if(_0x1fff5c[_0x5f83('0x45')]['id']){delete _0x1fff5c[_0x5f83('0x45')]['id'];}return db[_0x5f83('0x3a')]['find']({'where':{'id':_0x1fff5c[_0x5f83('0x3f')]['id']}})[_0x5f83('0x22')](handleEntityNotFound(_0x48f7c7,null))[_0x5f83('0x22')](saveUpdates(_0x1fff5c['body'],null))[_0x5f83('0x22')](respondWithResult(_0x48f7c7,null))[_0x5f83('0x3d')](handleError(_0x48f7c7,null));};exports['destroy']=function(_0x58ff4c,_0x14ecdd){return db[_0x5f83('0x3a')][_0x5f83('0x43')]({'where':{'id':_0x58ff4c[_0x5f83('0x3f')]['id']}})[_0x5f83('0x22')](handleEntityNotFound(_0x14ecdd,null))[_0x5f83('0x22')](removeEntity(_0x14ecdd,null))[_0x5f83('0x3d')](handleError(_0x14ecdd,null));};exports['describe']=function(_0x608b5c,_0x456d43){return db[_0x5f83('0x3a')][_0x5f83('0x46')]()['then'](respondWithResult(_0x456d43,null))[_0x5f83('0x3d')](handleError(_0x456d43,null));};