fix: 添加防止设备自关联的校验
This commit is contained in:
@@ -68,7 +68,9 @@ const { mutate: linkPortToDevice, isPending: linking } = useMutation({
|
||||
const lowerDeviceDbId = lowerDevice.value?.id;
|
||||
if (!lowerDeviceDbId) throw new Error('该设备没有ID');
|
||||
|
||||
// 0. 检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
|
||||
// 0. 检查是否会导致循环关联,
|
||||
if (upperDeviceDbId === lowerDeviceDbId) throw new Error('不能关联到自身');
|
||||
// 以及检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
|
||||
const duplicated = Object.entries(upperDeviceLinkDescription.value?.downstream ?? {}).find(([, deviceStoreIndex]) => {
|
||||
return deviceStoreIndex.deviceDbId === lowerDeviceDbId;
|
||||
});
|
||||
|
||||
@@ -78,7 +78,9 @@ const { mutate: linkPortToDevice, isPending: linking } = useMutation({
|
||||
const lowerDeviceDbId = lowerDevice.value?.id;
|
||||
if (!lowerDeviceDbId) throw new Error('该设备没有ID');
|
||||
|
||||
// 0. 检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
|
||||
// 0. 检查是否会导致循环关联,
|
||||
if (upperDeviceDbId === lowerDeviceDbId) throw new Error('不能关联到自身');
|
||||
// 以及检查上游设备的linkDescription的downstream字段是否存在某个端口已经关联下游设备
|
||||
const duplicated = Object.entries(upperDeviceLinkDescription.value?.downstream ?? {}).find(([, deviceStoreIndex]) => {
|
||||
return deviceStoreIndex.deviceDbId === lowerDeviceDbId;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user