Skip to content

Commit

Permalink
Merge pull request #723 from elmadev/dev
Browse files Browse the repository at this point in the history
feat(teams): upload logos and add field to some endpoints
  • Loading branch information
sunehs authored Dec 20, 2024
2 parents 52248e2 + 19853d9 commit 140b985
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/api/levelpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ const mapKuskiData = times => {
TeamData: {
TeamIndex: t.TeamIndex,
Team: t.Team,
Logo: t.Logo,
},
},
}));
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/api/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
30 changes: 29 additions & 1 deletion src/api/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -152,7 +174,7 @@ const Player = async KuskiIndex => {
{
model: Team,
as: 'TeamData',
attributes: ['Team', 'Locked'],
attributes: ['Team', 'Locked', 'Logo'],
},
],
});
Expand Down Expand Up @@ -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])) {
Expand Down
5 changes: 5 additions & 0 deletions src/data/models/Team.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const Team = Model.define(
allowNull: false,
defaultValue: 0,
},
Logo: {
type: DataType.STRING(255),
allowNull: true,
defaultValue: null,
},
},
{
indexes: [{ fields: ['Team'] }],
Expand Down

0 comments on commit 140b985

Please sign in to comment.