diff --git a/src/handlers/points.ts b/src/handlers/points.ts index a780900..3d80484 100644 --- a/src/handlers/points.ts +++ b/src/handlers/points.ts @@ -45,13 +45,22 @@ export const createScore = async function(prisma: PrismaClient, type: CodamCoali console.warn(`User ${user.login} is a test account, skipping score creation...`); return null; } + const blocAtScoreCreation = await getBlocAtDate(prisma, scoreDate); + const currentBloc = await getBlocAtDate(prisma, new Date()); + if (blocAtScoreCreation && currentBloc && blocAtScoreCreation.id !== currentBloc.id) { // Check if the score creation date is in the current bloc if a current bloc and previous bloc exist (if not, just assign the score - it won't belong to any season but it can be shifted using the admin panel) + console.warn(`Score creation date ${scoreDate} is not in the current bloc ${currentBloc.id} (${currentBloc.begin_at} - ${currentBloc.end_at}) but in bloc ${blocAtScoreCreation.id} (${blocAtScoreCreation.begin_at} - ${blocAtScoreCreation.end_at}), skipping score creation...`); + return null; + } + if (!blocAtScoreCreation) { // Check if there is a season ongoing at the score creation date + console.warn(`No bloc found for score creation date ${scoreDate}. The score will be created, but will not belong to any season. It should be shifted later to the correct season using the admin panel.`); + } if (!user.coalition_users || user.coalition_users.length === 0) { // Check if user has a coalition console.warn(`User ${userId} does not have a coalition, skipping score creation...`); return null; } const coalitionUser = user.coalition_users[0]; - console.log(`Creating score for user ${userId} in coalition ${coalitionUser.coalition_id} with ${points} points for reason "${reason}" (connected to Intra object ${typeIntraId} for fixed type ${(type ? type.type : "null")})...`); + console.log(`Creating score for user ${userId} in coalition ${coalitionUser.coalition_id} with ${points} points for reason "${reason}" (connected to Intra object ${typeIntraId} for fixed type ${(type ? type.type : "null")}), at score creation date ${scoreDate}...`); const score = await prisma.codamCoalitionScore.create({ data: { amount: points, diff --git a/src/routes/admin/dashboard.ts b/src/routes/admin/dashboard.ts index 97d2024..e031ef1 100644 --- a/src/routes/admin/dashboard.ts +++ b/src/routes/admin/dashboard.ts @@ -5,12 +5,20 @@ import { CoalitionScore, getCoalitionScore, getScoresPerType } from '../../utils export const setupAdminDashboardRoutes = function(app: Express, prisma: PrismaClient): void { app.get('/admin', async (req, res) => { // Get current bloc deadline - const blocDeadline = await prisma.intraBlocDeadline.findFirst({ + const currentBlocDeadline = await prisma.intraBlocDeadline.findFirst({ orderBy: { end_at: 'desc', }, }); + // Get previous bloc deadlines + const blocDeadlines = await prisma.intraBlocDeadline.findMany({ + orderBy: { + end_at: 'desc', + }, + take: 10, + }); + // Get coalitions const coalitions = await prisma.codamCoalition.findMany({ select: { @@ -41,7 +49,8 @@ export const setupAdminDashboardRoutes = function(app: Express, prisma: PrismaCl } return res.render('admin/dashboard.njk', { - blocDeadline, + currentBlocDeadline, + blocDeadlines, coalitions, coalitionScores, coalitionScoresPerFixedType, diff --git a/templates/admin/dashboard.njk b/templates/admin/dashboard.njk index 487ec98..9972f26 100644 --- a/templates/admin/dashboard.njk +++ b/templates/admin/dashboard.njk @@ -22,8 +22,8 @@
Season deadlines
-

Start: {{ blocDeadline.begin_at | timeAgo }}

-

End: {{ blocDeadline.end_at | timeFromNow }}

+

Start: {{ currentBlocDeadline.begin_at | timeAgo }}

+

End: {{ currentBlocDeadline.end_at | timeFromNow }}

@@ -99,5 +99,22 @@ {% endfor %} + +
+
+
+
+
Previous 10 seasons
+
+
+
    + {% for blocDeadline in blocDeadlines %} +
  • {{ blocDeadline.begin_at | dateInput }} - {{ blocDeadline.end_at | dateInput }}
  • + {% endfor %} +
+
+
+
+
{% endblock %}