Fix creating and deleting calendars

This fixes the creation and deletion of calendars to include a color and the proper chosen name.
This commit is contained in:
Bruno Bernardino
2025-09-06 19:17:48 +01:00
parent 24944de0f6
commit 49dbc724c8
8 changed files with 30 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ import { Handlers } from 'fresh/server.ts';
import { FreshContextState } from '/lib/types.ts';
import { Calendar, CalendarModel } from '/lib/models/calendar.ts';
import { getColorAsHex } from '/lib/utils/calendar.ts';
interface Data {}
@@ -23,7 +24,7 @@ export const handler: Handlers<Data, FreshContextState> = {
const requestBody = await request.clone().json() as RequestBody;
if (requestBody.name) {
await CalendarModel.create(context.state.user.id, requestBody.name);
await CalendarModel.create(context.state.user.id, requestBody.name, getColorAsHex('bg-gray-700'));
}
const newCalendars = await CalendarModel.list(context.state.user.id);

View File

@@ -3,7 +3,7 @@ import { Handlers } from 'fresh/server.ts';
import { FreshContextState } from '/lib/types.ts';
import { Calendar, CalendarModel } from '/lib/models/calendar.ts';
import { UserModel } from '/lib/models/user.ts';
import { getColorAsHex } from '/lib/utils/calendar.ts';
import { CALENDAR_COLOR_OPTIONS, getColorAsHex } from '/lib/utils/calendar.ts';
interface Data {}
@@ -37,7 +37,7 @@ export const handler: Handlers<Data, FreshContextState> = {
calendar.displayName = requestBody.name;
calendar.calendarColor = requestBody.color?.startsWith('#')
? requestBody.color
: getColorAsHex(requestBody.color || 'bg-gray-700');
: getColorAsHex((requestBody.color || 'bg-gray-700') as typeof CALENDAR_COLOR_OPTIONS[number]);
await CalendarModel.update(context.state.user.id, calendar.url, calendar.displayName, calendar.calendarColor);