Skip to content

Instantly share code, notes, and snippets.

@Daniel1984
Created January 10, 2021 15:37
Show Gist options
  • Save Daniel1984/3c31e0adfd9f9c78ad74ce2b4155fe97 to your computer and use it in GitHub Desktop.
Save Daniel1984/3c31e0adfd9f9c78ad74ce2b4155fe97 to your computer and use it in GitHub Desktop.
const express = require('express');
const validId = require('./validId');
const router = express.Router();
router.post('/some-route', async (req, res, next) => {
if (!req.body.account_id) {
return res.status(412).json({
code: 412,
message: 'missing body params',
});
}
if (!validId(req.body.account_id)) {
return res.status(400).json({
statusCode: 400,
message: 'invalid id',
});
}
let account;
try {
account = await req.db.Account.findByPk(req.body.account_id);
} catch (err) {
return res.status(500).json({
statusCode: 500,
error: err,
});
if (!req.body.currency) {
return res.status(412).json({
code: 412,
message: 'missing body params',
});
}
// getting more db records
// some operations
// more body params checks
// database transaction
// conditions
// conditions
// 2k LOK later
return res.status(200).json({
statusCode: 200,
message: 'some success message',
});
}
}
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment