Skip to content

Commit

Permalink
Merge pull request #146 from Lukasdotcom/fix-historical
Browse files Browse the repository at this point in the history
Fixes bug that does not show squad player in historical view when on the current matchday
  • Loading branch information
Lukasdotcom authored Sep 8, 2022
2 parents eeb48fa + eb10121 commit eac84d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions cypress/e2e/invite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ describe("Invite User into league and change some league Settings and run throug
cy.get(".MuiPagination-ul > :nth-child(2)").click();
cy.get(".MuiTableBody-root > :nth-child(1) > :nth-child(2)").contains("34");
cy.get(".MuiTableBody-root > :nth-child(2) > :nth-child(2)").contains("22");
// Checks if the historical viewer can see the playerdata
cy.get(
".MuiTableBody-root > :nth-child(1) > :nth-child(3) > .MuiTypography-root > .MuiButtonBase-root"
).click();
cy.get(':nth-child(8) > [style="width: 70%;"] > :nth-child(1)').contains(
"Robert Lewandowski"
);
// Checks Nkunku button
cy.contains("Squad").click();
cy.contains("Christopher Nkunku")
Expand Down
22 changes: 17 additions & 5 deletions pages/[league]/[user]/[matchday].js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ export async function getServerSideProps(ctx) {
notFound: true,
};
}
// Gets the latest squad of the user
const squad = await connection.query(
"SELECT * FROM historicalSquad WHERE leagueID=? AND user=? AND matchday=?",
[league, user, matchday]
);
// Calculates the timestamp for this matchday
const time = timeData[0].time;
const [transfers, username, latestMatchday, money] = await Promise.all([
Expand Down Expand Up @@ -52,6 +47,23 @@ export async function getServerSideProps(ctx) {
)
.then((res) => (res.length > 0 ? res[0].money : 0)),
]);
// Checks if it is the latest matchday and that the matchday is running because then the historicalSquad table does not have the squad data for the player
const historicalSquadExists = !(
latestMatchday == matchday &&
connection
.query("SELECT value2 FROM data WHERE value1='transferOpen'")
.then((result) => result[0].value2 !== "true")
);
// Gets the squad of the user on that matchday
const squad = historicalSquadExists
? await connection.query(
"SELECT * FROM historicalSquad WHERE leagueID=? AND user=? AND matchday=?",
[league, user, matchday]
)
: await connection.query(
"SELECT * FROM squad WHERE leagueID=? AND user=?",
[league, user]
);
connection.end();
// Checks if the user exists
if (username === "") {
Expand Down

0 comments on commit eac84d2

Please sign in to comment.