Skip to content

Commit

Permalink
Fixing exchange processing (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 30, 2023
1 parent 5a58bf6 commit 6477a74
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 71 deletions.
32 changes: 15 additions & 17 deletions assets/layouts/layout-default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,35 @@ const connectorsStore = useConnectors();
const isLoading = computed<boolean>((): boolean => connectorsStore.fetching);
const stores = computed(() => {
return [
useChannels(),
useChannelControls(),
useChannelProperties(),
useConnectors(),
useConnectorControls(),
useConnectorProperties(),
useDevices(),
useDeviceControls(),
useDeviceProperties(),
];
});
const stores = [
useConnectors(),
useConnectorControls(),
useConnectorProperties(),
useDevices(),
useDeviceControls(),
useDeviceProperties(),
useChannels(),
useChannelControls(),
useChannelProperties(),
];
const onWsMessage = (data: string): void => {
const onWsMessage = async (data: string): Promise<void> => {
const body = JSON.parse(data);
if (
Object.prototype.hasOwnProperty.call(body, 'routing_key') &&
Object.prototype.hasOwnProperty.call(body, 'source') &&
Object.prototype.hasOwnProperty.call(body, 'data')
) {
stores.value.forEach((store) => {
for (const store of stores) {
if (Object.prototype.hasOwnProperty.call(store, 'socketData')) {
store.socketData({
await store.socketData({
source: get(body, 'source'),
routingKey: get(body, 'routing_key'),
data: JSON.stringify(get(body, 'data')),
});
}
});
}
}
};
Expand Down
22 changes: 15 additions & 7 deletions assets/models/channels-controls/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -75,7 +75,7 @@ const recordFactory = async (data: IChannelControlRecordFactoryPayload): Promise
};

export const useChannelControls = defineStore<string, IChannelControlsState, IChannelControlsGetters, IChannelControlsActions>(
'channels_module_channels_controls',
'devices_module_channels_controls',
{
state: (): IChannelControlsState => {
return {
Expand Down Expand Up @@ -503,7 +503,11 @@ export const useChannelControls = defineStore<string, IChannelControlsState, ICh

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand All @@ -526,10 +530,14 @@ export const useChannelControls = defineStore<string, IChannelControlsState, ICh
const channel = channelsStore.findById(body.channel);

if (channel !== null) {
await this.get({
channel,
id: body.id,
});
try {
await this.get({
channel,
id: body.id,
});
} catch {
return false;
}
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions assets/models/channels-properties/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -112,7 +112,7 @@ const recordFactory = async (data: IChannelPropertyRecordFactoryPayload): Promis
};

export const useChannelProperties = defineStore<string, IChannelPropertiesState, IChannelPropertiesGetters, IChannelPropertiesActions>(
'channels_module_channels_properties',
'devices_module_channels_properties',
{
state: (): IChannelPropertiesState => {
return {
Expand Down Expand Up @@ -613,7 +613,11 @@ export const useChannelProperties = defineStore<string, IChannelPropertiesState,

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand Down Expand Up @@ -651,10 +655,14 @@ export const useChannelProperties = defineStore<string, IChannelPropertiesState,
const channel = channelsStore.findById(body.channel);

if (channel !== null) {
await this.get({
channel,
id: body.id,
});
try {
await this.get({
channel,
id: body.id,
});
} catch {
return false;
}
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions assets/models/channels/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -542,7 +542,11 @@ export const useChannels = defineStore<string, IChannelsState, IChannelsGetters,

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand Down Expand Up @@ -578,12 +582,20 @@ export const useChannels = defineStore<string, IChannelsState, IChannelsGetters,
const device = devicesStore.findById(body.device);

if (device !== null) {
this.get({
device,
id: body.id,
});
try {
await this.get({
device,
id: body.id,
});
} catch {
return false;
}
} else {
devicesStore.get({ id: body.device, withChannels: true });
try {
devicesStore.get({ id: body.device, withChannels: true });
} catch {
return false;
}
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions assets/models/connectors-controls/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -403,7 +403,11 @@ export const useConnectorControls = defineStore<string, IConnectorControlsState,

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand All @@ -426,12 +430,20 @@ export const useConnectorControls = defineStore<string, IConnectorControlsState,
const connector = connectorsStore.findById(body.connector);

if (connector !== null) {
await this.get({
connector,
id: body.id,
});
try {
await this.get({
connector,
id: body.id,
});
} catch {
return false;
}
} else {
await connectorsStore.get({ id: body.connector });
try {
await connectorsStore.get({ id: body.connector });
} catch {
return false;
}
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions assets/models/connectors-properties/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -528,7 +528,11 @@ export const useConnectorProperties = defineStore<string, IConnectorPropertiesSt

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand Down Expand Up @@ -566,12 +570,20 @@ export const useConnectorProperties = defineStore<string, IConnectorPropertiesSt
const connector = connectorsStore.findById(body.connector);

if (connector !== null) {
await this.get({
connector,
id: body.id,
});
try {
await this.get({
connector,
id: body.id,
});
} catch {
return false;
}
} else {
await connectorsStore.get({ id: body.connector });
try {
await connectorsStore.get({ id: body.connector });
} catch {
return false;
}
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions assets/models/connectors/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -485,7 +485,11 @@ export const useConnectors = defineStore<string, IConnectorsState, IConnectorsGe

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand Down Expand Up @@ -517,7 +521,11 @@ export const useConnectors = defineStore<string, IConnectorsState, IConnectorsGe
},
});
} else {
this.get({ id: body.id });
try {
await this.get({ id: body.id });
} catch {
return false;
}
}
}

Expand Down
26 changes: 19 additions & 7 deletions assets/models/devices-controls/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import axios from 'axios';
import { Jsona } from 'jsona';
import Ajv from 'ajv';
import Ajv from 'ajv/dist/2020';
import { v4 as uuid } from 'uuid';
import get from 'lodash/get';

Expand Down Expand Up @@ -402,7 +402,11 @@ export const useDeviceControls = defineStore<string, IDeviceControlsState, IDevi

const isValid = jsonSchemaValidator.compile<ExchangeEntity>(exchangeEntitySchema);

if (!isValid(body)) {
try {
if (!isValid(body)) {
return false;
}
} catch {
return false;
}

Expand All @@ -426,12 +430,20 @@ export const useDeviceControls = defineStore<string, IDeviceControlsState, IDevi
const device = devicesStore.findById(body.device);

if (device !== null) {
await this.get({
device,
id: body.id,
});
try {
await this.get({
device,
id: body.id,
});
} catch {
return false;
}
} else {
await devicesStore.get({ id: body.device });
try {
await devicesStore.get({ id: body.device });
} catch {
return false;
}
}
}
}
Expand Down
Loading

0 comments on commit 6477a74

Please sign in to comment.