e9e585d1256b0438da49cc046464108a15791ebf
[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 _0x18ea=['status','json','count','offset','limit','Content-Range','reject','save','update','then','destroy','error','stack','name','send','index','map','OpenchannelTransferReport','rawAttributes','fieldName','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','pick','filter','where','VIRTUAL','merge','options','include','findAll','rows','catch','show','params','includeAll','create','body','find','describe','html-pdf','eml-format','fast-json-patch','request-promise','bluebird','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus'];(function(_0x2986d4,_0x38c2ad){var _0x29b19f=function(_0x162a23){while(--_0x162a23){_0x2986d4['push'](_0x2986d4['shift']());}};_0x29b19f(++_0x38c2ad);}(_0x18ea,0xbe));var _0xa18e=function(_0x3368a3,_0x27c0bc){_0x3368a3=_0x3368a3-0x0;var _0x2aa33e=_0x18ea[_0x3368a3];return _0x2aa33e;};'use strict';var pdf=require(_0xa18e('0x0'));var emlformat=require(_0xa18e('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xa18e('0x2'));var rp=require(_0xa18e('0x3'));var moment=require('moment');var BPromise=require(_0xa18e('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0xa18e('0x5'));var sox=require('sox');var csv=require(_0xa18e('0x6'));var ejs=require(_0xa18e('0x7'));var fs=require('fs');var _=require(_0xa18e('0x8'));var squel=require(_0xa18e('0x9'));var crypto=require(_0xa18e('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xa18e('0xb'));var toCsv=require(_0xa18e('0x6'));var querystring=require(_0xa18e('0xc'));var Papa=require('papaparse');var Redis=require(_0xa18e('0xd'));var authService=require(_0xa18e('0xe'));var qs=require(_0xa18e('0xf'));var as=require(_0xa18e('0x10'));var hardwareService=require(_0xa18e('0x11'));var logger=require(_0xa18e('0x12'))('api');var utils=require(_0xa18e('0x13'));var config=require(_0xa18e('0x14'));var db=require(_0xa18e('0x15'))['db'];function respondWithStatusCode(_0x16012c,_0x28a3a0){_0x28a3a0=_0x28a3a0||0xcc;return function(_0x546ca1){if(_0x546ca1){return _0x16012c[_0xa18e('0x16')](_0x28a3a0);}return _0x16012c['status'](_0x28a3a0)['end']();};}function respondWithResult(_0x44af56,_0x34a87f){_0x34a87f=_0x34a87f||0xc8;return function(_0x5e41df){if(_0x5e41df){return _0x44af56[_0xa18e('0x17')](_0x34a87f)[_0xa18e('0x18')](_0x5e41df);}};}function respondWithFilteredResult(_0x59d13a,_0x4c710d){return function(_0x4b33f2){if(_0x4b33f2){var _0x3f9b3e=_0x4b33f2[_0xa18e('0x19')],_0x48b024=_0x4c710d['offset'],_0x4d5b32=_0x4c710d[_0xa18e('0x1a')]+_0x4c710d[_0xa18e('0x1b')],_0x60fc54;if(_0x4d5b32>=_0x3f9b3e){_0x4d5b32=_0x3f9b3e;_0x60fc54=0xc8;}else{_0x60fc54=0xce;}_0x59d13a[_0xa18e('0x17')](_0x60fc54);return _0x59d13a['set'](_0xa18e('0x1c'),_0x48b024+'-'+_0x4d5b32+'/'+_0x3f9b3e)[_0xa18e('0x18')](_0x4b33f2);}return null;};}function patchUpdates(_0x57a89b){return function(_0x1a6da1){try{jsonpatch['apply'](_0x1a6da1,_0x57a89b,!![]);}catch(_0x2b631f){return BPromise[_0xa18e('0x1d')](_0x2b631f);}return _0x1a6da1[_0xa18e('0x1e')]();};}function saveUpdates(_0x325adc,_0x4a15b4){return function(_0x5895c2){if(_0x5895c2){return _0x5895c2[_0xa18e('0x1f')](_0x325adc)[_0xa18e('0x20')](function(_0x562320){return _0x562320;});}return null;};}function removeEntity(_0x86fa9c,_0x3b115f){return function(_0x58d4f0){if(_0x58d4f0){return _0x58d4f0[_0xa18e('0x21')]()[_0xa18e('0x20')](function(){_0x86fa9c[_0xa18e('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3b84de,_0x1ddca9){return function(_0x35040a){if(!_0x35040a){_0x3b84de[_0xa18e('0x16')](0x194);}return _0x35040a;};}function handleError(_0x3663c7,_0x4d647b){_0x4d647b=_0x4d647b||0x1f4;return function(_0x3f53a4){logger[_0xa18e('0x22')](_0x3f53a4[_0xa18e('0x23')]);if(_0x3f53a4[_0xa18e('0x24')]){delete _0x3f53a4[_0xa18e('0x24')];}_0x3663c7[_0xa18e('0x17')](_0x4d647b)[_0xa18e('0x25')](_0x3f53a4);};}exports[_0xa18e('0x26')]=function(_0x1bfec9,_0x2a8234){var _0xd77ca4={},_0x245fde={},_0x3219ed={'count':0x0,'rows':[]};var _0x360d37=_[_0xa18e('0x27')](db[_0xa18e('0x28')][_0xa18e('0x29')],function(_0x336057){return{'name':_0x336057[_0xa18e('0x2a')],'type':_0x336057['type']['key']};});_0x245fde['model']=_[_0xa18e('0x27')](_0x360d37,_0xa18e('0x24'));_0x245fde[_0xa18e('0x2b')]=_[_0xa18e('0x2c')](_0x1bfec9['query']);_0x245fde[_0xa18e('0x2d')]=_[_0xa18e('0x2e')](_0x245fde[_0xa18e('0x2f')],_0x245fde['query']);_0xd77ca4[_0xa18e('0x30')]=_[_0xa18e('0x2e')](_0x245fde['model'],qs[_0xa18e('0x31')](_0x1bfec9[_0xa18e('0x2b')][_0xa18e('0x31')]));_0xd77ca4[_0xa18e('0x30')]=_0xd77ca4[_0xa18e('0x30')][_0xa18e('0x32')]?_0xd77ca4[_0xa18e('0x30')]:_0x245fde[_0xa18e('0x2f')];if(!_0x1bfec9[_0xa18e('0x2b')]['hasOwnProperty'](_0xa18e('0x33'))){_0xd77ca4[_0xa18e('0x1b')]=qs[_0xa18e('0x1b')](_0x1bfec9['query'][_0xa18e('0x1b')]);_0xd77ca4['offset']=qs[_0xa18e('0x1a')](_0x1bfec9[_0xa18e('0x2b')][_0xa18e('0x1a')]);}_0xd77ca4[_0xa18e('0x34')]=qs['sort'](_0x1bfec9['query'][_0xa18e('0x35')]);_0xd77ca4['where']=qs[_0xa18e('0x2d')](_[_0xa18e('0x36')](_0x1bfec9[_0xa18e('0x2b')],_0x245fde['filters']),_0x360d37);if(_0x1bfec9[_0xa18e('0x2b')][_0xa18e('0x37')]){_0xd77ca4[_0xa18e('0x38')]=_['merge'](_0xd77ca4[_0xa18e('0x38')],{'$or':_[_0xa18e('0x27')](_0x360d37,function(_0x56d214){if(_0x56d214['type']!==_0xa18e('0x39')){var _0x44e2df={};_0x44e2df[_0x56d214[_0xa18e('0x24')]]={'$like':'%'+_0x1bfec9[_0xa18e('0x2b')][_0xa18e('0x37')]+'%'};return _0x44e2df;}})});}_0xd77ca4=_[_0xa18e('0x3a')]({},_0xd77ca4,_0x1bfec9[_0xa18e('0x3b')]);var _0x4209e7={'where':_0xd77ca4['where']};return db[_0xa18e('0x28')]['count'](_0x4209e7)[_0xa18e('0x20')](function(_0x10c09a){_0x3219ed[_0xa18e('0x19')]=_0x10c09a;if(_0x1bfec9[_0xa18e('0x2b')]['includeAll']){_0xd77ca4[_0xa18e('0x3c')]=[{'all':!![]}];}return db[_0xa18e('0x28')][_0xa18e('0x3d')](_0xd77ca4);})[_0xa18e('0x20')](function(_0x3cea0b){_0x3219ed[_0xa18e('0x3e')]=_0x3cea0b;return _0x3219ed;})['then'](respondWithFilteredResult(_0x2a8234,_0xd77ca4))[_0xa18e('0x3f')](handleError(_0x2a8234,null));};exports[_0xa18e('0x40')]=function(_0x2e0e00,_0xb4792a){var _0x30420d={'raw':!![],'where':{'id':_0x2e0e00[_0xa18e('0x41')]['id']}},_0x20a8c1={};_0x20a8c1[_0xa18e('0x2f')]=_[_0xa18e('0x2c')](db['OpenchannelTransferReport']['rawAttributes']);_0x20a8c1[_0xa18e('0x2b')]=_[_0xa18e('0x2c')](_0x2e0e00[_0xa18e('0x2b')]);_0x20a8c1[_0xa18e('0x2d')]=_[_0xa18e('0x2e')](_0x20a8c1[_0xa18e('0x2f')],_0x20a8c1[_0xa18e('0x2b')]);_0x30420d[_0xa18e('0x30')]=_[_0xa18e('0x2e')](_0x20a8c1[_0xa18e('0x2f')],qs[_0xa18e('0x31')](_0x2e0e00[_0xa18e('0x2b')]['fields']));_0x30420d[_0xa18e('0x30')]=_0x30420d[_0xa18e('0x30')][_0xa18e('0x32')]?_0x30420d[_0xa18e('0x30')]:_0x20a8c1[_0xa18e('0x2f')];if(_0x2e0e00[_0xa18e('0x2b')][_0xa18e('0x42')]){_0x30420d[_0xa18e('0x3c')]=[{'all':!![]}];}_0x30420d=_[_0xa18e('0x3a')]({},_0x30420d,_0x2e0e00[_0xa18e('0x3b')]);return db[_0xa18e('0x28')]['find'](_0x30420d)['then'](handleEntityNotFound(_0xb4792a,null))['then'](respondWithResult(_0xb4792a,null))[_0xa18e('0x3f')](handleError(_0xb4792a,null));};exports[_0xa18e('0x43')]=function(_0x46c1cc,_0x41efd5){return db['OpenchannelTransferReport'][_0xa18e('0x43')](_0x46c1cc['body'],{})[_0xa18e('0x20')](respondWithResult(_0x41efd5,0xc9))[_0xa18e('0x3f')](handleError(_0x41efd5,null));};exports['update']=function(_0x3ccdd8,_0x254625){if(_0x3ccdd8[_0xa18e('0x44')]['id']){delete _0x3ccdd8[_0xa18e('0x44')]['id'];}return db[_0xa18e('0x28')][_0xa18e('0x45')]({'where':{'id':_0x3ccdd8[_0xa18e('0x41')]['id']}})[_0xa18e('0x20')](handleEntityNotFound(_0x254625,null))[_0xa18e('0x20')](saveUpdates(_0x3ccdd8[_0xa18e('0x44')],null))[_0xa18e('0x20')](respondWithResult(_0x254625,null))[_0xa18e('0x3f')](handleError(_0x254625,null));};exports[_0xa18e('0x21')]=function(_0x12cead,_0x1876c2){return db[_0xa18e('0x28')][_0xa18e('0x45')]({'where':{'id':_0x12cead[_0xa18e('0x41')]['id']}})['then'](handleEntityNotFound(_0x1876c2,null))[_0xa18e('0x20')](removeEntity(_0x1876c2,null))[_0xa18e('0x3f')](handleError(_0x1876c2,null));};exports[_0xa18e('0x46')]=function(_0x25341f,_0x4161f8){return db['OpenchannelTransferReport']['describe']()[_0xa18e('0x20')](respondWithResult(_0x4161f8,null))['catch'](handleError(_0x4161f8,null));};