Now I'm developing CRUD(Create, Read, Update, Delete) App with Express and LowDB.
And I successfully developed the create and read but Delete Function is not working.
There are detail page like this
as you can see there are trash can Icon and actually I also have some problem the submit button but It's not important so I just make submit button.
this is the part of the pug file
aside#Delete.is-visible
form(method="post" action='/delete_process')
input(type='submit')
a#DeleteButton(role='button')
img(src='https://png.icons8.com/ios/35/000000/waste-filled.png' id="go_up")
span.text
| Delete
br
b this
detail page have URL (ex: DIR1WTqr2) and it's DB id
and delete Process code is like this.
/* Delete Process */
router.post('/delete_process', function (req, res) {
// GET Delete ID from URL
let id=req.params.id;
console.log(id);
db.get('project').find({
id: id
}).remove().write();
});
I thought I can get URL and find the data with the id in json file. but It's not working. When I tried to console the req.params.id it said undefined
And I think there are collision with view Detail page because Detail page code is like this.
/* GET Detail View Page */
router.get('/:id', (req, res, next) => {
// GET URL params and put it into :id
let id = req.params.id;
// console.log(id);
// GET data id to use Object
let data = db.get('project').find({
id: id
}).value();
// Get github URL
let url = data.githuburl;
// Use Request Module to parsing Web page
request(url, function (error, response, html) {
if (error) {
throw error
};
// Parsing readme ID in github page
var $ = cheerio.load(html);
$('#readme').each(function () {
// save to readme Variable
let readme = $(this).html();
// console.log(data);
// console.log(id);
res.render('detail', {
dataarray: data,
name: data.name,
url: data.url,
explanation: data.explanation,
imgurl: data.imgurl,
markdown: readme,
startDate: data.pjdate1,
endDate: data.pjdate2,
githuburl: data.githuburl,
sumlang: data.sumlang
});
});
});
});
because of :id when I click the /delete_process it goes to detail page I think.
