Exclude archived routines from folder counts

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-07-05 12:23:08 +00:00
1 parent 5dbd390710
commit c87d009aab
2 files changed
+22 -3

No files matched your search

+20 -1
View File
@@ -49,13 +49,14 @@ describeEmbeddedPostgres("folder service", () => {
return companyId;
}
async function seedRoutine(companyId: string, title: string, folderId?: string | null) {
async function seedRoutine(companyId: string, title: string, folderId?: string | null, status = "active") {
const [routine] = await db
.insert(routines)
.values({
companyId,
title,
folderId: folderId ?? null,
status,
responsibleUserId: "responsible-user",
})
.returning();
@@ -109,6 +110,24 @@ describeEmbeddedPostgres("folder service", () => {
]);
});
it("excludes archived routines from folder counts", async () => {
const companyId = await seedCompany();
const svc = folderService(db);
const reporting = await svc.create(companyId, { kind: "routine", name: "Reporting" });
await seedRoutine(companyId, "Active filed", reporting.id);
await seedRoutine(companyId, "Archived filed", reporting.id, "archived");
await seedRoutine(companyId, "Active unfiled");
await seedRoutine(companyId, "Archived unfiled", null, "archived");
const listed = await svc.list(companyId, "routine");
expect(listed.allCount).toBe(2);
expect(listed.unfiledCount).toBe(1);
expect(listed.folders).toEqual([
expect.objectContaining({ id: reporting.id, itemCount: 1 }),
]);
});
it("moves routines and skills to folders and back to virtual Unfiled", async () => {
const companyId = await seedCompany();
const svc = folderService(db);
+2 -2
View File
@@ -1,4 +1,4 @@
import { and, asc, eq, max, sql } from "drizzle-orm";
import { and, asc, eq, max, ne, sql } from "drizzle-orm";
import type { Db } from "@paperclipai/db";
import { companySkills, folders, routines } from "@paperclipai/db";
import type {
@@ -67,7 +67,7 @@ export function folderService(db: Db) {
count: sql<number>`count(*)::int`,
})
.from(routines)
.where(eq(routines.companyId, companyId))
.where(and(eq(routines.companyId, companyId), ne(routines.status, "archived")))
.groupBy(routines.folderId);
}