Skip to content

Commit

Permalink
Revert "Remove default margin route as it is replaced with preferences"
Browse files Browse the repository at this point in the history
This reverts commit fb5667f.
  • Loading branch information
ArktinenKarpalo committed Jul 28, 2024
1 parent 4847ddd commit cb92376
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logger from './logger.js';
import admin_auth from './routes/admin/adminAuth.js';
import admin_boxes from './routes/admin/boxes.js';
import admin_categories from './routes/admin/categories.js';
import admin_default_margin from './routes/admin/default_margin.js';
import admin_history from './routes/admin/history.js';
import admin_preferences from './routes/admin/preferences.js';
import admin_products from './routes/admin/products.js';
Expand Down Expand Up @@ -45,6 +46,7 @@ app.use('/api/v1/register', register_route);
app.use('/api/v1/products', user_products);
app.use('/api/v1/categories', user_categories);

app.use('/api/v1/admin/defaultMargin', admin_default_margin);
app.use('/api/v1/admin/authenticate', admin_auth);
app.use('/api/v1/admin/products', admin_products);
app.use('/api/v1/admin/boxes', admin_boxes);
Expand Down
21 changes: 21 additions & 0 deletions src/routes/admin/default_margin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import express from 'express';
import { getPreference, preferences, setPreference } from '../../db/preferences.js';
import authMiddleware from '../authMiddleware.js';

const { GLOBAL_DEFAULT_MARGIN } = preferences;

const router = express.Router();

router.use(authMiddleware('ADMIN', process.env.JWT_ADMIN_SECRET));

router.get('/', async (_req, res) => {
const margin = await getPreference(GLOBAL_DEFAULT_MARGIN);
res.status(200).json({ margin });
});

router.patch('/', async (req, res) => {
await setPreference(GLOBAL_DEFAULT_MARGIN, req.body.margin);
res.status(200).send();
});

export default router;

0 comments on commit cb92376

Please sign in to comment.