The minimalistic document archiving platform.
feat(tags): order organization tags by creation date (#784)
Corentin Thomasset2c078e20f534
diff --git a/.changeset/big-corners-rest.md b/.changeset/big-corners-rest.mdnew file mode 100644index 00000000..7b33652a--- /dev/null+++ b/.changeset/big-corners-rest.md@@ -0,0 +1,5 @@+---+"@papra/docker": patch+---++Tag list: order tags by creation date descending (newest on top)diff --git a/apps/papra-server/src/modules/tags/tags.repository.test.ts b/apps/papra-server/src/modules/tags/tags.repository.test.tsindex 7ebe425b..b1f345be 100644--- a/apps/papra-server/src/modules/tags/tags.repository.test.ts+++ b/apps/papra-server/src/modules/tags/tags.repository.test.ts@@ -98,7 +98,7 @@ describe('tags repository', () => {});describe('getOrganizationTags', () => {- test('retrieves all tags for an organization along with the number of non-deleted documents associated with each tag', async () => {+ test('retrieves all tags for an organization along with the number of non-deleted documents associated with each tag ordered by creation date descending', async () => {const { db } = await createInMemoryDatabase({users: [{ id: 'user-1', email: '[email protected]' }],organizations: [{ id: 'organization-1', name: 'Organization 1' }],@@ -124,15 +124,16 @@ describe('tags repository', () => {const { tags } = await tagsRepository.getOrganizationTags({ organizationId: 'organization-1' });expect(tags).to.eql([+{- id: 'tag-1',+ id: 'tag-3',organizationId: 'organization-1',- name: 'Tag 1',+ name: 'Tag 3',description: null,- color: '#aa0000',- documentsCount: 1,- createdAt: new Date('2021-01-01'),- updatedAt: new Date('2021-01-01'),+ color: '#0000aa',+ documentsCount: 0,+ createdAt: new Date('2021-01-03'),+ updatedAt: new Date('2021-01-03'),},{id: 'tag-2',@@ -145,14 +146,14 @@ describe('tags repository', () => {updatedAt: new Date('2021-01-02'),},{- id: 'tag-3',+ id: 'tag-1',organizationId: 'organization-1',- name: 'Tag 3',+ name: 'Tag 1',description: null,- color: '#0000aa',- documentsCount: 0,- createdAt: new Date('2021-01-03'),- updatedAt: new Date('2021-01-03'),+ color: '#aa0000',+ documentsCount: 1,+ createdAt: new Date('2021-01-01'),+ updatedAt: new Date('2021-01-01'),},]);});diff --git a/apps/papra-server/src/modules/tags/tags.repository.ts b/apps/papra-server/src/modules/tags/tags.repository.tsindex c58ed7be..ed38b466 100644--- a/apps/papra-server/src/modules/tags/tags.repository.ts+++ b/apps/papra-server/src/modules/tags/tags.repository.ts@@ -1,7 +1,7 @@import type { Database } from '../app/database/database.types';import type { DbInsertableTag } from './tags.types';import { injectArguments, safely } from '@corentinth/chisels';-import { and, eq, getTableColumns, sql } from 'drizzle-orm';+import { and, desc, eq, getTableColumns, sql } from 'drizzle-orm';import { get } from 'lodash-es';import { documentsTable } from '../documents/documents.table';import { isUniqueConstraintError } from '../shared/db/constraints.models';@@ -38,7 +38,8 @@ async function getOrganizationTags({ organizationId, db }: { organizationId: str.leftJoin(documentsTagsTable, eq(tagsTable.id, documentsTagsTable.tagId)).leftJoin(documentsTable, eq(documentsTagsTable.documentId, documentsTable.id)).where(eq(tagsTable.organizationId, organizationId))- .groupBy(tagsTable.id);+ .groupBy(tagsTable.id)+ .orderBy(desc(tagsTable.createdAt));return { tags };}