Built motion from commit bab6f49e.|2.6.17
[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 _0x280f=['sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../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','json','offset','count','limit','set','Content-Range','apply','reject','update','then','destroy','error','stack','FaxQueueReport','rawAttributes','fieldName','type','key','model','name','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','merge','map','VIRTUAL','filter','includeAll','include','findAll','catch','show','params','length','options','create','body','find','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util'];(function(_0x211fef,_0x4ab716){var _0x5447bf=function(_0x306ea3){while(--_0x306ea3){_0x211fef['push'](_0x211fef['shift']());}};_0x5447bf(++_0x4ab716);}(_0x280f,0xe2));var _0xf280=function(_0x4eafed,_0x26e2bc){_0x4eafed=_0x4eafed-0x0;var _0x159c85=_0x280f[_0x4eafed];return _0x159c85;};'use strict';var emlformat=require(_0xf280('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf280('0x1'));var jsonpatch=require(_0xf280('0x2'));var rp=require(_0xf280('0x3'));var moment=require(_0xf280('0x4'));var BPromise=require(_0xf280('0x5'));var Mustache=require(_0xf280('0x6'));var util=require(_0xf280('0x7'));var path=require('path');var sox=require(_0xf280('0x8'));var csv=require(_0xf280('0x9'));var ejs=require(_0xf280('0xa'));var fs=require('fs');var fs_extra=require(_0xf280('0xb'));var _=require(_0xf280('0xc'));var squel=require('squel');var crypto=require(_0xf280('0xd'));var jsforce=require(_0xf280('0xe'));var deskjs=require(_0xf280('0xf'));var toCsv=require(_0xf280('0x9'));var querystring=require(_0xf280('0x10'));var Papa=require(_0xf280('0x11'));var Redis=require('ioredis');var authService=require(_0xf280('0x12'));var qs=require(_0xf280('0x13'));var as=require(_0xf280('0x14'));var hardwareService=require(_0xf280('0x15'));var logger=require(_0xf280('0x16'))(_0xf280('0x17'));var utils=require(_0xf280('0x18'));var config=require(_0xf280('0x19'));var licenseUtil=require(_0xf280('0x1a'));var db=require(_0xf280('0x1b'))['db'];function respondWithStatusCode(_0x148d24,_0x56221f){_0x56221f=_0x56221f||0xcc;return function(_0x566eb7){if(_0x566eb7){return _0x148d24[_0xf280('0x1c')](_0x56221f);}return _0x148d24[_0xf280('0x1d')](_0x56221f)[_0xf280('0x1e')]();};}function respondWithResult(_0x1d7175,_0x3e9acc){_0x3e9acc=_0x3e9acc||0xc8;return function(_0x59fb22){if(_0x59fb22){return _0x1d7175[_0xf280('0x1d')](_0x3e9acc)[_0xf280('0x1f')](_0x59fb22);}};}function respondWithFilteredResult(_0x34cadb,_0x224162){return function(_0x1e8f4d){if(_0x1e8f4d){var _0x462177=typeof _0x224162[_0xf280('0x20')]==='undefined'&&typeof _0x224162['limit']==='undefined';var _0x30a9a6=_0x1e8f4d['count'];var _0x11c2b0=_0x462177?0x0:_0x224162['offset'];var _0x2a19e7=_0x462177?_0x1e8f4d[_0xf280('0x21')]:_0x224162['offset']+_0x224162[_0xf280('0x22')];var _0x59b8af;if(_0x2a19e7>=_0x30a9a6){_0x2a19e7=_0x30a9a6;_0x59b8af=0xc8;}else{_0x59b8af=0xce;}_0x34cadb[_0xf280('0x1d')](_0x59b8af);return _0x34cadb[_0xf280('0x23')](_0xf280('0x24'),_0x11c2b0+'-'+_0x2a19e7+'/'+_0x30a9a6)[_0xf280('0x1f')](_0x1e8f4d);}return null;};}function patchUpdates(_0x11db7d){return function(_0x3a4eff){try{jsonpatch[_0xf280('0x25')](_0x3a4eff,_0x11db7d,!![]);}catch(_0x469bdf){return BPromise[_0xf280('0x26')](_0x469bdf);}return _0x3a4eff['save']();};}function saveUpdates(_0x1ad62a,_0x5a1aa1){return function(_0xfb624e){if(_0xfb624e){return _0xfb624e[_0xf280('0x27')](_0x1ad62a)[_0xf280('0x28')](function(_0x32039f){return _0x32039f;});}return null;};}function removeEntity(_0x3de08f,_0x42020c){return function(_0x4c3618){if(_0x4c3618){return _0x4c3618[_0xf280('0x29')]()[_0xf280('0x28')](function(){_0x3de08f[_0xf280('0x1d')](0xcc)[_0xf280('0x1e')]();});}};}function handleEntityNotFound(_0x35cd2d,_0x302132){return function(_0x4509c1){if(!_0x4509c1){_0x35cd2d[_0xf280('0x1c')](0x194);}return _0x4509c1;};}function handleError(_0x485788,_0x368b24){_0x368b24=_0x368b24||0x1f4;return function(_0x1b21fb){logger[_0xf280('0x2a')](_0x1b21fb[_0xf280('0x2b')]);if(_0x1b21fb['name']){delete _0x1b21fb['name'];}_0x485788['status'](_0x368b24)['send'](_0x1b21fb);};}exports['index']=function(_0x3da40e,_0x2409f4){var _0xa1fbb7={},_0x34edaf={},_0x545ccf={'count':0x0,'rows':[]};var _0x1cdf05=_['map'](db[_0xf280('0x2c')][_0xf280('0x2d')],function(_0x534233){return{'name':_0x534233[_0xf280('0x2e')],'type':_0x534233[_0xf280('0x2f')][_0xf280('0x30')]};});_0x34edaf[_0xf280('0x31')]=_['map'](_0x1cdf05,_0xf280('0x32'));_0x34edaf[_0xf280('0x33')]=_[_0xf280('0x34')](_0x3da40e[_0xf280('0x33')]);_0x34edaf[_0xf280('0x35')]=_[_0xf280('0x36')](_0x34edaf[_0xf280('0x31')],_0x34edaf[_0xf280('0x33')]);_0xa1fbb7['attributes']=_[_0xf280('0x36')](_0x34edaf[_0xf280('0x31')],qs[_0xf280('0x37')](_0x3da40e[_0xf280('0x33')]['fields']));_0xa1fbb7['attributes']=_0xa1fbb7[_0xf280('0x38')]['length']?_0xa1fbb7[_0xf280('0x38')]:_0x34edaf[_0xf280('0x31')];if(!_0x3da40e[_0xf280('0x33')][_0xf280('0x39')](_0xf280('0x3a'))){_0xa1fbb7['limit']=qs['limit'](_0x3da40e['query'][_0xf280('0x22')]);_0xa1fbb7['offset']=qs[_0xf280('0x20')](_0x3da40e[_0xf280('0x33')]['offset']);}_0xa1fbb7[_0xf280('0x3b')]=qs[_0xf280('0x3c')](_0x3da40e[_0xf280('0x33')][_0xf280('0x3c')]);_0xa1fbb7[_0xf280('0x3d')]=qs[_0xf280('0x35')](_[_0xf280('0x3e')](_0x3da40e[_0xf280('0x33')],_0x34edaf[_0xf280('0x35')]),_0x1cdf05);if(_0x3da40e[_0xf280('0x33')]['filter']){_0xa1fbb7[_0xf280('0x3d')]=_[_0xf280('0x3f')](_0xa1fbb7[_0xf280('0x3d')],{'$or':_[_0xf280('0x40')](_0x1cdf05,function(_0x263a56){if(_0x263a56['type']!==_0xf280('0x41')){var _0x1f9365={};_0x1f9365[_0x263a56['name']]={'$like':'%'+_0x3da40e[_0xf280('0x33')][_0xf280('0x42')]+'%'};return _0x1f9365;}})});}_0xa1fbb7=_[_0xf280('0x3f')]({},_0xa1fbb7,_0x3da40e['options']);var _0x1ff055={'where':_0xa1fbb7[_0xf280('0x3d')]};return db['FaxQueueReport'][_0xf280('0x21')](_0x1ff055)[_0xf280('0x28')](function(_0x422f4c){_0x545ccf[_0xf280('0x21')]=_0x422f4c;if(_0x3da40e[_0xf280('0x33')][_0xf280('0x43')]){_0xa1fbb7[_0xf280('0x44')]=[{'all':!![]}];}return db[_0xf280('0x2c')][_0xf280('0x45')](_0xa1fbb7);})[_0xf280('0x28')](function(_0x22822e){_0x545ccf['rows']=_0x22822e;return _0x545ccf;})[_0xf280('0x28')](respondWithFilteredResult(_0x2409f4,_0xa1fbb7))[_0xf280('0x46')](handleError(_0x2409f4,null));};exports[_0xf280('0x47')]=function(_0x408be4,_0x4dcffd){var _0x2ef2c6={'raw':!![],'where':{'id':_0x408be4[_0xf280('0x48')]['id']}},_0x456ac6={};_0x456ac6[_0xf280('0x31')]=_[_0xf280('0x34')](db['FaxQueueReport'][_0xf280('0x2d')]);_0x456ac6['query']=_[_0xf280('0x34')](_0x408be4['query']);_0x456ac6[_0xf280('0x35')]=_[_0xf280('0x36')](_0x456ac6[_0xf280('0x31')],_0x456ac6['query']);_0x2ef2c6['attributes']=_[_0xf280('0x36')](_0x456ac6[_0xf280('0x31')],qs['fields'](_0x408be4[_0xf280('0x33')][_0xf280('0x37')]));_0x2ef2c6[_0xf280('0x38')]=_0x2ef2c6[_0xf280('0x38')][_0xf280('0x49')]?_0x2ef2c6['attributes']:_0x456ac6[_0xf280('0x31')];if(_0x408be4[_0xf280('0x33')][_0xf280('0x43')]){_0x2ef2c6[_0xf280('0x44')]=[{'all':!![]}];}_0x2ef2c6=_[_0xf280('0x3f')]({},_0x2ef2c6,_0x408be4[_0xf280('0x4a')]);return db[_0xf280('0x2c')]['find'](_0x2ef2c6)[_0xf280('0x28')](handleEntityNotFound(_0x4dcffd,null))[_0xf280('0x28')](respondWithResult(_0x4dcffd,null))[_0xf280('0x46')](handleError(_0x4dcffd,null));};exports[_0xf280('0x4b')]=function(_0x5648cc,_0x29c7f0){return db[_0xf280('0x2c')]['create'](_0x5648cc[_0xf280('0x4c')],{})[_0xf280('0x28')](respondWithResult(_0x29c7f0,0xc9))['catch'](handleError(_0x29c7f0,null));};exports[_0xf280('0x27')]=function(_0x4991d9,_0x5f45ca){if(_0x4991d9[_0xf280('0x4c')]['id']){delete _0x4991d9[_0xf280('0x4c')]['id'];}return db['FaxQueueReport']['find']({'where':{'id':_0x4991d9[_0xf280('0x48')]['id']}})['then'](handleEntityNotFound(_0x5f45ca,null))[_0xf280('0x28')](saveUpdates(_0x4991d9[_0xf280('0x4c')],null))[_0xf280('0x28')](respondWithResult(_0x5f45ca,null))[_0xf280('0x46')](handleError(_0x5f45ca,null));};exports[_0xf280('0x29')]=function(_0x1c4522,_0xc3a873){return db['FaxQueueReport'][_0xf280('0x4d')]({'where':{'id':_0x1c4522[_0xf280('0x48')]['id']}})['then'](handleEntityNotFound(_0xc3a873,null))['then'](removeEntity(_0xc3a873,null))['catch'](handleError(_0xc3a873,null));};exports['describe']=function(_0x5a8325,_0x1ed725){return db[_0xf280('0x2c')]['describe']()[_0xf280('0x28')](respondWithResult(_0x1ed725,null))[_0xf280('0x46')](handleError(_0x1ed725,null));};