Built motion from commit (unavailable).|2.5.4
[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 _0x46f0=['include','findAll','catch','show','params','intersection','find','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','lodash','squel','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','map','IntegrationReport','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','fields','length','nolimit','sort','where','filter','merge','options','includeAll'];(function(_0x2fbaf9,_0x37fc52){var _0x17bb22=function(_0x1740de){while(--_0x1740de){_0x2fbaf9['push'](_0x2fbaf9['shift']());}};_0x17bb22(++_0x37fc52);}(_0x46f0,0xde));var _0x046f=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0x46f0[_0x4a9fb1];return _0x348672;};'use strict';var pdf=require(_0x046f('0x0'));var emlformat=require(_0x046f('0x1'));var rimraf=require(_0x046f('0x2'));var zipdir=require(_0x046f('0x3'));var jsonpatch=require(_0x046f('0x4'));var rp=require(_0x046f('0x5'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x046f('0x6'));var util=require(_0x046f('0x7'));var path=require(_0x046f('0x8'));var sox=require(_0x046f('0x9'));var csv=require(_0x046f('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x046f('0xb'));var squel=require(_0x046f('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x046f('0xd'));var toCsv=require('to-csv');var querystring=require(_0x046f('0xe'));var Papa=require(_0x046f('0xf'));var Redis=require('ioredis');var authService=require(_0x046f('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x046f('0x11'));var hardwareService=require(_0x046f('0x12'));var logger=require('../../config/logger')(_0x046f('0x13'));var utils=require(_0x046f('0x14'));var config=require(_0x046f('0x15'));var db=require(_0x046f('0x16'))['db'];function respondWithStatusCode(_0x7193b1,_0x549e39){_0x549e39=_0x549e39||0xcc;return function(_0xe71b38){if(_0xe71b38){return _0x7193b1[_0x046f('0x17')](_0x549e39);}return _0x7193b1[_0x046f('0x18')](_0x549e39)[_0x046f('0x19')]();};}function respondWithResult(_0x144308,_0x107dad){_0x107dad=_0x107dad||0xc8;return function(_0x4e3573){if(_0x4e3573){return _0x144308['status'](_0x107dad)[_0x046f('0x1a')](_0x4e3573);}};}function respondWithFilteredResult(_0x54e846,_0x589861){return function(_0x46e28e){if(_0x46e28e){var _0x4b155e=_0x46e28e[_0x046f('0x1b')],_0x15e59e=_0x589861['offset'],_0x18a4d1=_0x589861[_0x046f('0x1c')]+_0x589861[_0x046f('0x1d')],_0x48b122;if(_0x18a4d1>=_0x4b155e){_0x18a4d1=_0x4b155e;_0x48b122=0xc8;}else{_0x48b122=0xce;}_0x54e846[_0x046f('0x18')](_0x48b122);return _0x54e846[_0x046f('0x1e')](_0x046f('0x1f'),_0x15e59e+'-'+_0x18a4d1+'/'+_0x4b155e)[_0x046f('0x1a')](_0x46e28e);}return null;};}function patchUpdates(_0x1c35d5){return function(_0x37ae5d){try{jsonpatch[_0x046f('0x20')](_0x37ae5d,_0x1c35d5,!![]);}catch(_0x3946dc){return BPromise[_0x046f('0x21')](_0x3946dc);}return _0x37ae5d[_0x046f('0x22')]();};}function saveUpdates(_0x3f9a1d,_0x16b4d0){return function(_0x8ca5d){if(_0x8ca5d){return _0x8ca5d[_0x046f('0x23')](_0x3f9a1d)[_0x046f('0x24')](function(_0x5112fb){return _0x5112fb;});}return null;};}function removeEntity(_0xc8cc79,_0x4c7564){return function(_0x4f8cd6){if(_0x4f8cd6){return _0x4f8cd6[_0x046f('0x25')]()[_0x046f('0x24')](function(){_0xc8cc79[_0x046f('0x18')](0xcc)[_0x046f('0x19')]();});}};}function handleEntityNotFound(_0x546c2e,_0x32c6e8){return function(_0x477b6b){if(!_0x477b6b){_0x546c2e['sendStatus'](0x194);}return _0x477b6b;};}function handleError(_0x43447e,_0x270747){_0x270747=_0x270747||0x1f4;return function(_0x517664){logger[_0x046f('0x26')](_0x517664[_0x046f('0x27')]);if(_0x517664[_0x046f('0x28')]){delete _0x517664['name'];}_0x43447e['status'](_0x270747)[_0x046f('0x29')](_0x517664);};}exports['index']=function(_0x19a49f,_0x47fd1c){var _0x3fd067={},_0x142a41={},_0x1e7412={'count':0x0,'rows':[]};var _0x152f44=_[_0x046f('0x2a')](db[_0x046f('0x2b')][_0x046f('0x2c')],function(_0x1b7434){return{'name':_0x1b7434[_0x046f('0x2d')],'type':_0x1b7434[_0x046f('0x2e')][_0x046f('0x2f')]};});_0x142a41[_0x046f('0x30')]=_[_0x046f('0x2a')](_0x152f44,_0x046f('0x28'));_0x142a41['query']=_[_0x046f('0x31')](_0x19a49f[_0x046f('0x32')]);_0x142a41[_0x046f('0x33')]=_['intersection'](_0x142a41['model'],_0x142a41[_0x046f('0x32')]);_0x3fd067[_0x046f('0x34')]=_['intersection'](_0x142a41[_0x046f('0x30')],qs['fields'](_0x19a49f[_0x046f('0x32')][_0x046f('0x35')]));_0x3fd067[_0x046f('0x34')]=_0x3fd067[_0x046f('0x34')][_0x046f('0x36')]?_0x3fd067[_0x046f('0x34')]:_0x142a41['model'];if(!_0x19a49f[_0x046f('0x32')]['hasOwnProperty'](_0x046f('0x37'))){_0x3fd067[_0x046f('0x1d')]=qs['limit'](_0x19a49f[_0x046f('0x32')][_0x046f('0x1d')]);_0x3fd067[_0x046f('0x1c')]=qs[_0x046f('0x1c')](_0x19a49f[_0x046f('0x32')]['offset']);}_0x3fd067['order']=qs['sort'](_0x19a49f[_0x046f('0x32')][_0x046f('0x38')]);_0x3fd067[_0x046f('0x39')]=qs[_0x046f('0x33')](_['pick'](_0x19a49f[_0x046f('0x32')],_0x142a41[_0x046f('0x33')]),_0x152f44);if(_0x19a49f[_0x046f('0x32')][_0x046f('0x3a')]){_0x3fd067['where']=_[_0x046f('0x3b')](_0x3fd067[_0x046f('0x39')],{'$or':_['map'](_0x152f44,function(_0x14e7d9){if(_0x14e7d9[_0x046f('0x2e')]!=='VIRTUAL'){var _0x2cf009={};_0x2cf009[_0x14e7d9['name']]={'$like':'%'+_0x19a49f[_0x046f('0x32')][_0x046f('0x3a')]+'%'};return _0x2cf009;}})});}_0x3fd067=_[_0x046f('0x3b')]({},_0x3fd067,_0x19a49f[_0x046f('0x3c')]);var _0xb8769a={'where':_0x3fd067[_0x046f('0x39')]};return db[_0x046f('0x2b')][_0x046f('0x1b')](_0xb8769a)[_0x046f('0x24')](function(_0x5ed1ba){_0x1e7412[_0x046f('0x1b')]=_0x5ed1ba;if(_0x19a49f['query'][_0x046f('0x3d')]){_0x3fd067[_0x046f('0x3e')]=[{'all':!![]}];}return db['IntegrationReport'][_0x046f('0x3f')](_0x3fd067);})['then'](function(_0x387645){_0x1e7412['rows']=_0x387645;return _0x1e7412;})[_0x046f('0x24')](respondWithFilteredResult(_0x47fd1c,_0x3fd067))[_0x046f('0x40')](handleError(_0x47fd1c,null));};exports[_0x046f('0x41')]=function(_0x4e3476,_0x3861cc){var _0x5054d8={'raw':![],'where':{'id':_0x4e3476[_0x046f('0x42')]['id']}},_0xde2682={};_0xde2682[_0x046f('0x30')]=_['keys'](db[_0x046f('0x2b')]['rawAttributes']);_0xde2682[_0x046f('0x32')]=_[_0x046f('0x31')](_0x4e3476[_0x046f('0x32')]);_0xde2682[_0x046f('0x33')]=_[_0x046f('0x43')](_0xde2682[_0x046f('0x30')],_0xde2682[_0x046f('0x32')]);_0x5054d8[_0x046f('0x34')]=_[_0x046f('0x43')](_0xde2682[_0x046f('0x30')],qs[_0x046f('0x35')](_0x4e3476[_0x046f('0x32')][_0x046f('0x35')]));_0x5054d8[_0x046f('0x34')]=_0x5054d8[_0x046f('0x34')][_0x046f('0x36')]?_0x5054d8[_0x046f('0x34')]:_0xde2682[_0x046f('0x30')];if(_0x4e3476[_0x046f('0x32')][_0x046f('0x3d')]){_0x5054d8[_0x046f('0x3e')]=[{'all':!![]}];}_0x5054d8=_[_0x046f('0x3b')]({},_0x5054d8,_0x4e3476[_0x046f('0x3c')]);return db[_0x046f('0x2b')][_0x046f('0x44')](_0x5054d8)[_0x046f('0x24')](handleEntityNotFound(_0x3861cc,null))[_0x046f('0x24')](respondWithResult(_0x3861cc,null))[_0x046f('0x40')](handleError(_0x3861cc,null));};exports[_0x046f('0x45')]=function(_0x4e310c,_0x4fe65a){return db[_0x046f('0x2b')][_0x046f('0x45')](_0x4e310c[_0x046f('0x46')],{})[_0x046f('0x24')](respondWithResult(_0x4fe65a,0xc9))['catch'](handleError(_0x4fe65a,null));};exports[_0x046f('0x23')]=function(_0x454efe,_0x4850bd){if(_0x454efe[_0x046f('0x46')]['id']){delete _0x454efe[_0x046f('0x46')]['id'];}return db[_0x046f('0x2b')][_0x046f('0x44')]({'where':{'id':_0x454efe[_0x046f('0x42')]['id']}})[_0x046f('0x24')](handleEntityNotFound(_0x4850bd,null))[_0x046f('0x24')](saveUpdates(_0x454efe[_0x046f('0x46')],null))[_0x046f('0x24')](respondWithResult(_0x4850bd,null))[_0x046f('0x40')](handleError(_0x4850bd,null));};exports['destroy']=function(_0x8f8714,_0x50b165){return db[_0x046f('0x2b')][_0x046f('0x44')]({'where':{'id':_0x8f8714[_0x046f('0x42')]['id']}})[_0x046f('0x24')](handleEntityNotFound(_0x50b165,null))[_0x046f('0x24')](removeEntity(_0x50b165,null))['catch'](handleError(_0x50b165,null));};exports['describe']=function(_0x4fbe7e,_0x138286){return db['IntegrationReport']['describe']()[_0x046f('0x24')](respondWithResult(_0x138286,null))[_0x046f('0x40')](handleError(_0x138286,null));};