Made all created by human readable
This commit is contained in:
@@ -53,7 +53,17 @@ export async function getCourseEventAttendees(id: number): Promise<CourseAttende
|
||||
}
|
||||
|
||||
export async function getCourseEventDetails(id: number): Promise<CourseEventDetails> {
|
||||
const sql = `SELECT E.*, C.name AS course_name FROM course_events AS E LEFT JOIN courses AS C ON E.course_id = C.id WHERE E.id = ?;`;
|
||||
const sql = `SELECT
|
||||
E.*,
|
||||
M.name AS created_by_name,
|
||||
C.name AS course_name
|
||||
FROM course_events AS E
|
||||
LEFT JOIN courses AS C
|
||||
ON E.course_id = C.id
|
||||
LEFT JOIN members AS M
|
||||
ON E.created_by = M.id
|
||||
WHERE E.id = ?;
|
||||
`;
|
||||
let rows: CourseEventDetails[] = await pool.query(sql, [id]);
|
||||
let event = rows[0];
|
||||
event.attendees = await getCourseEventAttendees(id);
|
||||
@@ -65,7 +75,7 @@ export async function insertCourseEvent(event: CourseEventDetails): Promise<numb
|
||||
const con = await pool.getConnection();
|
||||
try {
|
||||
await con.beginTransaction();
|
||||
const res = await con.query("INSERT INTO course_events (course_id, event_date, remarks) VALUES (?, ?, ?);", [event.course_id, event.event_date, event.remarks]);
|
||||
const res = await con.query("INSERT INTO course_events (course_id, event_date, remarks, created_by) VALUES (?, ?, ?, ?);", [event.course_id, event.event_date, event.remarks, event.created_by]);
|
||||
var eventID: number = res.insertId;
|
||||
|
||||
for (const attendee of event.attendees) {
|
||||
@@ -89,7 +99,18 @@ export async function insertCourseEvent(event: CourseEventDetails): Promise<numb
|
||||
}
|
||||
|
||||
export async function getCourseEvents(): Promise<CourseEventSummary[]> {
|
||||
const sql = "SELECT E.id AS event_id, E.course_id, E.event_date AS date, E.created_by, C.name AS course_name FROM course_events as E LEFT JOIN courses AS C ON E.course_id = C.id;";
|
||||
const sql = `SELECT
|
||||
E.id AS event_id,
|
||||
E.course_id,
|
||||
E.event_date AS date,
|
||||
E.created_by,
|
||||
C.name AS course_name,
|
||||
M.name AS created_by_name
|
||||
FROM course_events AS E
|
||||
LEFT JOIN courses AS C
|
||||
ON E.course_id = C.id
|
||||
LEFT JOIN members AS M
|
||||
ON E.created_by = M.id;`;
|
||||
let events: CourseEventSummary[] = await pool.query(sql);
|
||||
return events;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user