mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-24 06:48:42 +03:00
Allow field/object update if name/label are similar values (#2709)
This commit is contained in:
parent
e810ad7016
commit
65aa91c774
@ -10,6 +10,7 @@ import {
|
||||
} from '@ptc-org/nestjs-query-graphql';
|
||||
|
||||
import { UpdateFieldInput } from 'src/metadata/field-metadata/dtos/update-field.input';
|
||||
import { FieldMetadataEntity } from 'src/metadata/field-metadata/field-metadata.entity';
|
||||
import { FieldMetadataService } from 'src/metadata/field-metadata/field-metadata.service';
|
||||
|
||||
@Injectable()
|
||||
@ -58,15 +59,26 @@ export class BeforeUpdateOneField<T extends UpdateFieldInput>
|
||||
);
|
||||
}
|
||||
|
||||
this.checkIfFieldIsEditable(instance.update);
|
||||
this.checkIfFieldIsEditable(instance.update, fieldMetadata);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
// This is temporary until we properly use the MigrationRunner to update column names
|
||||
private checkIfFieldIsEditable(update: UpdateFieldInput) {
|
||||
if (update.name || update.label) {
|
||||
throw new BadRequestException("Field's name and label can't be updated");
|
||||
private checkIfFieldIsEditable(
|
||||
update: UpdateFieldInput,
|
||||
fieldMetadata: FieldMetadataEntity,
|
||||
) {
|
||||
if (update.name && update.name !== fieldMetadata.name) {
|
||||
throw new BadRequestException(
|
||||
"Field's name can't be updated. Please create a new field instead",
|
||||
);
|
||||
}
|
||||
|
||||
if (update.label && update.label !== fieldMetadata.label) {
|
||||
throw new BadRequestException(
|
||||
"Field's label can't be updated. Please create a new field instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import { Equal, In, Repository } from 'typeorm';
|
||||
import { FieldMetadataEntity } from 'src/metadata/field-metadata/field-metadata.entity';
|
||||
import { UpdateObjectInput } from 'src/metadata/object-metadata/dtos/update-object.input';
|
||||
import { ObjectMetadataService } from 'src/metadata/object-metadata/object-metadata.service';
|
||||
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
|
||||
|
||||
@Injectable()
|
||||
export class BeforeUpdateOneObject<T extends UpdateObjectInput>
|
||||
@ -98,20 +99,47 @@ export class BeforeUpdateOneObject<T extends UpdateObjectInput>
|
||||
}
|
||||
}
|
||||
|
||||
this.checkIfFieldIsEditable(instance.update);
|
||||
this.checkIfFieldIsEditable(instance.update, objectMetadata);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
// This is temporary until we properly use the MigrationRunner to update column names
|
||||
private checkIfFieldIsEditable(update: UpdateObjectInput) {
|
||||
private checkIfFieldIsEditable(
|
||||
update: UpdateObjectInput,
|
||||
objectMetadata: ObjectMetadataEntity,
|
||||
) {
|
||||
if (
|
||||
update.nameSingular ||
|
||||
update.namePlural ||
|
||||
update.labelSingular ||
|
||||
update.labelPlural
|
||||
update.nameSingular &&
|
||||
update.nameSingular !== objectMetadata.nameSingular
|
||||
) {
|
||||
throw new BadRequestException("Object's name and label can't be updated");
|
||||
throw new BadRequestException(
|
||||
"Object's nameSingular can't be updated. Please create a new object instead",
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
update.labelSingular &&
|
||||
update.labelSingular !== objectMetadata.labelSingular
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
"Object's labelSingular can't be updated. Please create a new object instead",
|
||||
);
|
||||
}
|
||||
|
||||
if (update.namePlural && update.namePlural !== objectMetadata.namePlural) {
|
||||
throw new BadRequestException(
|
||||
"Object's namePlural can't be updated. Please create a new object instead",
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
update.labelPlural &&
|
||||
update.labelPlural !== objectMetadata.labelPlural
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
"Object's labelPlural can't be updated. Please create a new object instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user