1
0

Compare commits

...

6 Commits

Author SHA1 Message Date
jzitnik 1c6023beab chore: Added classes to announcement type
Remote Deploy / deploy (push) Successful in 1m26s
2026-06-02 17:13:32 +02:00
jzitnik f559d3a91b fix: No parse
Remote Deploy / deploy (push) Successful in 1m20s
2026-06-02 16:04:31 +02:00
jzitnik 1e971a0601 fix: Typo
Remote Deploy / deploy (push) Successful in 1m18s
2026-06-02 15:45:55 +02:00
jzitnik 32b31814e2 feat: Show always annoucements for this week
Remote Deploy / deploy (push) Successful in 1m35s
2026-06-02 12:29:00 +02:00
jzitnik 1f9543909a chore: Test
Remote Deploy / deploy (push) Successful in 1m16s
2026-06-02 12:12:35 +02:00
jzitnik b4118f7b25 chore: possible fix 2026-06-02 12:09:42 +02:00
3 changed files with 36 additions and 7 deletions
@@ -2,8 +2,9 @@ const API_BASE_URL = process.env.ANNOUNCEMENT_API || "http://localhost:3000";
export type Announcement = { export type Announcement = {
id: number; id: number;
text_content: string; text_content?: string;
author: string; author: string;
classes: string[];
flags: Flag[]; flags: Flag[];
start_date: string; start_date: string;
end_date: string; end_date: string;
+33 -5
View File
@@ -18,7 +18,7 @@ import parseTeachers from "../utils/parseTeachers.js"
import ExcelJS, { Worksheet, Cell, Row, Workbook } from "exceljs" import ExcelJS, { Worksheet, Cell, Row, Workbook } from "exceljs"
import JSZip from "jszip"; import JSZip from "jszip";
import { parseStringPromise } from "xml2js"; import { parseStringPromise } from "xml2js";
import getAnnouncements, { Flag } from "../api/annoucements.js"; import getAnnouncements, { Flag } from "../api/announcements.js";
interface ThemeColors { interface ThemeColors {
[key: number]: string | null; [key: number]: string | null;
@@ -124,13 +124,21 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
const upcoming = getUpcomingSheets(workbook); const upcoming = getUpcomingSheets(workbook);
const resolvedDays = groupSheetsByDate(upcoming); const resolvedDays = groupSheetsByDate(upcoming);
const getDates = resolvedDays.map((d) => d.dateKey);
const annoucements = await getAnnouncements(getDates); const sheetDates = resolvedDays.map((d) => d.dateKey);
const announcementDates = getWeekDates().concat(sheetDates);
if (new Date().getDay() === 0) {
announcementDates.push(...getWeekDates(7));
}
const announcements = await getAnnouncements([...new Set(announcementDates)]);
const schedule: any = {}; const schedule: any = {};
for (const { dateKey, sheet } of resolvedDays) { for (const { dateKey, sheet } of resolvedDays) {
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, annoucements[dateKey].map(a => a.flags).flat()); const ann = announcements[dateKey];
const allFlags = ann.map(a => a.flags).flat();
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, allFlags);
schedule[dateKey] = { schedule[dateKey] = {
info: { inWork }, info: { inWork },
@@ -143,7 +151,7 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
const data = { const data = {
status: { lastUpdated: formatNowTime() }, status: { lastUpdated: formatNowTime() },
annoucements, announcements,
schedule, schedule,
}; };
@@ -231,6 +239,7 @@ function isPripravaSheet(name: string) {
// //
function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null, flags: Flag[]) { function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null, flags: Flag[]) {
console.log(flags)
const ignoreColors = flags.includes(Flag.SHOW_ALL_ENTRIES) const ignoreColors = flags.includes(Flag.SHOW_ALL_ENTRIES)
const classRegex = /[AEC][0-4][a-c]?\s*\/.*/s; const classRegex = /[AEC][0-4][a-c]?\s*\/.*/s;
const prefixRegex = /[AEC][0-4][a-c]?/; const prefixRegex = /[AEC][0-4][a-c]?/;
@@ -420,6 +429,25 @@ function letterToNumber(letter: string) {
return letter.toLowerCase().charCodeAt(0) - 97; return letter.toLowerCase().charCodeAt(0) - 97;
} }
function getWeekDates(offset: number = 0): string[] {
const today = new Date();
const day = today.getDay();
const monday = new Date(today);
monday.setDate(today.getDate() + (day === 0 ? -6 : 1 - day) + offset);
const dates: string[] = [];
for (let i = 0; i < 5; i++) {
const d = new Date(monday);
d.setDate(monday.getDate() + i);
dates.push(formatDateKey(d));
}
return dates;
}
function formatDateKey(date: Date): string {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
}
function formatNowTime() { function formatNowTime() {
const now = new Date(); const now = new Date();
return ( return (