| 123456789101112131415161718192021222324 |
- const express = require('express');
- const Invoice = require('../models/Invoice');
- const auth = require('../middleware/auth');
- const router = express.Router();
- router.get('/', auth, async (req, res) => {
- try {
- const unpaidInvoices = await Invoice.find({ paid: false });
- res.json(unpaidInvoices);
- } catch (error) {
- res.status(500).json({ error: 'Failed to retrieve invoices' });
- }
- });
- router.post('/:id/pay', auth, async (req, res) => {
- try {
- await Invoice.findByIdAndUpdate(req.params.id, { paid: true });
- res.sendStatus(200);
- } catch (error) {
- res.status(500).json({ error: 'Failed to update invoice' });
- }
- });
- module.exports = router;
|