diff --git a/apps/api/src/app/column/usecases/add-column/add-column.usecase.ts b/apps/api/src/app/column/usecases/add-column/add-column.usecase.ts index fa3c99a77..e88248e6d 100644 --- a/apps/api/src/app/column/usecases/add-column/add-column.usecase.ts +++ b/apps/api/src/app/column/usecases/add-column/add-column.usecase.ts @@ -15,8 +15,8 @@ export class AddColumn { async execute(command: AddColumnCommand, _templateId: string) { const columns = await this.columnRepository.find({ _templateId }); - const isKeyUnique = columns.some((column) => column.key === command.key); - if (isKeyUnique) { + const sameKeyColumns = columns.filter((columnItem) => columnItem.key === command.key); + if (sameKeyColumns.length > 0) { throw new UniqueColumnException(); } const column = await this.columnRepository.create({ diff --git a/apps/api/src/app/column/usecases/update-column/update-column.usecase.ts b/apps/api/src/app/column/usecases/update-column/update-column.usecase.ts index 26257f541..51f6f4ab4 100644 --- a/apps/api/src/app/column/usecases/update-column/update-column.usecase.ts +++ b/apps/api/src/app/column/usecases/update-column/update-column.usecase.ts @@ -21,8 +21,10 @@ export class UpdateColumn { } const columns = await this.columnRepository.find({ _templateId: column._templateId }); - const isKeyUnique = columns.some((columnItem) => columnItem.key === command.key); - if (isKeyUnique) { + const sameKeyColumns = columns + .map((columnItem) => (columnItem._id === _id ? { ...command, ...columnItem } : columnItem)) + .filter((columnItem) => columnItem.key === command.key); + if (sameKeyColumns.length > 1) { throw new UniqueColumnException(); }