diff --git a/src/api/levelpack.js b/src/api/levelpack.js index 00234b15..3ea1ad69 100644 --- a/src/api/levelpack.js +++ b/src/api/levelpack.js @@ -393,6 +393,7 @@ const mapKuskiData = times => { TeamData: { TeamIndex: t.TeamIndex, Team: t.Team, + Logo: t.Logo, }, }, })); @@ -432,7 +433,7 @@ const getRecords = async ( } const sql = ` - SELECT bt.*, k.KuskiIndex, k.Kuski, k.Country, t.TeamIndex, t.Team + SELECT bt.*, k.KuskiIndex, k.Kuski, k.Country, t.TeamIndex, t.Team, t.Logo FROM ( SELECT time.*, ROW_NUMBER() OVER (PARTITION BY LevelIndex ORDER BY TIME ASC, TimeIndex ASC) posn FROM ${isLegacy ? 'legacybesttime' : 'besttime'} time${join} diff --git a/src/api/player.js b/src/api/player.js index 3108eb5e..12040bbe 100644 --- a/src/api/player.js +++ b/src/api/player.js @@ -94,7 +94,7 @@ const Player = async (IdentifierType, KuskiIdentifier, currentUser) => { include: { model: Team, as: 'TeamData', - attributes: ['Team', 'TeamIndex', 'Locked'], + attributes: ['Team', 'TeamIndex', 'Locked', 'Logo'], }, attributes: [ 'KuskiIndex', diff --git a/src/api/register.js b/src/api/register.js index d2667018..1b7b2009 100644 --- a/src/api/register.js +++ b/src/api/register.js @@ -136,6 +136,28 @@ const UpdateLocked = async (TeamIndex, Locked) => { await Team.update({ Locked }, { where: { TeamIndex } }); }; +const LogoUpdate = async (LogoUrl, TeamIndex) => { + let message = ''; + let error = false; + if (!TeamIndex) { + message = 'You need to be in a team to update the logo.'; + error = true; + } else if (LogoUrl.length > 155) { + message = 'Logo filename is too long. Maximum number of characters is 155.'; + error = true; + } else { + const split = LogoUrl.split('/u/'); + if (split[0] === LogoUrl) { + message = 'Invalid logo URL.'; + error = true; + } + const url = `https://eol.ams3.digitaloceanspaces.com/${config.s3SubFolder}files/${split[1]}`; + await Team.update({ Logo: url }, { where: { TeamIndex } }); + message = 'Logo has been updated.'; + } + return { message, error }; +}; + const Player = async KuskiIndex => { const data = await Kuski.findOne({ where: { KuskiIndex }, @@ -152,7 +174,7 @@ const Player = async KuskiIndex => { { model: Team, as: 'TeamData', - attributes: ['Team', 'Locked'], + attributes: ['Team', 'Locked', 'Logo'], }, ], }); @@ -282,6 +304,12 @@ router await UpdateTeam(TeamIndex, auth.userid); message = `Team updated to ${req.body.Value[0]}`; } + // logo + } else if (req.body.Field === 'Logo') { + const player = await Player(auth.userid); + const updateLogo = await LogoUpdate(req.body.Value, player.TeamIndex); + error = updateLogo.error; + message = updateLogo.message; // email } else if (req.body.Field === 'Email') { if (!validateEmail(req.body.Value[0])) { diff --git a/src/data/models/Team.js b/src/data/models/Team.js index 7ed56705..fcdca43e 100644 --- a/src/data/models/Team.js +++ b/src/data/models/Team.js @@ -20,6 +20,11 @@ const Team = Model.define( allowNull: false, defaultValue: 0, }, + Logo: { + type: DataType.STRING(255), + allowNull: true, + defaultValue: null, + }, }, { indexes: [{ fields: ['Team'] }],