c63c3cca1b2368dee759d384e6674b0129abeaf9
[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 _0xa1e8=['params','find','create','body','describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','limit','undefined','count','offset','Content-Range','json','reject','save','update','then','error','stack','name','index','map','FaxQueueReport','fieldName','type','key','model','keys','query','attributes','intersection','fields','hasOwnProperty','nolimit','sort','where','filters','pick','filter','merge','options','includeAll','include','findAll','rows','catch','show'];(function(_0x3505fe,_0x423e13){var _0x11e7ce=function(_0x2fe0f4){while(--_0x2fe0f4){_0x3505fe['push'](_0x3505fe['shift']());}};_0x11e7ce(++_0x423e13);}(_0xa1e8,0x1af));var _0x8a1e=function(_0xdcf33c,_0x2114c4){_0xdcf33c=_0xdcf33c-0x0;var _0x40eb19=_0xa1e8[_0xdcf33c];return _0x40eb19;};'use strict';var emlformat=require(_0x8a1e('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x8a1e('0x1'));var jsonpatch=require(_0x8a1e('0x2'));var rp=require(_0x8a1e('0x3'));var moment=require('moment');var BPromise=require(_0x8a1e('0x4'));var Mustache=require('mustache');var util=require(_0x8a1e('0x5'));var path=require(_0x8a1e('0x6'));var sox=require(_0x8a1e('0x7'));var csv=require(_0x8a1e('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x8a1e('0x9'));var _=require(_0x8a1e('0xa'));var squel=require(_0x8a1e('0xb'));var crypto=require(_0x8a1e('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x8a1e('0xd'));var toCsv=require(_0x8a1e('0x8'));var querystring=require(_0x8a1e('0xe'));var Papa=require('papaparse');var Redis=require(_0x8a1e('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x8a1e('0x10'));var as=require(_0x8a1e('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x8a1e('0x12'));var utils=require(_0x8a1e('0x13'));var config=require(_0x8a1e('0x14'));var licenseUtil=require(_0x8a1e('0x15'));var db=require(_0x8a1e('0x16'))['db'];function respondWithStatusCode(_0x8aebf4,_0x22a562){_0x22a562=_0x22a562||0xcc;return function(_0x4d8829){if(_0x4d8829){return _0x8aebf4[_0x8a1e('0x17')](_0x22a562);}return _0x8aebf4[_0x8a1e('0x18')](_0x22a562)[_0x8a1e('0x19')]();};}function respondWithResult(_0x50f242,_0x39eeec){_0x39eeec=_0x39eeec||0xc8;return function(_0x1ef391){if(_0x1ef391){return _0x50f242[_0x8a1e('0x18')](_0x39eeec)['json'](_0x1ef391);}};}function respondWithFilteredResult(_0x3b3c83,_0x472fc8){return function(_0x162a63){if(_0x162a63){var _0x4a31d0=typeof _0x472fc8['offset']==='undefined'&&typeof _0x472fc8[_0x8a1e('0x1a')]===_0x8a1e('0x1b');var _0x54d0fd=_0x162a63[_0x8a1e('0x1c')];var _0x27ff23=_0x4a31d0?0x0:_0x472fc8[_0x8a1e('0x1d')];var _0x362bb8=_0x4a31d0?_0x162a63[_0x8a1e('0x1c')]:_0x472fc8[_0x8a1e('0x1d')]+_0x472fc8['limit'];var _0x9946ad;if(_0x362bb8>=_0x54d0fd){_0x362bb8=_0x54d0fd;_0x9946ad=0xc8;}else{_0x9946ad=0xce;}_0x3b3c83[_0x8a1e('0x18')](_0x9946ad);return _0x3b3c83['set'](_0x8a1e('0x1e'),_0x27ff23+'-'+_0x362bb8+'/'+_0x54d0fd)[_0x8a1e('0x1f')](_0x162a63);}return null;};}function patchUpdates(_0x2208a5){return function(_0x27c3cd){try{jsonpatch['apply'](_0x27c3cd,_0x2208a5,!![]);}catch(_0x50d479){return BPromise[_0x8a1e('0x20')](_0x50d479);}return _0x27c3cd[_0x8a1e('0x21')]();};}function saveUpdates(_0x2b2334,_0x1f5c7b){return function(_0x6adaed){if(_0x6adaed){return _0x6adaed[_0x8a1e('0x22')](_0x2b2334)[_0x8a1e('0x23')](function(_0x31924e){return _0x31924e;});}return null;};}function removeEntity(_0x399361,_0x71f051){return function(_0x80dd6a){if(_0x80dd6a){return _0x80dd6a['destroy']()[_0x8a1e('0x23')](function(){_0x399361[_0x8a1e('0x18')](0xcc)[_0x8a1e('0x19')]();});}};}function handleEntityNotFound(_0x59de36,_0x24bf2f){return function(_0x187aa7){if(!_0x187aa7){_0x59de36[_0x8a1e('0x17')](0x194);}return _0x187aa7;};}function handleError(_0x79849d,_0x568dab){_0x568dab=_0x568dab||0x1f4;return function(_0x1cb9d7){logger[_0x8a1e('0x24')](_0x1cb9d7[_0x8a1e('0x25')]);if(_0x1cb9d7[_0x8a1e('0x26')]){delete _0x1cb9d7[_0x8a1e('0x26')];}_0x79849d[_0x8a1e('0x18')](_0x568dab)['send'](_0x1cb9d7);};}exports[_0x8a1e('0x27')]=function(_0x1289ac,_0x2d3ace){var _0x2ec304={},_0x4297c4={},_0x51294c={'count':0x0,'rows':[]};var _0x55a986=_[_0x8a1e('0x28')](db[_0x8a1e('0x29')]['rawAttributes'],function(_0xf39c6d){return{'name':_0xf39c6d[_0x8a1e('0x2a')],'type':_0xf39c6d[_0x8a1e('0x2b')][_0x8a1e('0x2c')]};});_0x4297c4[_0x8a1e('0x2d')]=_[_0x8a1e('0x28')](_0x55a986,_0x8a1e('0x26'));_0x4297c4['query']=_[_0x8a1e('0x2e')](_0x1289ac[_0x8a1e('0x2f')]);_0x4297c4['filters']=_['intersection'](_0x4297c4['model'],_0x4297c4['query']);_0x2ec304[_0x8a1e('0x30')]=_[_0x8a1e('0x31')](_0x4297c4[_0x8a1e('0x2d')],qs['fields'](_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x32')]));_0x2ec304[_0x8a1e('0x30')]=_0x2ec304[_0x8a1e('0x30')]['length']?_0x2ec304['attributes']:_0x4297c4[_0x8a1e('0x2d')];if(!_0x1289ac['query'][_0x8a1e('0x33')](_0x8a1e('0x34'))){_0x2ec304[_0x8a1e('0x1a')]=qs[_0x8a1e('0x1a')](_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x1a')]);_0x2ec304[_0x8a1e('0x1d')]=qs['offset'](_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x1d')]);}_0x2ec304['order']=qs[_0x8a1e('0x35')](_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x35')]);_0x2ec304[_0x8a1e('0x36')]=qs[_0x8a1e('0x37')](_[_0x8a1e('0x38')](_0x1289ac['query'],_0x4297c4['filters']),_0x55a986);if(_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x39')]){_0x2ec304['where']=_['merge'](_0x2ec304[_0x8a1e('0x36')],{'$or':_[_0x8a1e('0x28')](_0x55a986,function(_0x58edb7){if(_0x58edb7['type']!=='VIRTUAL'){var _0x5ca38c={};_0x5ca38c[_0x58edb7[_0x8a1e('0x26')]]={'$like':'%'+_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x39')]+'%'};return _0x5ca38c;}})});}_0x2ec304=_[_0x8a1e('0x3a')]({},_0x2ec304,_0x1289ac[_0x8a1e('0x3b')]);var _0x561fd2={'where':_0x2ec304[_0x8a1e('0x36')]};return db[_0x8a1e('0x29')][_0x8a1e('0x1c')](_0x561fd2)[_0x8a1e('0x23')](function(_0x39bb63){_0x51294c[_0x8a1e('0x1c')]=_0x39bb63;if(_0x1289ac[_0x8a1e('0x2f')][_0x8a1e('0x3c')]){_0x2ec304[_0x8a1e('0x3d')]=[{'all':!![]}];}return db[_0x8a1e('0x29')][_0x8a1e('0x3e')](_0x2ec304);})[_0x8a1e('0x23')](function(_0x40a71f){_0x51294c[_0x8a1e('0x3f')]=_0x40a71f;return _0x51294c;})['then'](respondWithFilteredResult(_0x2d3ace,_0x2ec304))[_0x8a1e('0x40')](handleError(_0x2d3ace,null));};exports[_0x8a1e('0x41')]=function(_0x4b6705,_0x6bea04){var _0x1a5951={'raw':!![],'where':{'id':_0x4b6705[_0x8a1e('0x42')]['id']}},_0xf2a702={};_0xf2a702['model']=_[_0x8a1e('0x2e')](db[_0x8a1e('0x29')]['rawAttributes']);_0xf2a702[_0x8a1e('0x2f')]=_[_0x8a1e('0x2e')](_0x4b6705['query']);_0xf2a702[_0x8a1e('0x37')]=_[_0x8a1e('0x31')](_0xf2a702[_0x8a1e('0x2d')],_0xf2a702[_0x8a1e('0x2f')]);_0x1a5951[_0x8a1e('0x30')]=_[_0x8a1e('0x31')](_0xf2a702[_0x8a1e('0x2d')],qs[_0x8a1e('0x32')](_0x4b6705[_0x8a1e('0x2f')][_0x8a1e('0x32')]));_0x1a5951['attributes']=_0x1a5951[_0x8a1e('0x30')]['length']?_0x1a5951['attributes']:_0xf2a702[_0x8a1e('0x2d')];if(_0x4b6705[_0x8a1e('0x2f')][_0x8a1e('0x3c')]){_0x1a5951[_0x8a1e('0x3d')]=[{'all':!![]}];}_0x1a5951=_['merge']({},_0x1a5951,_0x4b6705['options']);return db['FaxQueueReport'][_0x8a1e('0x43')](_0x1a5951)[_0x8a1e('0x23')](handleEntityNotFound(_0x6bea04,null))[_0x8a1e('0x23')](respondWithResult(_0x6bea04,null))[_0x8a1e('0x40')](handleError(_0x6bea04,null));};exports[_0x8a1e('0x44')]=function(_0x2c1437,_0x4b29f0){return db[_0x8a1e('0x29')][_0x8a1e('0x44')](_0x2c1437['body'],{})[_0x8a1e('0x23')](respondWithResult(_0x4b29f0,0xc9))[_0x8a1e('0x40')](handleError(_0x4b29f0,null));};exports['update']=function(_0x49cb8e,_0x5b1ec0){if(_0x49cb8e[_0x8a1e('0x45')]['id']){delete _0x49cb8e[_0x8a1e('0x45')]['id'];}return db[_0x8a1e('0x29')][_0x8a1e('0x43')]({'where':{'id':_0x49cb8e['params']['id']}})['then'](handleEntityNotFound(_0x5b1ec0,null))[_0x8a1e('0x23')](saveUpdates(_0x49cb8e[_0x8a1e('0x45')],null))[_0x8a1e('0x23')](respondWithResult(_0x5b1ec0,null))[_0x8a1e('0x40')](handleError(_0x5b1ec0,null));};exports['destroy']=function(_0x251ff2,_0x2ba406){return db[_0x8a1e('0x29')][_0x8a1e('0x43')]({'where':{'id':_0x251ff2[_0x8a1e('0x42')]['id']}})[_0x8a1e('0x23')](handleEntityNotFound(_0x2ba406,null))[_0x8a1e('0x23')](removeEntity(_0x2ba406,null))['catch'](handleError(_0x2ba406,null));};exports[_0x8a1e('0x46')]=function(_0x328c8c,_0x231b18){return db['FaxQueueReport']['describe']()[_0x8a1e('0x23')](respondWithResult(_0x231b18,null))['catch'](handleError(_0x231b18,null));};