bullpen/backend/controllers/position.controller.js

36 lines
913 B
JavaScript

const db = require("../models/index");
const Position = db.Position;
exports.findAll = (req, res) => {
Position.findAll()
.then(data => {
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving pitch types."
});
});
};
exports.findOne = (req, res) => {
const id = req.params.id;
Position.findByPk(id)
.then(data => {
if (data) {
res.send(data);
} else {
res.status(404).send({
message: `Cannot find pitch type with id=${id}.`
});
}
})
.catch(err => {
res.status(500).send({
message: `Error retrieving pitch type with id=${id}: ${err.message}`
});
});
};