109 lines
3.2 KiB
JavaScript
109 lines
3.2 KiB
JavaScript
|
|
|
|
exports.getOpponents = async (req, res, next) => {
|
|
const {user, team, layout, csrfToken} = req
|
|
opponents = await teamsnap.loadOpponents(team.id, ["event", "availabilitySummary"], (err, opponents)=>{
|
|
if (err) console.log('err in controllers/opponent.js')
|
|
|
|
else return opponents;
|
|
})
|
|
context = {
|
|
title: "Opponents",
|
|
user, team, layout, csrfToken,
|
|
opponents: opponents,
|
|
};
|
|
res.render("opponent/list", context);
|
|
};
|
|
|
|
exports.uploadOpponentLogoForm = (req, res, next) => {
|
|
opponent_id = req.params.opponent_id;
|
|
team_id = req.params.team_id;
|
|
res.set("Content-Type", "text/html");
|
|
res.render("upload-logo", {
|
|
title: "Upload Logo",
|
|
csrf_token: req.csrfToken(),
|
|
team_id: team_id,
|
|
opponent_id: opponent_id,
|
|
});
|
|
};
|
|
|
|
exports.uploadOpponentLogo = (req, res, next) => {
|
|
opponent_id = req.body.opponent_id;
|
|
team_id = req.body.team_id;
|
|
member_id = req.user.id;
|
|
file = new File(req.file.buffer, `team-logo-${opponent_id}.png`, {
|
|
type: "image/png",
|
|
});
|
|
authTeamsnap(req.user);
|
|
teamsnap
|
|
.loadCollections()
|
|
.then(() => {
|
|
return teamsnap.createTeamMedium({
|
|
file: file,
|
|
mediaFormat: "file",
|
|
memberId: member_id,
|
|
teamId: team_id,
|
|
teamMediaGroupId: "4927028",
|
|
description: `team-logo-${opponent_id}.png`,
|
|
});
|
|
})
|
|
.then((item) => {
|
|
return teamsnap.uploadTeamMedium(item);
|
|
})
|
|
.then((item) => {
|
|
res.send("Data Received: " + JSON.stringify(item));
|
|
})
|
|
.fail((err) => console.log(err));
|
|
};
|
|
|
|
exports.getOpponent = async (req, res) => {
|
|
await Promise.all(req.promises)
|
|
const {team, team_media_group, opponent, layout, opponent_logo, user, csrfToken} = req
|
|
context = {
|
|
team, team_media_group, opponent, layout, opponent_logo, user, csrfToken
|
|
// opponent_logo: items.find(
|
|
// (i) => i.type == "teamMedium" && i.description == `opponent-logo-${opponent_id}.png`
|
|
// ),
|
|
};
|
|
res.set("Content-Type", "text/html");
|
|
res.render("opponent/show", context);
|
|
};
|
|
|
|
exports.postOpponentLogo = async (req, res, next) => {
|
|
res.status('501').send('Not Implemented')
|
|
// await Promise.all(req.promises)
|
|
// const {team, opponent, user, body} = req
|
|
// const filename = `team-logo-${opponent.id}.png`
|
|
// file = new File(req.file.buffer, filename, {
|
|
// type: "image/png",
|
|
// });
|
|
|
|
// const team_medium = await teamsnap.createTeamMedium(
|
|
// {
|
|
// file: file,
|
|
// memberId: user.id,
|
|
// teamId: team.id,
|
|
// teamMediaGroupId: body.teamMediaGroupId,
|
|
// description: filename,
|
|
// }
|
|
// )
|
|
// await teamsnap.saveTeamMedium(team_medium)
|
|
// // await teamsnap.uploadTeamMedium(team_medium)
|
|
|
|
// const headers={'Authorization': `Bearer ${user.accessToken}`}
|
|
// // const url = teamsnap.collections.teamMedia.commands.uploadTeamMedium.href
|
|
// const url = teamsnap.collections.teamMedia.queries.search.href
|
|
// const response = await fetch(url+`?team_id=${team.id}`, {
|
|
// headers,
|
|
// method: 'get',
|
|
// // body:{team_id:team.id}
|
|
// // body: {
|
|
// // file: file,
|
|
// // member_id: user.id,
|
|
// // team_id: team.id,
|
|
// // team_media_group_id: body.teamMediaGroupId,
|
|
// // description: filename,
|
|
// // }
|
|
// })
|
|
// // await teamsnap
|
|
} |