diff --git a/api/forms/module_form.py b/api/forms/module_form.py index 514e207..94ace9f 100644 --- a/api/forms/module_form.py +++ b/api/forms/module_form.py @@ -10,5 +10,5 @@ class ModuleSetValueForm(FlaskForm): UUID(message='Hodnota nie je vo formáte UUID.') ] ) - data_point = StringField('data_point', validators=[DataRequired(message='Hodnota data_point je povinná.')]) + datapoint = StringField('data_point', validators=[DataRequired(message='Hodnota datapoint je povinná.')]) value = StringField('value', validators=[DataRequired(message='Hodnota value je povinná.')]) diff --git a/api/routes.py b/api/routes.py index 075f4ab..8b7d091 100644 --- a/api/routes.py +++ b/api/routes.py @@ -178,11 +178,15 @@ def set_value_module(module_id): raise ApiException('Daný modul sa nepodarilo nájsť.', status_code=http_status.HTTP_404_NOT_FOUND) device = module.devices.filter_by(id=data.get('device_id')).first() + del data['device_id'] if not device: raise ApiException('Dané zariadenie sa nepodarilo nájsť.', status_code=http_status.HTTP_404_NOT_FOUND) - data['device_uuid'] = data['device_id'] - del data['device_id'] + datapoint = module.module_device_type.device_type_datapoints.filter_by(code=data.get('datapoint')).first() + if not datapoint: + raise ApiException('Daný datapoint sa nepodarilo nájsť.', status_code=http_status.HTTP_404_NOT_FOUND) + + data['device_uuid'] = str(device.uuid) # TODO: Ziskat sequence number (odniekial) data['sequence_number'] = 123 diff --git a/core/models/module_device_type.py b/core/models/module_device_type.py index 7b8f91a..360e16d 100644 --- a/core/models/module_device_type.py +++ b/core/models/module_device_type.py @@ -11,7 +11,7 @@ class ModuleDeviceType(StandardModel): code = db.Column(db.String(100), nullable=True) protocol_id = db.Column(UUID(as_uuid=True), db.ForeignKey('protocols.id')) - device_type_datapoints = db.relationship("DeviceTypeDatapoint", back_populates="module_device_type") + device_type_datapoints = db.relationship("DeviceTypeDatapoint", lazy='dynamic', back_populates="module_device_type") protocol = db.relationship("Protocol", back_populates="module_device_types") modules = db.relationship("Module", back_populates="module_device_type")