mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
Fix 12 unnecessary condition warnings in database and package code
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,7 @@ export async function deleteSessionByToken(token: string): Promise<boolean> {
|
||||
}
|
||||
if (result.data.length === 0) return false
|
||||
const session = result.data[0]
|
||||
if (session === null || session === undefined) return false
|
||||
if (session === undefined) return false
|
||||
await adapter.delete('Session', session.id)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function updateSession(
|
||||
): Promise<Session> {
|
||||
const adapter = getAdapter()
|
||||
const record = await adapter.update('Session', sessionId, {
|
||||
...(input.token !== null && input.token !== undefined ? { token: input.token } : {}),
|
||||
...(input.token !== undefined ? { token: input.token } : {}),
|
||||
...(input.expiresAt !== undefined ? { expiresAt: BigInt(input.expiresAt) } : {}),
|
||||
...(input.lastActivity !== undefined ? { lastActivity: BigInt(input.lastActivity) } : {}),
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { ListSessionsOptions, Session } from '../types'
|
||||
|
||||
export async function listSessions(options?: ListSessionsOptions): Promise<Session[]> {
|
||||
const adapter = getAdapter()
|
||||
const result = options?.userId !== null && options?.userId !== undefined
|
||||
const result = options?.userId !== undefined
|
||||
? await adapter.list('Session', { filter: { userId: options.userId } })
|
||||
: await adapter.list('Session')
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function getSMTPConfig(): Promise<SMTPConfig | null> {
|
||||
const adapter = getAdapter()
|
||||
const result = (await adapter.list('SMTPConfig')) as { data: DBALSMTPConfig[] }
|
||||
const config = result.data[0]
|
||||
if (config === null || config === undefined) return null
|
||||
if (config === undefined) return null
|
||||
|
||||
return {
|
||||
host: config.host,
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function getUserById(
|
||||
options?: { tenantId?: string }
|
||||
): Promise<User | null> {
|
||||
const adapter = getAdapter()
|
||||
const record = options?.tenantId !== null && options?.tenantId !== undefined
|
||||
const record = options?.tenantId !== undefined
|
||||
? await adapter.findFirst('User', { where: { id: userId, tenantId: options.tenantId } })
|
||||
: await adapter.read('User', userId)
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ export type GetUsersOptions = { tenantId: string } | { scope: 'all' }
|
||||
export async function getUsers(options: GetUsersOptions): Promise<User[]> {
|
||||
const adapter = getAdapter()
|
||||
const listOptions = 'tenantId' in options ? { filter: { tenantId: options.tenantId } } : undefined
|
||||
const result = listOptions !== null && listOptions !== undefined ? await adapter.list('User', listOptions) : await adapter.list('User')
|
||||
const result = listOptions !== undefined ? await adapter.list('User', listOptions) : await adapter.list('User')
|
||||
return (result.data as Record<string, unknown>[]).map(user => mapUserRecord(user))
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export async function loadJSONPackage(packagePath: string): Promise<JSONPackage>
|
||||
const componentsContent = await readFile(componentsPath, 'utf-8')
|
||||
const componentsData = JSON.parse(componentsContent) as { components?: JSONComponent[] }
|
||||
components = componentsData.components ?? []
|
||||
hasComponents = (components !== null && components !== undefined && Array.isArray(components)) ? components.length > 0 : false
|
||||
hasComponents = Array.isArray(components) && components.length > 0
|
||||
} catch {
|
||||
// Components file doesn't exist
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export async function loadJSONPackage(packagePath: string): Promise<JSONPackage>
|
||||
const permissionsContent = await readFile(permissionsPath, 'utf-8')
|
||||
const permissionsData = JSON.parse(permissionsContent) as { permissions?: JSONPermission[] }
|
||||
permissions = permissionsData.permissions ?? []
|
||||
hasPermissions = (permissions !== null && permissions !== undefined && Array.isArray(permissions)) ? permissions.length > 0 : false
|
||||
hasPermissions = Array.isArray(permissions) && permissions.length > 0
|
||||
} catch {
|
||||
// Permissions file doesn't exist
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export function renderJSONComponent(
|
||||
props: Record<string, JsonValue> = {},
|
||||
ComponentRegistry: Record<string, React.ComponentType<Record<string, unknown>>> = {}
|
||||
): React.ReactElement {
|
||||
if (component.render === null || component.render === undefined) {
|
||||
if (component.render === undefined) {
|
||||
return (
|
||||
<div style={{ padding: '1rem', border: '1px solid red', borderRadius: '0.25rem' }}>
|
||||
<strong>Error:</strong> Component {component.name} has no render definition
|
||||
@@ -37,7 +37,7 @@ export function renderJSONComponent(
|
||||
|
||||
try {
|
||||
const template = component.render.template
|
||||
if (template === null || template === undefined) {
|
||||
if (template === undefined) {
|
||||
return (
|
||||
<div style={{ padding: '1rem', border: '1px solid yellow', borderRadius: '0.25rem' }}>
|
||||
<strong>Warning:</strong> Component {component.name} has no template
|
||||
|
||||
@@ -4,7 +4,7 @@ import { DEVELOPMENT_PACKAGE_REPO_CONFIG } from './development-config'
|
||||
import { PRODUCTION_PACKAGE_REPO_CONFIG } from './production-config'
|
||||
|
||||
export function getPackageRepoConfig(): PackageRepoConfig {
|
||||
const env = process.env.NODE_ENV !== undefined && process.env.NODE_ENV.length > 0 ? process.env.NODE_ENV : 'development'
|
||||
const env = process.env.NODE_ENV !== undefined ? process.env.NODE_ENV : 'development'
|
||||
const enableRemote = process.env.NEXT_PUBLIC_ENABLE_REMOTE_PACKAGES === 'true'
|
||||
|
||||
let config: PackageRepoConfig
|
||||
|
||||
@@ -10,7 +10,7 @@ export function checkDependencies(
|
||||
packageId: string
|
||||
): DependencyCheckResult {
|
||||
const pkg = registry[packageId]
|
||||
if (pkg === null || pkg === undefined) return { satisfied: false, missing: [packageId] }
|
||||
const missing = (pkg.dependencies ?? []).filter((dep) => registry[dep] === null || registry[dep] === undefined)
|
||||
if (pkg === undefined) return { satisfied: false, missing: [packageId] }
|
||||
const missing = (pkg.dependencies ?? []).filter((dep) => registry[dep] === undefined)
|
||||
return { satisfied: missing.length === 0, missing }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { PackageDefinition } from '../types'
|
||||
|
||||
export function getPackageComponents(pkg: PackageDefinition) {
|
||||
return pkg.components ?? []
|
||||
return pkg.components !== undefined ? pkg.components : []
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function loadPackage(packageId: string): Promise<UnifiedPackage | n
|
||||
}
|
||||
|
||||
const legacyEntry = PACKAGE_CATALOG[packageId]
|
||||
if (legacyEntry !== null && legacyEntry !== undefined) {
|
||||
if (legacyEntry !== undefined) {
|
||||
const data = legacyEntry()
|
||||
return {
|
||||
packageId: data.manifest.id,
|
||||
|
||||
Reference in New Issue
Block a user