41 lines
981 B
JavaScript
41 lines
981 B
JavaScript
const db = require("../models/index");
|
|
const Team = db.Team;
|
|
const Player = db.Player;
|
|
const Op = db.Sequelize.Op;
|
|
|
|
exports.findAll = (req, res) => {
|
|
const title = req.query.title;
|
|
const condition = title ? {title: {[Op.iLike]: `%${title}%`}} : null;
|
|
|
|
Team.findAll({
|
|
where: condition,
|
|
include: ['players']
|
|
}).then(data => {
|
|
res.send(data);
|
|
}).catch(err => {
|
|
res.status(500).send({
|
|
message:
|
|
err.message || "Some error occurred while retrieving teams."
|
|
});
|
|
});
|
|
};
|
|
|
|
exports.findOne = (req, res) => {
|
|
const id = req.params.id;
|
|
|
|
Team.findByPk(id, {
|
|
include: ['players']
|
|
}).then(data => {
|
|
res.send(data);
|
|
}).catch(err => {
|
|
res.status(500).send({
|
|
message: `Error retrieving team with id=${id}: ${err.message}`
|
|
});
|
|
});
|
|
};
|
|
|
|
exports.addPlayer = (req, res) => {
|
|
const id = req.params.id;
|
|
const playerId = req.params.playerId;
|
|
|
|
} |