implemented getter for course event details

This commit is contained in:
2025-11-16 01:29:22 -05:00
parent ca152f7955
commit 0ff3fc58de
3 changed files with 43 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
import pool from "../db"
import { Course, CourseAttendee, RawAttendeeRow } from "@app/shared/types/course"
import { Course, CourseAttendee, CourseEventDetails, RawAttendeeRow } from "@app/shared/types/course"
export async function getAllCourses(): Promise<Course[]> {
const sql = "SELECT * FROM courses WHERE deleted = false;"
@@ -32,7 +32,7 @@ function buildAttendee(row: RawAttendeeRow): CourseAttendee {
};
}
export async function getCourseAttendees(id: number): Promise<CourseAttendee[]> {
export async function getCourseEventAttendees(id: number): Promise<CourseAttendee[]> {
const sql = `SELECT
ca.*,
ar.id AS role_id,
@@ -48,4 +48,12 @@ export async function getCourseAttendees(id: number): Promise<CourseAttendee[]>
const res:RawAttendeeRow[] = await pool.query(sql, [id]);
return res.map((row) => buildAttendee(row))
}
export async function getCourseEventDetails(id: number): Promise<CourseEventDetails> {
const sql = `SELECT * FROM course_events WHERE id = ?;`;
let rows: CourseEventDetails[] = await pool.query(sql, [id]);
let event = rows[0];
event.attendees = await getCourseEventAttendees(id);
return event;
}