d051171f42e7e78e0ff664da9a2c58a51031e365
[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 _0xf143=['catch','show','params','length','find','create','update','body','describe','html-pdf','eml-format','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','reject','save','then','destroy','error','stack','name','send','map','OpenchannelTransferReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','filter','merge','includeAll','include','findAll','rows'];(function(_0x59c301,_0x359c50){var _0x3866b9=function(_0x2d380e){while(--_0x2d380e){_0x59c301['push'](_0x59c301['shift']());}};_0x3866b9(++_0x359c50);}(_0xf143,0xe7));var _0x3f14=function(_0x1fddd6,_0x35c1c8){_0x1fddd6=_0x1fddd6-0x0;var _0xdd2ba2=_0xf143[_0x1fddd6];return _0xdd2ba2;};'use strict';var pdf=require(_0x3f14('0x0'));var emlformat=require(_0x3f14('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x3f14('0x2'));var rp=require('request-promise');var moment=require(_0x3f14('0x3'));var BPromise=require(_0x3f14('0x4'));var Mustache=require(_0x3f14('0x5'));var util=require(_0x3f14('0x6'));var path=require(_0x3f14('0x7'));var sox=require(_0x3f14('0x8'));var csv=require(_0x3f14('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x3f14('0xa'));var jsforce=require(_0x3f14('0xb'));var deskjs=require(_0x3f14('0xc'));var toCsv=require('to-csv');var querystring=require(_0x3f14('0xd'));var Papa=require(_0x3f14('0xe'));var Redis=require(_0x3f14('0xf'));var authService=require(_0x3f14('0x10'));var qs=require(_0x3f14('0x11'));var as=require(_0x3f14('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x3f14('0x13'))(_0x3f14('0x14'));var utils=require('../../config/utils');var config=require(_0x3f14('0x15'));var licenseUtil=require(_0x3f14('0x16'));var db=require(_0x3f14('0x17'))['db'];function respondWithStatusCode(_0x2112ce,_0x5f5db3){_0x5f5db3=_0x5f5db3||0xcc;return function(_0x1e9514){if(_0x1e9514){return _0x2112ce[_0x3f14('0x18')](_0x5f5db3);}return _0x2112ce[_0x3f14('0x19')](_0x5f5db3)[_0x3f14('0x1a')]();};}function respondWithResult(_0x4c4a1c,_0xfa4c2){_0xfa4c2=_0xfa4c2||0xc8;return function(_0x4ea7c9){if(_0x4ea7c9){return _0x4c4a1c[_0x3f14('0x19')](_0xfa4c2)['json'](_0x4ea7c9);}};}function respondWithFilteredResult(_0x3077d7,_0x2d0a20){return function(_0x5eeb18){if(_0x5eeb18){var _0x3d0a26=_0x5eeb18[_0x3f14('0x1b')],_0x386c4b=_0x2d0a20[_0x3f14('0x1c')],_0x248a4f=_0x2d0a20[_0x3f14('0x1c')]+_0x2d0a20[_0x3f14('0x1d')],_0xa21c98;if(_0x248a4f>=_0x3d0a26){_0x248a4f=_0x3d0a26;_0xa21c98=0xc8;}else{_0xa21c98=0xce;}_0x3077d7[_0x3f14('0x19')](_0xa21c98);return _0x3077d7[_0x3f14('0x1e')](_0x3f14('0x1f'),_0x386c4b+'-'+_0x248a4f+'/'+_0x3d0a26)[_0x3f14('0x20')](_0x5eeb18);}return null;};}function patchUpdates(_0x11141f){return function(_0x533dc1){try{jsonpatch[_0x3f14('0x21')](_0x533dc1,_0x11141f,!![]);}catch(_0x1d73d8){return BPromise[_0x3f14('0x22')](_0x1d73d8);}return _0x533dc1[_0x3f14('0x23')]();};}function saveUpdates(_0x176ce7,_0x13f62c){return function(_0x5e7c0b){if(_0x5e7c0b){return _0x5e7c0b['update'](_0x176ce7)[_0x3f14('0x24')](function(_0xce9888){return _0xce9888;});}return null;};}function removeEntity(_0x56fcb5,_0x277b02){return function(_0xed201a){if(_0xed201a){return _0xed201a[_0x3f14('0x25')]()[_0x3f14('0x24')](function(){_0x56fcb5[_0x3f14('0x19')](0xcc)[_0x3f14('0x1a')]();});}};}function handleEntityNotFound(_0x9f389,_0x3ba1c5){return function(_0x4c960b){if(!_0x4c960b){_0x9f389[_0x3f14('0x18')](0x194);}return _0x4c960b;};}function handleError(_0x2141fb,_0x2182e8){_0x2182e8=_0x2182e8||0x1f4;return function(_0x332606){logger[_0x3f14('0x26')](_0x332606[_0x3f14('0x27')]);if(_0x332606[_0x3f14('0x28')]){delete _0x332606[_0x3f14('0x28')];}_0x2141fb['status'](_0x2182e8)[_0x3f14('0x29')](_0x332606);};}exports['index']=function(_0x5a591d,_0x4157b6){var _0x5dc062={},_0x527345={},_0x19088d={'count':0x0,'rows':[]};var _0x59ecab=_[_0x3f14('0x2a')](db[_0x3f14('0x2b')][_0x3f14('0x2c')],function(_0x5d4abf){return{'name':_0x5d4abf[_0x3f14('0x2d')],'type':_0x5d4abf[_0x3f14('0x2e')][_0x3f14('0x2f')]};});_0x527345[_0x3f14('0x30')]=_['map'](_0x59ecab,'name');_0x527345[_0x3f14('0x31')]=_[_0x3f14('0x32')](_0x5a591d[_0x3f14('0x31')]);_0x527345[_0x3f14('0x33')]=_[_0x3f14('0x34')](_0x527345[_0x3f14('0x30')],_0x527345[_0x3f14('0x31')]);_0x5dc062[_0x3f14('0x35')]=_[_0x3f14('0x34')](_0x527345['model'],qs['fields'](_0x5a591d[_0x3f14('0x31')][_0x3f14('0x36')]));_0x5dc062[_0x3f14('0x35')]=_0x5dc062[_0x3f14('0x35')]['length']?_0x5dc062[_0x3f14('0x35')]:_0x527345['model'];if(!_0x5a591d['query'][_0x3f14('0x37')]('nolimit')){_0x5dc062[_0x3f14('0x1d')]=qs[_0x3f14('0x1d')](_0x5a591d['query'][_0x3f14('0x1d')]);_0x5dc062[_0x3f14('0x1c')]=qs['offset'](_0x5a591d[_0x3f14('0x31')]['offset']);}_0x5dc062[_0x3f14('0x38')]=qs[_0x3f14('0x39')](_0x5a591d[_0x3f14('0x31')][_0x3f14('0x39')]);_0x5dc062[_0x3f14('0x3a')]=qs[_0x3f14('0x33')](_['pick'](_0x5a591d[_0x3f14('0x31')],_0x527345[_0x3f14('0x33')]),_0x59ecab);if(_0x5a591d[_0x3f14('0x31')][_0x3f14('0x3b')]){_0x5dc062['where']=_[_0x3f14('0x3c')](_0x5dc062[_0x3f14('0x3a')],{'$or':_['map'](_0x59ecab,function(_0x53fc85){if(_0x53fc85[_0x3f14('0x2e')]!=='VIRTUAL'){var _0x20039={};_0x20039[_0x53fc85[_0x3f14('0x28')]]={'$like':'%'+_0x5a591d[_0x3f14('0x31')][_0x3f14('0x3b')]+'%'};return _0x20039;}})});}_0x5dc062=_[_0x3f14('0x3c')]({},_0x5dc062,_0x5a591d['options']);var _0x5851ad={'where':_0x5dc062[_0x3f14('0x3a')]};return db[_0x3f14('0x2b')][_0x3f14('0x1b')](_0x5851ad)[_0x3f14('0x24')](function(_0xc37608){_0x19088d[_0x3f14('0x1b')]=_0xc37608;if(_0x5a591d[_0x3f14('0x31')][_0x3f14('0x3d')]){_0x5dc062[_0x3f14('0x3e')]=[{'all':!![]}];}return db[_0x3f14('0x2b')][_0x3f14('0x3f')](_0x5dc062);})[_0x3f14('0x24')](function(_0x544560){_0x19088d[_0x3f14('0x40')]=_0x544560;return _0x19088d;})[_0x3f14('0x24')](respondWithFilteredResult(_0x4157b6,_0x5dc062))[_0x3f14('0x41')](handleError(_0x4157b6,null));};exports[_0x3f14('0x42')]=function(_0x480813,_0x333b0d){var _0x121711={'raw':!![],'where':{'id':_0x480813[_0x3f14('0x43')]['id']}},_0x4eedd1={};_0x4eedd1[_0x3f14('0x30')]=_[_0x3f14('0x32')](db['OpenchannelTransferReport'][_0x3f14('0x2c')]);_0x4eedd1[_0x3f14('0x31')]=_[_0x3f14('0x32')](_0x480813[_0x3f14('0x31')]);_0x4eedd1[_0x3f14('0x33')]=_[_0x3f14('0x34')](_0x4eedd1['model'],_0x4eedd1[_0x3f14('0x31')]);_0x121711[_0x3f14('0x35')]=_['intersection'](_0x4eedd1['model'],qs['fields'](_0x480813[_0x3f14('0x31')]['fields']));_0x121711[_0x3f14('0x35')]=_0x121711[_0x3f14('0x35')][_0x3f14('0x44')]?_0x121711[_0x3f14('0x35')]:_0x4eedd1[_0x3f14('0x30')];if(_0x480813[_0x3f14('0x31')][_0x3f14('0x3d')]){_0x121711[_0x3f14('0x3e')]=[{'all':!![]}];}_0x121711=_[_0x3f14('0x3c')]({},_0x121711,_0x480813['options']);return db[_0x3f14('0x2b')][_0x3f14('0x45')](_0x121711)['then'](handleEntityNotFound(_0x333b0d,null))[_0x3f14('0x24')](respondWithResult(_0x333b0d,null))[_0x3f14('0x41')](handleError(_0x333b0d,null));};exports[_0x3f14('0x46')]=function(_0x244b5f,_0x357c5c){return db[_0x3f14('0x2b')]['create'](_0x244b5f['body'],{})[_0x3f14('0x24')](respondWithResult(_0x357c5c,0xc9))[_0x3f14('0x41')](handleError(_0x357c5c,null));};exports[_0x3f14('0x47')]=function(_0x24925a,_0x3558d5){if(_0x24925a[_0x3f14('0x48')]['id']){delete _0x24925a[_0x3f14('0x48')]['id'];}return db['OpenchannelTransferReport'][_0x3f14('0x45')]({'where':{'id':_0x24925a[_0x3f14('0x43')]['id']}})[_0x3f14('0x24')](handleEntityNotFound(_0x3558d5,null))[_0x3f14('0x24')](saveUpdates(_0x24925a['body'],null))['then'](respondWithResult(_0x3558d5,null))[_0x3f14('0x41')](handleError(_0x3558d5,null));};exports[_0x3f14('0x25')]=function(_0x3fa09c,_0x1a490b){return db[_0x3f14('0x2b')][_0x3f14('0x45')]({'where':{'id':_0x3fa09c[_0x3f14('0x43')]['id']}})[_0x3f14('0x24')](handleEntityNotFound(_0x1a490b,null))[_0x3f14('0x24')](removeEntity(_0x1a490b,null))[_0x3f14('0x41')](handleError(_0x1a490b,null));};exports['describe']=function(_0x2e6130,_0x5f51bb){return db[_0x3f14('0x2b')][_0x3f14('0x49')]()[_0x3f14('0x24')](respondWithResult(_0x5f51bb,null))[_0x3f14('0x41')](handleError(_0x5f51bb,null));};