feat(bases): allow updateRow to set position atomically

This commit is contained in:
Philipinho
2026-05-24 12:31:36 +01:00
parent a793e65560
commit 9cec9b64c6
5 changed files with 21 additions and 0 deletions
@@ -150,6 +150,9 @@ export function useUpdateRowMutation() {
? {
...row,
cells: { ...row.cells, ...variables.cells },
...(variables.position !== undefined && {
position: variables.position,
}),
}
: row,
),
@@ -272,6 +272,7 @@ export type UpdateRowInput = {
rowId: string;
pageId: string;
cells: Record<string, unknown>;
position?: string;
requestId?: string;
};
@@ -25,6 +25,11 @@ export class UpdateRowDto {
@IsObject()
cells: Record<string, unknown>;
@IsOptional()
@IsString()
@IsNotEmpty()
position?: string;
@IsOptional()
@IsString()
requestId?: string;
@@ -135,6 +135,15 @@ export class BaseRowService {
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const validatedCells = this.validateCells(dto.cells, properties);
// Smoke-check the position (same guard as `reorder`).
if (dto.position !== undefined) {
try {
generateJitteredKeyBetween(dto.position, null);
} catch {
throw new BadRequestException('Invalid position value');
}
}
const existing = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
const mergedRow = {
...((existing?.cells as Record<string, unknown>) ?? {}),
@@ -154,6 +163,7 @@ export class BaseRowService {
pageId: dto.pageId,
workspaceId,
actorId: userId,
position: dto.position,
},
);
@@ -275,6 +275,7 @@ export class BaseRowRepo {
pageId: string;
workspaceId: string;
actorId?: string;
position?: string;
trx?: KyselyTransaction;
},
): Promise<BaseRow | undefined> {
@@ -287,6 +288,7 @@ export class BaseRowRepo {
.updateTable('baseRows')
.set({
cells: sql`jsonb_set_many(cells, ${patchJson}::text::jsonb)`,
...(opts.position !== undefined && { position: opts.position }),
updatedAt: new Date(),
lastUpdatedById: opts.actorId ?? null,
})