Merge branch 'fix-bug-sonaqube' into 'dev'

Fix bug sonarqube

See merge request sa4-2020/the-sanmarinoes/frontend!149
This commit is contained in:
Andrea Brites Marto 2020-05-12 16:37:22 +02:00
commit 364f58fa24

View file

@ -557,7 +557,6 @@ export const RemoteService = {
*/
saveAutomation: (data) => {
const { automation, triggerList, order } = data;
console.log('automation: ', automation, triggerList, order);
automation.triggers = [];
automation.scenes = [];
return (dispatch) => {
@ -566,15 +565,16 @@ export const RemoteService = {
const urlRangeTrigger = '/rangeTrigger';
const urlScenePriority = '/scenePriority';
const rangeTriggerList = triggerList.filter((trigger) => trigger.hasOwnProperty('operand'));
const rangeTriggerList = triggerList.filter((trigger) => 'operand' in trigger);
const booleanTriggerList = triggerList.filter(
(trigger) => !trigger.hasOwnProperty('operand'),
(trigger) => !('operand' in trigger),
);
return Endpoint.post(urlAutomation, {}, automation).then(
async (automationRes) => {
const { id } = automationRes.data;
// Introduce the range triggers in the automation
const resRangeTriggers = [];
for (const t of rangeTriggerList) {
const trigger = {
automationId: id,
@ -582,38 +582,39 @@ export const RemoteService = {
operator: t.operand,
range: t.value,
};
const resRange = await Endpoint.post(urlRangeTrigger, {}, trigger);
automation.triggers.push(resRange.data);
resRangeTriggers.push(Endpoint.post(urlRangeTrigger, {}, trigger));
}
automation.triggers = (await Promise.all(resRangeTriggers)).map((v) => v.data);
const resBoolTriggers = [];
for (const t of booleanTriggerList) {
const trigger = {
automationId: id,
deviceId: t.device,
on: t.value,
};
const resBoolean = await Endpoint.post(
resBoolTriggers.push(Endpoint.post(
urlBooleanTrigger,
{},
trigger,
);
automation.triggers.push(resBoolean.data);
console.log('TRIGGERS: ', automation);
));
}
automation.triggers.push(...((await Promise.all(resBoolTriggers)).map((v) => v.data)));
const resScenePriorities = [];
for (const [priority, sceneId] of order.entries()) {
const scenePriority = {
automationId: id,
priority,
sceneId,
};
const resScenes = await Endpoint.post(
resScenePriorities.push(Endpoint.post(
urlScenePriority,
{},
scenePriority,
);
automation.scenes.push(resScenes.data);
));
}
automation.scenes = (await Promise.all(resScenePriorities)).map((v) => v.data);
automation.id = id;
dispatch(actions.automationSave(automation));
},