added support for optional checkboxes
This commit is contained in:
@@ -4,14 +4,21 @@ import { Course, CourseAttendee, CourseAttendeeRole, CourseEventDetails, CourseE
|
||||
export async function getAllCourses(): Promise<Course[]> {
|
||||
const sql = "SELECT * FROM courses WHERE deleted = false;"
|
||||
|
||||
const res = await pool.query(sql);
|
||||
const res: Course[] = await pool.query(sql);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function getCourseByID(id: number): Promise<Course> {
|
||||
const sql = "SELECT * FROM courses WHERE id = ?;"
|
||||
const res: Course[] = await pool.query(sql, [id]);
|
||||
return res[0];
|
||||
}
|
||||
|
||||
function buildAttendee(row: RawAttendeeRow): CourseAttendee {
|
||||
return {
|
||||
passed: !!row.passed,
|
||||
passed_bookwork: !!row.passed_bookwork,
|
||||
passed_qual: !!row.passed_qual,
|
||||
attendee_id: row.attendee_id,
|
||||
course_event_id: row.course_event_id,
|
||||
created_at: row.created_at,
|
||||
@@ -67,6 +74,7 @@ export async function getCourseEventDetails(id: number): Promise<CourseEventDeta
|
||||
let rows: CourseEventDetails[] = await pool.query(sql, [id]);
|
||||
let event = rows[0];
|
||||
event.attendees = await getCourseEventAttendees(id);
|
||||
event.course = await getCourseByID(event.course_id);
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -83,10 +91,11 @@ export async function insertCourseEvent(event: CourseEventDetails): Promise<numb
|
||||
attendee_id,
|
||||
course_event_id,
|
||||
attendee_role_id,
|
||||
passed,
|
||||
passed_bookwork,
|
||||
passed_qual,
|
||||
remarks
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?);`, [attendee.attendee_id, eventID, attendee.attendee_role_id, attendee.passed, attendee.remarks]);
|
||||
VALUES (?, ?, ?, ?, ?);`, [attendee.attendee_id, eventID, attendee.attendee_role_id, attendee.passed_bookwork, attendee.passed_qual, attendee.remarks]);
|
||||
}
|
||||
await con.commit();
|
||||
await con.release();
|
||||
|
||||
Reference in New Issue
Block a user