b5c83b25565d865cf82f944767dd04a780c0345b
[motion2.git] / server / api / faxTransferReport / faxTransferReport.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 _0xf562=['../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','update','then','destroy','name','index','FaxTransferReport','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','map','VIRTUAL','includeAll','rows','catch','show','params','rawAttributes','keys','include','options','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis'];(function(_0x571f59,_0x459b8b){var _0x462b64=function(_0x46831d){while(--_0x46831d){_0x571f59['push'](_0x571f59['shift']());}};_0x462b64(++_0x459b8b);}(_0xf562,0x15b));var _0x2f56=function(_0x4d4469,_0x5ecfcd){_0x4d4469=_0x4d4469-0x0;var _0x4d7fb5=_0xf562[_0x4d4469];return _0x4d7fb5;};'use strict';var emlformat=require(_0x2f56('0x0'));var rimraf=require(_0x2f56('0x1'));var zipdir=require(_0x2f56('0x2'));var jsonpatch=require(_0x2f56('0x3'));var rp=require(_0x2f56('0x4'));var moment=require(_0x2f56('0x5'));var BPromise=require(_0x2f56('0x6'));var Mustache=require(_0x2f56('0x7'));var util=require('util');var path=require('path');var sox=require(_0x2f56('0x8'));var csv=require(_0x2f56('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x2f56('0xa'));var _=require(_0x2f56('0xb'));var squel=require(_0x2f56('0xc'));var crypto=require(_0x2f56('0xd'));var jsforce=require(_0x2f56('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x2f56('0x9'));var querystring=require(_0x2f56('0xf'));var Papa=require(_0x2f56('0x10'));var Redis=require(_0x2f56('0x11'));var authService=require(_0x2f56('0x12'));var qs=require(_0x2f56('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x2f56('0x14'))(_0x2f56('0x15'));var utils=require('../../config/utils');var config=require(_0x2f56('0x16'));var licenseUtil=require(_0x2f56('0x17'));var db=require(_0x2f56('0x18'))['db'];function respondWithStatusCode(_0x52f762,_0x224629){_0x224629=_0x224629||0xcc;return function(_0x512cc3){if(_0x512cc3){return _0x52f762['sendStatus'](_0x224629);}return _0x52f762[_0x2f56('0x19')](_0x224629)[_0x2f56('0x1a')]();};}function respondWithResult(_0x54a6a5,_0x693822){_0x693822=_0x693822||0xc8;return function(_0x5f2637){if(_0x5f2637){return _0x54a6a5[_0x2f56('0x19')](_0x693822)['json'](_0x5f2637);}};}function respondWithFilteredResult(_0x48703,_0x30d6e9){return function(_0x349e8f){if(_0x349e8f){var _0x5ee070=typeof _0x30d6e9[_0x2f56('0x1b')]===_0x2f56('0x1c')&&typeof _0x30d6e9[_0x2f56('0x1d')]===_0x2f56('0x1c');var _0x17c5fa=_0x349e8f[_0x2f56('0x1e')];var _0x580d11=_0x5ee070?0x0:_0x30d6e9[_0x2f56('0x1b')];var _0x2d27e7=_0x5ee070?_0x349e8f['count']:_0x30d6e9[_0x2f56('0x1b')]+_0x30d6e9[_0x2f56('0x1d')];var _0x444eea;if(_0x2d27e7>=_0x17c5fa){_0x2d27e7=_0x17c5fa;_0x444eea=0xc8;}else{_0x444eea=0xce;}_0x48703['status'](_0x444eea);return _0x48703[_0x2f56('0x1f')](_0x2f56('0x20'),_0x580d11+'-'+_0x2d27e7+'/'+_0x17c5fa)[_0x2f56('0x21')](_0x349e8f);}return null;};}function patchUpdates(_0x185597){return function(_0x51c248){try{jsonpatch['apply'](_0x51c248,_0x185597,!![]);}catch(_0x5aa006){return BPromise[_0x2f56('0x22')](_0x5aa006);}return _0x51c248[_0x2f56('0x23')]();};}function saveUpdates(_0x5d2226,_0x22ef32){return function(_0x391ea1){if(_0x391ea1){return _0x391ea1[_0x2f56('0x24')](_0x5d2226)[_0x2f56('0x25')](function(_0x3829f1){return _0x3829f1;});}return null;};}function removeEntity(_0x5225da,_0x3cb95c){return function(_0x20e796){if(_0x20e796){return _0x20e796[_0x2f56('0x26')]()[_0x2f56('0x25')](function(){_0x5225da[_0x2f56('0x19')](0xcc)[_0x2f56('0x1a')]();});}};}function handleEntityNotFound(_0x238d5f,_0xfee2fd){return function(_0x2dc755){if(!_0x2dc755){_0x238d5f['sendStatus'](0x194);}return _0x2dc755;};}function handleError(_0x321b1e,_0x2f3d2b){_0x2f3d2b=_0x2f3d2b||0x1f4;return function(_0x51bcb6){logger['error'](_0x51bcb6['stack']);if(_0x51bcb6[_0x2f56('0x27')]){delete _0x51bcb6[_0x2f56('0x27')];}_0x321b1e[_0x2f56('0x19')](_0x2f3d2b)['send'](_0x51bcb6);};}exports[_0x2f56('0x28')]=function(_0x5b71f3,_0x232994){var _0x5dd160={},_0x1e2d28={},_0x54cd73={'count':0x0,'rows':[]};var _0x2dc47a=_['map'](db[_0x2f56('0x29')]['rawAttributes'],function(_0x4a0aa5){return{'name':_0x4a0aa5[_0x2f56('0x2a')],'type':_0x4a0aa5[_0x2f56('0x2b')][_0x2f56('0x2c')]};});_0x1e2d28['model']=_['map'](_0x2dc47a,'name');_0x1e2d28['query']=_['keys'](_0x5b71f3[_0x2f56('0x2d')]);_0x1e2d28[_0x2f56('0x2e')]=_[_0x2f56('0x2f')](_0x1e2d28[_0x2f56('0x30')],_0x1e2d28['query']);_0x5dd160[_0x2f56('0x31')]=_[_0x2f56('0x2f')](_0x1e2d28[_0x2f56('0x30')],qs[_0x2f56('0x32')](_0x5b71f3[_0x2f56('0x2d')][_0x2f56('0x32')]));_0x5dd160['attributes']=_0x5dd160[_0x2f56('0x31')][_0x2f56('0x33')]?_0x5dd160[_0x2f56('0x31')]:_0x1e2d28['model'];if(!_0x5b71f3['query'][_0x2f56('0x34')](_0x2f56('0x35'))){_0x5dd160[_0x2f56('0x1d')]=qs['limit'](_0x5b71f3[_0x2f56('0x2d')][_0x2f56('0x1d')]);_0x5dd160[_0x2f56('0x1b')]=qs[_0x2f56('0x1b')](_0x5b71f3['query']['offset']);}_0x5dd160[_0x2f56('0x36')]=qs[_0x2f56('0x37')](_0x5b71f3[_0x2f56('0x2d')][_0x2f56('0x37')]);_0x5dd160[_0x2f56('0x38')]=qs[_0x2f56('0x2e')](_['pick'](_0x5b71f3['query'],_0x1e2d28[_0x2f56('0x2e')]),_0x2dc47a);if(_0x5b71f3['query']['filter']){_0x5dd160['where']=_[_0x2f56('0x39')](_0x5dd160[_0x2f56('0x38')],{'$or':_[_0x2f56('0x3a')](_0x2dc47a,function(_0x4ed7fb){if(_0x4ed7fb[_0x2f56('0x2b')]!==_0x2f56('0x3b')){var _0x25c0e7={};_0x25c0e7[_0x4ed7fb[_0x2f56('0x27')]]={'$like':'%'+_0x5b71f3[_0x2f56('0x2d')]['filter']+'%'};return _0x25c0e7;}})});}_0x5dd160=_['merge']({},_0x5dd160,_0x5b71f3['options']);var _0x4ab0d1={'where':_0x5dd160[_0x2f56('0x38')]};return db[_0x2f56('0x29')][_0x2f56('0x1e')](_0x4ab0d1)[_0x2f56('0x25')](function(_0x27b946){_0x54cd73[_0x2f56('0x1e')]=_0x27b946;if(_0x5b71f3[_0x2f56('0x2d')][_0x2f56('0x3c')]){_0x5dd160['include']=[{'all':!![]}];}return db['FaxTransferReport']['findAll'](_0x5dd160);})[_0x2f56('0x25')](function(_0x5f3cd0){_0x54cd73[_0x2f56('0x3d')]=_0x5f3cd0;return _0x54cd73;})[_0x2f56('0x25')](respondWithFilteredResult(_0x232994,_0x5dd160))[_0x2f56('0x3e')](handleError(_0x232994,null));};exports[_0x2f56('0x3f')]=function(_0x419313,_0xbe8346){var _0x4dfe97={'raw':!![],'where':{'id':_0x419313[_0x2f56('0x40')]['id']}},_0x41e74e={};_0x41e74e[_0x2f56('0x30')]=_['keys'](db['FaxTransferReport'][_0x2f56('0x41')]);_0x41e74e[_0x2f56('0x2d')]=_[_0x2f56('0x42')](_0x419313['query']);_0x41e74e[_0x2f56('0x2e')]=_['intersection'](_0x41e74e[_0x2f56('0x30')],_0x41e74e[_0x2f56('0x2d')]);_0x4dfe97['attributes']=_['intersection'](_0x41e74e['model'],qs['fields'](_0x419313[_0x2f56('0x2d')][_0x2f56('0x32')]));_0x4dfe97['attributes']=_0x4dfe97[_0x2f56('0x31')][_0x2f56('0x33')]?_0x4dfe97['attributes']:_0x41e74e['model'];if(_0x419313['query'][_0x2f56('0x3c')]){_0x4dfe97[_0x2f56('0x43')]=[{'all':!![]}];}_0x4dfe97=_[_0x2f56('0x39')]({},_0x4dfe97,_0x419313[_0x2f56('0x44')]);return db[_0x2f56('0x29')][_0x2f56('0x45')](_0x4dfe97)[_0x2f56('0x25')](handleEntityNotFound(_0xbe8346,null))['then'](respondWithResult(_0xbe8346,null))[_0x2f56('0x3e')](handleError(_0xbe8346,null));};exports[_0x2f56('0x46')]=function(_0x423d81,_0x52273c){return db[_0x2f56('0x29')][_0x2f56('0x46')](_0x423d81[_0x2f56('0x47')],{})[_0x2f56('0x25')](respondWithResult(_0x52273c,0xc9))['catch'](handleError(_0x52273c,null));};exports[_0x2f56('0x24')]=function(_0x44e32b,_0x2ac991){if(_0x44e32b[_0x2f56('0x47')]['id']){delete _0x44e32b[_0x2f56('0x47')]['id'];}return db[_0x2f56('0x29')][_0x2f56('0x45')]({'where':{'id':_0x44e32b[_0x2f56('0x40')]['id']}})[_0x2f56('0x25')](handleEntityNotFound(_0x2ac991,null))['then'](saveUpdates(_0x44e32b[_0x2f56('0x47')],null))['then'](respondWithResult(_0x2ac991,null))[_0x2f56('0x3e')](handleError(_0x2ac991,null));};exports[_0x2f56('0x26')]=function(_0x59c1ec,_0x596556){return db['FaxTransferReport'][_0x2f56('0x45')]({'where':{'id':_0x59c1ec['params']['id']}})[_0x2f56('0x25')](handleEntityNotFound(_0x596556,null))['then'](removeEntity(_0x596556,null))[_0x2f56('0x3e')](handleError(_0x596556,null));};exports[_0x2f56('0x48')]=function(_0x6ea046,_0x1a050e){return db[_0x2f56('0x29')][_0x2f56('0x48')]()[_0x2f56('0x25')](respondWithResult(_0x1a050e,null))[_0x2f56('0x3e')](handleError(_0x1a050e,null));};