26 lines
924 B
JavaScript
26 lines
924 B
JavaScript
const CoffeeShippingFeeService = require('../../services/subscriptions/CoffeeShippingFeeService');
|
|
|
|
class ShippingFeesController {
|
|
// Public endpoint: returns the 2 configured shipping fees (60/120)
|
|
static async listPublic(req, res) {
|
|
const list = await CoffeeShippingFeeService.list();
|
|
return res.json(list);
|
|
}
|
|
|
|
// Admin endpoint: update price for a pieceCount (60 or 120)
|
|
static async updatePrice(req, res) {
|
|
try {
|
|
const pieceCount = req.params.pieceCount;
|
|
const price = req.body?.price;
|
|
const updated = await CoffeeShippingFeeService.setPrice(pieceCount, price);
|
|
if (!updated) return res.status(404).json({ error: 'Not found' });
|
|
return res.json(updated);
|
|
} catch (err) {
|
|
const status = err?.status || 500;
|
|
return res.status(status).json({ error: err?.message || 'Failed to update shipping fee' });
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = ShippingFeesController;
|