af6c265284122c454bfdfaa9edf3eee4a33258ba
[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 _0x4f57=['options','include','rows','catch','show','fields','includeAll','find','create','body','params','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','end','json','count','offset','status','Content-Range','apply','reject','save','update','then','destroy','sendStatus','stack','index','map','OpenchannelTransferReport','rawAttributes','fieldName','type','key','keys','query','intersection','model','attributes','length','hasOwnProperty','limit','order','sort','where','filters','filter','merge','VIRTUAL','name'];(function(_0x4e5046,_0x245c09){var _0x291904=function(_0x28d3e3){while(--_0x28d3e3){_0x4e5046['push'](_0x4e5046['shift']());}};_0x291904(++_0x245c09);}(_0x4f57,0x13c));var _0x74f5=function(_0x92eeb6,_0x574acf){_0x92eeb6=_0x92eeb6-0x0;var _0x38067d=_0x4f57[_0x92eeb6];return _0x38067d;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x74f5('0x0'));var rimraf=require(_0x74f5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x74f5('0x2'));var rp=require(_0x74f5('0x3'));var moment=require(_0x74f5('0x4'));var BPromise=require(_0x74f5('0x5'));var Mustache=require(_0x74f5('0x6'));var util=require(_0x74f5('0x7'));var path=require(_0x74f5('0x8'));var sox=require('sox');var csv=require(_0x74f5('0x9'));var ejs=require(_0x74f5('0xa'));var fs=require('fs');var _=require(_0x74f5('0xb'));var squel=require(_0x74f5('0xc'));var crypto=require(_0x74f5('0xd'));var jsforce=require(_0x74f5('0xe'));var deskjs=require(_0x74f5('0xf'));var toCsv=require(_0x74f5('0x9'));var querystring=require(_0x74f5('0x10'));var Papa=require(_0x74f5('0x11'));var Redis=require(_0x74f5('0x12'));var authService=require(_0x74f5('0x13'));var qs=require(_0x74f5('0x14'));var as=require(_0x74f5('0x15'));var hardwareService=require(_0x74f5('0x16'));var logger=require(_0x74f5('0x17'))(_0x74f5('0x18'));var utils=require(_0x74f5('0x19'));var config=require(_0x74f5('0x1a'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x31ab9a,_0xdfaec4){_0xdfaec4=_0xdfaec4||0xcc;return function(_0x5d669){if(_0x5d669){return _0x31ab9a['sendStatus'](_0xdfaec4);}return _0x31ab9a['status'](_0xdfaec4)[_0x74f5('0x1b')]();};}function respondWithResult(_0x3e359c,_0x24029e){_0x24029e=_0x24029e||0xc8;return function(_0x20e3d8){if(_0x20e3d8){return _0x3e359c['status'](_0x24029e)[_0x74f5('0x1c')](_0x20e3d8);}};}function respondWithFilteredResult(_0x34f92d,_0x434ce5){return function(_0x162092){if(_0x162092){var _0x1cb1b6=_0x162092[_0x74f5('0x1d')],_0x1743ac=_0x434ce5[_0x74f5('0x1e')],_0xa34a07=_0x434ce5['offset']+_0x434ce5['limit'],_0x391e5e;if(_0xa34a07>=_0x1cb1b6){_0xa34a07=_0x1cb1b6;_0x391e5e=0xc8;}else{_0x391e5e=0xce;}_0x34f92d[_0x74f5('0x1f')](_0x391e5e);return _0x34f92d['set'](_0x74f5('0x20'),_0x1743ac+'-'+_0xa34a07+'/'+_0x1cb1b6)[_0x74f5('0x1c')](_0x162092);}return null;};}function patchUpdates(_0x1b0b63){return function(_0x3707d3){try{jsonpatch[_0x74f5('0x21')](_0x3707d3,_0x1b0b63,!![]);}catch(_0xeaed4d){return BPromise[_0x74f5('0x22')](_0xeaed4d);}return _0x3707d3[_0x74f5('0x23')]();};}function saveUpdates(_0x482e36,_0x3c35e8){return function(_0x47e616){if(_0x47e616){return _0x47e616[_0x74f5('0x24')](_0x482e36)[_0x74f5('0x25')](function(_0x59e984){return _0x59e984;});}return null;};}function removeEntity(_0x4a64fb,_0x47866a){return function(_0x4fae1a){if(_0x4fae1a){return _0x4fae1a[_0x74f5('0x26')]()['then'](function(){_0x4a64fb[_0x74f5('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5d71a4,_0x2cc5bc){return function(_0x3bf2e5){if(!_0x3bf2e5){_0x5d71a4[_0x74f5('0x27')](0x194);}return _0x3bf2e5;};}function handleError(_0x40d530,_0x537b9d){_0x537b9d=_0x537b9d||0x1f4;return function(_0x4a1f66){logger['error'](_0x4a1f66[_0x74f5('0x28')]);if(_0x4a1f66['name']){delete _0x4a1f66['name'];}_0x40d530[_0x74f5('0x1f')](_0x537b9d)['send'](_0x4a1f66);};}exports[_0x74f5('0x29')]=function(_0x271beb,_0xca6354){var _0x5bb7a9={},_0x1063dc={},_0x1b6922={'count':0x0,'rows':[]};var _0x13e4ce=_[_0x74f5('0x2a')](db[_0x74f5('0x2b')][_0x74f5('0x2c')],function(_0xaa986d){return{'name':_0xaa986d[_0x74f5('0x2d')],'type':_0xaa986d[_0x74f5('0x2e')][_0x74f5('0x2f')]};});_0x1063dc['model']=_[_0x74f5('0x2a')](_0x13e4ce,'name');_0x1063dc['query']=_[_0x74f5('0x30')](_0x271beb[_0x74f5('0x31')]);_0x1063dc['filters']=_[_0x74f5('0x32')](_0x1063dc[_0x74f5('0x33')],_0x1063dc[_0x74f5('0x31')]);_0x5bb7a9['attributes']=_[_0x74f5('0x32')](_0x1063dc[_0x74f5('0x33')],qs['fields'](_0x271beb[_0x74f5('0x31')]['fields']));_0x5bb7a9['attributes']=_0x5bb7a9[_0x74f5('0x34')][_0x74f5('0x35')]?_0x5bb7a9[_0x74f5('0x34')]:_0x1063dc[_0x74f5('0x33')];if(!_0x271beb[_0x74f5('0x31')][_0x74f5('0x36')]('nolimit')){_0x5bb7a9[_0x74f5('0x37')]=qs[_0x74f5('0x37')](_0x271beb[_0x74f5('0x31')][_0x74f5('0x37')]);_0x5bb7a9[_0x74f5('0x1e')]=qs['offset'](_0x271beb[_0x74f5('0x31')][_0x74f5('0x1e')]);}_0x5bb7a9[_0x74f5('0x38')]=qs[_0x74f5('0x39')](_0x271beb[_0x74f5('0x31')][_0x74f5('0x39')]);_0x5bb7a9[_0x74f5('0x3a')]=qs[_0x74f5('0x3b')](_['pick'](_0x271beb[_0x74f5('0x31')],_0x1063dc['filters']),_0x13e4ce);if(_0x271beb[_0x74f5('0x31')][_0x74f5('0x3c')]){_0x5bb7a9[_0x74f5('0x3a')]=_[_0x74f5('0x3d')](_0x5bb7a9['where'],{'$or':_['map'](_0x13e4ce,function(_0x3e6409){if(_0x3e6409[_0x74f5('0x2e')]!==_0x74f5('0x3e')){var _0x46b9fa={};_0x46b9fa[_0x3e6409[_0x74f5('0x3f')]]={'$like':'%'+_0x271beb[_0x74f5('0x31')][_0x74f5('0x3c')]+'%'};return _0x46b9fa;}})});}_0x5bb7a9=_[_0x74f5('0x3d')]({},_0x5bb7a9,_0x271beb[_0x74f5('0x40')]);var _0x31e196={'where':_0x5bb7a9[_0x74f5('0x3a')]};return db[_0x74f5('0x2b')]['count'](_0x31e196)[_0x74f5('0x25')](function(_0x1313f1){_0x1b6922[_0x74f5('0x1d')]=_0x1313f1;if(_0x271beb[_0x74f5('0x31')]['includeAll']){_0x5bb7a9[_0x74f5('0x41')]=[{'all':!![]}];}return db[_0x74f5('0x2b')]['findAll'](_0x5bb7a9);})[_0x74f5('0x25')](function(_0x1f844e){_0x1b6922[_0x74f5('0x42')]=_0x1f844e;return _0x1b6922;})[_0x74f5('0x25')](respondWithFilteredResult(_0xca6354,_0x5bb7a9))[_0x74f5('0x43')](handleError(_0xca6354,null));};exports[_0x74f5('0x44')]=function(_0x3e2684,_0x5677d5){var _0x22bc9e={'raw':!![],'where':{'id':_0x3e2684['params']['id']}},_0x46f8c1={};_0x46f8c1[_0x74f5('0x33')]=_['keys'](db['OpenchannelTransferReport'][_0x74f5('0x2c')]);_0x46f8c1['query']=_[_0x74f5('0x30')](_0x3e2684[_0x74f5('0x31')]);_0x46f8c1[_0x74f5('0x3b')]=_[_0x74f5('0x32')](_0x46f8c1[_0x74f5('0x33')],_0x46f8c1[_0x74f5('0x31')]);_0x22bc9e[_0x74f5('0x34')]=_['intersection'](_0x46f8c1[_0x74f5('0x33')],qs[_0x74f5('0x45')](_0x3e2684['query'][_0x74f5('0x45')]));_0x22bc9e['attributes']=_0x22bc9e[_0x74f5('0x34')][_0x74f5('0x35')]?_0x22bc9e[_0x74f5('0x34')]:_0x46f8c1['model'];if(_0x3e2684[_0x74f5('0x31')][_0x74f5('0x46')]){_0x22bc9e[_0x74f5('0x41')]=[{'all':!![]}];}_0x22bc9e=_[_0x74f5('0x3d')]({},_0x22bc9e,_0x3e2684[_0x74f5('0x40')]);return db[_0x74f5('0x2b')][_0x74f5('0x47')](_0x22bc9e)[_0x74f5('0x25')](handleEntityNotFound(_0x5677d5,null))[_0x74f5('0x25')](respondWithResult(_0x5677d5,null))['catch'](handleError(_0x5677d5,null));};exports['create']=function(_0x505202,_0x3f44a7){return db[_0x74f5('0x2b')][_0x74f5('0x48')](_0x505202['body'],{})[_0x74f5('0x25')](respondWithResult(_0x3f44a7,0xc9))[_0x74f5('0x43')](handleError(_0x3f44a7,null));};exports[_0x74f5('0x24')]=function(_0x3f9186,_0x5689b1){if(_0x3f9186[_0x74f5('0x49')]['id']){delete _0x3f9186[_0x74f5('0x49')]['id'];}return db[_0x74f5('0x2b')]['find']({'where':{'id':_0x3f9186[_0x74f5('0x4a')]['id']}})[_0x74f5('0x25')](handleEntityNotFound(_0x5689b1,null))['then'](saveUpdates(_0x3f9186[_0x74f5('0x49')],null))[_0x74f5('0x25')](respondWithResult(_0x5689b1,null))[_0x74f5('0x43')](handleError(_0x5689b1,null));};exports[_0x74f5('0x26')]=function(_0x325fd7,_0x13b53a){return db[_0x74f5('0x2b')][_0x74f5('0x47')]({'where':{'id':_0x325fd7[_0x74f5('0x4a')]['id']}})[_0x74f5('0x25')](handleEntityNotFound(_0x13b53a,null))[_0x74f5('0x25')](removeEntity(_0x13b53a,null))[_0x74f5('0x43')](handleError(_0x13b53a,null));};exports[_0x74f5('0x4b')]=function(_0x14db8f,_0x4f0875){return db[_0x74f5('0x2b')][_0x74f5('0x4b')]()[_0x74f5('0x25')](respondWithResult(_0x4f0875,null))[_0x74f5('0x43')](handleError(_0x4f0875,null));};