11import type { DBHandle } from "@dotkomonline/db"
2+ import { findFeaturedEvents } from "@dotkomonline/db"
23import {
34 type AttendanceId ,
45 type CompanyId ,
@@ -12,6 +13,8 @@ import {
1213 type EventId ,
1314 EventSchema ,
1415 type EventWrite ,
16+ type FeaturedEvent ,
17+ FeaturedEventSchema ,
1518 type GroupId ,
1619 type UserId ,
1720} from "@dotkomonline/types"
@@ -41,6 +44,8 @@ const INCLUDE_COMPANY_AND_GROUPS = {
4144export interface EventRepository {
4245 create ( handle : DBHandle , data : EventWrite ) : Promise < Event >
4346 update ( handle : DBHandle , eventId : EventId , data : Partial < EventWrite > ) : Promise < Event >
47+ updateEventAttendance ( handle : DBHandle , eventId : EventId , attendanceId : AttendanceId ) : Promise < Event >
48+ updateEventParent ( handle : DBHandle , eventId : EventId , parentEventId : EventId | null ) : Promise < Event >
4449 /**
4550 * Soft-delete an event by setting its status to "DELETED".
4651 */
@@ -81,15 +86,17 @@ export interface EventRepository {
8186 page : Pageable
8287 ) : Promise < Event [ ] >
8388 findByParentEventId ( handle : DBHandle , parentEventId : EventId ) : Promise < Event [ ] >
89+ findEventsWithUnansweredFeedbackFormByUserId ( handle : DBHandle , userId : UserId ) : Promise < Event [ ] >
90+ findManyDeregisterReasonsWithEvent ( handle : DBHandle , page : Pageable ) : Promise < DeregisterReasonWithEvent [ ] >
91+ // This cannot use `Pageable` due to raw query needing numerical offset and not cursor based pagination
92+ findFeaturedEvents ( handle : DBHandle , offset : number , limit : number ) : Promise < FeaturedEvent [ "event" ] [ ] >
93+
8494 addEventHostingGroups ( handle : DBHandle , eventId : EventId , hostingGroupIds : Set < GroupId > ) : Promise < void >
85- addEventCompanies ( handle : DBHandle , eventId : EventId , companyIds : Set < CompanyId > ) : Promise < void >
8695 deleteEventHostingGroups ( handle : DBHandle , eventId : EventId , hostingGroupIds : Set < GroupId > ) : Promise < void >
96+ addEventCompanies ( handle : DBHandle , eventId : EventId , companyIds : Set < CompanyId > ) : Promise < void >
8797 deleteEventCompanies ( handle : DBHandle , eventId : EventId , companyIds : Set < CompanyId > ) : Promise < void >
88- updateEventAttendance ( handle : DBHandle , eventId : EventId , attendanceId : AttendanceId ) : Promise < Event >
89- updateEventParent ( handle : DBHandle , eventId : EventId , parentEventId : EventId | null ) : Promise < Event >
90- findEventsWithUnansweredFeedbackFormByUserId ( handle : DBHandle , userId : UserId ) : Promise < Event [ ] >
98+
9199 createDeregisterReason ( handle : DBHandle , data : DeregisterReasonWrite ) : Promise < DeregisterReason >
92- findManyDeregisterReasonsWithEvent ( handle : DBHandle , page : Pageable ) : Promise < DeregisterReasonWithEvent [ ] >
93100}
94101
95102export function getEventRepository ( ) : EventRepository {
@@ -310,6 +317,27 @@ export function getEventRepository(): EventRepository {
310317 )
311318 } ,
312319
320+ async findFeaturedEvents ( handle , offset , limit ) {
321+ // This is a complex task to do, and we will try to make it as simple as possible for now.
322+ //
323+ // Events will primarily be ranked by their type in the following order (lower number is higher ranking):
324+ // 1. GENERAL_ASSEMBLY
325+ // 2. COMPANY, ACADEMIC
326+ // 3. SOCIAL, INTERNAL, OTHER, WELCOME
327+ //
328+ // Within each bucket they will be ranked like this:
329+ // 1. Event in future, registration open and not full AND attendance capacity is limited (>0)
330+ // 2. Event in future, registration not started yet (attendance capacity does not matter)
331+ // 3. Event in future, no attendance registration OR attendance capacity is unlimited (=0)
332+ // 4. Event in future, registration full (registration status does not matter)
333+ //
334+ // Past events are not featured. We would rather have no featured events than "stale" events.
335+ const events = await handle . $queryRawTyped ( findFeaturedEvents ( offset , limit ) )
336+
337+ // FeaturedEventSchema includes attendance, so we pick just the event shape here
338+ return parseOrReport ( FeaturedEventSchema . shape . event . array ( ) , events )
339+ } ,
340+
313341 async addEventHostingGroups ( handle , eventId , hostingGroupIds ) {
314342 await handle . eventHostingGroup . createMany ( {
315343 data : hostingGroupIds
0 commit comments