Built motion from commit c738b9ac.|2.6.25
[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 _0x324f=['mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','end','error','stack','name','send','index','map','FaxQueueReport','rawAttributes','fieldName','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','options','include','findAll','rows','catch','show','params','includeAll','create','body','find','destroy','eml-format','rimraf','zip-dir','moment'];(function(_0x1c9f83,_0x349188){var _0x6d31f0=function(_0x4bddc6){while(--_0x4bddc6){_0x1c9f83['push'](_0x1c9f83['shift']());}};_0x6d31f0(++_0x349188);}(_0x324f,0x94));var _0xf324=function(_0x714d60,_0x1ede1f){_0x714d60=_0x714d60-0x0;var _0x25b2f1=_0x324f[_0x714d60];return _0x25b2f1;};'use strict';var emlformat=require(_0xf324('0x0'));var rimraf=require(_0xf324('0x1'));var zipdir=require(_0xf324('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xf324('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf324('0x4'));var util=require(_0xf324('0x5'));var path=require('path');var sox=require(_0xf324('0x6'));var csv=require(_0xf324('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf324('0x8'));var _=require(_0xf324('0x9'));var squel=require(_0xf324('0xa'));var crypto=require(_0xf324('0xb'));var jsforce=require(_0xf324('0xc'));var deskjs=require(_0xf324('0xd'));var toCsv=require(_0xf324('0x7'));var querystring=require(_0xf324('0xe'));var Papa=require(_0xf324('0xf'));var Redis=require('ioredis');var authService=require(_0xf324('0x10'));var qs=require(_0xf324('0x11'));var as=require(_0xf324('0x12'));var hardwareService=require(_0xf324('0x13'));var logger=require('../../config/logger')(_0xf324('0x14'));var utils=require(_0xf324('0x15'));var config=require(_0xf324('0x16'));var licenseUtil=require(_0xf324('0x17'));var db=require(_0xf324('0x18'))['db'];function respondWithStatusCode(_0x312dbf,_0x790180){_0x790180=_0x790180||0xcc;return function(_0x9b34d3){if(_0x9b34d3){return _0x312dbf[_0xf324('0x19')](_0x790180);}return _0x312dbf[_0xf324('0x1a')](_0x790180)['end']();};}function respondWithResult(_0x59136f,_0x52c645){_0x52c645=_0x52c645||0xc8;return function(_0x4a0c04){if(_0x4a0c04){return _0x59136f[_0xf324('0x1a')](_0x52c645)['json'](_0x4a0c04);}};}function respondWithFilteredResult(_0x1fec90,_0x47c72f){return function(_0xd59071){if(_0xd59071){var _0x5c5c84=typeof _0x47c72f[_0xf324('0x1b')]===_0xf324('0x1c')&&typeof _0x47c72f[_0xf324('0x1d')]==='undefined';var _0x29334c=_0xd59071[_0xf324('0x1e')];var _0x39ca8e=_0x5c5c84?0x0:_0x47c72f[_0xf324('0x1b')];var _0x28d986=_0x5c5c84?_0xd59071[_0xf324('0x1e')]:_0x47c72f[_0xf324('0x1b')]+_0x47c72f[_0xf324('0x1d')];var _0x2c936e;if(_0x28d986>=_0x29334c){_0x28d986=_0x29334c;_0x2c936e=0xc8;}else{_0x2c936e=0xce;}_0x1fec90[_0xf324('0x1a')](_0x2c936e);return _0x1fec90[_0xf324('0x1f')](_0xf324('0x20'),_0x39ca8e+'-'+_0x28d986+'/'+_0x29334c)['json'](_0xd59071);}return null;};}function patchUpdates(_0x10e157){return function(_0xe5afd8){try{jsonpatch['apply'](_0xe5afd8,_0x10e157,!![]);}catch(_0x51507a){return BPromise[_0xf324('0x21')](_0x51507a);}return _0xe5afd8[_0xf324('0x22')]();};}function saveUpdates(_0x235730,_0x407cb7){return function(_0x202a46){if(_0x202a46){return _0x202a46[_0xf324('0x23')](_0x235730)[_0xf324('0x24')](function(_0x2a583f){return _0x2a583f;});}return null;};}function removeEntity(_0x497b89,_0x829a3){return function(_0x2e125d){if(_0x2e125d){return _0x2e125d['destroy']()[_0xf324('0x24')](function(){_0x497b89[_0xf324('0x1a')](0xcc)[_0xf324('0x25')]();});}};}function handleEntityNotFound(_0x5ef883,_0xec0d36){return function(_0x24188b){if(!_0x24188b){_0x5ef883[_0xf324('0x19')](0x194);}return _0x24188b;};}function handleError(_0x41b611,_0x153350){_0x153350=_0x153350||0x1f4;return function(_0x391e48){logger[_0xf324('0x26')](_0x391e48[_0xf324('0x27')]);if(_0x391e48[_0xf324('0x28')]){delete _0x391e48[_0xf324('0x28')];}_0x41b611[_0xf324('0x1a')](_0x153350)[_0xf324('0x29')](_0x391e48);};}exports[_0xf324('0x2a')]=function(_0x37e28a,_0x4c0636){var _0x2eaa37={},_0x143934={},_0x4dd1fc={'count':0x0,'rows':[]};var _0x3e2af0=_[_0xf324('0x2b')](db[_0xf324('0x2c')][_0xf324('0x2d')],function(_0x5af3af){return{'name':_0x5af3af[_0xf324('0x2e')],'type':_0x5af3af['type'][_0xf324('0x2f')]};});_0x143934[_0xf324('0x30')]=_[_0xf324('0x2b')](_0x3e2af0,'name');_0x143934[_0xf324('0x31')]=_[_0xf324('0x32')](_0x37e28a[_0xf324('0x31')]);_0x143934[_0xf324('0x33')]=_['intersection'](_0x143934[_0xf324('0x30')],_0x143934[_0xf324('0x31')]);_0x2eaa37['attributes']=_[_0xf324('0x34')](_0x143934[_0xf324('0x30')],qs[_0xf324('0x35')](_0x37e28a[_0xf324('0x31')][_0xf324('0x35')]));_0x2eaa37['attributes']=_0x2eaa37[_0xf324('0x36')][_0xf324('0x37')]?_0x2eaa37[_0xf324('0x36')]:_0x143934[_0xf324('0x30')];if(!_0x37e28a[_0xf324('0x31')][_0xf324('0x38')](_0xf324('0x39'))){_0x2eaa37[_0xf324('0x1d')]=qs[_0xf324('0x1d')](_0x37e28a[_0xf324('0x31')][_0xf324('0x1d')]);_0x2eaa37[_0xf324('0x1b')]=qs[_0xf324('0x1b')](_0x37e28a['query'][_0xf324('0x1b')]);}_0x2eaa37[_0xf324('0x3a')]=qs[_0xf324('0x3b')](_0x37e28a[_0xf324('0x31')][_0xf324('0x3b')]);_0x2eaa37[_0xf324('0x3c')]=qs[_0xf324('0x33')](_['pick'](_0x37e28a[_0xf324('0x31')],_0x143934[_0xf324('0x33')]),_0x3e2af0);if(_0x37e28a['query'][_0xf324('0x3d')]){_0x2eaa37[_0xf324('0x3c')]=_[_0xf324('0x3e')](_0x2eaa37[_0xf324('0x3c')],{'$or':_[_0xf324('0x2b')](_0x3e2af0,function(_0x4ea2bb){if(_0x4ea2bb[_0xf324('0x3f')]!=='VIRTUAL'){var _0x25b279={};_0x25b279[_0x4ea2bb['name']]={'$like':'%'+_0x37e28a[_0xf324('0x31')][_0xf324('0x3d')]+'%'};return _0x25b279;}})});}_0x2eaa37=_['merge']({},_0x2eaa37,_0x37e28a[_0xf324('0x40')]);var _0x16116e={'where':_0x2eaa37[_0xf324('0x3c')]};return db[_0xf324('0x2c')]['count'](_0x16116e)[_0xf324('0x24')](function(_0x3cb1e7){_0x4dd1fc[_0xf324('0x1e')]=_0x3cb1e7;if(_0x37e28a[_0xf324('0x31')]['includeAll']){_0x2eaa37[_0xf324('0x41')]=[{'all':!![]}];}return db[_0xf324('0x2c')][_0xf324('0x42')](_0x2eaa37);})[_0xf324('0x24')](function(_0x59571d){_0x4dd1fc[_0xf324('0x43')]=_0x59571d;return _0x4dd1fc;})['then'](respondWithFilteredResult(_0x4c0636,_0x2eaa37))[_0xf324('0x44')](handleError(_0x4c0636,null));};exports[_0xf324('0x45')]=function(_0x1a8acc,_0x4dbc4e){var _0xce58c2={'raw':!![],'where':{'id':_0x1a8acc[_0xf324('0x46')]['id']}},_0x9c06dc={};_0x9c06dc[_0xf324('0x30')]=_[_0xf324('0x32')](db[_0xf324('0x2c')]['rawAttributes']);_0x9c06dc['query']=_[_0xf324('0x32')](_0x1a8acc[_0xf324('0x31')]);_0x9c06dc[_0xf324('0x33')]=_[_0xf324('0x34')](_0x9c06dc[_0xf324('0x30')],_0x9c06dc[_0xf324('0x31')]);_0xce58c2[_0xf324('0x36')]=_[_0xf324('0x34')](_0x9c06dc['model'],qs[_0xf324('0x35')](_0x1a8acc[_0xf324('0x31')][_0xf324('0x35')]));_0xce58c2[_0xf324('0x36')]=_0xce58c2[_0xf324('0x36')]['length']?_0xce58c2[_0xf324('0x36')]:_0x9c06dc[_0xf324('0x30')];if(_0x1a8acc[_0xf324('0x31')][_0xf324('0x47')]){_0xce58c2[_0xf324('0x41')]=[{'all':!![]}];}_0xce58c2=_[_0xf324('0x3e')]({},_0xce58c2,_0x1a8acc['options']);return db[_0xf324('0x2c')]['find'](_0xce58c2)[_0xf324('0x24')](handleEntityNotFound(_0x4dbc4e,null))['then'](respondWithResult(_0x4dbc4e,null))[_0xf324('0x44')](handleError(_0x4dbc4e,null));};exports[_0xf324('0x48')]=function(_0x536b42,_0x1402e3){return db['FaxQueueReport'][_0xf324('0x48')](_0x536b42[_0xf324('0x49')],{})['then'](respondWithResult(_0x1402e3,0xc9))[_0xf324('0x44')](handleError(_0x1402e3,null));};exports['update']=function(_0x1bdd1f,_0x9aa58d){if(_0x1bdd1f[_0xf324('0x49')]['id']){delete _0x1bdd1f[_0xf324('0x49')]['id'];}return db[_0xf324('0x2c')][_0xf324('0x4a')]({'where':{'id':_0x1bdd1f['params']['id']}})['then'](handleEntityNotFound(_0x9aa58d,null))[_0xf324('0x24')](saveUpdates(_0x1bdd1f['body'],null))[_0xf324('0x24')](respondWithResult(_0x9aa58d,null))[_0xf324('0x44')](handleError(_0x9aa58d,null));};exports[_0xf324('0x4b')]=function(_0x396ea4,_0xc4604c){return db['FaxQueueReport'][_0xf324('0x4a')]({'where':{'id':_0x396ea4[_0xf324('0x46')]['id']}})['then'](handleEntityNotFound(_0xc4604c,null))[_0xf324('0x24')](removeEntity(_0xc4604c,null))[_0xf324('0x44')](handleError(_0xc4604c,null));};exports['describe']=function(_0x901207,_0x48b95b){return db[_0xf324('0x2c')]['describe']()[_0xf324('0x24')](respondWithResult(_0x48b95b,null))[_0xf324('0x44')](handleError(_0x48b95b,null));};