f6d081e6b30abb847efc4e663849c5b259b4a4f1
[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 _0x96e6=['keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','sort','where','merge','VIRTUAL','includeAll','rows','catch','params','find','create','body','describe','rimraf','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','offset','limit','count','set','update','then','destroy','sendStatus','error','name','send','index','IntegrationReport','rawAttributes','fieldName','type','key','model','map','query'];(function(_0x40c2c9,_0xf6e33c){var _0x52452a=function(_0x4dcd6c){while(--_0x4dcd6c){_0x40c2c9['push'](_0x40c2c9['shift']());}};_0x52452a(++_0xf6e33c);}(_0x96e6,0x1a5));var _0x696e=function(_0x47f3a8,_0x2ddc81){_0x47f3a8=_0x47f3a8-0x0;var _0x9e2ff4=_0x96e6[_0x47f3a8];return _0x9e2ff4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x696e('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x696e('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x696e('0x2'));var Mustache=require(_0x696e('0x3'));var util=require(_0x696e('0x4'));var path=require(_0x696e('0x5'));var sox=require(_0x696e('0x6'));var csv=require(_0x696e('0x7'));var ejs=require(_0x696e('0x8'));var fs=require('fs');var fs_extra=require(_0x696e('0x9'));var _=require(_0x696e('0xa'));var squel=require(_0x696e('0xb'));var crypto=require('crypto');var jsforce=require(_0x696e('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x696e('0xd'));var Papa=require(_0x696e('0xe'));var Redis=require(_0x696e('0xf'));var authService=require(_0x696e('0x10'));var qs=require(_0x696e('0x11'));var as=require(_0x696e('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x696e('0x13'))(_0x696e('0x14'));var utils=require(_0x696e('0x15'));var config=require(_0x696e('0x16'));var licenseUtil=require(_0x696e('0x17'));var db=require(_0x696e('0x18'))['db'];function respondWithStatusCode(_0x591357,_0x4999ff){_0x4999ff=_0x4999ff||0xcc;return function(_0x3bb267){if(_0x3bb267){return _0x591357['sendStatus'](_0x4999ff);}return _0x591357['status'](_0x4999ff)[_0x696e('0x19')]();};}function respondWithResult(_0x50e675,_0x1af1c4){_0x1af1c4=_0x1af1c4||0xc8;return function(_0x1297ae){if(_0x1297ae){return _0x50e675[_0x696e('0x1a')](_0x1af1c4)[_0x696e('0x1b')](_0x1297ae);}};}function respondWithFilteredResult(_0x1b6e10,_0x421d11){return function(_0x5e5968){if(_0x5e5968){var _0x568370=typeof _0x421d11[_0x696e('0x1c')]==='undefined'&&typeof _0x421d11[_0x696e('0x1d')]==='undefined';var _0x5af8ae=_0x5e5968[_0x696e('0x1e')];var _0x4c2137=_0x568370?0x0:_0x421d11[_0x696e('0x1c')];var _0x30b2d5=_0x568370?_0x5e5968[_0x696e('0x1e')]:_0x421d11['offset']+_0x421d11[_0x696e('0x1d')];var _0x320561;if(_0x30b2d5>=_0x5af8ae){_0x30b2d5=_0x5af8ae;_0x320561=0xc8;}else{_0x320561=0xce;}_0x1b6e10['status'](_0x320561);return _0x1b6e10[_0x696e('0x1f')]('Content-Range',_0x4c2137+'-'+_0x30b2d5+'/'+_0x5af8ae)[_0x696e('0x1b')](_0x5e5968);}return null;};}function patchUpdates(_0x1cbbaa){return function(_0x54e6ea){try{jsonpatch['apply'](_0x54e6ea,_0x1cbbaa,!![]);}catch(_0x3dfe63){return BPromise['reject'](_0x3dfe63);}return _0x54e6ea['save']();};}function saveUpdates(_0x2a7c7e,_0x7b38aa){return function(_0x34770e){if(_0x34770e){return _0x34770e[_0x696e('0x20')](_0x2a7c7e)[_0x696e('0x21')](function(_0x5df002){return _0x5df002;});}return null;};}function removeEntity(_0x216d6d,_0x1f1e30){return function(_0x1c49c6){if(_0x1c49c6){return _0x1c49c6[_0x696e('0x22')]()[_0x696e('0x21')](function(){_0x216d6d[_0x696e('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1e1cf9,_0x403a91){return function(_0x43110e){if(!_0x43110e){_0x1e1cf9[_0x696e('0x23')](0x194);}return _0x43110e;};}function handleError(_0x155988,_0xcc7f90){_0xcc7f90=_0xcc7f90||0x1f4;return function(_0x3af8bb){logger[_0x696e('0x24')](_0x3af8bb['stack']);if(_0x3af8bb[_0x696e('0x25')]){delete _0x3af8bb[_0x696e('0x25')];}_0x155988[_0x696e('0x1a')](_0xcc7f90)[_0x696e('0x26')](_0x3af8bb);};}exports[_0x696e('0x27')]=function(_0x38171c,_0x313cb2){var _0x48dd91={},_0x447964={},_0x14d09c={'count':0x0,'rows':[]};var _0x4900f7=_['map'](db[_0x696e('0x28')][_0x696e('0x29')],function(_0x25c591){return{'name':_0x25c591[_0x696e('0x2a')],'type':_0x25c591[_0x696e('0x2b')][_0x696e('0x2c')]};});_0x447964[_0x696e('0x2d')]=_[_0x696e('0x2e')](_0x4900f7,_0x696e('0x25'));_0x447964[_0x696e('0x2f')]=_[_0x696e('0x30')](_0x38171c[_0x696e('0x2f')]);_0x447964[_0x696e('0x31')]=_['intersection'](_0x447964[_0x696e('0x2d')],_0x447964['query']);_0x48dd91['attributes']=_[_0x696e('0x32')](_0x447964[_0x696e('0x2d')],qs[_0x696e('0x33')](_0x38171c[_0x696e('0x2f')][_0x696e('0x33')]));_0x48dd91[_0x696e('0x34')]=_0x48dd91[_0x696e('0x34')]['length']?_0x48dd91[_0x696e('0x34')]:_0x447964[_0x696e('0x2d')];if(!_0x38171c['query'][_0x696e('0x35')](_0x696e('0x36'))){_0x48dd91[_0x696e('0x1d')]=qs[_0x696e('0x1d')](_0x38171c[_0x696e('0x2f')][_0x696e('0x1d')]);_0x48dd91[_0x696e('0x1c')]=qs[_0x696e('0x1c')](_0x38171c[_0x696e('0x2f')][_0x696e('0x1c')]);}_0x48dd91['order']=qs[_0x696e('0x37')](_0x38171c[_0x696e('0x2f')]['sort']);_0x48dd91[_0x696e('0x38')]=qs[_0x696e('0x31')](_['pick'](_0x38171c['query'],_0x447964[_0x696e('0x31')]),_0x4900f7);if(_0x38171c[_0x696e('0x2f')]['filter']){_0x48dd91[_0x696e('0x38')]=_[_0x696e('0x39')](_0x48dd91['where'],{'$or':_[_0x696e('0x2e')](_0x4900f7,function(_0x5aeb0e){if(_0x5aeb0e['type']!==_0x696e('0x3a')){var _0x467b7c={};_0x467b7c[_0x5aeb0e[_0x696e('0x25')]]={'$like':'%'+_0x38171c['query']['filter']+'%'};return _0x467b7c;}})});}_0x48dd91=_[_0x696e('0x39')]({},_0x48dd91,_0x38171c['options']);var _0x5072c7={'where':_0x48dd91[_0x696e('0x38')]};return db[_0x696e('0x28')][_0x696e('0x1e')](_0x5072c7)[_0x696e('0x21')](function(_0x3f0d72){_0x14d09c[_0x696e('0x1e')]=_0x3f0d72;if(_0x38171c[_0x696e('0x2f')][_0x696e('0x3b')]){_0x48dd91['include']=[{'all':!![]}];}return db[_0x696e('0x28')]['findAll'](_0x48dd91);})[_0x696e('0x21')](function(_0x48b29c){_0x14d09c[_0x696e('0x3c')]=_0x48b29c;return _0x14d09c;})[_0x696e('0x21')](respondWithFilteredResult(_0x313cb2,_0x48dd91))[_0x696e('0x3d')](handleError(_0x313cb2,null));};exports['show']=function(_0x338596,_0x5a7962){var _0x3f4995={'raw':![],'where':{'id':_0x338596[_0x696e('0x3e')]['id']}},_0x2e5487={};_0x2e5487[_0x696e('0x2d')]=_[_0x696e('0x30')](db[_0x696e('0x28')][_0x696e('0x29')]);_0x2e5487['query']=_[_0x696e('0x30')](_0x338596[_0x696e('0x2f')]);_0x2e5487[_0x696e('0x31')]=_[_0x696e('0x32')](_0x2e5487[_0x696e('0x2d')],_0x2e5487[_0x696e('0x2f')]);_0x3f4995['attributes']=_[_0x696e('0x32')](_0x2e5487['model'],qs[_0x696e('0x33')](_0x338596['query'][_0x696e('0x33')]));_0x3f4995['attributes']=_0x3f4995[_0x696e('0x34')]['length']?_0x3f4995[_0x696e('0x34')]:_0x2e5487[_0x696e('0x2d')];if(_0x338596[_0x696e('0x2f')][_0x696e('0x3b')]){_0x3f4995['include']=[{'all':!![]}];}_0x3f4995=_[_0x696e('0x39')]({},_0x3f4995,_0x338596['options']);return db[_0x696e('0x28')][_0x696e('0x3f')](_0x3f4995)[_0x696e('0x21')](handleEntityNotFound(_0x5a7962,null))[_0x696e('0x21')](respondWithResult(_0x5a7962,null))[_0x696e('0x3d')](handleError(_0x5a7962,null));};exports[_0x696e('0x40')]=function(_0x1551c4,_0x14cb0b){return db[_0x696e('0x28')]['create'](_0x1551c4[_0x696e('0x41')],{})[_0x696e('0x21')](respondWithResult(_0x14cb0b,0xc9))[_0x696e('0x3d')](handleError(_0x14cb0b,null));};exports['update']=function(_0x411267,_0x3fb8f9){if(_0x411267[_0x696e('0x41')]['id']){delete _0x411267[_0x696e('0x41')]['id'];}return db[_0x696e('0x28')][_0x696e('0x3f')]({'where':{'id':_0x411267['params']['id']}})[_0x696e('0x21')](handleEntityNotFound(_0x3fb8f9,null))[_0x696e('0x21')](saveUpdates(_0x411267[_0x696e('0x41')],null))[_0x696e('0x21')](respondWithResult(_0x3fb8f9,null))[_0x696e('0x3d')](handleError(_0x3fb8f9,null));};exports['destroy']=function(_0x58a7c7,_0x2723bb){return db[_0x696e('0x28')]['find']({'where':{'id':_0x58a7c7[_0x696e('0x3e')]['id']}})[_0x696e('0x21')](handleEntityNotFound(_0x2723bb,null))[_0x696e('0x21')](removeEntity(_0x2723bb,null))[_0x696e('0x3d')](handleError(_0x2723bb,null));};exports[_0x696e('0x42')]=function(_0x48a020,_0x427554){return db['IntegrationReport'][_0x696e('0x42')]()['then'](respondWithResult(_0x427554,null))[_0x696e('0x3d')](handleError(_0x427554,null));};