Built motion from commit (unavailable).|2.4.4
[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 _0x8c7a=['attributes','length','hasOwnProperty','nolimit','offset','order','sort','where','pick','filter','merge','type','VIRTUAL','field','options','includeAll','include','findAll','rows','catch','show','find','create','body','params','destroy','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','count','limit','set','json','apply','reject','save','update','then','status','stack','name','send','index','MemberReport','model','query','keys','filters','intersection','fields'];(function(_0x5338fe,_0x5e71d1){var _0xf0a1be=function(_0x306a01){while(--_0x306a01){_0x5338fe['push'](_0x5338fe['shift']());}};_0xf0a1be(++_0x5e71d1);}(_0x8c7a,0x197));var _0xa8c7=function(_0x2f35de,_0x4cdbf1){_0x2f35de=_0x2f35de-0x0;var _0x2a81ab=_0x8c7a[_0x2f35de];return _0x2a81ab;};'use strict';var pdf=require(_0xa8c7('0x0'));var emlformat=require(_0xa8c7('0x1'));var rimraf=require(_0xa8c7('0x2'));var zipdir=require(_0xa8c7('0x3'));var jsonpatch=require(_0xa8c7('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xa8c7('0x5'));var util=require(_0xa8c7('0x6'));var path=require(_0xa8c7('0x7'));var sox=require(_0xa8c7('0x8'));var csv=require('to-csv');var ejs=require(_0xa8c7('0x9'));var fs=require('fs');var _=require(_0xa8c7('0xa'));var squel=require(_0xa8c7('0xb'));var crypto=require(_0xa8c7('0xc'));var jsforce=require(_0xa8c7('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xa8c7('0xe'));var querystring=require(_0xa8c7('0xf'));var Papa=require(_0xa8c7('0x10'));var Redis=require(_0xa8c7('0x11'));var authService=require(_0xa8c7('0x12'));var qs=require(_0xa8c7('0x13'));var hardwareService=require(_0xa8c7('0x14'));var logger=require(_0xa8c7('0x15'))(_0xa8c7('0x16'));var utils=require(_0xa8c7('0x17'));var config=require(_0xa8c7('0x18'));var db=require(_0xa8c7('0x19'))['db'];function respondWithStatusCode(_0x4dd19b,_0xa27421){_0xa27421=_0xa27421||0xcc;return function(_0x4bf0b9){if(_0x4bf0b9){return _0x4dd19b[_0xa8c7('0x1a')](_0xa27421);}return _0x4dd19b['status'](_0xa27421)[_0xa8c7('0x1b')]();};}function respondWithResult(_0x4eef96,_0x3496cb){_0x3496cb=_0x3496cb||0xc8;return function(_0x552ef6){if(_0x552ef6){return _0x4eef96['status'](_0x3496cb)['json'](_0x552ef6);}};}function respondWithFilteredResult(_0x521e58,_0xb8cd05){return function(_0x4bb8e6){if(_0x4bb8e6){var _0x2ab1e3=_0x4bb8e6[_0xa8c7('0x1c')],_0x74add8=_0xb8cd05['offset'],_0x1dfa8f=_0xb8cd05['offset']+_0xb8cd05[_0xa8c7('0x1d')],_0x58b824;if(_0x1dfa8f>=_0x2ab1e3){_0x1dfa8f=_0x2ab1e3;_0x58b824=0xc8;}else{_0x58b824=0xce;}_0x521e58['status'](_0x58b824);return _0x521e58[_0xa8c7('0x1e')]('Content-Range',_0x74add8+'-'+_0x1dfa8f+'/'+_0x2ab1e3)[_0xa8c7('0x1f')](_0x4bb8e6);}return null;};}function patchUpdates(_0x42ef56){return function(_0x2768fe){try{jsonpatch[_0xa8c7('0x20')](_0x2768fe,_0x42ef56,!![]);}catch(_0x19404a){return BPromise[_0xa8c7('0x21')](_0x19404a);}return _0x2768fe[_0xa8c7('0x22')]();};}function saveUpdates(_0x4bf821,_0x53c827){return function(_0x58463e){if(_0x58463e){return _0x58463e[_0xa8c7('0x23')](_0x4bf821)[_0xa8c7('0x24')](function(_0x38ca4e){return _0x38ca4e;});}return null;};}function removeEntity(_0x4b0b7e,_0x4c71b4){return function(_0x3ed505){if(_0x3ed505){return _0x3ed505['destroy']()[_0xa8c7('0x24')](function(){_0x4b0b7e[_0xa8c7('0x25')](0xcc)['end']();});}};}function handleEntityNotFound(_0x551ddc,_0x36ff90){return function(_0x530b84){if(!_0x530b84){_0x551ddc[_0xa8c7('0x1a')](0x194);}return _0x530b84;};}function handleError(_0x2e06e7,_0x13002b){_0x13002b=_0x13002b||0x1f4;return function(_0x37bf0c){logger['error'](_0x37bf0c[_0xa8c7('0x26')]);if(_0x37bf0c[_0xa8c7('0x27')]){delete _0x37bf0c[_0xa8c7('0x27')];}_0x2e06e7[_0xa8c7('0x25')](_0x13002b)[_0xa8c7('0x28')](_0x37bf0c);};}exports[_0xa8c7('0x29')]=function(_0x1c3acf,_0x5dc2c3){var _0x283796={},_0x2cb8b2={},_0x1239ea={'count':0x0,'rows':[]};var _0x1c2232=db[_0xa8c7('0x2a')]['rawAttributes'];_0x2cb8b2[_0xa8c7('0x2b')]=_['keys'](_0x1c2232);_0x2cb8b2[_0xa8c7('0x2c')]=_[_0xa8c7('0x2d')](_0x1c3acf['query']);_0x2cb8b2[_0xa8c7('0x2e')]=_['intersection'](_0x2cb8b2[_0xa8c7('0x2b')],_0x2cb8b2[_0xa8c7('0x2c')]);_0x283796['attributes']=_[_0xa8c7('0x2f')](_0x2cb8b2[_0xa8c7('0x2b')],qs[_0xa8c7('0x30')](_0x1c3acf['query'][_0xa8c7('0x30')]));_0x283796[_0xa8c7('0x31')]=_0x283796['attributes'][_0xa8c7('0x32')]?_0x283796['attributes']:_0x2cb8b2[_0xa8c7('0x2b')];if(!_0x1c3acf[_0xa8c7('0x2c')][_0xa8c7('0x33')](_0xa8c7('0x34'))){_0x283796[_0xa8c7('0x1d')]=qs[_0xa8c7('0x1d')](_0x1c3acf[_0xa8c7('0x2c')]['limit']);_0x283796[_0xa8c7('0x35')]=qs[_0xa8c7('0x35')](_0x1c3acf[_0xa8c7('0x2c')][_0xa8c7('0x35')]);}_0x283796[_0xa8c7('0x36')]=qs[_0xa8c7('0x37')](_0x1c3acf['query'][_0xa8c7('0x37')]);_0x283796[_0xa8c7('0x38')]=qs[_0xa8c7('0x2e')](_[_0xa8c7('0x39')](_0x1c3acf[_0xa8c7('0x2c')],_0x2cb8b2[_0xa8c7('0x2e')]));if(_0x1c3acf['query'][_0xa8c7('0x3a')]){_0x283796[_0xa8c7('0x38')]=_[_0xa8c7('0x3b')](_0x283796['where'],{'$or':_['map'](_0x1c2232,function(_0x3ec927){if(_0x3ec927[_0xa8c7('0x3c')]['key']!==_0xa8c7('0x3d')){var _0x4ee7b1={};_0x4ee7b1[_0x3ec927[_0xa8c7('0x3e')]]={'$like':'%'+_0x1c3acf[_0xa8c7('0x2c')][_0xa8c7('0x3a')]+'%'};return _0x4ee7b1;}})});}_0x283796=_[_0xa8c7('0x3b')]({},_0x283796,_0x1c3acf[_0xa8c7('0x3f')]);var _0x56e252={'where':_0x283796[_0xa8c7('0x38')]};return db['MemberReport'][_0xa8c7('0x1c')](_0x56e252)[_0xa8c7('0x24')](function(_0xef2b45){_0x1239ea['count']=_0xef2b45;if(_0x1c3acf['query'][_0xa8c7('0x40')]){_0x283796[_0xa8c7('0x41')]=[{'all':!![]}];}return db[_0xa8c7('0x2a')][_0xa8c7('0x42')](_0x283796);})[_0xa8c7('0x24')](function(_0x3f5b12){_0x1239ea[_0xa8c7('0x43')]=_0x3f5b12;return _0x1239ea;})[_0xa8c7('0x24')](respondWithFilteredResult(_0x5dc2c3,_0x283796))[_0xa8c7('0x44')](handleError(_0x5dc2c3,null));};exports[_0xa8c7('0x45')]=function(_0x4cea93,_0x257390){var _0x58eda8={'raw':!![],'where':{'id':_0x4cea93['params']['id']}},_0x377e2b={};_0x377e2b[_0xa8c7('0x2b')]=_[_0xa8c7('0x2d')](db['MemberReport']['rawAttributes']);_0x377e2b['query']=_['keys'](_0x4cea93[_0xa8c7('0x2c')]);_0x377e2b[_0xa8c7('0x2e')]=_[_0xa8c7('0x2f')](_0x377e2b[_0xa8c7('0x2b')],_0x377e2b['query']);_0x58eda8[_0xa8c7('0x31')]=_['intersection'](_0x377e2b[_0xa8c7('0x2b')],qs['fields'](_0x4cea93[_0xa8c7('0x2c')][_0xa8c7('0x30')]));_0x58eda8[_0xa8c7('0x31')]=_0x58eda8[_0xa8c7('0x31')][_0xa8c7('0x32')]?_0x58eda8[_0xa8c7('0x31')]:_0x377e2b[_0xa8c7('0x2b')];if(_0x4cea93[_0xa8c7('0x2c')]['includeAll']){_0x58eda8[_0xa8c7('0x41')]=[{'all':!![]}];}_0x58eda8=_[_0xa8c7('0x3b')]({},_0x58eda8,_0x4cea93[_0xa8c7('0x3f')]);return db[_0xa8c7('0x2a')][_0xa8c7('0x46')](_0x58eda8)[_0xa8c7('0x24')](handleEntityNotFound(_0x257390,null))[_0xa8c7('0x24')](respondWithResult(_0x257390,null))[_0xa8c7('0x44')](handleError(_0x257390,null));};exports[_0xa8c7('0x47')]=function(_0x39c285,_0x2972d1){return db[_0xa8c7('0x2a')][_0xa8c7('0x47')](_0x39c285[_0xa8c7('0x48')],{})['then'](respondWithResult(_0x2972d1,0xc9))[_0xa8c7('0x44')](handleError(_0x2972d1,null));};exports[_0xa8c7('0x23')]=function(_0x2c02ec,_0x5c49b3){if(_0x2c02ec[_0xa8c7('0x48')]['id']){delete _0x2c02ec[_0xa8c7('0x48')]['id'];}return db[_0xa8c7('0x2a')]['find']({'where':{'id':_0x2c02ec[_0xa8c7('0x49')]['id']}})[_0xa8c7('0x24')](handleEntityNotFound(_0x5c49b3,null))['then'](saveUpdates(_0x2c02ec[_0xa8c7('0x48')],null))[_0xa8c7('0x24')](respondWithResult(_0x5c49b3,null))[_0xa8c7('0x44')](handleError(_0x5c49b3,null));};exports[_0xa8c7('0x4a')]=function(_0x595b3f,_0x458703){return db[_0xa8c7('0x2a')][_0xa8c7('0x46')]({'where':{'id':_0x595b3f[_0xa8c7('0x49')]['id']}})[_0xa8c7('0x24')](handleEntityNotFound(_0x458703,null))['then'](removeEntity(_0x458703,null))['catch'](handleError(_0x458703,null));};exports[_0xa8c7('0x4b')]=function(_0x10e149,_0x65331c){return db['MemberReport'][_0xa8c7('0x4b')]()[_0xa8c7('0x24')](respondWithResult(_0x65331c,null))[_0xa8c7('0x44')](handleError(_0x65331c,null));};