From 3c8f9a1adaf7693a697f37a5be8d27367d89c578 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Wed, 29 Mar 2023 10:11:55 +0200
Subject: [PATCH] Allow to delete npcs
---
truthinquiry/routes/routes_api_admin.py | 10 +++++++++-
truthinquiry/static/js/admin.js | 5 +++++
truthinquiry/templates/admin/npc.html | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/truthinquiry/routes/routes_api_admin.py b/truthinquiry/routes/routes_api_admin.py
index ec9b70a..08639dd 100644
--- a/truthinquiry/routes/routes_api_admin.py
+++ b/truthinquiry/routes/routes_api_admin.py
@@ -162,4 +162,12 @@ def set_npc():
db.session.commit()
- return {"error": 0}
\ No newline at end of file
+ return {"error": 0}
+
+@routes_api_admin.route("/deleteNpc", methods=["GET", "POST"])
+@require_admin(api=True)
+def delete_npc():
+ input_npc_id = flask.request.json["npc_id"]
+ db.session.execute(delete(Npc).where(Npc.NPC_ID==input_npc_id))
+ db.session.commit()
+ return {}
\ No newline at end of file
diff --git a/truthinquiry/static/js/admin.js b/truthinquiry/static/js/admin.js
index 4e4ac8d..faeb6dc 100644
--- a/truthinquiry/static/js/admin.js
+++ b/truthinquiry/static/js/admin.js
@@ -112,3 +112,8 @@ function saveFormNpc(){
makeAPIRequest("admin/setNpc", {"npc": data, "lang": "FR"}, {"content": "json"})
}
+async function deleteNpc(){
+ let npc_id = npc.querySelector("#npc_id").value;
+ await makeAPIRequest("admin/deleteNpc", {"npc_id": npc_id, "lang": "FR"}, {"content": "json"});
+ document.location = "/admin";
+}
\ No newline at end of file
diff --git a/truthinquiry/templates/admin/npc.html b/truthinquiry/templates/admin/npc.html
index 3f04ba7..13bd483 100644
--- a/truthinquiry/templates/admin/npc.html
+++ b/truthinquiry/templates/admin/npc.html
@@ -31,5 +31,6 @@
+