Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / analyticFieldReport / analyticFieldReport.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 _0x85dd=['zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','set','apply','reject','save','update','then','destroy','stack','name','map','AnalyticFieldReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','filter','where','VIRTUAL','merge','options','includeAll','include','rows','catch','show','params','find','create','bulkCreate','body','bulkDestroy','ids','addFields','AnalyticCustomReport','findOne','transaction','CustomReportId','findAll','eml-format','rimraf'];(function(_0x11a55c,_0x4eced9){var _0x26c390=function(_0x5b0662){while(--_0x5b0662){_0x11a55c['push'](_0x11a55c['shift']());}};_0x26c390(++_0x4eced9);}(_0x85dd,0xf7));var _0xd85d=function(_0x243b2f,_0x30aa15){_0x243b2f=_0x243b2f-0x0;var _0xcb3c2d=_0x85dd[_0x243b2f];return _0xcb3c2d;};'use strict';var emlformat=require(_0xd85d('0x0'));var rimraf=require(_0xd85d('0x1'));var zipdir=require(_0xd85d('0x2'));var jsonpatch=require(_0xd85d('0x3'));var rp=require(_0xd85d('0x4'));var moment=require(_0xd85d('0x5'));var BPromise=require(_0xd85d('0x6'));var Mustache=require(_0xd85d('0x7'));var util=require(_0xd85d('0x8'));var path=require(_0xd85d('0x9'));var sox=require('sox');var csv=require(_0xd85d('0xa'));var ejs=require(_0xd85d('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xd85d('0xc'));var crypto=require(_0xd85d('0xd'));var jsforce=require(_0xd85d('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xd85d('0xa'));var querystring=require(_0xd85d('0xf'));var Papa=require('papaparse');var Redis=require(_0xd85d('0x10'));var authService=require(_0xd85d('0x11'));var qs=require(_0xd85d('0x12'));var as=require(_0xd85d('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xd85d('0x14'))(_0xd85d('0x15'));var utils=require(_0xd85d('0x16'));var config=require(_0xd85d('0x17'));var licenseUtil=require(_0xd85d('0x18'));var db=require(_0xd85d('0x19'))['db'];function respondWithStatusCode(_0x68d118,_0x15887e){_0x15887e=_0x15887e||0xcc;return function(_0x34e907){if(_0x34e907){return _0x68d118[_0xd85d('0x1a')](_0x15887e);}return _0x68d118[_0xd85d('0x1b')](_0x15887e)[_0xd85d('0x1c')]();};}function respondWithResult(_0xbb9607,_0x4aabb1){_0x4aabb1=_0x4aabb1||0xc8;return function(_0x3f1546){if(_0x3f1546){return _0xbb9607[_0xd85d('0x1b')](_0x4aabb1)[_0xd85d('0x1d')](_0x3f1546);}};}function respondWithFilteredResult(_0x16d95e,_0x55cbb3){return function(_0x3a8b4e){if(_0x3a8b4e){var _0x18a3cb=typeof _0x55cbb3['offset']===_0xd85d('0x1e')&&typeof _0x55cbb3[_0xd85d('0x1f')]==='undefined';var _0x2efc28=_0x3a8b4e[_0xd85d('0x20')];var _0x39bffd=_0x18a3cb?0x0:_0x55cbb3[_0xd85d('0x21')];var _0x38f46c=_0x18a3cb?_0x3a8b4e['count']:_0x55cbb3[_0xd85d('0x21')]+_0x55cbb3[_0xd85d('0x1f')];var _0x1469cd;if(_0x38f46c>=_0x2efc28){_0x38f46c=_0x2efc28;_0x1469cd=0xc8;}else{_0x1469cd=0xce;}_0x16d95e[_0xd85d('0x1b')](_0x1469cd);return _0x16d95e[_0xd85d('0x22')]('Content-Range',_0x39bffd+'-'+_0x38f46c+'/'+_0x2efc28)[_0xd85d('0x1d')](_0x3a8b4e);}return null;};}function patchUpdates(_0xe5a730){return function(_0x5e4c95){try{jsonpatch[_0xd85d('0x23')](_0x5e4c95,_0xe5a730,!![]);}catch(_0x4d43b8){return BPromise[_0xd85d('0x24')](_0x4d43b8);}return _0x5e4c95[_0xd85d('0x25')]();};}function saveUpdates(_0x439259,_0x11ce53){return function(_0x110546){if(_0x110546){return _0x110546[_0xd85d('0x26')](_0x439259)[_0xd85d('0x27')](function(_0xfe7250){return _0xfe7250;});}return null;};}function removeEntity(_0xe69402,_0x186b61){return function(_0x1d5aec){if(_0x1d5aec){return _0x1d5aec[_0xd85d('0x28')]()[_0xd85d('0x27')](function(){_0xe69402[_0xd85d('0x1b')](0xcc)[_0xd85d('0x1c')]();});}};}function handleEntityNotFound(_0xc696aa,_0x30c9fb){return function(_0x8849d2){if(!_0x8849d2){_0xc696aa[_0xd85d('0x1a')](0x194);}return _0x8849d2;};}function handleError(_0x13bd07,_0x21e29b){_0x21e29b=_0x21e29b||0x1f4;return function(_0x37577c){logger['error'](_0x37577c[_0xd85d('0x29')]);if(_0x37577c[_0xd85d('0x2a')]){delete _0x37577c[_0xd85d('0x2a')];}_0x13bd07[_0xd85d('0x1b')](_0x21e29b)['send'](_0x37577c);};}exports['index']=function(_0x2383cc,_0x4452e3){var _0x1e1f7d={},_0x7c7025={},_0xb02739={'count':0x0,'rows':[]};var _0x530d34=_[_0xd85d('0x2b')](db[_0xd85d('0x2c')][_0xd85d('0x2d')],function(_0x148eaf){return{'name':_0x148eaf[_0xd85d('0x2e')],'type':_0x148eaf[_0xd85d('0x2f')][_0xd85d('0x30')]};});_0x7c7025[_0xd85d('0x31')]=_['map'](_0x530d34,'name');_0x7c7025[_0xd85d('0x32')]=_[_0xd85d('0x33')](_0x2383cc[_0xd85d('0x32')]);_0x7c7025[_0xd85d('0x34')]=_[_0xd85d('0x35')](_0x7c7025[_0xd85d('0x31')],_0x7c7025[_0xd85d('0x32')]);_0x1e1f7d['attributes']=_['intersection'](_0x7c7025[_0xd85d('0x31')],qs[_0xd85d('0x36')](_0x2383cc['query'][_0xd85d('0x36')]));_0x1e1f7d[_0xd85d('0x37')]=_0x1e1f7d[_0xd85d('0x37')][_0xd85d('0x38')]?_0x1e1f7d[_0xd85d('0x37')]:_0x7c7025[_0xd85d('0x31')];if(!_0x2383cc[_0xd85d('0x32')][_0xd85d('0x39')]('nolimit')){_0x1e1f7d[_0xd85d('0x1f')]=qs[_0xd85d('0x1f')](_0x2383cc['query'][_0xd85d('0x1f')]);_0x1e1f7d[_0xd85d('0x21')]=qs[_0xd85d('0x21')](_0x2383cc[_0xd85d('0x32')][_0xd85d('0x21')]);}_0x1e1f7d[_0xd85d('0x3a')]=qs[_0xd85d('0x3b')](_0x2383cc[_0xd85d('0x32')][_0xd85d('0x3b')]);_0x1e1f7d['where']=qs['filters'](_['pick'](_0x2383cc[_0xd85d('0x32')],_0x7c7025[_0xd85d('0x34')]),_0x530d34);if(_0x2383cc[_0xd85d('0x32')][_0xd85d('0x3c')]){_0x1e1f7d[_0xd85d('0x3d')]=_['merge'](_0x1e1f7d['where'],{'$or':_[_0xd85d('0x2b')](_0x530d34,function(_0x5d6127){if(_0x5d6127[_0xd85d('0x2f')]!==_0xd85d('0x3e')){var _0x7772d8={};_0x7772d8[_0x5d6127['name']]={'$like':'%'+_0x2383cc[_0xd85d('0x32')]['filter']+'%'};return _0x7772d8;}})});}_0x1e1f7d=_[_0xd85d('0x3f')]({},_0x1e1f7d,_0x2383cc[_0xd85d('0x40')]);var _0x26cc9a={'where':_0x1e1f7d[_0xd85d('0x3d')]};return db[_0xd85d('0x2c')][_0xd85d('0x20')](_0x26cc9a)[_0xd85d('0x27')](function(_0x56c6cf){_0xb02739['count']=_0x56c6cf;if(_0x2383cc[_0xd85d('0x32')][_0xd85d('0x41')]){_0x1e1f7d[_0xd85d('0x42')]=[{'all':!![]}];}return db[_0xd85d('0x2c')]['findAll'](_0x1e1f7d);})[_0xd85d('0x27')](function(_0x3f3d9c){_0xb02739[_0xd85d('0x43')]=_0x3f3d9c;return _0xb02739;})[_0xd85d('0x27')](respondWithFilteredResult(_0x4452e3,_0x1e1f7d))[_0xd85d('0x44')](handleError(_0x4452e3,null));};exports[_0xd85d('0x45')]=function(_0x13a0cc,_0x264c8b){var _0x26ef73={'raw':![],'where':{'id':_0x13a0cc[_0xd85d('0x46')]['id']}},_0x59ff86={};_0x59ff86[_0xd85d('0x31')]=_[_0xd85d('0x33')](db[_0xd85d('0x2c')][_0xd85d('0x2d')]);_0x59ff86[_0xd85d('0x32')]=_['keys'](_0x13a0cc[_0xd85d('0x32')]);_0x59ff86['filters']=_[_0xd85d('0x35')](_0x59ff86[_0xd85d('0x31')],_0x59ff86['query']);_0x26ef73[_0xd85d('0x37')]=_[_0xd85d('0x35')](_0x59ff86['model'],qs[_0xd85d('0x36')](_0x13a0cc[_0xd85d('0x32')][_0xd85d('0x36')]));_0x26ef73[_0xd85d('0x37')]=_0x26ef73[_0xd85d('0x37')][_0xd85d('0x38')]?_0x26ef73[_0xd85d('0x37')]:_0x59ff86[_0xd85d('0x31')];if(_0x13a0cc[_0xd85d('0x32')]['includeAll']){_0x26ef73['include']=[{'all':!![]}];}_0x26ef73=_[_0xd85d('0x3f')]({},_0x26ef73,_0x13a0cc['options']);return db[_0xd85d('0x2c')][_0xd85d('0x47')](_0x26ef73)['then'](handleEntityNotFound(_0x264c8b,null))[_0xd85d('0x27')](respondWithResult(_0x264c8b,null))[_0xd85d('0x44')](handleError(_0x264c8b,null));};exports[_0xd85d('0x48')]=function(_0x16337f,_0xb82e90){return db[_0xd85d('0x2c')]['create'](_0x16337f['body'],{})[_0xd85d('0x27')](respondWithResult(_0xb82e90,0xc9))['catch'](handleError(_0xb82e90,null));};exports[_0xd85d('0x49')]=function(_0x488d74,_0x56fbfd){return db[_0xd85d('0x2c')][_0xd85d('0x49')](_0x488d74[_0xd85d('0x4a')],{'raw':![],'individualHooks':!![]})[_0xd85d('0x27')](respondWithResult(_0x56fbfd,0xc9))[_0xd85d('0x44')](handleError(_0x56fbfd,null));};exports[_0xd85d('0x26')]=function(_0x32484d,_0x95bfd1){if(_0x32484d[_0xd85d('0x4a')]['id']){delete _0x32484d['body']['id'];}return db[_0xd85d('0x2c')][_0xd85d('0x47')]({'where':{'id':_0x32484d['params']['id']}})[_0xd85d('0x27')](handleEntityNotFound(_0x95bfd1,null))['then'](saveUpdates(_0x32484d[_0xd85d('0x4a')],null))[_0xd85d('0x27')](respondWithResult(_0x95bfd1,null))[_0xd85d('0x44')](handleError(_0x95bfd1,null));};exports[_0xd85d('0x28')]=function(_0x5735aa,_0x50bbe4){return db[_0xd85d('0x2c')][_0xd85d('0x47')]({'where':{'id':_0x5735aa[_0xd85d('0x46')]['id']}})[_0xd85d('0x27')](handleEntityNotFound(_0x50bbe4,null))[_0xd85d('0x27')](removeEntity(_0x50bbe4,null))[_0xd85d('0x44')](handleError(_0x50bbe4,null));};exports[_0xd85d('0x4b')]=function(_0x98d42c,_0x2e1ce9){return db[_0xd85d('0x2c')][_0xd85d('0x28')]({'where':{'id':_0x98d42c[_0xd85d('0x32')][_0xd85d('0x4c')]||[]},'raw':![],'individualHooks':!![]})[_0xd85d('0x27')](respondWithResult(_0x2e1ce9,0xcc))['catch'](handleError(_0x2e1ce9,null));};exports[_0xd85d('0x4d')]=function(_0x3a5b38,_0x713220,_0x1cdae9){return db[_0xd85d('0x4e')][_0xd85d('0x4f')]({'where':{'id':_0x3a5b38[_0xd85d('0x46')]['id']}})['then'](handleEntityNotFound(_0x713220,null))[_0xd85d('0x27')](function(_0x1fa129){if(_0x1fa129){return db['sequelize'][_0xd85d('0x50')](function(_0x2eb16f){return db['AnalyticFieldReport'][_0xd85d('0x28')]({'where':{'CustomReportId':_0x3a5b38[_0xd85d('0x46')]['id']},'transaction':_0x2eb16f})['then'](function(_0x3c82b4){var _0x1d94f3=_['map'](_0x3a5b38['body'],function(_0x13ec95){delete _0x13ec95['id'];_0x13ec95[_0xd85d('0x51')]=_0x3a5b38[_0xd85d('0x46')]['id'];return _0x13ec95;});return db[_0xd85d('0x2c')]['bulkCreate'](_0x1d94f3,{'transaction':_0x2eb16f});});})['then'](function(){return db[_0xd85d('0x2c')][_0xd85d('0x52')]({'where':{'CustomReportId':_0x3a5b38[_0xd85d('0x46')]['id']}});});}})[_0xd85d('0x27')](respondWithResult(_0x713220,null))[_0xd85d('0x44')](handleError(_0x713220,null));};