Skip to content

Commit

Permalink
fixes(v2024.05.20): bans - remove matchevents - new booster
Browse files Browse the repository at this point in the history
commit c8d62da
Author: Jonas Simoen <[email protected]>
Date:   Mon May 20 20:56:35 2024 +0200

    minor fixes

commit bb8e7fb
Author: Jonas Simoen <[email protected]>
Date:   Mon May 20 19:49:42 2024 +0200

    feat(booster): add new player booster

commit e8a3c9c
Author: Jonas Simoen <[email protected]>
Date:   Mon May 20 16:54:42 2024 +0200

    feat(news): article management
  • Loading branch information
jonassimoen committed May 20, 2024
1 parent dc51cdc commit e2f5b71
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 271 deletions.
106 changes: 4 additions & 102 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
// previewFeatures = ["metrics"]
Expand All @@ -11,25 +8,11 @@ datasource db {
url = env("DATABASE_URL")
}

enum MatchEventType {
Goal
Assist
SubstituteIn
SubstituteOut
PenaltyScored
PenaltyMissed
PenaltySaved
YellowCard
SecondYellowCard
RedCard
Starting
}

enum PlayerBoosterType {
HiddenGem
GoalRush
TripleCaptain
ViceVictory
FanFavourit
}

model User {
Expand All @@ -42,10 +25,9 @@ model User {
street String?
streetNr String?
postCode String?
// favoriteClubId String
// registerInfo String
role Int
payed Boolean? @default(false)
banned Boolean? @default(false)
teams Team[]
Audit Audit[]
Expand Down Expand Up @@ -77,7 +59,6 @@ model Player {
selections Selection[]
club Club? @relation(fields: [clubId], references: [id], onDelete: Cascade)
MatchEvent MatchEvent[]
stats Statistic[]
inPlayer Transfer[] @relation("inPlayer")
outPlayer Transfer[] @relation("outPlayer")
Expand Down Expand Up @@ -185,7 +166,7 @@ model Team {
// Boosters
freeHit Int?
tripleCaptain Int?
viceVictory Int?
fanFavourite Int?
superSubs Int?
hiddenGem Int?
goalRush Int?
Expand Down Expand Up @@ -255,21 +236,9 @@ model Match {
away Club? @relation(name: "awayMatch", fields: [awayId], references: [id])
week Week? @relation(fields: [weekId], references: [id])
MatchEvent MatchEvent[]
Statistic Statistic[]
}

model MatchEvent {
id Int @id @default(autoincrement())
type MatchEventType
matchId Int
playerId Int
minute Int
match Match @relation(fields: [matchId], references: [id], onDelete: Cascade)
player Player @relation(fields: [playerId], references: [id], onDelete: Cascade)
}

model Transfer {
id Int @id @default(autoincrement())
Expand Down Expand Up @@ -335,71 +304,4 @@ model Article {
timestampUpdated DateTime?
author User @relation(fields: [authorId], references: [id])
authorId Int
}

// model WeeksOnTeams {
// week Week @relation(fields: [weekId], references: [id])
// team Team @relation(fields: [teamId], references: [id])
// weekId Int
// teamId Int

// @@id([weekId, teamId])
// }

// export interface Player {
// id: number
// name: string
// short: string
// forename: string
// surname: string
// positionId: number
// externalId?: number
// value: number
// ban?: number
// injury?: number
// form?: number
// squadDepth?: number
// fieldOrder: number
// info?: number
// portraitUrl: string
// star: number
// setPieces: number
// captain: number
// caps: number
// squadStatus?: string
// clubId: number
// }

// export interface Club {
// id: number
// name: string
// short: string
// styling: any
// externalId: number
// }

// export interface DeadlineInfo {
// displayWeek: number
// deadlineWeek: number
// deadlineDate: string
// rosterEndWeek: number
// }

// export interface Week {
// weekId: number
// roundId: any
// deadlineDate: string
// }

// export interface Round {
// roundId: any
// deadlineDate: string
// }

// export interface Club {
// id: number
// name: string
// short: string
// styling: any
// externalId: number
// }
}
4 changes: 2 additions & 2 deletions src/controllers/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const GetUserOverview = async(req: any, rep: any) => {
}
},
tripleCaptain: true,
viceVictory: true,
fanFavourite: true,
freeHit: true,
superSubs: true,
hiddenGem: true,
Expand All @@ -54,7 +54,7 @@ export const GetUserOverview = async(req: any, rep: any) => {
where: {
OR: [
{tripleCaptain: weekId},
{viceVictory: weekId},
{fanFavourite: weekId},
{freeHit: weekId},
{superSubs: weekId},
{hiddenGem: weekId},
Expand Down
78 changes: 0 additions & 78 deletions src/controllers/MatchEvent.ts

This file was deleted.

8 changes: 5 additions & 3 deletions src/controllers/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const PostAddTeamHandler = async (req: any, rep: any) => {
userId: req.user.id,
action: 'POST_CREATE_UPDATE',
params: JSON.stringify({
teamId: req.team.id,
userId: req.user.id,
selections: {
createMany: {
Expand Down Expand Up @@ -317,20 +318,20 @@ export const GetPointsTeamHandler = async (req: any, rep: any) => {

export const PostBoosterTeamHandler = async (req: any, rep: any) => {
const boosterUnCC = req.body.type.charAt(0).toUpperCase() + req.body.type.slice(1);
const validBoosters = ["tripleCaptain","viceVictory","hiddenGem","goalRush","superSubs","freeHit"];
const validBoosters = ["tripleCaptain","fanFavourite","hiddenGem","goalRush","superSubs","freeHit"];

if(!validBoosters.includes(req.body.type))
throw new HttpError("Invalid booster", 404)

const isPlayerBooster = ["hiddenGem","goalRush"].includes(req.body.type);
const isPlayerBooster = ["hiddenGem","goalRush","fanFavourite"].includes(req.body.type);
const currentWeek = await upcomingWeekId();

const teamWithBoosters: { [key: string]: any } | null = await prisma.team.findFirst({
select: {
goalRush: true,
tripleCaptain: true,
hiddenGem: true,
viceVictory: true,
fanFavourite: true,
selections: {
select: {
playerId: true,
Expand Down Expand Up @@ -473,6 +474,7 @@ export const PostEditTeamHandler = async (req: any, rep: any) => {
userId: req.user.id,
action: `EDIT_TEAM_${hasFreeHit ? 'FREE_HIT' : 'BEFORE_START'}`,
params: JSON.stringify({
teamId: +req.params.id,
userId: req.user.id,
selections: allWithValues,
budget: budget,
Expand Down
10 changes: 8 additions & 2 deletions src/controllers/UserAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export const GoogleAuthHandler = async (req: AccessTokenRequest, rep: any) => {
}
});

let firstSignIn = false;
let firstSignIn = false;
if( !user && (process.env.DISABLED_REGISTRATIONS === "true" || false)) {
return rep.redirect(`${process.env.WEBAPP_URL}/denied?${qs.stringify({ reason: "registrations-disabled" })}`);
}
if (user && user.banned) {
return rep.redirect(`${process.env.WEBAPP_URL}/denied?${qs.stringify({ reason: "banned" })}`);
}
if (!user) {
user = await prisma.user.create({
data: {
Expand All @@ -54,7 +60,7 @@ export const GoogleAuthHandler = async (req: AccessTokenRequest, rep: any) => {
const refreshToken = signJwt({ ...user }, { expiresIn: "30d" });
rep.setCookie("token", accessToken, accessTokenCookieOptions);
rep.setCookie("refreshToken", refreshToken, refreshTokenCookieOptions);
rep.redirect(`${process.env.WEBAPP_URL}/login/callback?${qs.stringify({ token: accessToken, refreshToken: refreshToken })}`);
return rep.redirect(`${process.env.WEBAPP_URL}/login/callback?${qs.stringify({ token: accessToken, refreshToken: refreshToken })}`);


// rep.send(googleUserInfo)
Expand Down
5 changes: 4 additions & 1 deletion src/middleware/RequireUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export const RequireUser = (req: any, rep: any, done: any) => {
const user = req.user;

if (!user) {
done(new HttpError("No credentials provided", 401));
done(new HttpError("No credentials provided.", 401));
}
if (user?.banned) {
done(new HttpError("You have been banned.", 403));
}
done();
}
3 changes: 0 additions & 3 deletions src/routers/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AdminPlayerRouter, PublicPlayerRouter } from './Player';
import { AdminClubRouter, PublicClubRouter } from './Club';
import { RequireAdmin } from '../middleware//RequireAdmin';
import { AdminMatchRouter, PublicMatchRouter } from './Match';
import { AdminMatchEventRouter, PublicMatchEventRouter } from './MatchEvent';
import { AdminMatchStatisticRouter, PublicMatchStatisticRouter, PublicPlayerStatisticRouter } from './Statistic';
import { AdminWeekRouter, PublicWeekRouter } from './Week';
import { AdminPageRouter, PublicPageRouter } from './Page';
Expand All @@ -20,7 +19,6 @@ export const PublicRouter: FastifyPluginAsync = async server => {
server.register(PublicPlayerRouter, { prefix: '/players' })
server.register(PublicClubRouter, { prefix: '/clubs' })
server.register(PublicMatchRouter, { prefix: '/matches' })
server.register(PublicMatchEventRouter, { prefix: '/matches/:matchId/events' })
server.register(PublicMatchStatisticRouter, { prefix: '/matches/:matchId/stats' })
server.register(PublicWeekRouter, { prefix: '/weeks' })
server.register(PublicPlayerStatisticRouter, { prefix: '/player-stats' })
Expand All @@ -34,7 +32,6 @@ export const AdminRouter: FastifyPluginAsync = async server => {
server.register(AdminPlayerRouter, { prefix: '/players' })
server.register(AdminClubRouter, { prefix: '/clubs' })
server.register(AdminMatchRouter, { prefix: '/matches' })
server.register(AdminMatchEventRouter, { prefix: '/matches/:matchId/events' })
server.register(AdminMatchStatisticRouter, { prefix: '/matches/:matchId/stats' })
server.register(AdminWeekRouter, { prefix: '/weeks' })
server.register(AdminPageRouter, { prefix: '/pages' })
Expand Down
Loading

0 comments on commit e2f5b71

Please sign in to comment.