Built motion from commit 639a1a7f.|2.6.19
[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 _0xc298=['sort','where','filters','pick','filter','merge','options','FaxQueueReport','includeAll','include','findAll','catch','show','params','length','create','body','destroy','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','count','limit','set','Content-Range','json','reject','save','update','then','error','name','send','index','map','rawAttributes','type','key','query','keys','intersection','model','attributes','fields','hasOwnProperty','nolimit','order'];(function(_0xd1b4d7,_0x28b2c1){var _0x3002ec=function(_0x3d95ce){while(--_0x3d95ce){_0xd1b4d7['push'](_0xd1b4d7['shift']());}};_0x3002ec(++_0x28b2c1);}(_0xc298,0x143));var _0x8c29=function(_0x17b572,_0x544508){_0x17b572=_0x17b572-0x0;var _0x1d2f7a=_0xc298[_0x17b572];return _0x1d2f7a;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8c29('0x0'));var zipdir=require(_0x8c29('0x1'));var jsonpatch=require(_0x8c29('0x2'));var rp=require(_0x8c29('0x3'));var moment=require(_0x8c29('0x4'));var BPromise=require(_0x8c29('0x5'));var Mustache=require('mustache');var util=require(_0x8c29('0x6'));var path=require(_0x8c29('0x7'));var sox=require(_0x8c29('0x8'));var csv=require(_0x8c29('0x9'));var ejs=require(_0x8c29('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8c29('0xb'));var squel=require(_0x8c29('0xc'));var crypto=require(_0x8c29('0xd'));var jsforce=require(_0x8c29('0xe'));var deskjs=require(_0x8c29('0xf'));var toCsv=require(_0x8c29('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x8c29('0x10'));var qs=require(_0x8c29('0x11'));var as=require(_0x8c29('0x12'));var hardwareService=require(_0x8c29('0x13'));var logger=require(_0x8c29('0x14'))(_0x8c29('0x15'));var utils=require(_0x8c29('0x16'));var config=require(_0x8c29('0x17'));var licenseUtil=require(_0x8c29('0x18'));var db=require(_0x8c29('0x19'))['db'];function respondWithStatusCode(_0xd82e60,_0x1dc424){_0x1dc424=_0x1dc424||0xcc;return function(_0x3023d2){if(_0x3023d2){return _0xd82e60[_0x8c29('0x1a')](_0x1dc424);}return _0xd82e60[_0x8c29('0x1b')](_0x1dc424)[_0x8c29('0x1c')]();};}function respondWithResult(_0x5a9eb8,_0x3dc480){_0x3dc480=_0x3dc480||0xc8;return function(_0xcdae4d){if(_0xcdae4d){return _0x5a9eb8['status'](_0x3dc480)['json'](_0xcdae4d);}};}function respondWithFilteredResult(_0x17d84b,_0xe87c50){return function(_0x4929b9){if(_0x4929b9){var _0x24add4=typeof _0xe87c50[_0x8c29('0x1d')]===_0x8c29('0x1e')&&typeof _0xe87c50['limit']===_0x8c29('0x1e');var _0x37fc8e=_0x4929b9[_0x8c29('0x1f')];var _0x6324b8=_0x24add4?0x0:_0xe87c50[_0x8c29('0x1d')];var _0x21ada9=_0x24add4?_0x4929b9['count']:_0xe87c50[_0x8c29('0x1d')]+_0xe87c50[_0x8c29('0x20')];var _0x41e389;if(_0x21ada9>=_0x37fc8e){_0x21ada9=_0x37fc8e;_0x41e389=0xc8;}else{_0x41e389=0xce;}_0x17d84b[_0x8c29('0x1b')](_0x41e389);return _0x17d84b[_0x8c29('0x21')](_0x8c29('0x22'),_0x6324b8+'-'+_0x21ada9+'/'+_0x37fc8e)[_0x8c29('0x23')](_0x4929b9);}return null;};}function patchUpdates(_0x10810c){return function(_0x5c62a0){try{jsonpatch['apply'](_0x5c62a0,_0x10810c,!![]);}catch(_0x2702a1){return BPromise[_0x8c29('0x24')](_0x2702a1);}return _0x5c62a0[_0x8c29('0x25')]();};}function saveUpdates(_0x513efd,_0x5a61f3){return function(_0x3fb320){if(_0x3fb320){return _0x3fb320[_0x8c29('0x26')](_0x513efd)[_0x8c29('0x27')](function(_0x157e61){return _0x157e61;});}return null;};}function removeEntity(_0x34cf21,_0x507124){return function(_0x40431d){if(_0x40431d){return _0x40431d['destroy']()[_0x8c29('0x27')](function(){_0x34cf21['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x2c7979,_0x376297){return function(_0x3a967d){if(!_0x3a967d){_0x2c7979['sendStatus'](0x194);}return _0x3a967d;};}function handleError(_0x38a45c,_0x4e0066){_0x4e0066=_0x4e0066||0x1f4;return function(_0x5cd1e7){logger[_0x8c29('0x28')](_0x5cd1e7['stack']);if(_0x5cd1e7[_0x8c29('0x29')]){delete _0x5cd1e7[_0x8c29('0x29')];}_0x38a45c['status'](_0x4e0066)[_0x8c29('0x2a')](_0x5cd1e7);};}exports[_0x8c29('0x2b')]=function(_0x4eee54,_0x2c6ae1){var _0x5dd93a={},_0x48996c={},_0x25f26a={'count':0x0,'rows':[]};var _0x20e42f=_[_0x8c29('0x2c')](db['FaxQueueReport'][_0x8c29('0x2d')],function(_0xde770a){return{'name':_0xde770a['fieldName'],'type':_0xde770a[_0x8c29('0x2e')][_0x8c29('0x2f')]};});_0x48996c['model']=_[_0x8c29('0x2c')](_0x20e42f,_0x8c29('0x29'));_0x48996c[_0x8c29('0x30')]=_[_0x8c29('0x31')](_0x4eee54[_0x8c29('0x30')]);_0x48996c['filters']=_[_0x8c29('0x32')](_0x48996c[_0x8c29('0x33')],_0x48996c[_0x8c29('0x30')]);_0x5dd93a[_0x8c29('0x34')]=_[_0x8c29('0x32')](_0x48996c[_0x8c29('0x33')],qs[_0x8c29('0x35')](_0x4eee54['query'][_0x8c29('0x35')]));_0x5dd93a[_0x8c29('0x34')]=_0x5dd93a[_0x8c29('0x34')]['length']?_0x5dd93a[_0x8c29('0x34')]:_0x48996c[_0x8c29('0x33')];if(!_0x4eee54['query'][_0x8c29('0x36')](_0x8c29('0x37'))){_0x5dd93a['limit']=qs[_0x8c29('0x20')](_0x4eee54[_0x8c29('0x30')][_0x8c29('0x20')]);_0x5dd93a[_0x8c29('0x1d')]=qs['offset'](_0x4eee54[_0x8c29('0x30')][_0x8c29('0x1d')]);}_0x5dd93a[_0x8c29('0x38')]=qs[_0x8c29('0x39')](_0x4eee54[_0x8c29('0x30')]['sort']);_0x5dd93a[_0x8c29('0x3a')]=qs[_0x8c29('0x3b')](_[_0x8c29('0x3c')](_0x4eee54[_0x8c29('0x30')],_0x48996c[_0x8c29('0x3b')]),_0x20e42f);if(_0x4eee54[_0x8c29('0x30')][_0x8c29('0x3d')]){_0x5dd93a[_0x8c29('0x3a')]=_[_0x8c29('0x3e')](_0x5dd93a[_0x8c29('0x3a')],{'$or':_['map'](_0x20e42f,function(_0x351628){if(_0x351628[_0x8c29('0x2e')]!=='VIRTUAL'){var _0x426335={};_0x426335[_0x351628[_0x8c29('0x29')]]={'$like':'%'+_0x4eee54[_0x8c29('0x30')]['filter']+'%'};return _0x426335;}})});}_0x5dd93a=_[_0x8c29('0x3e')]({},_0x5dd93a,_0x4eee54[_0x8c29('0x3f')]);var _0x507aea={'where':_0x5dd93a[_0x8c29('0x3a')]};return db[_0x8c29('0x40')][_0x8c29('0x1f')](_0x507aea)[_0x8c29('0x27')](function(_0x313111){_0x25f26a['count']=_0x313111;if(_0x4eee54[_0x8c29('0x30')][_0x8c29('0x41')]){_0x5dd93a[_0x8c29('0x42')]=[{'all':!![]}];}return db[_0x8c29('0x40')][_0x8c29('0x43')](_0x5dd93a);})[_0x8c29('0x27')](function(_0x187da3){_0x25f26a['rows']=_0x187da3;return _0x25f26a;})[_0x8c29('0x27')](respondWithFilteredResult(_0x2c6ae1,_0x5dd93a))[_0x8c29('0x44')](handleError(_0x2c6ae1,null));};exports[_0x8c29('0x45')]=function(_0x258d4e,_0x5910ff){var _0x59faaf={'raw':!![],'where':{'id':_0x258d4e[_0x8c29('0x46')]['id']}},_0x127ad1={};_0x127ad1['model']=_[_0x8c29('0x31')](db[_0x8c29('0x40')][_0x8c29('0x2d')]);_0x127ad1[_0x8c29('0x30')]=_[_0x8c29('0x31')](_0x258d4e['query']);_0x127ad1[_0x8c29('0x3b')]=_['intersection'](_0x127ad1['model'],_0x127ad1['query']);_0x59faaf[_0x8c29('0x34')]=_[_0x8c29('0x32')](_0x127ad1[_0x8c29('0x33')],qs['fields'](_0x258d4e[_0x8c29('0x30')][_0x8c29('0x35')]));_0x59faaf['attributes']=_0x59faaf[_0x8c29('0x34')][_0x8c29('0x47')]?_0x59faaf[_0x8c29('0x34')]:_0x127ad1[_0x8c29('0x33')];if(_0x258d4e['query']['includeAll']){_0x59faaf['include']=[{'all':!![]}];}_0x59faaf=_[_0x8c29('0x3e')]({},_0x59faaf,_0x258d4e[_0x8c29('0x3f')]);return db['FaxQueueReport']['find'](_0x59faaf)[_0x8c29('0x27')](handleEntityNotFound(_0x5910ff,null))[_0x8c29('0x27')](respondWithResult(_0x5910ff,null))[_0x8c29('0x44')](handleError(_0x5910ff,null));};exports[_0x8c29('0x48')]=function(_0x3d3467,_0x2bb16f){return db[_0x8c29('0x40')]['create'](_0x3d3467[_0x8c29('0x49')],{})[_0x8c29('0x27')](respondWithResult(_0x2bb16f,0xc9))[_0x8c29('0x44')](handleError(_0x2bb16f,null));};exports[_0x8c29('0x26')]=function(_0x1ba6e2,_0x577459){if(_0x1ba6e2[_0x8c29('0x49')]['id']){delete _0x1ba6e2[_0x8c29('0x49')]['id'];}return db[_0x8c29('0x40')]['find']({'where':{'id':_0x1ba6e2[_0x8c29('0x46')]['id']}})[_0x8c29('0x27')](handleEntityNotFound(_0x577459,null))[_0x8c29('0x27')](saveUpdates(_0x1ba6e2[_0x8c29('0x49')],null))[_0x8c29('0x27')](respondWithResult(_0x577459,null))['catch'](handleError(_0x577459,null));};exports[_0x8c29('0x4a')]=function(_0x11b351,_0x4762c1){return db['FaxQueueReport']['find']({'where':{'id':_0x11b351[_0x8c29('0x46')]['id']}})[_0x8c29('0x27')](handleEntityNotFound(_0x4762c1,null))[_0x8c29('0x27')](removeEntity(_0x4762c1,null))[_0x8c29('0x44')](handleError(_0x4762c1,null));};exports['describe']=function(_0x39ffcb,_0x1a6a65){return db[_0x8c29('0x40')][_0x8c29('0x4b')]()[_0x8c29('0x27')](respondWithResult(_0x1a6a65,null))[_0x8c29('0x44')](handleError(_0x1a6a65,null));};