Thursday 28 May 2020

What would you improve?

https://try.gitea.io/nadal/repository​Used this in a coding challenge after a job interview. I didn't get chosen, but I was wondering if it was because of the code quality in the project.const express = require('express'); const app = express.Router(); const repository = require('../repositories/ExpenseRepository');/** * Get a list of expense objects * @method * @param req request object * @param res result object * @returns {Promise} json of expenses * */ app.get('/', (req, res) => { repository.findAll().then((expenses) => { res.json(expenses); }).catch((error) => console.log(error)); });/** * Post an expense object * @method * @param req request object * @param res result object * @returns {Promise} json of expenses * */ app.post('/', (req, res) => { const expense = { description: req.body.description, amount: req.body.amount }; repository.create(expense).then((json) => { res.json(json); }).catch((error) => console.log(error)); });/** * Deletes an expense object * @method * @param req request object * @param res result object * @returns {Promise} empty json * */ app.delete('/:id', (req, res) => { const { id } = req.params; repository.deleteById(id).then((ok) => { res.status(200).json([]); }).catch((error) => console.log(error)); });/** * Updates an expense objects * @method * @param req request object * @param res result object * @returns {Promise} empty json * */ app.put('/:id', (req, res) => { const { id } = req.params; const expense = { description: req.body.description, amount: req.body.amount }; repository.updateById(id, expense) .then(res.status(200).json([])) .catch((error) => console.log(error)); });module.exports = app;This is the "central" part of the application, so I am wondering if there's anything wrong with it. Is there anything that can be improved upon? Try to be as nitpicky and harsh as possible.

Submitted May 29, 2020 at 03:01AM by wonderfulnadal

No comments:

Post a Comment