Skip to content

Commit

Permalink
Fixing relations propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Sep 1, 2021
1 parent 75e718e commit 7fe6934
Show file tree
Hide file tree
Showing 15 changed files with 466 additions and 474 deletions.
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ max-attributes=10

# Maximum number of statements in function / method body
max-statements=300

# Minimum number of public methods for a class (see R0903).
min-public-methods=0
898 changes: 440 additions & 458 deletions devices_module/models.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/lib/jsonapi/JsonApiModelPropertiesMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ class JsonApiModelPropertiesMapper extends ModelPropertiesMapper implements IMod
) {
exceptProps.push('deviceId')
exceptProps.push('device')
exceptProps.push('device_backward')
exceptProps.push('deviceBackward')

if (model.type === DeviceConnectorEntityTypes.CONNECTOR) {
exceptProps.push('connectorId')
exceptProps.push('connector')
exceptProps.push('connector_backward')
exceptProps.push('connectorBackward')
}
} else if (
model.type === ChannelPropertyEntityTypes.PROPERTY ||
model.type === ChannelConfigurationEntityTypes.CONFIGURATION
) {
exceptProps.push('channelId')
exceptProps.push('channel')
exceptProps.push('channel_backward')
exceptProps.push('channelBackward')
}

if (Array.isArray(model[RELATIONSHIP_NAMES_PROP])) {
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/channel-configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ const moduleActions: ActionTree<ChannelConfigurationState, unknown> = {
const camelName = attrName.replace(camelRegex, g => g[1].toUpperCase())

if (camelName === 'channel') {
const channel = Channel.query().where('channel', body[attrName]).first()
const channel = Channel.query().where('id', body[attrName]).first()

if (channel !== null) {
entityData.channelId = channel.id
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/channel-properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ const moduleActions: ActionTree<ChannelPropertyState, unknown> = {
const camelName = attrName.replace(camelRegex, g => g[1].toUpperCase())

if (camelName === 'channel') {
const channel = Channel.query().where('channel', body[attrName]).first()
const channel = Channel.query().where('id', body[attrName]).first()

if (channel !== null) {
entityData.channelId = channel.id
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/channels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ const moduleActions: ActionTree<ChannelState, unknown> = {
const camelName = attrName.replace(camelRegex, g => g[1].toUpperCase())

if (camelName === 'device') {
const device = Device.query().where('identifier', body[attrName]).first()
const device = Device.query().where('id', body[attrName]).first()

if (device !== null) {
entityData.deviceId = device.id
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/device-configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const moduleActions: ActionTree<DeviceConfigurationState, unknown> = {
const camelName = attrName.replace(camelRegex, g => g[1].toUpperCase())

if (camelName === 'device') {
const device = Device.query().where('device', body[attrName]).first()
const device = Device.query().where('id', body[attrName]).first()

if (device !== null) {
entityData.deviceId = device.id
Expand Down
9 changes: 8 additions & 1 deletion public/lib/models/device-connector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
JsonApiJsonPropertiesMapper,
} from '@/lib/jsonapi'
import { DeviceConnectorJsonModelInterface, ModuleApiPrefix, SemaphoreTypes } from '@/lib/types'
import Connector from '@/lib/models/connectors/Connector'
import { ConnectorInterface } from '@/lib/models/connectors/types'

interface SemaphoreFetchingState {
Expand Down Expand Up @@ -402,11 +403,17 @@ const moduleActions: ActionTree<DeviceConnectorState, unknown> = {
const camelName = attrName.replace(camelRegex, g => g[1].toUpperCase())

if (camelName === 'device') {
const device = Device.query().where('identifier', body[attrName]).first()
const device = Device.query().where('id', body[attrName]).first()

if (device !== null) {
entityData.deviceId = device.id
}
} else if (camelName === 'connector') {
const connector = Connector.query().where('id', body[attrName]).first()

if (connector !== null) {
entityData.connectorId = connector.id
}
} else {
entityData[camelName] = body[attrName]
}
Expand Down
2 changes: 1 addition & 1 deletion public/lib/models/device-properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const moduleActions: ActionTree<DevicePropertyState, unknown> = {
const camelName = attrName.replace(camelRegex, g => g[1].toUpperCase())

if (camelName === 'device') {
const device = Device.query().where('identifier', body[attrName]).first()
const device = Device.query().where('id', body[attrName]).first()

if (device !== null) {
entityData.deviceId = device.id
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function toArray(): array

'params' => (array) $this->getParams(),

'owner' => $this->getDevice()->getOwnerId(),
'device' => $this->getDevice()->getPlainId(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Channels/Configuration/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
public function toArray(): array
{
return array_merge(parent::toArray(), [
'owner' => $this->getChannel()->getDevice()->getOwnerId(),
'channel' => $this->getChannel()->getPlainId(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Channels/Properties/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
public function toArray(): array
{
return array_merge(parent::toArray(), [
'owner' => $this->getChannel()->getDevice()->getOwnerId(),
'channel' => $this->getChannel()->getPlainId(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Devices/Configuration/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
public function toArray(): array
{
return array_merge(parent::toArray(), [
'owner' => $this->getDevice()->getOwnerId(),
'device' => $this->getDevice()->getPlainId(),
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Devices/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public function toArray(): array
{
$baseProperties = [
'id' => $this->getPlainId(),
'device' => $this->getDevice()->getKey(),
'connector' => $this->getConnector()->getType(),
'device' => $this->getDevice()->getPlainId(),
'connector' => $this->getConnector()->getPlainId(),
];

if ($this->getConnector() instanceof Entities\Connectors\FbBusConnector) {
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Devices/Properties/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(
public function toArray(): array
{
return array_merge(parent::toArray(), [
'owner' => $this->getDevice()->getOwnerId(),
'device' => $this->getDevice()->getPlainId(),
]);
}

Expand Down

0 comments on commit 7fe6934

Please sign in to comment.