bullpen/backend/controllers/bullpenSession.controller.js

54 lines
1.3 KiB
JavaScript

const db = require("../models/index");
const BullpenSession = db.BullpenSession;
const Pitch = db.Pitch;
exports.insert = (req, res) => {
BullpenSession.create(req.body, { include: [{
model: Pitch,
as: 'pitches'
}]}
)
.then(bullpenSession => {
return res.status(201).send(bullpenSession);
})
.catch(err => {
res.status(500).send({ message: err.message });
});
};
exports.findAll = (req, res) => {
BullpenSession.findAll({
include: {
model: Pitch,
as: 'pitches'
}
})
.then(bullpenSessions => {
res.status(200).send(bullpenSessions);
});
}
exports.findOne = (req, res) => {
const id = req.params.id;
BullpenSession.findByPk(id, {
include: {
model: Pitch,
as: 'pitches'
}
})
.then(data => {
if (data) {
res.send(data);
} else {
res.status(404).send({
message: `Cannot find bullpen session with id=${id}.`
});
}
})
.catch(err => {
res.status(500).send({
message: `Error retrieving bullpen session with id=${id}: ${err.message}`
});
});
}