mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 10:42:38 +00:00
Shift API calls to /api from /admin
This commit is contained in:
@@ -3,7 +3,8 @@ require('./lockTools.less');
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
|
|
||||||
const request = require('superagent');
|
// const request = require('superagent');
|
||||||
|
const request = require('../../homebrew/utils/request-middleware.js');
|
||||||
|
|
||||||
const LockTools = createClass({
|
const LockTools = createClass({
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
@@ -18,7 +19,7 @@ const LockTools = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateReviewCount : async function() {
|
updateReviewCount : async function() {
|
||||||
const newCount = await request.get('/admin/lock')
|
const newCount = await request.get('/api/lock/count')
|
||||||
.then((res)=>{return res.body?.count || 'Unknown';});
|
.then((res)=>{return res.body?.count || 'Unknown';});
|
||||||
if(newCount != this.state.reviewCount){
|
if(newCount != this.state.reviewCount){
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -33,13 +34,13 @@ const LockTools = createClass({
|
|||||||
<p>Number of brews currently locked: {this.state.reviewCount}</p>
|
<p>Number of brews currently locked: {this.state.reviewCount}</p>
|
||||||
<button onClick={this.updateReviewCount}>REFRESH</button>
|
<button onClick={this.updateReviewCount}>REFRESH</button>
|
||||||
<hr />
|
<hr />
|
||||||
<LockTable title='Brews Awaiting Review' resultName='reviewDocuments' fetchURL='/admin/lock/reviews' propertyNames={['shareId', 'title']} ></LockTable>
|
<LockTable title='Brews Awaiting Review' resultName='reviewDocuments' fetchURL='/api/lock/reviews' propertyNames={['shareId', 'title']} ></LockTable>
|
||||||
<hr />
|
<hr />
|
||||||
<LockBrew></LockBrew>
|
<LockBrew></LockBrew>
|
||||||
<hr />
|
<hr />
|
||||||
<div style={{ columns: 2 }}>
|
<div style={{ columns: 2 }}>
|
||||||
<LockLookup title='Unlock Brew' fetchURL='/admin/unlock' updateFn={this.updateReviewCount}></LockLookup>
|
<LockLookup title='Unlock Brew' fetchURL='/api/unlock' updateFn={this.updateReviewCount}></LockLookup>
|
||||||
<LockLookup title='Clear Review Request' fetchURL='/admin/lock/review/remove'></LockLookup>
|
<LockLookup title='Clear Review Request' fetchURL='/api/lock/review/remove'></LockLookup>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
</div>;
|
</div>;
|
||||||
@@ -48,11 +49,12 @@ const LockTools = createClass({
|
|||||||
|
|
||||||
const LockBrew = createClass({
|
const LockBrew = createClass({
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
|
// Default values
|
||||||
return {
|
return {
|
||||||
brewId : '',
|
brewId : '',
|
||||||
code : 1000,
|
code : 455,
|
||||||
editMessage : '',
|
editMessage : '',
|
||||||
shareMessage : '',
|
shareMessage : 'This Brew has been locked.',
|
||||||
result : {}
|
result : {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -73,7 +75,7 @@ const LockBrew = createClass({
|
|||||||
applied : new Date
|
applied : new Date
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(`/admin/lock/${this.state.brewId}`)
|
request.post(`/api/lock/${this.state.brewId}`)
|
||||||
.send(newLock)
|
.send(newLock)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.then((response)=>{
|
.then((response)=>{
|
||||||
@@ -167,7 +169,7 @@ const LockTable = createClass({
|
|||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
title : '',
|
title : '',
|
||||||
fetchURL : '/admin/locks',
|
fetchURL : '/api/locks',
|
||||||
resultName : '',
|
resultName : '',
|
||||||
propertyNames : ['shareId']
|
propertyNames : ['shareId']
|
||||||
};
|
};
|
||||||
@@ -236,7 +238,7 @@ const LockTable = createClass({
|
|||||||
const LockLookup = createClass({
|
const LockLookup = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
fetchURL : '/admin/lookup'
|
fetchURL : '/api/lookup'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
|
const version = require('../../../package.json').version;
|
||||||
|
|
||||||
const addHeader = (request)=>request.set('Homebrewery-Version', global.version);
|
const addHeader = (request)=>request.set('Homebrewery-Version', version);
|
||||||
|
|
||||||
const requestMiddleware = {
|
const requestMiddleware = {
|
||||||
get : (path)=>addHeader(request.get(path)),
|
get : (path)=>addHeader(request.get(path)),
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ router.get('/admin/stats', mw.adminOnly, async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/admin/lock', mw.adminOnly, async (req, res)=>{
|
router.get('/api/lock/count', mw.adminOnly, async (req, res)=>{
|
||||||
try {
|
try {
|
||||||
const countLocksQuery = {
|
const countLocksQuery = {
|
||||||
lock : { $exists: true }
|
lock : { $exists: true }
|
||||||
@@ -157,7 +157,7 @@ router.get('/admin/lock', mw.adminOnly, async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/admin/lock/:id', mw.adminOnly, async (req, res)=>{
|
router.post('/api/lock/:id', mw.adminOnly, async (req, res)=>{
|
||||||
try {
|
try {
|
||||||
const lock = req.body;
|
const lock = req.body;
|
||||||
lock.applied = new Date;
|
lock.applied = new Date;
|
||||||
@@ -186,7 +186,7 @@ router.post('/admin/lock/:id', mw.adminOnly, async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put('/admin/unlock/:id', mw.adminOnly, async (req, res)=>{
|
router.put('/api/unlock/:id', mw.adminOnly, async (req, res)=>{
|
||||||
try {
|
try {
|
||||||
const filter = {
|
const filter = {
|
||||||
shareId : req.params.id
|
shareId : req.params.id
|
||||||
@@ -210,7 +210,7 @@ router.put('/admin/unlock/:id', mw.adminOnly, async (req, res)=>{
|
|||||||
return res.json({ status: 'UNLOCKED', detail: `Lock removed from brew ID ${req.params.id}` });
|
return res.json({ status: 'UNLOCKED', detail: `Lock removed from brew ID ${req.params.id}` });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/admin/lock/reviews', mw.adminOnly, async (req, res)=>{
|
router.get('/api/lock/reviews', mw.adminOnly, async (req, res)=>{
|
||||||
try {
|
try {
|
||||||
const countReviewsPipeline = [
|
const countReviewsPipeline = [
|
||||||
{
|
{
|
||||||
@@ -260,7 +260,7 @@ router.put('/admin/lock/review/request/:id', async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put('/admin/lock/review/remove/:id', mw.adminOnly, async (req, res)=>{
|
router.put('/api/lock/review/remove/:id', mw.adminOnly, async (req, res)=>{
|
||||||
try {
|
try {
|
||||||
const filter = {
|
const filter = {
|
||||||
shareId : req.params.id,
|
shareId : req.params.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user