mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
Fix strict-boolean-expressions in error-logs, schemas, pages, and users
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -76,25 +76,25 @@ export default async function RootPage() {
|
||||
|
||||
const homePackageRecord = installedPackages.data.find((pkg) => {
|
||||
try {
|
||||
const config = JSON.parse(pkg.config || '{}')
|
||||
const config = JSON.parse(pkg.config ?? '{}') as { defaultRoute?: string }
|
||||
return config.defaultRoute === '/'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (homePackageRecord) {
|
||||
if (homePackageRecord !== null && homePackageRecord !== undefined) {
|
||||
const packageId = homePackageRecord.packageId
|
||||
const pkg = await loadJSONPackage(`/home/rewrich/Documents/GitHub/metabuilder/packages/${packageId}`)
|
||||
|
||||
if (pkg?.components && pkg.components.length > 0) {
|
||||
if ((pkg?.components !== null && pkg?.components !== undefined) && pkg.components.length > 0) {
|
||||
const pageComponent = pkg.components.find(c =>
|
||||
c.id === 'home_page' ||
|
||||
c.name === 'HomePage' ||
|
||||
c.name === 'Home'
|
||||
) || pkg.components[0]
|
||||
) ?? pkg.components[0]
|
||||
|
||||
if (pageComponent) {
|
||||
if (pageComponent !== null && pageComponent !== undefined) {
|
||||
return renderJSONComponent(pageComponent, {}, {})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export default async function DynamicUIPage({ params }: PageProps) {
|
||||
// Prefer Lua package-based UI pages, fallback to database-backed pages
|
||||
const rawPageData = (await loadPageFromLuaPackages(path)) ?? (await loadPageFromDb(path))
|
||||
|
||||
if (!rawPageData) {
|
||||
if (rawPageData === null || rawPageData === undefined) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export async function generateMetadata({ params }: PageProps): Promise<Metadata>
|
||||
|
||||
const pageData = (await loadPageFromLuaPackages(path)) ?? (await loadPageFromDb(path))
|
||||
|
||||
if (!pageData) {
|
||||
if (pageData === null || pageData === undefined) {
|
||||
return {
|
||||
title: 'Page Not Found',
|
||||
}
|
||||
|
||||
@@ -13,31 +13,46 @@ export async function getErrorLogs(options?: {
|
||||
const adapter = getAdapter()
|
||||
const result = await adapter.list('ErrorLog')
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let logs = (result.data as any[]).map(log => ({
|
||||
type ErrorLogRecord = {
|
||||
id: string
|
||||
timestamp: bigint | number
|
||||
level: string
|
||||
message: string
|
||||
stack?: string | null
|
||||
context?: string | null
|
||||
userId?: string | null
|
||||
username?: string | null
|
||||
tenantId?: string | null
|
||||
source?: string | null
|
||||
resolved: boolean
|
||||
resolvedAt?: bigint | number | null
|
||||
resolvedBy?: string | null
|
||||
}
|
||||
|
||||
let logs = (result.data as ErrorLogRecord[]).map(log => ({
|
||||
id: log.id,
|
||||
timestamp: Number(log.timestamp),
|
||||
level: log.level as 'error' | 'warning' | 'info',
|
||||
message: log.message,
|
||||
stack: log.stack || undefined,
|
||||
context: log.context || undefined,
|
||||
userId: log.userId || undefined,
|
||||
username: log.username || undefined,
|
||||
tenantId: log.tenantId || undefined,
|
||||
source: log.source || undefined,
|
||||
stack: log.stack ?? undefined,
|
||||
context: log.context ?? undefined,
|
||||
userId: log.userId ?? undefined,
|
||||
username: log.username ?? undefined,
|
||||
tenantId: log.tenantId ?? undefined,
|
||||
source: log.source ?? undefined,
|
||||
resolved: log.resolved,
|
||||
resolvedAt: log.resolvedAt ? Number(log.resolvedAt) : undefined,
|
||||
resolvedBy: log.resolvedBy || undefined,
|
||||
resolvedAt: (log.resolvedAt !== null && log.resolvedAt !== undefined) ? Number(log.resolvedAt) : undefined,
|
||||
resolvedBy: log.resolvedBy ?? undefined,
|
||||
}))
|
||||
|
||||
// Apply filters
|
||||
if (options?.level) {
|
||||
if (options?.level !== null && options?.level !== undefined) {
|
||||
logs = logs.filter(log => log.level === options.level)
|
||||
}
|
||||
if (options?.resolved !== undefined) {
|
||||
logs = logs.filter(log => log.resolved === options.resolved)
|
||||
}
|
||||
if (options?.tenantId) {
|
||||
if (options?.tenantId !== null && options?.tenantId !== undefined) {
|
||||
logs = logs.filter(log => log.tenantId === options.tenantId)
|
||||
}
|
||||
|
||||
@@ -45,7 +60,7 @@ export async function getErrorLogs(options?: {
|
||||
logs.sort((a, b) => b.timestamp - a.timestamp)
|
||||
|
||||
// Apply limit
|
||||
if (options?.limit && options.limit > 0) {
|
||||
if ((options?.limit !== null && options?.limit !== undefined) && options.limit > 0) {
|
||||
logs = logs.slice(0, options.limit)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ export async function getSchemas(): Promise<ModelSchema[]> {
|
||||
return result.data.map(s => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
label: s.label || undefined,
|
||||
labelPlural: s.labelPlural || undefined,
|
||||
icon: s.icon || undefined,
|
||||
fields: JSON.parse(s.fields),
|
||||
listDisplay: s.listDisplay ? JSON.parse(s.listDisplay) : undefined,
|
||||
listFilter: s.listFilter ? JSON.parse(s.listFilter) : undefined,
|
||||
searchFields: s.searchFields ? JSON.parse(s.searchFields) : undefined,
|
||||
ordering: s.ordering ? JSON.parse(s.ordering) : undefined,
|
||||
label: s.label ?? undefined,
|
||||
labelPlural: s.labelPlural ?? undefined,
|
||||
icon: s.icon ?? undefined,
|
||||
fields: JSON.parse(s.fields) as ModelSchema['fields'],
|
||||
listDisplay: (s.listDisplay !== null && s.listDisplay !== undefined) ? JSON.parse(s.listDisplay) as string[] : undefined,
|
||||
listFilter: (s.listFilter !== null && s.listFilter !== undefined) ? JSON.parse(s.listFilter) as string[] : undefined,
|
||||
searchFields: (s.searchFields !== null && s.searchFields !== undefined) ? JSON.parse(s.searchFields) as string[] : undefined,
|
||||
ordering: (s.ordering !== null && s.ordering !== undefined) ? JSON.parse(s.ordering) as string[] : undefined,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ export async function setSchemas(schemas: ModelSchema[]): Promise<void> {
|
||||
|
||||
// Delete existing schemas
|
||||
const existing = await adapter.list('ModelSchema')
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
for (const s of existing.data as any[]) {
|
||||
for (const s of existing.data as Array<{ name: string }>) {
|
||||
await adapter.delete('ModelSchema', s.name)
|
||||
}
|
||||
|
||||
@@ -22,10 +21,10 @@ export async function setSchemas(schemas: 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ export function mapUserRecord(record: Record<string, unknown>): User {
|
||||
username: String(record.username),
|
||||
email: String(record.email),
|
||||
role: record.role as User['role'],
|
||||
profilePicture: record.profilePicture ? String(record.profilePicture) : undefined,
|
||||
bio: record.bio ? String(record.bio) : undefined,
|
||||
profilePicture: (record.profilePicture !== null && record.profilePicture !== undefined) ? String(record.profilePicture) : undefined,
|
||||
bio: (record.bio !== null && record.bio !== undefined) ? String(record.bio) : undefined,
|
||||
createdAt: Number(record.createdAt),
|
||||
tenantId: record.tenantId ? String(record.tenantId) : undefined,
|
||||
tenantId: (record.tenantId !== null && record.tenantId !== undefined) ? String(record.tenantId) : undefined,
|
||||
isInstanceOwner: Boolean(record.isInstanceOwner),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user