Skip to content

Commit d53e26a

Browse files
committed
fix: use getBlocAtDate function to fetch current bloc
1 parent 7c72fd3 commit d53e26a

2 files changed

Lines changed: 3 additions & 27 deletions

File tree

src/routes/admin/dashboard.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
import { Express } from 'express';
22
import { PrismaClient } from '@prisma/client';
3-
import { CoalitionScore, getCoalitionScore, getScoresPerType } from '../../utils';
3+
import { CoalitionScore, getBlocAtDate, getCoalitionScore, getScoresPerType } from '../../utils';
44

55
export const setupAdminDashboardRoutes = function(app: Express, prisma: PrismaClient): void {
66
app.get('/admin', async (req, res) => {
77
const now = new Date();
88

99
// Get current bloc deadline
10-
const currentBlocDeadline = await prisma.intraBlocDeadline.findFirst({
11-
orderBy: {
12-
end_at: 'desc',
13-
},
14-
where: {
15-
begin_at: {
16-
gte: now,
17-
},
18-
end_at: {
19-
lt: now,
20-
},
21-
},
22-
});
10+
const currentBlocDeadline = await getBlocAtDate(prisma);
2311

2412
// Get previous bloc deadlines
2513
const blocDeadlines = await prisma.intraBlocDeadline.findMany({

src/routes/home.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,7 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
4646
const sortedCoalitionScores = Object.entries(coalitionScores).sort((a, b) => b[1].score - a[1].score);
4747

4848
// Get current bloc deadline
49-
const currentBlocDeadline = await prisma.intraBlocDeadline.findFirst({
50-
orderBy: {
51-
end_at: 'desc',
52-
},
53-
where: {
54-
begin_at: {
55-
gte: now,
56-
},
57-
end_at: {
58-
lt: now,
59-
},
60-
},
61-
});
49+
const currentBlocDeadline = await getBlocAtDate(prisma);
6250
const nextBlocDeadline = await prisma.intraBlocDeadline.findFirst({
6351
orderBy: {
6452
begin_at: 'asc',

0 commit comments

Comments
 (0)