55966db0f7618b95c2dd06d13fb8a52f4299a36f
[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 _0x10b8=['count','set','Content-Range','apply','update','then','stack','name','map','rawAttributes','fieldName','type','key','model','keys','filters','intersection','query','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','FaxTransferReport','include','findAll','rows','catch','show','params','length','includeAll','find','create','body','destroy','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit'];(function(_0x1780f8,_0x11ba93){var _0x33a410=function(_0x2a015f){while(--_0x2a015f){_0x1780f8['push'](_0x1780f8['shift']());}};_0x33a410(++_0x11ba93);}(_0x10b8,0x10d));var _0x810b=function(_0x26f702,_0x3919bf){_0x26f702=_0x26f702-0x0;var _0x11417d=_0x10b8[_0x26f702];return _0x11417d;};'use strict';var emlformat=require(_0x810b('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x810b('0x1'));var jsonpatch=require(_0x810b('0x2'));var rp=require(_0x810b('0x3'));var moment=require(_0x810b('0x4'));var BPromise=require(_0x810b('0x5'));var Mustache=require(_0x810b('0x6'));var util=require(_0x810b('0x7'));var path=require(_0x810b('0x8'));var sox=require(_0x810b('0x9'));var csv=require(_0x810b('0xa'));var ejs=require(_0x810b('0xb'));var fs=require('fs');var fs_extra=require(_0x810b('0xc'));var _=require(_0x810b('0xd'));var squel=require(_0x810b('0xe'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x810b('0xf'));var toCsv=require(_0x810b('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x810b('0x10'));var qs=require(_0x810b('0x11'));var as=require(_0x810b('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x810b('0x13'))(_0x810b('0x14'));var utils=require('../../config/utils');var config=require(_0x810b('0x15'));var licenseUtil=require(_0x810b('0x16'));var db=require(_0x810b('0x17'))['db'];function respondWithStatusCode(_0x1214bc,_0x5ca33f){_0x5ca33f=_0x5ca33f||0xcc;return function(_0x1baa7a){if(_0x1baa7a){return _0x1214bc[_0x810b('0x18')](_0x5ca33f);}return _0x1214bc[_0x810b('0x19')](_0x5ca33f)[_0x810b('0x1a')]();};}function respondWithResult(_0x4c5715,_0x4f6e8f){_0x4f6e8f=_0x4f6e8f||0xc8;return function(_0x3b87fa){if(_0x3b87fa){return _0x4c5715[_0x810b('0x19')](_0x4f6e8f)[_0x810b('0x1b')](_0x3b87fa);}};}function respondWithFilteredResult(_0xac2aab,_0x5ac7ee){return function(_0x34b994){if(_0x34b994){var _0x389cf3=typeof _0x5ac7ee[_0x810b('0x1c')]===_0x810b('0x1d')&&typeof _0x5ac7ee[_0x810b('0x1e')]===_0x810b('0x1d');var _0x3a7015=_0x34b994[_0x810b('0x1f')];var _0xaaa22a=_0x389cf3?0x0:_0x5ac7ee[_0x810b('0x1c')];var _0x2f64de=_0x389cf3?_0x34b994[_0x810b('0x1f')]:_0x5ac7ee[_0x810b('0x1c')]+_0x5ac7ee[_0x810b('0x1e')];var _0xc8e81;if(_0x2f64de>=_0x3a7015){_0x2f64de=_0x3a7015;_0xc8e81=0xc8;}else{_0xc8e81=0xce;}_0xac2aab['status'](_0xc8e81);return _0xac2aab[_0x810b('0x20')](_0x810b('0x21'),_0xaaa22a+'-'+_0x2f64de+'/'+_0x3a7015)[_0x810b('0x1b')](_0x34b994);}return null;};}function patchUpdates(_0x4745f9){return function(_0xa7b1d7){try{jsonpatch[_0x810b('0x22')](_0xa7b1d7,_0x4745f9,!![]);}catch(_0x499ae0){return BPromise['reject'](_0x499ae0);}return _0xa7b1d7['save']();};}function saveUpdates(_0x398ffb,_0x402f0a){return function(_0x2d1e8f){if(_0x2d1e8f){return _0x2d1e8f[_0x810b('0x23')](_0x398ffb)[_0x810b('0x24')](function(_0x7b9fa7){return _0x7b9fa7;});}return null;};}function removeEntity(_0x3093bd,_0x581213){return function(_0x477fc7){if(_0x477fc7){return _0x477fc7['destroy']()[_0x810b('0x24')](function(){_0x3093bd['status'](0xcc)[_0x810b('0x1a')]();});}};}function handleEntityNotFound(_0x4518ba,_0x4783a1){return function(_0x127055){if(!_0x127055){_0x4518ba['sendStatus'](0x194);}return _0x127055;};}function handleError(_0x579e5e,_0x4501b4){_0x4501b4=_0x4501b4||0x1f4;return function(_0x3c3af1){logger['error'](_0x3c3af1[_0x810b('0x25')]);if(_0x3c3af1[_0x810b('0x26')]){delete _0x3c3af1['name'];}_0x579e5e['status'](_0x4501b4)['send'](_0x3c3af1);};}exports['index']=function(_0x1c5bab,_0x557238){var _0x117392={},_0x358409={},_0x5dbf91={'count':0x0,'rows':[]};var _0xe30e5e=_[_0x810b('0x27')](db['FaxTransferReport'][_0x810b('0x28')],function(_0x5ecbd8){return{'name':_0x5ecbd8[_0x810b('0x29')],'type':_0x5ecbd8[_0x810b('0x2a')][_0x810b('0x2b')]};});_0x358409[_0x810b('0x2c')]=_[_0x810b('0x27')](_0xe30e5e,_0x810b('0x26'));_0x358409['query']=_[_0x810b('0x2d')](_0x1c5bab['query']);_0x358409[_0x810b('0x2e')]=_[_0x810b('0x2f')](_0x358409[_0x810b('0x2c')],_0x358409[_0x810b('0x30')]);_0x117392['attributes']=_[_0x810b('0x2f')](_0x358409[_0x810b('0x2c')],qs[_0x810b('0x31')](_0x1c5bab['query'][_0x810b('0x31')]));_0x117392[_0x810b('0x32')]=_0x117392[_0x810b('0x32')]['length']?_0x117392[_0x810b('0x32')]:_0x358409[_0x810b('0x2c')];if(!_0x1c5bab[_0x810b('0x30')][_0x810b('0x33')](_0x810b('0x34'))){_0x117392[_0x810b('0x1e')]=qs[_0x810b('0x1e')](_0x1c5bab[_0x810b('0x30')][_0x810b('0x1e')]);_0x117392[_0x810b('0x1c')]=qs[_0x810b('0x1c')](_0x1c5bab[_0x810b('0x30')][_0x810b('0x1c')]);}_0x117392[_0x810b('0x35')]=qs[_0x810b('0x36')](_0x1c5bab['query'][_0x810b('0x36')]);_0x117392[_0x810b('0x37')]=qs[_0x810b('0x2e')](_[_0x810b('0x38')](_0x1c5bab[_0x810b('0x30')],_0x358409['filters']),_0xe30e5e);if(_0x1c5bab['query']['filter']){_0x117392['where']=_[_0x810b('0x39')](_0x117392[_0x810b('0x37')],{'$or':_['map'](_0xe30e5e,function(_0x4bfb02){if(_0x4bfb02[_0x810b('0x2a')]!==_0x810b('0x3a')){var _0x4b7828={};_0x4b7828[_0x4bfb02['name']]={'$like':'%'+_0x1c5bab[_0x810b('0x30')][_0x810b('0x3b')]+'%'};return _0x4b7828;}})});}_0x117392=_[_0x810b('0x39')]({},_0x117392,_0x1c5bab[_0x810b('0x3c')]);var _0x17e8e6={'where':_0x117392['where']};return db[_0x810b('0x3d')][_0x810b('0x1f')](_0x17e8e6)[_0x810b('0x24')](function(_0x5413c2){_0x5dbf91[_0x810b('0x1f')]=_0x5413c2;if(_0x1c5bab['query']['includeAll']){_0x117392[_0x810b('0x3e')]=[{'all':!![]}];}return db[_0x810b('0x3d')][_0x810b('0x3f')](_0x117392);})[_0x810b('0x24')](function(_0x20a35e){_0x5dbf91[_0x810b('0x40')]=_0x20a35e;return _0x5dbf91;})[_0x810b('0x24')](respondWithFilteredResult(_0x557238,_0x117392))[_0x810b('0x41')](handleError(_0x557238,null));};exports[_0x810b('0x42')]=function(_0x9968ca,_0x1d1bfe){var _0x55d95a={'raw':!![],'where':{'id':_0x9968ca[_0x810b('0x43')]['id']}},_0x13e666={};_0x13e666[_0x810b('0x2c')]=_[_0x810b('0x2d')](db['FaxTransferReport'][_0x810b('0x28')]);_0x13e666[_0x810b('0x30')]=_[_0x810b('0x2d')](_0x9968ca[_0x810b('0x30')]);_0x13e666[_0x810b('0x2e')]=_[_0x810b('0x2f')](_0x13e666[_0x810b('0x2c')],_0x13e666[_0x810b('0x30')]);_0x55d95a['attributes']=_['intersection'](_0x13e666[_0x810b('0x2c')],qs['fields'](_0x9968ca[_0x810b('0x30')]['fields']));_0x55d95a[_0x810b('0x32')]=_0x55d95a[_0x810b('0x32')][_0x810b('0x44')]?_0x55d95a['attributes']:_0x13e666[_0x810b('0x2c')];if(_0x9968ca[_0x810b('0x30')][_0x810b('0x45')]){_0x55d95a[_0x810b('0x3e')]=[{'all':!![]}];}_0x55d95a=_[_0x810b('0x39')]({},_0x55d95a,_0x9968ca[_0x810b('0x3c')]);return db['FaxTransferReport'][_0x810b('0x46')](_0x55d95a)[_0x810b('0x24')](handleEntityNotFound(_0x1d1bfe,null))[_0x810b('0x24')](respondWithResult(_0x1d1bfe,null))[_0x810b('0x41')](handleError(_0x1d1bfe,null));};exports[_0x810b('0x47')]=function(_0x29110c,_0x7604a9){return db[_0x810b('0x3d')]['create'](_0x29110c[_0x810b('0x48')],{})[_0x810b('0x24')](respondWithResult(_0x7604a9,0xc9))['catch'](handleError(_0x7604a9,null));};exports[_0x810b('0x23')]=function(_0x376ba2,_0x3caccb){if(_0x376ba2[_0x810b('0x48')]['id']){delete _0x376ba2[_0x810b('0x48')]['id'];}return db[_0x810b('0x3d')][_0x810b('0x46')]({'where':{'id':_0x376ba2[_0x810b('0x43')]['id']}})['then'](handleEntityNotFound(_0x3caccb,null))['then'](saveUpdates(_0x376ba2[_0x810b('0x48')],null))[_0x810b('0x24')](respondWithResult(_0x3caccb,null))[_0x810b('0x41')](handleError(_0x3caccb,null));};exports[_0x810b('0x49')]=function(_0x1daf92,_0x5b8f4d){return db[_0x810b('0x3d')][_0x810b('0x46')]({'where':{'id':_0x1daf92[_0x810b('0x43')]['id']}})['then'](handleEntityNotFound(_0x5b8f4d,null))[_0x810b('0x24')](removeEntity(_0x5b8f4d,null))[_0x810b('0x41')](handleError(_0x5b8f4d,null));};exports[_0x810b('0x4a')]=function(_0x199cbf,_0x4b8f47){return db[_0x810b('0x3d')][_0x810b('0x4a')]()[_0x810b('0x24')](respondWithResult(_0x4b8f47,null))[_0x810b('0x41')](handleError(_0x4b8f47,null));};