Skip to content

Connecting to DB and writing a simple API to display risky profiles of customers according to the data given as input

License

Notifications You must be signed in to change notification settings

pallasite99/customer_risk_analysis_api

Repository files navigation

customer_risk_analysis_api

Connecting to DB and writing a simple API to display risky profiles of customers according to the data given as input

customer_risk_analysis_concept drawio

What does this do?

  • 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.

Sample API

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])
    }
  })
})

Handling condition where entries of phone and creditcard are not available

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])
    }
  })
})

Output

  1. For entity found

insomnia_rest_client

result_risky_customer

  1. Unknown entity

not_found_risky

  1. In case only email is found for a customer_id

only_email_risky

About

Connecting to DB and writing a simple API to display risky profiles of customers according to the data given as input

Resources

License

Stars

Watchers

Forks

Packages

No packages published