Built motion from commit 775e2a94.|2.6.3
[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 _0xc5da=['FaxTransferReport','include','findAll','rows','catch','show','params','length','includeAll','find','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','destroy','end','error','stack','name','send','index','rawAttributes','key','model','map','keys','query','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','VIRTUAL','merge','options'];(function(_0x5ebf9c,_0x1970a0){var _0x50f191=function(_0x39de54){while(--_0x39de54){_0x5ebf9c['push'](_0x5ebf9c['shift']());}};_0x50f191(++_0x1970a0);}(_0xc5da,0x148));var _0xac5d=function(_0x519888,_0x32f7c3){_0x519888=_0x519888-0x0;var _0x1aa974=_0xc5da[_0x519888];return _0x1aa974;};'use strict';var emlformat=require(_0xac5d('0x0'));var rimraf=require(_0xac5d('0x1'));var zipdir=require(_0xac5d('0x2'));var jsonpatch=require(_0xac5d('0x3'));var rp=require(_0xac5d('0x4'));var moment=require(_0xac5d('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xac5d('0x6'));var util=require(_0xac5d('0x7'));var path=require(_0xac5d('0x8'));var sox=require(_0xac5d('0x9'));var csv=require(_0xac5d('0xa'));var ejs=require(_0xac5d('0xb'));var fs=require('fs');var fs_extra=require(_0xac5d('0xc'));var _=require(_0xac5d('0xd'));var squel=require('squel');var crypto=require(_0xac5d('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xac5d('0xf'));var toCsv=require('to-csv');var querystring=require(_0xac5d('0x10'));var Papa=require('papaparse');var Redis=require(_0xac5d('0x11'));var authService=require(_0xac5d('0x12'));var qs=require(_0xac5d('0x13'));var as=require(_0xac5d('0x14'));var hardwareService=require(_0xac5d('0x15'));var logger=require(_0xac5d('0x16'))(_0xac5d('0x17'));var utils=require(_0xac5d('0x18'));var config=require(_0xac5d('0x19'));var licenseUtil=require(_0xac5d('0x1a'));var db=require(_0xac5d('0x1b'))['db'];function respondWithStatusCode(_0x5e473a,_0x12ed9b){_0x12ed9b=_0x12ed9b||0xcc;return function(_0x53bce4){if(_0x53bce4){return _0x5e473a[_0xac5d('0x1c')](_0x12ed9b);}return _0x5e473a['status'](_0x12ed9b)['end']();};}function respondWithResult(_0x3ee8f9,_0x4c5c77){_0x4c5c77=_0x4c5c77||0xc8;return function(_0x338d00){if(_0x338d00){return _0x3ee8f9[_0xac5d('0x1d')](_0x4c5c77)[_0xac5d('0x1e')](_0x338d00);}};}function respondWithFilteredResult(_0x2c30a9,_0x420ec8){return function(_0x6fc020){if(_0x6fc020){var _0x1d9241=typeof _0x420ec8[_0xac5d('0x1f')]===_0xac5d('0x20')&&typeof _0x420ec8[_0xac5d('0x21')]===_0xac5d('0x20');var _0x3b4bc1=_0x6fc020[_0xac5d('0x22')];var _0x522661=_0x1d9241?0x0:_0x420ec8['offset'];var _0x39fd1a=_0x1d9241?_0x6fc020['count']:_0x420ec8[_0xac5d('0x1f')]+_0x420ec8[_0xac5d('0x21')];var _0x54f9cb;if(_0x39fd1a>=_0x3b4bc1){_0x39fd1a=_0x3b4bc1;_0x54f9cb=0xc8;}else{_0x54f9cb=0xce;}_0x2c30a9['status'](_0x54f9cb);return _0x2c30a9[_0xac5d('0x23')](_0xac5d('0x24'),_0x522661+'-'+_0x39fd1a+'/'+_0x3b4bc1)[_0xac5d('0x1e')](_0x6fc020);}return null;};}function patchUpdates(_0x5b89fd){return function(_0x15519e){try{jsonpatch[_0xac5d('0x25')](_0x15519e,_0x5b89fd,!![]);}catch(_0x2d4f3d){return BPromise['reject'](_0x2d4f3d);}return _0x15519e[_0xac5d('0x26')]();};}function saveUpdates(_0x1d1775,_0x45cd87){return function(_0x286a07){if(_0x286a07){return _0x286a07[_0xac5d('0x27')](_0x1d1775)[_0xac5d('0x28')](function(_0x23fc87){return _0x23fc87;});}return null;};}function removeEntity(_0x2cca1f,_0x410b1f){return function(_0x3b7dbc){if(_0x3b7dbc){return _0x3b7dbc[_0xac5d('0x29')]()[_0xac5d('0x28')](function(){_0x2cca1f[_0xac5d('0x1d')](0xcc)[_0xac5d('0x2a')]();});}};}function handleEntityNotFound(_0x3b834e,_0x5bcc4a){return function(_0x1c33e3){if(!_0x1c33e3){_0x3b834e['sendStatus'](0x194);}return _0x1c33e3;};}function handleError(_0x2c49b3,_0x84d1d2){_0x84d1d2=_0x84d1d2||0x1f4;return function(_0x2e2311){logger[_0xac5d('0x2b')](_0x2e2311[_0xac5d('0x2c')]);if(_0x2e2311[_0xac5d('0x2d')]){delete _0x2e2311[_0xac5d('0x2d')];}_0x2c49b3[_0xac5d('0x1d')](_0x84d1d2)[_0xac5d('0x2e')](_0x2e2311);};}exports[_0xac5d('0x2f')]=function(_0x586c07,_0x397c15){var _0x598cd9={},_0x3c5e7d={},_0x4c3e50={'count':0x0,'rows':[]};var _0xe2b1fa=_['map'](db['FaxTransferReport'][_0xac5d('0x30')],function(_0x122a36){return{'name':_0x122a36['fieldName'],'type':_0x122a36['type'][_0xac5d('0x31')]};});_0x3c5e7d[_0xac5d('0x32')]=_[_0xac5d('0x33')](_0xe2b1fa,_0xac5d('0x2d'));_0x3c5e7d['query']=_[_0xac5d('0x34')](_0x586c07[_0xac5d('0x35')]);_0x3c5e7d[_0xac5d('0x36')]=_[_0xac5d('0x37')](_0x3c5e7d[_0xac5d('0x32')],_0x3c5e7d['query']);_0x598cd9[_0xac5d('0x38')]=_[_0xac5d('0x37')](_0x3c5e7d[_0xac5d('0x32')],qs[_0xac5d('0x39')](_0x586c07['query']['fields']));_0x598cd9['attributes']=_0x598cd9[_0xac5d('0x38')]['length']?_0x598cd9[_0xac5d('0x38')]:_0x3c5e7d[_0xac5d('0x32')];if(!_0x586c07[_0xac5d('0x35')][_0xac5d('0x3a')]('nolimit')){_0x598cd9[_0xac5d('0x21')]=qs['limit'](_0x586c07[_0xac5d('0x35')][_0xac5d('0x21')]);_0x598cd9['offset']=qs['offset'](_0x586c07[_0xac5d('0x35')][_0xac5d('0x1f')]);}_0x598cd9[_0xac5d('0x3b')]=qs[_0xac5d('0x3c')](_0x586c07['query'][_0xac5d('0x3c')]);_0x598cd9[_0xac5d('0x3d')]=qs[_0xac5d('0x36')](_[_0xac5d('0x3e')](_0x586c07[_0xac5d('0x35')],_0x3c5e7d[_0xac5d('0x36')]),_0xe2b1fa);if(_0x586c07[_0xac5d('0x35')][_0xac5d('0x3f')]){_0x598cd9[_0xac5d('0x3d')]=_['merge'](_0x598cd9[_0xac5d('0x3d')],{'$or':_[_0xac5d('0x33')](_0xe2b1fa,function(_0x46c921){if(_0x46c921['type']!==_0xac5d('0x40')){var _0x160f6a={};_0x160f6a[_0x46c921[_0xac5d('0x2d')]]={'$like':'%'+_0x586c07[_0xac5d('0x35')]['filter']+'%'};return _0x160f6a;}})});}_0x598cd9=_[_0xac5d('0x41')]({},_0x598cd9,_0x586c07[_0xac5d('0x42')]);var _0x44a91a={'where':_0x598cd9[_0xac5d('0x3d')]};return db[_0xac5d('0x43')][_0xac5d('0x22')](_0x44a91a)[_0xac5d('0x28')](function(_0x23824c){_0x4c3e50['count']=_0x23824c;if(_0x586c07['query']['includeAll']){_0x598cd9[_0xac5d('0x44')]=[{'all':!![]}];}return db[_0xac5d('0x43')][_0xac5d('0x45')](_0x598cd9);})[_0xac5d('0x28')](function(_0x3f0680){_0x4c3e50[_0xac5d('0x46')]=_0x3f0680;return _0x4c3e50;})[_0xac5d('0x28')](respondWithFilteredResult(_0x397c15,_0x598cd9))[_0xac5d('0x47')](handleError(_0x397c15,null));};exports[_0xac5d('0x48')]=function(_0x161d82,_0x42042d){var _0x35f9d5={'raw':!![],'where':{'id':_0x161d82[_0xac5d('0x49')]['id']}},_0xf67796={};_0xf67796[_0xac5d('0x32')]=_[_0xac5d('0x34')](db[_0xac5d('0x43')]['rawAttributes']);_0xf67796[_0xac5d('0x35')]=_[_0xac5d('0x34')](_0x161d82['query']);_0xf67796['filters']=_[_0xac5d('0x37')](_0xf67796['model'],_0xf67796[_0xac5d('0x35')]);_0x35f9d5['attributes']=_[_0xac5d('0x37')](_0xf67796[_0xac5d('0x32')],qs[_0xac5d('0x39')](_0x161d82['query']['fields']));_0x35f9d5[_0xac5d('0x38')]=_0x35f9d5['attributes'][_0xac5d('0x4a')]?_0x35f9d5['attributes']:_0xf67796[_0xac5d('0x32')];if(_0x161d82[_0xac5d('0x35')][_0xac5d('0x4b')]){_0x35f9d5[_0xac5d('0x44')]=[{'all':!![]}];}_0x35f9d5=_[_0xac5d('0x41')]({},_0x35f9d5,_0x161d82[_0xac5d('0x42')]);return db['FaxTransferReport'][_0xac5d('0x4c')](_0x35f9d5)['then'](handleEntityNotFound(_0x42042d,null))[_0xac5d('0x28')](respondWithResult(_0x42042d,null))[_0xac5d('0x47')](handleError(_0x42042d,null));};exports['create']=function(_0xf1fd0b,_0x59a65f){return db[_0xac5d('0x43')]['create'](_0xf1fd0b['body'],{})[_0xac5d('0x28')](respondWithResult(_0x59a65f,0xc9))[_0xac5d('0x47')](handleError(_0x59a65f,null));};exports[_0xac5d('0x27')]=function(_0x1d1394,_0x15598d){if(_0x1d1394[_0xac5d('0x4d')]['id']){delete _0x1d1394[_0xac5d('0x4d')]['id'];}return db[_0xac5d('0x43')]['find']({'where':{'id':_0x1d1394[_0xac5d('0x49')]['id']}})[_0xac5d('0x28')](handleEntityNotFound(_0x15598d,null))[_0xac5d('0x28')](saveUpdates(_0x1d1394[_0xac5d('0x4d')],null))[_0xac5d('0x28')](respondWithResult(_0x15598d,null))['catch'](handleError(_0x15598d,null));};exports[_0xac5d('0x29')]=function(_0x205858,_0xc5d32f){return db['FaxTransferReport'][_0xac5d('0x4c')]({'where':{'id':_0x205858[_0xac5d('0x49')]['id']}})[_0xac5d('0x28')](handleEntityNotFound(_0xc5d32f,null))[_0xac5d('0x28')](removeEntity(_0xc5d32f,null))['catch'](handleError(_0xc5d32f,null));};exports[_0xac5d('0x4e')]=function(_0x3dc056,_0x103c6e){return db[_0xac5d('0x43')][_0xac5d('0x4e')]()[_0xac5d('0x28')](respondWithResult(_0x103c6e,null))[_0xac5d('0x47')](handleError(_0x103c6e,null));};