// Create a candidate
app.post('/api/candidate', ({ body }, res) => {
const errors = inputCheck(body, 'first_name', 'last_name', 'industry_connected');
if (errors) {
res.status(400).json({ error: errors });
return;
}
const sql = `INSERT INTO candidates (first_name, last_name, industry_connected)
VALUES (?,?,?)`;
const params = [body.first_name, body.last_name, body.industry_connected];
db.query(sql, params, (err, result) => {
if (err) {
res.status(400).json({ error: err.message });
return;
}
res.json({
message: 'success',
data: body
});
});
});
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter