Immediate access granted if no appointments in system.

This commit is contained in:
Hendrik Belitz
2026-03-03 14:56:17 +01:00
parent 166373aa85
commit 10656edf2f
2 changed files with 18 additions and 0 deletions
@@ -77,6 +77,14 @@ export class AppointmentService {
}
}
async hasAppointments(): Promise<boolean> {
const log = logger.setContext("AppointmentService");
log.debug("Checking if tenant has appointments", { tenantId: this.tenantId });
const db = await this.getDb();
const result = await db.select().from(tenantSchema.appointment).limit(1);
return result.length > 0;
}
/**
* Send appointment notification email to client
* @param appointmentId - The appointment ID
+10
View File
@@ -19,6 +19,7 @@ import { TenantAdminService } from "./tenant-admin-service";
import { InviteService } from "./invite-service";
import type { PgTransaction } from "drizzle-orm/pg-core";
import type { PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js";
import { AppointmentService } from "./appointment-service";
export type InsertUser = InferInsertModel<typeof centralSchema.user>;
export type InsertUserPasskey = InferInsertModel<typeof centralSchema.userPasskey>;
@@ -140,6 +141,15 @@ export class UserService {
if (userData.role === "GLOBAL_ADMIN") {
userDataForDb.confirmationState = "ACCESS_GRANTED"; // Admin account is active immediately after email confirmation
userDataForDb.isActive = true;
} else if (userData.tenantId) {
const appointmentService = await AppointmentService.forTenant(userData.tenantId);
const hasAppointments = await appointmentService.hasAppointments();
if (!hasAppointments) {
log.debug("No appointments found for tenant, granting immediate access to user", {
tenantId: userData.tenantId,
});
userDataForDb.confirmationState = "ACCESS_GRANTED";
}
}
// Handle passphrase or generate recovery passphrase