Skip to content

Commit

Permalink
fix object metadata renaming (#8175)
Browse files Browse the repository at this point in the history
## Context
Latest refactoring broke the findOneWithinWorkspace method which is
called during object update, I'm simply reverting this change.
object-metadata-relation.service was naively computing a namePlural
based on the nameSingular while we already had that info in the DB...
Should fix some issues with renaming as well because the original field
was not computed with the right name.
  • Loading branch information
Weiko authored Oct 29, 2024
1 parent fe2c8bb commit 31ecaf2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,33 +320,36 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
return objectMetadata;
}

public async findMany(options?: FindManyOptions<ObjectMetadataEntity>) {
return this.objectMetadataRepository.find({
public async findOneWithinWorkspace(
workspaceId: string,
options: FindOneOptions<ObjectMetadataEntity>,
): Promise<ObjectMetadataEntity | null> {
return this.objectMetadataRepository.findOne({
relations: [
'fields',
'fields.fromRelationMetadata',
'fields.toRelationMetadata',
'fields.fromRelationMetadata.toObjectMetadata',
],
...options,
where: {
...options?.where,
...options.where,
workspaceId,
},
});
}

public async findOneWithinWorkspace(
workspaceId: string,
options: FindOneOptions<ObjectMetadataEntity>,
): Promise<ObjectMetadataEntity | null> {
return this.findManyWithinWorkspace(workspaceId, options)[0] ?? null;
}

public async findManyWithinWorkspace(
workspaceId: string,
options?: FindManyOptions<ObjectMetadataEntity>,
) {
return this.findMany({
return this.objectMetadataRepository.find({
relations: [
'fields.object',
'fields',
'fields.fromRelationMetadata',
'fields.toRelationMetadata',
'fields.fromRelationMetadata.toObjectMetadata',
],
...options,
where: {
...options?.where,
Expand All @@ -355,6 +358,21 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
});
}

public async findMany(options?: FindManyOptions<ObjectMetadataEntity>) {
return this.objectMetadataRepository.find({
relations: [
'fields',
'fields.fromRelationMetadata',
'fields.toRelationMetadata',
'fields.fromRelationMetadata.toObjectMetadata',
],
...options,
where: {
...options?.where,
},
});
}

public async deleteObjectsMetadata(workspaceId: string) {
await this.objectMetadataRepository.delete({ workspaceId });
await this.workspaceMetadataVersionService.incrementMetadataVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ export class ObjectMetadataRelationService {
createdObjectMetadata: ObjectMetadataEntity,
relatedObjectMetadata: ObjectMetadataEntity,
) {
const relationObjectMetadataNamePlural =
relatedObjectMetadata.nameSingular + 's';
const relationObjectMetadataNamePlural = relatedObjectMetadata.namePlural;

return {
standardId:
Expand All @@ -151,7 +150,7 @@ export class ObjectMetadataRelationService {
isActive: true,
isSystem: true,
type: FieldMetadataType.RELATION,
name: relationObjectMetadataNamePlural,
name: relatedObjectMetadata.namePlural,
label: capitalize(relationObjectMetadataNamePlural),
description: `${capitalize(relationObjectMetadataNamePlural)} tied to the ${createdObjectMetadata.labelSingular}`,
icon:
Expand Down

0 comments on commit 31ecaf2

Please sign in to comment.