Built motion from commit (unavailable).|2.5.26
[motion2.git] / server / api / analyticMetric / analyticMetric.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 _0xf072=['save','then','Metrics','destroy','sendStatus','error','stack','name','send','map','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','VIRTUAL','AnalyticMetric','includeAll','include','findAll','catch','options','find','create','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','status','end','count','offset','limit','set','Content-Range','json','apply','reject'];(function(_0x56daff,_0xadca9a){var _0x132c82=function(_0x19e0d7){while(--_0x19e0d7){_0x56daff['push'](_0x56daff['shift']());}};_0x132c82(++_0xadca9a);}(_0xf072,0x1d9));var _0x2f07=function(_0x2040f4,_0x4fe5cc){_0x2040f4=_0x2040f4-0x0;var _0x4b8540=_0xf072[_0x2040f4];return _0x4b8540;};'use strict';var emlformat=require(_0x2f07('0x0'));var rimraf=require(_0x2f07('0x1'));var zipdir=require(_0x2f07('0x2'));var jsonpatch=require(_0x2f07('0x3'));var rp=require(_0x2f07('0x4'));var moment=require(_0x2f07('0x5'));var BPromise=require(_0x2f07('0x6'));var Mustache=require(_0x2f07('0x7'));var util=require('util');var path=require(_0x2f07('0x8'));var sox=require(_0x2f07('0x9'));var csv=require(_0x2f07('0xa'));var ejs=require(_0x2f07('0xb'));var fs=require('fs');var fs_extra=require(_0x2f07('0xc'));var _=require(_0x2f07('0xd'));var squel=require(_0x2f07('0xe'));var crypto=require(_0x2f07('0xf'));var jsforce=require(_0x2f07('0x10'));var deskjs=require(_0x2f07('0x11'));var toCsv=require(_0x2f07('0xa'));var querystring=require(_0x2f07('0x12'));var Papa=require(_0x2f07('0x13'));var Redis=require('ioredis');var authService=require(_0x2f07('0x14'));var qs=require(_0x2f07('0x15'));var as=require(_0x2f07('0x16'));var hardwareService=require(_0x2f07('0x17'));var logger=require('../../config/logger')(_0x2f07('0x18'));var utils=require(_0x2f07('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x2f07('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1e1d16,_0xbb514f){_0xbb514f=_0xbb514f||0xcc;return function(_0xd3a6){if(_0xd3a6){return _0x1e1d16['sendStatus'](_0xbb514f);}return _0x1e1d16[_0x2f07('0x1b')](_0xbb514f)[_0x2f07('0x1c')]();};}function respondWithResult(_0x57dcd2,_0x1cc5a4){_0x1cc5a4=_0x1cc5a4||0xc8;return function(_0x171380){if(_0x171380){return _0x57dcd2[_0x2f07('0x1b')](_0x1cc5a4)['json'](_0x171380);}};}function respondWithFilteredResult(_0x586dda,_0x3d8b9b){return function(_0x37ffa7){if(_0x37ffa7){var _0x521e99=_0x37ffa7[_0x2f07('0x1d')],_0x3b64b2=_0x3d8b9b['offset'],_0x5337ae=_0x3d8b9b[_0x2f07('0x1e')]+_0x3d8b9b[_0x2f07('0x1f')],_0x60d8e4;if(_0x5337ae>=_0x521e99){_0x5337ae=_0x521e99;_0x60d8e4=0xc8;}else{_0x60d8e4=0xce;}_0x586dda[_0x2f07('0x1b')](_0x60d8e4);return _0x586dda[_0x2f07('0x20')](_0x2f07('0x21'),_0x3b64b2+'-'+_0x5337ae+'/'+_0x521e99)[_0x2f07('0x22')](_0x37ffa7);}return null;};}function patchUpdates(_0x1d7eb8){return function(_0x4f7670){try{jsonpatch[_0x2f07('0x23')](_0x4f7670,_0x1d7eb8,!![]);}catch(_0x319db6){return BPromise[_0x2f07('0x24')](_0x319db6);}return _0x4f7670[_0x2f07('0x25')]();};}function saveUpdates(_0x13c04d,_0x4bb406){return function(_0x253b89){if(_0x253b89){return _0x253b89['update'](_0x13c04d)[_0x2f07('0x26')](function(_0x445808){return _0x445808;});}return null;};}function removeEntity(_0x256f79,_0x5653cd){return function(_0x50f263){if(_0x50f263){return _0x50f263['destroy']()[_0x2f07('0x26')](function(){var _0x4ad315=_0x50f263['get']({'plain':!![]});var _0x34cd67=_0x2f07('0x27');return db['UserProfileResource'][_0x2f07('0x28')]({'where':{'type':_0x34cd67,'resourceId':_0x4ad315['id']}})[_0x2f07('0x26')](function(){return _0x50f263;});})['then'](function(){_0x256f79[_0x2f07('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2e276a,_0x38543f){return function(_0x46a5ec){if(!_0x46a5ec){_0x2e276a[_0x2f07('0x29')](0x194);}return _0x46a5ec;};}function handleError(_0x941e91,_0x50186a){_0x50186a=_0x50186a||0x1f4;return function(_0x27b5da){logger[_0x2f07('0x2a')](_0x27b5da[_0x2f07('0x2b')]);if(_0x27b5da[_0x2f07('0x2c')]){delete _0x27b5da['name'];}_0x941e91[_0x2f07('0x1b')](_0x50186a)[_0x2f07('0x2d')](_0x27b5da);};}exports['index']=function(_0x2da386,_0xf48a98){var _0x449da7={},_0x419b3d={},_0x52f3ac={'count':0x0,'rows':[]};var _0x722218=_[_0x2f07('0x2e')](db['AnalyticMetric'][_0x2f07('0x2f')],function(_0x142b33){return{'name':_0x142b33[_0x2f07('0x30')],'type':_0x142b33['type'][_0x2f07('0x31')]};});_0x419b3d[_0x2f07('0x32')]=_['map'](_0x722218,'name');_0x419b3d[_0x2f07('0x33')]=_[_0x2f07('0x34')](_0x2da386[_0x2f07('0x33')]);_0x419b3d[_0x2f07('0x35')]=_[_0x2f07('0x36')](_0x419b3d[_0x2f07('0x32')],_0x419b3d[_0x2f07('0x33')]);_0x449da7[_0x2f07('0x37')]=_['intersection'](_0x419b3d[_0x2f07('0x32')],qs[_0x2f07('0x38')](_0x2da386[_0x2f07('0x33')][_0x2f07('0x38')]));_0x449da7[_0x2f07('0x37')]=_0x449da7[_0x2f07('0x37')]['length']?_0x449da7[_0x2f07('0x37')]:_0x419b3d[_0x2f07('0x32')];if(!_0x2da386['query'][_0x2f07('0x39')](_0x2f07('0x3a'))){_0x449da7[_0x2f07('0x1f')]=qs[_0x2f07('0x1f')](_0x2da386[_0x2f07('0x33')][_0x2f07('0x1f')]);_0x449da7[_0x2f07('0x1e')]=qs[_0x2f07('0x1e')](_0x2da386[_0x2f07('0x33')]['offset']);}_0x449da7[_0x2f07('0x3b')]=qs[_0x2f07('0x3c')](_0x2da386[_0x2f07('0x33')]['sort']);_0x449da7['where']=qs[_0x2f07('0x35')](_[_0x2f07('0x3d')](_0x2da386['query'],_0x419b3d[_0x2f07('0x35')]),_0x722218);if(_0x2da386['query'][_0x2f07('0x3e')]){_0x449da7[_0x2f07('0x3f')]=_[_0x2f07('0x40')](_0x449da7[_0x2f07('0x3f')],{'$or':_[_0x2f07('0x2e')](_0x722218,function(_0x89c268){if(_0x89c268[_0x2f07('0x41')]!==_0x2f07('0x42')){var _0xb347fd={};_0xb347fd[_0x89c268['name']]={'$like':'%'+_0x2da386[_0x2f07('0x33')]['filter']+'%'};return _0xb347fd;}})});}_0x449da7=_['merge']({},_0x449da7,_0x2da386['options']);var _0x20983c={'where':_0x449da7[_0x2f07('0x3f')]};return db[_0x2f07('0x43')][_0x2f07('0x1d')](_0x20983c)['then'](function(_0x3bcf24){_0x52f3ac['count']=_0x3bcf24;if(_0x2da386['query'][_0x2f07('0x44')]){_0x449da7[_0x2f07('0x45')]=[{'all':!![]}];}return db[_0x2f07('0x43')][_0x2f07('0x46')](_0x449da7);})[_0x2f07('0x26')](function(_0x2f3528){_0x52f3ac['rows']=_0x2f3528;return _0x52f3ac;})[_0x2f07('0x26')](respondWithFilteredResult(_0xf48a98,_0x449da7))[_0x2f07('0x47')](handleError(_0xf48a98,null));};exports['show']=function(_0x300082,_0x56aa1a){var _0x42e67c={'raw':!![],'where':{'id':_0x300082['params']['id']}},_0x532ed9={};_0x532ed9['model']=_[_0x2f07('0x34')](db[_0x2f07('0x43')][_0x2f07('0x2f')]);_0x532ed9['query']=_[_0x2f07('0x34')](_0x300082['query']);_0x532ed9['filters']=_[_0x2f07('0x36')](_0x532ed9['model'],_0x532ed9['query']);_0x42e67c[_0x2f07('0x37')]=_[_0x2f07('0x36')](_0x532ed9[_0x2f07('0x32')],qs[_0x2f07('0x38')](_0x300082[_0x2f07('0x33')][_0x2f07('0x38')]));_0x42e67c[_0x2f07('0x37')]=_0x42e67c[_0x2f07('0x37')]['length']?_0x42e67c['attributes']:_0x532ed9['model'];if(_0x300082['query'][_0x2f07('0x44')]){_0x42e67c[_0x2f07('0x45')]=[{'all':!![]}];}_0x42e67c=_[_0x2f07('0x40')]({},_0x42e67c,_0x300082[_0x2f07('0x48')]);return db['AnalyticMetric'][_0x2f07('0x49')](_0x42e67c)[_0x2f07('0x26')](handleEntityNotFound(_0x56aa1a,null))[_0x2f07('0x26')](respondWithResult(_0x56aa1a,null))[_0x2f07('0x47')](handleError(_0x56aa1a,null));};exports[_0x2f07('0x4a')]=function(_0x41764a,_0x4b887a){return db[_0x2f07('0x43')]['create'](_0x41764a[_0x2f07('0x4b')],{})[_0x2f07('0x26')](function(_0x34046d){var _0xfdb50a=_0x41764a['user'][_0x2f07('0x4c')]({'plain':!![]});if(!_0xfdb50a)throw new Error(_0x2f07('0x4d'));if(_0xfdb50a[_0x2f07('0x4e')]==='user'){var _0x252b7b=_0x34046d[_0x2f07('0x4c')]({'plain':!![]});var _0x1c323e=_0x2f07('0x27');return db[_0x2f07('0x4f')][_0x2f07('0x49')]({'where':{'name':_0x1c323e,'userProfileId':_0xfdb50a[_0x2f07('0x50')]},'raw':!![]})[_0x2f07('0x26')](function(_0x373a51){if(_0x373a51&&_0x373a51['autoAssociation']===0x0){return db[_0x2f07('0x51')][_0x2f07('0x4a')]({'name':_0x252b7b[_0x2f07('0x2c')],'resourceId':_0x252b7b['id'],'type':_0x373a51[_0x2f07('0x2c')],'sectionId':_0x373a51['id']},{})[_0x2f07('0x26')](function(){return _0x34046d;});}else{return _0x34046d;}})[_0x2f07('0x47')](function(_0x4b9dc8){logger[_0x2f07('0x2a')](_0x2f07('0x52'),_0x4b9dc8);throw _0x4b9dc8;});}return _0x34046d;})[_0x2f07('0x26')](respondWithResult(_0x4b887a,0xc9))['catch'](handleError(_0x4b887a,null));};exports[_0x2f07('0x53')]=function(_0x8c0432,_0x345d13){if(_0x8c0432[_0x2f07('0x4b')]['id']){delete _0x8c0432[_0x2f07('0x4b')]['id'];}return db[_0x2f07('0x43')][_0x2f07('0x49')]({'where':{'id':_0x8c0432[_0x2f07('0x54')]['id']}})['then'](handleEntityNotFound(_0x345d13,null))[_0x2f07('0x26')](saveUpdates(_0x8c0432[_0x2f07('0x4b')],null))[_0x2f07('0x26')](respondWithResult(_0x345d13,null))[_0x2f07('0x47')](handleError(_0x345d13,null));};exports['destroy']=function(_0x18c671,_0x505edd){return db[_0x2f07('0x43')][_0x2f07('0x49')]({'where':{'id':_0x18c671[_0x2f07('0x54')]['id']}})[_0x2f07('0x26')](handleEntityNotFound(_0x505edd,null))[_0x2f07('0x26')](removeEntity(_0x505edd,null))[_0x2f07('0x47')](handleError(_0x505edd,null));};