Built motion from commit e1760111.|2.6.18
[motion2.git] / server / api / whatsappTransferReport / whatsappTransferReport.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 _0x9e1a=['request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','status','end','json','offset','undefined','limit','count','set','apply','save','update','then','destroy','sendStatus','error','name','send','WhatsappTransferReport','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','filter','VIRTUAL','merge','includeAll','rows','catch','show','params','length','include','create','body','find','eml-format','rimraf','zip-dir','fast-json-patch'];(function(_0x399ff0,_0x21bd69){var _0x26aec9=function(_0x1f3e20){while(--_0x1f3e20){_0x399ff0['push'](_0x399ff0['shift']());}};_0x26aec9(++_0x21bd69);}(_0x9e1a,0x120));var _0xa9e1=function(_0xc2de8a,_0x50423c){_0xc2de8a=_0xc2de8a-0x0;var _0x12e280=_0x9e1a[_0xc2de8a];return _0x12e280;};'use strict';var emlformat=require(_0xa9e1('0x0'));var rimraf=require(_0xa9e1('0x1'));var zipdir=require(_0xa9e1('0x2'));var jsonpatch=require(_0xa9e1('0x3'));var rp=require(_0xa9e1('0x4'));var moment=require(_0xa9e1('0x5'));var BPromise=require(_0xa9e1('0x6'));var Mustache=require(_0xa9e1('0x7'));var util=require('util');var path=require(_0xa9e1('0x8'));var sox=require('sox');var csv=require(_0xa9e1('0x9'));var ejs=require(_0xa9e1('0xa'));var fs=require('fs');var fs_extra=require(_0xa9e1('0xb'));var _=require(_0xa9e1('0xc'));var squel=require('squel');var crypto=require(_0xa9e1('0xd'));var jsforce=require(_0xa9e1('0xe'));var deskjs=require(_0xa9e1('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xa9e1('0x10'));var Redis=require('ioredis');var authService=require(_0xa9e1('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xa9e1('0x12'));var hardwareService=require(_0xa9e1('0x13'));var logger=require(_0xa9e1('0x14'))(_0xa9e1('0x15'));var utils=require(_0xa9e1('0x16'));var config=require(_0xa9e1('0x17'));var licenseUtil=require(_0xa9e1('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3bedae,_0x47afa7){_0x47afa7=_0x47afa7||0xcc;return function(_0x322f72){if(_0x322f72){return _0x3bedae['sendStatus'](_0x47afa7);}return _0x3bedae[_0xa9e1('0x19')](_0x47afa7)[_0xa9e1('0x1a')]();};}function respondWithResult(_0x4c3fc2,_0x3087bd){_0x3087bd=_0x3087bd||0xc8;return function(_0x4af5a6){if(_0x4af5a6){return _0x4c3fc2['status'](_0x3087bd)[_0xa9e1('0x1b')](_0x4af5a6);}};}function respondWithFilteredResult(_0x273053,_0x236116){return function(_0x3f2490){if(_0x3f2490){var _0x14ea04=typeof _0x236116[_0xa9e1('0x1c')]===_0xa9e1('0x1d')&&typeof _0x236116[_0xa9e1('0x1e')]===_0xa9e1('0x1d');var _0x2a189f=_0x3f2490[_0xa9e1('0x1f')];var _0x3bc753=_0x14ea04?0x0:_0x236116[_0xa9e1('0x1c')];var _0x41d694=_0x14ea04?_0x3f2490[_0xa9e1('0x1f')]:_0x236116[_0xa9e1('0x1c')]+_0x236116[_0xa9e1('0x1e')];var _0x548da8;if(_0x41d694>=_0x2a189f){_0x41d694=_0x2a189f;_0x548da8=0xc8;}else{_0x548da8=0xce;}_0x273053[_0xa9e1('0x19')](_0x548da8);return _0x273053[_0xa9e1('0x20')]('Content-Range',_0x3bc753+'-'+_0x41d694+'/'+_0x2a189f)[_0xa9e1('0x1b')](_0x3f2490);}return null;};}function patchUpdates(_0x3cabd0){return function(_0x1f28a2){try{jsonpatch[_0xa9e1('0x21')](_0x1f28a2,_0x3cabd0,!![]);}catch(_0x9ed6ca){return BPromise['reject'](_0x9ed6ca);}return _0x1f28a2[_0xa9e1('0x22')]();};}function saveUpdates(_0x59679e,_0x3c9847){return function(_0x1ec786){if(_0x1ec786){return _0x1ec786[_0xa9e1('0x23')](_0x59679e)[_0xa9e1('0x24')](function(_0x2b2cb6){return _0x2b2cb6;});}return null;};}function removeEntity(_0x84872a,_0x885575){return function(_0x5819ae){if(_0x5819ae){return _0x5819ae[_0xa9e1('0x25')]()['then'](function(){_0x84872a[_0xa9e1('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x251696,_0x4756d4){return function(_0x4fb669){if(!_0x4fb669){_0x251696[_0xa9e1('0x26')](0x194);}return _0x4fb669;};}function handleError(_0x4c5a7f,_0x145418){_0x145418=_0x145418||0x1f4;return function(_0x7555a){logger[_0xa9e1('0x27')](_0x7555a['stack']);if(_0x7555a['name']){delete _0x7555a[_0xa9e1('0x28')];}_0x4c5a7f['status'](_0x145418)[_0xa9e1('0x29')](_0x7555a);};}exports['index']=function(_0x375486,_0x495669){var _0x1c477c={},_0x4bf37b={},_0x5c2819={'count':0x0,'rows':[]};var _0x4de6d7=_['map'](db[_0xa9e1('0x2a')][_0xa9e1('0x2b')],function(_0x3f7e33){return{'name':_0x3f7e33[_0xa9e1('0x2c')],'type':_0x3f7e33[_0xa9e1('0x2d')][_0xa9e1('0x2e')]};});_0x4bf37b[_0xa9e1('0x2f')]=_[_0xa9e1('0x30')](_0x4de6d7,'name');_0x4bf37b[_0xa9e1('0x31')]=_[_0xa9e1('0x32')](_0x375486['query']);_0x4bf37b[_0xa9e1('0x33')]=_['intersection'](_0x4bf37b[_0xa9e1('0x2f')],_0x4bf37b[_0xa9e1('0x31')]);_0x1c477c['attributes']=_[_0xa9e1('0x34')](_0x4bf37b[_0xa9e1('0x2f')],qs['fields'](_0x375486['query'][_0xa9e1('0x35')]));_0x1c477c[_0xa9e1('0x36')]=_0x1c477c[_0xa9e1('0x36')]['length']?_0x1c477c[_0xa9e1('0x36')]:_0x4bf37b['model'];if(!_0x375486[_0xa9e1('0x31')][_0xa9e1('0x37')](_0xa9e1('0x38'))){_0x1c477c['limit']=qs[_0xa9e1('0x1e')](_0x375486[_0xa9e1('0x31')][_0xa9e1('0x1e')]);_0x1c477c['offset']=qs[_0xa9e1('0x1c')](_0x375486['query'][_0xa9e1('0x1c')]);}_0x1c477c[_0xa9e1('0x39')]=qs[_0xa9e1('0x3a')](_0x375486[_0xa9e1('0x31')]['sort']);_0x1c477c[_0xa9e1('0x3b')]=qs[_0xa9e1('0x33')](_['pick'](_0x375486[_0xa9e1('0x31')],_0x4bf37b[_0xa9e1('0x33')]),_0x4de6d7);if(_0x375486[_0xa9e1('0x31')][_0xa9e1('0x3c')]){_0x1c477c[_0xa9e1('0x3b')]=_['merge'](_0x1c477c[_0xa9e1('0x3b')],{'$or':_[_0xa9e1('0x30')](_0x4de6d7,function(_0x12cfaa){if(_0x12cfaa[_0xa9e1('0x2d')]!==_0xa9e1('0x3d')){var _0x3d7561={};_0x3d7561[_0x12cfaa['name']]={'$like':'%'+_0x375486[_0xa9e1('0x31')][_0xa9e1('0x3c')]+'%'};return _0x3d7561;}})});}_0x1c477c=_[_0xa9e1('0x3e')]({},_0x1c477c,_0x375486['options']);var _0x4befe6={'where':_0x1c477c['where']};return db[_0xa9e1('0x2a')]['count'](_0x4befe6)[_0xa9e1('0x24')](function(_0x46eabd){_0x5c2819[_0xa9e1('0x1f')]=_0x46eabd;if(_0x375486['query'][_0xa9e1('0x3f')]){_0x1c477c['include']=[{'all':!![]}];}return db[_0xa9e1('0x2a')]['findAll'](_0x1c477c);})[_0xa9e1('0x24')](function(_0x2abd8c){_0x5c2819[_0xa9e1('0x40')]=_0x2abd8c;return _0x5c2819;})[_0xa9e1('0x24')](respondWithFilteredResult(_0x495669,_0x1c477c))[_0xa9e1('0x41')](handleError(_0x495669,null));};exports[_0xa9e1('0x42')]=function(_0x85692d,_0x43d9db){var _0x1b4dd4={'raw':!![],'where':{'id':_0x85692d[_0xa9e1('0x43')]['id']}},_0x89eaa9={};_0x89eaa9[_0xa9e1('0x2f')]=_[_0xa9e1('0x32')](db['WhatsappTransferReport']['rawAttributes']);_0x89eaa9['query']=_[_0xa9e1('0x32')](_0x85692d['query']);_0x89eaa9[_0xa9e1('0x33')]=_[_0xa9e1('0x34')](_0x89eaa9[_0xa9e1('0x2f')],_0x89eaa9[_0xa9e1('0x31')]);_0x1b4dd4[_0xa9e1('0x36')]=_['intersection'](_0x89eaa9[_0xa9e1('0x2f')],qs[_0xa9e1('0x35')](_0x85692d['query'][_0xa9e1('0x35')]));_0x1b4dd4[_0xa9e1('0x36')]=_0x1b4dd4[_0xa9e1('0x36')][_0xa9e1('0x44')]?_0x1b4dd4[_0xa9e1('0x36')]:_0x89eaa9[_0xa9e1('0x2f')];if(_0x85692d[_0xa9e1('0x31')][_0xa9e1('0x3f')]){_0x1b4dd4[_0xa9e1('0x45')]=[{'all':!![]}];}_0x1b4dd4=_[_0xa9e1('0x3e')]({},_0x1b4dd4,_0x85692d['options']);return db[_0xa9e1('0x2a')]['find'](_0x1b4dd4)[_0xa9e1('0x24')](handleEntityNotFound(_0x43d9db,null))[_0xa9e1('0x24')](respondWithResult(_0x43d9db,null))[_0xa9e1('0x41')](handleError(_0x43d9db,null));};exports[_0xa9e1('0x46')]=function(_0x2763ad,_0x1f3d9e){return db['WhatsappTransferReport'][_0xa9e1('0x46')](_0x2763ad[_0xa9e1('0x47')],{})[_0xa9e1('0x24')](respondWithResult(_0x1f3d9e,0xc9))[_0xa9e1('0x41')](handleError(_0x1f3d9e,null));};exports[_0xa9e1('0x23')]=function(_0x504e58,_0x46213a){if(_0x504e58['body']['id']){delete _0x504e58[_0xa9e1('0x47')]['id'];}return db['WhatsappTransferReport'][_0xa9e1('0x48')]({'where':{'id':_0x504e58['params']['id']}})[_0xa9e1('0x24')](handleEntityNotFound(_0x46213a,null))['then'](saveUpdates(_0x504e58[_0xa9e1('0x47')],null))['then'](respondWithResult(_0x46213a,null))[_0xa9e1('0x41')](handleError(_0x46213a,null));};exports[_0xa9e1('0x25')]=function(_0x150ca5,_0x7e9415){return db[_0xa9e1('0x2a')]['find']({'where':{'id':_0x150ca5['params']['id']}})[_0xa9e1('0x24')](handleEntityNotFound(_0x7e9415,null))[_0xa9e1('0x24')](removeEntity(_0x7e9415,null))[_0xa9e1('0x41')](handleError(_0x7e9415,null));};exports['describe']=function(_0x5105b9,_0x27a013){return db[_0xa9e1('0x2a')]['describe']()[_0xa9e1('0x24')](respondWithResult(_0x27a013,null))[_0xa9e1('0x41')](handleError(_0x27a013,null));};