222780b9163827edfb89d09eeeefa9aec42ab99c
[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 _0x0f97=['mustache','util','path','ejs','lodash','squel','crypto','to-csv','querystring','papaparse','ioredis','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','count','offset','limit','set','Content-Range','apply','update','destroy','then','error','stack','name','send','index','map','IntegrationReport','rawAttributes','fieldName','model','query','filters','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','type','VIRTUAL','filter','merge','options','include','findAll','show','keys','length','includeAll','find','catch','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird'];(function(_0x25632f,_0x33af49){var _0x880021=function(_0x39b7d3){while(--_0x39b7d3){_0x25632f['push'](_0x25632f['shift']());}};_0x880021(++_0x33af49);}(_0x0f97,0x196));var _0x70f9=function(_0x42f3a6,_0x45285c){_0x42f3a6=_0x42f3a6-0x0;var _0xdf3c33=_0x0f97[_0x42f3a6];return _0xdf3c33;};'use strict';var pdf=require(_0x70f9('0x0'));var emlformat=require(_0x70f9('0x1'));var rimraf=require(_0x70f9('0x2'));var zipdir=require(_0x70f9('0x3'));var jsonpatch=require(_0x70f9('0x4'));var rp=require(_0x70f9('0x5'));var moment=require(_0x70f9('0x6'));var BPromise=require(_0x70f9('0x7'));var Mustache=require(_0x70f9('0x8'));var util=require(_0x70f9('0x9'));var path=require(_0x70f9('0xa'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x70f9('0xb'));var fs=require('fs');var _=require(_0x70f9('0xc'));var squel=require(_0x70f9('0xd'));var crypto=require(_0x70f9('0xe'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x70f9('0xf'));var querystring=require(_0x70f9('0x10'));var Papa=require(_0x70f9('0x11'));var Redis=require(_0x70f9('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x70f9('0x13'))(_0x70f9('0x14'));var utils=require(_0x70f9('0x15'));var config=require(_0x70f9('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x32568f,_0x2ae8f0){_0x2ae8f0=_0x2ae8f0||0xcc;return function(_0x27d5cd){if(_0x27d5cd){return _0x32568f[_0x70f9('0x17')](_0x2ae8f0);}return _0x32568f[_0x70f9('0x18')](_0x2ae8f0)['end']();};}function respondWithResult(_0x6d9d9f,_0x5186dd){_0x5186dd=_0x5186dd||0xc8;return function(_0x57f942){if(_0x57f942){return _0x6d9d9f['status'](_0x5186dd)['json'](_0x57f942);}};}function respondWithFilteredResult(_0x30b651,_0x4d1deb){return function(_0x2a86bb){if(_0x2a86bb){var _0x36044f=_0x2a86bb[_0x70f9('0x19')],_0x138a8e=_0x4d1deb[_0x70f9('0x1a')],_0x3ce5ed=_0x4d1deb[_0x70f9('0x1a')]+_0x4d1deb[_0x70f9('0x1b')],_0x25b88f;if(_0x3ce5ed>=_0x36044f){_0x3ce5ed=_0x36044f;_0x25b88f=0xc8;}else{_0x25b88f=0xce;}_0x30b651['status'](_0x25b88f);return _0x30b651[_0x70f9('0x1c')](_0x70f9('0x1d'),_0x138a8e+'-'+_0x3ce5ed+'/'+_0x36044f)['json'](_0x2a86bb);}return null;};}function patchUpdates(_0x35ba0b){return function(_0x3634d3){try{jsonpatch[_0x70f9('0x1e')](_0x3634d3,_0x35ba0b,!![]);}catch(_0x22f7f7){return BPromise['reject'](_0x22f7f7);}return _0x3634d3['save']();};}function saveUpdates(_0x14de5c,_0x24a7f1){return function(_0x34e740){if(_0x34e740){return _0x34e740[_0x70f9('0x1f')](_0x14de5c)['then'](function(_0x15d7a8){return _0x15d7a8;});}return null;};}function removeEntity(_0x5156d5,_0x454339){return function(_0x309afd){if(_0x309afd){return _0x309afd[_0x70f9('0x20')]()[_0x70f9('0x21')](function(){_0x5156d5[_0x70f9('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x440f34,_0x38479d){return function(_0x388f13){if(!_0x388f13){_0x440f34['sendStatus'](0x194);}return _0x388f13;};}function handleError(_0x47057b,_0x474474){_0x474474=_0x474474||0x1f4;return function(_0xcc9c19){logger[_0x70f9('0x22')](_0xcc9c19[_0x70f9('0x23')]);if(_0xcc9c19['name']){delete _0xcc9c19[_0x70f9('0x24')];}_0x47057b[_0x70f9('0x18')](_0x474474)[_0x70f9('0x25')](_0xcc9c19);};}exports[_0x70f9('0x26')]=function(_0x345c11,_0xfe324e){var _0x54ddcd={},_0x470d0c={},_0x37d551={'count':0x0,'rows':[]};var _0x1a0da5=_[_0x70f9('0x27')](db[_0x70f9('0x28')][_0x70f9('0x29')],function(_0x3e29b9){return{'name':_0x3e29b9[_0x70f9('0x2a')],'type':_0x3e29b9['type']['key']};});_0x470d0c[_0x70f9('0x2b')]=_[_0x70f9('0x27')](_0x1a0da5,_0x70f9('0x24'));_0x470d0c['query']=_['keys'](_0x345c11[_0x70f9('0x2c')]);_0x470d0c[_0x70f9('0x2d')]=_['intersection'](_0x470d0c['model'],_0x470d0c[_0x70f9('0x2c')]);_0x54ddcd[_0x70f9('0x2e')]=_['intersection'](_0x470d0c[_0x70f9('0x2b')],qs[_0x70f9('0x2f')](_0x345c11['query'][_0x70f9('0x2f')]));_0x54ddcd[_0x70f9('0x2e')]=_0x54ddcd[_0x70f9('0x2e')]['length']?_0x54ddcd[_0x70f9('0x2e')]:_0x470d0c[_0x70f9('0x2b')];if(!_0x345c11['query'][_0x70f9('0x30')](_0x70f9('0x31'))){_0x54ddcd['limit']=qs[_0x70f9('0x1b')](_0x345c11[_0x70f9('0x2c')][_0x70f9('0x1b')]);_0x54ddcd[_0x70f9('0x1a')]=qs[_0x70f9('0x1a')](_0x345c11[_0x70f9('0x2c')][_0x70f9('0x1a')]);}_0x54ddcd['order']=qs[_0x70f9('0x32')](_0x345c11[_0x70f9('0x2c')][_0x70f9('0x32')]);_0x54ddcd[_0x70f9('0x33')]=qs[_0x70f9('0x2d')](_[_0x70f9('0x34')](_0x345c11['query'],_0x470d0c[_0x70f9('0x2d')]));if(_0x345c11[_0x70f9('0x2c')]['filter']){_0x54ddcd[_0x70f9('0x33')]=_['merge'](_0x54ddcd[_0x70f9('0x33')],{'$or':_['map'](_0x1a0da5,function(_0x53b955){if(_0x53b955[_0x70f9('0x35')]!==_0x70f9('0x36')){var _0x3385f9={};_0x3385f9[_0x53b955[_0x70f9('0x24')]]={'$like':'%'+_0x345c11[_0x70f9('0x2c')][_0x70f9('0x37')]+'%'};return _0x3385f9;}})});}_0x54ddcd=_[_0x70f9('0x38')]({},_0x54ddcd,_0x345c11[_0x70f9('0x39')]);var _0x16c40c={'where':_0x54ddcd['where']};return db[_0x70f9('0x28')][_0x70f9('0x19')](_0x16c40c)[_0x70f9('0x21')](function(_0x27b717){_0x37d551[_0x70f9('0x19')]=_0x27b717;if(_0x345c11[_0x70f9('0x2c')]['includeAll']){_0x54ddcd[_0x70f9('0x3a')]=[{'all':!![]}];}return db[_0x70f9('0x28')][_0x70f9('0x3b')](_0x54ddcd);})[_0x70f9('0x21')](function(_0x255a8f){_0x37d551['rows']=_0x255a8f;return _0x37d551;})[_0x70f9('0x21')](respondWithFilteredResult(_0xfe324e,_0x54ddcd))['catch'](handleError(_0xfe324e,null));};exports[_0x70f9('0x3c')]=function(_0x4cb3b8,_0x40cdd2){var _0x54452c={'raw':![],'where':{'id':_0x4cb3b8['params']['id']}},_0x8c3827={};_0x8c3827['model']=_[_0x70f9('0x3d')](db['IntegrationReport'][_0x70f9('0x29')]);_0x8c3827['query']=_[_0x70f9('0x3d')](_0x4cb3b8[_0x70f9('0x2c')]);_0x8c3827[_0x70f9('0x2d')]=_['intersection'](_0x8c3827['model'],_0x8c3827[_0x70f9('0x2c')]);_0x54452c[_0x70f9('0x2e')]=_['intersection'](_0x8c3827[_0x70f9('0x2b')],qs[_0x70f9('0x2f')](_0x4cb3b8[_0x70f9('0x2c')][_0x70f9('0x2f')]));_0x54452c[_0x70f9('0x2e')]=_0x54452c[_0x70f9('0x2e')][_0x70f9('0x3e')]?_0x54452c['attributes']:_0x8c3827[_0x70f9('0x2b')];if(_0x4cb3b8[_0x70f9('0x2c')][_0x70f9('0x3f')]){_0x54452c[_0x70f9('0x3a')]=[{'all':!![]}];}_0x54452c=_['merge']({},_0x54452c,_0x4cb3b8[_0x70f9('0x39')]);return db[_0x70f9('0x28')][_0x70f9('0x40')](_0x54452c)[_0x70f9('0x21')](handleEntityNotFound(_0x40cdd2,null))[_0x70f9('0x21')](respondWithResult(_0x40cdd2,null))[_0x70f9('0x41')](handleError(_0x40cdd2,null));};exports['create']=function(_0x34e4da,_0x15a22e){return db[_0x70f9('0x28')][_0x70f9('0x42')](_0x34e4da['body'],{})[_0x70f9('0x21')](respondWithResult(_0x15a22e,0xc9))['catch'](handleError(_0x15a22e,null));};exports[_0x70f9('0x1f')]=function(_0x4a10de,_0x322f0b){if(_0x4a10de[_0x70f9('0x43')]['id']){delete _0x4a10de[_0x70f9('0x43')]['id'];}return db[_0x70f9('0x28')][_0x70f9('0x40')]({'where':{'id':_0x4a10de['params']['id']}})[_0x70f9('0x21')](handleEntityNotFound(_0x322f0b,null))['then'](saveUpdates(_0x4a10de[_0x70f9('0x43')],null))[_0x70f9('0x21')](respondWithResult(_0x322f0b,null))[_0x70f9('0x41')](handleError(_0x322f0b,null));};exports[_0x70f9('0x20')]=function(_0x15b024,_0x59c385){return db[_0x70f9('0x28')]['find']({'where':{'id':_0x15b024['params']['id']}})[_0x70f9('0x21')](handleEntityNotFound(_0x59c385,null))[_0x70f9('0x21')](removeEntity(_0x59c385,null))['catch'](handleError(_0x59c385,null));};exports[_0x70f9('0x44')]=function(_0x175083,_0x3e9fa5){return db[_0x70f9('0x28')][_0x70f9('0x44')]()[_0x70f9('0x21')](respondWithResult(_0x3e9fa5,null))[_0x70f9('0x41')](handleError(_0x3e9fa5,null));};