From 1dad9552f697c077fb40a58597de833a00cfb56e Mon Sep 17 00:00:00 2001 From: Hendrik Belitz Date: Tue, 3 Mar 2026 15:58:24 +0100 Subject: [PATCH] If staff creates an appointment, treat it as being already confirmed --- .../server/services/appointment-service.ts | 48 +++++++++++-------- .../[id]/appointments/staff-create/+server.ts | 6 +-- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/lib/server/services/appointment-service.ts b/src/lib/server/services/appointment-service.ts index 9606414..0e2d969 100644 --- a/src/lib/server/services/appointment-service.ts +++ b/src/lib/server/services/appointment-service.ts @@ -481,21 +481,24 @@ export class AppointmentService { /** * Add appointment to existing client tunnel */ - public async addAppointmentToTunnel(appointmentData: { - emailHash: string; - tunnelId: string; - channelId: string; - agentId: string; - appointmentDate: string; - duration: number; - clientEmail: string; - clientLanguage?: string; - encryptedAppointment: { - encryptedPayload: string; - iv: string; - authTag: string; - }; - }): Promise { + public async addAppointmentToTunnel( + appointmentData: { + emailHash: string; + tunnelId: string; + channelId: string; + agentId: string; + appointmentDate: string; + duration: number; + clientEmail: string; + clientLanguage?: string; + encryptedAppointment: { + encryptedPayload: string; + iv: string; + authTag: string; + }; + }, + staffCreated = false, + ): Promise { const log = logger.setContext("AppointmentService"); log.info("Adding appointment to existing tunnel", { @@ -539,8 +542,11 @@ export class AppointmentService { throw new NotFoundError("Active channel not found"); } - const initialStatus = channelResult[0].requiresConfirmation ? "NEW" : "CONFIRMED"; - const requiresConfirmation = channelResult[0].requiresConfirmation || false; + const initialStatus = + channelResult[0].requiresConfirmation && !staffCreated ? "NEW" : "CONFIRMED"; + const requiresConfirmation = staffCreated + ? false + : channelResult[0].requiresConfirmation || false; // Create encrypted appointment const appointmentResult = await db @@ -589,6 +595,7 @@ export class AppointmentService { */ public async createNewClientWithAppointment( clientData: ClientTunnelData, + staffCreated = false, ): Promise { const log = logger.setContext("AppointmentService"); @@ -685,8 +692,11 @@ export class AppointmentService { throw new NotFoundError("Channel not found"); } - const initialStatus = channelResult[0].requiresConfirmation ? "NEW" : "CONFIRMED"; - const requiresConfirmation = channelResult[0].requiresConfirmation || false; + const initialStatus = + channelResult[0].requiresConfirmation && !staffCreated ? "NEW" : "CONFIRMED"; + const requiresConfirmation = staffCreated + ? false + : channelResult[0].requiresConfirmation || false; // 4. Create encrypted appointment const appointmentResult = await tx diff --git a/src/routes/api/tenants/[id]/appointments/staff-create/+server.ts b/src/routes/api/tenants/[id]/appointments/staff-create/+server.ts index 425b280..92e737d 100644 --- a/src/routes/api/tenants/[id]/appointments/staff-create/+server.ts +++ b/src/routes/api/tenants/[id]/appointments/staff-create/+server.ts @@ -321,7 +321,7 @@ export const POST: RequestHandler = async ({ params, request, locals }) => { encryptedAppointment: validatedData.encryptedAppointment, }; - result = await appointmentService.addAppointmentToTunnel(appointmentData); + result = await appointmentService.addAppointmentToTunnel(appointmentData, true); } else { // New client - create tunnel and appointment isNewClient = true; @@ -360,7 +360,7 @@ export const POST: RequestHandler = async ({ params, request, locals }) => { clientEncryptedTunnelKey: validatedData.clientEncryptedTunnelKey, }; - result = await appointmentService.createNewClientWithAppointment(clientData); + result = await appointmentService.createNewClientWithAppointment(clientData, true); // For new clients with email: initiate PIN reset flow if (validatedData.clientEmail && !validatedData.hasNoEmail) { @@ -397,7 +397,7 @@ export const POST: RequestHandler = async ({ params, request, locals }) => { validatedData.channelId, validatedData.clientEmail, validatedData.clientLanguage, - !!result.requiresConfirmation, + false, ); } catch (error) { logger.error("Failed to send appointment notification", {