Skip to content

Commit acbd504

Browse files
committed
show current rating count on event details page
1 parent c98bcb9 commit acbd504

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

packages/client/src/pages/events/EventDetails.page.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const EventDetailsPage = () => {
7171
/>
7272
)
7373
}
74-
const { event, userRating } = dbQuery.data
74+
const { event, userRating, editingNow, submittedRatingCount } = dbQuery.data
7575

7676
return (
7777
<VStack alignItems="flex-start" spacing={3}>
@@ -91,6 +91,19 @@ export const EventDetailsPage = () => {
9191
<Text>
9292
<b>Értékelési eredmények várható publikálása:</b> {getRatingResultPublishedDate(new Date(event.endDate ?? event.startDate))}
9393
</Text>
94+
{event.state === EventState.RATEABLE && submittedRatingCount === 0 && (
95+
<Text>Még senki nem értékelte ezt a versenyt, legyél te az első!</Text>
96+
)}
97+
{event.state === EventState.RATEABLE && submittedRatingCount > 0 && (
98+
<Text>
99+
Eddig <b>{submittedRatingCount}</b> felhasználó értékelte a versenyt{' '}
100+
{editingNow > 0 && (
101+
<span>
102+
, <b>{editingNow}</b> épp most értékel
103+
</span>
104+
)}
105+
</Text>
106+
)}
94107
</VStack>
95108
<HStack flexWrap="wrap">
96109
{event.state === EventState.RESULTS_READY && (

packages/common/src/lib/types/dbEvents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface EventWithRating {
3030
stages: DbStage[]
3131
})
3232
| null
33+
submittedRatingCount: number
34+
editingNow: number
3335
}
3436

3537
export enum Rank {

packages/functions/src/functions/events/getOne.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { app, HttpRequest, InvocationContext } from '@azure/functions'
2-
import { EventWithRating, PontozoException } from '@pontozo/common'
2+
import { EventWithRating, PontozoException, RatingStatus } from '@pontozo/common'
33
import { getUserFromHeaderIfPresent } from '../../service/auth.service'
44
import Event from '../../typeorm/entities/Event'
55
import EventRating from '../../typeorm/entities/EventRating'
@@ -17,19 +17,34 @@ export const getOneEvent = async (req: HttpRequest, context: InvocationContext):
1717

1818
const user = getUserFromHeaderIfPresent(req)
1919
const ads = await getAppDataSource(context)
20+
const erRepo = ads.getRepository(EventRating)
2021
const eventQuery = ads.getRepository(Event).findOne({ where: { id: eventId }, relations: { organisers: true, stages: true } })
21-
const userRatingQuery = ads
22-
.getRepository(EventRating)
23-
.findOne({ where: { eventId: eventId, userId: user?.szemely_id }, relations: { stages: true } })
24-
const [event, userRating] = await Promise.all([eventQuery, user ? userRatingQuery : Promise.resolve(null)])
22+
const userRatingQuery = erRepo.findOne({ where: { eventId, userId: user?.szemely_id }, relations: { stages: true } })
23+
const allRatingsQuery = erRepo.find({ where: { eventId } })
24+
const [event, userRating, allRatings] = await Promise.all([eventQuery, user ? userRatingQuery : Promise.resolve(null), allRatingsQuery])
2525

2626
if (!event) {
2727
throw new PontozoException('A verseny nem található!', 404)
2828
}
29+
const now = new Date().getTime()
30+
let submittedRatingCount = 0
31+
let editingNow = 0
32+
allRatings.forEach((er) => {
33+
if (er.status === RatingStatus.SUBMITTED) {
34+
submittedRatingCount++
35+
return
36+
}
37+
// ratings started in the past hour that haven't been submitted yet
38+
if (new Date(er.createdAt).getTime() > now - 1000 * 60 * 60) {
39+
editingNow++
40+
}
41+
})
2942
return {
3043
jsonBody: {
3144
event,
3245
userRating,
46+
submittedRatingCount,
47+
editingNow,
3348
},
3449
}
3550
} catch (error) {

0 commit comments

Comments
 (0)