Built motion from commit (unavailable).|2.5.21
[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 _0xa4de=['params','include','find','create','body','describe','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','squel','crypto','jsforce','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','reject','save','then','destroy','error','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','pick','filter','merge','VIRTUAL','options','WhatsappTransferReport','findAll','rows','catch','show'];(function(_0xff0760,_0x3bb095){var _0x1c625b=function(_0x55c4af){while(--_0x55c4af){_0xff0760['push'](_0xff0760['shift']());}};_0x1c625b(++_0x3bb095);}(_0xa4de,0x17d));var _0xea4d=function(_0x39589b,_0x20f8a8){_0x39589b=_0x39589b-0x0;var _0x589229=_0xa4de[_0x39589b];return _0x589229;};'use strict';var pdf=require(_0xea4d('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xea4d('0x1'));var zipdir=require(_0xea4d('0x2'));var jsonpatch=require(_0xea4d('0x3'));var rp=require(_0xea4d('0x4'));var moment=require(_0xea4d('0x5'));var BPromise=require(_0xea4d('0x6'));var Mustache=require(_0xea4d('0x7'));var util=require(_0xea4d('0x8'));var path=require(_0xea4d('0x9'));var sox=require(_0xea4d('0xa'));var csv=require('to-csv');var ejs=require(_0xea4d('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0xea4d('0xc'));var crypto=require(_0xea4d('0xd'));var jsforce=require(_0xea4d('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xea4d('0xf'));var querystring=require('querystring');var Papa=require(_0xea4d('0x10'));var Redis=require(_0xea4d('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xea4d('0x12'));var as=require(_0xea4d('0x13'));var hardwareService=require(_0xea4d('0x14'));var logger=require(_0xea4d('0x15'))('api');var utils=require(_0xea4d('0x16'));var config=require(_0xea4d('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xea4d('0x18'))['db'];function respondWithStatusCode(_0xe538ba,_0x142898){_0x142898=_0x142898||0xcc;return function(_0x4a77d9){if(_0x4a77d9){return _0xe538ba[_0xea4d('0x19')](_0x142898);}return _0xe538ba[_0xea4d('0x1a')](_0x142898)[_0xea4d('0x1b')]();};}function respondWithResult(_0x3c7139,_0x4661ae){_0x4661ae=_0x4661ae||0xc8;return function(_0x54136b){if(_0x54136b){return _0x3c7139[_0xea4d('0x1a')](_0x4661ae)['json'](_0x54136b);}};}function respondWithFilteredResult(_0xc0d844,_0x3fda08){return function(_0xa6af22){if(_0xa6af22){var _0x27fbae=_0xa6af22[_0xea4d('0x1c')],_0x221ec0=_0x3fda08[_0xea4d('0x1d')],_0x54c2a2=_0x3fda08[_0xea4d('0x1d')]+_0x3fda08[_0xea4d('0x1e')],_0x3e823c;if(_0x54c2a2>=_0x27fbae){_0x54c2a2=_0x27fbae;_0x3e823c=0xc8;}else{_0x3e823c=0xce;}_0xc0d844['status'](_0x3e823c);return _0xc0d844[_0xea4d('0x1f')](_0xea4d('0x20'),_0x221ec0+'-'+_0x54c2a2+'/'+_0x27fbae)[_0xea4d('0x21')](_0xa6af22);}return null;};}function patchUpdates(_0x443733){return function(_0x4d4174){try{jsonpatch[_0xea4d('0x22')](_0x4d4174,_0x443733,!![]);}catch(_0x5ef981){return BPromise[_0xea4d('0x23')](_0x5ef981);}return _0x4d4174[_0xea4d('0x24')]();};}function saveUpdates(_0x598936,_0x62025){return function(_0x259cd2){if(_0x259cd2){return _0x259cd2['update'](_0x598936)[_0xea4d('0x25')](function(_0x11523a){return _0x11523a;});}return null;};}function removeEntity(_0x762ada,_0xc6ea2e){return function(_0x3b0c85){if(_0x3b0c85){return _0x3b0c85[_0xea4d('0x26')]()[_0xea4d('0x25')](function(){_0x762ada[_0xea4d('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x53c2e3,_0x4f5a22){return function(_0x5ba165){if(!_0x5ba165){_0x53c2e3[_0xea4d('0x19')](0x194);}return _0x5ba165;};}function handleError(_0x4b6562,_0x49a2e4){_0x49a2e4=_0x49a2e4||0x1f4;return function(_0x4de874){logger[_0xea4d('0x27')](_0x4de874[_0xea4d('0x28')]);if(_0x4de874[_0xea4d('0x29')]){delete _0x4de874[_0xea4d('0x29')];}_0x4b6562[_0xea4d('0x1a')](_0x49a2e4)['send'](_0x4de874);};}exports[_0xea4d('0x2a')]=function(_0x48734e,_0x55d819){var _0x493caf={},_0x2d4bd6={},_0x37053c={'count':0x0,'rows':[]};var _0x1881bd=_[_0xea4d('0x2b')](db['WhatsappTransferReport'][_0xea4d('0x2c')],function(_0x26cf04){return{'name':_0x26cf04[_0xea4d('0x2d')],'type':_0x26cf04[_0xea4d('0x2e')][_0xea4d('0x2f')]};});_0x2d4bd6[_0xea4d('0x30')]=_['map'](_0x1881bd,'name');_0x2d4bd6[_0xea4d('0x31')]=_[_0xea4d('0x32')](_0x48734e['query']);_0x2d4bd6[_0xea4d('0x33')]=_[_0xea4d('0x34')](_0x2d4bd6[_0xea4d('0x30')],_0x2d4bd6['query']);_0x493caf[_0xea4d('0x35')]=_['intersection'](_0x2d4bd6[_0xea4d('0x30')],qs[_0xea4d('0x36')](_0x48734e['query']['fields']));_0x493caf['attributes']=_0x493caf[_0xea4d('0x35')][_0xea4d('0x37')]?_0x493caf[_0xea4d('0x35')]:_0x2d4bd6[_0xea4d('0x30')];if(!_0x48734e[_0xea4d('0x31')][_0xea4d('0x38')]('nolimit')){_0x493caf[_0xea4d('0x1e')]=qs[_0xea4d('0x1e')](_0x48734e[_0xea4d('0x31')][_0xea4d('0x1e')]);_0x493caf[_0xea4d('0x1d')]=qs[_0xea4d('0x1d')](_0x48734e[_0xea4d('0x31')][_0xea4d('0x1d')]);}_0x493caf['order']=qs[_0xea4d('0x39')](_0x48734e[_0xea4d('0x31')][_0xea4d('0x39')]);_0x493caf[_0xea4d('0x3a')]=qs[_0xea4d('0x33')](_[_0xea4d('0x3b')](_0x48734e[_0xea4d('0x31')],_0x2d4bd6[_0xea4d('0x33')]),_0x1881bd);if(_0x48734e[_0xea4d('0x31')][_0xea4d('0x3c')]){_0x493caf[_0xea4d('0x3a')]=_[_0xea4d('0x3d')](_0x493caf[_0xea4d('0x3a')],{'$or':_[_0xea4d('0x2b')](_0x1881bd,function(_0xb7a375){if(_0xb7a375[_0xea4d('0x2e')]!==_0xea4d('0x3e')){var _0x2f6e35={};_0x2f6e35[_0xb7a375[_0xea4d('0x29')]]={'$like':'%'+_0x48734e[_0xea4d('0x31')][_0xea4d('0x3c')]+'%'};return _0x2f6e35;}})});}_0x493caf=_[_0xea4d('0x3d')]({},_0x493caf,_0x48734e[_0xea4d('0x3f')]);var _0xd49341={'where':_0x493caf[_0xea4d('0x3a')]};return db[_0xea4d('0x40')][_0xea4d('0x1c')](_0xd49341)[_0xea4d('0x25')](function(_0x4d16f4){_0x37053c[_0xea4d('0x1c')]=_0x4d16f4;if(_0x48734e[_0xea4d('0x31')]['includeAll']){_0x493caf['include']=[{'all':!![]}];}return db[_0xea4d('0x40')][_0xea4d('0x41')](_0x493caf);})['then'](function(_0x52980){_0x37053c[_0xea4d('0x42')]=_0x52980;return _0x37053c;})[_0xea4d('0x25')](respondWithFilteredResult(_0x55d819,_0x493caf))[_0xea4d('0x43')](handleError(_0x55d819,null));};exports[_0xea4d('0x44')]=function(_0x1c19e5,_0x2c04ee){var _0x1f700d={'raw':!![],'where':{'id':_0x1c19e5[_0xea4d('0x45')]['id']}},_0x28d6aa={};_0x28d6aa[_0xea4d('0x30')]=_[_0xea4d('0x32')](db[_0xea4d('0x40')]['rawAttributes']);_0x28d6aa[_0xea4d('0x31')]=_[_0xea4d('0x32')](_0x1c19e5[_0xea4d('0x31')]);_0x28d6aa[_0xea4d('0x33')]=_['intersection'](_0x28d6aa[_0xea4d('0x30')],_0x28d6aa[_0xea4d('0x31')]);_0x1f700d[_0xea4d('0x35')]=_[_0xea4d('0x34')](_0x28d6aa[_0xea4d('0x30')],qs[_0xea4d('0x36')](_0x1c19e5[_0xea4d('0x31')][_0xea4d('0x36')]));_0x1f700d['attributes']=_0x1f700d[_0xea4d('0x35')][_0xea4d('0x37')]?_0x1f700d['attributes']:_0x28d6aa[_0xea4d('0x30')];if(_0x1c19e5[_0xea4d('0x31')]['includeAll']){_0x1f700d[_0xea4d('0x46')]=[{'all':!![]}];}_0x1f700d=_[_0xea4d('0x3d')]({},_0x1f700d,_0x1c19e5['options']);return db[_0xea4d('0x40')][_0xea4d('0x47')](_0x1f700d)[_0xea4d('0x25')](handleEntityNotFound(_0x2c04ee,null))[_0xea4d('0x25')](respondWithResult(_0x2c04ee,null))[_0xea4d('0x43')](handleError(_0x2c04ee,null));};exports[_0xea4d('0x48')]=function(_0x12dec6,_0x52baa7){return db['WhatsappTransferReport'][_0xea4d('0x48')](_0x12dec6[_0xea4d('0x49')],{})[_0xea4d('0x25')](respondWithResult(_0x52baa7,0xc9))[_0xea4d('0x43')](handleError(_0x52baa7,null));};exports['update']=function(_0x4837b6,_0x187414){if(_0x4837b6[_0xea4d('0x49')]['id']){delete _0x4837b6[_0xea4d('0x49')]['id'];}return db[_0xea4d('0x40')][_0xea4d('0x47')]({'where':{'id':_0x4837b6[_0xea4d('0x45')]['id']}})[_0xea4d('0x25')](handleEntityNotFound(_0x187414,null))['then'](saveUpdates(_0x4837b6[_0xea4d('0x49')],null))[_0xea4d('0x25')](respondWithResult(_0x187414,null))[_0xea4d('0x43')](handleError(_0x187414,null));};exports[_0xea4d('0x26')]=function(_0xcb5328,_0x355ed0){return db[_0xea4d('0x40')][_0xea4d('0x47')]({'where':{'id':_0xcb5328['params']['id']}})['then'](handleEntityNotFound(_0x355ed0,null))[_0xea4d('0x25')](removeEntity(_0x355ed0,null))['catch'](handleError(_0x355ed0,null));};exports[_0xea4d('0x4a')]=function(_0x1855f0,_0x518caa){return db['WhatsappTransferReport'][_0xea4d('0x4a')]()['then'](respondWithResult(_0x518caa,null))[_0xea4d('0x43')](handleError(_0x518caa,null));};