diff --git a/src/lib/domain/diff/area-diff.ts b/src/lib/domain/diff/area-diff.ts index b131421f..d4685de0 100644 --- a/src/lib/domain/diff/area-diff.ts +++ b/src/lib/domain/diff/area-diff.ts @@ -1,11 +1,13 @@ import { z } from 'zod'; import type { Area } from '../area'; -export type AreaDiffAttribute = keyof Pick; +export type AreaDiffAttribute = keyof Pick; const areaDiffAttributeSchema: z.ZodType = z.union([ z.literal('name'), z.literal('color'), + z.literal('x'), + z.literal('y'), ]); export interface AreaDiffChanged { @@ -13,8 +15,8 @@ export interface AreaDiffChanged { type: 'changed'; areaId: string; attribute: AreaDiffAttribute; - oldValue?: string | null; - newValue?: string | null; + oldValue?: string | number | null; + newValue?: string | number | null; } export const AreaDiffChangedSchema: z.ZodType = z.object({ @@ -22,8 +24,8 @@ export const AreaDiffChangedSchema: z.ZodType = z.object({ type: z.literal('changed'), areaId: z.string(), attribute: areaDiffAttributeSchema, - oldValue: z.string().or(z.null()).optional(), - newValue: z.string().or(z.null()).optional(), + oldValue: z.union([z.string(), z.number(), z.null()]).optional(), + newValue: z.union([z.string(), z.number(), z.null()]).optional(), }); export interface AreaDiffRemoved { diff --git a/src/lib/domain/diff/diff-check/diff-check.ts b/src/lib/domain/diff/diff-check/diff-check.ts index dadaa5cd..a9dee324 100644 --- a/src/lib/domain/diff/diff-check/diff-check.ts +++ b/src/lib/domain/diff/diff-check/diff-check.ts @@ -269,6 +269,46 @@ function compareTables({ changedTables.set(oldTable.id, true); } + + if (attributesToCheck.includes('x') && oldTable.x !== newTable.x) { + diffMap.set( + getDiffMapKey({ + diffObject: 'table', + objectId: oldTable.id, + attribute: 'x', + }), + { + object: 'table', + type: 'changed', + tableId: oldTable.id, + attribute: 'x', + newValue: newTable.x, + oldValue: oldTable.x, + } + ); + + changedTables.set(oldTable.id, true); + } + + if (attributesToCheck.includes('y') && oldTable.y !== newTable.y) { + diffMap.set( + getDiffMapKey({ + diffObject: 'table', + objectId: oldTable.id, + attribute: 'y', + }), + { + object: 'table', + type: 'changed', + tableId: oldTable.id, + attribute: 'y', + newValue: newTable.y, + oldValue: oldTable.y, + } + ); + + changedTables.set(oldTable.id, true); + } } } } @@ -788,6 +828,44 @@ function compareAreas({ ); changedAreas.set(oldArea.id, true); } + + if (attributesToCheck.includes('x') && oldArea.x !== newArea.x) { + diffMap.set( + getDiffMapKey({ + diffObject: 'area', + objectId: oldArea.id, + attribute: 'x', + }), + { + object: 'area', + type: 'changed', + areaId: oldArea.id, + attribute: 'x', + newValue: newArea.x, + oldValue: oldArea.x, + } + ); + changedAreas.set(oldArea.id, true); + } + + if (attributesToCheck.includes('y') && oldArea.y !== newArea.y) { + diffMap.set( + getDiffMapKey({ + diffObject: 'area', + objectId: oldArea.id, + attribute: 'y', + }), + { + object: 'area', + type: 'changed', + areaId: oldArea.id, + attribute: 'y', + newValue: newArea.y, + oldValue: oldArea.y, + } + ); + changedAreas.set(oldArea.id, true); + } } } } diff --git a/src/lib/domain/diff/table-diff.ts b/src/lib/domain/diff/table-diff.ts index fa492bf5..7a8f1363 100644 --- a/src/lib/domain/diff/table-diff.ts +++ b/src/lib/domain/diff/table-diff.ts @@ -3,13 +3,15 @@ import type { DBTable } from '../db-table'; export type TableDiffAttribute = keyof Pick< DBTable, - 'name' | 'comments' | 'color' + 'name' | 'comments' | 'color' | 'x' | 'y' >; const tableDiffAttributeSchema: z.ZodType = z.union([ z.literal('name'), z.literal('comments'), z.literal('color'), + z.literal('x'), + z.literal('y'), ]); export interface TableDiffChanged { @@ -17,8 +19,8 @@ export interface TableDiffChanged { type: 'changed'; tableId: string; attribute: TableDiffAttribute; - oldValue?: string | null; - newValue?: string | null; + oldValue?: string | number | null; + newValue?: string | number | null; } export const TableDiffChangedSchema: z.ZodType = z.object({ @@ -26,8 +28,8 @@ export const TableDiffChangedSchema: z.ZodType = z.object({ type: z.literal('changed'), tableId: z.string(), attribute: tableDiffAttributeSchema, - oldValue: z.string().or(z.null()).optional(), - newValue: z.string().or(z.null()).optional(), + oldValue: z.union([z.string(), z.number(), z.null()]).optional(), + newValue: z.union([z.string(), z.number(), z.null()]).optional(), }); export interface TableDiffRemoved {