2fa051327278d7b309364fa906b4cdc1325d8c2c
[motion2.git] / server / api / analyticTreeReport / analyticTreeReport.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 _0x3dc7=['desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','reject','update','then','destroy','stack','name','send','AnalyticTreeReport','rawAttributes','type','key','model','map','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','VIRTUAL','filter','merge','include','findAll','catch','show','includeAll','options','create','body','find','params','eml-format','zip-dir','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','jsforce'];(function(_0x52e904,_0x1eb4d8){var _0x1fd4e3=function(_0x2f32ce){while(--_0x2f32ce){_0x52e904['push'](_0x52e904['shift']());}};_0x1fd4e3(++_0x1eb4d8);}(_0x3dc7,0x81));var _0x73dc=function(_0x3d4a6e,_0x4f396c){_0x3d4a6e=_0x3d4a6e-0x0;var _0x4ea24f=_0x3dc7[_0x3d4a6e];return _0x4ea24f;};'use strict';var emlformat=require(_0x73dc('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x73dc('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x73dc('0x2'));var moment=require(_0x73dc('0x3'));var BPromise=require(_0x73dc('0x4'));var Mustache=require(_0x73dc('0x5'));var util=require('util');var path=require(_0x73dc('0x6'));var sox=require('sox');var csv=require(_0x73dc('0x7'));var ejs=require(_0x73dc('0x8'));var fs=require('fs');var fs_extra=require(_0x73dc('0x9'));var _=require(_0x73dc('0xa'));var squel=require(_0x73dc('0xb'));var crypto=require('crypto');var jsforce=require(_0x73dc('0xc'));var deskjs=require(_0x73dc('0xd'));var toCsv=require(_0x73dc('0x7'));var querystring=require(_0x73dc('0xe'));var Papa=require(_0x73dc('0xf'));var Redis=require(_0x73dc('0x10'));var authService=require(_0x73dc('0x11'));var qs=require(_0x73dc('0x12'));var as=require(_0x73dc('0x13'));var hardwareService=require(_0x73dc('0x14'));var logger=require(_0x73dc('0x15'))('api');var utils=require(_0x73dc('0x16'));var config=require(_0x73dc('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x73dc('0x18'))['db'];function respondWithStatusCode(_0x27e7ad,_0x2c3b11){_0x2c3b11=_0x2c3b11||0xcc;return function(_0x2d01e5){if(_0x2d01e5){return _0x27e7ad[_0x73dc('0x19')](_0x2c3b11);}return _0x27e7ad[_0x73dc('0x1a')](_0x2c3b11)[_0x73dc('0x1b')]();};}function respondWithResult(_0x3e985c,_0x4bd0ef){_0x4bd0ef=_0x4bd0ef||0xc8;return function(_0x2598cf){if(_0x2598cf){return _0x3e985c['status'](_0x4bd0ef)[_0x73dc('0x1c')](_0x2598cf);}};}function respondWithFilteredResult(_0x40d781,_0x5084b0){return function(_0x30f0de){if(_0x30f0de){var _0x5bae96=typeof _0x5084b0[_0x73dc('0x1d')]===_0x73dc('0x1e')&&typeof _0x5084b0[_0x73dc('0x1f')]===_0x73dc('0x1e');var _0x2efca0=_0x30f0de[_0x73dc('0x20')];var _0x5d7e9d=_0x5bae96?0x0:_0x5084b0['offset'];var _0x22fdb7=_0x5bae96?_0x30f0de[_0x73dc('0x20')]:_0x5084b0[_0x73dc('0x1d')]+_0x5084b0[_0x73dc('0x1f')];var _0xd1f8fd;if(_0x22fdb7>=_0x2efca0){_0x22fdb7=_0x2efca0;_0xd1f8fd=0xc8;}else{_0xd1f8fd=0xce;}_0x40d781['status'](_0xd1f8fd);return _0x40d781[_0x73dc('0x21')]('Content-Range',_0x5d7e9d+'-'+_0x22fdb7+'/'+_0x2efca0)[_0x73dc('0x1c')](_0x30f0de);}return null;};}function patchUpdates(_0xef2371){return function(_0xbaa1ba){try{jsonpatch['apply'](_0xbaa1ba,_0xef2371,!![]);}catch(_0x47ea1d){return BPromise[_0x73dc('0x22')](_0x47ea1d);}return _0xbaa1ba['save']();};}function saveUpdates(_0x1bb38b,_0x455572){return function(_0x40ec7d){if(_0x40ec7d){return _0x40ec7d[_0x73dc('0x23')](_0x1bb38b)[_0x73dc('0x24')](function(_0x39610c){return _0x39610c;});}return null;};}function removeEntity(_0x32cf33,_0x3c7341){return function(_0x3d0253){if(_0x3d0253){return _0x3d0253[_0x73dc('0x25')]()[_0x73dc('0x24')](function(){_0x32cf33[_0x73dc('0x1a')](0xcc)[_0x73dc('0x1b')]();});}};}function handleEntityNotFound(_0x298361,_0x2ea32b){return function(_0x3e48ae){if(!_0x3e48ae){_0x298361['sendStatus'](0x194);}return _0x3e48ae;};}function handleError(_0x1b5166,_0x3cdb53){_0x3cdb53=_0x3cdb53||0x1f4;return function(_0x6c4cd6){logger['error'](_0x6c4cd6[_0x73dc('0x26')]);if(_0x6c4cd6[_0x73dc('0x27')]){delete _0x6c4cd6[_0x73dc('0x27')];}_0x1b5166['status'](_0x3cdb53)[_0x73dc('0x28')](_0x6c4cd6);};}exports['index']=function(_0x3c254d,_0x564d33){var _0x5619fc={},_0x46413c={},_0x40f910={'count':0x0,'rows':[]};var _0x349922=_['map'](db[_0x73dc('0x29')][_0x73dc('0x2a')],function(_0xdfe176){return{'name':_0xdfe176['fieldName'],'type':_0xdfe176[_0x73dc('0x2b')][_0x73dc('0x2c')]};});_0x46413c[_0x73dc('0x2d')]=_[_0x73dc('0x2e')](_0x349922,'name');_0x46413c[_0x73dc('0x2f')]=_['keys'](_0x3c254d[_0x73dc('0x2f')]);_0x46413c[_0x73dc('0x30')]=_[_0x73dc('0x31')](_0x46413c[_0x73dc('0x2d')],_0x46413c[_0x73dc('0x2f')]);_0x5619fc[_0x73dc('0x32')]=_[_0x73dc('0x31')](_0x46413c[_0x73dc('0x2d')],qs['fields'](_0x3c254d[_0x73dc('0x2f')][_0x73dc('0x33')]));_0x5619fc[_0x73dc('0x32')]=_0x5619fc[_0x73dc('0x32')][_0x73dc('0x34')]?_0x5619fc[_0x73dc('0x32')]:_0x46413c[_0x73dc('0x2d')];if(!_0x3c254d[_0x73dc('0x2f')][_0x73dc('0x35')](_0x73dc('0x36'))){_0x5619fc[_0x73dc('0x1f')]=qs[_0x73dc('0x1f')](_0x3c254d[_0x73dc('0x2f')][_0x73dc('0x1f')]);_0x5619fc[_0x73dc('0x1d')]=qs[_0x73dc('0x1d')](_0x3c254d[_0x73dc('0x2f')][_0x73dc('0x1d')]);}_0x5619fc['order']=qs[_0x73dc('0x37')](_0x3c254d['query']['sort']);_0x5619fc[_0x73dc('0x38')]=qs[_0x73dc('0x30')](_[_0x73dc('0x39')](_0x3c254d['query'],_0x46413c[_0x73dc('0x30')]),_0x349922);if(_0x3c254d['query']['filter']){_0x5619fc[_0x73dc('0x38')]=_['merge'](_0x5619fc['where'],{'$or':_[_0x73dc('0x2e')](_0x349922,function(_0x1b9a3a){if(_0x1b9a3a[_0x73dc('0x2b')]!==_0x73dc('0x3a')){var _0x49d810={};_0x49d810[_0x1b9a3a[_0x73dc('0x27')]]={'$like':'%'+_0x3c254d[_0x73dc('0x2f')][_0x73dc('0x3b')]+'%'};return _0x49d810;}})});}_0x5619fc=_[_0x73dc('0x3c')]({},_0x5619fc,_0x3c254d['options']);var _0x38f008={'where':_0x5619fc[_0x73dc('0x38')]};return db['AnalyticTreeReport']['count'](_0x38f008)[_0x73dc('0x24')](function(_0x24cfe1){_0x40f910[_0x73dc('0x20')]=_0x24cfe1;if(_0x3c254d['query']['includeAll']){_0x5619fc[_0x73dc('0x3d')]=[{'all':!![]}];}return db[_0x73dc('0x29')][_0x73dc('0x3e')](_0x5619fc);})[_0x73dc('0x24')](function(_0xea8441){_0x40f910['rows']=_0xea8441;return _0x40f910;})['then'](respondWithFilteredResult(_0x564d33,_0x5619fc))[_0x73dc('0x3f')](handleError(_0x564d33,null));};exports[_0x73dc('0x40')]=function(_0x11e412,_0x372aea){var _0x26f775={'raw':!![],'where':{'id':_0x11e412['params']['id']}},_0x2274fb={};_0x2274fb[_0x73dc('0x2d')]=_['keys'](db[_0x73dc('0x29')][_0x73dc('0x2a')]);_0x2274fb['query']=_['keys'](_0x11e412[_0x73dc('0x2f')]);_0x2274fb['filters']=_[_0x73dc('0x31')](_0x2274fb['model'],_0x2274fb[_0x73dc('0x2f')]);_0x26f775[_0x73dc('0x32')]=_[_0x73dc('0x31')](_0x2274fb[_0x73dc('0x2d')],qs['fields'](_0x11e412[_0x73dc('0x2f')][_0x73dc('0x33')]));_0x26f775[_0x73dc('0x32')]=_0x26f775['attributes']['length']?_0x26f775[_0x73dc('0x32')]:_0x2274fb[_0x73dc('0x2d')];if(_0x11e412['query'][_0x73dc('0x41')]){_0x26f775['include']=[{'all':!![]}];}_0x26f775=_[_0x73dc('0x3c')]({},_0x26f775,_0x11e412[_0x73dc('0x42')]);return db[_0x73dc('0x29')]['find'](_0x26f775)[_0x73dc('0x24')](handleEntityNotFound(_0x372aea,null))[_0x73dc('0x24')](respondWithResult(_0x372aea,null))[_0x73dc('0x3f')](handleError(_0x372aea,null));};exports[_0x73dc('0x43')]=function(_0x1f4e81,_0x51821b){return db[_0x73dc('0x29')][_0x73dc('0x43')](_0x1f4e81[_0x73dc('0x44')],{})['then'](respondWithResult(_0x51821b,0xc9))[_0x73dc('0x3f')](handleError(_0x51821b,null));};exports['update']=function(_0x2735f3,_0x5790ae){if(_0x2735f3['body']['id']){delete _0x2735f3[_0x73dc('0x44')]['id'];}return db[_0x73dc('0x29')][_0x73dc('0x45')]({'where':{'id':_0x2735f3[_0x73dc('0x46')]['id']}})[_0x73dc('0x24')](handleEntityNotFound(_0x5790ae,null))[_0x73dc('0x24')](saveUpdates(_0x2735f3['body'],null))[_0x73dc('0x24')](respondWithResult(_0x5790ae,null))[_0x73dc('0x3f')](handleError(_0x5790ae,null));};exports['destroy']=function(_0xbcc979,_0x3b98bb){return db[_0x73dc('0x29')][_0x73dc('0x45')]({'where':{'id':_0xbcc979[_0x73dc('0x46')]['id']}})['then'](handleEntityNotFound(_0x3b98bb,null))[_0x73dc('0x24')](removeEntity(_0x3b98bb,null))[_0x73dc('0x3f')](handleError(_0x3b98bb,null));};