Built motion from commit d5e4af8c.|2.6.23
[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 _0x22dd=['findAll','catch','params','attributes','include','find','create','body','destroy','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','undefined','limit','offset','set','Content-Range','reject','save','update','then','error','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','filter','options','FaxQueueReport','count','includeAll'];(function(_0x67143c,_0x433024){var _0x1dbbc3=function(_0x35a77f){while(--_0x35a77f){_0x67143c['push'](_0x67143c['shift']());}};_0x1dbbc3(++_0x433024);}(_0x22dd,0xe4));var _0xd22d=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x22dd[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xd22d('0x0'));var rimraf=require(_0xd22d('0x1'));var zipdir=require(_0xd22d('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xd22d('0x3'));var BPromise=require(_0xd22d('0x4'));var Mustache=require(_0xd22d('0x5'));var util=require(_0xd22d('0x6'));var path=require(_0xd22d('0x7'));var sox=require(_0xd22d('0x8'));var csv=require(_0xd22d('0x9'));var ejs=require(_0xd22d('0xa'));var fs=require('fs');var fs_extra=require(_0xd22d('0xb'));var _=require(_0xd22d('0xc'));var squel=require('squel');var crypto=require(_0xd22d('0xd'));var jsforce=require(_0xd22d('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xd22d('0x9'));var querystring=require('querystring');var Papa=require(_0xd22d('0xf'));var Redis=require('ioredis');var authService=require(_0xd22d('0x10'));var qs=require(_0xd22d('0x11'));var as=require(_0xd22d('0x12'));var hardwareService=require(_0xd22d('0x13'));var logger=require(_0xd22d('0x14'))(_0xd22d('0x15'));var utils=require(_0xd22d('0x16'));var config=require(_0xd22d('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xd22d('0x18'))['db'];function respondWithStatusCode(_0x46f164,_0x51a8ea){_0x51a8ea=_0x51a8ea||0xcc;return function(_0x38978b){if(_0x38978b){return _0x46f164[_0xd22d('0x19')](_0x51a8ea);}return _0x46f164['status'](_0x51a8ea)['end']();};}function respondWithResult(_0x5994fe,_0x156546){_0x156546=_0x156546||0xc8;return function(_0x5dc338){if(_0x5dc338){return _0x5994fe[_0xd22d('0x1a')](_0x156546)['json'](_0x5dc338);}};}function respondWithFilteredResult(_0x78d93e,_0x5b91bd){return function(_0x5027d){if(_0x5027d){var _0x377e75=typeof _0x5b91bd['offset']===_0xd22d('0x1b')&&typeof _0x5b91bd[_0xd22d('0x1c')]===_0xd22d('0x1b');var _0x11c410=_0x5027d['count'];var _0x5c516a=_0x377e75?0x0:_0x5b91bd[_0xd22d('0x1d')];var _0x5a0a0b=_0x377e75?_0x5027d['count']:_0x5b91bd['offset']+_0x5b91bd[_0xd22d('0x1c')];var _0x46f8b6;if(_0x5a0a0b>=_0x11c410){_0x5a0a0b=_0x11c410;_0x46f8b6=0xc8;}else{_0x46f8b6=0xce;}_0x78d93e[_0xd22d('0x1a')](_0x46f8b6);return _0x78d93e[_0xd22d('0x1e')](_0xd22d('0x1f'),_0x5c516a+'-'+_0x5a0a0b+'/'+_0x11c410)['json'](_0x5027d);}return null;};}function patchUpdates(_0x2bfc84){return function(_0x4e18f5){try{jsonpatch['apply'](_0x4e18f5,_0x2bfc84,!![]);}catch(_0x478c1f){return BPromise[_0xd22d('0x20')](_0x478c1f);}return _0x4e18f5[_0xd22d('0x21')]();};}function saveUpdates(_0x1ecab6,_0x420836){return function(_0x1be46f){if(_0x1be46f){return _0x1be46f[_0xd22d('0x22')](_0x1ecab6)[_0xd22d('0x23')](function(_0x52039a){return _0x52039a;});}return null;};}function removeEntity(_0x3b07b3,_0x8340e5){return function(_0x55bce9){if(_0x55bce9){return _0x55bce9['destroy']()[_0xd22d('0x23')](function(){_0x3b07b3[_0xd22d('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2b0959,_0x370902){return function(_0xee8f2){if(!_0xee8f2){_0x2b0959[_0xd22d('0x19')](0x194);}return _0xee8f2;};}function handleError(_0x2b47c2,_0x2c7b5a){_0x2c7b5a=_0x2c7b5a||0x1f4;return function(_0x2d45ab){logger[_0xd22d('0x24')](_0x2d45ab[_0xd22d('0x25')]);if(_0x2d45ab['name']){delete _0x2d45ab[_0xd22d('0x26')];}_0x2b47c2[_0xd22d('0x1a')](_0x2c7b5a)['send'](_0x2d45ab);};}exports[_0xd22d('0x27')]=function(_0x5f00f9,_0x5381a8){var _0x2d377d={},_0x96a17e={},_0xb3e1f2={'count':0x0,'rows':[]};var _0x16b1c7=_[_0xd22d('0x28')](db['FaxQueueReport'][_0xd22d('0x29')],function(_0x5b47f9){return{'name':_0x5b47f9[_0xd22d('0x2a')],'type':_0x5b47f9[_0xd22d('0x2b')][_0xd22d('0x2c')]};});_0x96a17e[_0xd22d('0x2d')]=_[_0xd22d('0x28')](_0x16b1c7,'name');_0x96a17e[_0xd22d('0x2e')]=_[_0xd22d('0x2f')](_0x5f00f9['query']);_0x96a17e[_0xd22d('0x30')]=_['intersection'](_0x96a17e[_0xd22d('0x2d')],_0x96a17e[_0xd22d('0x2e')]);_0x2d377d['attributes']=_[_0xd22d('0x31')](_0x96a17e[_0xd22d('0x2d')],qs[_0xd22d('0x32')](_0x5f00f9['query'][_0xd22d('0x32')]));_0x2d377d['attributes']=_0x2d377d['attributes'][_0xd22d('0x33')]?_0x2d377d['attributes']:_0x96a17e[_0xd22d('0x2d')];if(!_0x5f00f9['query'][_0xd22d('0x34')](_0xd22d('0x35'))){_0x2d377d['limit']=qs['limit'](_0x5f00f9[_0xd22d('0x2e')][_0xd22d('0x1c')]);_0x2d377d[_0xd22d('0x1d')]=qs[_0xd22d('0x1d')](_0x5f00f9[_0xd22d('0x2e')][_0xd22d('0x1d')]);}_0x2d377d[_0xd22d('0x36')]=qs['sort'](_0x5f00f9['query'][_0xd22d('0x37')]);_0x2d377d[_0xd22d('0x38')]=qs['filters'](_[_0xd22d('0x39')](_0x5f00f9[_0xd22d('0x2e')],_0x96a17e['filters']),_0x16b1c7);if(_0x5f00f9['query']['filter']){_0x2d377d[_0xd22d('0x38')]=_[_0xd22d('0x3a')](_0x2d377d[_0xd22d('0x38')],{'$or':_['map'](_0x16b1c7,function(_0x3d9dfa){if(_0x3d9dfa['type']!=='VIRTUAL'){var _0x1ad490={};_0x1ad490[_0x3d9dfa[_0xd22d('0x26')]]={'$like':'%'+_0x5f00f9['query'][_0xd22d('0x3b')]+'%'};return _0x1ad490;}})});}_0x2d377d=_[_0xd22d('0x3a')]({},_0x2d377d,_0x5f00f9[_0xd22d('0x3c')]);var _0x5c1876={'where':_0x2d377d[_0xd22d('0x38')]};return db[_0xd22d('0x3d')][_0xd22d('0x3e')](_0x5c1876)[_0xd22d('0x23')](function(_0x332830){_0xb3e1f2[_0xd22d('0x3e')]=_0x332830;if(_0x5f00f9[_0xd22d('0x2e')][_0xd22d('0x3f')]){_0x2d377d['include']=[{'all':!![]}];}return db[_0xd22d('0x3d')][_0xd22d('0x40')](_0x2d377d);})[_0xd22d('0x23')](function(_0x1c5007){_0xb3e1f2['rows']=_0x1c5007;return _0xb3e1f2;})[_0xd22d('0x23')](respondWithFilteredResult(_0x5381a8,_0x2d377d))[_0xd22d('0x41')](handleError(_0x5381a8,null));};exports['show']=function(_0x1dea34,_0x360026){var _0x111e84={'raw':!![],'where':{'id':_0x1dea34[_0xd22d('0x42')]['id']}},_0x9ecd41={};_0x9ecd41[_0xd22d('0x2d')]=_[_0xd22d('0x2f')](db['FaxQueueReport'][_0xd22d('0x29')]);_0x9ecd41['query']=_[_0xd22d('0x2f')](_0x1dea34[_0xd22d('0x2e')]);_0x9ecd41[_0xd22d('0x30')]=_[_0xd22d('0x31')](_0x9ecd41['model'],_0x9ecd41[_0xd22d('0x2e')]);_0x111e84[_0xd22d('0x43')]=_['intersection'](_0x9ecd41[_0xd22d('0x2d')],qs[_0xd22d('0x32')](_0x1dea34[_0xd22d('0x2e')]['fields']));_0x111e84[_0xd22d('0x43')]=_0x111e84[_0xd22d('0x43')][_0xd22d('0x33')]?_0x111e84[_0xd22d('0x43')]:_0x9ecd41[_0xd22d('0x2d')];if(_0x1dea34['query'][_0xd22d('0x3f')]){_0x111e84[_0xd22d('0x44')]=[{'all':!![]}];}_0x111e84=_[_0xd22d('0x3a')]({},_0x111e84,_0x1dea34[_0xd22d('0x3c')]);return db[_0xd22d('0x3d')][_0xd22d('0x45')](_0x111e84)[_0xd22d('0x23')](handleEntityNotFound(_0x360026,null))['then'](respondWithResult(_0x360026,null))[_0xd22d('0x41')](handleError(_0x360026,null));};exports[_0xd22d('0x46')]=function(_0x2cbd41,_0x1ec1ec){return db[_0xd22d('0x3d')]['create'](_0x2cbd41[_0xd22d('0x47')],{})[_0xd22d('0x23')](respondWithResult(_0x1ec1ec,0xc9))[_0xd22d('0x41')](handleError(_0x1ec1ec,null));};exports[_0xd22d('0x22')]=function(_0x1ac8e9,_0x1330c1){if(_0x1ac8e9[_0xd22d('0x47')]['id']){delete _0x1ac8e9['body']['id'];}return db['FaxQueueReport']['find']({'where':{'id':_0x1ac8e9[_0xd22d('0x42')]['id']}})[_0xd22d('0x23')](handleEntityNotFound(_0x1330c1,null))['then'](saveUpdates(_0x1ac8e9[_0xd22d('0x47')],null))[_0xd22d('0x23')](respondWithResult(_0x1330c1,null))[_0xd22d('0x41')](handleError(_0x1330c1,null));};exports[_0xd22d('0x48')]=function(_0x125b86,_0x463384){return db['FaxQueueReport'][_0xd22d('0x45')]({'where':{'id':_0x125b86['params']['id']}})[_0xd22d('0x23')](handleEntityNotFound(_0x463384,null))[_0xd22d('0x23')](removeEntity(_0x463384,null))[_0xd22d('0x41')](handleError(_0x463384,null));};exports['describe']=function(_0x2f0375,_0x43df58){return db['FaxQueueReport']['describe']()[_0xd22d('0x23')](respondWithResult(_0x43df58,null))[_0xd22d('0x41')](handleError(_0x43df58,null));};