04dfc6fc17b8cc9e3bec4688a75eada8a5ce9f05
[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 _0x93f4=['length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','rows','catch','show','params','find','create','body','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','api','../../config/environment','../../mysqldb','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','end','error','stack','name','send','index','map','OpenchannelTransferReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes'];(function(_0x30c3c2,_0x330cca){var _0x738110=function(_0x13891e){while(--_0x13891e){_0x30c3c2['push'](_0x30c3c2['shift']());}};_0x738110(++_0x330cca);}(_0x93f4,0x13a));var _0x493f=function(_0x4b8618,_0x3dcb39){_0x4b8618=_0x4b8618-0x0;var _0x3da94d=_0x93f4[_0x4b8618];return _0x3da94d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x493f('0x0'));var zipdir=require(_0x493f('0x1'));var jsonpatch=require(_0x493f('0x2'));var rp=require(_0x493f('0x3'));var moment=require(_0x493f('0x4'));var BPromise=require(_0x493f('0x5'));var Mustache=require(_0x493f('0x6'));var util=require('util');var path=require(_0x493f('0x7'));var sox=require('sox');var csv=require(_0x493f('0x8'));var ejs=require(_0x493f('0x9'));var fs=require('fs');var fs_extra=require(_0x493f('0xa'));var _=require(_0x493f('0xb'));var squel=require(_0x493f('0xc'));var crypto=require(_0x493f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x493f('0xe'));var toCsv=require('to-csv');var querystring=require(_0x493f('0xf'));var Papa=require(_0x493f('0x10'));var Redis=require('ioredis');var authService=require(_0x493f('0x11'));var qs=require(_0x493f('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x493f('0x13'));var utils=require('../../config/utils');var config=require(_0x493f('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x493f('0x15'))['db'];function respondWithStatusCode(_0x25eb44,_0x36aa24){_0x36aa24=_0x36aa24||0xcc;return function(_0x1e5126){if(_0x1e5126){return _0x25eb44[_0x493f('0x16')](_0x36aa24);}return _0x25eb44[_0x493f('0x17')](_0x36aa24)['end']();};}function respondWithResult(_0x54c788,_0x395ad4){_0x395ad4=_0x395ad4||0xc8;return function(_0x30496d){if(_0x30496d){return _0x54c788[_0x493f('0x17')](_0x395ad4)[_0x493f('0x18')](_0x30496d);}};}function respondWithFilteredResult(_0x419fb7,_0x55cd17){return function(_0x21dd33){if(_0x21dd33){var _0x1b034b=typeof _0x55cd17[_0x493f('0x19')]===_0x493f('0x1a')&&typeof _0x55cd17['limit']===_0x493f('0x1a');var _0x59f18a=_0x21dd33[_0x493f('0x1b')];var _0x4ecfc2=_0x1b034b?0x0:_0x55cd17[_0x493f('0x19')];var _0x1c6237=_0x1b034b?_0x21dd33[_0x493f('0x1b')]:_0x55cd17[_0x493f('0x19')]+_0x55cd17[_0x493f('0x1c')];var _0x362032;if(_0x1c6237>=_0x59f18a){_0x1c6237=_0x59f18a;_0x362032=0xc8;}else{_0x362032=0xce;}_0x419fb7['status'](_0x362032);return _0x419fb7[_0x493f('0x1d')](_0x493f('0x1e'),_0x4ecfc2+'-'+_0x1c6237+'/'+_0x59f18a)['json'](_0x21dd33);}return null;};}function patchUpdates(_0x3287b1){return function(_0x4d1c45){try{jsonpatch[_0x493f('0x1f')](_0x4d1c45,_0x3287b1,!![]);}catch(_0x50b9d6){return BPromise[_0x493f('0x20')](_0x50b9d6);}return _0x4d1c45[_0x493f('0x21')]();};}function saveUpdates(_0x2e209c,_0x27e467){return function(_0x20dc4f){if(_0x20dc4f){return _0x20dc4f[_0x493f('0x22')](_0x2e209c)[_0x493f('0x23')](function(_0x588ce5){return _0x588ce5;});}return null;};}function removeEntity(_0x24dcfd,_0x50952e){return function(_0x3674d5){if(_0x3674d5){return _0x3674d5[_0x493f('0x24')]()[_0x493f('0x23')](function(){_0x24dcfd[_0x493f('0x17')](0xcc)[_0x493f('0x25')]();});}};}function handleEntityNotFound(_0xe38ab7,_0x1b0827){return function(_0x583c57){if(!_0x583c57){_0xe38ab7[_0x493f('0x16')](0x194);}return _0x583c57;};}function handleError(_0x40eb1f,_0x106bfa){_0x106bfa=_0x106bfa||0x1f4;return function(_0x2e1c63){logger[_0x493f('0x26')](_0x2e1c63[_0x493f('0x27')]);if(_0x2e1c63[_0x493f('0x28')]){delete _0x2e1c63[_0x493f('0x28')];}_0x40eb1f['status'](_0x106bfa)[_0x493f('0x29')](_0x2e1c63);};}exports[_0x493f('0x2a')]=function(_0x2e43ea,_0x503d0f){var _0x24f3b2={},_0x15e0df={},_0x1e7373={'count':0x0,'rows':[]};var _0x1e2acd=_[_0x493f('0x2b')](db[_0x493f('0x2c')][_0x493f('0x2d')],function(_0x115653){return{'name':_0x115653[_0x493f('0x2e')],'type':_0x115653[_0x493f('0x2f')][_0x493f('0x30')]};});_0x15e0df[_0x493f('0x31')]=_[_0x493f('0x2b')](_0x1e2acd,_0x493f('0x28'));_0x15e0df[_0x493f('0x32')]=_[_0x493f('0x33')](_0x2e43ea[_0x493f('0x32')]);_0x15e0df[_0x493f('0x34')]=_[_0x493f('0x35')](_0x15e0df[_0x493f('0x31')],_0x15e0df[_0x493f('0x32')]);_0x24f3b2['attributes']=_[_0x493f('0x35')](_0x15e0df[_0x493f('0x31')],qs['fields'](_0x2e43ea[_0x493f('0x32')][_0x493f('0x36')]));_0x24f3b2[_0x493f('0x37')]=_0x24f3b2['attributes'][_0x493f('0x38')]?_0x24f3b2[_0x493f('0x37')]:_0x15e0df[_0x493f('0x31')];if(!_0x2e43ea[_0x493f('0x32')]['hasOwnProperty'](_0x493f('0x39'))){_0x24f3b2[_0x493f('0x1c')]=qs[_0x493f('0x1c')](_0x2e43ea[_0x493f('0x32')][_0x493f('0x1c')]);_0x24f3b2['offset']=qs['offset'](_0x2e43ea['query']['offset']);}_0x24f3b2[_0x493f('0x3a')]=qs[_0x493f('0x3b')](_0x2e43ea[_0x493f('0x32')][_0x493f('0x3b')]);_0x24f3b2[_0x493f('0x3c')]=qs['filters'](_[_0x493f('0x3d')](_0x2e43ea[_0x493f('0x32')],_0x15e0df[_0x493f('0x34')]),_0x1e2acd);if(_0x2e43ea[_0x493f('0x32')][_0x493f('0x3e')]){_0x24f3b2['where']=_[_0x493f('0x3f')](_0x24f3b2[_0x493f('0x3c')],{'$or':_[_0x493f('0x2b')](_0x1e2acd,function(_0x259659){if(_0x259659['type']!==_0x493f('0x40')){var _0x26fc11={};_0x26fc11[_0x259659['name']]={'$like':'%'+_0x2e43ea[_0x493f('0x32')][_0x493f('0x3e')]+'%'};return _0x26fc11;}})});}_0x24f3b2=_[_0x493f('0x3f')]({},_0x24f3b2,_0x2e43ea['options']);var _0x2c5ede={'where':_0x24f3b2['where']};return db['OpenchannelTransferReport'][_0x493f('0x1b')](_0x2c5ede)[_0x493f('0x23')](function(_0x2434d4){_0x1e7373[_0x493f('0x1b')]=_0x2434d4;if(_0x2e43ea[_0x493f('0x32')][_0x493f('0x41')]){_0x24f3b2[_0x493f('0x42')]=[{'all':!![]}];}return db[_0x493f('0x2c')]['findAll'](_0x24f3b2);})['then'](function(_0x35da64){_0x1e7373[_0x493f('0x43')]=_0x35da64;return _0x1e7373;})[_0x493f('0x23')](respondWithFilteredResult(_0x503d0f,_0x24f3b2))[_0x493f('0x44')](handleError(_0x503d0f,null));};exports[_0x493f('0x45')]=function(_0x51de80,_0x5a7c02){var _0x20ac8c={'raw':!![],'where':{'id':_0x51de80[_0x493f('0x46')]['id']}},_0x275fa0={};_0x275fa0['model']=_[_0x493f('0x33')](db[_0x493f('0x2c')][_0x493f('0x2d')]);_0x275fa0[_0x493f('0x32')]=_[_0x493f('0x33')](_0x51de80[_0x493f('0x32')]);_0x275fa0[_0x493f('0x34')]=_[_0x493f('0x35')](_0x275fa0[_0x493f('0x31')],_0x275fa0[_0x493f('0x32')]);_0x20ac8c[_0x493f('0x37')]=_[_0x493f('0x35')](_0x275fa0[_0x493f('0x31')],qs[_0x493f('0x36')](_0x51de80[_0x493f('0x32')]['fields']));_0x20ac8c[_0x493f('0x37')]=_0x20ac8c[_0x493f('0x37')]['length']?_0x20ac8c['attributes']:_0x275fa0[_0x493f('0x31')];if(_0x51de80['query'][_0x493f('0x41')]){_0x20ac8c[_0x493f('0x42')]=[{'all':!![]}];}_0x20ac8c=_[_0x493f('0x3f')]({},_0x20ac8c,_0x51de80['options']);return db[_0x493f('0x2c')][_0x493f('0x47')](_0x20ac8c)[_0x493f('0x23')](handleEntityNotFound(_0x5a7c02,null))[_0x493f('0x23')](respondWithResult(_0x5a7c02,null))[_0x493f('0x44')](handleError(_0x5a7c02,null));};exports[_0x493f('0x48')]=function(_0x4ff974,_0x43c772){return db[_0x493f('0x2c')][_0x493f('0x48')](_0x4ff974['body'],{})[_0x493f('0x23')](respondWithResult(_0x43c772,0xc9))[_0x493f('0x44')](handleError(_0x43c772,null));};exports[_0x493f('0x22')]=function(_0x756765,_0x452e1d){if(_0x756765[_0x493f('0x49')]['id']){delete _0x756765[_0x493f('0x49')]['id'];}return db[_0x493f('0x2c')][_0x493f('0x47')]({'where':{'id':_0x756765['params']['id']}})[_0x493f('0x23')](handleEntityNotFound(_0x452e1d,null))['then'](saveUpdates(_0x756765['body'],null))[_0x493f('0x23')](respondWithResult(_0x452e1d,null))[_0x493f('0x44')](handleError(_0x452e1d,null));};exports[_0x493f('0x24')]=function(_0x5ce1e3,_0x1f242b){return db[_0x493f('0x2c')][_0x493f('0x47')]({'where':{'id':_0x5ce1e3[_0x493f('0x46')]['id']}})[_0x493f('0x23')](handleEntityNotFound(_0x1f242b,null))['then'](removeEntity(_0x1f242b,null))[_0x493f('0x44')](handleError(_0x1f242b,null));};exports['describe']=function(_0x8a457b,_0x31b4aa){return db[_0x493f('0x2c')]['describe']()['then'](respondWithResult(_0x31b4aa,null))[_0x493f('0x44')](handleError(_0x31b4aa,null));};