refactor(base): rename baseId to pageId in DTOs, schemas, and services

This commit is contained in:
Philipinho
2026-04-27 01:27:10 +01:00
parent 54de3a7791
commit a53dabae70
13 changed files with 77 additions and 77 deletions
+1 -1
View File
@@ -2,5 +2,5 @@ import { IsUUID } from 'class-validator';
export class BaseIdDto { export class BaseIdDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
} }
@@ -10,7 +10,7 @@ import { BASE_PROPERTY_TYPES } from '../base.schemas';
export class CreatePropertyDto { export class CreatePropertyDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@@ -2,7 +2,7 @@ import { IsObject, IsOptional, IsString, IsUUID } from 'class-validator';
export class CreateRowDto { export class CreateRowDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsObject() @IsObject()
@@ -9,7 +9,7 @@ import {
export class CreateViewDto { export class CreateViewDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@@ -2,5 +2,5 @@ import { IsUUID } from 'class-validator';
export class ExportBaseCsvDto { export class ExportBaseCsvDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
} }
@@ -2,7 +2,7 @@ import { IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
export class UpdateBaseDto { export class UpdateBaseDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsString() @IsString()
@@ -12,7 +12,7 @@ export class UpdatePropertyDto {
propertyId: string; propertyId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsString() @IsString()
@@ -43,7 +43,7 @@ export class DeletePropertyDto {
propertyId: string; propertyId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsString() @IsString()
@@ -55,7 +55,7 @@ export class ReorderPropertyDto {
propertyId: string; propertyId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@@ -20,7 +20,7 @@ export class UpdateRowDto {
rowId: string; rowId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsObject() @IsObject()
cells: Record<string, unknown>; cells: Record<string, unknown>;
@@ -35,7 +35,7 @@ export class DeleteRowDto {
rowId: string; rowId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsString() @IsString()
@@ -47,7 +47,7 @@ export class RowIdDto {
rowId: string; rowId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
} }
class SortDto { class SortDto {
@@ -60,7 +60,7 @@ class SortDto {
export class ListRowsDto { export class ListRowsDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsUUID() @IsUUID()
@@ -86,7 +86,7 @@ export class ListRowsDto {
export class CountRowsDto { export class CountRowsDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsObject() @IsObject()
@@ -108,7 +108,7 @@ export class ReorderRowDto {
rowId: string; rowId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@@ -121,7 +121,7 @@ export class ReorderRowDto {
export class DeleteRowsDto { export class DeleteRowsDto {
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsArray() @IsArray()
@ArrayMinSize(1) @ArrayMinSize(1)
@@ -12,7 +12,7 @@ export class UpdateViewDto {
viewId: string; viewId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
@IsOptional() @IsOptional()
@IsString() @IsString()
@@ -33,5 +33,5 @@ export class DeleteViewDto {
viewId: string; viewId: string;
@IsUUID() @IsUUID()
baseId: string; pageId: string;
} }
@@ -88,7 +88,7 @@ export class BasePropertyService {
async create(workspaceId: string, dto: CreatePropertyDto, actorId?: string) { async create(workspaceId: string, dto: CreatePropertyDto, actorId?: string) {
const type = dto.type as BasePropertyTypeValue; const type = dto.type as BasePropertyTypeValue;
await this.ensureNameUnique(dto.baseId, dto.name); await this.ensureNameUnique(dto.pageId, dto.name);
let validatedTypeOptions: unknown; let validatedTypeOptions: unknown;
if (type === 'formula') { if (type === 'formula') {
@@ -96,7 +96,7 @@ export class BasePropertyService {
if (typeof sourceCandidate !== 'string') { if (typeof sourceCandidate !== 'string') {
throw new BadRequestException('formula.source is required'); throw new BadRequestException('formula.source is required');
} }
const existing = await this.basePropertyRepo.findByPageId(dto.baseId); const existing = await this.basePropertyRepo.findByPageId(dto.pageId);
const compiled = this.formulaService.compile(sourceCandidate, existing); const compiled = this.formulaService.compile(sourceCandidate, existing);
const candidate = { const candidate = {
id: 'pending', id: 'pending',
@@ -113,14 +113,14 @@ export class BasePropertyService {
} }
const lastPosition = await this.basePropertyRepo.getLastPosition( const lastPosition = await this.basePropertyRepo.getLastPosition(
dto.baseId, dto.pageId,
); );
const position = generateJitteredKeyBetween(lastPosition, null); const position = generateJitteredKeyBetween(lastPosition, null);
const created = await executeTx(this.db, async (trx) => { const created = await executeTx(this.db, async (trx) => {
const row = await this.basePropertyRepo.insertProperty( const row = await this.basePropertyRepo.insertProperty(
{ {
pageId: dto.baseId, pageId: dto.pageId,
name: dto.name, name: dto.name,
type: dto.type, type: dto.type,
position, position,
@@ -129,12 +129,12 @@ export class BasePropertyService {
}, },
trx, trx,
); );
await this.baseRepo.bumpSchemaVersion(dto.baseId, trx); await this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
return row; return row;
}); });
const event: BasePropertyCreatedEvent = { const event: BasePropertyCreatedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: actorId ?? null, actorId: actorId ?? null,
requestId: null, requestId: null,
@@ -190,12 +190,12 @@ export class BasePropertyService {
throw new NotFoundException('Property not found'); throw new NotFoundException('Property not found');
} }
if (property.pageId !== dto.baseId) { if (property.pageId !== dto.pageId) {
throw new BadRequestException('Property does not belong to this base'); throw new BadRequestException('Property does not belong to this base');
} }
if (dto.name !== undefined) { if (dto.name !== undefined) {
await this.ensureNameUnique(dto.baseId, dto.name, dto.propertyId); await this.ensureNameUnique(dto.pageId, dto.name, dto.propertyId);
} }
// Block concurrent type changes — the worker still owns the previous // Block concurrent type changes — the worker still owns the previous
@@ -227,7 +227,7 @@ export class BasePropertyService {
if (typeof sourceCandidate !== 'string') { if (typeof sourceCandidate !== 'string') {
throw new BadRequestException('formula.source is required'); throw new BadRequestException('formula.source is required');
} }
const allProps = await this.basePropertyRepo.findByPageId(dto.baseId); const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
const compiled = this.formulaService.compile(sourceCandidate, allProps); const compiled = this.formulaService.compile(sourceCandidate, allProps);
const candidate = { const candidate = {
id: property.id, id: property.id,
@@ -272,13 +272,13 @@ export class BasePropertyService {
); );
if (isTypeChange) { if (isTypeChange) {
await this.basePropertyRepo.bumpSchemaVersion(dto.propertyId, trx); await this.basePropertyRepo.bumpSchemaVersion(dto.propertyId, trx);
await this.baseRepo.bumpSchemaVersion(dto.baseId, trx); await this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
} }
}); });
if (newType === 'formula' && (isTypeChange || sourceChanged)) { if (newType === 'formula' && (isTypeChange || sourceChanged)) {
await this.formulaService.enqueueRecompute({ await this.formulaService.enqueueRecompute({
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
propertyIds: [dto.propertyId], propertyIds: [dto.propertyId],
reason: isTypeChange ? 'formula_created' : 'formula_edited', reason: isTypeChange ? 'formula_created' : 'formula_edited',
@@ -287,12 +287,12 @@ export class BasePropertyService {
} }
if (isTypeChange && newType !== 'formula') { if (isTypeChange && newType !== 'formula') {
const allProps = await this.basePropertyRepo.findByPageId(dto.baseId); const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
const graph = new BaseFormulaGraph(allProps); const graph = new BaseFormulaGraph(allProps);
const affected = graph.affectedFormulas([dto.propertyId]); const affected = graph.affectedFormulas([dto.propertyId]);
if (affected.length > 0) { if (affected.length > 0) {
await this.formulaService.enqueueRecompute({ await this.formulaService.enqueueRecompute({
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
propertyIds: affected, propertyIds: affected,
reason: 'dep_type_changed', reason: 'dep_type_changed',
@@ -306,7 +306,7 @@ export class BasePropertyService {
// --- Path 2 or 3: cell rewrite needed ------------------------------- // --- Path 2 or 3: cell rewrite needed -------------------------------
const conversionPayload: IBaseTypeConversionJob = { const conversionPayload: IBaseTypeConversionJob = {
baseId: dto.baseId, baseId: dto.pageId,
propertyId: dto.propertyId, propertyId: dto.propertyId,
workspaceId, workspaceId,
fromType: oldType, fromType: oldType,
@@ -322,7 +322,7 @@ export class BasePropertyService {
// property set on 12 rows is trivial to convert inline; the previous // property set on 12 rows is trivial to convert inline; the previous
// count-all-live-rows check was routing those to the worker. // count-all-live-rows check was routing those to the worker.
const rowsToConvert = await this.countRowsToConvert( const rowsToConvert = await this.countRowsToConvert(
dto.baseId, dto.pageId,
workspaceId, workspaceId,
dto.propertyId, dto.propertyId,
); );
@@ -356,11 +356,11 @@ export class BasePropertyService {
trx, trx,
); );
await this.basePropertyRepo.bumpSchemaVersion(dto.propertyId, trx); await this.basePropertyRepo.bumpSchemaVersion(dto.propertyId, trx);
return this.baseRepo.bumpSchemaVersion(dto.baseId, trx); return this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
}); });
tick('inline-tx-done'); tick('inline-tx-done');
const bumpEvent: BaseSchemaBumpedEvent = { const bumpEvent: BaseSchemaBumpedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: actorId ?? null, actorId: actorId ?? null,
requestId: null, requestId: null,
@@ -454,7 +454,7 @@ export class BasePropertyService {
const updated = await this.basePropertyRepo.findById(dto.propertyId); const updated = await this.basePropertyRepo.findById(dto.propertyId);
if (updated) { if (updated) {
const event: BasePropertyUpdatedEvent = { const event: BasePropertyUpdatedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: actorId ?? null, actorId: actorId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -492,7 +492,7 @@ export class BasePropertyService {
throw new NotFoundException('Property not found'); throw new NotFoundException('Property not found');
} }
if (property.pageId !== dto.baseId) { if (property.pageId !== dto.pageId) {
throw new BadRequestException('Property does not belong to this base'); throw new BadRequestException('Property does not belong to this base');
} }
@@ -502,7 +502,7 @@ export class BasePropertyService {
// Compute dependents BEFORE the delete — once soft-deleted the graph // Compute dependents BEFORE the delete — once soft-deleted the graph
// wouldn't include them. // wouldn't include them.
const allProps = await this.basePropertyRepo.findByPageId(dto.baseId); const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
const graph = new BaseFormulaGraph(allProps); const graph = new BaseFormulaGraph(allProps);
const affected = graph.affectedFormulas([dto.propertyId]); const affected = graph.affectedFormulas([dto.propertyId]);
@@ -511,11 +511,11 @@ export class BasePropertyService {
// fails, revert the soft-delete so the property isn't orphaned. // fails, revert the soft-delete so the property isn't orphaned.
await executeTx(this.db, async (trx) => { await executeTx(this.db, async (trx) => {
await this.basePropertyRepo.softDelete(dto.propertyId, trx); await this.basePropertyRepo.softDelete(dto.propertyId, trx);
await this.baseRepo.bumpSchemaVersion(dto.baseId, trx); await this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
}); });
const payload: IBaseCellGcJob = { const payload: IBaseCellGcJob = {
baseId: dto.baseId, baseId: dto.pageId,
propertyId: dto.propertyId, propertyId: dto.propertyId,
workspaceId, workspaceId,
}; };
@@ -542,7 +542,7 @@ export class BasePropertyService {
} }
const event: BasePropertyDeletedEvent = { const event: BasePropertyDeletedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: actorId ?? null, actorId: actorId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -552,7 +552,7 @@ export class BasePropertyService {
if (affected.length > 0) { if (affected.length > 0) {
await this.formulaService.enqueueRecompute({ await this.formulaService.enqueueRecompute({
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
propertyIds: affected, propertyIds: affected,
reason: 'dep_deleted', reason: 'dep_deleted',
@@ -571,7 +571,7 @@ export class BasePropertyService {
throw new NotFoundException('Property not found'); throw new NotFoundException('Property not found');
} }
if (property.pageId !== dto.baseId) { if (property.pageId !== dto.pageId) {
throw new BadRequestException('Property does not belong to this base'); throw new BadRequestException('Property does not belong to this base');
} }
@@ -580,7 +580,7 @@ export class BasePropertyService {
}); });
const event: BasePropertyReorderedEvent = { const event: BasePropertyReorderedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: actorId ?? null, actorId: actorId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -72,18 +72,18 @@ export class BaseRowService {
const afterRow = await this.baseRowRepo.findById(dto.afterRowId, { const afterRow = await this.baseRowRepo.findById(dto.afterRowId, {
workspaceId, workspaceId,
}); });
if (!afterRow || afterRow.pageId !== dto.baseId) { if (!afterRow || afterRow.pageId !== dto.pageId) {
throw new BadRequestException('Invalid afterRowId'); throw new BadRequestException('Invalid afterRowId');
} }
position = generateJitteredKeyBetween(afterRow.position, null); position = generateJitteredKeyBetween(afterRow.position, null);
} else { } else {
const lastPosition = await this.baseRowRepo.getLastPosition(dto.baseId, { const lastPosition = await this.baseRowRepo.getLastPosition(dto.pageId, {
workspaceId, workspaceId,
}); });
position = generateJitteredKeyBetween(lastPosition, null); position = generateJitteredKeyBetween(lastPosition, null);
} }
const properties = await this.basePropertyRepo.findByPageId(dto.baseId); const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
let validatedCells: Record<string, unknown> = {}; let validatedCells: Record<string, unknown> = {};
if (dto.cells && Object.keys(dto.cells).length > 0) { if (dto.cells && Object.keys(dto.cells).length > 0) {
@@ -104,7 +104,7 @@ export class BaseRowService {
const finalCells = { ...validatedCells, ...formulaPatch }; const finalCells = { ...validatedCells, ...formulaPatch };
const created = await this.baseRowRepo.insertRow({ const created = await this.baseRowRepo.insertRow({
pageId: dto.baseId, pageId: dto.pageId,
cells: finalCells as any, cells: finalCells as any,
position, position,
creatorId: userId, creatorId: userId,
@@ -112,7 +112,7 @@ export class BaseRowService {
}); });
const event: BaseRowCreatedEvent = { const event: BaseRowCreatedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId, actorId: userId,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -132,7 +132,7 @@ export class BaseRowService {
} }
async update(dto: UpdateRowDto, workspaceId: string, userId?: string) { async update(dto: UpdateRowDto, workspaceId: string, userId?: string) {
const properties = await this.basePropertyRepo.findByPageId(dto.baseId); const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const validatedCells = this.validateCells(dto.cells, properties); const validatedCells = this.validateCells(dto.cells, properties);
const existing = await this.baseRowRepo.findById(dto.rowId, { workspaceId }); const existing = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
@@ -151,7 +151,7 @@ export class BaseRowService {
dto.rowId, dto.rowId,
finalCells, finalCells,
{ {
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
actorId: userId, actorId: userId,
}, },
@@ -162,7 +162,7 @@ export class BaseRowService {
} }
const event: BaseRowUpdatedEvent = { const event: BaseRowUpdatedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId ?? null, actorId: userId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -177,17 +177,17 @@ export class BaseRowService {
async delete(dto: DeleteRowDto, workspaceId: string, userId?: string) { async delete(dto: DeleteRowDto, workspaceId: string, userId?: string) {
const row = await this.baseRowRepo.findById(dto.rowId, { workspaceId }); const row = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
if (!row || row.pageId !== dto.baseId) { if (!row || row.pageId !== dto.pageId) {
throw new NotFoundException('Row not found'); throw new NotFoundException('Row not found');
} }
await this.baseRowRepo.softDelete(dto.rowId, { await this.baseRowRepo.softDelete(dto.rowId, {
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
}); });
const event: BaseRowDeletedEvent = { const event: BaseRowDeletedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId ?? null, actorId: userId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -205,17 +205,17 @@ export class BaseRowService {
if (rows.length !== dto.rowIds.length) { if (rows.length !== dto.rowIds.length) {
throw new NotFoundException('One or more rows not found'); throw new NotFoundException('One or more rows not found');
} }
if (rows.some((r) => r.pageId !== dto.baseId)) { if (rows.some((r) => r.pageId !== dto.pageId)) {
throw new NotFoundException('Row does not belong to base'); throw new NotFoundException('Row does not belong to base');
} }
await this.baseRowRepo.softDeleteMany(dto.rowIds, { await this.baseRowRepo.softDeleteMany(dto.rowIds, {
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
}); });
const event: BaseRowsDeletedEvent = { const event: BaseRowsDeletedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId ?? null, actorId: userId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -229,7 +229,7 @@ export class BaseRowService {
pagination: PaginationOptions, pagination: PaginationOptions,
workspaceId: string, workspaceId: string,
) { ) {
const properties = await this.basePropertyRepo.findByPageId(dto.baseId); const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const schema: PropertySchema = new Map( const schema: PropertySchema = new Map(
properties.map((p) => [p.id, p]), properties.map((p) => [p.id, p]),
); );
@@ -242,7 +242,7 @@ export class BaseRowService {
})); }));
return this.baseRowRepo.list({ return this.baseRowRepo.list({
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
filter, filter,
sorts, sorts,
@@ -253,7 +253,7 @@ export class BaseRowService {
} }
async count(dto: CountRowsDto, workspaceId: string) { async count(dto: CountRowsDto, workspaceId: string) {
const properties = await this.basePropertyRepo.findByPageId(dto.baseId); const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const schema: PropertySchema = new Map(properties.map((p) => [p.id, p])); const schema: PropertySchema = new Map(properties.map((p) => [p.id, p]));
const filter = this.normaliseFilter({ filter: dto.filter }); const filter = this.normaliseFilter({ filter: dto.filter });
@@ -268,7 +268,7 @@ export class BaseRowService {
if (useExact) { if (useExact) {
const { value, capped } = await this.baseRowRepo.countExact({ const { value, capped } = await this.baseRowRepo.countExact({
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
filter, filter,
search, search,
@@ -279,7 +279,7 @@ export class BaseRowService {
} }
const estimate = await this.baseRowRepo.countEstimate({ const estimate = await this.baseRowRepo.countEstimate({
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
filter, filter,
search, search,
@@ -294,7 +294,7 @@ export class BaseRowService {
async reorder(dto: ReorderRowDto, workspaceId: string, userId?: string) { async reorder(dto: ReorderRowDto, workspaceId: string, userId?: string) {
const row = await this.baseRowRepo.findById(dto.rowId, { workspaceId }); const row = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
if (!row || row.pageId !== dto.baseId) { if (!row || row.pageId !== dto.pageId) {
throw new NotFoundException('Row not found'); throw new NotFoundException('Row not found');
} }
@@ -305,12 +305,12 @@ export class BaseRowService {
} }
await this.baseRowRepo.updatePosition(dto.rowId, dto.position, { await this.baseRowRepo.updatePosition(dto.rowId, dto.position, {
pageId: dto.baseId, pageId: dto.pageId,
workspaceId, workspaceId,
}); });
const event: BaseRowReorderedEvent = { const event: BaseRowReorderedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId ?? null, actorId: userId ?? null,
requestId: dto.requestId ?? null, requestId: dto.requestId ?? null,
@@ -36,13 +36,13 @@ export class BaseViewService {
validatedConfig = result.data; validatedConfig = result.data;
} }
const lastPosition = await this.baseViewRepo.getLastPosition(dto.baseId, { const lastPosition = await this.baseViewRepo.getLastPosition(dto.pageId, {
workspaceId, workspaceId,
}); });
const position = generateJitteredKeyBetween(lastPosition, null); const position = generateJitteredKeyBetween(lastPosition, null);
const created = await this.baseViewRepo.insertView({ const created = await this.baseViewRepo.insertView({
pageId: dto.baseId, pageId: dto.pageId,
name: dto.name, name: dto.name,
type: dto.type ?? 'table', type: dto.type ?? 'table',
position, position,
@@ -52,7 +52,7 @@ export class BaseViewService {
}); });
const event: BaseViewCreatedEvent = { const event: BaseViewCreatedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId, actorId: userId,
requestId: null, requestId: null,
@@ -69,7 +69,7 @@ export class BaseViewService {
throw new NotFoundException('View not found'); throw new NotFoundException('View not found');
} }
if (view.pageId !== dto.baseId) { if (view.pageId !== dto.pageId) {
throw new BadRequestException('View does not belong to this base'); throw new BadRequestException('View does not belong to this base');
} }
@@ -101,7 +101,7 @@ export class BaseViewService {
if (updated) { if (updated) {
const event: BaseViewUpdatedEvent = { const event: BaseViewUpdatedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId ?? null, actorId: userId ?? null,
requestId: null, requestId: null,
@@ -119,11 +119,11 @@ export class BaseViewService {
throw new NotFoundException('View not found'); throw new NotFoundException('View not found');
} }
if (view.pageId !== dto.baseId) { if (view.pageId !== dto.pageId) {
throw new BadRequestException('View does not belong to this base'); throw new BadRequestException('View does not belong to this base');
} }
const viewCount = await this.baseViewRepo.countByPageId(dto.baseId, { const viewCount = await this.baseViewRepo.countByPageId(dto.pageId, {
workspaceId, workspaceId,
}); });
if (viewCount <= 1) { if (viewCount <= 1) {
@@ -133,7 +133,7 @@ export class BaseViewService {
await this.baseViewRepo.deleteView(dto.viewId, { workspaceId }); await this.baseViewRepo.deleteView(dto.viewId, { workspaceId });
const event: BaseViewDeletedEvent = { const event: BaseViewDeletedEvent = {
baseId: dto.baseId, baseId: dto.pageId,
workspaceId, workspaceId,
actorId: userId ?? null, actorId: userId ?? null,
requestId: null, requestId: null,
@@ -91,7 +91,7 @@ export class BaseService {
} }
async update(dto: UpdateBaseDto) { async update(dto: UpdateBaseDto) {
const base = await this.baseRepo.findById(dto.baseId); const base = await this.baseRepo.findById(dto.pageId);
if (!base) { if (!base) {
throw new NotFoundException('Base not found'); throw new NotFoundException('Base not found');
} }
@@ -101,10 +101,10 @@ export class BaseService {
...(dto.name !== undefined && { title: dto.name }), ...(dto.name !== undefined && { title: dto.name }),
...(dto.icon !== undefined && { icon: dto.icon }), ...(dto.icon !== undefined && { icon: dto.icon }),
}, },
dto.baseId, dto.pageId,
); );
return this.baseRepo.findById(dto.baseId); return this.baseRepo.findById(dto.pageId);
} }
async delete(baseId: string) { async delete(baseId: string) {