Built motion from commit 9e1ec266.|2.6.28
[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 _0xfc0c=['../../mysqldb','sendStatus','end','status','offset','undefined','limit','count','set','json','reject','save','update','then','destroy','error','stack','name','rawAttributes','fieldName','type','key','model','map','query','keys','intersection','attributes','fields','length','nolimit','sort','where','filters','pick','merge','VIRTUAL','filter','options','WhatsappTransferReport','include','findAll','catch','params','includeAll','find','create','body','describe','rimraf','zip-dir','request-promise','mustache','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util'];(function(_0x4b90f8,_0x3a3331){var _0x3723f3=function(_0x4b6d7f){while(--_0x4b6d7f){_0x4b90f8['push'](_0x4b90f8['shift']());}};_0x3723f3(++_0x3a3331);}(_0xfc0c,0x103));var _0xcfc0=function(_0x43dec1,_0x53f198){_0x43dec1=_0x43dec1-0x0;var _0x5ca575=_0xfc0c[_0x43dec1];return _0x5ca575;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcfc0('0x0'));var zipdir=require(_0xcfc0('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xcfc0('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xcfc0('0x3'));var util=require(_0xcfc0('0x4'));var path=require(_0xcfc0('0x5'));var sox=require(_0xcfc0('0x6'));var csv=require(_0xcfc0('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xcfc0('0x8'));var _=require(_0xcfc0('0x9'));var squel=require('squel');var crypto=require(_0xcfc0('0xa'));var jsforce=require(_0xcfc0('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xcfc0('0x7'));var querystring=require('querystring');var Papa=require(_0xcfc0('0xc'));var Redis=require(_0xcfc0('0xd'));var authService=require(_0xcfc0('0xe'));var qs=require(_0xcfc0('0xf'));var as=require(_0xcfc0('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xcfc0('0x11'))('api');var utils=require(_0xcfc0('0x12'));var config=require(_0xcfc0('0x13'));var licenseUtil=require(_0xcfc0('0x14'));var db=require(_0xcfc0('0x15'))['db'];function respondWithStatusCode(_0x245bc8,_0x5bd9e5){_0x5bd9e5=_0x5bd9e5||0xcc;return function(_0x14892f){if(_0x14892f){return _0x245bc8[_0xcfc0('0x16')](_0x5bd9e5);}return _0x245bc8['status'](_0x5bd9e5)[_0xcfc0('0x17')]();};}function respondWithResult(_0x32d2fb,_0x12f305){_0x12f305=_0x12f305||0xc8;return function(_0x132ed0){if(_0x132ed0){return _0x32d2fb[_0xcfc0('0x18')](_0x12f305)['json'](_0x132ed0);}};}function respondWithFilteredResult(_0x355b56,_0x1ecece){return function(_0x221515){if(_0x221515){var _0x478d61=typeof _0x1ecece[_0xcfc0('0x19')]===_0xcfc0('0x1a')&&typeof _0x1ecece[_0xcfc0('0x1b')]==='undefined';var _0x42624a=_0x221515[_0xcfc0('0x1c')];var _0x429b20=_0x478d61?0x0:_0x1ecece['offset'];var _0x3e7065=_0x478d61?_0x221515[_0xcfc0('0x1c')]:_0x1ecece[_0xcfc0('0x19')]+_0x1ecece['limit'];var _0x193f5e;if(_0x3e7065>=_0x42624a){_0x3e7065=_0x42624a;_0x193f5e=0xc8;}else{_0x193f5e=0xce;}_0x355b56[_0xcfc0('0x18')](_0x193f5e);return _0x355b56[_0xcfc0('0x1d')]('Content-Range',_0x429b20+'-'+_0x3e7065+'/'+_0x42624a)[_0xcfc0('0x1e')](_0x221515);}return null;};}function patchUpdates(_0x4fa2f8){return function(_0x365d20){try{jsonpatch['apply'](_0x365d20,_0x4fa2f8,!![]);}catch(_0x1d136c){return BPromise[_0xcfc0('0x1f')](_0x1d136c);}return _0x365d20[_0xcfc0('0x20')]();};}function saveUpdates(_0x2ac41a,_0x3e5358){return function(_0x3be8f2){if(_0x3be8f2){return _0x3be8f2[_0xcfc0('0x21')](_0x2ac41a)[_0xcfc0('0x22')](function(_0x36b6bb){return _0x36b6bb;});}return null;};}function removeEntity(_0x265a75,_0x3f43d4){return function(_0x5f4f2e){if(_0x5f4f2e){return _0x5f4f2e[_0xcfc0('0x23')]()[_0xcfc0('0x22')](function(){_0x265a75['status'](0xcc)[_0xcfc0('0x17')]();});}};}function handleEntityNotFound(_0xb42a0b,_0xa52a43){return function(_0x57f3cc){if(!_0x57f3cc){_0xb42a0b['sendStatus'](0x194);}return _0x57f3cc;};}function handleError(_0x14457a,_0x35962d){_0x35962d=_0x35962d||0x1f4;return function(_0x32c99e){logger[_0xcfc0('0x24')](_0x32c99e[_0xcfc0('0x25')]);if(_0x32c99e[_0xcfc0('0x26')]){delete _0x32c99e[_0xcfc0('0x26')];}_0x14457a[_0xcfc0('0x18')](_0x35962d)['send'](_0x32c99e);};}exports['index']=function(_0x7388e4,_0x2d5587){var _0x31a4fc={},_0x32fb3b={},_0x57d132={'count':0x0,'rows':[]};var _0xa0bb8f=_['map'](db['WhatsappTransferReport'][_0xcfc0('0x27')],function(_0x5a4f72){return{'name':_0x5a4f72[_0xcfc0('0x28')],'type':_0x5a4f72[_0xcfc0('0x29')][_0xcfc0('0x2a')]};});_0x32fb3b[_0xcfc0('0x2b')]=_[_0xcfc0('0x2c')](_0xa0bb8f,'name');_0x32fb3b[_0xcfc0('0x2d')]=_[_0xcfc0('0x2e')](_0x7388e4[_0xcfc0('0x2d')]);_0x32fb3b['filters']=_[_0xcfc0('0x2f')](_0x32fb3b[_0xcfc0('0x2b')],_0x32fb3b[_0xcfc0('0x2d')]);_0x31a4fc[_0xcfc0('0x30')]=_[_0xcfc0('0x2f')](_0x32fb3b[_0xcfc0('0x2b')],qs[_0xcfc0('0x31')](_0x7388e4[_0xcfc0('0x2d')][_0xcfc0('0x31')]));_0x31a4fc[_0xcfc0('0x30')]=_0x31a4fc[_0xcfc0('0x30')][_0xcfc0('0x32')]?_0x31a4fc[_0xcfc0('0x30')]:_0x32fb3b[_0xcfc0('0x2b')];if(!_0x7388e4[_0xcfc0('0x2d')]['hasOwnProperty'](_0xcfc0('0x33'))){_0x31a4fc[_0xcfc0('0x1b')]=qs[_0xcfc0('0x1b')](_0x7388e4[_0xcfc0('0x2d')][_0xcfc0('0x1b')]);_0x31a4fc[_0xcfc0('0x19')]=qs[_0xcfc0('0x19')](_0x7388e4[_0xcfc0('0x2d')][_0xcfc0('0x19')]);}_0x31a4fc['order']=qs[_0xcfc0('0x34')](_0x7388e4['query'][_0xcfc0('0x34')]);_0x31a4fc[_0xcfc0('0x35')]=qs[_0xcfc0('0x36')](_[_0xcfc0('0x37')](_0x7388e4['query'],_0x32fb3b['filters']),_0xa0bb8f);if(_0x7388e4[_0xcfc0('0x2d')]['filter']){_0x31a4fc[_0xcfc0('0x35')]=_[_0xcfc0('0x38')](_0x31a4fc[_0xcfc0('0x35')],{'$or':_[_0xcfc0('0x2c')](_0xa0bb8f,function(_0x96fc3c){if(_0x96fc3c['type']!==_0xcfc0('0x39')){var _0x215098={};_0x215098[_0x96fc3c['name']]={'$like':'%'+_0x7388e4[_0xcfc0('0x2d')][_0xcfc0('0x3a')]+'%'};return _0x215098;}})});}_0x31a4fc=_['merge']({},_0x31a4fc,_0x7388e4[_0xcfc0('0x3b')]);var _0x4cc920={'where':_0x31a4fc[_0xcfc0('0x35')]};return db[_0xcfc0('0x3c')][_0xcfc0('0x1c')](_0x4cc920)[_0xcfc0('0x22')](function(_0x4e9451){_0x57d132[_0xcfc0('0x1c')]=_0x4e9451;if(_0x7388e4[_0xcfc0('0x2d')]['includeAll']){_0x31a4fc[_0xcfc0('0x3d')]=[{'all':!![]}];}return db[_0xcfc0('0x3c')][_0xcfc0('0x3e')](_0x31a4fc);})['then'](function(_0x253839){_0x57d132['rows']=_0x253839;return _0x57d132;})['then'](respondWithFilteredResult(_0x2d5587,_0x31a4fc))[_0xcfc0('0x3f')](handleError(_0x2d5587,null));};exports['show']=function(_0x9ca0bf,_0x2c402c){var _0x4b6d44={'raw':!![],'where':{'id':_0x9ca0bf[_0xcfc0('0x40')]['id']}},_0x51e26a={};_0x51e26a[_0xcfc0('0x2b')]=_[_0xcfc0('0x2e')](db['WhatsappTransferReport'][_0xcfc0('0x27')]);_0x51e26a['query']=_[_0xcfc0('0x2e')](_0x9ca0bf[_0xcfc0('0x2d')]);_0x51e26a[_0xcfc0('0x36')]=_[_0xcfc0('0x2f')](_0x51e26a[_0xcfc0('0x2b')],_0x51e26a[_0xcfc0('0x2d')]);_0x4b6d44[_0xcfc0('0x30')]=_[_0xcfc0('0x2f')](_0x51e26a[_0xcfc0('0x2b')],qs[_0xcfc0('0x31')](_0x9ca0bf[_0xcfc0('0x2d')]['fields']));_0x4b6d44[_0xcfc0('0x30')]=_0x4b6d44[_0xcfc0('0x30')][_0xcfc0('0x32')]?_0x4b6d44[_0xcfc0('0x30')]:_0x51e26a['model'];if(_0x9ca0bf[_0xcfc0('0x2d')][_0xcfc0('0x41')]){_0x4b6d44['include']=[{'all':!![]}];}_0x4b6d44=_[_0xcfc0('0x38')]({},_0x4b6d44,_0x9ca0bf[_0xcfc0('0x3b')]);return db[_0xcfc0('0x3c')][_0xcfc0('0x42')](_0x4b6d44)[_0xcfc0('0x22')](handleEntityNotFound(_0x2c402c,null))[_0xcfc0('0x22')](respondWithResult(_0x2c402c,null))[_0xcfc0('0x3f')](handleError(_0x2c402c,null));};exports[_0xcfc0('0x43')]=function(_0x786397,_0x101a15){return db[_0xcfc0('0x3c')][_0xcfc0('0x43')](_0x786397['body'],{})['then'](respondWithResult(_0x101a15,0xc9))[_0xcfc0('0x3f')](handleError(_0x101a15,null));};exports[_0xcfc0('0x21')]=function(_0x3de97e,_0x1f06dd){if(_0x3de97e[_0xcfc0('0x44')]['id']){delete _0x3de97e[_0xcfc0('0x44')]['id'];}return db[_0xcfc0('0x3c')][_0xcfc0('0x42')]({'where':{'id':_0x3de97e[_0xcfc0('0x40')]['id']}})[_0xcfc0('0x22')](handleEntityNotFound(_0x1f06dd,null))[_0xcfc0('0x22')](saveUpdates(_0x3de97e[_0xcfc0('0x44')],null))[_0xcfc0('0x22')](respondWithResult(_0x1f06dd,null))[_0xcfc0('0x3f')](handleError(_0x1f06dd,null));};exports[_0xcfc0('0x23')]=function(_0x35c442,_0x28ad72){return db[_0xcfc0('0x3c')][_0xcfc0('0x42')]({'where':{'id':_0x35c442[_0xcfc0('0x40')]['id']}})[_0xcfc0('0x22')](handleEntityNotFound(_0x28ad72,null))[_0xcfc0('0x22')](removeEntity(_0x28ad72,null))[_0xcfc0('0x3f')](handleError(_0x28ad72,null));};exports[_0xcfc0('0x45')]=function(_0x3bea43,_0x1a680c){return db[_0xcfc0('0x3c')][_0xcfc0('0x45')]()[_0xcfc0('0x22')](respondWithResult(_0x1a680c,null))['catch'](handleError(_0x1a680c,null));};