Built motion from commit e0fa946e.|2.6.5
[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 _0xea70=['body','destroy','describe','eml-format','rimraf','zip-dir','request-promise','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','status','end','undefined','limit','count','offset','set','Content-Range','json','reject','save','update','then','stack','name','send','index','map','FaxQueueReport','rawAttributes','fieldName','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filters','filter','type','VIRTUAL','merge','options','include','findAll','show','params','find','catch','create'];(function(_0x132995,_0x5ece6a){var _0x55880e=function(_0x204b76){while(--_0x204b76){_0x132995['push'](_0x132995['shift']());}};_0x55880e(++_0x5ece6a);}(_0xea70,0x175));var _0x0ea7=function(_0x4565bf,_0x5ad9d6){_0x4565bf=_0x4565bf-0x0;var _0x5610ba=_0xea70[_0x4565bf];return _0x5610ba;};'use strict';var emlformat=require(_0x0ea7('0x0'));var rimraf=require(_0x0ea7('0x1'));var zipdir=require(_0x0ea7('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0ea7('0x3'));var moment=require('moment');var BPromise=require(_0x0ea7('0x4'));var Mustache=require('mustache');var util=require(_0x0ea7('0x5'));var path=require(_0x0ea7('0x6'));var sox=require(_0x0ea7('0x7'));var csv=require(_0x0ea7('0x8'));var ejs=require(_0x0ea7('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x0ea7('0xa'));var squel=require(_0x0ea7('0xb'));var crypto=require('crypto');var jsforce=require(_0x0ea7('0xc'));var deskjs=require(_0x0ea7('0xd'));var toCsv=require('to-csv');var querystring=require(_0x0ea7('0xe'));var Papa=require(_0x0ea7('0xf'));var Redis=require(_0x0ea7('0x10'));var authService=require(_0x0ea7('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x0ea7('0x12'));var hardwareService=require(_0x0ea7('0x13'));var logger=require(_0x0ea7('0x14'))(_0x0ea7('0x15'));var utils=require(_0x0ea7('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x0ea7('0x17'));var db=require(_0x0ea7('0x18'))['db'];function respondWithStatusCode(_0x349753,_0x56d68f){_0x56d68f=_0x56d68f||0xcc;return function(_0x5addc6){if(_0x5addc6){return _0x349753['sendStatus'](_0x56d68f);}return _0x349753[_0x0ea7('0x19')](_0x56d68f)[_0x0ea7('0x1a')]();};}function respondWithResult(_0x3312b3,_0x2cd543){_0x2cd543=_0x2cd543||0xc8;return function(_0x4e1cd9){if(_0x4e1cd9){return _0x3312b3['status'](_0x2cd543)['json'](_0x4e1cd9);}};}function respondWithFilteredResult(_0x44e922,_0x1e52e1){return function(_0xa6b67f){if(_0xa6b67f){var _0x548dad=typeof _0x1e52e1['offset']===_0x0ea7('0x1b')&&typeof _0x1e52e1[_0x0ea7('0x1c')]===_0x0ea7('0x1b');var _0x22fae2=_0xa6b67f[_0x0ea7('0x1d')];var _0x987032=_0x548dad?0x0:_0x1e52e1[_0x0ea7('0x1e')];var _0x48f10a=_0x548dad?_0xa6b67f['count']:_0x1e52e1[_0x0ea7('0x1e')]+_0x1e52e1[_0x0ea7('0x1c')];var _0x4f526b;if(_0x48f10a>=_0x22fae2){_0x48f10a=_0x22fae2;_0x4f526b=0xc8;}else{_0x4f526b=0xce;}_0x44e922[_0x0ea7('0x19')](_0x4f526b);return _0x44e922[_0x0ea7('0x1f')](_0x0ea7('0x20'),_0x987032+'-'+_0x48f10a+'/'+_0x22fae2)[_0x0ea7('0x21')](_0xa6b67f);}return null;};}function patchUpdates(_0x306ace){return function(_0x38494d){try{jsonpatch['apply'](_0x38494d,_0x306ace,!![]);}catch(_0x1f3bce){return BPromise[_0x0ea7('0x22')](_0x1f3bce);}return _0x38494d[_0x0ea7('0x23')]();};}function saveUpdates(_0x61c70e,_0x411603){return function(_0x82bb8){if(_0x82bb8){return _0x82bb8[_0x0ea7('0x24')](_0x61c70e)[_0x0ea7('0x25')](function(_0x47b53b){return _0x47b53b;});}return null;};}function removeEntity(_0x25b6c9,_0x2a0f71){return function(_0x76d6a9){if(_0x76d6a9){return _0x76d6a9['destroy']()[_0x0ea7('0x25')](function(){_0x25b6c9[_0x0ea7('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3ba808,_0x5870b2){return function(_0x5adf93){if(!_0x5adf93){_0x3ba808['sendStatus'](0x194);}return _0x5adf93;};}function handleError(_0x32b956,_0x36ff0a){_0x36ff0a=_0x36ff0a||0x1f4;return function(_0x462715){logger['error'](_0x462715[_0x0ea7('0x26')]);if(_0x462715[_0x0ea7('0x27')]){delete _0x462715[_0x0ea7('0x27')];}_0x32b956[_0x0ea7('0x19')](_0x36ff0a)[_0x0ea7('0x28')](_0x462715);};}exports[_0x0ea7('0x29')]=function(_0x247c8c,_0x3fe1e3){var _0x4b6c47={},_0x27e9fd={},_0x3d07c3={'count':0x0,'rows':[]};var _0x51f18a=_[_0x0ea7('0x2a')](db[_0x0ea7('0x2b')][_0x0ea7('0x2c')],function(_0x465da4){return{'name':_0x465da4[_0x0ea7('0x2d')],'type':_0x465da4['type'][_0x0ea7('0x2e')]};});_0x27e9fd[_0x0ea7('0x2f')]=_[_0x0ea7('0x2a')](_0x51f18a,_0x0ea7('0x27'));_0x27e9fd[_0x0ea7('0x30')]=_[_0x0ea7('0x31')](_0x247c8c['query']);_0x27e9fd['filters']=_[_0x0ea7('0x32')](_0x27e9fd[_0x0ea7('0x2f')],_0x27e9fd[_0x0ea7('0x30')]);_0x4b6c47['attributes']=_['intersection'](_0x27e9fd[_0x0ea7('0x2f')],qs[_0x0ea7('0x33')](_0x247c8c[_0x0ea7('0x30')]['fields']));_0x4b6c47['attributes']=_0x4b6c47[_0x0ea7('0x34')][_0x0ea7('0x35')]?_0x4b6c47[_0x0ea7('0x34')]:_0x27e9fd[_0x0ea7('0x2f')];if(!_0x247c8c['query'][_0x0ea7('0x36')](_0x0ea7('0x37'))){_0x4b6c47['limit']=qs[_0x0ea7('0x1c')](_0x247c8c[_0x0ea7('0x30')][_0x0ea7('0x1c')]);_0x4b6c47[_0x0ea7('0x1e')]=qs['offset'](_0x247c8c[_0x0ea7('0x30')][_0x0ea7('0x1e')]);}_0x4b6c47['order']=qs[_0x0ea7('0x38')](_0x247c8c[_0x0ea7('0x30')][_0x0ea7('0x38')]);_0x4b6c47[_0x0ea7('0x39')]=qs[_0x0ea7('0x3a')](_['pick'](_0x247c8c[_0x0ea7('0x30')],_0x27e9fd[_0x0ea7('0x3a')]),_0x51f18a);if(_0x247c8c[_0x0ea7('0x30')][_0x0ea7('0x3b')]){_0x4b6c47['where']=_['merge'](_0x4b6c47[_0x0ea7('0x39')],{'$or':_[_0x0ea7('0x2a')](_0x51f18a,function(_0x521c1e){if(_0x521c1e[_0x0ea7('0x3c')]!==_0x0ea7('0x3d')){var _0x295708={};_0x295708[_0x521c1e[_0x0ea7('0x27')]]={'$like':'%'+_0x247c8c[_0x0ea7('0x30')][_0x0ea7('0x3b')]+'%'};return _0x295708;}})});}_0x4b6c47=_[_0x0ea7('0x3e')]({},_0x4b6c47,_0x247c8c[_0x0ea7('0x3f')]);var _0x11310a={'where':_0x4b6c47[_0x0ea7('0x39')]};return db['FaxQueueReport'][_0x0ea7('0x1d')](_0x11310a)[_0x0ea7('0x25')](function(_0x4fc3fb){_0x3d07c3[_0x0ea7('0x1d')]=_0x4fc3fb;if(_0x247c8c[_0x0ea7('0x30')]['includeAll']){_0x4b6c47[_0x0ea7('0x40')]=[{'all':!![]}];}return db['FaxQueueReport'][_0x0ea7('0x41')](_0x4b6c47);})[_0x0ea7('0x25')](function(_0x4f4bc3){_0x3d07c3['rows']=_0x4f4bc3;return _0x3d07c3;})[_0x0ea7('0x25')](respondWithFilteredResult(_0x3fe1e3,_0x4b6c47))['catch'](handleError(_0x3fe1e3,null));};exports[_0x0ea7('0x42')]=function(_0x8d2f37,_0x1eab95){var _0x461946={'raw':!![],'where':{'id':_0x8d2f37[_0x0ea7('0x43')]['id']}},_0x251f26={};_0x251f26[_0x0ea7('0x2f')]=_[_0x0ea7('0x31')](db[_0x0ea7('0x2b')][_0x0ea7('0x2c')]);_0x251f26['query']=_[_0x0ea7('0x31')](_0x8d2f37[_0x0ea7('0x30')]);_0x251f26[_0x0ea7('0x3a')]=_[_0x0ea7('0x32')](_0x251f26[_0x0ea7('0x2f')],_0x251f26[_0x0ea7('0x30')]);_0x461946[_0x0ea7('0x34')]=_[_0x0ea7('0x32')](_0x251f26['model'],qs[_0x0ea7('0x33')](_0x8d2f37['query'][_0x0ea7('0x33')]));_0x461946[_0x0ea7('0x34')]=_0x461946[_0x0ea7('0x34')]['length']?_0x461946[_0x0ea7('0x34')]:_0x251f26['model'];if(_0x8d2f37[_0x0ea7('0x30')]['includeAll']){_0x461946[_0x0ea7('0x40')]=[{'all':!![]}];}_0x461946=_[_0x0ea7('0x3e')]({},_0x461946,_0x8d2f37['options']);return db[_0x0ea7('0x2b')][_0x0ea7('0x44')](_0x461946)[_0x0ea7('0x25')](handleEntityNotFound(_0x1eab95,null))['then'](respondWithResult(_0x1eab95,null))[_0x0ea7('0x45')](handleError(_0x1eab95,null));};exports[_0x0ea7('0x46')]=function(_0x426388,_0xdedde2){return db[_0x0ea7('0x2b')][_0x0ea7('0x46')](_0x426388['body'],{})['then'](respondWithResult(_0xdedde2,0xc9))[_0x0ea7('0x45')](handleError(_0xdedde2,null));};exports[_0x0ea7('0x24')]=function(_0x2d6b25,_0x34d84e){if(_0x2d6b25['body']['id']){delete _0x2d6b25[_0x0ea7('0x47')]['id'];}return db[_0x0ea7('0x2b')][_0x0ea7('0x44')]({'where':{'id':_0x2d6b25[_0x0ea7('0x43')]['id']}})[_0x0ea7('0x25')](handleEntityNotFound(_0x34d84e,null))[_0x0ea7('0x25')](saveUpdates(_0x2d6b25[_0x0ea7('0x47')],null))[_0x0ea7('0x25')](respondWithResult(_0x34d84e,null))['catch'](handleError(_0x34d84e,null));};exports[_0x0ea7('0x48')]=function(_0x3a9e4c,_0x819d67){return db[_0x0ea7('0x2b')][_0x0ea7('0x44')]({'where':{'id':_0x3a9e4c[_0x0ea7('0x43')]['id']}})[_0x0ea7('0x25')](handleEntityNotFound(_0x819d67,null))[_0x0ea7('0x25')](removeEntity(_0x819d67,null))[_0x0ea7('0x45')](handleError(_0x819d67,null));};exports['describe']=function(_0x355bc3,_0x5bd597){return db[_0x0ea7('0x2b')][_0x0ea7('0x49')]()[_0x0ea7('0x25')](respondWithResult(_0x5bd597,null))[_0x0ea7('0x45')](handleError(_0x5bd597,null));};