Built motion from commit e02f907f.|2.6.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 _0x76a3=['filters','intersection','fields','attributes','hasOwnProperty','order','sort','where','pick','filter','VIRTUAL','merge','FaxQueueReport','includeAll','include','rows','catch','show','params','keys','length','options','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','status','json','undefined','limit','count','offset','set','Content-Range','reject','save','update','then','name','send','index','map','rawAttributes','fieldName','key','model','query'];(function(_0x508a0a,_0x5c01f0){var _0x239daa=function(_0x1d24d1){while(--_0x1d24d1){_0x508a0a['push'](_0x508a0a['shift']());}};_0x239daa(++_0x5c01f0);}(_0x76a3,0xf8));var _0x376a=function(_0x55ff3e,_0x41077f){_0x55ff3e=_0x55ff3e-0x0;var _0x2709eb=_0x76a3[_0x55ff3e];return _0x2709eb;};'use strict';var emlformat=require(_0x376a('0x0'));var rimraf=require(_0x376a('0x1'));var zipdir=require(_0x376a('0x2'));var jsonpatch=require(_0x376a('0x3'));var rp=require(_0x376a('0x4'));var moment=require(_0x376a('0x5'));var BPromise=require(_0x376a('0x6'));var Mustache=require(_0x376a('0x7'));var util=require(_0x376a('0x8'));var path=require(_0x376a('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x376a('0xa'));var fs=require('fs');var fs_extra=require(_0x376a('0xb'));var _=require(_0x376a('0xc'));var squel=require(_0x376a('0xd'));var crypto=require('crypto');var jsforce=require(_0x376a('0xe'));var deskjs=require(_0x376a('0xf'));var toCsv=require(_0x376a('0x10'));var querystring=require(_0x376a('0x11'));var Papa=require(_0x376a('0x12'));var Redis=require(_0x376a('0x13'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x376a('0x14'));var logger=require(_0x376a('0x15'))('api');var utils=require(_0x376a('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x376a('0x17'));var db=require(_0x376a('0x18'))['db'];function respondWithStatusCode(_0x4c643c,_0x448f95){_0x448f95=_0x448f95||0xcc;return function(_0x1c023e){if(_0x1c023e){return _0x4c643c[_0x376a('0x19')](_0x448f95);}return _0x4c643c['status'](_0x448f95)[_0x376a('0x1a')]();};}function respondWithResult(_0x541d34,_0x33ad40){_0x33ad40=_0x33ad40||0xc8;return function(_0x457027){if(_0x457027){return _0x541d34[_0x376a('0x1b')](_0x33ad40)[_0x376a('0x1c')](_0x457027);}};}function respondWithFilteredResult(_0x3c43a0,_0x1747f2){return function(_0x3f5409){if(_0x3f5409){var _0x2ec88c=typeof _0x1747f2['offset']===_0x376a('0x1d')&&typeof _0x1747f2[_0x376a('0x1e')]==='undefined';var _0x2a3c5b=_0x3f5409[_0x376a('0x1f')];var _0x2dff31=_0x2ec88c?0x0:_0x1747f2[_0x376a('0x20')];var _0x2519d4=_0x2ec88c?_0x3f5409[_0x376a('0x1f')]:_0x1747f2[_0x376a('0x20')]+_0x1747f2['limit'];var _0x3ed990;if(_0x2519d4>=_0x2a3c5b){_0x2519d4=_0x2a3c5b;_0x3ed990=0xc8;}else{_0x3ed990=0xce;}_0x3c43a0['status'](_0x3ed990);return _0x3c43a0[_0x376a('0x21')](_0x376a('0x22'),_0x2dff31+'-'+_0x2519d4+'/'+_0x2a3c5b)[_0x376a('0x1c')](_0x3f5409);}return null;};}function patchUpdates(_0xd9f03a){return function(_0x3220a6){try{jsonpatch['apply'](_0x3220a6,_0xd9f03a,!![]);}catch(_0x25d295){return BPromise[_0x376a('0x23')](_0x25d295);}return _0x3220a6[_0x376a('0x24')]();};}function saveUpdates(_0x579104,_0x4adf3d){return function(_0x3159b6){if(_0x3159b6){return _0x3159b6[_0x376a('0x25')](_0x579104)['then'](function(_0x98205d){return _0x98205d;});}return null;};}function removeEntity(_0x2b1a35,_0x44b960){return function(_0x12f812){if(_0x12f812){return _0x12f812['destroy']()[_0x376a('0x26')](function(){_0x2b1a35[_0x376a('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1dd8ac,_0x146c7c){return function(_0x34338a){if(!_0x34338a){_0x1dd8ac[_0x376a('0x19')](0x194);}return _0x34338a;};}function handleError(_0x2247ca,_0x412f64){_0x412f64=_0x412f64||0x1f4;return function(_0x581c2b){logger['error'](_0x581c2b['stack']);if(_0x581c2b[_0x376a('0x27')]){delete _0x581c2b[_0x376a('0x27')];}_0x2247ca[_0x376a('0x1b')](_0x412f64)[_0x376a('0x28')](_0x581c2b);};}exports[_0x376a('0x29')]=function(_0x54d340,_0x46cb76){var _0x1ca79f={},_0x56d0b9={},_0x510a3f={'count':0x0,'rows':[]};var _0x3103c3=_[_0x376a('0x2a')](db['FaxQueueReport'][_0x376a('0x2b')],function(_0x47f3dd){return{'name':_0x47f3dd[_0x376a('0x2c')],'type':_0x47f3dd['type'][_0x376a('0x2d')]};});_0x56d0b9[_0x376a('0x2e')]=_[_0x376a('0x2a')](_0x3103c3,'name');_0x56d0b9[_0x376a('0x2f')]=_['keys'](_0x54d340['query']);_0x56d0b9[_0x376a('0x30')]=_[_0x376a('0x31')](_0x56d0b9['model'],_0x56d0b9[_0x376a('0x2f')]);_0x1ca79f['attributes']=_[_0x376a('0x31')](_0x56d0b9['model'],qs[_0x376a('0x32')](_0x54d340[_0x376a('0x2f')]['fields']));_0x1ca79f[_0x376a('0x33')]=_0x1ca79f[_0x376a('0x33')]['length']?_0x1ca79f[_0x376a('0x33')]:_0x56d0b9[_0x376a('0x2e')];if(!_0x54d340[_0x376a('0x2f')][_0x376a('0x34')]('nolimit')){_0x1ca79f[_0x376a('0x1e')]=qs[_0x376a('0x1e')](_0x54d340['query'][_0x376a('0x1e')]);_0x1ca79f['offset']=qs[_0x376a('0x20')](_0x54d340[_0x376a('0x2f')][_0x376a('0x20')]);}_0x1ca79f[_0x376a('0x35')]=qs[_0x376a('0x36')](_0x54d340[_0x376a('0x2f')]['sort']);_0x1ca79f[_0x376a('0x37')]=qs['filters'](_[_0x376a('0x38')](_0x54d340[_0x376a('0x2f')],_0x56d0b9[_0x376a('0x30')]),_0x3103c3);if(_0x54d340[_0x376a('0x2f')][_0x376a('0x39')]){_0x1ca79f[_0x376a('0x37')]=_['merge'](_0x1ca79f[_0x376a('0x37')],{'$or':_['map'](_0x3103c3,function(_0x16d419){if(_0x16d419['type']!==_0x376a('0x3a')){var _0x557f92={};_0x557f92[_0x16d419[_0x376a('0x27')]]={'$like':'%'+_0x54d340['query'][_0x376a('0x39')]+'%'};return _0x557f92;}})});}_0x1ca79f=_[_0x376a('0x3b')]({},_0x1ca79f,_0x54d340['options']);var _0x4c48ed={'where':_0x1ca79f['where']};return db[_0x376a('0x3c')][_0x376a('0x1f')](_0x4c48ed)[_0x376a('0x26')](function(_0x57116d){_0x510a3f[_0x376a('0x1f')]=_0x57116d;if(_0x54d340[_0x376a('0x2f')][_0x376a('0x3d')]){_0x1ca79f[_0x376a('0x3e')]=[{'all':!![]}];}return db[_0x376a('0x3c')]['findAll'](_0x1ca79f);})[_0x376a('0x26')](function(_0x268a39){_0x510a3f[_0x376a('0x3f')]=_0x268a39;return _0x510a3f;})[_0x376a('0x26')](respondWithFilteredResult(_0x46cb76,_0x1ca79f))[_0x376a('0x40')](handleError(_0x46cb76,null));};exports[_0x376a('0x41')]=function(_0x37d1ef,_0xacf246){var _0x113c11={'raw':!![],'where':{'id':_0x37d1ef[_0x376a('0x42')]['id']}},_0x356727={};_0x356727[_0x376a('0x2e')]=_[_0x376a('0x43')](db[_0x376a('0x3c')][_0x376a('0x2b')]);_0x356727[_0x376a('0x2f')]=_[_0x376a('0x43')](_0x37d1ef[_0x376a('0x2f')]);_0x356727[_0x376a('0x30')]=_[_0x376a('0x31')](_0x356727[_0x376a('0x2e')],_0x356727[_0x376a('0x2f')]);_0x113c11[_0x376a('0x33')]=_['intersection'](_0x356727['model'],qs[_0x376a('0x32')](_0x37d1ef[_0x376a('0x2f')][_0x376a('0x32')]));_0x113c11[_0x376a('0x33')]=_0x113c11[_0x376a('0x33')][_0x376a('0x44')]?_0x113c11[_0x376a('0x33')]:_0x356727['model'];if(_0x37d1ef[_0x376a('0x2f')]['includeAll']){_0x113c11[_0x376a('0x3e')]=[{'all':!![]}];}_0x113c11=_['merge']({},_0x113c11,_0x37d1ef[_0x376a('0x45')]);return db[_0x376a('0x3c')][_0x376a('0x46')](_0x113c11)['then'](handleEntityNotFound(_0xacf246,null))[_0x376a('0x26')](respondWithResult(_0xacf246,null))[_0x376a('0x40')](handleError(_0xacf246,null));};exports['create']=function(_0x3ed038,_0x5f083e){return db[_0x376a('0x3c')][_0x376a('0x47')](_0x3ed038[_0x376a('0x48')],{})[_0x376a('0x26')](respondWithResult(_0x5f083e,0xc9))[_0x376a('0x40')](handleError(_0x5f083e,null));};exports['update']=function(_0x2024bc,_0xb381db){if(_0x2024bc[_0x376a('0x48')]['id']){delete _0x2024bc['body']['id'];}return db['FaxQueueReport'][_0x376a('0x46')]({'where':{'id':_0x2024bc[_0x376a('0x42')]['id']}})[_0x376a('0x26')](handleEntityNotFound(_0xb381db,null))[_0x376a('0x26')](saveUpdates(_0x2024bc['body'],null))['then'](respondWithResult(_0xb381db,null))['catch'](handleError(_0xb381db,null));};exports['destroy']=function(_0x4cf7e0,_0x2329a7){return db[_0x376a('0x3c')][_0x376a('0x46')]({'where':{'id':_0x4cf7e0[_0x376a('0x42')]['id']}})['then'](handleEntityNotFound(_0x2329a7,null))[_0x376a('0x26')](removeEntity(_0x2329a7,null))[_0x376a('0x40')](handleError(_0x2329a7,null));};exports[_0x376a('0x49')]=function(_0x54d2c6,_0x403178){return db[_0x376a('0x3c')]['describe']()[_0x376a('0x26')](respondWithResult(_0x403178,null))['catch'](handleError(_0x403178,null));};