mirror of
https://github.com/open-reception/appointment-booking-software.git
synced 2026-08-17 21:25:52 +02:00
Immediate access granted if no appointments in system.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user