feat(ocr): implement delete provider API endpoint
Add DELETE endpoint for OCR providers with proper type definitions and handler implementation. The endpoint removes the provider from both the registry and database after validation checks.
This commit is contained in:
@@ -382,7 +382,8 @@ export interface ApiSchemas {
|
||||
response: PutOcrProviderResponse
|
||||
}
|
||||
DELETE: {
|
||||
// TODO
|
||||
params: { id: OcrProviderId }
|
||||
response: void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,8 +230,8 @@ export const apiHandlers: ApiImplementation = {
|
||||
PUT: async ({ body }) => {
|
||||
return ocrService.putProvider(body)
|
||||
},
|
||||
DELETE: async () => {
|
||||
throw new Error('Not implemented')
|
||||
DELETE: async ({ params }) => {
|
||||
return ocrService.deleteProvider(params.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,22 @@ export class OcrService {
|
||||
return { data: updated }
|
||||
}
|
||||
|
||||
public async deleteProvider(providerId: string): Promise<void> {
|
||||
if (!this.registry.has(providerId)) {
|
||||
throw new Error(`OCR provider ${providerId} is not registered`)
|
||||
}
|
||||
const providers = await dbService
|
||||
.getDb()
|
||||
.select()
|
||||
.from(ocrProviderTable)
|
||||
.where(eq(ocrProviderTable.id, providerId))
|
||||
.limit(1)
|
||||
if (providers.length === 0) {
|
||||
throw new Error(`OCR provider ${providerId} not found`)
|
||||
}
|
||||
await dbService.getDb().delete(ocrProviderTable).where(eq(ocrProviderTable.id, providerId))
|
||||
}
|
||||
|
||||
public async ocr(file: SupportedOcrFile, params: OcrParams): Promise<OcrResult> {
|
||||
const service = this.registry.get(params.providerId)
|
||||
if (!service) {
|
||||
|
||||
Reference in New Issue
Block a user