e-scooter-rental-system/server/routes/applications.js

43 lines
1.2 KiB
JavaScript

const express = require('express');
const router = express.Router();
const Application = require('../models/Application');
router.get('/', async (req, res) => {
try {
const apps = await Application.find().populate('store');
res.json({ success: true, data: apps });
} catch (error) {
res.status(500).json({ success: false, message: error.message });
}
});
router.post('/', async (req, res) => {
try {
const app = new Application(req.body);
await app.save();
res.json({ success: true, data: app });
} catch (error) {
res.status(400).json({ success: false, message: error.message });
}
});
router.put('/:id', async (req, res) => {
try {
const app = await Application.findByIdAndUpdate(req.params.id, req.body, { new: true });
res.json({ success: true, data: app });
} catch (error) {
res.status(400).json({ success: false, message: error.message });
}
});
router.delete('/:id', async (req, res) => {
try {
await Application.findByIdAndDelete(req.params.id);
res.json({ success: true });
} catch (error) {
res.status(400).json({ success: false, message: error.message });
}
});
module.exports = router;