format codebase with prettier
This commit is contained in:
@@ -4,34 +4,37 @@ import {
|
||||
DAY_TO_GERMAN,
|
||||
DAY_TO_GERMAN_SHORT,
|
||||
MONTH_TO_GERMAN,
|
||||
} from '@caldav/shared';
|
||||
import { EventRepository } from '../services/interfaces';
|
||||
import { expandRecurringEvents, ExpandedEvent } from './recurrenceExpander';
|
||||
} from "@caldav/shared";
|
||||
import { EventRepository } from "../services/interfaces";
|
||||
import { expandRecurringEvents, ExpandedEvent } from "./recurrenceExpander";
|
||||
|
||||
// Private formatting helpers
|
||||
|
||||
function formatTime(date: Date): string {
|
||||
const hours = date.getHours().toString().padStart(2, '0');
|
||||
const minutes = date.getMinutes().toString().padStart(2, '0');
|
||||
const hours = date.getHours().toString().padStart(2, "0");
|
||||
const minutes = date.getMinutes().toString().padStart(2, "0");
|
||||
return `${hours}:${minutes}`;
|
||||
}
|
||||
|
||||
function formatDateShort(date: Date): string {
|
||||
const day = date.getDate().toString().padStart(2, '0');
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = date.getDate().toString().padStart(2, "0");
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||
return `${day}.${month}.`;
|
||||
}
|
||||
|
||||
function getWeekNumber(date: Date): number {
|
||||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||
const d = new Date(
|
||||
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()),
|
||||
);
|
||||
const dayNum = d.getUTCDay() || 7;
|
||||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
return Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
|
||||
return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);
|
||||
}
|
||||
|
||||
function formatWeeksText(events: ExpandedEvent[], weeks: number): string {
|
||||
const weeksText = weeks === 1 ? 'die nächste Woche' : `die nächsten ${weeks} Wochen`;
|
||||
const weeksText =
|
||||
weeks === 1 ? "die nächste Woche" : `die nächsten ${weeks} Wochen`;
|
||||
|
||||
if (events.length === 0) {
|
||||
return `Du hast für ${weeksText} keine Termine.`;
|
||||
@@ -47,8 +50,10 @@ function formatWeeksText(events: ExpandedEvent[], weeks: number): string {
|
||||
lines.push(`${weekday}, ${dateStr} - ${timeStr} Uhr: ${event.title}`);
|
||||
}
|
||||
|
||||
lines.push(`\nInsgesamt ${events.length} Termin${events.length === 1 ? '' : 'e'}.`);
|
||||
return lines.join('\n');
|
||||
lines.push(
|
||||
`\nInsgesamt ${events.length} Termin${events.length === 1 ? "" : "e"}.`,
|
||||
);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function formatMonthText(events: ExpandedEvent[], monthName: string): string {
|
||||
@@ -66,13 +71,17 @@ function formatMonthText(events: ExpandedEvent[], monthName: string): string {
|
||||
weekGroups.get(weekNum)!.push(event);
|
||||
}
|
||||
|
||||
const lines: string[] = [`Hier ist deine Monatsübersicht für ${monthName}:\n`];
|
||||
const lines: string[] = [
|
||||
`Hier ist deine Monatsübersicht für ${monthName}:\n`,
|
||||
];
|
||||
|
||||
// Sort weeks and format
|
||||
const sortedWeeks = Array.from(weekGroups.keys()).sort((a, b) => a - b);
|
||||
for (const weekNum of sortedWeeks) {
|
||||
const weekEvents = weekGroups.get(weekNum)!;
|
||||
lines.push(`KW ${weekNum}: ${weekEvents.length} Termin${weekEvents.length === 1 ? '' : 'e'}`);
|
||||
lines.push(
|
||||
`KW ${weekNum}: ${weekEvents.length} Termin${weekEvents.length === 1 ? "" : "e"}`,
|
||||
);
|
||||
|
||||
for (const event of weekEvents) {
|
||||
const day = DAY_INDEX_TO_DAY[event.occurrenceStart.getDay()];
|
||||
@@ -81,11 +90,13 @@ function formatMonthText(events: ExpandedEvent[], monthName: string): string {
|
||||
const timeStr = formatTime(event.occurrenceStart);
|
||||
lines.push(` • ${weekdayShort} ${dateStr}, ${timeStr}: ${event.title}`);
|
||||
}
|
||||
lines.push('');
|
||||
lines.push("");
|
||||
}
|
||||
|
||||
lines.push(`Insgesamt ${events.length} Termin${events.length === 1 ? '' : 'e'} im ${monthName}.`);
|
||||
return lines.join('\n');
|
||||
lines.push(
|
||||
`Insgesamt ${events.length} Termin${events.length === 1 ? "" : "e"} im ${monthName}.`,
|
||||
);
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
// Public API
|
||||
@@ -97,7 +108,7 @@ function formatMonthText(events: ExpandedEvent[], monthName: string): string {
|
||||
export async function getWeeksOverview(
|
||||
eventRepo: EventRepository,
|
||||
userId: string,
|
||||
weeks: number
|
||||
weeks: number,
|
||||
): Promise<string> {
|
||||
const now = new Date();
|
||||
const endDate = new Date(now.getTime() + weeks * 7 * 24 * 60 * 60 * 1000);
|
||||
@@ -114,7 +125,7 @@ export async function getMonthOverview(
|
||||
eventRepo: EventRepository,
|
||||
userId: string,
|
||||
year: number,
|
||||
month: number
|
||||
month: number,
|
||||
): Promise<string> {
|
||||
const startOfMonth = new Date(year, month, 1);
|
||||
const endOfMonth = new Date(year, month + 1, 0, 23, 59, 59);
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './jwt';
|
||||
export * from './password';
|
||||
export * from "./jwt";
|
||||
export * from "./password";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export interface TokenPayload {
|
||||
userId: string;
|
||||
@@ -10,17 +10,17 @@ export interface JWTConfig {
|
||||
expiresIn: string;
|
||||
}
|
||||
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key';
|
||||
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || '1h';
|
||||
const JWT_SECRET = process.env.JWT_SECRET || "your-secret-key";
|
||||
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || "1h";
|
||||
|
||||
export function signToken(payload: TokenPayload): string {
|
||||
throw new Error('Not implemented');
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
export function verifyToken(token: string): TokenPayload {
|
||||
throw new Error('Not implemented');
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
export function decodeToken(token: string): TokenPayload | null {
|
||||
throw new Error('Not implemented');
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import bcrypt from 'bcrypt';
|
||||
import bcrypt from "bcrypt";
|
||||
|
||||
const SALT_ROUNDS = 10;
|
||||
|
||||
@@ -6,6 +6,9 @@ export async function hash(password: string): Promise<string> {
|
||||
return bcrypt.hash(password, SALT_ROUNDS);
|
||||
}
|
||||
|
||||
export async function compare(password: string, hash: string): Promise<boolean> {
|
||||
export async function compare(
|
||||
password: string,
|
||||
hash: string,
|
||||
): Promise<boolean> {
|
||||
return bcrypt.compare(password, hash);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { RRule, rrulestr } from 'rrule';
|
||||
import { CalendarEvent } from '@caldav/shared';
|
||||
import { RRule, rrulestr } from "rrule";
|
||||
import { CalendarEvent } from "@caldav/shared";
|
||||
|
||||
export interface ExpandedEvent extends CalendarEvent {
|
||||
occurrenceStart: Date;
|
||||
@@ -9,14 +9,16 @@ export interface ExpandedEvent extends CalendarEvent {
|
||||
// Convert local time to "fake UTC" for rrule
|
||||
// rrule interprets all dates as UTC internally, so we need to trick it
|
||||
function toRRuleDate(date: Date): Date {
|
||||
return new Date(Date.UTC(
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
date.getSeconds()
|
||||
));
|
||||
return new Date(
|
||||
Date.UTC(
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
date.getSeconds(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Convert rrule result back to local time
|
||||
@@ -27,7 +29,7 @@ function fromRRuleDate(date: Date): Date {
|
||||
date.getUTCDate(),
|
||||
date.getUTCHours(),
|
||||
date.getUTCMinutes(),
|
||||
date.getUTCSeconds()
|
||||
date.getUTCSeconds(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,7 +40,7 @@ function fromRRuleDate(date: Date): Date {
|
||||
export function expandRecurringEvents(
|
||||
events: CalendarEvent[],
|
||||
rangeStart: Date,
|
||||
rangeEnd: Date
|
||||
rangeEnd: Date,
|
||||
): ExpandedEvent[] {
|
||||
const expanded: ExpandedEvent[] = [];
|
||||
|
||||
@@ -61,13 +63,15 @@ export function expandRecurringEvents(
|
||||
|
||||
// Recurring event: parse RRULE and expand
|
||||
try {
|
||||
const rule = rrulestr(`DTSTART:${formatRRuleDateString(startTime)}\nRRULE:${event.recurrenceRule}`);
|
||||
const rule = rrulestr(
|
||||
`DTSTART:${formatRRuleDateString(startTime)}\nRRULE:${event.recurrenceRule}`,
|
||||
);
|
||||
|
||||
// Get occurrences within the range (using fake UTC dates)
|
||||
const occurrences = rule.between(
|
||||
toRRuleDate(rangeStart),
|
||||
toRRuleDate(rangeEnd),
|
||||
true // inclusive
|
||||
true, // inclusive
|
||||
);
|
||||
|
||||
for (const occurrence of occurrences) {
|
||||
@@ -82,7 +86,10 @@ export function expandRecurringEvents(
|
||||
}
|
||||
} catch (error) {
|
||||
// If RRULE parsing fails, include the event as a single occurrence
|
||||
console.error(`Failed to parse recurrence rule for event ${event.id}:`, error);
|
||||
console.error(
|
||||
`Failed to parse recurrence rule for event ${event.id}:`,
|
||||
error,
|
||||
);
|
||||
expanded.push({
|
||||
...event,
|
||||
occurrenceStart: startTime,
|
||||
@@ -92,7 +99,9 @@ export function expandRecurringEvents(
|
||||
}
|
||||
|
||||
// Sort by occurrence start time
|
||||
expanded.sort((a, b) => a.occurrenceStart.getTime() - b.occurrenceStart.getTime());
|
||||
expanded.sort(
|
||||
(a, b) => a.occurrenceStart.getTime() - b.occurrenceStart.getTime(),
|
||||
);
|
||||
|
||||
return expanded;
|
||||
}
|
||||
@@ -100,10 +109,10 @@ export function expandRecurringEvents(
|
||||
// Format date as RRULE DTSTART string (YYYYMMDDTHHMMSS)
|
||||
function formatRRuleDateString(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
const hours = String(date.getHours()).padStart(2, "0");
|
||||
const minutes = String(date.getMinutes()).padStart(2, "0");
|
||||
const seconds = String(date.getSeconds()).padStart(2, "0");
|
||||
return `${year}${month}${day}T${hours}${minutes}${seconds}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user