e51f90769ed9a7cf6c99c9a05a48502109d2b1bc
[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 _0x7fe5=['include','OpenchannelTransferReport','findAll','rows','params','keys','rawAttributes','merge','find','catch','create','update','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','then','destroy','end','error','stack','name','send','map','type','key','model','query','filters','intersection','fields','attributes','length','order','sort','pick','filter','where','VIRTUAL','options','includeAll'];(function(_0x535ec3,_0x3c8d40){var _0x783a20=function(_0x4f32d8){while(--_0x4f32d8){_0x535ec3['push'](_0x535ec3['shift']());}};_0x783a20(++_0x3c8d40);}(_0x7fe5,0x13a));var _0x57fe=function(_0x2d24e2,_0x38c3af){_0x2d24e2=_0x2d24e2-0x0;var _0x330f61=_0x7fe5[_0x2d24e2];return _0x330f61;};'use strict';var emlformat=require(_0x57fe('0x0'));var rimraf=require(_0x57fe('0x1'));var zipdir=require(_0x57fe('0x2'));var jsonpatch=require(_0x57fe('0x3'));var rp=require(_0x57fe('0x4'));var moment=require(_0x57fe('0x5'));var BPromise=require(_0x57fe('0x6'));var Mustache=require('mustache');var util=require('util');var path=require(_0x57fe('0x7'));var sox=require(_0x57fe('0x8'));var csv=require(_0x57fe('0x9'));var ejs=require(_0x57fe('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x57fe('0xb'));var crypto=require(_0x57fe('0xc'));var jsforce=require(_0x57fe('0xd'));var deskjs=require(_0x57fe('0xe'));var toCsv=require(_0x57fe('0x9'));var querystring=require(_0x57fe('0xf'));var Papa=require(_0x57fe('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x57fe('0x11'));var as=require(_0x57fe('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x57fe('0x13'))('api');var utils=require(_0x57fe('0x14'));var config=require(_0x57fe('0x15'));var licenseUtil=require(_0x57fe('0x16'));var db=require(_0x57fe('0x17'))['db'];function respondWithStatusCode(_0x2deb50,_0x8592b0){_0x8592b0=_0x8592b0||0xcc;return function(_0x4ea889){if(_0x4ea889){return _0x2deb50[_0x57fe('0x18')](_0x8592b0);}return _0x2deb50[_0x57fe('0x19')](_0x8592b0)['end']();};}function respondWithResult(_0x309424,_0x3fed0f){_0x3fed0f=_0x3fed0f||0xc8;return function(_0x4d151b){if(_0x4d151b){return _0x309424[_0x57fe('0x19')](_0x3fed0f)[_0x57fe('0x1a')](_0x4d151b);}};}function respondWithFilteredResult(_0x301cd3,_0x22ee0d){return function(_0x3f7123){if(_0x3f7123){var _0x33a6b4=typeof _0x22ee0d[_0x57fe('0x1b')]===_0x57fe('0x1c')&&typeof _0x22ee0d[_0x57fe('0x1d')]==='undefined';var _0x12e681=_0x3f7123[_0x57fe('0x1e')];var _0x4d7fab=_0x33a6b4?0x0:_0x22ee0d['offset'];var _0x6f8db9=_0x33a6b4?_0x3f7123[_0x57fe('0x1e')]:_0x22ee0d[_0x57fe('0x1b')]+_0x22ee0d[_0x57fe('0x1d')];var _0x3c139a;if(_0x6f8db9>=_0x12e681){_0x6f8db9=_0x12e681;_0x3c139a=0xc8;}else{_0x3c139a=0xce;}_0x301cd3[_0x57fe('0x19')](_0x3c139a);return _0x301cd3[_0x57fe('0x1f')](_0x57fe('0x20'),_0x4d7fab+'-'+_0x6f8db9+'/'+_0x12e681)['json'](_0x3f7123);}return null;};}function patchUpdates(_0x59b344){return function(_0x4a4e9c){try{jsonpatch[_0x57fe('0x21')](_0x4a4e9c,_0x59b344,!![]);}catch(_0x862c81){return BPromise[_0x57fe('0x22')](_0x862c81);}return _0x4a4e9c[_0x57fe('0x23')]();};}function saveUpdates(_0x4d4aad,_0x1bb579){return function(_0x4eb163){if(_0x4eb163){return _0x4eb163['update'](_0x4d4aad)[_0x57fe('0x24')](function(_0x539b04){return _0x539b04;});}return null;};}function removeEntity(_0x28504c,_0x167848){return function(_0x335f3a){if(_0x335f3a){return _0x335f3a[_0x57fe('0x25')]()[_0x57fe('0x24')](function(){_0x28504c[_0x57fe('0x19')](0xcc)[_0x57fe('0x26')]();});}};}function handleEntityNotFound(_0x5a8a4f,_0x8d1b78){return function(_0x6745aa){if(!_0x6745aa){_0x5a8a4f[_0x57fe('0x18')](0x194);}return _0x6745aa;};}function handleError(_0x2a468f,_0x5b624d){_0x5b624d=_0x5b624d||0x1f4;return function(_0x2f3c2d){logger[_0x57fe('0x27')](_0x2f3c2d[_0x57fe('0x28')]);if(_0x2f3c2d[_0x57fe('0x29')]){delete _0x2f3c2d[_0x57fe('0x29')];}_0x2a468f['status'](_0x5b624d)[_0x57fe('0x2a')](_0x2f3c2d);};}exports['index']=function(_0x8666f4,_0x15927f){var _0x378f98={},_0x255fa1={},_0x2d1540={'count':0x0,'rows':[]};var _0x22d5a4=_[_0x57fe('0x2b')](db['OpenchannelTransferReport']['rawAttributes'],function(_0x4c3c54){return{'name':_0x4c3c54['fieldName'],'type':_0x4c3c54[_0x57fe('0x2c')][_0x57fe('0x2d')]};});_0x255fa1[_0x57fe('0x2e')]=_['map'](_0x22d5a4,_0x57fe('0x29'));_0x255fa1['query']=_['keys'](_0x8666f4[_0x57fe('0x2f')]);_0x255fa1[_0x57fe('0x30')]=_['intersection'](_0x255fa1['model'],_0x255fa1[_0x57fe('0x2f')]);_0x378f98['attributes']=_[_0x57fe('0x31')](_0x255fa1[_0x57fe('0x2e')],qs[_0x57fe('0x32')](_0x8666f4['query'][_0x57fe('0x32')]));_0x378f98['attributes']=_0x378f98[_0x57fe('0x33')][_0x57fe('0x34')]?_0x378f98['attributes']:_0x255fa1[_0x57fe('0x2e')];if(!_0x8666f4[_0x57fe('0x2f')]['hasOwnProperty']('nolimit')){_0x378f98['limit']=qs['limit'](_0x8666f4['query'][_0x57fe('0x1d')]);_0x378f98['offset']=qs[_0x57fe('0x1b')](_0x8666f4[_0x57fe('0x2f')]['offset']);}_0x378f98[_0x57fe('0x35')]=qs[_0x57fe('0x36')](_0x8666f4[_0x57fe('0x2f')][_0x57fe('0x36')]);_0x378f98['where']=qs[_0x57fe('0x30')](_[_0x57fe('0x37')](_0x8666f4[_0x57fe('0x2f')],_0x255fa1[_0x57fe('0x30')]),_0x22d5a4);if(_0x8666f4[_0x57fe('0x2f')][_0x57fe('0x38')]){_0x378f98[_0x57fe('0x39')]=_['merge'](_0x378f98[_0x57fe('0x39')],{'$or':_[_0x57fe('0x2b')](_0x22d5a4,function(_0x2a5874){if(_0x2a5874['type']!==_0x57fe('0x3a')){var _0x1ade32={};_0x1ade32[_0x2a5874[_0x57fe('0x29')]]={'$like':'%'+_0x8666f4[_0x57fe('0x2f')][_0x57fe('0x38')]+'%'};return _0x1ade32;}})});}_0x378f98=_['merge']({},_0x378f98,_0x8666f4[_0x57fe('0x3b')]);var _0x3d0d67={'where':_0x378f98[_0x57fe('0x39')]};return db['OpenchannelTransferReport'][_0x57fe('0x1e')](_0x3d0d67)['then'](function(_0x315d29){_0x2d1540[_0x57fe('0x1e')]=_0x315d29;if(_0x8666f4[_0x57fe('0x2f')][_0x57fe('0x3c')]){_0x378f98[_0x57fe('0x3d')]=[{'all':!![]}];}return db[_0x57fe('0x3e')][_0x57fe('0x3f')](_0x378f98);})[_0x57fe('0x24')](function(_0xb24186){_0x2d1540[_0x57fe('0x40')]=_0xb24186;return _0x2d1540;})[_0x57fe('0x24')](respondWithFilteredResult(_0x15927f,_0x378f98))['catch'](handleError(_0x15927f,null));};exports['show']=function(_0x2859c3,_0x2c8b96){var _0x22476b={'raw':!![],'where':{'id':_0x2859c3[_0x57fe('0x41')]['id']}},_0x2bfb9b={};_0x2bfb9b[_0x57fe('0x2e')]=_[_0x57fe('0x42')](db[_0x57fe('0x3e')][_0x57fe('0x43')]);_0x2bfb9b['query']=_[_0x57fe('0x42')](_0x2859c3[_0x57fe('0x2f')]);_0x2bfb9b['filters']=_[_0x57fe('0x31')](_0x2bfb9b[_0x57fe('0x2e')],_0x2bfb9b['query']);_0x22476b['attributes']=_[_0x57fe('0x31')](_0x2bfb9b[_0x57fe('0x2e')],qs[_0x57fe('0x32')](_0x2859c3[_0x57fe('0x2f')][_0x57fe('0x32')]));_0x22476b[_0x57fe('0x33')]=_0x22476b[_0x57fe('0x33')][_0x57fe('0x34')]?_0x22476b[_0x57fe('0x33')]:_0x2bfb9b[_0x57fe('0x2e')];if(_0x2859c3[_0x57fe('0x2f')][_0x57fe('0x3c')]){_0x22476b[_0x57fe('0x3d')]=[{'all':!![]}];}_0x22476b=_[_0x57fe('0x44')]({},_0x22476b,_0x2859c3[_0x57fe('0x3b')]);return db[_0x57fe('0x3e')][_0x57fe('0x45')](_0x22476b)[_0x57fe('0x24')](handleEntityNotFound(_0x2c8b96,null))['then'](respondWithResult(_0x2c8b96,null))[_0x57fe('0x46')](handleError(_0x2c8b96,null));};exports[_0x57fe('0x47')]=function(_0x59f442,_0xd99c32){return db[_0x57fe('0x3e')][_0x57fe('0x47')](_0x59f442['body'],{})[_0x57fe('0x24')](respondWithResult(_0xd99c32,0xc9))[_0x57fe('0x46')](handleError(_0xd99c32,null));};exports[_0x57fe('0x48')]=function(_0x22914b,_0x48e6ec){if(_0x22914b['body']['id']){delete _0x22914b[_0x57fe('0x49')]['id'];}return db[_0x57fe('0x3e')][_0x57fe('0x45')]({'where':{'id':_0x22914b[_0x57fe('0x41')]['id']}})[_0x57fe('0x24')](handleEntityNotFound(_0x48e6ec,null))[_0x57fe('0x24')](saveUpdates(_0x22914b[_0x57fe('0x49')],null))[_0x57fe('0x24')](respondWithResult(_0x48e6ec,null))[_0x57fe('0x46')](handleError(_0x48e6ec,null));};exports[_0x57fe('0x25')]=function(_0x477bbb,_0x1d7e6e){return db['OpenchannelTransferReport'][_0x57fe('0x45')]({'where':{'id':_0x477bbb[_0x57fe('0x41')]['id']}})[_0x57fe('0x24')](handleEntityNotFound(_0x1d7e6e,null))[_0x57fe('0x24')](removeEntity(_0x1d7e6e,null))['catch'](handleError(_0x1d7e6e,null));};exports['describe']=function(_0x63a672,_0x2a0201){return db['OpenchannelTransferReport'][_0x57fe('0x4a')]()['then'](respondWithResult(_0x2a0201,null))[_0x57fe('0x46')](handleError(_0x2a0201,null));};