mirror of
https://github.com/Alvin-Zilverstand/challenge-11.git
synced 2026-03-06 11:06:21 +01:00
Enhance CarModifications component by integrating API calls for fetching modifications and customers, implementing a dialog for adding modifications to customers, and improving error and success message handling. Refactor state management and UI elements for better user experience.
This commit is contained in:
27
routes/modifications.js
Normal file
27
routes/modifications.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const Modification = require('../models/Modification');
|
||||
const auth = require('../middleware/auth');
|
||||
|
||||
// Get all modifications
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const modifications = await Modification.find().sort({ name: 1 });
|
||||
res.json(modifications);
|
||||
} catch (err) {
|
||||
res.status(500).json({ message: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Add a new modification (admin only, or for seeding)
|
||||
router.post('/', auth, async (req, res) => {
|
||||
try {
|
||||
const mod = new Modification(req.body);
|
||||
await mod.save();
|
||||
res.status(201).json(mod);
|
||||
} catch (err) {
|
||||
res.status(400).json({ message: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user