Hooked up calendar viewing to API, still needs a lot more polish
This commit is contained in:
6
api/src/services/calendarService.d.ts
vendored
6
api/src/services/calendarService.d.ts
vendored
@@ -1,6 +0,0 @@
|
||||
export declare function createEvent(eventObject: any): Promise<void>;
|
||||
export declare function updateEvent(eventObject: any): Promise<void>;
|
||||
export declare function cancelEvent(eventID: any): Promise<void>;
|
||||
export declare function getShortEventsInRange(startDate: any, endDate: any): Promise<void>;
|
||||
export declare function getEventDetailed(eventID: any): Promise<void>;
|
||||
//# sourceMappingURL=calendarService.d.ts.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"calendarService.d.ts","sourceRoot":"","sources":["calendarService.ts"],"names":[],"mappings":"AAEA,wBAAsB,WAAW,CAAC,WAAW,KAAA,iBAE5C;AAED,wBAAsB,WAAW,CAAC,WAAW,KAAA,iBAE5C;AAED,wBAAsB,WAAW,CAAC,OAAO,KAAA,iBAExC;AAED,wBAAsB,qBAAqB,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA,iBAE7D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,KAAA,iBAE7C"}
|
||||
@@ -1,19 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createEvent = createEvent;
|
||||
exports.updateEvent = updateEvent;
|
||||
exports.cancelEvent = cancelEvent;
|
||||
exports.getShortEventsInRange = getShortEventsInRange;
|
||||
exports.getEventDetailed = getEventDetailed;
|
||||
const pool = require('../db');
|
||||
async function createEvent(eventObject) {
|
||||
}
|
||||
async function updateEvent(eventObject) {
|
||||
}
|
||||
async function cancelEvent(eventID) {
|
||||
}
|
||||
async function getShortEventsInRange(startDate, endDate) {
|
||||
}
|
||||
async function getEventDetailed(eventID) {
|
||||
}
|
||||
//# sourceMappingURL=calendarService.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"calendarService.js","sourceRoot":"","sources":["calendarService.ts"],"names":[],"mappings":";;AAEA,kCAEC;AAED,kCAEC;AAED,kCAEC;AAED,sDAEC;AAED,4CAEC;AApBD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAEtB,KAAK,UAAU,WAAW,CAAC,WAAW;AAE7C,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,WAAW;AAE7C,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,OAAO;AAEzC,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,SAAS,EAAE,OAAO;AAE9D,CAAC;AAEM,KAAK,UAAU,gBAAgB,CAAC,OAAO;AAE9C,CAAC"}
|
||||
@@ -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