added support for short format training report and created_by field
This commit is contained in:
@@ -17,7 +17,7 @@ courseRouter.get('/', async (req, res) => {
|
||||
|
||||
eventRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let events: CourseEventDetails[] = await getCourseEvents();
|
||||
let events = await getCourseEvents();
|
||||
res.status(200).json(events);
|
||||
} catch (error) {
|
||||
console.error('failed to fetch reports', error);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pool from "../db"
|
||||
import { Course, CourseAttendee, CourseEventDetails, RawAttendeeRow } from "@app/shared/types/course"
|
||||
import { Course, CourseAttendee, CourseEventDetails, CourseEventSummary, RawAttendeeRow } from "@app/shared/types/course"
|
||||
|
||||
export async function getAllCourses(): Promise<Course[]> {
|
||||
const sql = "SELECT * FROM courses WHERE deleted = false;"
|
||||
@@ -86,8 +86,9 @@ export async function insertCourseEvent(event: CourseEventDetails): Promise<numb
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCourseEvents(): Promise<CourseEventDetails[]> {
|
||||
const sql = "SELECT * FROM course_events;";
|
||||
let events: CourseEventDetails[] = await pool.query(sql);
|
||||
export async function getCourseEvents(): Promise<CourseEventSummary[]> {
|
||||
const sql = "SELECT E.id, E.course_id, E.event_date, E.created_by, C.name FROM course_events as E LEFT JOIN courses AS C ON E.course_id = C.id;";
|
||||
let events: CourseEventSummary[] = await pool.query(sql);
|
||||
console.log(events);
|
||||
return events;
|
||||
}
|
||||
@@ -27,6 +27,8 @@ export interface CourseEventDetails {
|
||||
remarks: string | null; // text
|
||||
|
||||
attendees: CourseAttendee[] | null;
|
||||
|
||||
created_by: number | null;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,3 +68,11 @@ export interface RawAttendeeRow {
|
||||
role_created_at: string | null;
|
||||
role_updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface CourseEventSummary {
|
||||
event_id: number;
|
||||
course_id: number;
|
||||
course_name: string;
|
||||
date: string;
|
||||
created_by: number;
|
||||
}
|
||||
Reference in New Issue
Block a user