Built motion from commit 896e83a8.|2.6.30
[motion2.git] / server / api / faxQueueReport / faxQueueReport.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 _0xb11e=['ejs','squel','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','status','json','offset','limit','count','then','destroy','sendStatus','stack','name','send','map','FaxQueueReport','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','findAll','catch','params','include','create','body','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox'];(function(_0xc6b2ff,_0x1558d7){var _0x47f7a4=function(_0x1241f7){while(--_0x1241f7){_0xc6b2ff['push'](_0xc6b2ff['shift']());}};_0x47f7a4(++_0x1558d7);}(_0xb11e,0x7d));var _0xeb11=function(_0x34ca66,_0x42fa4d){_0x34ca66=_0x34ca66-0x0;var _0x450724=_0xb11e[_0x34ca66];return _0x450724;};'use strict';var emlformat=require(_0xeb11('0x0'));var rimraf=require(_0xeb11('0x1'));var zipdir=require(_0xeb11('0x2'));var jsonpatch=require(_0xeb11('0x3'));var rp=require(_0xeb11('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xeb11('0x5'));var util=require(_0xeb11('0x6'));var path=require(_0xeb11('0x7'));var sox=require(_0xeb11('0x8'));var csv=require('to-csv');var ejs=require(_0xeb11('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xeb11('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xeb11('0xb'));var toCsv=require(_0xeb11('0xc'));var querystring=require(_0xeb11('0xd'));var Papa=require('papaparse');var Redis=require(_0xeb11('0xe'));var authService=require(_0xeb11('0xf'));var qs=require(_0xeb11('0x10'));var as=require(_0xeb11('0x11'));var hardwareService=require(_0xeb11('0x12'));var logger=require(_0xeb11('0x13'))(_0xeb11('0x14'));var utils=require(_0xeb11('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xeb11('0x16'));var db=require(_0xeb11('0x17'))['db'];function respondWithStatusCode(_0x15b1e4,_0x517962){_0x517962=_0x517962||0xcc;return function(_0x44b192){if(_0x44b192){return _0x15b1e4['sendStatus'](_0x517962);}return _0x15b1e4[_0xeb11('0x18')](_0x517962)['end']();};}function respondWithResult(_0x5d183d,_0x146cfa){_0x146cfa=_0x146cfa||0xc8;return function(_0x2e0d2c){if(_0x2e0d2c){return _0x5d183d[_0xeb11('0x18')](_0x146cfa)[_0xeb11('0x19')](_0x2e0d2c);}};}function respondWithFilteredResult(_0x4c6a67,_0x58d276){return function(_0x200730){if(_0x200730){var _0xd1a9bf=typeof _0x58d276[_0xeb11('0x1a')]==='undefined'&&typeof _0x58d276[_0xeb11('0x1b')]==='undefined';var _0x33a996=_0x200730[_0xeb11('0x1c')];var _0x139ff8=_0xd1a9bf?0x0:_0x58d276['offset'];var _0xf36770=_0xd1a9bf?_0x200730[_0xeb11('0x1c')]:_0x58d276['offset']+_0x58d276['limit'];var _0x1906db;if(_0xf36770>=_0x33a996){_0xf36770=_0x33a996;_0x1906db=0xc8;}else{_0x1906db=0xce;}_0x4c6a67[_0xeb11('0x18')](_0x1906db);return _0x4c6a67['set']('Content-Range',_0x139ff8+'-'+_0xf36770+'/'+_0x33a996)[_0xeb11('0x19')](_0x200730);}return null;};}function patchUpdates(_0xf057c){return function(_0x4dfe03){try{jsonpatch['apply'](_0x4dfe03,_0xf057c,!![]);}catch(_0x17af28){return BPromise['reject'](_0x17af28);}return _0x4dfe03['save']();};}function saveUpdates(_0x5779df,_0xeeb427){return function(_0x1caf4f){if(_0x1caf4f){return _0x1caf4f['update'](_0x5779df)[_0xeb11('0x1d')](function(_0x40a4cb){return _0x40a4cb;});}return null;};}function removeEntity(_0x53e48d,_0x1c526d){return function(_0x3b2e1a){if(_0x3b2e1a){return _0x3b2e1a[_0xeb11('0x1e')]()['then'](function(){_0x53e48d[_0xeb11('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5b97b5,_0x8af064){return function(_0x2a4fc6){if(!_0x2a4fc6){_0x5b97b5[_0xeb11('0x1f')](0x194);}return _0x2a4fc6;};}function handleError(_0x59e3fb,_0x4d8cf8){_0x4d8cf8=_0x4d8cf8||0x1f4;return function(_0xca08dd){logger['error'](_0xca08dd[_0xeb11('0x20')]);if(_0xca08dd[_0xeb11('0x21')]){delete _0xca08dd[_0xeb11('0x21')];}_0x59e3fb[_0xeb11('0x18')](_0x4d8cf8)[_0xeb11('0x22')](_0xca08dd);};}exports['index']=function(_0x1d9bf7,_0x387fb7){var _0x4ee70a={},_0x104561={},_0x4bb5b8={'count':0x0,'rows':[]};var _0xa18410=_[_0xeb11('0x23')](db[_0xeb11('0x24')][_0xeb11('0x25')],function(_0x22e3d2){return{'name':_0x22e3d2[_0xeb11('0x26')],'type':_0x22e3d2[_0xeb11('0x27')][_0xeb11('0x28')]};});_0x104561[_0xeb11('0x29')]=_['map'](_0xa18410,_0xeb11('0x21'));_0x104561['query']=_[_0xeb11('0x2a')](_0x1d9bf7[_0xeb11('0x2b')]);_0x104561[_0xeb11('0x2c')]=_['intersection'](_0x104561['model'],_0x104561[_0xeb11('0x2b')]);_0x4ee70a[_0xeb11('0x2d')]=_[_0xeb11('0x2e')](_0x104561[_0xeb11('0x29')],qs['fields'](_0x1d9bf7[_0xeb11('0x2b')][_0xeb11('0x2f')]));_0x4ee70a[_0xeb11('0x2d')]=_0x4ee70a['attributes'][_0xeb11('0x30')]?_0x4ee70a['attributes']:_0x104561[_0xeb11('0x29')];if(!_0x1d9bf7['query'][_0xeb11('0x31')](_0xeb11('0x32'))){_0x4ee70a[_0xeb11('0x1b')]=qs[_0xeb11('0x1b')](_0x1d9bf7[_0xeb11('0x2b')][_0xeb11('0x1b')]);_0x4ee70a[_0xeb11('0x1a')]=qs['offset'](_0x1d9bf7[_0xeb11('0x2b')]['offset']);}_0x4ee70a[_0xeb11('0x33')]=qs['sort'](_0x1d9bf7[_0xeb11('0x2b')][_0xeb11('0x34')]);_0x4ee70a[_0xeb11('0x35')]=qs[_0xeb11('0x2c')](_['pick'](_0x1d9bf7[_0xeb11('0x2b')],_0x104561[_0xeb11('0x2c')]),_0xa18410);if(_0x1d9bf7[_0xeb11('0x2b')][_0xeb11('0x36')]){_0x4ee70a[_0xeb11('0x35')]=_[_0xeb11('0x37')](_0x4ee70a[_0xeb11('0x35')],{'$or':_[_0xeb11('0x23')](_0xa18410,function(_0x436aff){if(_0x436aff[_0xeb11('0x27')]!==_0xeb11('0x38')){var _0x25bc1a={};_0x25bc1a[_0x436aff[_0xeb11('0x21')]]={'$like':'%'+_0x1d9bf7[_0xeb11('0x2b')][_0xeb11('0x36')]+'%'};return _0x25bc1a;}})});}_0x4ee70a=_['merge']({},_0x4ee70a,_0x1d9bf7[_0xeb11('0x39')]);var _0x480bb9={'where':_0x4ee70a[_0xeb11('0x35')]};return db[_0xeb11('0x24')]['count'](_0x480bb9)['then'](function(_0x210dcc){_0x4bb5b8[_0xeb11('0x1c')]=_0x210dcc;if(_0x1d9bf7[_0xeb11('0x2b')][_0xeb11('0x3a')]){_0x4ee70a['include']=[{'all':!![]}];}return db[_0xeb11('0x24')][_0xeb11('0x3b')](_0x4ee70a);})[_0xeb11('0x1d')](function(_0xffa000){_0x4bb5b8['rows']=_0xffa000;return _0x4bb5b8;})['then'](respondWithFilteredResult(_0x387fb7,_0x4ee70a))[_0xeb11('0x3c')](handleError(_0x387fb7,null));};exports['show']=function(_0x7b589,_0xa750bf){var _0xfb67ee={'raw':!![],'where':{'id':_0x7b589[_0xeb11('0x3d')]['id']}},_0xdf32e7={};_0xdf32e7[_0xeb11('0x29')]=_['keys'](db['FaxQueueReport'][_0xeb11('0x25')]);_0xdf32e7[_0xeb11('0x2b')]=_[_0xeb11('0x2a')](_0x7b589['query']);_0xdf32e7[_0xeb11('0x2c')]=_[_0xeb11('0x2e')](_0xdf32e7[_0xeb11('0x29')],_0xdf32e7[_0xeb11('0x2b')]);_0xfb67ee[_0xeb11('0x2d')]=_['intersection'](_0xdf32e7['model'],qs[_0xeb11('0x2f')](_0x7b589['query'][_0xeb11('0x2f')]));_0xfb67ee[_0xeb11('0x2d')]=_0xfb67ee[_0xeb11('0x2d')][_0xeb11('0x30')]?_0xfb67ee[_0xeb11('0x2d')]:_0xdf32e7[_0xeb11('0x29')];if(_0x7b589['query'][_0xeb11('0x3a')]){_0xfb67ee[_0xeb11('0x3e')]=[{'all':!![]}];}_0xfb67ee=_[_0xeb11('0x37')]({},_0xfb67ee,_0x7b589[_0xeb11('0x39')]);return db[_0xeb11('0x24')]['find'](_0xfb67ee)[_0xeb11('0x1d')](handleEntityNotFound(_0xa750bf,null))[_0xeb11('0x1d')](respondWithResult(_0xa750bf,null))['catch'](handleError(_0xa750bf,null));};exports[_0xeb11('0x3f')]=function(_0x28d67a,_0x65e0ac){return db[_0xeb11('0x24')][_0xeb11('0x3f')](_0x28d67a['body'],{})['then'](respondWithResult(_0x65e0ac,0xc9))[_0xeb11('0x3c')](handleError(_0x65e0ac,null));};exports['update']=function(_0x355251,_0x2307ff){if(_0x355251[_0xeb11('0x40')]['id']){delete _0x355251[_0xeb11('0x40')]['id'];}return db['FaxQueueReport'][_0xeb11('0x41')]({'where':{'id':_0x355251[_0xeb11('0x3d')]['id']}})[_0xeb11('0x1d')](handleEntityNotFound(_0x2307ff,null))[_0xeb11('0x1d')](saveUpdates(_0x355251[_0xeb11('0x40')],null))['then'](respondWithResult(_0x2307ff,null))['catch'](handleError(_0x2307ff,null));};exports['destroy']=function(_0x315f87,_0x371513){return db['FaxQueueReport']['find']({'where':{'id':_0x315f87[_0xeb11('0x3d')]['id']}})['then'](handleEntityNotFound(_0x371513,null))[_0xeb11('0x1d')](removeEntity(_0x371513,null))[_0xeb11('0x3c')](handleError(_0x371513,null));};exports[_0xeb11('0x42')]=function(_0x3e2134,_0x24ecdc){return db[_0xeb11('0x24')][_0xeb11('0x42')]()[_0xeb11('0x1d')](respondWithResult(_0x24ecdc,null))[_0xeb11('0x3c')](handleError(_0x24ecdc,null));};