344530984f7120726459b8a7b55f1970ed5b6668
[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 _0x54b6=['rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','set','Content-Range','apply','destroy','end','error','name','send','index','map','MemberReport','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','limit','sort','where','pick','merge','VIRTUAL','options','then','include','findAll','rows','catch','params','rawAttributes','includeAll','find','create','update','body','describe','eml-format'];(function(_0x50d8da,_0xe56e5b){var _0x1b55bb=function(_0x5c15eb){while(--_0x5c15eb){_0x50d8da['push'](_0x50d8da['shift']());}};_0x1b55bb(++_0xe56e5b);}(_0x54b6,0xd1));var _0x654b=function(_0x386c3e,_0x44a375){_0x386c3e=_0x386c3e-0x0;var _0x4b8e13=_0x54b6[_0x386c3e];return _0x4b8e13;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x654b('0x0'));var rimraf=require(_0x654b('0x1'));var zipdir=require(_0x654b('0x2'));var jsonpatch=require(_0x654b('0x3'));var rp=require(_0x654b('0x4'));var moment=require(_0x654b('0x5'));var BPromise=require(_0x654b('0x6'));var Mustache=require('mustache');var util=require(_0x654b('0x7'));var path=require(_0x654b('0x8'));var sox=require(_0x654b('0x9'));var csv=require(_0x654b('0xa'));var ejs=require(_0x654b('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x654b('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x654b('0xd'));var toCsv=require(_0x654b('0xa'));var querystring=require('querystring');var Papa=require(_0x654b('0xe'));var Redis=require(_0x654b('0xf'));var authService=require(_0x654b('0x10'));var qs=require(_0x654b('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x654b('0x12'));var logger=require(_0x654b('0x13'))(_0x654b('0x14'));var utils=require('../../config/utils');var config=require(_0x654b('0x15'));var db=require(_0x654b('0x16'))['db'];function respondWithStatusCode(_0x5e8591,_0x206069){_0x206069=_0x206069||0xcc;return function(_0x530f53){if(_0x530f53){return _0x5e8591[_0x654b('0x17')](_0x206069);}return _0x5e8591[_0x654b('0x18')](_0x206069)['end']();};}function respondWithResult(_0x13f2cd,_0x41b7ac){_0x41b7ac=_0x41b7ac||0xc8;return function(_0x2ef78e){if(_0x2ef78e){return _0x13f2cd[_0x654b('0x18')](_0x41b7ac)[_0x654b('0x19')](_0x2ef78e);}};}function respondWithFilteredResult(_0x57c037,_0x590699){return function(_0x5a05aa){if(_0x5a05aa){var _0x442d5c=_0x5a05aa[_0x654b('0x1a')],_0x5a2940=_0x590699[_0x654b('0x1b')],_0x17c280=_0x590699[_0x654b('0x1b')]+_0x590699['limit'],_0x121c77;if(_0x17c280>=_0x442d5c){_0x17c280=_0x442d5c;_0x121c77=0xc8;}else{_0x121c77=0xce;}_0x57c037[_0x654b('0x18')](_0x121c77);return _0x57c037[_0x654b('0x1c')](_0x654b('0x1d'),_0x5a2940+'-'+_0x17c280+'/'+_0x442d5c)[_0x654b('0x19')](_0x5a05aa);}return null;};}function patchUpdates(_0x32b17b){return function(_0x51e5b7){try{jsonpatch[_0x654b('0x1e')](_0x51e5b7,_0x32b17b,!![]);}catch(_0x201eb5){return BPromise['reject'](_0x201eb5);}return _0x51e5b7['save']();};}function saveUpdates(_0xb32b02,_0x53357e){return function(_0xe45542){if(_0xe45542){return _0xe45542['update'](_0xb32b02)['then'](function(_0x2849ca){return _0x2849ca;});}return null;};}function removeEntity(_0x3e94a6,_0x27e531){return function(_0x37bd70){if(_0x37bd70){return _0x37bd70[_0x654b('0x1f')]()['then'](function(){_0x3e94a6[_0x654b('0x18')](0xcc)[_0x654b('0x20')]();});}};}function handleEntityNotFound(_0x3808ff,_0x3ac0a1){return function(_0x451550){if(!_0x451550){_0x3808ff[_0x654b('0x17')](0x194);}return _0x451550;};}function handleError(_0x80986a,_0x173a09){_0x173a09=_0x173a09||0x1f4;return function(_0xe63d34){logger[_0x654b('0x21')](_0xe63d34['stack']);if(_0xe63d34[_0x654b('0x22')]){delete _0xe63d34['name'];}_0x80986a[_0x654b('0x18')](_0x173a09)[_0x654b('0x23')](_0xe63d34);};}exports[_0x654b('0x24')]=function(_0xe3dc57,_0x549baa){var _0x35a17b={},_0x2241d2={},_0x201a34={'count':0x0,'rows':[]};var _0x775fe3=_[_0x654b('0x25')](db[_0x654b('0x26')]['rawAttributes'],function(_0xbaa097){return{'name':_0xbaa097[_0x654b('0x27')],'type':_0xbaa097[_0x654b('0x28')][_0x654b('0x29')]};});_0x2241d2[_0x654b('0x2a')]=_[_0x654b('0x25')](_0x775fe3,_0x654b('0x22'));_0x2241d2[_0x654b('0x2b')]=_[_0x654b('0x2c')](_0xe3dc57[_0x654b('0x2b')]);_0x2241d2[_0x654b('0x2d')]=_[_0x654b('0x2e')](_0x2241d2[_0x654b('0x2a')],_0x2241d2[_0x654b('0x2b')]);_0x35a17b[_0x654b('0x2f')]=_[_0x654b('0x2e')](_0x2241d2[_0x654b('0x2a')],qs[_0x654b('0x30')](_0xe3dc57['query']['fields']));_0x35a17b['attributes']=_0x35a17b[_0x654b('0x2f')]['length']?_0x35a17b['attributes']:_0x2241d2[_0x654b('0x2a')];if(!_0xe3dc57['query']['hasOwnProperty'](_0x654b('0x31'))){_0x35a17b['limit']=qs['limit'](_0xe3dc57[_0x654b('0x2b')][_0x654b('0x32')]);_0x35a17b[_0x654b('0x1b')]=qs[_0x654b('0x1b')](_0xe3dc57[_0x654b('0x2b')][_0x654b('0x1b')]);}_0x35a17b['order']=qs[_0x654b('0x33')](_0xe3dc57[_0x654b('0x2b')][_0x654b('0x33')]);_0x35a17b[_0x654b('0x34')]=qs[_0x654b('0x2d')](_[_0x654b('0x35')](_0xe3dc57[_0x654b('0x2b')],_0x2241d2['filters']));if(_0xe3dc57[_0x654b('0x2b')]['filter']){_0x35a17b['where']=_[_0x654b('0x36')](_0x35a17b[_0x654b('0x34')],{'$or':_[_0x654b('0x25')](_0x775fe3,function(_0x4cb32d){if(_0x4cb32d['type']!==_0x654b('0x37')){var _0x8e4212={};_0x8e4212[_0x4cb32d[_0x654b('0x22')]]={'$like':'%'+_0xe3dc57[_0x654b('0x2b')]['filter']+'%'};return _0x8e4212;}})});}_0x35a17b=_['merge']({},_0x35a17b,_0xe3dc57[_0x654b('0x38')]);var _0x37ffa2={'where':_0x35a17b['where']};return db[_0x654b('0x26')]['count'](_0x37ffa2)[_0x654b('0x39')](function(_0x228654){_0x201a34[_0x654b('0x1a')]=_0x228654;if(_0xe3dc57[_0x654b('0x2b')]['includeAll']){_0x35a17b[_0x654b('0x3a')]=[{'all':!![]}];}return db[_0x654b('0x26')][_0x654b('0x3b')](_0x35a17b);})[_0x654b('0x39')](function(_0x1a85a6){_0x201a34[_0x654b('0x3c')]=_0x1a85a6;return _0x201a34;})[_0x654b('0x39')](respondWithFilteredResult(_0x549baa,_0x35a17b))[_0x654b('0x3d')](handleError(_0x549baa,null));};exports['show']=function(_0x55ae7c,_0x62ab57){var _0x53c836={'raw':!![],'where':{'id':_0x55ae7c[_0x654b('0x3e')]['id']}},_0x43d9f6={};_0x43d9f6[_0x654b('0x2a')]=_[_0x654b('0x2c')](db['MemberReport'][_0x654b('0x3f')]);_0x43d9f6['query']=_[_0x654b('0x2c')](_0x55ae7c['query']);_0x43d9f6[_0x654b('0x2d')]=_[_0x654b('0x2e')](_0x43d9f6[_0x654b('0x2a')],_0x43d9f6[_0x654b('0x2b')]);_0x53c836[_0x654b('0x2f')]=_['intersection'](_0x43d9f6['model'],qs[_0x654b('0x30')](_0x55ae7c['query'][_0x654b('0x30')]));_0x53c836[_0x654b('0x2f')]=_0x53c836['attributes']['length']?_0x53c836['attributes']:_0x43d9f6['model'];if(_0x55ae7c[_0x654b('0x2b')][_0x654b('0x40')]){_0x53c836[_0x654b('0x3a')]=[{'all':!![]}];}_0x53c836=_[_0x654b('0x36')]({},_0x53c836,_0x55ae7c[_0x654b('0x38')]);return db[_0x654b('0x26')][_0x654b('0x41')](_0x53c836)['then'](handleEntityNotFound(_0x62ab57,null))[_0x654b('0x39')](respondWithResult(_0x62ab57,null))[_0x654b('0x3d')](handleError(_0x62ab57,null));};exports['create']=function(_0x4f8e68,_0x4705d4){return db[_0x654b('0x26')][_0x654b('0x42')](_0x4f8e68['body'],{})[_0x654b('0x39')](respondWithResult(_0x4705d4,0xc9))[_0x654b('0x3d')](handleError(_0x4705d4,null));};exports[_0x654b('0x43')]=function(_0x119426,_0xe398c5){if(_0x119426[_0x654b('0x44')]['id']){delete _0x119426[_0x654b('0x44')]['id'];}return db[_0x654b('0x26')]['find']({'where':{'id':_0x119426[_0x654b('0x3e')]['id']}})[_0x654b('0x39')](handleEntityNotFound(_0xe398c5,null))[_0x654b('0x39')](saveUpdates(_0x119426[_0x654b('0x44')],null))[_0x654b('0x39')](respondWithResult(_0xe398c5,null))[_0x654b('0x3d')](handleError(_0xe398c5,null));};exports['destroy']=function(_0x5b85c8,_0xe4369){return db[_0x654b('0x26')][_0x654b('0x41')]({'where':{'id':_0x5b85c8[_0x654b('0x3e')]['id']}})['then'](handleEntityNotFound(_0xe4369,null))[_0x654b('0x39')](removeEntity(_0xe4369,null))['catch'](handleError(_0xe4369,null));};exports[_0x654b('0x45')]=function(_0x3f7ac2,_0x742844){return db[_0x654b('0x26')]['describe']()[_0x654b('0x39')](respondWithResult(_0x742844,null))[_0x654b('0x3d')](handleError(_0x742844,null));};