mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
fix: Add explicit null checks for strict boolean expressions
- Fixed strict-boolean-expressions in API routes and database functions - Added explicit null/undefined/empty string checks throughout - Fixed 14 more errors in production code - Total: 97 errors remaining (25% reduction from baseline) Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -182,7 +182,7 @@ function handleApprove(registry: SchemaRegistry, registryPath: string, id?: stri
|
||||
}
|
||||
|
||||
function handleReject(registry: SchemaRegistry, registryPath: string, id?: string) {
|
||||
if (!id) {
|
||||
if (id === null || id === undefined || id === '') {
|
||||
return NextResponse.json(
|
||||
{ status: 'error', error: 'Migration ID required' },
|
||||
{ status: 400 }
|
||||
|
||||
@@ -48,7 +48,7 @@ export const GET = async (request: NextRequest, { params }: RouteParams) => {
|
||||
})
|
||||
} catch (error) {
|
||||
const status =
|
||||
typeof error === 'object' && error && 'status' in error
|
||||
typeof error === 'object' && error !== null && 'status' in error
|
||||
? Number((error as { status?: number }).status)
|
||||
: 500
|
||||
const message = error instanceof Error ? error.message : 'Unknown error'
|
||||
|
||||
@@ -30,7 +30,7 @@ export const GET = async (request: NextRequest) => {
|
||||
})
|
||||
} catch (error) {
|
||||
const status =
|
||||
typeof error === 'object' && error && 'status' in error
|
||||
typeof error === 'object' && error !== null && 'status' in error
|
||||
? Number((error as { status?: number }).status)
|
||||
: 500
|
||||
const message = error instanceof Error ? error.message : 'Unknown error'
|
||||
|
||||
@@ -81,7 +81,7 @@ async function handleRequest(
|
||||
if (['POST', 'PUT', 'PATCH'].includes(request.method)) {
|
||||
try {
|
||||
const text = await request.text()
|
||||
if (text) {
|
||||
if (text !== null && text !== undefined && text !== '') {
|
||||
body = JSON.parse(text)
|
||||
}
|
||||
} catch {
|
||||
@@ -124,18 +124,18 @@ async function handleRequest(
|
||||
|
||||
if (!result.success) {
|
||||
// Map common errors to appropriate status codes
|
||||
const errorMsg = result.error || 'Operation failed'
|
||||
if (errorMsg.includes('not found')) {
|
||||
const errorMsg = result.error ?? 'Operation failed'
|
||||
if (errorMsg !== null && errorMsg !== undefined && errorMsg.includes('not found')) {
|
||||
return errorResponse(errorMsg, STATUS.NOT_FOUND)
|
||||
}
|
||||
if (errorMsg.includes('required')) {
|
||||
if (errorMsg !== null && errorMsg !== undefined && errorMsg.includes('required')) {
|
||||
return errorResponse(errorMsg, STATUS.BAD_REQUEST)
|
||||
}
|
||||
return errorResponse(errorMsg, STATUS.INTERNAL_ERROR)
|
||||
}
|
||||
|
||||
// Build response with metadata
|
||||
const responseData = result.meta
|
||||
const responseData = result.meta !== null && result.meta !== undefined
|
||||
? { data: result.data, ...(result.meta as Record<string, unknown>) }
|
||||
: result.data
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ export default async function RootPage() {
|
||||
const pkg = await loadJSONPackage(`/home/rewrich/Documents/GitHub/metabuilder/packages/${route.packageId}`)
|
||||
const component = pkg?.components?.find(c => c.id === route.component || c.name === route.component)
|
||||
|
||||
if (component) {
|
||||
if (component !== null && component !== undefined) {
|
||||
return renderJSONComponent(component, {}, {})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ export async function getPackageData(packageId: string): Promise<PackageSeedData
|
||||
const pkg = (await adapter.findFirst('PackageData', {
|
||||
where: { packageId },
|
||||
})) as { data: string } | null
|
||||
if (!pkg) return {}
|
||||
if (pkg === null || pkg === undefined) return {}
|
||||
return JSON.parse(pkg.data) as PackageSeedData
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function installPackage(packageData: InstalledPackage): Promise<voi
|
||||
const existing = await adapter.findFirst('InstalledPackage', {
|
||||
where: { packageId: packageData.packageId },
|
||||
})
|
||||
if (!existing) {
|
||||
if (existing === null || existing === undefined) {
|
||||
await adapter.create('InstalledPackage', {
|
||||
packageId: packageData.packageId,
|
||||
installedAt: BigInt(packageData.installedAt),
|
||||
|
||||
@@ -37,6 +37,6 @@ export async function getPages(): Promise<PageConfig[]> {
|
||||
level: Number(p.level) as PageConfig['level'],
|
||||
componentTree: JSON.parse(p.componentTree) as PageConfig['componentTree'],
|
||||
requiresAuth: p.requiresAuth,
|
||||
requiredRole: p.requiredRole ? toUserRole(p.requiredRole) : undefined,
|
||||
requiredRole: p.requiredRole !== null && p.requiredRole !== undefined ? toUserRole(p.requiredRole) : undefined,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ export async function addSchema(schema: ModelSchema): Promise<void> {
|
||||
labelPlural: schema.labelPlural,
|
||||
icon: schema.icon,
|
||||
fields: JSON.stringify(schema.fields),
|
||||
listDisplay: schema.listDisplay ? JSON.stringify(schema.listDisplay) : null,
|
||||
listFilter: schema.listFilter ? JSON.stringify(schema.listFilter) : null,
|
||||
searchFields: schema.searchFields ? JSON.stringify(schema.searchFields) : null,
|
||||
ordering: schema.ordering ? JSON.stringify(schema.ordering) : null,
|
||||
listDisplay: schema.listDisplay !== null && schema.listDisplay !== undefined ? JSON.stringify(schema.listDisplay) : null,
|
||||
listFilter: schema.listFilter !== null && schema.listFilter !== undefined ? JSON.stringify(schema.listFilter) : null,
|
||||
searchFields: schema.searchFields !== null && schema.searchFields !== undefined ? JSON.stringify(schema.searchFields) : null,
|
||||
ordering: schema.ordering !== null && schema.ordering !== undefined ? JSON.stringify(schema.ordering) : null,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user