Built motion from commit 47436d59.|2.6.7
[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 _0x3cdb=['create','body','find','params','destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','fs-extra','lodash','squel','crypto','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','WhatsappTransferReport','rawAttributes','key','map','query','filters','intersection','attributes','model','length','hasOwnProperty','order','sort','where','pick','merge','type','VIRTUAL','filter','options','count','includeAll','rows','catch','show','keys','fields','include'];(function(_0x822c4b,_0xd2e559){var _0x441bfc=function(_0x1f156b){while(--_0x1f156b){_0x822c4b['push'](_0x822c4b['shift']());}};_0x441bfc(++_0xd2e559);}(_0x3cdb,0xa6));var _0xb3cd=function(_0x3818c0,_0x542521){_0x3818c0=_0x3818c0-0x0;var _0x55ec33=_0x3cdb[_0x3818c0];return _0x55ec33;};'use strict';var emlformat=require(_0xb3cd('0x0'));var rimraf=require(_0xb3cd('0x1'));var zipdir=require(_0xb3cd('0x2'));var jsonpatch=require(_0xb3cd('0x3'));var rp=require(_0xb3cd('0x4'));var moment=require(_0xb3cd('0x5'));var BPromise=require(_0xb3cd('0x6'));var Mustache=require(_0xb3cd('0x7'));var util=require(_0xb3cd('0x8'));var path=require('path');var sox=require(_0xb3cd('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb3cd('0xa'));var _=require(_0xb3cd('0xb'));var squel=require(_0xb3cd('0xc'));var crypto=require(_0xb3cd('0xd'));var jsforce=require(_0xb3cd('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xb3cd('0xf'));var querystring=require('querystring');var Papa=require(_0xb3cd('0x10'));var Redis=require(_0xb3cd('0x11'));var authService=require(_0xb3cd('0x12'));var qs=require(_0xb3cd('0x13'));var as=require(_0xb3cd('0x14'));var hardwareService=require(_0xb3cd('0x15'));var logger=require(_0xb3cd('0x16'))(_0xb3cd('0x17'));var utils=require(_0xb3cd('0x18'));var config=require(_0xb3cd('0x19'));var licenseUtil=require(_0xb3cd('0x1a'));var db=require(_0xb3cd('0x1b'))['db'];function respondWithStatusCode(_0x13b479,_0x339a46){_0x339a46=_0x339a46||0xcc;return function(_0x480c34){if(_0x480c34){return _0x13b479[_0xb3cd('0x1c')](_0x339a46);}return _0x13b479[_0xb3cd('0x1d')](_0x339a46)[_0xb3cd('0x1e')]();};}function respondWithResult(_0x1ebe2c,_0x443c6a){_0x443c6a=_0x443c6a||0xc8;return function(_0x597137){if(_0x597137){return _0x1ebe2c['status'](_0x443c6a)[_0xb3cd('0x1f')](_0x597137);}};}function respondWithFilteredResult(_0x1dafce,_0x2bb89a){return function(_0x3e43a9){if(_0x3e43a9){var _0x56b7ec=typeof _0x2bb89a[_0xb3cd('0x20')]==='undefined'&&typeof _0x2bb89a[_0xb3cd('0x21')]==='undefined';var _0x523aca=_0x3e43a9['count'];var _0x6d31e1=_0x56b7ec?0x0:_0x2bb89a[_0xb3cd('0x20')];var _0x1b681f=_0x56b7ec?_0x3e43a9['count']:_0x2bb89a[_0xb3cd('0x20')]+_0x2bb89a['limit'];var _0x4a4446;if(_0x1b681f>=_0x523aca){_0x1b681f=_0x523aca;_0x4a4446=0xc8;}else{_0x4a4446=0xce;}_0x1dafce[_0xb3cd('0x1d')](_0x4a4446);return _0x1dafce[_0xb3cd('0x22')](_0xb3cd('0x23'),_0x6d31e1+'-'+_0x1b681f+'/'+_0x523aca)[_0xb3cd('0x1f')](_0x3e43a9);}return null;};}function patchUpdates(_0x3236cd){return function(_0x5cbb83){try{jsonpatch[_0xb3cd('0x24')](_0x5cbb83,_0x3236cd,!![]);}catch(_0x1698db){return BPromise[_0xb3cd('0x25')](_0x1698db);}return _0x5cbb83[_0xb3cd('0x26')]();};}function saveUpdates(_0x19fb16,_0xfbcb3b){return function(_0x1960dd){if(_0x1960dd){return _0x1960dd[_0xb3cd('0x27')](_0x19fb16)[_0xb3cd('0x28')](function(_0x4acac2){return _0x4acac2;});}return null;};}function removeEntity(_0x11475f,_0x15bfa7){return function(_0x620246){if(_0x620246){return _0x620246['destroy']()['then'](function(){_0x11475f[_0xb3cd('0x1d')](0xcc)[_0xb3cd('0x1e')]();});}};}function handleEntityNotFound(_0x2871b1,_0x284f2a){return function(_0x522058){if(!_0x522058){_0x2871b1[_0xb3cd('0x1c')](0x194);}return _0x522058;};}function handleError(_0x55a763,_0x5d31d){_0x5d31d=_0x5d31d||0x1f4;return function(_0x5b156f){logger[_0xb3cd('0x29')](_0x5b156f[_0xb3cd('0x2a')]);if(_0x5b156f[_0xb3cd('0x2b')]){delete _0x5b156f['name'];}_0x55a763['status'](_0x5d31d)[_0xb3cd('0x2c')](_0x5b156f);};}exports[_0xb3cd('0x2d')]=function(_0x588e1f,_0x26c58c){var _0x4f3561={},_0x14371b={},_0x46fe69={'count':0x0,'rows':[]};var _0x5c78d2=_['map'](db[_0xb3cd('0x2e')][_0xb3cd('0x2f')],function(_0x4436ed){return{'name':_0x4436ed['fieldName'],'type':_0x4436ed['type'][_0xb3cd('0x30')]};});_0x14371b['model']=_[_0xb3cd('0x31')](_0x5c78d2,'name');_0x14371b[_0xb3cd('0x32')]=_['keys'](_0x588e1f['query']);_0x14371b[_0xb3cd('0x33')]=_[_0xb3cd('0x34')](_0x14371b['model'],_0x14371b['query']);_0x4f3561[_0xb3cd('0x35')]=_['intersection'](_0x14371b[_0xb3cd('0x36')],qs['fields'](_0x588e1f[_0xb3cd('0x32')]['fields']));_0x4f3561['attributes']=_0x4f3561['attributes'][_0xb3cd('0x37')]?_0x4f3561['attributes']:_0x14371b[_0xb3cd('0x36')];if(!_0x588e1f[_0xb3cd('0x32')][_0xb3cd('0x38')]('nolimit')){_0x4f3561[_0xb3cd('0x21')]=qs[_0xb3cd('0x21')](_0x588e1f[_0xb3cd('0x32')]['limit']);_0x4f3561[_0xb3cd('0x20')]=qs[_0xb3cd('0x20')](_0x588e1f['query'][_0xb3cd('0x20')]);}_0x4f3561[_0xb3cd('0x39')]=qs[_0xb3cd('0x3a')](_0x588e1f[_0xb3cd('0x32')][_0xb3cd('0x3a')]);_0x4f3561[_0xb3cd('0x3b')]=qs[_0xb3cd('0x33')](_[_0xb3cd('0x3c')](_0x588e1f['query'],_0x14371b[_0xb3cd('0x33')]),_0x5c78d2);if(_0x588e1f[_0xb3cd('0x32')]['filter']){_0x4f3561['where']=_[_0xb3cd('0x3d')](_0x4f3561['where'],{'$or':_[_0xb3cd('0x31')](_0x5c78d2,function(_0x246662){if(_0x246662[_0xb3cd('0x3e')]!==_0xb3cd('0x3f')){var _0xdc4269={};_0xdc4269[_0x246662['name']]={'$like':'%'+_0x588e1f[_0xb3cd('0x32')][_0xb3cd('0x40')]+'%'};return _0xdc4269;}})});}_0x4f3561=_[_0xb3cd('0x3d')]({},_0x4f3561,_0x588e1f[_0xb3cd('0x41')]);var _0x183351={'where':_0x4f3561[_0xb3cd('0x3b')]};return db[_0xb3cd('0x2e')][_0xb3cd('0x42')](_0x183351)['then'](function(_0x531e45){_0x46fe69['count']=_0x531e45;if(_0x588e1f[_0xb3cd('0x32')][_0xb3cd('0x43')]){_0x4f3561['include']=[{'all':!![]}];}return db[_0xb3cd('0x2e')]['findAll'](_0x4f3561);})['then'](function(_0x2552d1){_0x46fe69[_0xb3cd('0x44')]=_0x2552d1;return _0x46fe69;})[_0xb3cd('0x28')](respondWithFilteredResult(_0x26c58c,_0x4f3561))[_0xb3cd('0x45')](handleError(_0x26c58c,null));};exports[_0xb3cd('0x46')]=function(_0x8d87c7,_0x4223ff){var _0xc6a58a={'raw':!![],'where':{'id':_0x8d87c7['params']['id']}},_0x54807d={};_0x54807d[_0xb3cd('0x36')]=_[_0xb3cd('0x47')](db[_0xb3cd('0x2e')][_0xb3cd('0x2f')]);_0x54807d[_0xb3cd('0x32')]=_['keys'](_0x8d87c7[_0xb3cd('0x32')]);_0x54807d[_0xb3cd('0x33')]=_[_0xb3cd('0x34')](_0x54807d[_0xb3cd('0x36')],_0x54807d[_0xb3cd('0x32')]);_0xc6a58a[_0xb3cd('0x35')]=_[_0xb3cd('0x34')](_0x54807d[_0xb3cd('0x36')],qs[_0xb3cd('0x48')](_0x8d87c7[_0xb3cd('0x32')]['fields']));_0xc6a58a[_0xb3cd('0x35')]=_0xc6a58a[_0xb3cd('0x35')][_0xb3cd('0x37')]?_0xc6a58a[_0xb3cd('0x35')]:_0x54807d['model'];if(_0x8d87c7[_0xb3cd('0x32')][_0xb3cd('0x43')]){_0xc6a58a[_0xb3cd('0x49')]=[{'all':!![]}];}_0xc6a58a=_[_0xb3cd('0x3d')]({},_0xc6a58a,_0x8d87c7['options']);return db['WhatsappTransferReport']['find'](_0xc6a58a)[_0xb3cd('0x28')](handleEntityNotFound(_0x4223ff,null))['then'](respondWithResult(_0x4223ff,null))[_0xb3cd('0x45')](handleError(_0x4223ff,null));};exports[_0xb3cd('0x4a')]=function(_0x3147e9,_0xcf77ba){return db[_0xb3cd('0x2e')][_0xb3cd('0x4a')](_0x3147e9[_0xb3cd('0x4b')],{})[_0xb3cd('0x28')](respondWithResult(_0xcf77ba,0xc9))[_0xb3cd('0x45')](handleError(_0xcf77ba,null));};exports[_0xb3cd('0x27')]=function(_0x286f9f,_0x5e20e1){if(_0x286f9f[_0xb3cd('0x4b')]['id']){delete _0x286f9f['body']['id'];}return db[_0xb3cd('0x2e')][_0xb3cd('0x4c')]({'where':{'id':_0x286f9f[_0xb3cd('0x4d')]['id']}})['then'](handleEntityNotFound(_0x5e20e1,null))[_0xb3cd('0x28')](saveUpdates(_0x286f9f[_0xb3cd('0x4b')],null))[_0xb3cd('0x28')](respondWithResult(_0x5e20e1,null))[_0xb3cd('0x45')](handleError(_0x5e20e1,null));};exports[_0xb3cd('0x4e')]=function(_0x10212d,_0x1063e0){return db[_0xb3cd('0x2e')][_0xb3cd('0x4c')]({'where':{'id':_0x10212d[_0xb3cd('0x4d')]['id']}})[_0xb3cd('0x28')](handleEntityNotFound(_0x1063e0,null))[_0xb3cd('0x28')](removeEntity(_0x1063e0,null))[_0xb3cd('0x45')](handleError(_0x1063e0,null));};exports['describe']=function(_0x595195,_0x29022d){return db[_0xb3cd('0x2e')][_0xb3cd('0x4f')]()['then'](respondWithResult(_0x29022d,null))['catch'](handleError(_0x29022d,null));};