mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-24 14:53:52 +03:00
Add deleteOneRelation resolver (#2569)
This commit is contained in:
parent
ed71ef67af
commit
1deb742ac9
@ -42,7 +42,7 @@ import { RelationMetadataDTO } from './dtos/relation-metadata.dto';
|
||||
pagingStrategy: PagingStrategies.CURSOR,
|
||||
create: { many: { disabled: true } },
|
||||
update: { disabled: true },
|
||||
delete: { disabled: true },
|
||||
delete: { many: { disabled: true } },
|
||||
guards: [JwtAuthGuard],
|
||||
},
|
||||
],
|
||||
|
@ -35,6 +35,44 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
super(relationMetadataRepository);
|
||||
}
|
||||
|
||||
override async deleteOne(id: string): Promise<RelationMetadataEntity> {
|
||||
const relationMetadata = await this.relationMetadataRepository.findOne({
|
||||
where: { id },
|
||||
relations: ['fromFieldMetadata', 'toFieldMetadata'],
|
||||
});
|
||||
|
||||
if (!relationMetadata) {
|
||||
throw new NotFoundException('Relation does not exist');
|
||||
}
|
||||
|
||||
if (
|
||||
!relationMetadata.toFieldMetadata.isCustom ||
|
||||
!relationMetadata.fromFieldMetadata.isCustom
|
||||
) {
|
||||
throw new BadRequestException("Standard Relations can't be deleted");
|
||||
}
|
||||
|
||||
if (
|
||||
relationMetadata.toFieldMetadata.isActive ||
|
||||
relationMetadata.fromFieldMetadata.isActive
|
||||
) {
|
||||
throw new BadRequestException("Active relations can't be deleted");
|
||||
}
|
||||
|
||||
const deletedRelationMetadata = super.deleteOne(id);
|
||||
|
||||
this.fieldMetadataService.deleteMany({
|
||||
id: {
|
||||
in: [
|
||||
relationMetadata.fromFieldMetadataId,
|
||||
relationMetadata.toFieldMetadataId,
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
return deletedRelationMetadata;
|
||||
}
|
||||
|
||||
override async createOne(
|
||||
record: CreateRelationInput,
|
||||
): Promise<RelationMetadataEntity> {
|
||||
|
Loading…
Reference in New Issue
Block a user