Built motion from commit (unavailable).|2.5.14
[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 _0xbc5f=['jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','count','offset','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','FaxQueueReport','rawAttributes','fieldName','type','model','map','query','keys','intersection','attributes','fields','length','nolimit','limit','order','sort','where','filters','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','update','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','lodash','squel','crypto'];(function(_0x5ce405,_0x29315d){var _0x42de0c=function(_0x281976){while(--_0x281976){_0x5ce405['push'](_0x5ce405['shift']());}};_0x42de0c(++_0x29315d);}(_0xbc5f,0x118));var _0xfbc5=function(_0x302933,_0x1b99b0){_0x302933=_0x302933-0x0;var _0x438e79=_0xbc5f[_0x302933];return _0x438e79;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xfbc5('0x0'));var rimraf=require(_0xfbc5('0x1'));var zipdir=require(_0xfbc5('0x2'));var jsonpatch=require(_0xfbc5('0x3'));var rp=require(_0xfbc5('0x4'));var moment=require(_0xfbc5('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xfbc5('0x6'));var util=require('util');var path=require(_0xfbc5('0x7'));var sox=require(_0xfbc5('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xfbc5('0x9'));var squel=require(_0xfbc5('0xa'));var crypto=require(_0xfbc5('0xb'));var jsforce=require(_0xfbc5('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xfbc5('0xd'));var querystring=require(_0xfbc5('0xe'));var Papa=require(_0xfbc5('0xf'));var Redis=require(_0xfbc5('0x10'));var authService=require(_0xfbc5('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xfbc5('0x12'));var hardwareService=require(_0xfbc5('0x13'));var logger=require('../../config/logger')(_0xfbc5('0x14'));var utils=require(_0xfbc5('0x15'));var config=require(_0xfbc5('0x16'));var licenseUtil=require(_0xfbc5('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x352c5a,_0x1d0a3d){_0x1d0a3d=_0x1d0a3d||0xcc;return function(_0x55fe5a){if(_0x55fe5a){return _0x352c5a[_0xfbc5('0x18')](_0x1d0a3d);}return _0x352c5a[_0xfbc5('0x19')](_0x1d0a3d)[_0xfbc5('0x1a')]();};}function respondWithResult(_0x409a0f,_0x14b4cd){_0x14b4cd=_0x14b4cd||0xc8;return function(_0x214a0a){if(_0x214a0a){return _0x409a0f['status'](_0x14b4cd)[_0xfbc5('0x1b')](_0x214a0a);}};}function respondWithFilteredResult(_0x26493c,_0x2564dc){return function(_0x53a809){if(_0x53a809){var _0x411bad=_0x53a809[_0xfbc5('0x1c')],_0x5e616d=_0x2564dc['offset'],_0x39992b=_0x2564dc[_0xfbc5('0x1d')]+_0x2564dc['limit'],_0x28c716;if(_0x39992b>=_0x411bad){_0x39992b=_0x411bad;_0x28c716=0xc8;}else{_0x28c716=0xce;}_0x26493c[_0xfbc5('0x19')](_0x28c716);return _0x26493c['set'](_0xfbc5('0x1e'),_0x5e616d+'-'+_0x39992b+'/'+_0x411bad)[_0xfbc5('0x1b')](_0x53a809);}return null;};}function patchUpdates(_0x102b76){return function(_0x4d90cd){try{jsonpatch[_0xfbc5('0x1f')](_0x4d90cd,_0x102b76,!![]);}catch(_0x2ef85d){return BPromise[_0xfbc5('0x20')](_0x2ef85d);}return _0x4d90cd[_0xfbc5('0x21')]();};}function saveUpdates(_0x400380,_0x292617){return function(_0x5537d8){if(_0x5537d8){return _0x5537d8['update'](_0x400380)[_0xfbc5('0x22')](function(_0x536439){return _0x536439;});}return null;};}function removeEntity(_0x15e99a,_0x50b9eb){return function(_0x1bdf2c){if(_0x1bdf2c){return _0x1bdf2c[_0xfbc5('0x23')]()[_0xfbc5('0x22')](function(){_0x15e99a[_0xfbc5('0x19')](0xcc)[_0xfbc5('0x1a')]();});}};}function handleEntityNotFound(_0x5a158c,_0x4edec9){return function(_0x3ec980){if(!_0x3ec980){_0x5a158c[_0xfbc5('0x18')](0x194);}return _0x3ec980;};}function handleError(_0x4f96d6,_0x46a021){_0x46a021=_0x46a021||0x1f4;return function(_0xe41be1){logger[_0xfbc5('0x24')](_0xe41be1[_0xfbc5('0x25')]);if(_0xe41be1[_0xfbc5('0x26')]){delete _0xe41be1['name'];}_0x4f96d6[_0xfbc5('0x19')](_0x46a021)[_0xfbc5('0x27')](_0xe41be1);};}exports['index']=function(_0x320a9d,_0xe52244){var _0x1023f7={},_0x266b40={},_0x2988e7={'count':0x0,'rows':[]};var _0x9d2274=_['map'](db[_0xfbc5('0x28')][_0xfbc5('0x29')],function(_0x518024){return{'name':_0x518024[_0xfbc5('0x2a')],'type':_0x518024[_0xfbc5('0x2b')]['key']};});_0x266b40[_0xfbc5('0x2c')]=_[_0xfbc5('0x2d')](_0x9d2274,'name');_0x266b40[_0xfbc5('0x2e')]=_[_0xfbc5('0x2f')](_0x320a9d[_0xfbc5('0x2e')]);_0x266b40['filters']=_[_0xfbc5('0x30')](_0x266b40['model'],_0x266b40[_0xfbc5('0x2e')]);_0x1023f7[_0xfbc5('0x31')]=_['intersection'](_0x266b40[_0xfbc5('0x2c')],qs['fields'](_0x320a9d[_0xfbc5('0x2e')][_0xfbc5('0x32')]));_0x1023f7[_0xfbc5('0x31')]=_0x1023f7['attributes'][_0xfbc5('0x33')]?_0x1023f7[_0xfbc5('0x31')]:_0x266b40['model'];if(!_0x320a9d['query']['hasOwnProperty'](_0xfbc5('0x34'))){_0x1023f7[_0xfbc5('0x35')]=qs[_0xfbc5('0x35')](_0x320a9d[_0xfbc5('0x2e')][_0xfbc5('0x35')]);_0x1023f7[_0xfbc5('0x1d')]=qs[_0xfbc5('0x1d')](_0x320a9d[_0xfbc5('0x2e')][_0xfbc5('0x1d')]);}_0x1023f7[_0xfbc5('0x36')]=qs[_0xfbc5('0x37')](_0x320a9d[_0xfbc5('0x2e')][_0xfbc5('0x37')]);_0x1023f7[_0xfbc5('0x38')]=qs[_0xfbc5('0x39')](_['pick'](_0x320a9d[_0xfbc5('0x2e')],_0x266b40[_0xfbc5('0x39')]),_0x9d2274);if(_0x320a9d[_0xfbc5('0x2e')]['filter']){_0x1023f7['where']=_[_0xfbc5('0x3a')](_0x1023f7[_0xfbc5('0x38')],{'$or':_['map'](_0x9d2274,function(_0x2b44e5){if(_0x2b44e5['type']!==_0xfbc5('0x3b')){var _0x57534f={};_0x57534f[_0x2b44e5[_0xfbc5('0x26')]]={'$like':'%'+_0x320a9d['query']['filter']+'%'};return _0x57534f;}})});}_0x1023f7=_[_0xfbc5('0x3a')]({},_0x1023f7,_0x320a9d[_0xfbc5('0x3c')]);var _0x538246={'where':_0x1023f7['where']};return db['FaxQueueReport'][_0xfbc5('0x1c')](_0x538246)['then'](function(_0x48f981){_0x2988e7[_0xfbc5('0x1c')]=_0x48f981;if(_0x320a9d['query'][_0xfbc5('0x3d')]){_0x1023f7[_0xfbc5('0x3e')]=[{'all':!![]}];}return db[_0xfbc5('0x28')][_0xfbc5('0x3f')](_0x1023f7);})[_0xfbc5('0x22')](function(_0x50df4a){_0x2988e7[_0xfbc5('0x40')]=_0x50df4a;return _0x2988e7;})[_0xfbc5('0x22')](respondWithFilteredResult(_0xe52244,_0x1023f7))[_0xfbc5('0x41')](handleError(_0xe52244,null));};exports[_0xfbc5('0x42')]=function(_0x37eb12,_0x251687){var _0x244e58={'raw':!![],'where':{'id':_0x37eb12[_0xfbc5('0x43')]['id']}},_0x10c9aa={};_0x10c9aa[_0xfbc5('0x2c')]=_['keys'](db[_0xfbc5('0x28')]['rawAttributes']);_0x10c9aa[_0xfbc5('0x2e')]=_[_0xfbc5('0x2f')](_0x37eb12[_0xfbc5('0x2e')]);_0x10c9aa[_0xfbc5('0x39')]=_['intersection'](_0x10c9aa['model'],_0x10c9aa[_0xfbc5('0x2e')]);_0x244e58[_0xfbc5('0x31')]=_[_0xfbc5('0x30')](_0x10c9aa[_0xfbc5('0x2c')],qs['fields'](_0x37eb12['query'][_0xfbc5('0x32')]));_0x244e58['attributes']=_0x244e58['attributes'][_0xfbc5('0x33')]?_0x244e58[_0xfbc5('0x31')]:_0x10c9aa[_0xfbc5('0x2c')];if(_0x37eb12['query'][_0xfbc5('0x3d')]){_0x244e58[_0xfbc5('0x3e')]=[{'all':!![]}];}_0x244e58=_['merge']({},_0x244e58,_0x37eb12['options']);return db[_0xfbc5('0x28')][_0xfbc5('0x44')](_0x244e58)[_0xfbc5('0x22')](handleEntityNotFound(_0x251687,null))[_0xfbc5('0x22')](respondWithResult(_0x251687,null))[_0xfbc5('0x41')](handleError(_0x251687,null));};exports[_0xfbc5('0x45')]=function(_0x5c1570,_0x1bcd4a){return db['FaxQueueReport'][_0xfbc5('0x45')](_0x5c1570[_0xfbc5('0x46')],{})[_0xfbc5('0x22')](respondWithResult(_0x1bcd4a,0xc9))[_0xfbc5('0x41')](handleError(_0x1bcd4a,null));};exports[_0xfbc5('0x47')]=function(_0x36dc75,_0x195716){if(_0x36dc75['body']['id']){delete _0x36dc75['body']['id'];}return db[_0xfbc5('0x28')][_0xfbc5('0x44')]({'where':{'id':_0x36dc75[_0xfbc5('0x43')]['id']}})['then'](handleEntityNotFound(_0x195716,null))[_0xfbc5('0x22')](saveUpdates(_0x36dc75[_0xfbc5('0x46')],null))[_0xfbc5('0x22')](respondWithResult(_0x195716,null))[_0xfbc5('0x41')](handleError(_0x195716,null));};exports[_0xfbc5('0x23')]=function(_0x17841d,_0x3a3b13){return db[_0xfbc5('0x28')][_0xfbc5('0x44')]({'where':{'id':_0x17841d[_0xfbc5('0x43')]['id']}})[_0xfbc5('0x22')](handleEntityNotFound(_0x3a3b13,null))[_0xfbc5('0x22')](removeEntity(_0x3a3b13,null))[_0xfbc5('0x41')](handleError(_0x3a3b13,null));};exports[_0xfbc5('0x48')]=function(_0x4bc8c3,_0x448cf2){return db[_0xfbc5('0x28')][_0xfbc5('0x48')]()[_0xfbc5('0x22')](respondWithResult(_0x448cf2,null))[_0xfbc5('0x41')](handleError(_0x448cf2,null));};