df391f9349430804cbbc472c519999554f15ec63
[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 _0xf015=['api','../../config/environment','../../mysqldb','sendStatus','status','json','offset','set','Content-Range','apply','reject','save','update','destroy','then','end','error','stack','name','send','index','map','MemberReport','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','filters','filter','merge','type','VIRTUAL','options','includeAll','findAll','rows','params','include','find','catch','create','body','describe','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger'];(function(_0x107995,_0x42fb77){var _0xa09073=function(_0x581ba7){while(--_0x581ba7){_0x107995['push'](_0x107995['shift']());}};_0xa09073(++_0x42fb77);}(_0xf015,0xc2));var _0x5f01=function(_0x1823e9,_0x2d7b01){_0x1823e9=_0x1823e9-0x0;var _0x29808f=_0xf015[_0x1823e9];return _0x29808f;};'use strict';var pdf=require(_0x5f01('0x0'));var emlformat=require(_0x5f01('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x5f01('0x2'));var jsonpatch=require(_0x5f01('0x3'));var rp=require(_0x5f01('0x4'));var moment=require(_0x5f01('0x5'));var BPromise=require(_0x5f01('0x6'));var Mustache=require(_0x5f01('0x7'));var util=require(_0x5f01('0x8'));var path=require(_0x5f01('0x9'));var sox=require(_0x5f01('0xa'));var csv=require('to-csv');var ejs=require(_0x5f01('0xb'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x5f01('0xc'));var jsforce=require(_0x5f01('0xd'));var deskjs=require(_0x5f01('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x5f01('0xf'));var Redis=require('ioredis');var authService=require(_0x5f01('0x10'));var qs=require(_0x5f01('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x5f01('0x12'))(_0x5f01('0x13'));var utils=require('../../config/utils');var config=require(_0x5f01('0x14'));var db=require(_0x5f01('0x15'))['db'];function respondWithStatusCode(_0x5f2b92,_0x4de2ce){_0x4de2ce=_0x4de2ce||0xcc;return function(_0xcdc919){if(_0xcdc919){return _0x5f2b92[_0x5f01('0x16')](_0x4de2ce);}return _0x5f2b92[_0x5f01('0x17')](_0x4de2ce)['end']();};}function respondWithResult(_0x2b77f6,_0x4498b6){_0x4498b6=_0x4498b6||0xc8;return function(_0x4d13f0){if(_0x4d13f0){return _0x2b77f6[_0x5f01('0x17')](_0x4498b6)[_0x5f01('0x18')](_0x4d13f0);}};}function respondWithFilteredResult(_0x2664cf,_0x1f0bd1){return function(_0x100a71){if(_0x100a71){var _0x16f8ea=_0x100a71['count'],_0x1bba2b=_0x1f0bd1[_0x5f01('0x19')],_0x2be2b5=_0x1f0bd1[_0x5f01('0x19')]+_0x1f0bd1['limit'],_0x568523;if(_0x2be2b5>=_0x16f8ea){_0x2be2b5=_0x16f8ea;_0x568523=0xc8;}else{_0x568523=0xce;}_0x2664cf[_0x5f01('0x17')](_0x568523);return _0x2664cf[_0x5f01('0x1a')](_0x5f01('0x1b'),_0x1bba2b+'-'+_0x2be2b5+'/'+_0x16f8ea)['json'](_0x100a71);}return null;};}function patchUpdates(_0x27069f){return function(_0x1d8040){try{jsonpatch[_0x5f01('0x1c')](_0x1d8040,_0x27069f,!![]);}catch(_0x4daadf){return BPromise[_0x5f01('0x1d')](_0x4daadf);}return _0x1d8040[_0x5f01('0x1e')]();};}function saveUpdates(_0x1bfd4c,_0x5ae548){return function(_0x1d437b){if(_0x1d437b){return _0x1d437b[_0x5f01('0x1f')](_0x1bfd4c)['then'](function(_0x243f75){return _0x243f75;});}return null;};}function removeEntity(_0x35cd02,_0x5c8cc6){return function(_0xbd9e82){if(_0xbd9e82){return _0xbd9e82[_0x5f01('0x20')]()[_0x5f01('0x21')](function(){_0x35cd02[_0x5f01('0x17')](0xcc)[_0x5f01('0x22')]();});}};}function handleEntityNotFound(_0x37a817,_0x268ce8){return function(_0x15af9b){if(!_0x15af9b){_0x37a817[_0x5f01('0x16')](0x194);}return _0x15af9b;};}function handleError(_0x59193f,_0x2cc737){_0x2cc737=_0x2cc737||0x1f4;return function(_0x32874a){logger[_0x5f01('0x23')](_0x32874a[_0x5f01('0x24')]);if(_0x32874a[_0x5f01('0x25')]){delete _0x32874a['name'];}_0x59193f[_0x5f01('0x17')](_0x2cc737)[_0x5f01('0x26')](_0x32874a);};}exports[_0x5f01('0x27')]=function(_0x52b76d,_0x482ea3){var _0x1c2074={},_0x11bc29={},_0x42287f={'count':0x0,'rows':[]};var _0x5ec8ee=_[_0x5f01('0x28')](db[_0x5f01('0x29')]['rawAttributes'],function(_0x3ca33b){return{'name':_0x3ca33b['fieldName'],'type':_0x3ca33b['type'][_0x5f01('0x2a')]};});_0x11bc29[_0x5f01('0x2b')]=_[_0x5f01('0x28')](_0x5ec8ee,_0x5f01('0x25'));_0x11bc29[_0x5f01('0x2c')]=_[_0x5f01('0x2d')](_0x52b76d[_0x5f01('0x2c')]);_0x11bc29['filters']=_[_0x5f01('0x2e')](_0x11bc29[_0x5f01('0x2b')],_0x11bc29['query']);_0x1c2074[_0x5f01('0x2f')]=_[_0x5f01('0x2e')](_0x11bc29[_0x5f01('0x2b')],qs[_0x5f01('0x30')](_0x52b76d[_0x5f01('0x2c')]['fields']));_0x1c2074['attributes']=_0x1c2074[_0x5f01('0x2f')][_0x5f01('0x31')]?_0x1c2074['attributes']:_0x11bc29['model'];if(!_0x52b76d['query'][_0x5f01('0x32')](_0x5f01('0x33'))){_0x1c2074[_0x5f01('0x34')]=qs[_0x5f01('0x34')](_0x52b76d[_0x5f01('0x2c')][_0x5f01('0x34')]);_0x1c2074[_0x5f01('0x19')]=qs['offset'](_0x52b76d[_0x5f01('0x2c')][_0x5f01('0x19')]);}_0x1c2074['order']=qs['sort'](_0x52b76d[_0x5f01('0x2c')][_0x5f01('0x35')]);_0x1c2074[_0x5f01('0x36')]=qs[_0x5f01('0x37')](_['pick'](_0x52b76d['query'],_0x11bc29['filters']),_0x5ec8ee);if(_0x52b76d[_0x5f01('0x2c')][_0x5f01('0x38')]){_0x1c2074[_0x5f01('0x36')]=_[_0x5f01('0x39')](_0x1c2074['where'],{'$or':_[_0x5f01('0x28')](_0x5ec8ee,function(_0x380b20){if(_0x380b20[_0x5f01('0x3a')]!==_0x5f01('0x3b')){var _0x4bebcf={};_0x4bebcf[_0x380b20[_0x5f01('0x25')]]={'$like':'%'+_0x52b76d['query'][_0x5f01('0x38')]+'%'};return _0x4bebcf;}})});}_0x1c2074=_[_0x5f01('0x39')]({},_0x1c2074,_0x52b76d[_0x5f01('0x3c')]);var _0x1e7144={'where':_0x1c2074[_0x5f01('0x36')]};return db[_0x5f01('0x29')]['count'](_0x1e7144)[_0x5f01('0x21')](function(_0x59428e){_0x42287f['count']=_0x59428e;if(_0x52b76d[_0x5f01('0x2c')][_0x5f01('0x3d')]){_0x1c2074['include']=[{'all':!![]}];}return db[_0x5f01('0x29')][_0x5f01('0x3e')](_0x1c2074);})['then'](function(_0x289831){_0x42287f[_0x5f01('0x3f')]=_0x289831;return _0x42287f;})[_0x5f01('0x21')](respondWithFilteredResult(_0x482ea3,_0x1c2074))['catch'](handleError(_0x482ea3,null));};exports['show']=function(_0x41e418,_0x2de445){var _0x5b0b05={'raw':!![],'where':{'id':_0x41e418[_0x5f01('0x40')]['id']}},_0x3e3bf4={};_0x3e3bf4[_0x5f01('0x2b')]=_[_0x5f01('0x2d')](db[_0x5f01('0x29')]['rawAttributes']);_0x3e3bf4[_0x5f01('0x2c')]=_[_0x5f01('0x2d')](_0x41e418['query']);_0x3e3bf4['filters']=_[_0x5f01('0x2e')](_0x3e3bf4[_0x5f01('0x2b')],_0x3e3bf4['query']);_0x5b0b05[_0x5f01('0x2f')]=_['intersection'](_0x3e3bf4['model'],qs['fields'](_0x41e418['query'][_0x5f01('0x30')]));_0x5b0b05[_0x5f01('0x2f')]=_0x5b0b05[_0x5f01('0x2f')][_0x5f01('0x31')]?_0x5b0b05[_0x5f01('0x2f')]:_0x3e3bf4['model'];if(_0x41e418[_0x5f01('0x2c')]['includeAll']){_0x5b0b05[_0x5f01('0x41')]=[{'all':!![]}];}_0x5b0b05=_[_0x5f01('0x39')]({},_0x5b0b05,_0x41e418[_0x5f01('0x3c')]);return db[_0x5f01('0x29')][_0x5f01('0x42')](_0x5b0b05)[_0x5f01('0x21')](handleEntityNotFound(_0x2de445,null))[_0x5f01('0x21')](respondWithResult(_0x2de445,null))[_0x5f01('0x43')](handleError(_0x2de445,null));};exports[_0x5f01('0x44')]=function(_0x56c60c,_0x254919){return db['MemberReport'][_0x5f01('0x44')](_0x56c60c['body'],{})[_0x5f01('0x21')](respondWithResult(_0x254919,0xc9))['catch'](handleError(_0x254919,null));};exports[_0x5f01('0x1f')]=function(_0x546abc,_0xbb1da){if(_0x546abc[_0x5f01('0x45')]['id']){delete _0x546abc['body']['id'];}return db[_0x5f01('0x29')][_0x5f01('0x42')]({'where':{'id':_0x546abc['params']['id']}})[_0x5f01('0x21')](handleEntityNotFound(_0xbb1da,null))[_0x5f01('0x21')](saveUpdates(_0x546abc['body'],null))[_0x5f01('0x21')](respondWithResult(_0xbb1da,null))['catch'](handleError(_0xbb1da,null));};exports[_0x5f01('0x20')]=function(_0x580856,_0x68b9df){return db[_0x5f01('0x29')]['find']({'where':{'id':_0x580856[_0x5f01('0x40')]['id']}})['then'](handleEntityNotFound(_0x68b9df,null))['then'](removeEntity(_0x68b9df,null))[_0x5f01('0x43')](handleError(_0x68b9df,null));};exports[_0x5f01('0x46')]=function(_0x137899,_0x1f65e8){return db['MemberReport'][_0x5f01('0x46')]()[_0x5f01('0x21')](respondWithResult(_0x1f65e8,null))[_0x5f01('0x43')](handleError(_0x1f65e8,null));};