04a7bc918ee2f3d123bbe88219be3a22fe6dee2a
[motion2.git] / server / api / openchannelTransferReport / openchannelTransferReport.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 _0x864f=['path','sox','to-csv','fs-extra','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','save','update','then','end','error','stack','name','send','index','map','OpenchannelTransferReport','rawAttributes','fieldName','type','key','model','filters','intersection','query','attributes','length','order','sort','where','pick','merge','filter','options','includeAll','rows','show','params','keys','fields','include','find','create','body','catch','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util'];(function(_0x2e9a06,_0x3d0b26){var _0x4a3e10=function(_0x4f8100){while(--_0x4f8100){_0x2e9a06['push'](_0x2e9a06['shift']());}};_0x4a3e10(++_0x3d0b26);}(_0x864f,0xd4));var _0xf864=function(_0x2d5915,_0x1aec02){_0x2d5915=_0x2d5915-0x0;var _0x3772b6=_0x864f[_0x2d5915];return _0x3772b6;};'use strict';var emlformat=require(_0xf864('0x0'));var rimraf=require(_0xf864('0x1'));var zipdir=require(_0xf864('0x2'));var jsonpatch=require(_0xf864('0x3'));var rp=require('request-promise');var moment=require(_0xf864('0x4'));var BPromise=require(_0xf864('0x5'));var Mustache=require('mustache');var util=require(_0xf864('0x6'));var path=require(_0xf864('0x7'));var sox=require(_0xf864('0x8'));var csv=require(_0xf864('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf864('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xf864('0xb'));var jsforce=require(_0xf864('0xc'));var deskjs=require(_0xf864('0xd'));var toCsv=require(_0xf864('0x9'));var querystring=require(_0xf864('0xe'));var Papa=require('papaparse');var Redis=require(_0xf864('0xf'));var authService=require(_0xf864('0x10'));var qs=require(_0xf864('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf864('0x12'));var logger=require(_0xf864('0x13'))('api');var utils=require(_0xf864('0x14'));var config=require(_0xf864('0x15'));var licenseUtil=require(_0xf864('0x16'));var db=require(_0xf864('0x17'))['db'];function respondWithStatusCode(_0x95e132,_0x65163b){_0x65163b=_0x65163b||0xcc;return function(_0x568551){if(_0x568551){return _0x95e132[_0xf864('0x18')](_0x65163b);}return _0x95e132[_0xf864('0x19')](_0x65163b)['end']();};}function respondWithResult(_0x4c7140,_0x230dcc){_0x230dcc=_0x230dcc||0xc8;return function(_0x2ae283){if(_0x2ae283){return _0x4c7140[_0xf864('0x19')](_0x230dcc)[_0xf864('0x1a')](_0x2ae283);}};}function respondWithFilteredResult(_0x3923dc,_0x1db9e8){return function(_0x1150b3){if(_0x1150b3){var _0x2c5ec7=typeof _0x1db9e8[_0xf864('0x1b')]===_0xf864('0x1c')&&typeof _0x1db9e8[_0xf864('0x1d')]===_0xf864('0x1c');var _0x508361=_0x1150b3[_0xf864('0x1e')];var _0x1c1955=_0x2c5ec7?0x0:_0x1db9e8[_0xf864('0x1b')];var _0x24fb19=_0x2c5ec7?_0x1150b3[_0xf864('0x1e')]:_0x1db9e8[_0xf864('0x1b')]+_0x1db9e8[_0xf864('0x1d')];var _0x37b076;if(_0x24fb19>=_0x508361){_0x24fb19=_0x508361;_0x37b076=0xc8;}else{_0x37b076=0xce;}_0x3923dc[_0xf864('0x19')](_0x37b076);return _0x3923dc[_0xf864('0x1f')](_0xf864('0x20'),_0x1c1955+'-'+_0x24fb19+'/'+_0x508361)[_0xf864('0x1a')](_0x1150b3);}return null;};}function patchUpdates(_0x53c361){return function(_0x4ff75b){try{jsonpatch['apply'](_0x4ff75b,_0x53c361,!![]);}catch(_0x5a6c9a){return BPromise['reject'](_0x5a6c9a);}return _0x4ff75b[_0xf864('0x21')]();};}function saveUpdates(_0x5163f4,_0x583d80){return function(_0x35f5c5){if(_0x35f5c5){return _0x35f5c5[_0xf864('0x22')](_0x5163f4)['then'](function(_0x5500c4){return _0x5500c4;});}return null;};}function removeEntity(_0x2e972b,_0x1df2ad){return function(_0x3ef33d){if(_0x3ef33d){return _0x3ef33d['destroy']()[_0xf864('0x23')](function(){_0x2e972b[_0xf864('0x19')](0xcc)[_0xf864('0x24')]();});}};}function handleEntityNotFound(_0xc5ec46,_0x38a274){return function(_0x4f0864){if(!_0x4f0864){_0xc5ec46['sendStatus'](0x194);}return _0x4f0864;};}function handleError(_0x2ecb8d,_0x5a7501){_0x5a7501=_0x5a7501||0x1f4;return function(_0x7d75e0){logger[_0xf864('0x25')](_0x7d75e0[_0xf864('0x26')]);if(_0x7d75e0[_0xf864('0x27')]){delete _0x7d75e0[_0xf864('0x27')];}_0x2ecb8d[_0xf864('0x19')](_0x5a7501)[_0xf864('0x28')](_0x7d75e0);};}exports[_0xf864('0x29')]=function(_0x82b790,_0x251230){var _0x52e507={},_0x251cc6={},_0x315888={'count':0x0,'rows':[]};var _0x19d00f=_[_0xf864('0x2a')](db[_0xf864('0x2b')][_0xf864('0x2c')],function(_0x2e2984){return{'name':_0x2e2984[_0xf864('0x2d')],'type':_0x2e2984[_0xf864('0x2e')][_0xf864('0x2f')]};});_0x251cc6[_0xf864('0x30')]=_[_0xf864('0x2a')](_0x19d00f,'name');_0x251cc6['query']=_['keys'](_0x82b790['query']);_0x251cc6[_0xf864('0x31')]=_[_0xf864('0x32')](_0x251cc6[_0xf864('0x30')],_0x251cc6[_0xf864('0x33')]);_0x52e507['attributes']=_[_0xf864('0x32')](_0x251cc6[_0xf864('0x30')],qs['fields'](_0x82b790['query']['fields']));_0x52e507[_0xf864('0x34')]=_0x52e507[_0xf864('0x34')][_0xf864('0x35')]?_0x52e507[_0xf864('0x34')]:_0x251cc6['model'];if(!_0x82b790[_0xf864('0x33')]['hasOwnProperty']('nolimit')){_0x52e507[_0xf864('0x1d')]=qs['limit'](_0x82b790[_0xf864('0x33')][_0xf864('0x1d')]);_0x52e507['offset']=qs[_0xf864('0x1b')](_0x82b790[_0xf864('0x33')][_0xf864('0x1b')]);}_0x52e507[_0xf864('0x36')]=qs[_0xf864('0x37')](_0x82b790[_0xf864('0x33')]['sort']);_0x52e507[_0xf864('0x38')]=qs[_0xf864('0x31')](_[_0xf864('0x39')](_0x82b790[_0xf864('0x33')],_0x251cc6['filters']),_0x19d00f);if(_0x82b790['query']['filter']){_0x52e507[_0xf864('0x38')]=_[_0xf864('0x3a')](_0x52e507[_0xf864('0x38')],{'$or':_['map'](_0x19d00f,function(_0x4e9e3e){if(_0x4e9e3e[_0xf864('0x2e')]!=='VIRTUAL'){var _0x405ee2={};_0x405ee2[_0x4e9e3e[_0xf864('0x27')]]={'$like':'%'+_0x82b790['query'][_0xf864('0x3b')]+'%'};return _0x405ee2;}})});}_0x52e507=_['merge']({},_0x52e507,_0x82b790[_0xf864('0x3c')]);var _0x352152={'where':_0x52e507['where']};return db[_0xf864('0x2b')][_0xf864('0x1e')](_0x352152)[_0xf864('0x23')](function(_0x4b9e1b){_0x315888[_0xf864('0x1e')]=_0x4b9e1b;if(_0x82b790[_0xf864('0x33')][_0xf864('0x3d')]){_0x52e507['include']=[{'all':!![]}];}return db['OpenchannelTransferReport']['findAll'](_0x52e507);})['then'](function(_0x4ad9e6){_0x315888[_0xf864('0x3e')]=_0x4ad9e6;return _0x315888;})[_0xf864('0x23')](respondWithFilteredResult(_0x251230,_0x52e507))['catch'](handleError(_0x251230,null));};exports[_0xf864('0x3f')]=function(_0x37215e,_0x44cbfc){var _0x2af4ad={'raw':!![],'where':{'id':_0x37215e[_0xf864('0x40')]['id']}},_0x529a62={};_0x529a62[_0xf864('0x30')]=_[_0xf864('0x41')](db[_0xf864('0x2b')][_0xf864('0x2c')]);_0x529a62[_0xf864('0x33')]=_[_0xf864('0x41')](_0x37215e[_0xf864('0x33')]);_0x529a62[_0xf864('0x31')]=_['intersection'](_0x529a62['model'],_0x529a62[_0xf864('0x33')]);_0x2af4ad['attributes']=_[_0xf864('0x32')](_0x529a62['model'],qs[_0xf864('0x42')](_0x37215e[_0xf864('0x33')][_0xf864('0x42')]));_0x2af4ad[_0xf864('0x34')]=_0x2af4ad[_0xf864('0x34')][_0xf864('0x35')]?_0x2af4ad[_0xf864('0x34')]:_0x529a62[_0xf864('0x30')];if(_0x37215e[_0xf864('0x33')][_0xf864('0x3d')]){_0x2af4ad[_0xf864('0x43')]=[{'all':!![]}];}_0x2af4ad=_[_0xf864('0x3a')]({},_0x2af4ad,_0x37215e[_0xf864('0x3c')]);return db[_0xf864('0x2b')][_0xf864('0x44')](_0x2af4ad)[_0xf864('0x23')](handleEntityNotFound(_0x44cbfc,null))['then'](respondWithResult(_0x44cbfc,null))['catch'](handleError(_0x44cbfc,null));};exports[_0xf864('0x45')]=function(_0x5f4c80,_0x4ccba6){return db['OpenchannelTransferReport']['create'](_0x5f4c80[_0xf864('0x46')],{})[_0xf864('0x23')](respondWithResult(_0x4ccba6,0xc9))['catch'](handleError(_0x4ccba6,null));};exports[_0xf864('0x22')]=function(_0x330c1a,_0x1c84c6){if(_0x330c1a[_0xf864('0x46')]['id']){delete _0x330c1a[_0xf864('0x46')]['id'];}return db['OpenchannelTransferReport']['find']({'where':{'id':_0x330c1a[_0xf864('0x40')]['id']}})[_0xf864('0x23')](handleEntityNotFound(_0x1c84c6,null))['then'](saveUpdates(_0x330c1a[_0xf864('0x46')],null))['then'](respondWithResult(_0x1c84c6,null))[_0xf864('0x47')](handleError(_0x1c84c6,null));};exports['destroy']=function(_0x83acc8,_0x2717b0){return db['OpenchannelTransferReport'][_0xf864('0x44')]({'where':{'id':_0x83acc8[_0xf864('0x40')]['id']}})[_0xf864('0x23')](handleEntityNotFound(_0x2717b0,null))[_0xf864('0x23')](removeEntity(_0x2717b0,null))[_0xf864('0x47')](handleError(_0x2717b0,null));};exports[_0xf864('0x48')]=function(_0x138e0f,_0x3e11e2){return db['OpenchannelTransferReport'][_0xf864('0x48')]()[_0xf864('0x23')](respondWithResult(_0x3e11e2,null))['catch'](handleError(_0x3e11e2,null));};