6220d2149a870fb34521b1e7c0bbc8b540b49ab0
[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 _0xa644=['../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','undefined','limit','offset','count','Content-Range','json','apply','then','destroy','error','stack','name','send','IntegrationReport','rawAttributes','fieldName','type','key','model','map','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','options','includeAll','include','catch','show','params','merge','find','create','body','update','describe','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch'];(function(_0x4e8f8b,_0x5c7b1d){var _0x7f6ee8=function(_0x4f7822){while(--_0x4f7822){_0x4e8f8b['push'](_0x4e8f8b['shift']());}};_0x7f6ee8(++_0x5c7b1d);}(_0xa644,0x16c));var _0x4a64=function(_0x144501,_0x2a4576){_0x144501=_0x144501-0x0;var _0x1c2907=_0xa644[_0x144501];return _0x1c2907;};'use strict';var emlformat=require(_0x4a64('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x4a64('0x1'));var rp=require(_0x4a64('0x2'));var moment=require(_0x4a64('0x3'));var BPromise=require(_0x4a64('0x4'));var Mustache=require(_0x4a64('0x5'));var util=require('util');var path=require(_0x4a64('0x6'));var sox=require(_0x4a64('0x7'));var csv=require(_0x4a64('0x8'));var ejs=require(_0x4a64('0x9'));var fs=require('fs');var fs_extra=require(_0x4a64('0xa'));var _=require(_0x4a64('0xb'));var squel=require(_0x4a64('0xc'));var crypto=require(_0x4a64('0xd'));var jsforce=require(_0x4a64('0xe'));var deskjs=require(_0x4a64('0xf'));var toCsv=require(_0x4a64('0x8'));var querystring=require(_0x4a64('0x10'));var Papa=require(_0x4a64('0x11'));var Redis=require('ioredis');var authService=require(_0x4a64('0x12'));var qs=require(_0x4a64('0x13'));var as=require(_0x4a64('0x14'));var hardwareService=require(_0x4a64('0x15'));var logger=require(_0x4a64('0x16'))(_0x4a64('0x17'));var utils=require(_0x4a64('0x18'));var config=require(_0x4a64('0x19'));var licenseUtil=require(_0x4a64('0x1a'));var db=require(_0x4a64('0x1b'))['db'];function respondWithStatusCode(_0x3bcf4b,_0x27349c){_0x27349c=_0x27349c||0xcc;return function(_0xcd768c){if(_0xcd768c){return _0x3bcf4b[_0x4a64('0x1c')](_0x27349c);}return _0x3bcf4b[_0x4a64('0x1d')](_0x27349c)[_0x4a64('0x1e')]();};}function respondWithResult(_0x183862,_0x17e901){_0x17e901=_0x17e901||0xc8;return function(_0x19ea04){if(_0x19ea04){return _0x183862[_0x4a64('0x1d')](_0x17e901)['json'](_0x19ea04);}};}function respondWithFilteredResult(_0x13e4ed,_0x2795fd){return function(_0x536477){if(_0x536477){var _0x10c8e6=typeof _0x2795fd['offset']===_0x4a64('0x1f')&&typeof _0x2795fd[_0x4a64('0x20')]===_0x4a64('0x1f');var _0x2451d1=_0x536477['count'];var _0x5e12d4=_0x10c8e6?0x0:_0x2795fd[_0x4a64('0x21')];var _0x4f6a15=_0x10c8e6?_0x536477[_0x4a64('0x22')]:_0x2795fd[_0x4a64('0x21')]+_0x2795fd[_0x4a64('0x20')];var _0x4d47e6;if(_0x4f6a15>=_0x2451d1){_0x4f6a15=_0x2451d1;_0x4d47e6=0xc8;}else{_0x4d47e6=0xce;}_0x13e4ed[_0x4a64('0x1d')](_0x4d47e6);return _0x13e4ed['set'](_0x4a64('0x23'),_0x5e12d4+'-'+_0x4f6a15+'/'+_0x2451d1)[_0x4a64('0x24')](_0x536477);}return null;};}function patchUpdates(_0x286160){return function(_0x4818ff){try{jsonpatch[_0x4a64('0x25')](_0x4818ff,_0x286160,!![]);}catch(_0x8277a1){return BPromise['reject'](_0x8277a1);}return _0x4818ff['save']();};}function saveUpdates(_0x1b9d12,_0x354819){return function(_0x2d1d56){if(_0x2d1d56){return _0x2d1d56['update'](_0x1b9d12)[_0x4a64('0x26')](function(_0x528268){return _0x528268;});}return null;};}function removeEntity(_0x5af5a6,_0x36b3dc){return function(_0x3767c0){if(_0x3767c0){return _0x3767c0[_0x4a64('0x27')]()[_0x4a64('0x26')](function(){_0x5af5a6[_0x4a64('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4a7a94,_0x5789cd){return function(_0x396daf){if(!_0x396daf){_0x4a7a94[_0x4a64('0x1c')](0x194);}return _0x396daf;};}function handleError(_0x4f1019,_0x12aeaf){_0x12aeaf=_0x12aeaf||0x1f4;return function(_0x27d145){logger[_0x4a64('0x28')](_0x27d145[_0x4a64('0x29')]);if(_0x27d145[_0x4a64('0x2a')]){delete _0x27d145[_0x4a64('0x2a')];}_0x4f1019[_0x4a64('0x1d')](_0x12aeaf)[_0x4a64('0x2b')](_0x27d145);};}exports['index']=function(_0x2e76c3,_0x2258df){var _0x5e0edc={},_0x53c3c0={},_0x1443d3={'count':0x0,'rows':[]};var _0x26cf24=_['map'](db[_0x4a64('0x2c')][_0x4a64('0x2d')],function(_0x1de46b){return{'name':_0x1de46b[_0x4a64('0x2e')],'type':_0x1de46b[_0x4a64('0x2f')][_0x4a64('0x30')]};});_0x53c3c0[_0x4a64('0x31')]=_[_0x4a64('0x32')](_0x26cf24,_0x4a64('0x2a'));_0x53c3c0[_0x4a64('0x33')]=_[_0x4a64('0x34')](_0x2e76c3['query']);_0x53c3c0[_0x4a64('0x35')]=_['intersection'](_0x53c3c0['model'],_0x53c3c0['query']);_0x5e0edc[_0x4a64('0x36')]=_[_0x4a64('0x37')](_0x53c3c0[_0x4a64('0x31')],qs[_0x4a64('0x38')](_0x2e76c3[_0x4a64('0x33')][_0x4a64('0x38')]));_0x5e0edc['attributes']=_0x5e0edc['attributes']['length']?_0x5e0edc[_0x4a64('0x36')]:_0x53c3c0['model'];if(!_0x2e76c3[_0x4a64('0x33')][_0x4a64('0x39')](_0x4a64('0x3a'))){_0x5e0edc['limit']=qs[_0x4a64('0x20')](_0x2e76c3[_0x4a64('0x33')]['limit']);_0x5e0edc[_0x4a64('0x21')]=qs[_0x4a64('0x21')](_0x2e76c3[_0x4a64('0x33')][_0x4a64('0x21')]);}_0x5e0edc[_0x4a64('0x3b')]=qs[_0x4a64('0x3c')](_0x2e76c3['query'][_0x4a64('0x3c')]);_0x5e0edc[_0x4a64('0x3d')]=qs[_0x4a64('0x35')](_[_0x4a64('0x3e')](_0x2e76c3['query'],_0x53c3c0[_0x4a64('0x35')]),_0x26cf24);if(_0x2e76c3[_0x4a64('0x33')][_0x4a64('0x3f')]){_0x5e0edc['where']=_['merge'](_0x5e0edc['where'],{'$or':_[_0x4a64('0x32')](_0x26cf24,function(_0x456b1e){if(_0x456b1e[_0x4a64('0x2f')]!==_0x4a64('0x40')){var _0x35fa93={};_0x35fa93[_0x456b1e[_0x4a64('0x2a')]]={'$like':'%'+_0x2e76c3[_0x4a64('0x33')][_0x4a64('0x3f')]+'%'};return _0x35fa93;}})});}_0x5e0edc=_['merge']({},_0x5e0edc,_0x2e76c3[_0x4a64('0x41')]);var _0x48f2a0={'where':_0x5e0edc[_0x4a64('0x3d')]};return db[_0x4a64('0x2c')][_0x4a64('0x22')](_0x48f2a0)['then'](function(_0x1c6bf6){_0x1443d3[_0x4a64('0x22')]=_0x1c6bf6;if(_0x2e76c3['query'][_0x4a64('0x42')]){_0x5e0edc[_0x4a64('0x43')]=[{'all':!![]}];}return db['IntegrationReport']['findAll'](_0x5e0edc);})[_0x4a64('0x26')](function(_0x10a21d){_0x1443d3['rows']=_0x10a21d;return _0x1443d3;})[_0x4a64('0x26')](respondWithFilteredResult(_0x2258df,_0x5e0edc))[_0x4a64('0x44')](handleError(_0x2258df,null));};exports[_0x4a64('0x45')]=function(_0x535cff,_0x27312c){var _0x161b6c={'raw':![],'where':{'id':_0x535cff[_0x4a64('0x46')]['id']}},_0x138398={};_0x138398[_0x4a64('0x31')]=_['keys'](db[_0x4a64('0x2c')][_0x4a64('0x2d')]);_0x138398[_0x4a64('0x33')]=_[_0x4a64('0x34')](_0x535cff[_0x4a64('0x33')]);_0x138398[_0x4a64('0x35')]=_['intersection'](_0x138398[_0x4a64('0x31')],_0x138398['query']);_0x161b6c['attributes']=_[_0x4a64('0x37')](_0x138398[_0x4a64('0x31')],qs[_0x4a64('0x38')](_0x535cff['query']['fields']));_0x161b6c[_0x4a64('0x36')]=_0x161b6c[_0x4a64('0x36')]['length']?_0x161b6c['attributes']:_0x138398[_0x4a64('0x31')];if(_0x535cff[_0x4a64('0x33')][_0x4a64('0x42')]){_0x161b6c[_0x4a64('0x43')]=[{'all':!![]}];}_0x161b6c=_[_0x4a64('0x47')]({},_0x161b6c,_0x535cff[_0x4a64('0x41')]);return db[_0x4a64('0x2c')][_0x4a64('0x48')](_0x161b6c)[_0x4a64('0x26')](handleEntityNotFound(_0x27312c,null))[_0x4a64('0x26')](respondWithResult(_0x27312c,null))[_0x4a64('0x44')](handleError(_0x27312c,null));};exports[_0x4a64('0x49')]=function(_0x3c3cbe,_0x228921){return db[_0x4a64('0x2c')][_0x4a64('0x49')](_0x3c3cbe[_0x4a64('0x4a')],{})['then'](respondWithResult(_0x228921,0xc9))['catch'](handleError(_0x228921,null));};exports[_0x4a64('0x4b')]=function(_0x6c9222,_0x1d0496){if(_0x6c9222['body']['id']){delete _0x6c9222[_0x4a64('0x4a')]['id'];}return db[_0x4a64('0x2c')][_0x4a64('0x48')]({'where':{'id':_0x6c9222[_0x4a64('0x46')]['id']}})[_0x4a64('0x26')](handleEntityNotFound(_0x1d0496,null))['then'](saveUpdates(_0x6c9222[_0x4a64('0x4a')],null))[_0x4a64('0x26')](respondWithResult(_0x1d0496,null))[_0x4a64('0x44')](handleError(_0x1d0496,null));};exports[_0x4a64('0x27')]=function(_0x81a38e,_0x486dc1){return db[_0x4a64('0x2c')][_0x4a64('0x48')]({'where':{'id':_0x81a38e[_0x4a64('0x46')]['id']}})[_0x4a64('0x26')](handleEntityNotFound(_0x486dc1,null))[_0x4a64('0x26')](removeEntity(_0x486dc1,null))[_0x4a64('0x44')](handleError(_0x486dc1,null));};exports[_0x4a64('0x4c')]=function(_0x1cb9cf,_0x3d189e){return db[_0x4a64('0x2c')][_0x4a64('0x4c')]()[_0x4a64('0x26')](respondWithResult(_0x3d189e,null))[_0x4a64('0x44')](handleError(_0x3d189e,null));};