e6fa0236d40627335f41d42fc27d3299e93dca7c
[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 _0x83f1=['sox','to-csv','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','FaxQueueReport','rawAttributes','fieldName','model','map','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','show','params','length','find','catch','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path'];(function(_0x1e63f1,_0xe3c3cc){var _0x5bc880=function(_0x106961){while(--_0x106961){_0x1e63f1['push'](_0x1e63f1['shift']());}};_0x5bc880(++_0xe3c3cc);}(_0x83f1,0x1cc));var _0x183f=function(_0x245a26,_0x57c49e){_0x245a26=_0x245a26-0x0;var _0x3b87b9=_0x83f1[_0x245a26];return _0x3b87b9;};'use strict';var emlformat=require(_0x183f('0x0'));var rimraf=require(_0x183f('0x1'));var zipdir=require(_0x183f('0x2'));var jsonpatch=require(_0x183f('0x3'));var rp=require(_0x183f('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x183f('0x5'));var util=require(_0x183f('0x6'));var path=require(_0x183f('0x7'));var sox=require(_0x183f('0x8'));var csv=require(_0x183f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x183f('0xa'));var _=require(_0x183f('0xb'));var squel=require(_0x183f('0xc'));var crypto=require('crypto');var jsforce=require(_0x183f('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x183f('0x9'));var querystring=require(_0x183f('0xe'));var Papa=require(_0x183f('0xf'));var Redis=require(_0x183f('0x10'));var authService=require(_0x183f('0x11'));var qs=require(_0x183f('0x12'));var as=require(_0x183f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x183f('0x14'))(_0x183f('0x15'));var utils=require(_0x183f('0x16'));var config=require(_0x183f('0x17'));var licenseUtil=require(_0x183f('0x18'));var db=require(_0x183f('0x19'))['db'];function respondWithStatusCode(_0x16572d,_0x5e638c){_0x5e638c=_0x5e638c||0xcc;return function(_0x29452c){if(_0x29452c){return _0x16572d['sendStatus'](_0x5e638c);}return _0x16572d['status'](_0x5e638c)[_0x183f('0x1a')]();};}function respondWithResult(_0x417e1c,_0x37335a){_0x37335a=_0x37335a||0xc8;return function(_0x103526){if(_0x103526){return _0x417e1c[_0x183f('0x1b')](_0x37335a)['json'](_0x103526);}};}function respondWithFilteredResult(_0x170f43,_0x550a50){return function(_0x3e5994){if(_0x3e5994){var _0x357f65=typeof _0x550a50[_0x183f('0x1c')]==='undefined'&&typeof _0x550a50[_0x183f('0x1d')]===_0x183f('0x1e');var _0x3db030=_0x3e5994['count'];var _0x284244=_0x357f65?0x0:_0x550a50[_0x183f('0x1c')];var _0x2c3468=_0x357f65?_0x3e5994[_0x183f('0x1f')]:_0x550a50[_0x183f('0x1c')]+_0x550a50[_0x183f('0x1d')];var _0x5e7196;if(_0x2c3468>=_0x3db030){_0x2c3468=_0x3db030;_0x5e7196=0xc8;}else{_0x5e7196=0xce;}_0x170f43[_0x183f('0x1b')](_0x5e7196);return _0x170f43[_0x183f('0x20')](_0x183f('0x21'),_0x284244+'-'+_0x2c3468+'/'+_0x3db030)['json'](_0x3e5994);}return null;};}function patchUpdates(_0x26a103){return function(_0x4ad044){try{jsonpatch[_0x183f('0x22')](_0x4ad044,_0x26a103,!![]);}catch(_0x28e9c5){return BPromise[_0x183f('0x23')](_0x28e9c5);}return _0x4ad044[_0x183f('0x24')]();};}function saveUpdates(_0x52ef31,_0x3a1bec){return function(_0x29a5cb){if(_0x29a5cb){return _0x29a5cb[_0x183f('0x25')](_0x52ef31)[_0x183f('0x26')](function(_0x3871b7){return _0x3871b7;});}return null;};}function removeEntity(_0xde34f,_0x2b0f17){return function(_0x129ba5){if(_0x129ba5){return _0x129ba5[_0x183f('0x27')]()[_0x183f('0x26')](function(){_0xde34f['status'](0xcc)[_0x183f('0x1a')]();});}};}function handleEntityNotFound(_0x4d6ccf,_0x583326){return function(_0x427ea6){if(!_0x427ea6){_0x4d6ccf[_0x183f('0x28')](0x194);}return _0x427ea6;};}function handleError(_0x6c2913,_0x30e6bf){_0x30e6bf=_0x30e6bf||0x1f4;return function(_0x3fd9de){logger[_0x183f('0x29')](_0x3fd9de[_0x183f('0x2a')]);if(_0x3fd9de[_0x183f('0x2b')]){delete _0x3fd9de[_0x183f('0x2b')];}_0x6c2913[_0x183f('0x1b')](_0x30e6bf)[_0x183f('0x2c')](_0x3fd9de);};}exports[_0x183f('0x2d')]=function(_0x110853,_0x8e331b){var _0xb7a748={},_0x43bd3c={},_0x3566bf={'count':0x0,'rows':[]};var _0x483496=_['map'](db[_0x183f('0x2e')][_0x183f('0x2f')],function(_0x51e7f1){return{'name':_0x51e7f1[_0x183f('0x30')],'type':_0x51e7f1['type']['key']};});_0x43bd3c[_0x183f('0x31')]=_[_0x183f('0x32')](_0x483496,_0x183f('0x2b'));_0x43bd3c[_0x183f('0x33')]=_[_0x183f('0x34')](_0x110853[_0x183f('0x33')]);_0x43bd3c[_0x183f('0x35')]=_[_0x183f('0x36')](_0x43bd3c[_0x183f('0x31')],_0x43bd3c['query']);_0xb7a748[_0x183f('0x37')]=_[_0x183f('0x36')](_0x43bd3c[_0x183f('0x31')],qs[_0x183f('0x38')](_0x110853[_0x183f('0x33')]['fields']));_0xb7a748[_0x183f('0x37')]=_0xb7a748[_0x183f('0x37')]['length']?_0xb7a748[_0x183f('0x37')]:_0x43bd3c['model'];if(!_0x110853[_0x183f('0x33')][_0x183f('0x39')](_0x183f('0x3a'))){_0xb7a748[_0x183f('0x1d')]=qs['limit'](_0x110853[_0x183f('0x33')]['limit']);_0xb7a748[_0x183f('0x1c')]=qs[_0x183f('0x1c')](_0x110853['query'][_0x183f('0x1c')]);}_0xb7a748[_0x183f('0x3b')]=qs['sort'](_0x110853[_0x183f('0x33')][_0x183f('0x3c')]);_0xb7a748[_0x183f('0x3d')]=qs[_0x183f('0x35')](_[_0x183f('0x3e')](_0x110853[_0x183f('0x33')],_0x43bd3c[_0x183f('0x35')]),_0x483496);if(_0x110853[_0x183f('0x33')][_0x183f('0x3f')]){_0xb7a748['where']=_[_0x183f('0x40')](_0xb7a748[_0x183f('0x3d')],{'$or':_[_0x183f('0x32')](_0x483496,function(_0x458942){if(_0x458942[_0x183f('0x41')]!==_0x183f('0x42')){var _0x512f3f={};_0x512f3f[_0x458942[_0x183f('0x2b')]]={'$like':'%'+_0x110853[_0x183f('0x33')][_0x183f('0x3f')]+'%'};return _0x512f3f;}})});}_0xb7a748=_['merge']({},_0xb7a748,_0x110853[_0x183f('0x43')]);var _0x1c9eb6={'where':_0xb7a748[_0x183f('0x3d')]};return db[_0x183f('0x2e')][_0x183f('0x1f')](_0x1c9eb6)[_0x183f('0x26')](function(_0x4fe2ce){_0x3566bf[_0x183f('0x1f')]=_0x4fe2ce;if(_0x110853[_0x183f('0x33')][_0x183f('0x44')]){_0xb7a748[_0x183f('0x45')]=[{'all':!![]}];}return db[_0x183f('0x2e')]['findAll'](_0xb7a748);})[_0x183f('0x26')](function(_0x502c1a){_0x3566bf['rows']=_0x502c1a;return _0x3566bf;})[_0x183f('0x26')](respondWithFilteredResult(_0x8e331b,_0xb7a748))['catch'](handleError(_0x8e331b,null));};exports[_0x183f('0x46')]=function(_0x37214f,_0x546f14){var _0x107d04={'raw':!![],'where':{'id':_0x37214f[_0x183f('0x47')]['id']}},_0x118385={};_0x118385[_0x183f('0x31')]=_[_0x183f('0x34')](db[_0x183f('0x2e')][_0x183f('0x2f')]);_0x118385[_0x183f('0x33')]=_['keys'](_0x37214f[_0x183f('0x33')]);_0x118385[_0x183f('0x35')]=_[_0x183f('0x36')](_0x118385[_0x183f('0x31')],_0x118385[_0x183f('0x33')]);_0x107d04[_0x183f('0x37')]=_[_0x183f('0x36')](_0x118385[_0x183f('0x31')],qs[_0x183f('0x38')](_0x37214f[_0x183f('0x33')][_0x183f('0x38')]));_0x107d04[_0x183f('0x37')]=_0x107d04[_0x183f('0x37')][_0x183f('0x48')]?_0x107d04['attributes']:_0x118385[_0x183f('0x31')];if(_0x37214f[_0x183f('0x33')]['includeAll']){_0x107d04[_0x183f('0x45')]=[{'all':!![]}];}_0x107d04=_[_0x183f('0x40')]({},_0x107d04,_0x37214f[_0x183f('0x43')]);return db[_0x183f('0x2e')][_0x183f('0x49')](_0x107d04)['then'](handleEntityNotFound(_0x546f14,null))['then'](respondWithResult(_0x546f14,null))[_0x183f('0x4a')](handleError(_0x546f14,null));};exports[_0x183f('0x4b')]=function(_0x569354,_0x34f49e){return db[_0x183f('0x2e')]['create'](_0x569354[_0x183f('0x4c')],{})[_0x183f('0x26')](respondWithResult(_0x34f49e,0xc9))[_0x183f('0x4a')](handleError(_0x34f49e,null));};exports['update']=function(_0x2488ad,_0x5f9312){if(_0x2488ad[_0x183f('0x4c')]['id']){delete _0x2488ad[_0x183f('0x4c')]['id'];}return db[_0x183f('0x2e')][_0x183f('0x49')]({'where':{'id':_0x2488ad['params']['id']}})[_0x183f('0x26')](handleEntityNotFound(_0x5f9312,null))[_0x183f('0x26')](saveUpdates(_0x2488ad['body'],null))['then'](respondWithResult(_0x5f9312,null))[_0x183f('0x4a')](handleError(_0x5f9312,null));};exports[_0x183f('0x27')]=function(_0x4c4554,_0x2c79b7){return db[_0x183f('0x2e')]['find']({'where':{'id':_0x4c4554[_0x183f('0x47')]['id']}})['then'](handleEntityNotFound(_0x2c79b7,null))[_0x183f('0x26')](removeEntity(_0x2c79b7,null))[_0x183f('0x4a')](handleError(_0x2c79b7,null));};exports[_0x183f('0x4d')]=function(_0x23aeb3,_0x5b609f){return db[_0x183f('0x2e')][_0x183f('0x4d')]()['then'](respondWithResult(_0x5b609f,null))['catch'](handleError(_0x5b609f,null));};