Added REST PATCH endpoint for updating ARE rules.

This commit is contained in:
root
2024-02-18 21:05:02 -05:00
parent 6a18655a48
commit 1b1c8543b3
4 changed files with 138 additions and 5 deletions

View File

@@ -1,4 +1,19 @@
const areNotificationUpdateTest = {
"name": "Display an alert-----",
"author": "mgeeky",
"modules": [
{
"name": "alert_dialog",
"condition": null,
"options": {
"text":"You've been BeEFed ;>"
}
}
],
"execution_order": [0],
"execution_delay": [0],
"chain_mode": "nested-forward"
};
/**
* Form for the user to read, update and delete a specific Auto Run rule.
*
@@ -8,6 +23,11 @@
*/
AutoRunRuleForm = function(rule, deleteFn, updateFn, addFn) {
function handleUpdateRule() {
// TODO: Get data from form inputs.
updateFn(areNotificationUpdateTest);
}
AutoRunRuleForm.superclass.constructor.call(this, {
padding:'10 10 10 10',
items: [{
@@ -35,7 +55,7 @@ AutoRunRuleForm = function(rule, deleteFn, updateFn, addFn) {
handler: deleteFn
}, {
text: 'Save',
handler: updateFn
handler: handleUpdateRule
},
{
text: 'Add New',

View File

@@ -87,9 +87,9 @@ AutoRunTab = function() {
async function updateRule(id, newRuleData) {
// TODO: Check if this API endpoint even exists.
const res = await fetch(`/api/autorun/rule/${id}?token=${token}`, {
method: 'PUT',
method: 'PATCH',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(areNotification)
body: JSON.stringify(newRuleData)
});
if (!res.ok) {
console.error(`Failed when adding a new rule with status ${res.status}.`);
@@ -106,7 +106,7 @@ AutoRunTab = function() {
ruleForm = new AutoRunRuleForm(
rules[i],
function() {deleteRule(rules[i].id)},
function(newRuleData) {updateRule(rules[i].id, newRuleData)}, // TODO: Implement rule update.
function(newRuleData) {updateRule(rules[i].id, newRuleData)},
addRule
);
container.add(ruleForm);