Fix TypeScript type errors in schemaConfigurationService

- Type all db variables as DatabaseAdapter to enable generic method calls
- Add explicit type annotations for row parameters in map callbacks
- Cast ensureInitialized calls to any (not part of DatabaseAdapter interface)

Resolves all 9 TypeScript linter errors in the file
This commit is contained in:
2026-01-21 03:31:55 +01:00
parent cdee0e8819
commit c331540369

View File

@@ -10,6 +10,7 @@ import { logger } from './logger.js';
import { normalizedCacheStore } from './normalizedCacheStore.js';
import { config } from '../config/env.js';
import { toPascalCase } from './schemaUtils.js';
import type { DatabaseAdapter } from './database/interface.js';
export interface JiraSchema {
id: number;
@@ -62,12 +63,12 @@ class SchemaConfigurationService {
schemaName: string;
objectTypes: ConfiguredObjectType[];
}>> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
const rows = await db.query<{
id: number;
@@ -141,12 +142,12 @@ class SchemaConfigurationService {
* id format: "schemaId:objectTypeId" (e.g., "6:123")
*/
async setObjectTypeEnabled(id: string, enabled: boolean): Promise<void> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
// Parse id: "schemaId:objectTypeId"
const [schemaIdStr, objectTypeIdStr] = id.split(':');
@@ -226,16 +227,16 @@ class SchemaConfigurationService {
* Bulk update enabled status for multiple object types
*/
async bulkSetObjectTypesEnabled(updates: Array<{ id: string; enabled: boolean }>): Promise<void> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
const now = new Date().toISOString();
await db.transaction(async (txDb) => {
await db.transaction(async (txDb: DatabaseAdapter) => {
for (const update of updates) {
// Parse id: "schemaId:objectTypeId"
const [schemaIdStr, objectTypeIdStr] = update.id.split(':');
@@ -321,12 +322,12 @@ class SchemaConfigurationService {
objectTypeName: string;
displayName: string;
}>> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
// Use parameterized query to avoid boolean/integer comparison issues
const rows = await db.query<{
@@ -342,7 +343,12 @@ class SchemaConfigurationService {
[db.isPostgres ? true : 1]
);
return rows.map(row => ({
return rows.map((row: {
jira_schema_id: string;
jira_type_id: number;
type_name: string;
display_name: string;
}) => ({
schemaId: row.jira_schema_id,
objectTypeId: row.jira_type_id,
objectTypeName: row.type_name,
@@ -368,12 +374,12 @@ class SchemaConfigurationService {
disabledObjectTypes: number;
isConfigured: boolean;
}> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
const totalRow = await db.queryOne<{ count: number }>(`
SELECT COUNT(*) as count FROM object_types
@@ -410,12 +416,12 @@ class SchemaConfigurationService {
schemaName: string;
searchEnabled: boolean;
}>> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
const rows = await db.query<{
jira_schema_id: string;
@@ -427,7 +433,11 @@ class SchemaConfigurationService {
ORDER BY name ASC
`);
return rows.map(row => ({
return rows.map((row: {
jira_schema_id: string;
name: string;
search_enabled: boolean | number;
}) => ({
schemaId: row.jira_schema_id,
schemaName: row.name,
searchEnabled: typeof row.search_enabled === 'boolean' ? row.search_enabled : row.search_enabled === 1,
@@ -438,12 +448,12 @@ class SchemaConfigurationService {
* Set search enabled status for a schema
*/
async setSchemaSearchEnabled(schemaId: string, searchEnabled: boolean): Promise<void> {
const db = (normalizedCacheStore as any).db;
const db: DatabaseAdapter = (normalizedCacheStore as any).db;
if (!db) {
throw new Error('Database not available');
}
await db.ensureInitialized?.();
await (db as any).ensureInitialized?.();
const now = new Date().toISOString();