mirror of
https://github.com/docmost/docmost.git
synced 2026-08-29 10:05:03 +08:00
index label ids on typesense
This commit is contained in:
@@ -7,12 +7,15 @@ import { executeTx } from '@docmost/db/utils';
|
|||||||
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
||||||
import { PagePermissionRepo } from '@docmost/db/repos/page/page-permission.repo';
|
import { PagePermissionRepo } from '@docmost/db/repos/page/page-permission.repo';
|
||||||
import { normalizeLabelName } from './utils';
|
import { normalizeLabelName } from './utils';
|
||||||
|
import { EventEmitter2 } from "@nestjs/event-emitter";
|
||||||
|
import { EventName } from "src/common/events/event.contants";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LabelService {
|
export class LabelService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly labelRepo: LabelRepo,
|
private readonly labelRepo: LabelRepo,
|
||||||
private readonly pagePermissionRepo: PagePermissionRepo,
|
private readonly pagePermissionRepo: PagePermissionRepo,
|
||||||
|
private readonly eventEmitter: EventEmitter2,
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -30,10 +33,16 @@ export class LabelService {
|
|||||||
LabelType.PAGE,
|
LabelType.PAGE,
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
await this.labelRepo.addLabelToPage(pageId, label.id, workspaceId, trx);
|
await this.labelRepo.addLabelToPage(pageId, label.id, trx);
|
||||||
attached.push(label);
|
attached.push(label);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
||||||
|
pageIds: [pageId],
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
});
|
||||||
|
|
||||||
return attached;
|
return attached;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +73,11 @@ export class LabelService {
|
|||||||
await this.labelRepo.deleteLabel(labelId, workspaceId, trx);
|
await this.labelRepo.deleteLabel(labelId, workspaceId, trx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
||||||
|
pageIds: [pageId],
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageLabels(pageId: string, pagination: PaginationOptions) {
|
async getPageLabels(pageId: string, pagination: PaginationOptions) {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
|||||||
import { executeWithCursorPagination } from '@docmost/db/pagination/cursor-pagination';
|
import { executeWithCursorPagination } from '@docmost/db/pagination/cursor-pagination';
|
||||||
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
||||||
import { normalizeLabelName } from '../../../core/label/utils';
|
import { normalizeLabelName } from '../../../core/label/utils';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
||||||
import { EventName } from 'src/common/events/event.contants';
|
|
||||||
|
|
||||||
export const LabelType = {
|
export const LabelType = {
|
||||||
PAGE: 'page',
|
PAGE: 'page',
|
||||||
@@ -23,7 +21,6 @@ export class LabelRepo {
|
|||||||
constructor(
|
constructor(
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
private readonly spaceMemberRepo: SpaceMemberRepo,
|
private readonly spaceMemberRepo: SpaceMemberRepo,
|
||||||
private readonly eventEmitter: EventEmitter2,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findById(
|
async findById(
|
||||||
@@ -169,7 +166,6 @@ export class LabelRepo {
|
|||||||
async addLabelToPage(
|
async addLabelToPage(
|
||||||
pageId: string,
|
pageId: string,
|
||||||
labelId: string,
|
labelId: string,
|
||||||
workspaceId: string,
|
|
||||||
trx?: KyselyTransaction,
|
trx?: KyselyTransaction,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const db = dbOrTx(this.db, trx);
|
const db = dbOrTx(this.db, trx);
|
||||||
@@ -178,11 +174,6 @@ export class LabelRepo {
|
|||||||
.values({ pageId, labelId })
|
.values({ pageId, labelId })
|
||||||
.onConflict((oc) => oc.doNothing())
|
.onConflict((oc) => oc.doNothing())
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
|
||||||
pageIds: [pageId],
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeLabelFromPage(
|
async removeLabelFromPage(
|
||||||
@@ -206,11 +197,6 @@ export class LabelRepo {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
|
||||||
pageIds: [pageId],
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageLabelCount(
|
async getPageLabelCount(
|
||||||
|
|||||||
Reference in New Issue
Block a user