Skip to content

Commit

Permalink
Create transactions.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 27, 2024
1 parent faa0b81 commit 2690c66
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pi-nexus-api/routes/v1/transactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import express from 'express';
import { Transaction } from '../models';
import { apiUtils } from '../utils';

const router = express.Router();

router.get('/', async (req, res) => {
try {
const transactions = await Transaction.find().exec();
res.json(transactions);
} catch (err) {
apiUtils.errorHandler(err, req, res);
}
});

router.get('/:transactionId', async (req, res) => {
try {
const transaction = await Transaction.findById(req.params.transactionId).exec();
if (!transaction) {
res.status(404).json({ error: 'Transaction not found' });
} else {
res.json(transaction);
}
} catch (err) {
apiUtils.errorHandler(err, req, res);
}
});

router.post('/', async (req, res) => {
try {
const transaction = new Transaction(req.body);
await transaction.save();
res.json(transaction);
} catch (err) {
apiUtils.errorHandler(err, req, res);
}
});

export default router;

0 comments on commit 2690c66

Please sign in to comment.