From 2f99cd8f7d13acdc03324333a6d06ac05133aba7 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 17 Feb 2026 02:42:30 +0000 Subject: [PATCH] label type --- apps/server/src/core/label/label.service.ts | 3 ++- .../migrations/20260217T120000-labels.ts | 3 ++- .../src/database/repos/label/label.repo.ts | 19 +++++++++++++++---- apps/server/src/database/types/db.d.ts | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/server/src/core/label/label.service.ts b/apps/server/src/core/label/label.service.ts index 0d32ba56..75f6faec 100644 --- a/apps/server/src/core/label/label.service.ts +++ b/apps/server/src/core/label/label.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { LabelRepo } from '@docmost/db/repos/label/label.repo'; +import { LabelRepo, LabelType } from '@docmost/db/repos/label/label.repo'; import { InjectKysely } from 'nestjs-kysely'; import { KyselyDB } from '@docmost/db/types/kysely.types'; import { Label } from '@docmost/db/types/entity.types'; @@ -22,6 +22,7 @@ export class LabelService { const label = await this.labelRepo.findOrCreate( name.trim(), workspaceId, + LabelType.PAGE, trx, ); await this.labelRepo.addLabelToPage(pageId, label.id, trx); diff --git a/apps/server/src/database/migrations/20260217T120000-labels.ts b/apps/server/src/database/migrations/20260217T120000-labels.ts index c3a258b8..5d2c5812 100644 --- a/apps/server/src/database/migrations/20260217T120000-labels.ts +++ b/apps/server/src/database/migrations/20260217T120000-labels.ts @@ -7,6 +7,7 @@ export async function up(db: Kysely): Promise { col.primaryKey().defaultTo(sql`gen_uuid_v7()`), ) .addColumn('name', 'varchar', (col) => col.notNull()) + .addColumn('type', 'varchar', (col) => col.notNull().defaultTo('page')) .addColumn('workspace_id', 'uuid', (col) => col.references('workspaces.id').onDelete('cascade').notNull(), ) @@ -21,7 +22,7 @@ export async function up(db: Kysely): Promise { await db.schema .createIndex('labels_workspace_id_name_unique') .on('labels') - .columns(['workspace_id', 'name']) + .columns(['workspace_id', 'name', 'type']) .unique() .execute(); diff --git a/apps/server/src/database/repos/label/label.repo.ts b/apps/server/src/database/repos/label/label.repo.ts index 345b5bee..5f1d4953 100644 --- a/apps/server/src/database/repos/label/label.repo.ts +++ b/apps/server/src/database/repos/label/label.repo.ts @@ -5,6 +5,13 @@ import { Label } from '@docmost/db/types/entity.types'; import { dbOrTx } from '@docmost/db/utils'; import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo'; +export const LabelType = { + PAGE: 'page', + SPACE: 'space', +} as const; + +export type LabelType = (typeof LabelType)[keyof typeof LabelType]; + @Injectable() export class LabelRepo { constructor( @@ -27,6 +34,7 @@ export class LabelRepo { async findByNameAndWorkspace( name: string, workspaceId: string, + type: LabelType, trx?: KyselyTransaction, ): Promise