|
|
@ -38,30 +38,39 @@ class Database { |
|
|
|
} |
|
|
|
|
|
|
|
getPresets() { |
|
|
|
return db.execute("SELECT * from `preset`") |
|
|
|
return db.execute("SELECT PK_preset as id, title, description from `preset`") |
|
|
|
.then(res => { |
|
|
|
return res[0] |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
setPreset(preset) { |
|
|
|
console.log("INSERT INTO `led`.`preset` VALUES (NUll,"+preset.name+","+preset.description+");") |
|
|
|
return db.execute("INSERT INTO `led`.`preset` VALUES (NUll,'"+preset.name+"','"+preset.description+"');") |
|
|
|
.then(res=> { |
|
|
|
console.log(res) |
|
|
|
let temp = "" |
|
|
|
preset.settings.forEach(channel => { |
|
|
|
console.log(channel) |
|
|
|
preset.settings.forEach( (channel, index) => { |
|
|
|
if(index!=0){ |
|
|
|
temp+="," |
|
|
|
} |
|
|
|
temp += "(NULL,"+channel.id+","+res[0].insertId+","+channel.value+",'"+channel.key+"')" |
|
|
|
}) |
|
|
|
console.log("INSERT INTO `led`.`mapping-preset` VALUES "+temp+";") |
|
|
|
return db.execute("INSERT INTO `led`.`mapping-preset` VALUES "+temp+";") |
|
|
|
.then(res=>{console.log("done")}) |
|
|
|
.catch(err=>{console.log(err)}) |
|
|
|
.then(res=>{return 200}) |
|
|
|
.catch(err=>{ |
|
|
|
console.log(err) |
|
|
|
console.log("Inserting channels for preset failed, cleaning up preset...") |
|
|
|
db.execute("DELETE FROM `led`.`preset` WHERE PK_preset="+res[0].insertId) |
|
|
|
.then(res => {console.log("Cleaning up was successfull!")}) |
|
|
|
.catch(err => { |
|
|
|
console.log("Cleaning up failed: ") |
|
|
|
console.log(err) |
|
|
|
}) |
|
|
|
return 500 |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
getPresest(preset) { |
|
|
|
getPreset(preset) { |
|
|
|
return db.execute("SELECT board.address, `mapping-light`.channel, `mapping-preset`.value \ |
|
|
|
FROM `led`.`mapping-light`, `led`.`mapping-preset`, `board` \ |
|
|
|
WHERE `mapping-preset`.`FK_preset` = "+ preset + " \ |
|
|
@ -73,6 +82,15 @@ class Database { |
|
|
|
} |
|
|
|
|
|
|
|
deletePreset(id) { |
|
|
|
console.log(id) |
|
|
|
return db.execute("DELETE FROM `led`.`preset` WHERE PK_preset = " + id) |
|
|
|
.then(res => { |
|
|
|
|
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.log(err) |
|
|
|
}) |
|
|
|
|
|
|
|
//return db.execute("DELETE FROM ")
|
|
|
|
} |
|
|
|
} |
|
|
|