chore(types): remove anys and harden Convex data fetch

- Strongly type company-service and API routes
- Fix Next.js searchParams (promise) in admin/machines page
- Add vitest module marker + stub for tsconfig-paths/register
- Use Convex query in client as primary fallback for machine details
- Replace any casts in admin machines components

Build + lint are clean locally; details page no longer skeleton-loops.
This commit is contained in:
Esdras Renan 2025-10-22 19:19:38 -03:00
parent eee0f432e7
commit c640e288b1
8 changed files with 76 additions and 90 deletions

View file

@ -17,6 +17,8 @@ export type NormalizedCompany = CompanyFormValues & {
updatedAt: string
}
type CompanyCreatePayload = Omit<Prisma.CompanyCreateInput, "provisioningCode">
// Local representation of the DB enum to avoid relying on Prisma enum exports
type DbCompanyStateRegistrationType = "STANDARD" | "EXEMPT" | "SIMPLES"
@ -210,10 +212,7 @@ export function sanitizeCompanyInput(input: unknown, tenantId: string): CompanyF
return normalized
}
export function buildCompanyData(
payload: CompanyFormValues,
tenantId: string
): Record<string, unknown> {
export function buildCompanyData(payload: CompanyFormValues, tenantId: string): CompanyCreatePayload {
const stateRegistrationType = payload.stateRegistrationType
? STATE_REGISTRATION_TYPE_TO_PRISMA[payload.stateRegistrationType as CompanyStateRegistrationTypeOption]
: null
@ -221,7 +220,7 @@ export function buildCompanyData(
const communicationChannels = mergeChannelsWithPrimary(payload)
const privacyPolicyMetadata = payload.privacyPolicy?.metadata ?? null
return {
const data: CompanyCreatePayload = {
tenantId,
name: payload.name.trim(),
slug: payload.slug.trim(),
@ -267,9 +266,11 @@ export function buildCompanyData(
customFields: payload.customFields,
notes: payload.notes ?? null,
}
return data
}
export function normalizeCompany(company: any): NormalizedCompany {
export function normalizeCompany(company: Company): NormalizedCompany {
const communicationChannels = normalizeChannels(
company.communicationChannels as CompanyCommunicationChannels | null | undefined
)
@ -387,7 +388,7 @@ function parseJsonValue(value: string | null): Prisma.JsonValue | null {
}
}
function mapRawRowToCompany(row: RawCompanyRow): any {
function mapRawRowToCompany(row: RawCompanyRow): Company {
return {
id: row.id,
tenantId: row.tenantId,
@ -477,7 +478,7 @@ const COMPANY_BASE_SELECT = Prisma.sql`
FROM "Company"
`
export async function fetchCompaniesByTenant(tenantId: string): Promise<any[]> {
export async function fetchCompaniesByTenant(tenantId: string): Promise<Company[]> {
const rows = await prisma.$queryRaw<RawCompanyRow[]>(Prisma.sql`
${COMPANY_BASE_SELECT}
WHERE tenantId = ${tenantId}
@ -486,7 +487,7 @@ export async function fetchCompaniesByTenant(tenantId: string): Promise<any[]> {
return rows.map(mapRawRowToCompany)
}
export async function fetchCompanyById(id: string): Promise<any | null> {
export async function fetchCompanyById(id: string): Promise<Company | null> {
const rows = await prisma.$queryRaw<RawCompanyRow[]>(Prisma.sql`
${COMPANY_BASE_SELECT}
WHERE id = ${id}