Skip to content

Commit

Permalink
feat: add json to fetch single coalition score
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekBes committed Jan 28, 2025
1 parent 8055606 commit 5cf4b5a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/routes/admin/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ export const setupAdminPointsRoutes = function(app: Express, prisma: PrismaClien
});
});

app.get('/admin/points/history/:id', async (req, res) => {
const scoreId = parseInt(req.params.id);
if (isNaN(scoreId)) {
return res.status(400).json({ error: 'Invalid score ID' });
}

const score = await prisma.codamCoalitionScore.findFirst({
where: {
id: scoreId,
},
include: {
coalition: {
include: {
intra_coalition: true,
},
},
user: {
include: {
intra_user: true,
},
},
fixed_type: true,
},
});

if (!score) {
return res.status(404).json({ error: 'Score not found' });
}

return res.json(score);
});

app.get('/admin/points/history/:id/sync', async (req, res) => {
try {
const scoreId = parseInt(req.params.id);
Expand Down
2 changes: 2 additions & 0 deletions templates/admin/points/history.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<table class="table coalition-colored">
<thead>
<th scope="col">Internal ID</th>
<th scope="col">Date</th>
<th scope="col">Coalition</th>
<th scope="col">Points</th>
Expand All @@ -24,6 +25,7 @@
<tbody>
{% for score in scores %}
<tr style="background: {{ coalitions[score.coalition_id].intra_coalition.color | rgba(0.25) }}">
<td><a href="/admin/points/history/{{ score.id }}" target="scorejson">{{ score.id }}</a></td>
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
<td>{{ coalitions[score.coalition_id].intra_coalition.name | striptags(true) | escape }}</td>
<td>{{ score.amount }}</td>
Expand Down

0 comments on commit 5cf4b5a

Please sign in to comment.