6b3d52d85fe96cf27641db6c1cd3962d575c787a
[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 _0x6b5f=['rawAttributes','find','create','body','describe','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','ejs','fs-extra','lodash','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','limit','undefined','count','offset','Content-Range','json','apply','save','update','destroy','then','stack','name','send','index','map','type','key','query','filters','intersection','model','attributes','fields','length','order','sort','where','merge','filter','options','includeAll','include','catch','show','params','keys','WhatsappTransferReport'];(function(_0x3902c1,_0x1c9eb2){var _0x1266cc=function(_0x50c2c5){while(--_0x50c2c5){_0x3902c1['push'](_0x3902c1['shift']());}};_0x1266cc(++_0x1c9eb2);}(_0x6b5f,0x119));var _0xf6b5=function(_0x80f4eb,_0x11aca3){_0x80f4eb=_0x80f4eb-0x0;var _0xaf0a97=_0x6b5f[_0x80f4eb];return _0xaf0a97;};'use strict';var emlformat=require(_0xf6b5('0x0'));var rimraf=require(_0xf6b5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf6b5('0x2'));var rp=require(_0xf6b5('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf6b5('0x4'));var util=require(_0xf6b5('0x5'));var path=require(_0xf6b5('0x6'));var sox=require(_0xf6b5('0x7'));var csv=require('to-csv');var ejs=require(_0xf6b5('0x8'));var fs=require('fs');var fs_extra=require(_0xf6b5('0x9'));var _=require(_0xf6b5('0xa'));var squel=require('squel');var crypto=require(_0xf6b5('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf6b5('0xc'));var toCsv=require(_0xf6b5('0xd'));var querystring=require(_0xf6b5('0xe'));var Papa=require(_0xf6b5('0xf'));var Redis=require(_0xf6b5('0x10'));var authService=require(_0xf6b5('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf6b5('0x12'));var logger=require(_0xf6b5('0x13'))(_0xf6b5('0x14'));var utils=require(_0xf6b5('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xf6b5('0x16'))['db'];function respondWithStatusCode(_0x4eb544,_0x57e3c8){_0x57e3c8=_0x57e3c8||0xcc;return function(_0x43d411){if(_0x43d411){return _0x4eb544[_0xf6b5('0x17')](_0x57e3c8);}return _0x4eb544[_0xf6b5('0x18')](_0x57e3c8)[_0xf6b5('0x19')]();};}function respondWithResult(_0x1659c0,_0x3831f2){_0x3831f2=_0x3831f2||0xc8;return function(_0x2805dc){if(_0x2805dc){return _0x1659c0[_0xf6b5('0x18')](_0x3831f2)['json'](_0x2805dc);}};}function respondWithFilteredResult(_0x40dacd,_0x19f154){return function(_0x43da20){if(_0x43da20){var _0x30e251=typeof _0x19f154['offset']==='undefined'&&typeof _0x19f154[_0xf6b5('0x1a')]===_0xf6b5('0x1b');var _0x28486c=_0x43da20[_0xf6b5('0x1c')];var _0x34b8a2=_0x30e251?0x0:_0x19f154[_0xf6b5('0x1d')];var _0x5454a4=_0x30e251?_0x43da20[_0xf6b5('0x1c')]:_0x19f154[_0xf6b5('0x1d')]+_0x19f154[_0xf6b5('0x1a')];var _0x1c4b53;if(_0x5454a4>=_0x28486c){_0x5454a4=_0x28486c;_0x1c4b53=0xc8;}else{_0x1c4b53=0xce;}_0x40dacd[_0xf6b5('0x18')](_0x1c4b53);return _0x40dacd['set'](_0xf6b5('0x1e'),_0x34b8a2+'-'+_0x5454a4+'/'+_0x28486c)[_0xf6b5('0x1f')](_0x43da20);}return null;};}function patchUpdates(_0x32f277){return function(_0x4a7a99){try{jsonpatch[_0xf6b5('0x20')](_0x4a7a99,_0x32f277,!![]);}catch(_0x1ec561){return BPromise['reject'](_0x1ec561);}return _0x4a7a99[_0xf6b5('0x21')]();};}function saveUpdates(_0x3d2f77,_0x39ec12){return function(_0x4fc236){if(_0x4fc236){return _0x4fc236[_0xf6b5('0x22')](_0x3d2f77)['then'](function(_0x497461){return _0x497461;});}return null;};}function removeEntity(_0x554b16,_0x4b206f){return function(_0x3417cd){if(_0x3417cd){return _0x3417cd[_0xf6b5('0x23')]()[_0xf6b5('0x24')](function(){_0x554b16['status'](0xcc)[_0xf6b5('0x19')]();});}};}function handleEntityNotFound(_0x1d0dea,_0x646f87){return function(_0x4a2ab3){if(!_0x4a2ab3){_0x1d0dea[_0xf6b5('0x17')](0x194);}return _0x4a2ab3;};}function handleError(_0x179007,_0x31d4db){_0x31d4db=_0x31d4db||0x1f4;return function(_0xb2cda0){logger['error'](_0xb2cda0[_0xf6b5('0x25')]);if(_0xb2cda0[_0xf6b5('0x26')]){delete _0xb2cda0['name'];}_0x179007[_0xf6b5('0x18')](_0x31d4db)[_0xf6b5('0x27')](_0xb2cda0);};}exports[_0xf6b5('0x28')]=function(_0x220c63,_0x35f61e){var _0x3fa73f={},_0x379cac={},_0x54da37={'count':0x0,'rows':[]};var _0x21ac21=_[_0xf6b5('0x29')](db['WhatsappTransferReport']['rawAttributes'],function(_0x176b8e){return{'name':_0x176b8e['fieldName'],'type':_0x176b8e[_0xf6b5('0x2a')][_0xf6b5('0x2b')]};});_0x379cac['model']=_[_0xf6b5('0x29')](_0x21ac21,_0xf6b5('0x26'));_0x379cac[_0xf6b5('0x2c')]=_['keys'](_0x220c63['query']);_0x379cac[_0xf6b5('0x2d')]=_[_0xf6b5('0x2e')](_0x379cac[_0xf6b5('0x2f')],_0x379cac[_0xf6b5('0x2c')]);_0x3fa73f[_0xf6b5('0x30')]=_[_0xf6b5('0x2e')](_0x379cac[_0xf6b5('0x2f')],qs[_0xf6b5('0x31')](_0x220c63[_0xf6b5('0x2c')]['fields']));_0x3fa73f['attributes']=_0x3fa73f[_0xf6b5('0x30')][_0xf6b5('0x32')]?_0x3fa73f[_0xf6b5('0x30')]:_0x379cac[_0xf6b5('0x2f')];if(!_0x220c63[_0xf6b5('0x2c')]['hasOwnProperty']('nolimit')){_0x3fa73f['limit']=qs[_0xf6b5('0x1a')](_0x220c63[_0xf6b5('0x2c')][_0xf6b5('0x1a')]);_0x3fa73f[_0xf6b5('0x1d')]=qs['offset'](_0x220c63[_0xf6b5('0x2c')]['offset']);}_0x3fa73f[_0xf6b5('0x33')]=qs[_0xf6b5('0x34')](_0x220c63[_0xf6b5('0x2c')][_0xf6b5('0x34')]);_0x3fa73f[_0xf6b5('0x35')]=qs[_0xf6b5('0x2d')](_['pick'](_0x220c63['query'],_0x379cac[_0xf6b5('0x2d')]),_0x21ac21);if(_0x220c63[_0xf6b5('0x2c')]['filter']){_0x3fa73f[_0xf6b5('0x35')]=_[_0xf6b5('0x36')](_0x3fa73f[_0xf6b5('0x35')],{'$or':_[_0xf6b5('0x29')](_0x21ac21,function(_0x156b46){if(_0x156b46['type']!=='VIRTUAL'){var _0xb115df={};_0xb115df[_0x156b46[_0xf6b5('0x26')]]={'$like':'%'+_0x220c63[_0xf6b5('0x2c')][_0xf6b5('0x37')]+'%'};return _0xb115df;}})});}_0x3fa73f=_['merge']({},_0x3fa73f,_0x220c63[_0xf6b5('0x38')]);var _0x56dceb={'where':_0x3fa73f[_0xf6b5('0x35')]};return db['WhatsappTransferReport']['count'](_0x56dceb)[_0xf6b5('0x24')](function(_0x3d0ed4){_0x54da37[_0xf6b5('0x1c')]=_0x3d0ed4;if(_0x220c63[_0xf6b5('0x2c')][_0xf6b5('0x39')]){_0x3fa73f[_0xf6b5('0x3a')]=[{'all':!![]}];}return db['WhatsappTransferReport']['findAll'](_0x3fa73f);})[_0xf6b5('0x24')](function(_0x55088c){_0x54da37['rows']=_0x55088c;return _0x54da37;})['then'](respondWithFilteredResult(_0x35f61e,_0x3fa73f))[_0xf6b5('0x3b')](handleError(_0x35f61e,null));};exports[_0xf6b5('0x3c')]=function(_0xb82837,_0x14eeb5){var _0x378026={'raw':!![],'where':{'id':_0xb82837[_0xf6b5('0x3d')]['id']}},_0x3047c6={};_0x3047c6[_0xf6b5('0x2f')]=_[_0xf6b5('0x3e')](db[_0xf6b5('0x3f')][_0xf6b5('0x40')]);_0x3047c6[_0xf6b5('0x2c')]=_[_0xf6b5('0x3e')](_0xb82837['query']);_0x3047c6[_0xf6b5('0x2d')]=_[_0xf6b5('0x2e')](_0x3047c6['model'],_0x3047c6['query']);_0x378026[_0xf6b5('0x30')]=_[_0xf6b5('0x2e')](_0x3047c6[_0xf6b5('0x2f')],qs['fields'](_0xb82837[_0xf6b5('0x2c')][_0xf6b5('0x31')]));_0x378026[_0xf6b5('0x30')]=_0x378026[_0xf6b5('0x30')][_0xf6b5('0x32')]?_0x378026[_0xf6b5('0x30')]:_0x3047c6[_0xf6b5('0x2f')];if(_0xb82837[_0xf6b5('0x2c')]['includeAll']){_0x378026[_0xf6b5('0x3a')]=[{'all':!![]}];}_0x378026=_[_0xf6b5('0x36')]({},_0x378026,_0xb82837[_0xf6b5('0x38')]);return db['WhatsappTransferReport'][_0xf6b5('0x41')](_0x378026)['then'](handleEntityNotFound(_0x14eeb5,null))[_0xf6b5('0x24')](respondWithResult(_0x14eeb5,null))['catch'](handleError(_0x14eeb5,null));};exports[_0xf6b5('0x42')]=function(_0x2fe1,_0x5c73a9){return db[_0xf6b5('0x3f')]['create'](_0x2fe1[_0xf6b5('0x43')],{})[_0xf6b5('0x24')](respondWithResult(_0x5c73a9,0xc9))['catch'](handleError(_0x5c73a9,null));};exports[_0xf6b5('0x22')]=function(_0x294100,_0x560991){if(_0x294100[_0xf6b5('0x43')]['id']){delete _0x294100[_0xf6b5('0x43')]['id'];}return db[_0xf6b5('0x3f')][_0xf6b5('0x41')]({'where':{'id':_0x294100['params']['id']}})['then'](handleEntityNotFound(_0x560991,null))[_0xf6b5('0x24')](saveUpdates(_0x294100['body'],null))[_0xf6b5('0x24')](respondWithResult(_0x560991,null))[_0xf6b5('0x3b')](handleError(_0x560991,null));};exports[_0xf6b5('0x23')]=function(_0x4b66fd,_0x5d1318){return db[_0xf6b5('0x3f')][_0xf6b5('0x41')]({'where':{'id':_0x4b66fd[_0xf6b5('0x3d')]['id']}})[_0xf6b5('0x24')](handleEntityNotFound(_0x5d1318,null))['then'](removeEntity(_0x5d1318,null))[_0xf6b5('0x3b')](handleError(_0x5d1318,null));};exports['describe']=function(_0x9f8c64,_0x1f5b4d){return db[_0xf6b5('0x3f')][_0xf6b5('0x44')]()[_0xf6b5('0x24')](respondWithResult(_0x1f5b4d,null))['catch'](handleError(_0x1f5b4d,null));};