|
1 | | -import type { DBHandle, Prisma } from "@dotkomonline/db" |
| 1 | +import type { DBHandle, Prisma, findFeaturedEvents } from "@dotkomonline/db" |
2 | 2 | import { |
3 | 3 | type AttendanceId, |
| 4 | + type BaseEvent, |
| 5 | + BaseEventSchema, |
4 | 6 | type CompanyId, |
5 | 7 | type DeregisterReason, |
6 | 8 | DeregisterReasonSchema, |
@@ -40,6 +42,8 @@ const INCLUDE_COMPANY_AND_GROUPS = { |
40 | 42 | export interface EventRepository { |
41 | 43 | create(handle: DBHandle, data: EventWrite): Promise<Event> |
42 | 44 | update(handle: DBHandle, eventId: EventId, data: Partial<EventWrite>): Promise<Event> |
| 45 | + updateEventAttendance(handle: DBHandle, eventId: EventId, attendanceId: AttendanceId): Promise<Event> |
| 46 | + updateEventParent(handle: DBHandle, eventId: EventId, parentEventId: EventId | null): Promise<Event> |
43 | 47 | /** |
44 | 48 | * Soft-delete an event by setting its status to "DELETED". |
45 | 49 | */ |
@@ -80,15 +84,17 @@ export interface EventRepository { |
80 | 84 | page: Pageable |
81 | 85 | ): Promise<Event[]> |
82 | 86 | findByParentEventId(handle: DBHandle, parentEventId: EventId): Promise<Event[]> |
| 87 | + findEventsWithUnansweredFeedbackFormByUserId(handle: DBHandle, userId: UserId): Promise<Event[]> |
| 88 | + findManyDeregisterReasonsWithEvent(handle: DBHandle, page: Pageable): Promise<DeregisterReasonWithEvent[]> |
| 89 | + // This cannot use `Pageable` due to raw query needing numerical offset and not cursor based pagination |
| 90 | + findFeaturedEvents(handle: DBHandle, offset: number, limit: number): Promise<BaseEvent[]> |
| 91 | + |
83 | 92 | addEventHostingGroups(handle: DBHandle, eventId: EventId, hostingGroupIds: Set<GroupId>): Promise<void> |
84 | | - addEventCompanies(handle: DBHandle, eventId: EventId, companyIds: Set<CompanyId>): Promise<void> |
85 | 93 | deleteEventHostingGroups(handle: DBHandle, eventId: EventId, hostingGroupIds: Set<GroupId>): Promise<void> |
| 94 | + addEventCompanies(handle: DBHandle, eventId: EventId, companyIds: Set<CompanyId>): Promise<void> |
86 | 95 | deleteEventCompanies(handle: DBHandle, eventId: EventId, companyIds: Set<CompanyId>): Promise<void> |
87 | | - updateEventAttendance(handle: DBHandle, eventId: EventId, attendanceId: AttendanceId): Promise<Event> |
88 | | - updateEventParent(handle: DBHandle, eventId: EventId, parentEventId: EventId | null): Promise<Event> |
89 | | - findEventsWithUnansweredFeedbackFormByUserId(handle: DBHandle, userId: UserId): Promise<Event[]> |
| 96 | + |
90 | 97 | createDeregisterReason(handle: DBHandle, data: DeregisterReasonWrite): Promise<DeregisterReason> |
91 | | - findManyDeregisterReasonsWithEvent(handle: DBHandle, page: Pageable): Promise<DeregisterReasonWithEvent[]> |
92 | 98 | } |
93 | 99 |
|
94 | 100 | export function getEventRepository(): EventRepository { |
@@ -309,6 +315,25 @@ export function getEventRepository(): EventRepository { |
309 | 315 | ) |
310 | 316 | }, |
311 | 317 |
|
| 318 | + async findFeaturedEvents(handle, offset, limit) { |
| 319 | + // Events will primarily be ranked by their type in the following order (lower number is higher ranking): |
| 320 | + // 1. GENERAL_ASSEMBLY |
| 321 | + // 2. COMPANY, ACADEMIC |
| 322 | + // 3. SOCIAL, INTERNAL, OTHER, WELCOME |
| 323 | + // |
| 324 | + // Within each bucket they will be ranked like this: |
| 325 | + // 1. Event in future, registration open and not full AND attendance capacity is limited (>0) |
| 326 | + // 2. Event in future, registration not started yet (attendance capacity does not matter) |
| 327 | + // 3. Event in future, no attendance registration OR attendance capacity is unlimited (=0) |
| 328 | + // 4. Event in future, registration full (registration status does not matter) |
| 329 | + // |
| 330 | + // Past events are not featured. We would rather have no featured events than "stale" events. |
| 331 | + |
| 332 | + const events = await handle.$queryRawTyped(findFeaturedEvents(offset, limit)) |
| 333 | + |
| 334 | + return parseOrReport(BaseEventSchema.array(), events) |
| 335 | + }, |
| 336 | + |
312 | 337 | async addEventHostingGroups(handle, eventId, hostingGroupIds) { |
313 | 338 | await handle.eventHostingGroup.createMany({ |
314 | 339 | data: hostingGroupIds |
|
0 commit comments