72fd1f2fe66e3ba509ccc2df148f784eac59bb5b
[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 _0xfc9a=['type','key','model','map','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','offset','order','sort','where','pick','filter','merge','VIRTUAL','findAll','catch','show','params','includeAll','options','find','create','body','destroy','describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','json','undefined','limit','count','status','set','apply','reject','save','update','then','error','name','OpenchannelTransferReport','rawAttributes','fieldName'];(function(_0x5193fb,_0x3f3140){var _0x28bed0=function(_0x37bee1){while(--_0x37bee1){_0x5193fb['push'](_0x5193fb['shift']());}};_0x28bed0(++_0x3f3140);}(_0xfc9a,0x147));var _0xafc9=function(_0x5b644e,_0x2e5e07){_0x5b644e=_0x5b644e-0x0;var _0x49c6bf=_0xfc9a[_0x5b644e];return _0x49c6bf;};'use strict';var emlformat=require(_0xafc9('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xafc9('0x1'));var jsonpatch=require(_0xafc9('0x2'));var rp=require(_0xafc9('0x3'));var moment=require('moment');var BPromise=require(_0xafc9('0x4'));var Mustache=require(_0xafc9('0x5'));var util=require(_0xafc9('0x6'));var path=require(_0xafc9('0x7'));var sox=require(_0xafc9('0x8'));var csv=require('to-csv');var ejs=require(_0xafc9('0x9'));var fs=require('fs');var fs_extra=require(_0xafc9('0xa'));var _=require(_0xafc9('0xb'));var squel=require(_0xafc9('0xc'));var crypto=require('crypto');var jsforce=require(_0xafc9('0xd'));var deskjs=require(_0xafc9('0xe'));var toCsv=require(_0xafc9('0xf'));var querystring=require('querystring');var Papa=require(_0xafc9('0x10'));var Redis=require(_0xafc9('0x11'));var authService=require(_0xafc9('0x12'));var qs=require(_0xafc9('0x13'));var as=require(_0xafc9('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xafc9('0x15'));var utils=require(_0xafc9('0x16'));var config=require(_0xafc9('0x17'));var licenseUtil=require(_0xafc9('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xd1e35,_0x5b86ab){_0x5b86ab=_0x5b86ab||0xcc;return function(_0x23a48a){if(_0x23a48a){return _0xd1e35[_0xafc9('0x19')](_0x5b86ab);}return _0xd1e35['status'](_0x5b86ab)[_0xafc9('0x1a')]();};}function respondWithResult(_0x9bdc8a,_0x1d7f8a){_0x1d7f8a=_0x1d7f8a||0xc8;return function(_0x562a1f){if(_0x562a1f){return _0x9bdc8a['status'](_0x1d7f8a)[_0xafc9('0x1b')](_0x562a1f);}};}function respondWithFilteredResult(_0x37d209,_0x3e581e){return function(_0x44e0e5){if(_0x44e0e5){var _0x19eff4=typeof _0x3e581e['offset']===_0xafc9('0x1c')&&typeof _0x3e581e[_0xafc9('0x1d')]===_0xafc9('0x1c');var _0x1dac6e=_0x44e0e5[_0xafc9('0x1e')];var _0x58b3d7=_0x19eff4?0x0:_0x3e581e['offset'];var _0x45d01c=_0x19eff4?_0x44e0e5[_0xafc9('0x1e')]:_0x3e581e['offset']+_0x3e581e[_0xafc9('0x1d')];var _0x17ba5d;if(_0x45d01c>=_0x1dac6e){_0x45d01c=_0x1dac6e;_0x17ba5d=0xc8;}else{_0x17ba5d=0xce;}_0x37d209[_0xafc9('0x1f')](_0x17ba5d);return _0x37d209[_0xafc9('0x20')]('Content-Range',_0x58b3d7+'-'+_0x45d01c+'/'+_0x1dac6e)['json'](_0x44e0e5);}return null;};}function patchUpdates(_0xbde185){return function(_0xae0808){try{jsonpatch[_0xafc9('0x21')](_0xae0808,_0xbde185,!![]);}catch(_0x596a87){return BPromise[_0xafc9('0x22')](_0x596a87);}return _0xae0808[_0xafc9('0x23')]();};}function saveUpdates(_0x42a152,_0x2c6e01){return function(_0x31af3d){if(_0x31af3d){return _0x31af3d[_0xafc9('0x24')](_0x42a152)[_0xafc9('0x25')](function(_0x55a4ec){return _0x55a4ec;});}return null;};}function removeEntity(_0x39af68,_0x2adebc){return function(_0x33add3){if(_0x33add3){return _0x33add3['destroy']()[_0xafc9('0x25')](function(){_0x39af68[_0xafc9('0x1f')](0xcc)[_0xafc9('0x1a')]();});}};}function handleEntityNotFound(_0x152f5a,_0x231440){return function(_0x4ad61a){if(!_0x4ad61a){_0x152f5a[_0xafc9('0x19')](0x194);}return _0x4ad61a;};}function handleError(_0x4af5dd,_0x35d71d){_0x35d71d=_0x35d71d||0x1f4;return function(_0x1c28bc){logger[_0xafc9('0x26')](_0x1c28bc['stack']);if(_0x1c28bc[_0xafc9('0x27')]){delete _0x1c28bc[_0xafc9('0x27')];}_0x4af5dd[_0xafc9('0x1f')](_0x35d71d)['send'](_0x1c28bc);};}exports['index']=function(_0x3e1c1f,_0x1c1546){var _0x47b8df={},_0x5895dc={},_0x4db720={'count':0x0,'rows':[]};var _0x15a1a8=_['map'](db[_0xafc9('0x28')][_0xafc9('0x29')],function(_0x37e59d){return{'name':_0x37e59d[_0xafc9('0x2a')],'type':_0x37e59d[_0xafc9('0x2b')][_0xafc9('0x2c')]};});_0x5895dc[_0xafc9('0x2d')]=_[_0xafc9('0x2e')](_0x15a1a8,'name');_0x5895dc[_0xafc9('0x2f')]=_[_0xafc9('0x30')](_0x3e1c1f[_0xafc9('0x2f')]);_0x5895dc[_0xafc9('0x31')]=_['intersection'](_0x5895dc[_0xafc9('0x2d')],_0x5895dc[_0xafc9('0x2f')]);_0x47b8df['attributes']=_[_0xafc9('0x32')](_0x5895dc[_0xafc9('0x2d')],qs[_0xafc9('0x33')](_0x3e1c1f[_0xafc9('0x2f')]['fields']));_0x47b8df[_0xafc9('0x34')]=_0x47b8df[_0xafc9('0x34')][_0xafc9('0x35')]?_0x47b8df[_0xafc9('0x34')]:_0x5895dc[_0xafc9('0x2d')];if(!_0x3e1c1f[_0xafc9('0x2f')][_0xafc9('0x36')]('nolimit')){_0x47b8df[_0xafc9('0x1d')]=qs['limit'](_0x3e1c1f['query'][_0xafc9('0x1d')]);_0x47b8df[_0xafc9('0x37')]=qs[_0xafc9('0x37')](_0x3e1c1f[_0xafc9('0x2f')]['offset']);}_0x47b8df[_0xafc9('0x38')]=qs[_0xafc9('0x39')](_0x3e1c1f[_0xafc9('0x2f')][_0xafc9('0x39')]);_0x47b8df[_0xafc9('0x3a')]=qs[_0xafc9('0x31')](_[_0xafc9('0x3b')](_0x3e1c1f[_0xafc9('0x2f')],_0x5895dc[_0xafc9('0x31')]),_0x15a1a8);if(_0x3e1c1f[_0xafc9('0x2f')][_0xafc9('0x3c')]){_0x47b8df[_0xafc9('0x3a')]=_[_0xafc9('0x3d')](_0x47b8df[_0xafc9('0x3a')],{'$or':_[_0xafc9('0x2e')](_0x15a1a8,function(_0x2d83fa){if(_0x2d83fa['type']!==_0xafc9('0x3e')){var _0x4c491e={};_0x4c491e[_0x2d83fa[_0xafc9('0x27')]]={'$like':'%'+_0x3e1c1f[_0xafc9('0x2f')][_0xafc9('0x3c')]+'%'};return _0x4c491e;}})});}_0x47b8df=_[_0xafc9('0x3d')]({},_0x47b8df,_0x3e1c1f['options']);var _0x4371e4={'where':_0x47b8df[_0xafc9('0x3a')]};return db[_0xafc9('0x28')][_0xafc9('0x1e')](_0x4371e4)[_0xafc9('0x25')](function(_0x462353){_0x4db720[_0xafc9('0x1e')]=_0x462353;if(_0x3e1c1f[_0xafc9('0x2f')]['includeAll']){_0x47b8df['include']=[{'all':!![]}];}return db[_0xafc9('0x28')][_0xafc9('0x3f')](_0x47b8df);})[_0xafc9('0x25')](function(_0x2ca24d){_0x4db720['rows']=_0x2ca24d;return _0x4db720;})[_0xafc9('0x25')](respondWithFilteredResult(_0x1c1546,_0x47b8df))[_0xafc9('0x40')](handleError(_0x1c1546,null));};exports[_0xafc9('0x41')]=function(_0x21d0eb,_0x3b1f7b){var _0xb16834={'raw':!![],'where':{'id':_0x21d0eb[_0xafc9('0x42')]['id']}},_0xfd963a={};_0xfd963a[_0xafc9('0x2d')]=_[_0xafc9('0x30')](db['OpenchannelTransferReport'][_0xafc9('0x29')]);_0xfd963a[_0xafc9('0x2f')]=_[_0xafc9('0x30')](_0x21d0eb[_0xafc9('0x2f')]);_0xfd963a[_0xafc9('0x31')]=_[_0xafc9('0x32')](_0xfd963a[_0xafc9('0x2d')],_0xfd963a[_0xafc9('0x2f')]);_0xb16834[_0xafc9('0x34')]=_['intersection'](_0xfd963a['model'],qs[_0xafc9('0x33')](_0x21d0eb['query'][_0xafc9('0x33')]));_0xb16834['attributes']=_0xb16834[_0xafc9('0x34')]['length']?_0xb16834[_0xafc9('0x34')]:_0xfd963a[_0xafc9('0x2d')];if(_0x21d0eb[_0xafc9('0x2f')][_0xafc9('0x43')]){_0xb16834['include']=[{'all':!![]}];}_0xb16834=_[_0xafc9('0x3d')]({},_0xb16834,_0x21d0eb[_0xafc9('0x44')]);return db[_0xafc9('0x28')][_0xafc9('0x45')](_0xb16834)[_0xafc9('0x25')](handleEntityNotFound(_0x3b1f7b,null))['then'](respondWithResult(_0x3b1f7b,null))[_0xafc9('0x40')](handleError(_0x3b1f7b,null));};exports[_0xafc9('0x46')]=function(_0x2633ce,_0x5c3a3d){return db[_0xafc9('0x28')][_0xafc9('0x46')](_0x2633ce[_0xafc9('0x47')],{})[_0xafc9('0x25')](respondWithResult(_0x5c3a3d,0xc9))[_0xafc9('0x40')](handleError(_0x5c3a3d,null));};exports['update']=function(_0x253bc7,_0x21db88){if(_0x253bc7['body']['id']){delete _0x253bc7[_0xafc9('0x47')]['id'];}return db[_0xafc9('0x28')][_0xafc9('0x45')]({'where':{'id':_0x253bc7['params']['id']}})[_0xafc9('0x25')](handleEntityNotFound(_0x21db88,null))[_0xafc9('0x25')](saveUpdates(_0x253bc7[_0xafc9('0x47')],null))[_0xafc9('0x25')](respondWithResult(_0x21db88,null))['catch'](handleError(_0x21db88,null));};exports[_0xafc9('0x48')]=function(_0x51d967,_0x59ca66){return db[_0xafc9('0x28')][_0xafc9('0x45')]({'where':{'id':_0x51d967[_0xafc9('0x42')]['id']}})[_0xafc9('0x25')](handleEntityNotFound(_0x59ca66,null))['then'](removeEntity(_0x59ca66,null))[_0xafc9('0x40')](handleError(_0x59ca66,null));};exports[_0xafc9('0x49')]=function(_0x5605c0,_0x4460d3){return db['OpenchannelTransferReport']['describe']()[_0xafc9('0x25')](respondWithResult(_0x4460d3,null))['catch'](handleError(_0x4460d3,null));};