Problem statement:User will able to login and submit a application form and select particular authorities to get verified. Initially the request will be not confirmed.Later admin(authorities) will be able to access the verification page and update the status to "Confirmed".There can be more than one authority. (all the data will be stored in the mongoDB database)
This is nodejs API format
app.route("/requests/:rollno")
.get(function(req, res) {
Request.find({
rollno: req.params.rollno
}, function(err, foundRequest) {
if (foundRequest) {
res.send(foundRequest);
} else {
res.send("No requests found");
}
});
})
.patch(function(req, res) {
Request.update({
rollno: req.params.rollno
}, {
$set:req.body
},
function(err) {
if (!err) {
res.send("Successfully updated requests");
}else{
res.send(err);
}
}
);
});
<%- include('partials/header') %>
<h1>Recent requests</h1>
<% for(let i = 0; i < posts.length; i++) { %>
<article>
<h2><%= posts[i].purpose %></h1>
<p><%= posts[i].from %></p>
<p><%= posts[i].rollno %></p>
<p><%= posts[i].date %></p>
<% for(let j = 0; j < posts[i].to.length; j++) { %>
<p><%= posts[i].to[j] %></p>
<% } %>
<form action="/requests/B194057EP" method="PATCH">
<input type="text" name="status[0]">
<div id="participant"></div>
<br>
<button type="button" onclick="addParticipant()">Add</button>
<button type="button" onclick="delParticipant()">Remove</button>
<div class="btn-block">
<button type="submit" href="/success">Submit Request</button>
</div>
</form>
<p><%= posts[i].email %></p>
<p><%= posts[i].description %></p>
<p><%= posts[i].duration %></p>
</article>
<% } %>
<script type="text/javascript">
var cont = 1;
function addParticipant() {
var div = document.createElement('div');
div.className = 'participant';
div.innerHTML = '<input type="text" name="status[' + cont + ']">';
document.getElementById('participant').appendChild(div);
cont++
}
function delParticipant() {
var select = document.getElementById('participant');
document.getElementById('participant').removeChild(select.lastChild);
cont--
}
</script>
The problem is that the form is not actually patching the information but with postman the data is getting updated.What's the best resolution for the same or is there any alternate method for same ?