added --today parameter to send a nofitication for todays events else its change or new events. also fetches current and next month now.

This commit is contained in:
2025-10-20 02:58:16 +02:00
parent 1cdcf2f423
commit f086fd9792
6 changed files with 49 additions and 54 deletions

View File

@@ -4,6 +4,14 @@ import { transformArray } from "../../util";
const BASE_URL = "https://77th-jsoc.com/service.php?action=get_events";
export type TGetEventsOptions = {
notification?: TEventEntity["notification"][] | null,
date?: {
year: number,
month: number,
day: number
}
}
export type TEventEntity = TEvent & {
event_uid: number
notification: "new" | "changed" | "deleted" | "done"
@@ -45,7 +53,7 @@ export class Event implements TEventEntity {
console.log(`Inserted ${count} events`);
}
static async fetch_events( _year_: number, _month_: number, timezone: number) {
static async fetch_events( _year_: number, _month_: number, timezone: number): Promise<TEvent[]> {
const url = `${BASE_URL}&year=${_year_}&month=${_month_}&timezone=${timezone}`
const response = await fetch(url, {
method: "GET",
@@ -55,15 +63,18 @@ export class Event implements TEventEntity {
return events;
}
static get_events (notification: TEventEntity["notification"][] | null, db: Database ) {
static get_events (options: TGetEventsOptions, db: Database ) {
const whereConditions: string[] = [];
if ( notification ) {
whereConditions.push( `notification IN ('${ notification.join("', '") }')` )
if ( options.notification ) {
whereConditions.push( `notification IN ('${ options.notification.join("', '") }')` )
}
if (options.date) {
whereConditions.push(`date_at = "${options.date.year}-${options.date.month}-${options.date.day}"`);
}
const where = ( () => {
let str = "WHERE ";
if ( whereConditions.length >= 1 ) {
str += whereConditions.join(" AND ");
str += whereConditions.join(" OR ");
}
return str;
})()