diff --git a/src/lib/services/documents.service.ts b/src/lib/services/documents.service.ts index d0b9d821..09909a7b 100644 --- a/src/lib/services/documents.service.ts +++ b/src/lib/services/documents.service.ts @@ -184,6 +184,10 @@ export async function listDocuments( } else { filters.push(eq(documents.folderId, query.folderId)); } + // When viewing a specific folder, hide completed workflows — they surface + // via their resulting signed-PDF file row in the Files section, not the + // Signing section. + filters.push(ne(documents.status, 'completed')); } if (sentSince) filters.push(gte(documents.createdAt, new Date(sentSince))); if (sentUntil) filters.push(lte(documents.createdAt, new Date(sentUntil))); diff --git a/tests/integration/documents-list-folder-filter.test.ts b/tests/integration/documents-list-folder-filter.test.ts index f764631b..d9189d29 100644 --- a/tests/integration/documents-list-folder-filter.test.ts +++ b/tests/integration/documents-list-folder-filter.test.ts @@ -126,4 +126,38 @@ describe('documents.listDocuments folder filtering', () => { const titles = (res.data as Array<{ title: string }>).map((d) => d.title); expect(titles).toEqual(['At Root']); }); + + it('hides completed workflows when folderId is set', async () => { + const folder = await createFolder(portId, testUserId, { name: 'ClientFolder', parentId: null }); + await db.insert(documents).values([ + { + portId, + documentType: 'eoi', + title: 'In flight', + createdBy: testUserId, + folderId: folder.id, + status: 'sent', + }, + { + portId, + documentType: 'eoi', + title: 'Completed workflow', + createdBy: testUserId, + folderId: folder.id, + status: 'completed', + }, + ]); + + const res = await listDocuments(portId, { + page: 1, + limit: 50, + order: 'desc', + includeArchived: false, + includeDescendants: false, + folderId: folder.id, + }); + const titles = (res.data as Array<{ title: string }>).map((d) => d.title); + expect(titles).toContain('In flight'); + expect(titles).not.toContain('Completed workflow'); + }); });