Hooked up calendar viewing to API, still needs a lot more polish
This commit is contained in:
@@ -1,18 +1,5 @@
|
||||
import pool from '../db';
|
||||
|
||||
export interface CalendarEvent {
|
||||
id: number;
|
||||
name: string;
|
||||
start: Date; // DATETIME -> Date
|
||||
end: Date; // DATETIME -> Date
|
||||
location: string;
|
||||
color: string; // 7 character hex string
|
||||
description?: string | null;
|
||||
creator?: number | null; // foreign key to members.id, nullable
|
||||
cancelled: boolean; // TINYINT(1) -> boolean
|
||||
created_at: Date; // TIMESTAMP -> Date
|
||||
updated_at: Date; // TIMESTAMP -> Date
|
||||
}
|
||||
import { CalendarEventShort, CalendarSignup, CalendarEvent } from "@app/shared/types/calendar"
|
||||
|
||||
export type Attendance = 'attending' | 'maybe' | 'not_attending';
|
||||
|
||||
@@ -29,7 +16,7 @@ export async function createEvent(eventObject: Omit<CalendarEvent, 'id' | 'creat
|
||||
eventObject.location,
|
||||
eventObject.color,
|
||||
eventObject.description ?? null,
|
||||
eventObject.creator,
|
||||
eventObject.creator_id,
|
||||
];
|
||||
|
||||
const result = await pool.query(sql, params);
|
||||
@@ -78,17 +65,19 @@ export async function cancelEvent(eventID: number) {
|
||||
}
|
||||
|
||||
|
||||
export async function getShortEventsInRange(startDate: Date, endDate: Date) {
|
||||
export async function getShortEventsInRange(startDate: string, endDate: string): Promise<CalendarEventShort[]> {
|
||||
const sql = `
|
||||
SELECT id, name, start, end, color
|
||||
FROM calendar_events
|
||||
WHERE start BETWEEN ? AND ?
|
||||
ORDER BY start ASC
|
||||
`;
|
||||
return await pool.query(sql, [startDate, endDate]);
|
||||
const res: CalendarEventShort[] = await pool.query(sql, [startDate, endDate]);
|
||||
console.log(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function getEventDetails(eventID: number) {
|
||||
export async function getEventDetails(eventID: number): Promise<CalendarEvent> {
|
||||
const sql = `
|
||||
SELECT
|
||||
e.id,
|
||||
@@ -101,14 +90,14 @@ export async function getEventDetails(eventID: number) {
|
||||
e.cancelled,
|
||||
e.created_at,
|
||||
e.updated_at,
|
||||
m.id AS creator_id,
|
||||
e.creator AS creator_id,
|
||||
m.name AS creator_name
|
||||
FROM calendar_events e
|
||||
LEFT JOIN members m ON e.creator = m.id
|
||||
WHERE e.id = ?
|
||||
`;
|
||||
|
||||
return await pool.query(sql, [eventID])
|
||||
let vals: CalendarEvent[] = await pool.query(sql, [eventID]);
|
||||
return vals[0];
|
||||
}
|
||||
|
||||
export async function getUpcomingEvents(date: Date, limit: number) {
|
||||
@@ -135,7 +124,7 @@ export async function setAttendanceStatus(memberID: number, eventID: number, sta
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function getEventAttendance(eventID: number) {
|
||||
export async function getEventAttendance(eventID: number): Promise<CalendarSignup[]> {
|
||||
const sql = `
|
||||
SELECT
|
||||
s.member_id,
|
||||
|
||||
Reference in New Issue
Block a user