e71bb3ad9d2f75421f427ed9a664b8f470c94a4d
[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 _0xb6fb=['nolimit','order','sort','where','merge','VIRTUAL','filter','options','OpenchannelTransferReport','includeAll','include','rows','catch','params','find','create','body','destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','sendStatus','end','status','offset','limit','count','Content-Range','json','apply','reject','save','update','then','error','stack','name','map','rawAttributes','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty'];(function(_0x5bbaac,_0x34a7f1){var _0x454b28=function(_0x1bd500){while(--_0x1bd500){_0x5bbaac['push'](_0x5bbaac['shift']());}};_0x454b28(++_0x34a7f1);}(_0xb6fb,0x1c3));var _0xbb6f=function(_0x4a339c,_0x1230f9){_0x4a339c=_0x4a339c-0x0;var _0x3f4953=_0xb6fb[_0x4a339c];return _0x3f4953;};'use strict';var emlformat=require(_0xbb6f('0x0'));var rimraf=require(_0xbb6f('0x1'));var zipdir=require(_0xbb6f('0x2'));var jsonpatch=require(_0xbb6f('0x3'));var rp=require(_0xbb6f('0x4'));var moment=require(_0xbb6f('0x5'));var BPromise=require(_0xbb6f('0x6'));var Mustache=require(_0xbb6f('0x7'));var util=require(_0xbb6f('0x8'));var path=require(_0xbb6f('0x9'));var sox=require('sox');var csv=require(_0xbb6f('0xa'));var ejs=require(_0xbb6f('0xb'));var fs=require('fs');var fs_extra=require(_0xbb6f('0xc'));var _=require(_0xbb6f('0xd'));var squel=require('squel');var crypto=require(_0xbb6f('0xe'));var jsforce=require(_0xbb6f('0xf'));var deskjs=require(_0xbb6f('0x10'));var toCsv=require('to-csv');var querystring=require(_0xbb6f('0x11'));var Papa=require(_0xbb6f('0x12'));var Redis=require(_0xbb6f('0x13'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xbb6f('0x14'));var hardwareService=require(_0xbb6f('0x15'));var logger=require(_0xbb6f('0x16'))('api');var utils=require(_0xbb6f('0x17'));var config=require(_0xbb6f('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x53a859,_0x36ca14){_0x36ca14=_0x36ca14||0xcc;return function(_0x227f09){if(_0x227f09){return _0x53a859[_0xbb6f('0x19')](_0x36ca14);}return _0x53a859['status'](_0x36ca14)[_0xbb6f('0x1a')]();};}function respondWithResult(_0x2a2844,_0x4e1493){_0x4e1493=_0x4e1493||0xc8;return function(_0x28e218){if(_0x28e218){return _0x2a2844[_0xbb6f('0x1b')](_0x4e1493)['json'](_0x28e218);}};}function respondWithFilteredResult(_0x5f5a2e,_0x4712e8){return function(_0x5b68f2){if(_0x5b68f2){var _0x5f57c4=typeof _0x4712e8[_0xbb6f('0x1c')]==='undefined'&&typeof _0x4712e8[_0xbb6f('0x1d')]==='undefined';var _0x36ec30=_0x5b68f2[_0xbb6f('0x1e')];var _0x5eece1=_0x5f57c4?0x0:_0x4712e8[_0xbb6f('0x1c')];var _0x1727cb=_0x5f57c4?_0x5b68f2['count']:_0x4712e8[_0xbb6f('0x1c')]+_0x4712e8[_0xbb6f('0x1d')];var _0x192455;if(_0x1727cb>=_0x36ec30){_0x1727cb=_0x36ec30;_0x192455=0xc8;}else{_0x192455=0xce;}_0x5f5a2e[_0xbb6f('0x1b')](_0x192455);return _0x5f5a2e['set'](_0xbb6f('0x1f'),_0x5eece1+'-'+_0x1727cb+'/'+_0x36ec30)[_0xbb6f('0x20')](_0x5b68f2);}return null;};}function patchUpdates(_0x4f5188){return function(_0x483dd1){try{jsonpatch[_0xbb6f('0x21')](_0x483dd1,_0x4f5188,!![]);}catch(_0x5beace){return BPromise[_0xbb6f('0x22')](_0x5beace);}return _0x483dd1[_0xbb6f('0x23')]();};}function saveUpdates(_0x878184,_0x40eb4d){return function(_0x161c9a){if(_0x161c9a){return _0x161c9a[_0xbb6f('0x24')](_0x878184)[_0xbb6f('0x25')](function(_0x87c06b){return _0x87c06b;});}return null;};}function removeEntity(_0x1f164a,_0x212aba){return function(_0x1ea76c){if(_0x1ea76c){return _0x1ea76c['destroy']()[_0xbb6f('0x25')](function(){_0x1f164a['status'](0xcc)[_0xbb6f('0x1a')]();});}};}function handleEntityNotFound(_0x40feac,_0x4cfad5){return function(_0x1cd672){if(!_0x1cd672){_0x40feac[_0xbb6f('0x19')](0x194);}return _0x1cd672;};}function handleError(_0x3b9244,_0x5840e9){_0x5840e9=_0x5840e9||0x1f4;return function(_0x5040c0){logger[_0xbb6f('0x26')](_0x5040c0[_0xbb6f('0x27')]);if(_0x5040c0[_0xbb6f('0x28')]){delete _0x5040c0[_0xbb6f('0x28')];}_0x3b9244[_0xbb6f('0x1b')](_0x5840e9)['send'](_0x5040c0);};}exports['index']=function(_0xf968c5,_0x466dda){var _0x750983={},_0x31285c={},_0x346b42={'count':0x0,'rows':[]};var _0x5e6531=_[_0xbb6f('0x29')](db['OpenchannelTransferReport'][_0xbb6f('0x2a')],function(_0x35011f){return{'name':_0x35011f['fieldName'],'type':_0x35011f[_0xbb6f('0x2b')]['key']};});_0x31285c[_0xbb6f('0x2c')]=_[_0xbb6f('0x29')](_0x5e6531,_0xbb6f('0x28'));_0x31285c[_0xbb6f('0x2d')]=_[_0xbb6f('0x2e')](_0xf968c5[_0xbb6f('0x2d')]);_0x31285c[_0xbb6f('0x2f')]=_['intersection'](_0x31285c[_0xbb6f('0x2c')],_0x31285c['query']);_0x750983['attributes']=_[_0xbb6f('0x30')](_0x31285c[_0xbb6f('0x2c')],qs[_0xbb6f('0x31')](_0xf968c5['query'][_0xbb6f('0x31')]));_0x750983[_0xbb6f('0x32')]=_0x750983[_0xbb6f('0x32')][_0xbb6f('0x33')]?_0x750983[_0xbb6f('0x32')]:_0x31285c[_0xbb6f('0x2c')];if(!_0xf968c5[_0xbb6f('0x2d')][_0xbb6f('0x34')](_0xbb6f('0x35'))){_0x750983[_0xbb6f('0x1d')]=qs[_0xbb6f('0x1d')](_0xf968c5['query'][_0xbb6f('0x1d')]);_0x750983['offset']=qs[_0xbb6f('0x1c')](_0xf968c5['query'][_0xbb6f('0x1c')]);}_0x750983[_0xbb6f('0x36')]=qs[_0xbb6f('0x37')](_0xf968c5[_0xbb6f('0x2d')][_0xbb6f('0x37')]);_0x750983['where']=qs[_0xbb6f('0x2f')](_['pick'](_0xf968c5[_0xbb6f('0x2d')],_0x31285c[_0xbb6f('0x2f')]),_0x5e6531);if(_0xf968c5[_0xbb6f('0x2d')]['filter']){_0x750983[_0xbb6f('0x38')]=_[_0xbb6f('0x39')](_0x750983[_0xbb6f('0x38')],{'$or':_[_0xbb6f('0x29')](_0x5e6531,function(_0x2c29df){if(_0x2c29df['type']!==_0xbb6f('0x3a')){var _0x5d7342={};_0x5d7342[_0x2c29df['name']]={'$like':'%'+_0xf968c5[_0xbb6f('0x2d')][_0xbb6f('0x3b')]+'%'};return _0x5d7342;}})});}_0x750983=_[_0xbb6f('0x39')]({},_0x750983,_0xf968c5[_0xbb6f('0x3c')]);var _0x3b3044={'where':_0x750983[_0xbb6f('0x38')]};return db[_0xbb6f('0x3d')][_0xbb6f('0x1e')](_0x3b3044)['then'](function(_0x2ef772){_0x346b42[_0xbb6f('0x1e')]=_0x2ef772;if(_0xf968c5[_0xbb6f('0x2d')][_0xbb6f('0x3e')]){_0x750983[_0xbb6f('0x3f')]=[{'all':!![]}];}return db[_0xbb6f('0x3d')]['findAll'](_0x750983);})['then'](function(_0x586e34){_0x346b42[_0xbb6f('0x40')]=_0x586e34;return _0x346b42;})[_0xbb6f('0x25')](respondWithFilteredResult(_0x466dda,_0x750983))[_0xbb6f('0x41')](handleError(_0x466dda,null));};exports['show']=function(_0x2f46dc,_0x479281){var _0x187fb0={'raw':!![],'where':{'id':_0x2f46dc[_0xbb6f('0x42')]['id']}},_0x4e11d8={};_0x4e11d8['model']=_[_0xbb6f('0x2e')](db[_0xbb6f('0x3d')][_0xbb6f('0x2a')]);_0x4e11d8[_0xbb6f('0x2d')]=_[_0xbb6f('0x2e')](_0x2f46dc['query']);_0x4e11d8[_0xbb6f('0x2f')]=_['intersection'](_0x4e11d8[_0xbb6f('0x2c')],_0x4e11d8[_0xbb6f('0x2d')]);_0x187fb0[_0xbb6f('0x32')]=_['intersection'](_0x4e11d8['model'],qs['fields'](_0x2f46dc[_0xbb6f('0x2d')][_0xbb6f('0x31')]));_0x187fb0[_0xbb6f('0x32')]=_0x187fb0[_0xbb6f('0x32')]['length']?_0x187fb0[_0xbb6f('0x32')]:_0x4e11d8[_0xbb6f('0x2c')];if(_0x2f46dc['query'][_0xbb6f('0x3e')]){_0x187fb0[_0xbb6f('0x3f')]=[{'all':!![]}];}_0x187fb0=_[_0xbb6f('0x39')]({},_0x187fb0,_0x2f46dc['options']);return db['OpenchannelTransferReport'][_0xbb6f('0x43')](_0x187fb0)[_0xbb6f('0x25')](handleEntityNotFound(_0x479281,null))[_0xbb6f('0x25')](respondWithResult(_0x479281,null))['catch'](handleError(_0x479281,null));};exports[_0xbb6f('0x44')]=function(_0x15c407,_0x26bc7c){return db[_0xbb6f('0x3d')][_0xbb6f('0x44')](_0x15c407['body'],{})[_0xbb6f('0x25')](respondWithResult(_0x26bc7c,0xc9))[_0xbb6f('0x41')](handleError(_0x26bc7c,null));};exports[_0xbb6f('0x24')]=function(_0x29c358,_0x587e3d){if(_0x29c358[_0xbb6f('0x45')]['id']){delete _0x29c358[_0xbb6f('0x45')]['id'];}return db[_0xbb6f('0x3d')]['find']({'where':{'id':_0x29c358[_0xbb6f('0x42')]['id']}})[_0xbb6f('0x25')](handleEntityNotFound(_0x587e3d,null))[_0xbb6f('0x25')](saveUpdates(_0x29c358[_0xbb6f('0x45')],null))['then'](respondWithResult(_0x587e3d,null))[_0xbb6f('0x41')](handleError(_0x587e3d,null));};exports[_0xbb6f('0x46')]=function(_0x388bd4,_0x2162be){return db['OpenchannelTransferReport']['find']({'where':{'id':_0x388bd4[_0xbb6f('0x42')]['id']}})[_0xbb6f('0x25')](handleEntityNotFound(_0x2162be,null))[_0xbb6f('0x25')](removeEntity(_0x2162be,null))[_0xbb6f('0x41')](handleError(_0x2162be,null));};exports[_0xbb6f('0x47')]=function(_0x921d24,_0x2adda9){return db[_0xbb6f('0x3d')]['describe']()['then'](respondWithResult(_0x2adda9,null))[_0xbb6f('0x41')](handleError(_0x2adda9,null));};