import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; /** * Whether the instance still requires the first-run setup wizard * (issue #80). Setup is pending until `setup.completedAt` is written — * by the wizard's complete step, by env pre-seeding, by the fixture seed, * or by the backfill migration for instances that predate the wizard. * * Reads the row directly instead of going through InstanceSettingsService: * that service caches misses, and a request hitting a still-pending * instance must not freeze the pending state past an external seed (the * e2e stacks seed a running api). Completion is permanent, so a completed * answer is remembered for the process lifetime and costs nothing per * request; while pending, the instance serves almost no traffic anyway. */ @Injectable() export class SetupStateService { private completed = false; constructor(private readonly prisma: PrismaService) {} async isPending(): Promise { if (this.completed) return false; const row = await this.prisma.instanceSetting.findUnique({ where: { key: 'setup.completedAt' }, select: { value: true }, }); if (typeof row?.value === 'string' && row.value) { this.completed = true; return false; } return true; } }