9a777511ce570b7848bde5d7dca11c1cf57a42a4
[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 _0xf1f6=['params','keys','intersection','create','body','find','describe','eml-format','rimraf','fast-json-patch','moment','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','index','map','rawAttributes','fieldName','type','model','query','filters','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','merge','options','where','OpenchannelTransferReport','includeAll','include','findAll','rows','catch'];(function(_0x4de586,_0x183427){var _0x46baf5=function(_0x1157f0){while(--_0x1157f0){_0x4de586['push'](_0x4de586['shift']());}};_0x46baf5(++_0x183427);}(_0xf1f6,0xa1));var _0x6f1f=function(_0x3f3899,_0xde9370){_0x3f3899=_0x3f3899-0x0;var _0x14fa2f=_0xf1f6[_0x3f3899];return _0x14fa2f;};'use strict';var emlformat=require(_0x6f1f('0x0'));var rimraf=require(_0x6f1f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6f1f('0x2'));var rp=require('request-promise');var moment=require(_0x6f1f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x6f1f('0x4'));var util=require('util');var path=require('path');var sox=require(_0x6f1f('0x5'));var csv=require(_0x6f1f('0x6'));var ejs=require(_0x6f1f('0x7'));var fs=require('fs');var fs_extra=require(_0x6f1f('0x8'));var _=require(_0x6f1f('0x9'));var squel=require(_0x6f1f('0xa'));var crypto=require(_0x6f1f('0xb'));var jsforce=require(_0x6f1f('0xc'));var deskjs=require(_0x6f1f('0xd'));var toCsv=require(_0x6f1f('0x6'));var querystring=require(_0x6f1f('0xe'));var Papa=require('papaparse');var Redis=require(_0x6f1f('0xf'));var authService=require(_0x6f1f('0x10'));var qs=require(_0x6f1f('0x11'));var as=require(_0x6f1f('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x6f1f('0x13'))(_0x6f1f('0x14'));var utils=require(_0x6f1f('0x15'));var config=require(_0x6f1f('0x16'));var licenseUtil=require(_0x6f1f('0x17'));var db=require(_0x6f1f('0x18'))['db'];function respondWithStatusCode(_0x408a8b,_0xf4a8f5){_0xf4a8f5=_0xf4a8f5||0xcc;return function(_0x5a6e19){if(_0x5a6e19){return _0x408a8b['sendStatus'](_0xf4a8f5);}return _0x408a8b['status'](_0xf4a8f5)[_0x6f1f('0x19')]();};}function respondWithResult(_0x4ca80c,_0xa47c6f){_0xa47c6f=_0xa47c6f||0xc8;return function(_0xee7075){if(_0xee7075){return _0x4ca80c[_0x6f1f('0x1a')](_0xa47c6f)[_0x6f1f('0x1b')](_0xee7075);}};}function respondWithFilteredResult(_0x54004a,_0x1dee46){return function(_0x4aa27d){if(_0x4aa27d){var _0xeaa434=typeof _0x1dee46[_0x6f1f('0x1c')]===_0x6f1f('0x1d')&&typeof _0x1dee46[_0x6f1f('0x1e')]==='undefined';var _0x4f8eaf=_0x4aa27d[_0x6f1f('0x1f')];var _0xde109c=_0xeaa434?0x0:_0x1dee46['offset'];var _0x4cd015=_0xeaa434?_0x4aa27d[_0x6f1f('0x1f')]:_0x1dee46[_0x6f1f('0x1c')]+_0x1dee46[_0x6f1f('0x1e')];var _0x29fe4e;if(_0x4cd015>=_0x4f8eaf){_0x4cd015=_0x4f8eaf;_0x29fe4e=0xc8;}else{_0x29fe4e=0xce;}_0x54004a[_0x6f1f('0x1a')](_0x29fe4e);return _0x54004a[_0x6f1f('0x20')](_0x6f1f('0x21'),_0xde109c+'-'+_0x4cd015+'/'+_0x4f8eaf)[_0x6f1f('0x1b')](_0x4aa27d);}return null;};}function patchUpdates(_0x2156bb){return function(_0xee92f2){try{jsonpatch[_0x6f1f('0x22')](_0xee92f2,_0x2156bb,!![]);}catch(_0x313104){return BPromise[_0x6f1f('0x23')](_0x313104);}return _0xee92f2[_0x6f1f('0x24')]();};}function saveUpdates(_0x3964e6,_0x5a1c7a){return function(_0x16e007){if(_0x16e007){return _0x16e007[_0x6f1f('0x25')](_0x3964e6)[_0x6f1f('0x26')](function(_0x680479){return _0x680479;});}return null;};}function removeEntity(_0x570d8e,_0x2909b6){return function(_0xf69df3){if(_0xf69df3){return _0xf69df3[_0x6f1f('0x27')]()[_0x6f1f('0x26')](function(){_0x570d8e[_0x6f1f('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x17d38e,_0x3cae09){return function(_0x3d65c5){if(!_0x3d65c5){_0x17d38e[_0x6f1f('0x28')](0x194);}return _0x3d65c5;};}function handleError(_0x30b87b,_0x19dc55){_0x19dc55=_0x19dc55||0x1f4;return function(_0x3cff5f){logger[_0x6f1f('0x29')](_0x3cff5f[_0x6f1f('0x2a')]);if(_0x3cff5f[_0x6f1f('0x2b')]){delete _0x3cff5f[_0x6f1f('0x2b')];}_0x30b87b[_0x6f1f('0x1a')](_0x19dc55)['send'](_0x3cff5f);};}exports[_0x6f1f('0x2c')]=function(_0x5904af,_0x5a6473){var _0x420f15={},_0x35cc7a={},_0x4c308e={'count':0x0,'rows':[]};var _0x451975=_[_0x6f1f('0x2d')](db['OpenchannelTransferReport'][_0x6f1f('0x2e')],function(_0x868e4e){return{'name':_0x868e4e[_0x6f1f('0x2f')],'type':_0x868e4e[_0x6f1f('0x30')]['key']};});_0x35cc7a[_0x6f1f('0x31')]=_['map'](_0x451975,_0x6f1f('0x2b'));_0x35cc7a['query']=_['keys'](_0x5904af[_0x6f1f('0x32')]);_0x35cc7a[_0x6f1f('0x33')]=_['intersection'](_0x35cc7a[_0x6f1f('0x31')],_0x35cc7a[_0x6f1f('0x32')]);_0x420f15[_0x6f1f('0x34')]=_['intersection'](_0x35cc7a['model'],qs['fields'](_0x5904af[_0x6f1f('0x32')][_0x6f1f('0x35')]));_0x420f15[_0x6f1f('0x34')]=_0x420f15['attributes'][_0x6f1f('0x36')]?_0x420f15[_0x6f1f('0x34')]:_0x35cc7a[_0x6f1f('0x31')];if(!_0x5904af['query'][_0x6f1f('0x37')](_0x6f1f('0x38'))){_0x420f15[_0x6f1f('0x1e')]=qs['limit'](_0x5904af[_0x6f1f('0x32')]['limit']);_0x420f15[_0x6f1f('0x1c')]=qs[_0x6f1f('0x1c')](_0x5904af['query'][_0x6f1f('0x1c')]);}_0x420f15[_0x6f1f('0x39')]=qs['sort'](_0x5904af[_0x6f1f('0x32')][_0x6f1f('0x3a')]);_0x420f15['where']=qs[_0x6f1f('0x33')](_[_0x6f1f('0x3b')](_0x5904af[_0x6f1f('0x32')],_0x35cc7a[_0x6f1f('0x33')]),_0x451975);if(_0x5904af[_0x6f1f('0x32')][_0x6f1f('0x3c')]){_0x420f15['where']=_[_0x6f1f('0x3d')](_0x420f15['where'],{'$or':_[_0x6f1f('0x2d')](_0x451975,function(_0x42e235){if(_0x42e235[_0x6f1f('0x30')]!=='VIRTUAL'){var _0x2eb860={};_0x2eb860[_0x42e235[_0x6f1f('0x2b')]]={'$like':'%'+_0x5904af[_0x6f1f('0x32')]['filter']+'%'};return _0x2eb860;}})});}_0x420f15=_[_0x6f1f('0x3d')]({},_0x420f15,_0x5904af[_0x6f1f('0x3e')]);var _0x3754f5={'where':_0x420f15[_0x6f1f('0x3f')]};return db[_0x6f1f('0x40')][_0x6f1f('0x1f')](_0x3754f5)[_0x6f1f('0x26')](function(_0x5e3a29){_0x4c308e['count']=_0x5e3a29;if(_0x5904af['query'][_0x6f1f('0x41')]){_0x420f15[_0x6f1f('0x42')]=[{'all':!![]}];}return db[_0x6f1f('0x40')][_0x6f1f('0x43')](_0x420f15);})['then'](function(_0x119707){_0x4c308e[_0x6f1f('0x44')]=_0x119707;return _0x4c308e;})['then'](respondWithFilteredResult(_0x5a6473,_0x420f15))[_0x6f1f('0x45')](handleError(_0x5a6473,null));};exports['show']=function(_0x307c3f,_0x54a010){var _0x43dbc4={'raw':!![],'where':{'id':_0x307c3f[_0x6f1f('0x46')]['id']}},_0x421d28={};_0x421d28[_0x6f1f('0x31')]=_[_0x6f1f('0x47')](db['OpenchannelTransferReport'][_0x6f1f('0x2e')]);_0x421d28[_0x6f1f('0x32')]=_[_0x6f1f('0x47')](_0x307c3f[_0x6f1f('0x32')]);_0x421d28[_0x6f1f('0x33')]=_[_0x6f1f('0x48')](_0x421d28['model'],_0x421d28[_0x6f1f('0x32')]);_0x43dbc4[_0x6f1f('0x34')]=_['intersection'](_0x421d28[_0x6f1f('0x31')],qs[_0x6f1f('0x35')](_0x307c3f[_0x6f1f('0x32')][_0x6f1f('0x35')]));_0x43dbc4['attributes']=_0x43dbc4[_0x6f1f('0x34')]['length']?_0x43dbc4[_0x6f1f('0x34')]:_0x421d28['model'];if(_0x307c3f[_0x6f1f('0x32')][_0x6f1f('0x41')]){_0x43dbc4[_0x6f1f('0x42')]=[{'all':!![]}];}_0x43dbc4=_[_0x6f1f('0x3d')]({},_0x43dbc4,_0x307c3f[_0x6f1f('0x3e')]);return db['OpenchannelTransferReport']['find'](_0x43dbc4)[_0x6f1f('0x26')](handleEntityNotFound(_0x54a010,null))['then'](respondWithResult(_0x54a010,null))[_0x6f1f('0x45')](handleError(_0x54a010,null));};exports[_0x6f1f('0x49')]=function(_0x4ccd65,_0xc2fb4){return db[_0x6f1f('0x40')][_0x6f1f('0x49')](_0x4ccd65[_0x6f1f('0x4a')],{})[_0x6f1f('0x26')](respondWithResult(_0xc2fb4,0xc9))['catch'](handleError(_0xc2fb4,null));};exports[_0x6f1f('0x25')]=function(_0x36c178,_0xf0592c){if(_0x36c178[_0x6f1f('0x4a')]['id']){delete _0x36c178[_0x6f1f('0x4a')]['id'];}return db[_0x6f1f('0x40')]['find']({'where':{'id':_0x36c178[_0x6f1f('0x46')]['id']}})[_0x6f1f('0x26')](handleEntityNotFound(_0xf0592c,null))[_0x6f1f('0x26')](saveUpdates(_0x36c178[_0x6f1f('0x4a')],null))[_0x6f1f('0x26')](respondWithResult(_0xf0592c,null))[_0x6f1f('0x45')](handleError(_0xf0592c,null));};exports['destroy']=function(_0x556be7,_0x57133c){return db[_0x6f1f('0x40')][_0x6f1f('0x4b')]({'where':{'id':_0x556be7[_0x6f1f('0x46')]['id']}})[_0x6f1f('0x26')](handleEntityNotFound(_0x57133c,null))[_0x6f1f('0x26')](removeEntity(_0x57133c,null))[_0x6f1f('0x45')](handleError(_0x57133c,null));};exports['describe']=function(_0x56187b,_0x1ca2ae){return db[_0x6f1f('0x40')][_0x6f1f('0x4c')]()['then'](respondWithResult(_0x1ca2ae,null))[_0x6f1f('0x45')](handleError(_0x1ca2ae,null));};