c9e806fd03d2b263000e9c8e67edf2503f20062a
[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 _0x90a4=['body','find','params','describe','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','sox','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','apply','reject','save','update','then','destroy','end','stack','name','index','map','FaxTransferReport','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','create'];(function(_0x40ad54,_0x4b7e7c){var _0x3b062f=function(_0x149468){while(--_0x149468){_0x40ad54['push'](_0x40ad54['shift']());}};_0x3b062f(++_0x4b7e7c);}(_0x90a4,0xf4));var _0x490a=function(_0x108f9e,_0x4f753b){_0x108f9e=_0x108f9e-0x0;var _0x14f605=_0x90a4[_0x108f9e];return _0x14f605;};'use strict';var emlformat=require(_0x490a('0x0'));var rimraf=require(_0x490a('0x1'));var zipdir=require(_0x490a('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x490a('0x3'));var BPromise=require(_0x490a('0x4'));var Mustache=require(_0x490a('0x5'));var util=require(_0x490a('0x6'));var path=require(_0x490a('0x7'));var sox=require(_0x490a('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x490a('0x9'));var _=require(_0x490a('0xa'));var squel=require(_0x490a('0xb'));var crypto=require(_0x490a('0xc'));var jsforce=require(_0x490a('0xd'));var deskjs=require(_0x490a('0xe'));var toCsv=require(_0x490a('0xf'));var querystring=require(_0x490a('0x10'));var Papa=require(_0x490a('0x11'));var Redis=require(_0x490a('0x12'));var authService=require(_0x490a('0x13'));var qs=require(_0x490a('0x14'));var as=require(_0x490a('0x15'));var hardwareService=require(_0x490a('0x16'));var logger=require(_0x490a('0x17'))(_0x490a('0x18'));var utils=require('../../config/utils');var config=require(_0x490a('0x19'));var licenseUtil=require(_0x490a('0x1a'));var db=require(_0x490a('0x1b'))['db'];function respondWithStatusCode(_0x186415,_0x49e08a){_0x49e08a=_0x49e08a||0xcc;return function(_0x3a521f){if(_0x3a521f){return _0x186415[_0x490a('0x1c')](_0x49e08a);}return _0x186415[_0x490a('0x1d')](_0x49e08a)['end']();};}function respondWithResult(_0x1c0c10,_0x56cb52){_0x56cb52=_0x56cb52||0xc8;return function(_0x35f5a5){if(_0x35f5a5){return _0x1c0c10[_0x490a('0x1d')](_0x56cb52)[_0x490a('0x1e')](_0x35f5a5);}};}function respondWithFilteredResult(_0x42c324,_0x1dd1d8){return function(_0x551a47){if(_0x551a47){var _0x93fa60=typeof _0x1dd1d8[_0x490a('0x1f')]===_0x490a('0x20')&&typeof _0x1dd1d8[_0x490a('0x21')]===_0x490a('0x20');var _0x33b0de=_0x551a47[_0x490a('0x22')];var _0x181bd5=_0x93fa60?0x0:_0x1dd1d8[_0x490a('0x1f')];var _0x1e1c2f=_0x93fa60?_0x551a47[_0x490a('0x22')]:_0x1dd1d8['offset']+_0x1dd1d8['limit'];var _0xbcde53;if(_0x1e1c2f>=_0x33b0de){_0x1e1c2f=_0x33b0de;_0xbcde53=0xc8;}else{_0xbcde53=0xce;}_0x42c324['status'](_0xbcde53);return _0x42c324[_0x490a('0x23')]('Content-Range',_0x181bd5+'-'+_0x1e1c2f+'/'+_0x33b0de)[_0x490a('0x1e')](_0x551a47);}return null;};}function patchUpdates(_0x3e66ac){return function(_0x16c26a){try{jsonpatch[_0x490a('0x24')](_0x16c26a,_0x3e66ac,!![]);}catch(_0x1597a2){return BPromise[_0x490a('0x25')](_0x1597a2);}return _0x16c26a[_0x490a('0x26')]();};}function saveUpdates(_0xa2d142,_0x4ccd0a){return function(_0x1a7b49){if(_0x1a7b49){return _0x1a7b49[_0x490a('0x27')](_0xa2d142)[_0x490a('0x28')](function(_0x21992a){return _0x21992a;});}return null;};}function removeEntity(_0x581c1b,_0x133b54){return function(_0x13b101){if(_0x13b101){return _0x13b101[_0x490a('0x29')]()[_0x490a('0x28')](function(){_0x581c1b[_0x490a('0x1d')](0xcc)[_0x490a('0x2a')]();});}};}function handleEntityNotFound(_0x52b71d,_0x1b2121){return function(_0x360a26){if(!_0x360a26){_0x52b71d['sendStatus'](0x194);}return _0x360a26;};}function handleError(_0x1df929,_0x47a883){_0x47a883=_0x47a883||0x1f4;return function(_0x339b23){logger['error'](_0x339b23[_0x490a('0x2b')]);if(_0x339b23['name']){delete _0x339b23[_0x490a('0x2c')];}_0x1df929[_0x490a('0x1d')](_0x47a883)['send'](_0x339b23);};}exports[_0x490a('0x2d')]=function(_0x16d834,_0x14c2b9){var _0x333607={},_0x1584a2={},_0xf3d942={'count':0x0,'rows':[]};var _0x3a3f00=_[_0x490a('0x2e')](db[_0x490a('0x2f')][_0x490a('0x30')],function(_0x1c3a79){return{'name':_0x1c3a79[_0x490a('0x31')],'type':_0x1c3a79[_0x490a('0x32')][_0x490a('0x33')]};});_0x1584a2['model']=_[_0x490a('0x2e')](_0x3a3f00,_0x490a('0x2c'));_0x1584a2['query']=_[_0x490a('0x34')](_0x16d834[_0x490a('0x35')]);_0x1584a2[_0x490a('0x36')]=_[_0x490a('0x37')](_0x1584a2[_0x490a('0x38')],_0x1584a2[_0x490a('0x35')]);_0x333607[_0x490a('0x39')]=_[_0x490a('0x37')](_0x1584a2['model'],qs['fields'](_0x16d834['query'][_0x490a('0x3a')]));_0x333607[_0x490a('0x39')]=_0x333607['attributes'][_0x490a('0x3b')]?_0x333607[_0x490a('0x39')]:_0x1584a2[_0x490a('0x38')];if(!_0x16d834[_0x490a('0x35')][_0x490a('0x3c')](_0x490a('0x3d'))){_0x333607[_0x490a('0x21')]=qs[_0x490a('0x21')](_0x16d834[_0x490a('0x35')][_0x490a('0x21')]);_0x333607['offset']=qs[_0x490a('0x1f')](_0x16d834['query'][_0x490a('0x1f')]);}_0x333607[_0x490a('0x3e')]=qs[_0x490a('0x3f')](_0x16d834[_0x490a('0x35')][_0x490a('0x3f')]);_0x333607[_0x490a('0x40')]=qs[_0x490a('0x36')](_[_0x490a('0x41')](_0x16d834[_0x490a('0x35')],_0x1584a2[_0x490a('0x36')]),_0x3a3f00);if(_0x16d834['query'][_0x490a('0x42')]){_0x333607[_0x490a('0x40')]=_[_0x490a('0x43')](_0x333607[_0x490a('0x40')],{'$or':_[_0x490a('0x2e')](_0x3a3f00,function(_0x5a815b){if(_0x5a815b[_0x490a('0x32')]!==_0x490a('0x44')){var _0xdac3f1={};_0xdac3f1[_0x5a815b['name']]={'$like':'%'+_0x16d834['query'][_0x490a('0x42')]+'%'};return _0xdac3f1;}})});}_0x333607=_['merge']({},_0x333607,_0x16d834['options']);var _0x32b75b={'where':_0x333607[_0x490a('0x40')]};return db['FaxTransferReport'][_0x490a('0x22')](_0x32b75b)[_0x490a('0x28')](function(_0x2cbc3c){_0xf3d942[_0x490a('0x22')]=_0x2cbc3c;if(_0x16d834[_0x490a('0x35')][_0x490a('0x45')]){_0x333607[_0x490a('0x46')]=[{'all':!![]}];}return db[_0x490a('0x2f')][_0x490a('0x47')](_0x333607);})['then'](function(_0x3b3351){_0xf3d942[_0x490a('0x48')]=_0x3b3351;return _0xf3d942;})['then'](respondWithFilteredResult(_0x14c2b9,_0x333607))[_0x490a('0x49')](handleError(_0x14c2b9,null));};exports[_0x490a('0x4a')]=function(_0xb2da27,_0x3165fb){var _0x173f8a={'raw':!![],'where':{'id':_0xb2da27['params']['id']}},_0x1c4264={};_0x1c4264[_0x490a('0x38')]=_[_0x490a('0x34')](db[_0x490a('0x2f')][_0x490a('0x30')]);_0x1c4264[_0x490a('0x35')]=_[_0x490a('0x34')](_0xb2da27['query']);_0x1c4264['filters']=_['intersection'](_0x1c4264[_0x490a('0x38')],_0x1c4264[_0x490a('0x35')]);_0x173f8a[_0x490a('0x39')]=_[_0x490a('0x37')](_0x1c4264[_0x490a('0x38')],qs[_0x490a('0x3a')](_0xb2da27[_0x490a('0x35')]['fields']));_0x173f8a['attributes']=_0x173f8a[_0x490a('0x39')][_0x490a('0x3b')]?_0x173f8a[_0x490a('0x39')]:_0x1c4264[_0x490a('0x38')];if(_0xb2da27[_0x490a('0x35')][_0x490a('0x45')]){_0x173f8a[_0x490a('0x46')]=[{'all':!![]}];}_0x173f8a=_['merge']({},_0x173f8a,_0xb2da27['options']);return db[_0x490a('0x2f')]['find'](_0x173f8a)['then'](handleEntityNotFound(_0x3165fb,null))[_0x490a('0x28')](respondWithResult(_0x3165fb,null))['catch'](handleError(_0x3165fb,null));};exports[_0x490a('0x4b')]=function(_0x365635,_0x52d15d){return db[_0x490a('0x2f')][_0x490a('0x4b')](_0x365635['body'],{})[_0x490a('0x28')](respondWithResult(_0x52d15d,0xc9))['catch'](handleError(_0x52d15d,null));};exports[_0x490a('0x27')]=function(_0x10a99c,_0x512b8a){if(_0x10a99c[_0x490a('0x4c')]['id']){delete _0x10a99c[_0x490a('0x4c')]['id'];}return db['FaxTransferReport'][_0x490a('0x4d')]({'where':{'id':_0x10a99c[_0x490a('0x4e')]['id']}})[_0x490a('0x28')](handleEntityNotFound(_0x512b8a,null))[_0x490a('0x28')](saveUpdates(_0x10a99c[_0x490a('0x4c')],null))[_0x490a('0x28')](respondWithResult(_0x512b8a,null))[_0x490a('0x49')](handleError(_0x512b8a,null));};exports['destroy']=function(_0x4064b0,_0x5eda8a){return db[_0x490a('0x2f')][_0x490a('0x4d')]({'where':{'id':_0x4064b0['params']['id']}})['then'](handleEntityNotFound(_0x5eda8a,null))[_0x490a('0x28')](removeEntity(_0x5eda8a,null))[_0x490a('0x49')](handleError(_0x5eda8a,null));};exports[_0x490a('0x4f')]=function(_0x481b83,_0x173508){return db[_0x490a('0x2f')][_0x490a('0x4f')]()[_0x490a('0x28')](respondWithResult(_0x173508,null))[_0x490a('0x49')](handleError(_0x173508,null));};