mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
feat(base): add deleteMany service method for batch row delete
This commit is contained in:
@@ -13,6 +13,7 @@ import { CreateRowDto } from '../dto/create-row.dto';
|
|||||||
import {
|
import {
|
||||||
UpdateRowDto,
|
UpdateRowDto,
|
||||||
DeleteRowDto,
|
DeleteRowDto,
|
||||||
|
DeleteRowsDto,
|
||||||
ListRowsDto,
|
ListRowsDto,
|
||||||
ReorderRowDto,
|
ReorderRowDto,
|
||||||
} from '../dto/update-row.dto';
|
} from '../dto/update-row.dto';
|
||||||
@@ -38,6 +39,7 @@ import {
|
|||||||
BaseRowDeletedEvent,
|
BaseRowDeletedEvent,
|
||||||
BaseRowReorderedEvent,
|
BaseRowReorderedEvent,
|
||||||
BaseRowUpdatedEvent,
|
BaseRowUpdatedEvent,
|
||||||
|
BaseRowsDeletedEvent,
|
||||||
} from '../events/base-events';
|
} from '../events/base-events';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -155,6 +157,34 @@ export class BaseRowService {
|
|||||||
this.eventEmitter.emit(EventName.BASE_ROW_DELETED, event);
|
this.eventEmitter.emit(EventName.BASE_ROW_DELETED, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteMany(
|
||||||
|
dto: DeleteRowsDto,
|
||||||
|
workspaceId: string,
|
||||||
|
userId?: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const rows = await this.baseRowRepo.findByIds(dto.rowIds, { workspaceId });
|
||||||
|
if (rows.length !== dto.rowIds.length) {
|
||||||
|
throw new NotFoundException('One or more rows not found');
|
||||||
|
}
|
||||||
|
if (rows.some((r) => r.baseId !== dto.baseId)) {
|
||||||
|
throw new NotFoundException('Row does not belong to base');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.baseRowRepo.softDeleteMany(dto.rowIds, {
|
||||||
|
baseId: dto.baseId,
|
||||||
|
workspaceId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const event: BaseRowsDeletedEvent = {
|
||||||
|
baseId: dto.baseId,
|
||||||
|
workspaceId,
|
||||||
|
actorId: userId ?? null,
|
||||||
|
requestId: dto.requestId ?? null,
|
||||||
|
rowIds: dto.rowIds,
|
||||||
|
};
|
||||||
|
this.eventEmitter.emit(EventName.BASE_ROWS_DELETED, event);
|
||||||
|
}
|
||||||
|
|
||||||
async list(
|
async list(
|
||||||
dto: ListRowsDto,
|
dto: ListRowsDto,
|
||||||
pagination: PaginationOptions,
|
pagination: PaginationOptions,
|
||||||
|
|||||||
Reference in New Issue
Block a user