this is my transport.request.model import mongoose from "mongoose";
const schema = new mongoose.Schema({ Transport : String, Product : String, Material : String, Capacity : Number, Manufacturer : String, Retailer : String, currentOwner : String, Status : String, // setup request // accepted request by distributor // raw material received by retailer IsActive : { type : Boolean, default : true}, IsAcceptedbyDistributor : { type : Boolean, default : false}, Isfulfilled : { type : Boolean, default : false}, timestamp: { type: Date, default: Date.now} });
const model = mongoose.model('transportRequest', schema);
export default model; and this is the view code. It shows the profile, but does not show the table
<div class = "profile-flex">
<div class="profile">
<h2><img id ="profimag" src="https://icon-library.com/images/coder-icon/coder-icon-13.jpg" alt=""> Profile</h2>
<div class="details">
<ul >
<% if (Data.Profile != {}){ for (var prop in Data.Profile ) { %>
<li> <%= prop %> : <%= Data.Profile[prop] %></li>
<% } } else {%>
<li>No data available</li>
<% } %>
</ul>
</div>
</div>
</div>
<!-- Table / Collection Section -->
<div>
<h2>Requests on the Transport Network</h2>
<div class = "box">
<% if (Data.Requests != []) { for (const Request of Data.Requests) {
console.log("if first is working") %>
<div class="card">
<div class = "container">
<form action="/distributor/accept-request" method="post">
<% if (Request != {}) { %>
<label for="Product"> Product :</label>
<input type="text" name="Product" readonly value = <%= Request.Product %> ><br><br>
<label for="Material"> Material :</label>
<input type="text" name="Material" readonly value = <%= Request.Material %> ><br><br>
<label for="TransportAddress"> Transport :</label>
<input type="text" name="TransportAddress"readonly value= <%= Request.Transport %> ><br><br>
<input type="submit" value="Accept Request">
<% }%>
</form>
</div>
</div>
<% } } %>
and finally the route code where I think the problem is , but I'm not sure
router.post('/confirm-fulfillment-of-request', async (req, res) => {
// to contract needs to fulfill at the same, html form will have 2 fields : product Address and transport address
// accessing the cookie
const user = req.cookies.accessToken;
await db.transportRequest.findOne({ Transport: req.body.TransportAddress, IsActive: true }).then(async (result) => {
if (result == null)
return res.send({ Success: false });
else {
// update the Product contract
const productContract = await new web3.eth.Contract(product_ABI, req.body.ProductAddress);
await productContract.methods.fulfillRequest(result.Material).send({ from: process.env.defaultAccount });
// update the Transport Contract
const transportContract = await new web3.eth.Contract(transport_ABI, result.Transport);
await transportContract.methods.fulfillRequest(result.Material).send({ from: process.env.defaultAccount });
// update productrequest collection in database
await db.productRequest.updateOne({ Product: req.body.ProductAddress }, {
$set: {
currentOwner: user.ContractAddress,
Status: "Raw material received by retailer",
IsActive: false,
Isfulfilled: true
}
});
// update transportRequest collection in database
await db.transportRequest.updateOne({ Transport: req.body.TransportAddress }, {
$set: {
currentOwner: user.ContractAddress,
Status: "Raw material received by retailer",
IsActive: false,
Isfulfilled: true
}
}).then(async(result)=>{
console.log("result", result)
// update the retailer stock in rawmaterials
// update on database
await db.transportRequest.findOne({ Transport: req.body.TransportAddress}).then(async (ress)=>{
await db.rawMaterial.updateOne({Material: ress.Material, Owner : ress.Manufacturer}, {
$set: {
Owner: user.ContractAddress
}
});
await db.rawMaterial.findOne({ Material: ress.Material, Owner: user.ContractAddress }).then(async (docs) => {
await db.tracking.create({
CertificateID : docs.CertificateID,
Operation : "Confirm-delivery-of-Goods",
From : req.body.TransportAddress,
To: user.ContractAddress,
})
});
})
})
// pay the distributor his money from smart contract
//
res.redirect('/retailer-page');
}
})
});