Built motion from commit (unavailable).|2.5.18
[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 _0x5f53=['destroy','sendStatus','error','stack','name','index','map','AnalyticFieldReport','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','sort','pick','filter','merge','where','VIRTUAL','options','includeAll','findAll','rows','catch','show','include','find','create','body','bulkCreate','params','ids','addFields','AnalyticCustomReport','sequelize','transaction','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','status','end','json','count','offset','limit','Content-Range','apply','reject','update','then'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x5f53,0x178));var _0x35f5=function(_0x546ce7,_0x135234){_0x546ce7=_0x546ce7-0x0;var _0x1e1530=_0x5f53[_0x546ce7];return _0x1e1530;};'use strict';var pdf=require(_0x35f5('0x0'));var emlformat=require(_0x35f5('0x1'));var rimraf=require(_0x35f5('0x2'));var zipdir=require(_0x35f5('0x3'));var jsonpatch=require(_0x35f5('0x4'));var rp=require('request-promise');var moment=require(_0x35f5('0x5'));var BPromise=require(_0x35f5('0x6'));var Mustache=require(_0x35f5('0x7'));var util=require(_0x35f5('0x8'));var path=require(_0x35f5('0x9'));var sox=require(_0x35f5('0xa'));var csv=require(_0x35f5('0xb'));var ejs=require(_0x35f5('0xc'));var fs=require('fs');var _=require(_0x35f5('0xd'));var squel=require(_0x35f5('0xe'));var crypto=require(_0x35f5('0xf'));var jsforce=require(_0x35f5('0x10'));var deskjs=require(_0x35f5('0x11'));var toCsv=require(_0x35f5('0xb'));var querystring=require(_0x35f5('0x12'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x35f5('0x13'));var qs=require(_0x35f5('0x14'));var as=require(_0x35f5('0x15'));var hardwareService=require(_0x35f5('0x16'));var logger=require(_0x35f5('0x17'))(_0x35f5('0x18'));var utils=require(_0x35f5('0x19'));var config=require(_0x35f5('0x1a'));var licenseUtil=require(_0x35f5('0x1b'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1a80ce,_0x12cef){_0x12cef=_0x12cef||0xcc;return function(_0x2e3ce7){if(_0x2e3ce7){return _0x1a80ce['sendStatus'](_0x12cef);}return _0x1a80ce[_0x35f5('0x1c')](_0x12cef)[_0x35f5('0x1d')]();};}function respondWithResult(_0xe5795b,_0x52c577){_0x52c577=_0x52c577||0xc8;return function(_0x151a32){if(_0x151a32){return _0xe5795b['status'](_0x52c577)[_0x35f5('0x1e')](_0x151a32);}};}function respondWithFilteredResult(_0x53f62b,_0x59c538){return function(_0x5860df){if(_0x5860df){var _0x122ea1=_0x5860df[_0x35f5('0x1f')],_0x2fe6da=_0x59c538[_0x35f5('0x20')],_0x3a9900=_0x59c538['offset']+_0x59c538[_0x35f5('0x21')],_0x37f6ab;if(_0x3a9900>=_0x122ea1){_0x3a9900=_0x122ea1;_0x37f6ab=0xc8;}else{_0x37f6ab=0xce;}_0x53f62b[_0x35f5('0x1c')](_0x37f6ab);return _0x53f62b['set'](_0x35f5('0x22'),_0x2fe6da+'-'+_0x3a9900+'/'+_0x122ea1)[_0x35f5('0x1e')](_0x5860df);}return null;};}function patchUpdates(_0x40faf3){return function(_0x5f5d9a){try{jsonpatch[_0x35f5('0x23')](_0x5f5d9a,_0x40faf3,!![]);}catch(_0x1ae213){return BPromise[_0x35f5('0x24')](_0x1ae213);}return _0x5f5d9a['save']();};}function saveUpdates(_0x345788,_0x5c0806){return function(_0xc1cc6d){if(_0xc1cc6d){return _0xc1cc6d[_0x35f5('0x25')](_0x345788)[_0x35f5('0x26')](function(_0x2ada38){return _0x2ada38;});}return null;};}function removeEntity(_0x404bd7,_0x1d688c){return function(_0x416cd8){if(_0x416cd8){return _0x416cd8[_0x35f5('0x27')]()[_0x35f5('0x26')](function(){_0x404bd7[_0x35f5('0x1c')](0xcc)[_0x35f5('0x1d')]();});}};}function handleEntityNotFound(_0x5b3aaa,_0x2b41a6){return function(_0x2e1960){if(!_0x2e1960){_0x5b3aaa[_0x35f5('0x28')](0x194);}return _0x2e1960;};}function handleError(_0x300ad9,_0x39d31c){_0x39d31c=_0x39d31c||0x1f4;return function(_0x17588d){logger[_0x35f5('0x29')](_0x17588d[_0x35f5('0x2a')]);if(_0x17588d[_0x35f5('0x2b')]){delete _0x17588d[_0x35f5('0x2b')];}_0x300ad9[_0x35f5('0x1c')](_0x39d31c)['send'](_0x17588d);};}exports[_0x35f5('0x2c')]=function(_0x49ed47,_0x50ba7b){var _0x153cc0={},_0x4e4372={},_0x4ee27e={'count':0x0,'rows':[]};var _0x4ff339=_[_0x35f5('0x2d')](db[_0x35f5('0x2e')][_0x35f5('0x2f')],function(_0x45e241){return{'name':_0x45e241[_0x35f5('0x30')],'type':_0x45e241[_0x35f5('0x31')][_0x35f5('0x32')]};});_0x4e4372['model']=_['map'](_0x4ff339,_0x35f5('0x2b'));_0x4e4372[_0x35f5('0x33')]=_[_0x35f5('0x34')](_0x49ed47[_0x35f5('0x33')]);_0x4e4372[_0x35f5('0x35')]=_[_0x35f5('0x36')](_0x4e4372[_0x35f5('0x37')],_0x4e4372[_0x35f5('0x33')]);_0x153cc0[_0x35f5('0x38')]=_[_0x35f5('0x36')](_0x4e4372['model'],qs[_0x35f5('0x39')](_0x49ed47[_0x35f5('0x33')][_0x35f5('0x39')]));_0x153cc0[_0x35f5('0x38')]=_0x153cc0[_0x35f5('0x38')][_0x35f5('0x3a')]?_0x153cc0['attributes']:_0x4e4372['model'];if(!_0x49ed47[_0x35f5('0x33')][_0x35f5('0x3b')]('nolimit')){_0x153cc0[_0x35f5('0x21')]=qs[_0x35f5('0x21')](_0x49ed47[_0x35f5('0x33')][_0x35f5('0x21')]);_0x153cc0['offset']=qs[_0x35f5('0x20')](_0x49ed47['query'][_0x35f5('0x20')]);}_0x153cc0['order']=qs['sort'](_0x49ed47[_0x35f5('0x33')][_0x35f5('0x3c')]);_0x153cc0['where']=qs['filters'](_[_0x35f5('0x3d')](_0x49ed47['query'],_0x4e4372[_0x35f5('0x35')]),_0x4ff339);if(_0x49ed47[_0x35f5('0x33')][_0x35f5('0x3e')]){_0x153cc0['where']=_[_0x35f5('0x3f')](_0x153cc0[_0x35f5('0x40')],{'$or':_[_0x35f5('0x2d')](_0x4ff339,function(_0x71eb16){if(_0x71eb16[_0x35f5('0x31')]!==_0x35f5('0x41')){var _0x155b01={};_0x155b01[_0x71eb16[_0x35f5('0x2b')]]={'$like':'%'+_0x49ed47['query'][_0x35f5('0x3e')]+'%'};return _0x155b01;}})});}_0x153cc0=_[_0x35f5('0x3f')]({},_0x153cc0,_0x49ed47[_0x35f5('0x42')]);var _0x54c086={'where':_0x153cc0[_0x35f5('0x40')]};return db[_0x35f5('0x2e')][_0x35f5('0x1f')](_0x54c086)[_0x35f5('0x26')](function(_0xa15ed5){_0x4ee27e['count']=_0xa15ed5;if(_0x49ed47[_0x35f5('0x33')][_0x35f5('0x43')]){_0x153cc0['include']=[{'all':!![]}];}return db['AnalyticFieldReport'][_0x35f5('0x44')](_0x153cc0);})[_0x35f5('0x26')](function(_0x3628f5){_0x4ee27e[_0x35f5('0x45')]=_0x3628f5;return _0x4ee27e;})[_0x35f5('0x26')](respondWithFilteredResult(_0x50ba7b,_0x153cc0))[_0x35f5('0x46')](handleError(_0x50ba7b,null));};exports[_0x35f5('0x47')]=function(_0x295d6a,_0x13dfca){var _0x978d49={'raw':![],'where':{'id':_0x295d6a['params']['id']}},_0x4afb52={};_0x4afb52[_0x35f5('0x37')]=_[_0x35f5('0x34')](db[_0x35f5('0x2e')][_0x35f5('0x2f')]);_0x4afb52[_0x35f5('0x33')]=_[_0x35f5('0x34')](_0x295d6a[_0x35f5('0x33')]);_0x4afb52[_0x35f5('0x35')]=_[_0x35f5('0x36')](_0x4afb52['model'],_0x4afb52[_0x35f5('0x33')]);_0x978d49[_0x35f5('0x38')]=_[_0x35f5('0x36')](_0x4afb52[_0x35f5('0x37')],qs[_0x35f5('0x39')](_0x295d6a[_0x35f5('0x33')][_0x35f5('0x39')]));_0x978d49[_0x35f5('0x38')]=_0x978d49[_0x35f5('0x38')]['length']?_0x978d49[_0x35f5('0x38')]:_0x4afb52[_0x35f5('0x37')];if(_0x295d6a[_0x35f5('0x33')][_0x35f5('0x43')]){_0x978d49[_0x35f5('0x48')]=[{'all':!![]}];}_0x978d49=_[_0x35f5('0x3f')]({},_0x978d49,_0x295d6a[_0x35f5('0x42')]);return db['AnalyticFieldReport'][_0x35f5('0x49')](_0x978d49)[_0x35f5('0x26')](handleEntityNotFound(_0x13dfca,null))[_0x35f5('0x26')](respondWithResult(_0x13dfca,null))['catch'](handleError(_0x13dfca,null));};exports[_0x35f5('0x4a')]=function(_0x20fc54,_0x574c9f){return db[_0x35f5('0x2e')][_0x35f5('0x4a')](_0x20fc54[_0x35f5('0x4b')],{})[_0x35f5('0x26')](respondWithResult(_0x574c9f,0xc9))[_0x35f5('0x46')](handleError(_0x574c9f,null));};exports[_0x35f5('0x4c')]=function(_0x3c7af2,_0x4467a4){return db[_0x35f5('0x2e')][_0x35f5('0x4c')](_0x3c7af2['body'],{'raw':![],'individualHooks':!![]})[_0x35f5('0x26')](respondWithResult(_0x4467a4,0xc9))[_0x35f5('0x46')](handleError(_0x4467a4,null));};exports['update']=function(_0x33bac3,_0x5e4e16){if(_0x33bac3['body']['id']){delete _0x33bac3[_0x35f5('0x4b')]['id'];}return db[_0x35f5('0x2e')][_0x35f5('0x49')]({'where':{'id':_0x33bac3[_0x35f5('0x4d')]['id']}})[_0x35f5('0x26')](handleEntityNotFound(_0x5e4e16,null))[_0x35f5('0x26')](saveUpdates(_0x33bac3['body'],null))[_0x35f5('0x26')](respondWithResult(_0x5e4e16,null))[_0x35f5('0x46')](handleError(_0x5e4e16,null));};exports[_0x35f5('0x27')]=function(_0x2ea152,_0x2665ee){return db[_0x35f5('0x2e')][_0x35f5('0x49')]({'where':{'id':_0x2ea152[_0x35f5('0x4d')]['id']}})['then'](handleEntityNotFound(_0x2665ee,null))[_0x35f5('0x26')](removeEntity(_0x2665ee,null))['catch'](handleError(_0x2665ee,null));};exports['bulkDestroy']=function(_0x46b1cf,_0x2f56aa){return db[_0x35f5('0x2e')][_0x35f5('0x27')]({'where':{'id':_0x46b1cf['query'][_0x35f5('0x4e')]||[]},'raw':![],'individualHooks':!![]})[_0x35f5('0x26')](respondWithResult(_0x2f56aa,0xcc))[_0x35f5('0x46')](handleError(_0x2f56aa,null));};exports[_0x35f5('0x4f')]=function(_0x3c7d7e,_0x2e9a06,_0x5c1cc9){return db[_0x35f5('0x50')]['findOne']({'where':{'id':_0x3c7d7e[_0x35f5('0x4d')]['id']}})['then'](handleEntityNotFound(_0x2e9a06,null))[_0x35f5('0x26')](function(_0x4cbe83){if(_0x4cbe83){return db[_0x35f5('0x51')][_0x35f5('0x52')](function(_0x16c8b7){return db[_0x35f5('0x2e')][_0x35f5('0x27')]({'where':{'CustomReportId':_0x3c7d7e['params']['id']},'transaction':_0x16c8b7})[_0x35f5('0x26')](function(_0x4899e7){var _0x425227=_[_0x35f5('0x2d')](_0x3c7d7e[_0x35f5('0x4b')],function(_0xe22aa7){delete _0xe22aa7['id'];_0xe22aa7['CustomReportId']=_0x3c7d7e[_0x35f5('0x4d')]['id'];return _0xe22aa7;});return db['AnalyticFieldReport'][_0x35f5('0x4c')](_0x425227,{'transaction':_0x16c8b7});});})[_0x35f5('0x26')](function(){return db[_0x35f5('0x2e')]['findAll']({'where':{'CustomReportId':_0x3c7d7e[_0x35f5('0x4d')]['id']}});});}})['then'](respondWithResult(_0x2e9a06,null))[_0x35f5('0x46')](handleError(_0x2e9a06,null));};