Skip to content

Commit

Permalink
Create transfers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 10, 2024
1 parent eb12002 commit 564f06c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/routes/transfers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const express = require("express");
const router = express.Router();

const TransferController = require("../controllers/transfers");
const authenticate = require("../middleware/auth");
const createTransaction = require("../middleware/network");

router.post("/", authenticate, async (req, res) => {
try {
const transfer = await TransferController.create(req, res);
const transactionHash = await createTransaction(req.user.wallet_address, req.body.receiver_account_id, req.body.amount);
transfer.transaction_hash = transactionHash;
await transfer.save();
res.json({ message: "Transfer successful", transfer });
} catch (error) {
res.status(400).json({ message: error.message });
}
});

module.exports = router;

0 comments on commit 564f06c

Please sign in to comment.