Built motion from commit (unavailable).|2.5.7
[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 _0x13f6=['name','send','index','map','IntegrationReport','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','nolimit','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','findAll','rows','show','params','include','find','catch','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','save','update','then','destroy','error','stack'];(function(_0xff9eeb,_0x39308f){var _0x9d2183=function(_0x13869e){while(--_0x13869e){_0xff9eeb['push'](_0xff9eeb['shift']());}};_0x9d2183(++_0x39308f);}(_0x13f6,0x162));var _0x613f=function(_0x542a4e,_0x23f7ef){_0x542a4e=_0x542a4e-0x0;var _0x11d75d=_0x13f6[_0x542a4e];return _0x11d75d;};'use strict';var pdf=require(_0x613f('0x0'));var emlformat=require(_0x613f('0x1'));var rimraf=require(_0x613f('0x2'));var zipdir=require(_0x613f('0x3'));var jsonpatch=require(_0x613f('0x4'));var rp=require('request-promise');var moment=require(_0x613f('0x5'));var BPromise=require(_0x613f('0x6'));var Mustache=require(_0x613f('0x7'));var util=require(_0x613f('0x8'));var path=require(_0x613f('0x9'));var sox=require(_0x613f('0xa'));var csv=require(_0x613f('0xb'));var ejs=require(_0x613f('0xc'));var fs=require('fs');var _=require(_0x613f('0xd'));var squel=require(_0x613f('0xe'));var crypto=require(_0x613f('0xf'));var jsforce=require(_0x613f('0x10'));var deskjs=require(_0x613f('0x11'));var toCsv=require('to-csv');var querystring=require(_0x613f('0x12'));var Papa=require(_0x613f('0x13'));var Redis=require(_0x613f('0x14'));var authService=require(_0x613f('0x15'));var qs=require(_0x613f('0x16'));var as=require(_0x613f('0x17'));var hardwareService=require(_0x613f('0x18'));var logger=require(_0x613f('0x19'))('api');var utils=require(_0x613f('0x1a'));var config=require(_0x613f('0x1b'));var licenseUtil=require(_0x613f('0x1c'));var db=require(_0x613f('0x1d'))['db'];function respondWithStatusCode(_0x4e87d7,_0x4236e5){_0x4236e5=_0x4236e5||0xcc;return function(_0x396b95){if(_0x396b95){return _0x4e87d7[_0x613f('0x1e')](_0x4236e5);}return _0x4e87d7[_0x613f('0x1f')](_0x4236e5)[_0x613f('0x20')]();};}function respondWithResult(_0x4a6cf5,_0x558f38){_0x558f38=_0x558f38||0xc8;return function(_0x52d61f){if(_0x52d61f){return _0x4a6cf5[_0x613f('0x1f')](_0x558f38)['json'](_0x52d61f);}};}function respondWithFilteredResult(_0x3989dd,_0x584a79){return function(_0x360cb9){if(_0x360cb9){var _0x301067=_0x360cb9[_0x613f('0x21')],_0x1ddae0=_0x584a79[_0x613f('0x22')],_0x2a28ba=_0x584a79[_0x613f('0x22')]+_0x584a79[_0x613f('0x23')],_0x341303;if(_0x2a28ba>=_0x301067){_0x2a28ba=_0x301067;_0x341303=0xc8;}else{_0x341303=0xce;}_0x3989dd[_0x613f('0x1f')](_0x341303);return _0x3989dd[_0x613f('0x24')](_0x613f('0x25'),_0x1ddae0+'-'+_0x2a28ba+'/'+_0x301067)[_0x613f('0x26')](_0x360cb9);}return null;};}function patchUpdates(_0x460e4c){return function(_0x55729b){try{jsonpatch[_0x613f('0x27')](_0x55729b,_0x460e4c,!![]);}catch(_0x2bde69){return BPromise['reject'](_0x2bde69);}return _0x55729b[_0x613f('0x28')]();};}function saveUpdates(_0x1e16e0,_0x167dc7){return function(_0x1eb91c){if(_0x1eb91c){return _0x1eb91c[_0x613f('0x29')](_0x1e16e0)[_0x613f('0x2a')](function(_0x24280c){return _0x24280c;});}return null;};}function removeEntity(_0xf1a7cc,_0x5ded65){return function(_0x4bb2d9){if(_0x4bb2d9){return _0x4bb2d9[_0x613f('0x2b')]()[_0x613f('0x2a')](function(){_0xf1a7cc[_0x613f('0x1f')](0xcc)[_0x613f('0x20')]();});}};}function handleEntityNotFound(_0x551f1e,_0x4dee33){return function(_0x4c519d){if(!_0x4c519d){_0x551f1e[_0x613f('0x1e')](0x194);}return _0x4c519d;};}function handleError(_0x3bd820,_0x50f634){_0x50f634=_0x50f634||0x1f4;return function(_0x345a2a){logger[_0x613f('0x2c')](_0x345a2a[_0x613f('0x2d')]);if(_0x345a2a[_0x613f('0x2e')]){delete _0x345a2a['name'];}_0x3bd820[_0x613f('0x1f')](_0x50f634)[_0x613f('0x2f')](_0x345a2a);};}exports[_0x613f('0x30')]=function(_0xeab78a,_0x25a32c){var _0x14d728={},_0x55d2b5={},_0x37708a={'count':0x0,'rows':[]};var _0x1e2881=_[_0x613f('0x31')](db[_0x613f('0x32')][_0x613f('0x33')],function(_0x51bc27){return{'name':_0x51bc27[_0x613f('0x34')],'type':_0x51bc27[_0x613f('0x35')]['key']};});_0x55d2b5[_0x613f('0x36')]=_[_0x613f('0x31')](_0x1e2881,_0x613f('0x2e'));_0x55d2b5[_0x613f('0x37')]=_[_0x613f('0x38')](_0xeab78a[_0x613f('0x37')]);_0x55d2b5[_0x613f('0x39')]=_['intersection'](_0x55d2b5['model'],_0x55d2b5[_0x613f('0x37')]);_0x14d728['attributes']=_[_0x613f('0x3a')](_0x55d2b5[_0x613f('0x36')],qs[_0x613f('0x3b')](_0xeab78a[_0x613f('0x37')][_0x613f('0x3b')]));_0x14d728[_0x613f('0x3c')]=_0x14d728[_0x613f('0x3c')]['length']?_0x14d728['attributes']:_0x55d2b5[_0x613f('0x36')];if(!_0xeab78a['query']['hasOwnProperty'](_0x613f('0x3d'))){_0x14d728[_0x613f('0x23')]=qs[_0x613f('0x23')](_0xeab78a[_0x613f('0x37')][_0x613f('0x23')]);_0x14d728['offset']=qs[_0x613f('0x22')](_0xeab78a[_0x613f('0x37')][_0x613f('0x22')]);}_0x14d728['order']=qs[_0x613f('0x3e')](_0xeab78a[_0x613f('0x37')][_0x613f('0x3e')]);_0x14d728[_0x613f('0x3f')]=qs[_0x613f('0x39')](_[_0x613f('0x40')](_0xeab78a[_0x613f('0x37')],_0x55d2b5[_0x613f('0x39')]),_0x1e2881);if(_0xeab78a['query']['filter']){_0x14d728['where']=_[_0x613f('0x41')](_0x14d728['where'],{'$or':_['map'](_0x1e2881,function(_0x4dd354){if(_0x4dd354[_0x613f('0x35')]!==_0x613f('0x42')){var _0x50990b={};_0x50990b[_0x4dd354[_0x613f('0x2e')]]={'$like':'%'+_0xeab78a[_0x613f('0x37')][_0x613f('0x43')]+'%'};return _0x50990b;}})});}_0x14d728=_[_0x613f('0x41')]({},_0x14d728,_0xeab78a[_0x613f('0x44')]);var _0x3759f6={'where':_0x14d728[_0x613f('0x3f')]};return db['IntegrationReport'][_0x613f('0x21')](_0x3759f6)[_0x613f('0x2a')](function(_0xd93d6c){_0x37708a[_0x613f('0x21')]=_0xd93d6c;if(_0xeab78a['query'][_0x613f('0x45')]){_0x14d728['include']=[{'all':!![]}];}return db[_0x613f('0x32')][_0x613f('0x46')](_0x14d728);})[_0x613f('0x2a')](function(_0x3337d0){_0x37708a[_0x613f('0x47')]=_0x3337d0;return _0x37708a;})[_0x613f('0x2a')](respondWithFilteredResult(_0x25a32c,_0x14d728))['catch'](handleError(_0x25a32c,null));};exports[_0x613f('0x48')]=function(_0x3411bc,_0x513700){var _0x294919={'raw':![],'where':{'id':_0x3411bc[_0x613f('0x49')]['id']}},_0x50816a={};_0x50816a[_0x613f('0x36')]=_[_0x613f('0x38')](db[_0x613f('0x32')][_0x613f('0x33')]);_0x50816a[_0x613f('0x37')]=_[_0x613f('0x38')](_0x3411bc[_0x613f('0x37')]);_0x50816a[_0x613f('0x39')]=_[_0x613f('0x3a')](_0x50816a[_0x613f('0x36')],_0x50816a[_0x613f('0x37')]);_0x294919[_0x613f('0x3c')]=_['intersection'](_0x50816a[_0x613f('0x36')],qs[_0x613f('0x3b')](_0x3411bc[_0x613f('0x37')][_0x613f('0x3b')]));_0x294919[_0x613f('0x3c')]=_0x294919[_0x613f('0x3c')]['length']?_0x294919['attributes']:_0x50816a['model'];if(_0x3411bc[_0x613f('0x37')][_0x613f('0x45')]){_0x294919[_0x613f('0x4a')]=[{'all':!![]}];}_0x294919=_[_0x613f('0x41')]({},_0x294919,_0x3411bc[_0x613f('0x44')]);return db[_0x613f('0x32')][_0x613f('0x4b')](_0x294919)['then'](handleEntityNotFound(_0x513700,null))[_0x613f('0x2a')](respondWithResult(_0x513700,null))[_0x613f('0x4c')](handleError(_0x513700,null));};exports[_0x613f('0x4d')]=function(_0x34f0db,_0x397133){return db[_0x613f('0x32')][_0x613f('0x4d')](_0x34f0db[_0x613f('0x4e')],{})['then'](respondWithResult(_0x397133,0xc9))[_0x613f('0x4c')](handleError(_0x397133,null));};exports['update']=function(_0x1e77bf,_0x5c5f63){if(_0x1e77bf[_0x613f('0x4e')]['id']){delete _0x1e77bf['body']['id'];}return db[_0x613f('0x32')][_0x613f('0x4b')]({'where':{'id':_0x1e77bf[_0x613f('0x49')]['id']}})[_0x613f('0x2a')](handleEntityNotFound(_0x5c5f63,null))['then'](saveUpdates(_0x1e77bf[_0x613f('0x4e')],null))[_0x613f('0x2a')](respondWithResult(_0x5c5f63,null))[_0x613f('0x4c')](handleError(_0x5c5f63,null));};exports[_0x613f('0x2b')]=function(_0x18fb41,_0x539d07){return db['IntegrationReport'][_0x613f('0x4b')]({'where':{'id':_0x18fb41[_0x613f('0x49')]['id']}})[_0x613f('0x2a')](handleEntityNotFound(_0x539d07,null))[_0x613f('0x2a')](removeEntity(_0x539d07,null))[_0x613f('0x4c')](handleError(_0x539d07,null));};exports[_0x613f('0x4f')]=function(_0x351e1c,_0x5b7652){return db['IntegrationReport'][_0x613f('0x4f')]()['then'](respondWithResult(_0x5b7652,null))[_0x613f('0x4c')](handleError(_0x5b7652,null));};