Fix support custom object renaming (#8089)
In this PR 1) (FE) fixing update of name not taken into account if toggle value is changed in the same transaction 2) (BE) moving same nameSingular and namePlural validation before effective update
This commit is contained in:
@ -447,6 +447,15 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
isDefined(input.update.nameSingular) ||
|
||||
isDefined(input.update.namePlural)
|
||||
) {
|
||||
this.validateNameSingularAndNamePluralAreDifferentOrThrow(
|
||||
fullObjectMetadataAfterUpdate,
|
||||
);
|
||||
}
|
||||
|
||||
const updatedObject = await super.updateOne(input.id, input.update);
|
||||
|
||||
await this.handleObjectNameAndLabelUpdates(
|
||||
@ -1416,21 +1425,6 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
objectMetadataForUpdate: ObjectMetadataEntity,
|
||||
input: UpdateOneObjectInput,
|
||||
) {
|
||||
if (
|
||||
isDefined(input.update.nameSingular) ||
|
||||
isDefined(input.update.namePlural)
|
||||
) {
|
||||
if (
|
||||
objectMetadataForUpdate.nameSingular ===
|
||||
objectMetadataForUpdate.namePlural
|
||||
) {
|
||||
throw new ObjectMetadataException(
|
||||
'The singular and plural name cannot be the same for an object',
|
||||
ObjectMetadataExceptionCode.INVALID_OBJECT_INPUT,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const newTargetTableName = computeObjectTargetTable(
|
||||
objectMetadataForUpdate,
|
||||
);
|
||||
@ -1641,4 +1635,18 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private validateNameSingularAndNamePluralAreDifferentOrThrow = (
|
||||
fullObjectMetadataAfterUpdate: ObjectMetadataEntity,
|
||||
) => {
|
||||
if (
|
||||
fullObjectMetadataAfterUpdate.nameSingular ===
|
||||
fullObjectMetadataAfterUpdate.namePlural
|
||||
) {
|
||||
throw new ObjectMetadataException(
|
||||
'The singular and plural name cannot be the same for an object',
|
||||
ObjectMetadataExceptionCode.INVALID_OBJECT_INPUT,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user