Built motion from commit 5b761a7b.|2.5.36
[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 _0xb40e=['set','Content-Range','apply','save','update','then','error','stack','name','send','index','AnalyticTreeReport','fieldName','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','type','options','count','include','findAll','rows','catch','show','params','rawAttributes','create','body','find','rimraf','zip-dir','fast-json-patch','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit'];(function(_0x1e3a27,_0x44ab11){var _0x141fe2=function(_0x297e8f){while(--_0x297e8f){_0x1e3a27['push'](_0x1e3a27['shift']());}};_0x141fe2(++_0x44ab11);}(_0xb40e,0xb7));var _0xeb40=function(_0x546aaf,_0x1ed138){_0x546aaf=_0x546aaf-0x0;var _0x1cbf6d=_0xb40e[_0x546aaf];return _0x1cbf6d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xeb40('0x0'));var zipdir=require(_0xeb40('0x1'));var jsonpatch=require(_0xeb40('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xeb40('0x3'));var Mustache=require('mustache');var util=require('util');var path=require(_0xeb40('0x4'));var sox=require(_0xeb40('0x5'));var csv=require(_0xeb40('0x6'));var ejs=require(_0xeb40('0x7'));var fs=require('fs');var fs_extra=require(_0xeb40('0x8'));var _=require(_0xeb40('0x9'));var squel=require(_0xeb40('0xa'));var crypto=require(_0xeb40('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xeb40('0xc'));var toCsv=require('to-csv');var querystring=require(_0xeb40('0xd'));var Papa=require(_0xeb40('0xe'));var Redis=require(_0xeb40('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xeb40('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xeb40('0x11'))(_0xeb40('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xeb40('0x13'))['db'];function respondWithStatusCode(_0x528898,_0x14076b){_0x14076b=_0x14076b||0xcc;return function(_0x17b5af){if(_0x17b5af){return _0x528898[_0xeb40('0x14')](_0x14076b);}return _0x528898['status'](_0x14076b)[_0xeb40('0x15')]();};}function respondWithResult(_0x44d4d9,_0x4a2115){_0x4a2115=_0x4a2115||0xc8;return function(_0x394640){if(_0x394640){return _0x44d4d9[_0xeb40('0x16')](_0x4a2115)[_0xeb40('0x17')](_0x394640);}};}function respondWithFilteredResult(_0x205fa7,_0x4b38f5){return function(_0x2bda72){if(_0x2bda72){var _0x50dd31=typeof _0x4b38f5[_0xeb40('0x18')]==='undefined'&&typeof _0x4b38f5['limit']===_0xeb40('0x19');var _0x487db2=_0x2bda72['count'];var _0x19f1c7=_0x50dd31?0x0:_0x4b38f5[_0xeb40('0x18')];var _0x41f03f=_0x50dd31?_0x2bda72['count']:_0x4b38f5['offset']+_0x4b38f5[_0xeb40('0x1a')];var _0x1731f6;if(_0x41f03f>=_0x487db2){_0x41f03f=_0x487db2;_0x1731f6=0xc8;}else{_0x1731f6=0xce;}_0x205fa7[_0xeb40('0x16')](_0x1731f6);return _0x205fa7[_0xeb40('0x1b')](_0xeb40('0x1c'),_0x19f1c7+'-'+_0x41f03f+'/'+_0x487db2)[_0xeb40('0x17')](_0x2bda72);}return null;};}function patchUpdates(_0xe30623){return function(_0x1f2bd1){try{jsonpatch[_0xeb40('0x1d')](_0x1f2bd1,_0xe30623,!![]);}catch(_0x1536f5){return BPromise['reject'](_0x1536f5);}return _0x1f2bd1[_0xeb40('0x1e')]();};}function saveUpdates(_0x70c33d,_0x5e45b2){return function(_0x2ad65c){if(_0x2ad65c){return _0x2ad65c[_0xeb40('0x1f')](_0x70c33d)['then'](function(_0x46a3ac){return _0x46a3ac;});}return null;};}function removeEntity(_0x19e95e,_0x1dfbf3){return function(_0x33b2c4){if(_0x33b2c4){return _0x33b2c4['destroy']()[_0xeb40('0x20')](function(){_0x19e95e[_0xeb40('0x16')](0xcc)[_0xeb40('0x15')]();});}};}function handleEntityNotFound(_0x33dd47,_0x952148){return function(_0x3da60f){if(!_0x3da60f){_0x33dd47[_0xeb40('0x14')](0x194);}return _0x3da60f;};}function handleError(_0x57e9bf,_0x459012){_0x459012=_0x459012||0x1f4;return function(_0x3d5172){logger[_0xeb40('0x21')](_0x3d5172[_0xeb40('0x22')]);if(_0x3d5172[_0xeb40('0x23')]){delete _0x3d5172[_0xeb40('0x23')];}_0x57e9bf[_0xeb40('0x16')](_0x459012)[_0xeb40('0x24')](_0x3d5172);};}exports[_0xeb40('0x25')]=function(_0x57aed2,_0x47f389){var _0x6d501f={},_0x14ecd2={},_0xc36f57={'count':0x0,'rows':[]};var _0x410437=_['map'](db[_0xeb40('0x26')]['rawAttributes'],function(_0xe68618){return{'name':_0xe68618[_0xeb40('0x27')],'type':_0xe68618['type'][_0xeb40('0x28')]};});_0x14ecd2[_0xeb40('0x29')]=_[_0xeb40('0x2a')](_0x410437,_0xeb40('0x23'));_0x14ecd2[_0xeb40('0x2b')]=_[_0xeb40('0x2c')](_0x57aed2[_0xeb40('0x2b')]);_0x14ecd2[_0xeb40('0x2d')]=_[_0xeb40('0x2e')](_0x14ecd2[_0xeb40('0x29')],_0x14ecd2[_0xeb40('0x2b')]);_0x6d501f[_0xeb40('0x2f')]=_[_0xeb40('0x2e')](_0x14ecd2['model'],qs[_0xeb40('0x30')](_0x57aed2[_0xeb40('0x2b')][_0xeb40('0x30')]));_0x6d501f[_0xeb40('0x2f')]=_0x6d501f[_0xeb40('0x2f')][_0xeb40('0x31')]?_0x6d501f['attributes']:_0x14ecd2[_0xeb40('0x29')];if(!_0x57aed2['query'][_0xeb40('0x32')]('nolimit')){_0x6d501f[_0xeb40('0x1a')]=qs[_0xeb40('0x1a')](_0x57aed2[_0xeb40('0x2b')]['limit']);_0x6d501f['offset']=qs['offset'](_0x57aed2[_0xeb40('0x2b')][_0xeb40('0x18')]);}_0x6d501f[_0xeb40('0x33')]=qs['sort'](_0x57aed2[_0xeb40('0x2b')][_0xeb40('0x34')]);_0x6d501f[_0xeb40('0x35')]=qs[_0xeb40('0x2d')](_[_0xeb40('0x36')](_0x57aed2['query'],_0x14ecd2[_0xeb40('0x2d')]),_0x410437);if(_0x57aed2[_0xeb40('0x2b')][_0xeb40('0x37')]){_0x6d501f[_0xeb40('0x35')]=_[_0xeb40('0x38')](_0x6d501f[_0xeb40('0x35')],{'$or':_['map'](_0x410437,function(_0x49773f){if(_0x49773f[_0xeb40('0x39')]!=='VIRTUAL'){var _0x33063f={};_0x33063f[_0x49773f['name']]={'$like':'%'+_0x57aed2[_0xeb40('0x2b')][_0xeb40('0x37')]+'%'};return _0x33063f;}})});}_0x6d501f=_[_0xeb40('0x38')]({},_0x6d501f,_0x57aed2[_0xeb40('0x3a')]);var _0x2db190={'where':_0x6d501f[_0xeb40('0x35')]};return db['AnalyticTreeReport']['count'](_0x2db190)[_0xeb40('0x20')](function(_0x151aad){_0xc36f57[_0xeb40('0x3b')]=_0x151aad;if(_0x57aed2['query']['includeAll']){_0x6d501f[_0xeb40('0x3c')]=[{'all':!![]}];}return db['AnalyticTreeReport'][_0xeb40('0x3d')](_0x6d501f);})[_0xeb40('0x20')](function(_0x2eed0f){_0xc36f57[_0xeb40('0x3e')]=_0x2eed0f;return _0xc36f57;})[_0xeb40('0x20')](respondWithFilteredResult(_0x47f389,_0x6d501f))[_0xeb40('0x3f')](handleError(_0x47f389,null));};exports[_0xeb40('0x40')]=function(_0x3f81d5,_0x58fb72){var _0x3f052a={'raw':!![],'where':{'id':_0x3f81d5[_0xeb40('0x41')]['id']}},_0x2cec39={};_0x2cec39[_0xeb40('0x29')]=_[_0xeb40('0x2c')](db[_0xeb40('0x26')][_0xeb40('0x42')]);_0x2cec39[_0xeb40('0x2b')]=_['keys'](_0x3f81d5[_0xeb40('0x2b')]);_0x2cec39[_0xeb40('0x2d')]=_['intersection'](_0x2cec39[_0xeb40('0x29')],_0x2cec39['query']);_0x3f052a[_0xeb40('0x2f')]=_[_0xeb40('0x2e')](_0x2cec39[_0xeb40('0x29')],qs['fields'](_0x3f81d5[_0xeb40('0x2b')][_0xeb40('0x30')]));_0x3f052a[_0xeb40('0x2f')]=_0x3f052a['attributes'][_0xeb40('0x31')]?_0x3f052a['attributes']:_0x2cec39[_0xeb40('0x29')];if(_0x3f81d5[_0xeb40('0x2b')]['includeAll']){_0x3f052a['include']=[{'all':!![]}];}_0x3f052a=_[_0xeb40('0x38')]({},_0x3f052a,_0x3f81d5[_0xeb40('0x3a')]);return db[_0xeb40('0x26')]['find'](_0x3f052a)['then'](handleEntityNotFound(_0x58fb72,null))[_0xeb40('0x20')](respondWithResult(_0x58fb72,null))[_0xeb40('0x3f')](handleError(_0x58fb72,null));};exports['create']=function(_0x4594d0,_0x3e1c0a){return db[_0xeb40('0x26')][_0xeb40('0x43')](_0x4594d0[_0xeb40('0x44')],{})['then'](respondWithResult(_0x3e1c0a,0xc9))[_0xeb40('0x3f')](handleError(_0x3e1c0a,null));};exports[_0xeb40('0x1f')]=function(_0x366154,_0x3cb975){if(_0x366154[_0xeb40('0x44')]['id']){delete _0x366154['body']['id'];}return db[_0xeb40('0x26')][_0xeb40('0x45')]({'where':{'id':_0x366154[_0xeb40('0x41')]['id']}})[_0xeb40('0x20')](handleEntityNotFound(_0x3cb975,null))[_0xeb40('0x20')](saveUpdates(_0x366154[_0xeb40('0x44')],null))['then'](respondWithResult(_0x3cb975,null))[_0xeb40('0x3f')](handleError(_0x3cb975,null));};exports['destroy']=function(_0x41288f,_0x3709be){return db[_0xeb40('0x26')][_0xeb40('0x45')]({'where':{'id':_0x41288f[_0xeb40('0x41')]['id']}})[_0xeb40('0x20')](handleEntityNotFound(_0x3709be,null))[_0xeb40('0x20')](removeEntity(_0x3709be,null))[_0xeb40('0x3f')](handleError(_0x3709be,null));};