Built motion from commit 10af8726.|2.6.34
[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 _0xadfa=['fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','catch','show','params','rawAttributes','find','create','body','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','path','ejs','fs-extra','lodash','squel','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','AnalyticTreeReport','fieldName','type','key','model','map','query','keys','filters','intersection','attributes'];(function(_0x48f4e8,_0x6663bb){var _0x51cdaf=function(_0x62dbe9){while(--_0x62dbe9){_0x48f4e8['push'](_0x48f4e8['shift']());}};_0x51cdaf(++_0x6663bb);}(_0xadfa,0x64));var _0xaadf=function(_0x18399d,_0x12cd44){_0x18399d=_0x18399d-0x0;var _0x123685=_0xadfa[_0x18399d];return _0x123685;};'use strict';var emlformat=require(_0xaadf('0x0'));var rimraf=require(_0xaadf('0x1'));var zipdir=require(_0xaadf('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xaadf('0x3'));var moment=require('moment');var BPromise=require(_0xaadf('0x4'));var Mustache=require(_0xaadf('0x5'));var util=require('util');var path=require(_0xaadf('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xaadf('0x7'));var fs=require('fs');var fs_extra=require(_0xaadf('0x8'));var _=require(_0xaadf('0x9'));var squel=require(_0xaadf('0xa'));var crypto=require('crypto');var jsforce=require(_0xaadf('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xaadf('0xc'));var querystring=require(_0xaadf('0xd'));var Papa=require(_0xaadf('0xe'));var Redis=require(_0xaadf('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xaadf('0x10'));var as=require(_0xaadf('0x11'));var hardwareService=require(_0xaadf('0x12'));var logger=require(_0xaadf('0x13'))(_0xaadf('0x14'));var utils=require(_0xaadf('0x15'));var config=require(_0xaadf('0x16'));var licenseUtil=require(_0xaadf('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5a9e9d,_0x51d4f2){_0x51d4f2=_0x51d4f2||0xcc;return function(_0x407391){if(_0x407391){return _0x5a9e9d[_0xaadf('0x18')](_0x51d4f2);}return _0x5a9e9d['status'](_0x51d4f2)[_0xaadf('0x19')]();};}function respondWithResult(_0x374394,_0x37e237){_0x37e237=_0x37e237||0xc8;return function(_0xf92649){if(_0xf92649){return _0x374394[_0xaadf('0x1a')](_0x37e237)[_0xaadf('0x1b')](_0xf92649);}};}function respondWithFilteredResult(_0x1669ca,_0x9399a0){return function(_0x1a80e7){if(_0x1a80e7){var _0x3a78a8=typeof _0x9399a0[_0xaadf('0x1c')]===_0xaadf('0x1d')&&typeof _0x9399a0[_0xaadf('0x1e')]===_0xaadf('0x1d');var _0x31aaf5=_0x1a80e7[_0xaadf('0x1f')];var _0x50bf0b=_0x3a78a8?0x0:_0x9399a0[_0xaadf('0x1c')];var _0x410a8d=_0x3a78a8?_0x1a80e7[_0xaadf('0x1f')]:_0x9399a0['offset']+_0x9399a0[_0xaadf('0x1e')];var _0x3ff5c6;if(_0x410a8d>=_0x31aaf5){_0x410a8d=_0x31aaf5;_0x3ff5c6=0xc8;}else{_0x3ff5c6=0xce;}_0x1669ca[_0xaadf('0x1a')](_0x3ff5c6);return _0x1669ca[_0xaadf('0x20')](_0xaadf('0x21'),_0x50bf0b+'-'+_0x410a8d+'/'+_0x31aaf5)[_0xaadf('0x1b')](_0x1a80e7);}return null;};}function patchUpdates(_0x481a85){return function(_0x45ee8d){try{jsonpatch[_0xaadf('0x22')](_0x45ee8d,_0x481a85,!![]);}catch(_0x292433){return BPromise[_0xaadf('0x23')](_0x292433);}return _0x45ee8d[_0xaadf('0x24')]();};}function saveUpdates(_0x201825,_0xd45bc6){return function(_0x1c0eb2){if(_0x1c0eb2){return _0x1c0eb2[_0xaadf('0x25')](_0x201825)[_0xaadf('0x26')](function(_0x4f972f){return _0x4f972f;});}return null;};}function removeEntity(_0x4e6a65,_0x434d16){return function(_0xa12124){if(_0xa12124){return _0xa12124[_0xaadf('0x27')]()['then'](function(){_0x4e6a65['status'](0xcc)[_0xaadf('0x19')]();});}};}function handleEntityNotFound(_0x3b7017,_0x301aa1){return function(_0x4662cd){if(!_0x4662cd){_0x3b7017[_0xaadf('0x18')](0x194);}return _0x4662cd;};}function handleError(_0x4cade9,_0x53cd31){_0x53cd31=_0x53cd31||0x1f4;return function(_0x460168){logger[_0xaadf('0x28')](_0x460168[_0xaadf('0x29')]);if(_0x460168[_0xaadf('0x2a')]){delete _0x460168['name'];}_0x4cade9['status'](_0x53cd31)[_0xaadf('0x2b')](_0x460168);};}exports[_0xaadf('0x2c')]=function(_0x3ea854,_0x77cc43){var _0x8688cc={},_0x543afb={},_0x59c379={'count':0x0,'rows':[]};var _0x3689f2=_['map'](db[_0xaadf('0x2d')]['rawAttributes'],function(_0x155314){return{'name':_0x155314[_0xaadf('0x2e')],'type':_0x155314[_0xaadf('0x2f')][_0xaadf('0x30')]};});_0x543afb[_0xaadf('0x31')]=_[_0xaadf('0x32')](_0x3689f2,_0xaadf('0x2a'));_0x543afb[_0xaadf('0x33')]=_[_0xaadf('0x34')](_0x3ea854[_0xaadf('0x33')]);_0x543afb[_0xaadf('0x35')]=_[_0xaadf('0x36')](_0x543afb['model'],_0x543afb[_0xaadf('0x33')]);_0x8688cc[_0xaadf('0x37')]=_[_0xaadf('0x36')](_0x543afb[_0xaadf('0x31')],qs[_0xaadf('0x38')](_0x3ea854[_0xaadf('0x33')][_0xaadf('0x38')]));_0x8688cc[_0xaadf('0x37')]=_0x8688cc[_0xaadf('0x37')][_0xaadf('0x39')]?_0x8688cc['attributes']:_0x543afb[_0xaadf('0x31')];if(!_0x3ea854[_0xaadf('0x33')][_0xaadf('0x3a')](_0xaadf('0x3b'))){_0x8688cc[_0xaadf('0x1e')]=qs[_0xaadf('0x1e')](_0x3ea854[_0xaadf('0x33')]['limit']);_0x8688cc['offset']=qs[_0xaadf('0x1c')](_0x3ea854[_0xaadf('0x33')][_0xaadf('0x1c')]);}_0x8688cc[_0xaadf('0x3c')]=qs[_0xaadf('0x3d')](_0x3ea854['query']['sort']);_0x8688cc[_0xaadf('0x3e')]=qs[_0xaadf('0x35')](_[_0xaadf('0x3f')](_0x3ea854[_0xaadf('0x33')],_0x543afb[_0xaadf('0x35')]),_0x3689f2);if(_0x3ea854[_0xaadf('0x33')][_0xaadf('0x40')]){_0x8688cc[_0xaadf('0x3e')]=_[_0xaadf('0x41')](_0x8688cc[_0xaadf('0x3e')],{'$or':_['map'](_0x3689f2,function(_0x480f7b){if(_0x480f7b[_0xaadf('0x2f')]!==_0xaadf('0x42')){var _0x251f90={};_0x251f90[_0x480f7b['name']]={'$like':'%'+_0x3ea854['query'][_0xaadf('0x40')]+'%'};return _0x251f90;}})});}_0x8688cc=_[_0xaadf('0x41')]({},_0x8688cc,_0x3ea854[_0xaadf('0x43')]);var _0x47b663={'where':_0x8688cc['where']};return db[_0xaadf('0x2d')]['count'](_0x47b663)['then'](function(_0x5a2b8b){_0x59c379['count']=_0x5a2b8b;if(_0x3ea854[_0xaadf('0x33')]['includeAll']){_0x8688cc[_0xaadf('0x44')]=[{'all':!![]}];}return db['AnalyticTreeReport'][_0xaadf('0x45')](_0x8688cc);})['then'](function(_0x12cadb){_0x59c379[_0xaadf('0x46')]=_0x12cadb;return _0x59c379;})[_0xaadf('0x26')](respondWithFilteredResult(_0x77cc43,_0x8688cc))[_0xaadf('0x47')](handleError(_0x77cc43,null));};exports[_0xaadf('0x48')]=function(_0x299ecf,_0x47778c){var _0x3cfba9={'raw':!![],'where':{'id':_0x299ecf[_0xaadf('0x49')]['id']}},_0x5748de={};_0x5748de['model']=_[_0xaadf('0x34')](db[_0xaadf('0x2d')][_0xaadf('0x4a')]);_0x5748de[_0xaadf('0x33')]=_[_0xaadf('0x34')](_0x299ecf[_0xaadf('0x33')]);_0x5748de[_0xaadf('0x35')]=_[_0xaadf('0x36')](_0x5748de[_0xaadf('0x31')],_0x5748de[_0xaadf('0x33')]);_0x3cfba9['attributes']=_[_0xaadf('0x36')](_0x5748de[_0xaadf('0x31')],qs['fields'](_0x299ecf[_0xaadf('0x33')][_0xaadf('0x38')]));_0x3cfba9[_0xaadf('0x37')]=_0x3cfba9[_0xaadf('0x37')][_0xaadf('0x39')]?_0x3cfba9['attributes']:_0x5748de['model'];if(_0x299ecf[_0xaadf('0x33')]['includeAll']){_0x3cfba9[_0xaadf('0x44')]=[{'all':!![]}];}_0x3cfba9=_[_0xaadf('0x41')]({},_0x3cfba9,_0x299ecf[_0xaadf('0x43')]);return db['AnalyticTreeReport'][_0xaadf('0x4b')](_0x3cfba9)['then'](handleEntityNotFound(_0x47778c,null))['then'](respondWithResult(_0x47778c,null))[_0xaadf('0x47')](handleError(_0x47778c,null));};exports[_0xaadf('0x4c')]=function(_0x48f02d,_0x554974){return db[_0xaadf('0x2d')][_0xaadf('0x4c')](_0x48f02d[_0xaadf('0x4d')],{})['then'](respondWithResult(_0x554974,0xc9))[_0xaadf('0x47')](handleError(_0x554974,null));};exports[_0xaadf('0x25')]=function(_0x3cd66f,_0x242f78){if(_0x3cd66f[_0xaadf('0x4d')]['id']){delete _0x3cd66f[_0xaadf('0x4d')]['id'];}return db[_0xaadf('0x2d')][_0xaadf('0x4b')]({'where':{'id':_0x3cd66f[_0xaadf('0x49')]['id']}})['then'](handleEntityNotFound(_0x242f78,null))[_0xaadf('0x26')](saveUpdates(_0x3cd66f['body'],null))['then'](respondWithResult(_0x242f78,null))[_0xaadf('0x47')](handleError(_0x242f78,null));};exports[_0xaadf('0x27')]=function(_0x128a1a,_0x491506){return db['AnalyticTreeReport'][_0xaadf('0x4b')]({'where':{'id':_0x128a1a[_0xaadf('0x49')]['id']}})[_0xaadf('0x26')](handleEntityNotFound(_0x491506,null))[_0xaadf('0x26')](removeEntity(_0x491506,null))[_0xaadf('0x47')](handleError(_0x491506,null));};