0c6de8330e6ce1753ea015f7747d860174a5bfa3
[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 _0xb5f8=['stack','name','send','index','map','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','VIRTUAL','MemberReport','then','include','rows','show','params','fields','merge','options','find','catch','create','body','destroy','describe','rimraf','zip-dir','fast-json-patch','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/utils','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','save','update','error'];(function(_0x48e13d,_0x43fc3b){var _0x51a9c7=function(_0x1497cb){while(--_0x1497cb){_0x48e13d['push'](_0x48e13d['shift']());}};_0x51a9c7(++_0x43fc3b);}(_0xb5f8,0x135));var _0x8b5f=function(_0x6b8f8a,_0x5c4897){_0x6b8f8a=_0x6b8f8a-0x0;var _0x53ecd4=_0xb5f8[_0x6b8f8a];return _0x53ecd4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8b5f('0x0'));var zipdir=require(_0x8b5f('0x1'));var jsonpatch=require(_0x8b5f('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x8b5f('0x3'));var Mustache=require('mustache');var util=require('util');var path=require(_0x8b5f('0x4'));var sox=require(_0x8b5f('0x5'));var csv=require(_0x8b5f('0x6'));var ejs=require(_0x8b5f('0x7'));var fs=require('fs');var fs_extra=require(_0x8b5f('0x8'));var _=require(_0x8b5f('0x9'));var squel=require('squel');var crypto=require(_0x8b5f('0xa'));var jsforce=require(_0x8b5f('0xb'));var deskjs=require(_0x8b5f('0xc'));var toCsv=require(_0x8b5f('0x6'));var querystring=require(_0x8b5f('0xd'));var Papa=require(_0x8b5f('0xe'));var Redis=require(_0x8b5f('0xf'));var authService=require(_0x8b5f('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x8b5f('0x11'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4f8420,_0x2c6a84){_0x2c6a84=_0x2c6a84||0xcc;return function(_0x1ee16e){if(_0x1ee16e){return _0x4f8420[_0x8b5f('0x12')](_0x2c6a84);}return _0x4f8420[_0x8b5f('0x13')](_0x2c6a84)[_0x8b5f('0x14')]();};}function respondWithResult(_0x500856,_0x95f33f){_0x95f33f=_0x95f33f||0xc8;return function(_0x108d4a){if(_0x108d4a){return _0x500856['status'](_0x95f33f)[_0x8b5f('0x15')](_0x108d4a);}};}function respondWithFilteredResult(_0x1ff7b2,_0xe3b933){return function(_0x4228d9){if(_0x4228d9){var _0x16d7b7=typeof _0xe3b933[_0x8b5f('0x16')]===_0x8b5f('0x17')&&typeof _0xe3b933[_0x8b5f('0x18')]===_0x8b5f('0x17');var _0x107128=_0x4228d9[_0x8b5f('0x19')];var _0x1a7c3f=_0x16d7b7?0x0:_0xe3b933[_0x8b5f('0x16')];var _0x50c12d=_0x16d7b7?_0x4228d9[_0x8b5f('0x19')]:_0xe3b933['offset']+_0xe3b933['limit'];var _0x3983d7;if(_0x50c12d>=_0x107128){_0x50c12d=_0x107128;_0x3983d7=0xc8;}else{_0x3983d7=0xce;}_0x1ff7b2['status'](_0x3983d7);return _0x1ff7b2['set'](_0x8b5f('0x1a'),_0x1a7c3f+'-'+_0x50c12d+'/'+_0x107128)['json'](_0x4228d9);}return null;};}function patchUpdates(_0x14c606){return function(_0x3ab8e3){try{jsonpatch[_0x8b5f('0x1b')](_0x3ab8e3,_0x14c606,!![]);}catch(_0x55e6aa){return BPromise['reject'](_0x55e6aa);}return _0x3ab8e3[_0x8b5f('0x1c')]();};}function saveUpdates(_0x4dabe4,_0x1dad7d){return function(_0x58dff7){if(_0x58dff7){return _0x58dff7[_0x8b5f('0x1d')](_0x4dabe4)['then'](function(_0x30faad){return _0x30faad;});}return null;};}function removeEntity(_0x1dc0ea,_0x4038e8){return function(_0x12e686){if(_0x12e686){return _0x12e686['destroy']()['then'](function(){_0x1dc0ea[_0x8b5f('0x13')](0xcc)[_0x8b5f('0x14')]();});}};}function handleEntityNotFound(_0x5e41c5,_0x47c9be){return function(_0x391be0){if(!_0x391be0){_0x5e41c5[_0x8b5f('0x12')](0x194);}return _0x391be0;};}function handleError(_0x24c2d6,_0x3a94da){_0x3a94da=_0x3a94da||0x1f4;return function(_0x245117){logger[_0x8b5f('0x1e')](_0x245117[_0x8b5f('0x1f')]);if(_0x245117[_0x8b5f('0x20')]){delete _0x245117['name'];}_0x24c2d6['status'](_0x3a94da)[_0x8b5f('0x21')](_0x245117);};}exports[_0x8b5f('0x22')]=function(_0x3dceaf,_0x2442ff){var _0x477f4e={},_0x2fa8a0={},_0x9b25e2={'count':0x0,'rows':[]};var _0x10dc02=_[_0x8b5f('0x23')](db['MemberReport'][_0x8b5f('0x24')],function(_0x50f312){return{'name':_0x50f312['fieldName'],'type':_0x50f312[_0x8b5f('0x25')][_0x8b5f('0x26')]};});_0x2fa8a0[_0x8b5f('0x27')]=_[_0x8b5f('0x23')](_0x10dc02,_0x8b5f('0x20'));_0x2fa8a0[_0x8b5f('0x28')]=_[_0x8b5f('0x29')](_0x3dceaf[_0x8b5f('0x28')]);_0x2fa8a0[_0x8b5f('0x2a')]=_[_0x8b5f('0x2b')](_0x2fa8a0[_0x8b5f('0x27')],_0x2fa8a0[_0x8b5f('0x28')]);_0x477f4e[_0x8b5f('0x2c')]=_[_0x8b5f('0x2b')](_0x2fa8a0[_0x8b5f('0x27')],qs['fields'](_0x3dceaf[_0x8b5f('0x28')]['fields']));_0x477f4e['attributes']=_0x477f4e[_0x8b5f('0x2c')][_0x8b5f('0x2d')]?_0x477f4e['attributes']:_0x2fa8a0[_0x8b5f('0x27')];if(!_0x3dceaf[_0x8b5f('0x28')][_0x8b5f('0x2e')](_0x8b5f('0x2f'))){_0x477f4e['limit']=qs[_0x8b5f('0x18')](_0x3dceaf['query']['limit']);_0x477f4e[_0x8b5f('0x16')]=qs[_0x8b5f('0x16')](_0x3dceaf['query'][_0x8b5f('0x16')]);}_0x477f4e[_0x8b5f('0x30')]=qs['sort'](_0x3dceaf[_0x8b5f('0x28')][_0x8b5f('0x31')]);_0x477f4e[_0x8b5f('0x32')]=qs[_0x8b5f('0x2a')](_['pick'](_0x3dceaf[_0x8b5f('0x28')],_0x2fa8a0[_0x8b5f('0x2a')]),_0x10dc02);if(_0x3dceaf['query'][_0x8b5f('0x33')]){_0x477f4e['where']=_['merge'](_0x477f4e['where'],{'$or':_[_0x8b5f('0x23')](_0x10dc02,function(_0xf16dcc){if(_0xf16dcc[_0x8b5f('0x25')]!==_0x8b5f('0x34')){var _0x4e78a3={};_0x4e78a3[_0xf16dcc[_0x8b5f('0x20')]]={'$like':'%'+_0x3dceaf[_0x8b5f('0x28')][_0x8b5f('0x33')]+'%'};return _0x4e78a3;}})});}_0x477f4e=_['merge']({},_0x477f4e,_0x3dceaf['options']);var _0x2b1f18={'where':_0x477f4e[_0x8b5f('0x32')]};return db[_0x8b5f('0x35')]['count'](_0x2b1f18)[_0x8b5f('0x36')](function(_0x41ef6d){_0x9b25e2[_0x8b5f('0x19')]=_0x41ef6d;if(_0x3dceaf[_0x8b5f('0x28')]['includeAll']){_0x477f4e[_0x8b5f('0x37')]=[{'all':!![]}];}return db[_0x8b5f('0x35')]['findAll'](_0x477f4e);})[_0x8b5f('0x36')](function(_0x28af64){_0x9b25e2[_0x8b5f('0x38')]=_0x28af64;return _0x9b25e2;})[_0x8b5f('0x36')](respondWithFilteredResult(_0x2442ff,_0x477f4e))['catch'](handleError(_0x2442ff,null));};exports[_0x8b5f('0x39')]=function(_0x326a10,_0x160445){var _0x39f665={'raw':!![],'where':{'id':_0x326a10[_0x8b5f('0x3a')]['id']}},_0x6807c0={};_0x6807c0[_0x8b5f('0x27')]=_['keys'](db[_0x8b5f('0x35')][_0x8b5f('0x24')]);_0x6807c0[_0x8b5f('0x28')]=_[_0x8b5f('0x29')](_0x326a10[_0x8b5f('0x28')]);_0x6807c0[_0x8b5f('0x2a')]=_[_0x8b5f('0x2b')](_0x6807c0[_0x8b5f('0x27')],_0x6807c0[_0x8b5f('0x28')]);_0x39f665[_0x8b5f('0x2c')]=_[_0x8b5f('0x2b')](_0x6807c0[_0x8b5f('0x27')],qs['fields'](_0x326a10[_0x8b5f('0x28')][_0x8b5f('0x3b')]));_0x39f665[_0x8b5f('0x2c')]=_0x39f665['attributes'][_0x8b5f('0x2d')]?_0x39f665[_0x8b5f('0x2c')]:_0x6807c0[_0x8b5f('0x27')];if(_0x326a10[_0x8b5f('0x28')]['includeAll']){_0x39f665['include']=[{'all':!![]}];}_0x39f665=_[_0x8b5f('0x3c')]({},_0x39f665,_0x326a10[_0x8b5f('0x3d')]);return db['MemberReport'][_0x8b5f('0x3e')](_0x39f665)[_0x8b5f('0x36')](handleEntityNotFound(_0x160445,null))[_0x8b5f('0x36')](respondWithResult(_0x160445,null))[_0x8b5f('0x3f')](handleError(_0x160445,null));};exports['create']=function(_0x376dfa,_0x523c05){return db[_0x8b5f('0x35')][_0x8b5f('0x40')](_0x376dfa[_0x8b5f('0x41')],{})[_0x8b5f('0x36')](respondWithResult(_0x523c05,0xc9))[_0x8b5f('0x3f')](handleError(_0x523c05,null));};exports['update']=function(_0x430025,_0x54023b){if(_0x430025[_0x8b5f('0x41')]['id']){delete _0x430025[_0x8b5f('0x41')]['id'];}return db[_0x8b5f('0x35')][_0x8b5f('0x3e')]({'where':{'id':_0x430025[_0x8b5f('0x3a')]['id']}})['then'](handleEntityNotFound(_0x54023b,null))[_0x8b5f('0x36')](saveUpdates(_0x430025[_0x8b5f('0x41')],null))[_0x8b5f('0x36')](respondWithResult(_0x54023b,null))[_0x8b5f('0x3f')](handleError(_0x54023b,null));};exports[_0x8b5f('0x42')]=function(_0x5704db,_0x40969e){return db['MemberReport'][_0x8b5f('0x3e')]({'where':{'id':_0x5704db[_0x8b5f('0x3a')]['id']}})[_0x8b5f('0x36')](handleEntityNotFound(_0x40969e,null))[_0x8b5f('0x36')](removeEntity(_0x40969e,null))[_0x8b5f('0x3f')](handleError(_0x40969e,null));};exports[_0x8b5f('0x43')]=function(_0x34a1e5,_0x331053){return db[_0x8b5f('0x35')]['describe']()[_0x8b5f('0x36')](respondWithResult(_0x331053,null))['catch'](handleError(_0x331053,null));};