Built motion from commit (unavailable).|2.5.26
[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 _0x7f47=['rows','catch','rawAttributes','includeAll','include','find','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','fs-extra','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','count','offset','limit','status','Content-Range','json','apply','reject','save','update','then','destroy','error','name','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','where','merge','VIRTUAL','filter','options','IntegrationReport'];(function(_0x321248,_0x1bf881){var _0x32db83=function(_0x2321fc){while(--_0x2321fc){_0x321248['push'](_0x321248['shift']());}};_0x32db83(++_0x1bf881);}(_0x7f47,0x12e));var _0x77f4=function(_0x1d3791,_0x51c613){_0x1d3791=_0x1d3791-0x0;var _0x40fbf5=_0x7f47[_0x1d3791];return _0x40fbf5;};'use strict';var emlformat=require(_0x77f4('0x0'));var rimraf=require(_0x77f4('0x1'));var zipdir=require(_0x77f4('0x2'));var jsonpatch=require(_0x77f4('0x3'));var rp=require(_0x77f4('0x4'));var moment=require(_0x77f4('0x5'));var BPromise=require(_0x77f4('0x6'));var Mustache=require(_0x77f4('0x7'));var util=require('util');var path=require(_0x77f4('0x8'));var sox=require(_0x77f4('0x9'));var csv=require(_0x77f4('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x77f4('0xb'));var _=require('lodash');var squel=require(_0x77f4('0xc'));var crypto=require(_0x77f4('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x77f4('0xe'));var toCsv=require('to-csv');var querystring=require(_0x77f4('0xf'));var Papa=require(_0x77f4('0x10'));var Redis=require('ioredis');var authService=require(_0x77f4('0x11'));var qs=require(_0x77f4('0x12'));var as=require(_0x77f4('0x13'));var hardwareService=require(_0x77f4('0x14'));var logger=require('../../config/logger')(_0x77f4('0x15'));var utils=require(_0x77f4('0x16'));var config=require(_0x77f4('0x17'));var licenseUtil=require(_0x77f4('0x18'));var db=require(_0x77f4('0x19'))['db'];function respondWithStatusCode(_0x2a0243,_0x47428a){_0x47428a=_0x47428a||0xcc;return function(_0x15cce6){if(_0x15cce6){return _0x2a0243[_0x77f4('0x1a')](_0x47428a);}return _0x2a0243['status'](_0x47428a)[_0x77f4('0x1b')]();};}function respondWithResult(_0xd23097,_0x15a137){_0x15a137=_0x15a137||0xc8;return function(_0x2fadaf){if(_0x2fadaf){return _0xd23097['status'](_0x15a137)['json'](_0x2fadaf);}};}function respondWithFilteredResult(_0x2d2dbb,_0x18848d){return function(_0x249237){if(_0x249237){var _0x395bb1=_0x249237[_0x77f4('0x1c')],_0x5a8a43=_0x18848d[_0x77f4('0x1d')],_0x310435=_0x18848d[_0x77f4('0x1d')]+_0x18848d[_0x77f4('0x1e')],_0x9ed030;if(_0x310435>=_0x395bb1){_0x310435=_0x395bb1;_0x9ed030=0xc8;}else{_0x9ed030=0xce;}_0x2d2dbb[_0x77f4('0x1f')](_0x9ed030);return _0x2d2dbb['set'](_0x77f4('0x20'),_0x5a8a43+'-'+_0x310435+'/'+_0x395bb1)[_0x77f4('0x21')](_0x249237);}return null;};}function patchUpdates(_0xdf6582){return function(_0x3773a5){try{jsonpatch[_0x77f4('0x22')](_0x3773a5,_0xdf6582,!![]);}catch(_0x39e15c){return BPromise[_0x77f4('0x23')](_0x39e15c);}return _0x3773a5[_0x77f4('0x24')]();};}function saveUpdates(_0x49a688,_0x46ac19){return function(_0x2c7faa){if(_0x2c7faa){return _0x2c7faa[_0x77f4('0x25')](_0x49a688)[_0x77f4('0x26')](function(_0x4067a4){return _0x4067a4;});}return null;};}function removeEntity(_0x20cd71,_0x4ad47b){return function(_0x5ea739){if(_0x5ea739){return _0x5ea739[_0x77f4('0x27')]()[_0x77f4('0x26')](function(){_0x20cd71[_0x77f4('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x12c3d5,_0x4a3e98){return function(_0x508076){if(!_0x508076){_0x12c3d5[_0x77f4('0x1a')](0x194);}return _0x508076;};}function handleError(_0x20519d,_0x560213){_0x560213=_0x560213||0x1f4;return function(_0x16c4a6){logger[_0x77f4('0x28')](_0x16c4a6['stack']);if(_0x16c4a6['name']){delete _0x16c4a6[_0x77f4('0x29')];}_0x20519d[_0x77f4('0x1f')](_0x560213)['send'](_0x16c4a6);};}exports['index']=function(_0x98b961,_0x3d487c){var _0x22a69d={},_0x4bef97={},_0x3f45a1={'count':0x0,'rows':[]};var _0x1542c8=_['map'](db['IntegrationReport']['rawAttributes'],function(_0x5c6c27){return{'name':_0x5c6c27['fieldName'],'type':_0x5c6c27[_0x77f4('0x2a')][_0x77f4('0x2b')]};});_0x4bef97[_0x77f4('0x2c')]=_[_0x77f4('0x2d')](_0x1542c8,_0x77f4('0x29'));_0x4bef97[_0x77f4('0x2e')]=_[_0x77f4('0x2f')](_0x98b961[_0x77f4('0x2e')]);_0x4bef97[_0x77f4('0x30')]=_[_0x77f4('0x31')](_0x4bef97[_0x77f4('0x2c')],_0x4bef97['query']);_0x22a69d[_0x77f4('0x32')]=_['intersection'](_0x4bef97[_0x77f4('0x2c')],qs[_0x77f4('0x33')](_0x98b961[_0x77f4('0x2e')][_0x77f4('0x33')]));_0x22a69d[_0x77f4('0x32')]=_0x22a69d[_0x77f4('0x32')][_0x77f4('0x34')]?_0x22a69d[_0x77f4('0x32')]:_0x4bef97['model'];if(!_0x98b961[_0x77f4('0x2e')][_0x77f4('0x35')](_0x77f4('0x36'))){_0x22a69d[_0x77f4('0x1e')]=qs['limit'](_0x98b961[_0x77f4('0x2e')][_0x77f4('0x1e')]);_0x22a69d[_0x77f4('0x1d')]=qs['offset'](_0x98b961[_0x77f4('0x2e')][_0x77f4('0x1d')]);}_0x22a69d['order']=qs[_0x77f4('0x37')](_0x98b961[_0x77f4('0x2e')][_0x77f4('0x37')]);_0x22a69d['where']=qs['filters'](_[_0x77f4('0x38')](_0x98b961[_0x77f4('0x2e')],_0x4bef97['filters']),_0x1542c8);if(_0x98b961[_0x77f4('0x2e')]['filter']){_0x22a69d[_0x77f4('0x39')]=_[_0x77f4('0x3a')](_0x22a69d[_0x77f4('0x39')],{'$or':_[_0x77f4('0x2d')](_0x1542c8,function(_0x4390e3){if(_0x4390e3['type']!==_0x77f4('0x3b')){var _0x398369={};_0x398369[_0x4390e3[_0x77f4('0x29')]]={'$like':'%'+_0x98b961['query'][_0x77f4('0x3c')]+'%'};return _0x398369;}})});}_0x22a69d=_[_0x77f4('0x3a')]({},_0x22a69d,_0x98b961[_0x77f4('0x3d')]);var _0x4be843={'where':_0x22a69d['where']};return db['IntegrationReport'][_0x77f4('0x1c')](_0x4be843)[_0x77f4('0x26')](function(_0x1ab721){_0x3f45a1[_0x77f4('0x1c')]=_0x1ab721;if(_0x98b961['query']['includeAll']){_0x22a69d['include']=[{'all':!![]}];}return db[_0x77f4('0x3e')]['findAll'](_0x22a69d);})['then'](function(_0x4b098a){_0x3f45a1[_0x77f4('0x3f')]=_0x4b098a;return _0x3f45a1;})[_0x77f4('0x26')](respondWithFilteredResult(_0x3d487c,_0x22a69d))[_0x77f4('0x40')](handleError(_0x3d487c,null));};exports['show']=function(_0x26fed3,_0x372618){var _0x4ed9c9={'raw':![],'where':{'id':_0x26fed3['params']['id']}},_0x56d0d8={};_0x56d0d8[_0x77f4('0x2c')]=_['keys'](db[_0x77f4('0x3e')][_0x77f4('0x41')]);_0x56d0d8['query']=_[_0x77f4('0x2f')](_0x26fed3[_0x77f4('0x2e')]);_0x56d0d8[_0x77f4('0x30')]=_[_0x77f4('0x31')](_0x56d0d8[_0x77f4('0x2c')],_0x56d0d8['query']);_0x4ed9c9['attributes']=_[_0x77f4('0x31')](_0x56d0d8[_0x77f4('0x2c')],qs[_0x77f4('0x33')](_0x26fed3[_0x77f4('0x2e')][_0x77f4('0x33')]));_0x4ed9c9[_0x77f4('0x32')]=_0x4ed9c9[_0x77f4('0x32')][_0x77f4('0x34')]?_0x4ed9c9[_0x77f4('0x32')]:_0x56d0d8[_0x77f4('0x2c')];if(_0x26fed3[_0x77f4('0x2e')][_0x77f4('0x42')]){_0x4ed9c9[_0x77f4('0x43')]=[{'all':!![]}];}_0x4ed9c9=_[_0x77f4('0x3a')]({},_0x4ed9c9,_0x26fed3[_0x77f4('0x3d')]);return db[_0x77f4('0x3e')][_0x77f4('0x44')](_0x4ed9c9)['then'](handleEntityNotFound(_0x372618,null))[_0x77f4('0x26')](respondWithResult(_0x372618,null))[_0x77f4('0x40')](handleError(_0x372618,null));};exports[_0x77f4('0x45')]=function(_0x5d4d06,_0x251dfe){return db[_0x77f4('0x3e')][_0x77f4('0x45')](_0x5d4d06['body'],{})[_0x77f4('0x26')](respondWithResult(_0x251dfe,0xc9))[_0x77f4('0x40')](handleError(_0x251dfe,null));};exports['update']=function(_0x39d7bb,_0x186bb8){if(_0x39d7bb[_0x77f4('0x46')]['id']){delete _0x39d7bb['body']['id'];}return db[_0x77f4('0x3e')][_0x77f4('0x44')]({'where':{'id':_0x39d7bb[_0x77f4('0x47')]['id']}})['then'](handleEntityNotFound(_0x186bb8,null))[_0x77f4('0x26')](saveUpdates(_0x39d7bb[_0x77f4('0x46')],null))[_0x77f4('0x26')](respondWithResult(_0x186bb8,null))[_0x77f4('0x40')](handleError(_0x186bb8,null));};exports['destroy']=function(_0x456f19,_0x92f207){return db[_0x77f4('0x3e')]['find']({'where':{'id':_0x456f19['params']['id']}})[_0x77f4('0x26')](handleEntityNotFound(_0x92f207,null))[_0x77f4('0x26')](removeEntity(_0x92f207,null))[_0x77f4('0x40')](handleError(_0x92f207,null));};exports[_0x77f4('0x48')]=function(_0xbb2a3a,_0x158e1c){return db[_0x77f4('0x3e')][_0x77f4('0x48')]()[_0x77f4('0x26')](respondWithResult(_0x158e1c,null))[_0x77f4('0x40')](handleError(_0x158e1c,null));};