feat(CC-061): add DocumentsController (GET /documents with classification/ocrStatus filters)
This commit is contained in:
parent
c5d256ea78
commit
47b85203bd
1 changed files with 31 additions and 0 deletions
31
src/documents/documents.controller.ts
Normal file
31
src/documents/documents.controller.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
|
import { and, desc, eq, isNull } from 'drizzle-orm';
|
||||||
|
import { CurrentSession } from '../auth/session.decorator';
|
||||||
|
import type { AuthenticatedSession } from '../auth/tenant.guard';
|
||||||
|
import { db } from '../db/client';
|
||||||
|
import { documents } from '../db/schema';
|
||||||
|
|
||||||
|
@Controller('documents')
|
||||||
|
export class DocumentsController {
|
||||||
|
@Get()
|
||||||
|
async list(
|
||||||
|
@CurrentSession() session: AuthenticatedSession,
|
||||||
|
@Query('classification') classification?: string,
|
||||||
|
@Query('ocrStatus') ocrStatus?: string,
|
||||||
|
@Query('limit') limitStr?: string,
|
||||||
|
) {
|
||||||
|
const limit = Math.min(Math.max(1, parseInt(limitStr ?? '200', 10) || 200), 500);
|
||||||
|
const conditions = [
|
||||||
|
eq(documents.tenantId, session.tenantId),
|
||||||
|
isNull(documents.deletedAt),
|
||||||
|
];
|
||||||
|
if (classification) conditions.push(eq(documents.classification, classification as 'c0' | 'c1' | 'c2' | 'c3' | 'c4'));
|
||||||
|
if (ocrStatus) conditions.push(eq(documents.ocrStatus, ocrStatus));
|
||||||
|
|
||||||
|
return db.query.documents.findMany({
|
||||||
|
where: and(...conditions),
|
||||||
|
orderBy: desc(documents.createdAt),
|
||||||
|
limit,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue