Connecting to DB and writing a simple API to display risky profiles of customers according to the data given as input
- Is this just yet another run of the mill code done for getting a job? Nope
- It has simple support for CRUD operations using mysql and express js, which is understandable, extendable and can be implemented in any other language after understanding the flow
- The focus here was on the process and not the end result, which is an important value for any developer
- It makes use of GH workflows like Node.js linter, super linter which help in CI for running static checks against modifications made in existing / modified code across different langauges like bash, js, mysql, etc.
app.get('/risky_identities/:customer_id', async (req, res) => {
const query = 'SELECT email, phone, creditcard FROM test_view WHERE customer_id = ?'
pool.query(query, [req.params.customer_id], (error, results) => {
if (error) {
res.json({ status: '502 internal server error' })
}
if (!results[0]) {
res.json({ status: '404 not found' })
} else {
res.json(results[0])
}
})
})
app.get('/risky_identities/:customer_id', async (req, res) => {
const query = 'SELECT email, phone, creditcard FROM test_view WHERE customer_id = ?'
pool.query(query, [req.params.customer_id], (error, results) => {
if (error) {
res.json({ status: '502 internal server error' })
}
if (!results[0]) {
const email_query = 'SELECT email FROM risky_email WHERE customer_id = ?'
pool.query(email_query, [req.params.customer_id], (error, results) => {
if (error) {
res.json({ status: '502 internal server error' })
}
if(!results[0]) {
res.json({ status: '404 not found' })
} else {
res.json(results[0])
}
})
} else {
res.json(results[0])
}
})
})
- For entity found
- Unknown entity
- In case only email is found for a customer_id