Built motion from commit (unavailable).|2.5.30
[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 _0xc80a=['util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','WhatsappTransferReport','rawAttributes','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','options','include','findAll','catch','show','params','includeAll','find','body','describe','rimraf','fast-json-patch','request-promise','moment','bluebird'];(function(_0x2303b3,_0x2ec788){var _0x42fe45=function(_0xc7a416){while(--_0xc7a416){_0x2303b3['push'](_0x2303b3['shift']());}};_0x42fe45(++_0x2ec788);}(_0xc80a,0x17c));var _0xac80=function(_0x96d40f,_0x2c291f){_0x96d40f=_0x96d40f-0x0;var _0x167b7f=_0xc80a[_0x96d40f];return _0x167b7f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xac80('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xac80('0x1'));var rp=require(_0xac80('0x2'));var moment=require(_0xac80('0x3'));var BPromise=require(_0xac80('0x4'));var Mustache=require('mustache');var util=require(_0xac80('0x5'));var path=require(_0xac80('0x6'));var sox=require(_0xac80('0x7'));var csv=require(_0xac80('0x8'));var ejs=require(_0xac80('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xac80('0xa'));var squel=require(_0xac80('0xb'));var crypto=require(_0xac80('0xc'));var jsforce=require(_0xac80('0xd'));var deskjs=require(_0xac80('0xe'));var toCsv=require(_0xac80('0x8'));var querystring=require(_0xac80('0xf'));var Papa=require('papaparse');var Redis=require(_0xac80('0x10'));var authService=require(_0xac80('0x11'));var qs=require(_0xac80('0x12'));var as=require(_0xac80('0x13'));var hardwareService=require(_0xac80('0x14'));var logger=require(_0xac80('0x15'))(_0xac80('0x16'));var utils=require(_0xac80('0x17'));var config=require(_0xac80('0x18'));var licenseUtil=require(_0xac80('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5e3c55,_0x2903bf){_0x2903bf=_0x2903bf||0xcc;return function(_0x48a656){if(_0x48a656){return _0x5e3c55[_0xac80('0x1a')](_0x2903bf);}return _0x5e3c55[_0xac80('0x1b')](_0x2903bf)[_0xac80('0x1c')]();};}function respondWithResult(_0x41fde6,_0x46f688){_0x46f688=_0x46f688||0xc8;return function(_0x27c554){if(_0x27c554){return _0x41fde6[_0xac80('0x1b')](_0x46f688)[_0xac80('0x1d')](_0x27c554);}};}function respondWithFilteredResult(_0x1ae0bd,_0x33856b){return function(_0x531cb7){if(_0x531cb7){var _0x4d2343=typeof _0x33856b[_0xac80('0x1e')]===_0xac80('0x1f')&&typeof _0x33856b[_0xac80('0x20')]==='undefined';var _0x3ae1d8=_0x531cb7[_0xac80('0x21')];var _0x5c1465=_0x4d2343?0x0:_0x33856b[_0xac80('0x1e')];var _0x4d3eb3=_0x4d2343?_0x531cb7[_0xac80('0x21')]:_0x33856b['offset']+_0x33856b[_0xac80('0x20')];var _0x284cc5;if(_0x4d3eb3>=_0x3ae1d8){_0x4d3eb3=_0x3ae1d8;_0x284cc5=0xc8;}else{_0x284cc5=0xce;}_0x1ae0bd[_0xac80('0x1b')](_0x284cc5);return _0x1ae0bd[_0xac80('0x22')](_0xac80('0x23'),_0x5c1465+'-'+_0x4d3eb3+'/'+_0x3ae1d8)[_0xac80('0x1d')](_0x531cb7);}return null;};}function patchUpdates(_0xb51ba7){return function(_0x449ec8){try{jsonpatch[_0xac80('0x24')](_0x449ec8,_0xb51ba7,!![]);}catch(_0x1e3147){return BPromise[_0xac80('0x25')](_0x1e3147);}return _0x449ec8[_0xac80('0x26')]();};}function saveUpdates(_0x23c21d,_0x4e3d7b){return function(_0x20423f){if(_0x20423f){return _0x20423f[_0xac80('0x27')](_0x23c21d)[_0xac80('0x28')](function(_0x40ccdf){return _0x40ccdf;});}return null;};}function removeEntity(_0x9fc6c0,_0x85f91c){return function(_0x5c0f98){if(_0x5c0f98){return _0x5c0f98[_0xac80('0x29')]()[_0xac80('0x28')](function(){_0x9fc6c0[_0xac80('0x1b')](0xcc)[_0xac80('0x1c')]();});}};}function handleEntityNotFound(_0x55b6f0,_0x38d592){return function(_0x2c190f){if(!_0x2c190f){_0x55b6f0[_0xac80('0x1a')](0x194);}return _0x2c190f;};}function handleError(_0x5e6795,_0xe02dd9){_0xe02dd9=_0xe02dd9||0x1f4;return function(_0x10a470){logger[_0xac80('0x2a')](_0x10a470[_0xac80('0x2b')]);if(_0x10a470['name']){delete _0x10a470[_0xac80('0x2c')];}_0x5e6795[_0xac80('0x1b')](_0xe02dd9)[_0xac80('0x2d')](_0x10a470);};}exports[_0xac80('0x2e')]=function(_0x5b46f6,_0x49b4d9){var _0x4e28d9={},_0x27d66f={},_0x58e928={'count':0x0,'rows':[]};var _0x250200=_['map'](db[_0xac80('0x2f')][_0xac80('0x30')],function(_0x4e4db7){return{'name':_0x4e4db7['fieldName'],'type':_0x4e4db7[_0xac80('0x31')][_0xac80('0x32')]};});_0x27d66f[_0xac80('0x33')]=_[_0xac80('0x34')](_0x250200,'name');_0x27d66f[_0xac80('0x35')]=_[_0xac80('0x36')](_0x5b46f6[_0xac80('0x35')]);_0x27d66f[_0xac80('0x37')]=_[_0xac80('0x38')](_0x27d66f[_0xac80('0x33')],_0x27d66f[_0xac80('0x35')]);_0x4e28d9[_0xac80('0x39')]=_[_0xac80('0x38')](_0x27d66f[_0xac80('0x33')],qs[_0xac80('0x3a')](_0x5b46f6[_0xac80('0x35')][_0xac80('0x3a')]));_0x4e28d9[_0xac80('0x39')]=_0x4e28d9[_0xac80('0x39')][_0xac80('0x3b')]?_0x4e28d9[_0xac80('0x39')]:_0x27d66f['model'];if(!_0x5b46f6[_0xac80('0x35')]['hasOwnProperty'](_0xac80('0x3c'))){_0x4e28d9[_0xac80('0x20')]=qs[_0xac80('0x20')](_0x5b46f6['query'][_0xac80('0x20')]);_0x4e28d9[_0xac80('0x1e')]=qs['offset'](_0x5b46f6[_0xac80('0x35')][_0xac80('0x1e')]);}_0x4e28d9[_0xac80('0x3d')]=qs[_0xac80('0x3e')](_0x5b46f6[_0xac80('0x35')][_0xac80('0x3e')]);_0x4e28d9[_0xac80('0x3f')]=qs[_0xac80('0x37')](_[_0xac80('0x40')](_0x5b46f6[_0xac80('0x35')],_0x27d66f['filters']),_0x250200);if(_0x5b46f6[_0xac80('0x35')][_0xac80('0x41')]){_0x4e28d9[_0xac80('0x3f')]=_[_0xac80('0x42')](_0x4e28d9[_0xac80('0x3f')],{'$or':_[_0xac80('0x34')](_0x250200,function(_0x7da78b){if(_0x7da78b['type']!=='VIRTUAL'){var _0x481af8={};_0x481af8[_0x7da78b[_0xac80('0x2c')]]={'$like':'%'+_0x5b46f6[_0xac80('0x35')][_0xac80('0x41')]+'%'};return _0x481af8;}})});}_0x4e28d9=_['merge']({},_0x4e28d9,_0x5b46f6[_0xac80('0x43')]);var _0x2ce429={'where':_0x4e28d9[_0xac80('0x3f')]};return db['WhatsappTransferReport']['count'](_0x2ce429)['then'](function(_0x570cb6){_0x58e928['count']=_0x570cb6;if(_0x5b46f6[_0xac80('0x35')]['includeAll']){_0x4e28d9[_0xac80('0x44')]=[{'all':!![]}];}return db[_0xac80('0x2f')][_0xac80('0x45')](_0x4e28d9);})['then'](function(_0x36680f){_0x58e928['rows']=_0x36680f;return _0x58e928;})[_0xac80('0x28')](respondWithFilteredResult(_0x49b4d9,_0x4e28d9))[_0xac80('0x46')](handleError(_0x49b4d9,null));};exports[_0xac80('0x47')]=function(_0x58740e,_0x54f1cd){var _0x1b53f8={'raw':!![],'where':{'id':_0x58740e[_0xac80('0x48')]['id']}},_0x2e5b18={};_0x2e5b18[_0xac80('0x33')]=_['keys'](db['WhatsappTransferReport']['rawAttributes']);_0x2e5b18[_0xac80('0x35')]=_[_0xac80('0x36')](_0x58740e['query']);_0x2e5b18[_0xac80('0x37')]=_[_0xac80('0x38')](_0x2e5b18['model'],_0x2e5b18[_0xac80('0x35')]);_0x1b53f8['attributes']=_[_0xac80('0x38')](_0x2e5b18['model'],qs[_0xac80('0x3a')](_0x58740e[_0xac80('0x35')][_0xac80('0x3a')]));_0x1b53f8[_0xac80('0x39')]=_0x1b53f8['attributes']['length']?_0x1b53f8[_0xac80('0x39')]:_0x2e5b18[_0xac80('0x33')];if(_0x58740e['query'][_0xac80('0x49')]){_0x1b53f8['include']=[{'all':!![]}];}_0x1b53f8=_[_0xac80('0x42')]({},_0x1b53f8,_0x58740e[_0xac80('0x43')]);return db[_0xac80('0x2f')][_0xac80('0x4a')](_0x1b53f8)[_0xac80('0x28')](handleEntityNotFound(_0x54f1cd,null))[_0xac80('0x28')](respondWithResult(_0x54f1cd,null))[_0xac80('0x46')](handleError(_0x54f1cd,null));};exports['create']=function(_0x7f974c,_0x54efd7){return db[_0xac80('0x2f')]['create'](_0x7f974c['body'],{})[_0xac80('0x28')](respondWithResult(_0x54efd7,0xc9))[_0xac80('0x46')](handleError(_0x54efd7,null));};exports[_0xac80('0x27')]=function(_0x3bbc58,_0x214fca){if(_0x3bbc58['body']['id']){delete _0x3bbc58[_0xac80('0x4b')]['id'];}return db['WhatsappTransferReport'][_0xac80('0x4a')]({'where':{'id':_0x3bbc58[_0xac80('0x48')]['id']}})[_0xac80('0x28')](handleEntityNotFound(_0x214fca,null))[_0xac80('0x28')](saveUpdates(_0x3bbc58[_0xac80('0x4b')],null))[_0xac80('0x28')](respondWithResult(_0x214fca,null))[_0xac80('0x46')](handleError(_0x214fca,null));};exports[_0xac80('0x29')]=function(_0x4d32e6,_0x12d26e){return db[_0xac80('0x2f')][_0xac80('0x4a')]({'where':{'id':_0x4d32e6[_0xac80('0x48')]['id']}})[_0xac80('0x28')](handleEntityNotFound(_0x12d26e,null))[_0xac80('0x28')](removeEntity(_0x12d26e,null))['catch'](handleError(_0x12d26e,null));};exports[_0xac80('0x4c')]=function(_0x2ac44d,_0x383391){return db[_0xac80('0x2f')]['describe']()['then'](respondWithResult(_0x383391,null))[_0xac80('0x46')](handleError(_0x383391,null));};