Moved Function to get a Title and Body of a Event to the Event Class.

This commit is contained in:
2025-10-26 14:07:28 +01:00
parent 420076a8cf
commit e9ead4e7bf
2 changed files with 50 additions and 54 deletions

View File

@@ -1,6 +1,6 @@
import { Database } from "bun:sqlite";
import type { TEvent } from "./event.types";
import { transformArray } from "../../util";
import { TEventType, type TEvent } from "./event.types";
import { getTsNow, pad_l2, transformArray } from "../../util";
const BASE_URL = "https://77th-jsoc.com/service.php?action=get_events";
@@ -176,4 +176,47 @@ export class Event implements TEventEntity {
});
return this.syncWithDb( db );
}
get_title() {
const type_of_notification = ( (event: Event) => {
switch ( event.notification ) {
case "new":
return "New";
case "changed":
return "Changed";
case "removed":
return "Removed";
default:
return null;
}
} ) ( this );
const title_prefix_arr = [];
if ( type_of_notification ) title_prefix_arr.push( "<" + type_of_notification + ">" );
if ( this.isEventToday() ) title_prefix_arr.push( "<TODAY>" )
return `${title_prefix_arr.length >= 1 ? ( title_prefix_arr.join(" " ) + " - ") : "" }${this.title} (${ TEventType[ this.event_type ] })`;
}
get_body() {
const body = [
`Title: ${this.title}`,
`Date: ${this.date_at}`,
`Time: ${this.time_start}`,
`Type: ${ TEventType[ this.event_type ] }`,
`Location: ${this.location}`,
`By: ${this.posted_by}`,
`Link: ${this.link}`,
].join("\n");
return body;
}
isEventToday ( ) {
const now = getTsNow();
const [year, month, day] = this.date_at.split("-")
if (
year == String(now.year) &&
month == pad_l2( String(now.month) ) &&
day == pad_l2( String( now.day ) )
) {
return true;
}
return false;
}
}