Built motion from commit (unavailable).|2.6.0
[motion2.git] / server / api / memberReport / memberReport.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 _0xec73=['end','offset','limit','undefined','count','Content-Range','json','reject','save','update','then','destroy','error','stack','name','send','index','map','MemberReport','fieldName','query','keys','filters','intersection','model','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','type','VIRTUAL','filter','options','includeAll','findAll','rows','show','params','attributes','include','find','catch','create','body','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','to-csv','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','sendStatus','status'];(function(_0x901f26,_0x3d7dd4){var _0x378315=function(_0x205bfe){while(--_0x205bfe){_0x901f26['push'](_0x901f26['shift']());}};_0x378315(++_0x3d7dd4);}(_0xec73,0xc3));var _0x3ec7=function(_0x3cf261,_0x578763){_0x3cf261=_0x3cf261-0x0;var _0x174f87=_0xec73[_0x3cf261];return _0x174f87;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3ec7('0x0'));var zipdir=require(_0x3ec7('0x1'));var jsonpatch=require(_0x3ec7('0x2'));var rp=require(_0x3ec7('0x3'));var moment=require(_0x3ec7('0x4'));var BPromise=require(_0x3ec7('0x5'));var Mustache=require('mustache');var util=require(_0x3ec7('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x3ec7('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x3ec7('0x8'));var squel=require(_0x3ec7('0x9'));var crypto=require(_0x3ec7('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x3ec7('0xb'));var toCsv=require(_0x3ec7('0x7'));var querystring=require(_0x3ec7('0xc'));var Papa=require(_0x3ec7('0xd'));var Redis=require(_0x3ec7('0xe'));var authService=require(_0x3ec7('0xf'));var qs=require(_0x3ec7('0x10'));var as=require(_0x3ec7('0x11'));var hardwareService=require(_0x3ec7('0x12'));var logger=require('../../config/logger')(_0x3ec7('0x13'));var utils=require(_0x3ec7('0x14'));var config=require(_0x3ec7('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3d65f8,_0x387bb2){_0x387bb2=_0x387bb2||0xcc;return function(_0x50030c){if(_0x50030c){return _0x3d65f8[_0x3ec7('0x16')](_0x387bb2);}return _0x3d65f8[_0x3ec7('0x17')](_0x387bb2)[_0x3ec7('0x18')]();};}function respondWithResult(_0x54cb92,_0x5004fb){_0x5004fb=_0x5004fb||0xc8;return function(_0x108142){if(_0x108142){return _0x54cb92[_0x3ec7('0x17')](_0x5004fb)['json'](_0x108142);}};}function respondWithFilteredResult(_0x4bc919,_0xdf6dff){return function(_0x5b882d){if(_0x5b882d){var _0x13f812=typeof _0xdf6dff[_0x3ec7('0x19')]==='undefined'&&typeof _0xdf6dff[_0x3ec7('0x1a')]===_0x3ec7('0x1b');var _0x25f746=_0x5b882d[_0x3ec7('0x1c')];var _0x5b0d7d=_0x13f812?0x0:_0xdf6dff[_0x3ec7('0x19')];var _0x2f73e2=_0x13f812?_0x5b882d[_0x3ec7('0x1c')]:_0xdf6dff['offset']+_0xdf6dff['limit'];var _0x24323a;if(_0x2f73e2>=_0x25f746){_0x2f73e2=_0x25f746;_0x24323a=0xc8;}else{_0x24323a=0xce;}_0x4bc919[_0x3ec7('0x17')](_0x24323a);return _0x4bc919['set'](_0x3ec7('0x1d'),_0x5b0d7d+'-'+_0x2f73e2+'/'+_0x25f746)[_0x3ec7('0x1e')](_0x5b882d);}return null;};}function patchUpdates(_0x5f3333){return function(_0x20a3a5){try{jsonpatch['apply'](_0x20a3a5,_0x5f3333,!![]);}catch(_0x14a7f7){return BPromise[_0x3ec7('0x1f')](_0x14a7f7);}return _0x20a3a5[_0x3ec7('0x20')]();};}function saveUpdates(_0x4a7b5d,_0x56382a){return function(_0x2dd7f5){if(_0x2dd7f5){return _0x2dd7f5[_0x3ec7('0x21')](_0x4a7b5d)[_0x3ec7('0x22')](function(_0x45771c){return _0x45771c;});}return null;};}function removeEntity(_0x252f54,_0x486019){return function(_0x479b83){if(_0x479b83){return _0x479b83[_0x3ec7('0x23')]()[_0x3ec7('0x22')](function(){_0x252f54[_0x3ec7('0x17')](0xcc)[_0x3ec7('0x18')]();});}};}function handleEntityNotFound(_0x346322,_0x18c0ac){return function(_0x36c7cb){if(!_0x36c7cb){_0x346322['sendStatus'](0x194);}return _0x36c7cb;};}function handleError(_0x101c52,_0xdfed88){_0xdfed88=_0xdfed88||0x1f4;return function(_0x227bc8){logger[_0x3ec7('0x24')](_0x227bc8[_0x3ec7('0x25')]);if(_0x227bc8[_0x3ec7('0x26')]){delete _0x227bc8[_0x3ec7('0x26')];}_0x101c52[_0x3ec7('0x17')](_0xdfed88)[_0x3ec7('0x27')](_0x227bc8);};}exports[_0x3ec7('0x28')]=function(_0x5df47c,_0x56ed6e){var _0x56ee89={},_0xadf37c={},_0x393f5a={'count':0x0,'rows':[]};var _0x2aec35=_[_0x3ec7('0x29')](db[_0x3ec7('0x2a')]['rawAttributes'],function(_0x45dd75){return{'name':_0x45dd75[_0x3ec7('0x2b')],'type':_0x45dd75['type']['key']};});_0xadf37c['model']=_[_0x3ec7('0x29')](_0x2aec35,_0x3ec7('0x26'));_0xadf37c[_0x3ec7('0x2c')]=_[_0x3ec7('0x2d')](_0x5df47c[_0x3ec7('0x2c')]);_0xadf37c[_0x3ec7('0x2e')]=_[_0x3ec7('0x2f')](_0xadf37c[_0x3ec7('0x30')],_0xadf37c[_0x3ec7('0x2c')]);_0x56ee89['attributes']=_['intersection'](_0xadf37c[_0x3ec7('0x30')],qs[_0x3ec7('0x31')](_0x5df47c['query'][_0x3ec7('0x31')]));_0x56ee89['attributes']=_0x56ee89['attributes'][_0x3ec7('0x32')]?_0x56ee89['attributes']:_0xadf37c[_0x3ec7('0x30')];if(!_0x5df47c[_0x3ec7('0x2c')][_0x3ec7('0x33')](_0x3ec7('0x34'))){_0x56ee89[_0x3ec7('0x1a')]=qs[_0x3ec7('0x1a')](_0x5df47c[_0x3ec7('0x2c')][_0x3ec7('0x1a')]);_0x56ee89[_0x3ec7('0x19')]=qs[_0x3ec7('0x19')](_0x5df47c[_0x3ec7('0x2c')]['offset']);}_0x56ee89[_0x3ec7('0x35')]=qs['sort'](_0x5df47c[_0x3ec7('0x2c')][_0x3ec7('0x36')]);_0x56ee89['where']=qs[_0x3ec7('0x2e')](_['pick'](_0x5df47c['query'],_0xadf37c[_0x3ec7('0x2e')]),_0x2aec35);if(_0x5df47c[_0x3ec7('0x2c')]['filter']){_0x56ee89[_0x3ec7('0x37')]=_[_0x3ec7('0x38')](_0x56ee89[_0x3ec7('0x37')],{'$or':_[_0x3ec7('0x29')](_0x2aec35,function(_0x47a15e){if(_0x47a15e[_0x3ec7('0x39')]!==_0x3ec7('0x3a')){var _0x42cfa5={};_0x42cfa5[_0x47a15e['name']]={'$like':'%'+_0x5df47c['query'][_0x3ec7('0x3b')]+'%'};return _0x42cfa5;}})});}_0x56ee89=_['merge']({},_0x56ee89,_0x5df47c[_0x3ec7('0x3c')]);var _0xf6b417={'where':_0x56ee89[_0x3ec7('0x37')]};return db[_0x3ec7('0x2a')]['count'](_0xf6b417)[_0x3ec7('0x22')](function(_0x3f9feb){_0x393f5a[_0x3ec7('0x1c')]=_0x3f9feb;if(_0x5df47c[_0x3ec7('0x2c')][_0x3ec7('0x3d')]){_0x56ee89['include']=[{'all':!![]}];}return db[_0x3ec7('0x2a')][_0x3ec7('0x3e')](_0x56ee89);})[_0x3ec7('0x22')](function(_0x239564){_0x393f5a[_0x3ec7('0x3f')]=_0x239564;return _0x393f5a;})[_0x3ec7('0x22')](respondWithFilteredResult(_0x56ed6e,_0x56ee89))['catch'](handleError(_0x56ed6e,null));};exports[_0x3ec7('0x40')]=function(_0x186106,_0x34ffd2){var _0x35ae37={'raw':!![],'where':{'id':_0x186106[_0x3ec7('0x41')]['id']}},_0x5886f7={};_0x5886f7['model']=_[_0x3ec7('0x2d')](db[_0x3ec7('0x2a')]['rawAttributes']);_0x5886f7[_0x3ec7('0x2c')]=_[_0x3ec7('0x2d')](_0x186106[_0x3ec7('0x2c')]);_0x5886f7[_0x3ec7('0x2e')]=_[_0x3ec7('0x2f')](_0x5886f7['model'],_0x5886f7[_0x3ec7('0x2c')]);_0x35ae37['attributes']=_['intersection'](_0x5886f7[_0x3ec7('0x30')],qs[_0x3ec7('0x31')](_0x186106[_0x3ec7('0x2c')]['fields']));_0x35ae37[_0x3ec7('0x42')]=_0x35ae37[_0x3ec7('0x42')][_0x3ec7('0x32')]?_0x35ae37[_0x3ec7('0x42')]:_0x5886f7[_0x3ec7('0x30')];if(_0x186106[_0x3ec7('0x2c')][_0x3ec7('0x3d')]){_0x35ae37[_0x3ec7('0x43')]=[{'all':!![]}];}_0x35ae37=_['merge']({},_0x35ae37,_0x186106[_0x3ec7('0x3c')]);return db[_0x3ec7('0x2a')][_0x3ec7('0x44')](_0x35ae37)[_0x3ec7('0x22')](handleEntityNotFound(_0x34ffd2,null))[_0x3ec7('0x22')](respondWithResult(_0x34ffd2,null))[_0x3ec7('0x45')](handleError(_0x34ffd2,null));};exports[_0x3ec7('0x46')]=function(_0x437105,_0x27b226){return db[_0x3ec7('0x2a')][_0x3ec7('0x46')](_0x437105[_0x3ec7('0x47')],{})['then'](respondWithResult(_0x27b226,0xc9))[_0x3ec7('0x45')](handleError(_0x27b226,null));};exports[_0x3ec7('0x21')]=function(_0xa9a0aa,_0x5da1ad){if(_0xa9a0aa[_0x3ec7('0x47')]['id']){delete _0xa9a0aa['body']['id'];}return db[_0x3ec7('0x2a')][_0x3ec7('0x44')]({'where':{'id':_0xa9a0aa[_0x3ec7('0x41')]['id']}})[_0x3ec7('0x22')](handleEntityNotFound(_0x5da1ad,null))['then'](saveUpdates(_0xa9a0aa[_0x3ec7('0x47')],null))[_0x3ec7('0x22')](respondWithResult(_0x5da1ad,null))['catch'](handleError(_0x5da1ad,null));};exports[_0x3ec7('0x23')]=function(_0x2a09ee,_0x1722c7){return db[_0x3ec7('0x2a')][_0x3ec7('0x44')]({'where':{'id':_0x2a09ee[_0x3ec7('0x41')]['id']}})[_0x3ec7('0x22')](handleEntityNotFound(_0x1722c7,null))[_0x3ec7('0x22')](removeEntity(_0x1722c7,null))[_0x3ec7('0x45')](handleError(_0x1722c7,null));};exports[_0x3ec7('0x48')]=function(_0x24f299,_0x56726d){return db[_0x3ec7('0x2a')][_0x3ec7('0x48')]()[_0x3ec7('0x22')](respondWithResult(_0x56726d,null))[_0x3ec7('0x45')](handleError(_0x56726d,null));};