diff --git a/src/anlagen/components/components.service.ts b/src/anlagen/components/components.service.ts index 14b62cc..e8f1f1a 100644 --- a/src/anlagen/components/components.service.ts +++ b/src/anlagen/components/components.service.ts @@ -131,6 +131,11 @@ export class ComponentsService { } + async removeSignalRef(compId: string, signalId: string): Promise { + await this.model.updateOne({ 'components._id': new Types.ObjectId(compId) }, + { $pull: { 'components.$.signalIds': new Types.ObjectId(signalId) } }).exec(); + } + async createSignalRef(compId: string, signalId: string): Promise { if (!Types.ObjectId.isValid(compId)) throw new NotFoundException('Create Component id ist kein ObjectId') @@ -155,6 +160,9 @@ export class ComponentsService { { id: component._id!.toString(), name: component.name, + prefix: component.prefix, + index: component.index, + postfix: component.postfix, type: this.getComponentType(component.type.toString()), properties: component.properties } diff --git a/src/anlagen/signals/signals.service.ts b/src/anlagen/signals/signals.service.ts index cd70122..579c4a0 100644 --- a/src/anlagen/signals/signals.service.ts +++ b/src/anlagen/signals/signals.service.ts @@ -157,6 +157,9 @@ export class SignalsService { const removedItem = await this.model.findByIdAndDelete(id, { returnDocument: 'after', runValidators: true }); if (!removedItem) throw new NotFoundException(`Signal ${id} nicht gefunden`); + if (removedItem.componentId) { + await this.componentService.removeSignalRef(removedItem.componentId.toString(), removedItem._id.toString()); + } return this.toDto(removedItem); }