Create route for creating intents

This commit is contained in:
Apher Fox 2026-07-01 23:42:05 +00:00
parent 36bcf3786d
commit 2d84f16e8a
2 changed files with 29 additions and 2 deletions

View File

@ -37,7 +37,7 @@ exports.getIntentCommand = async (req, res) => {
const intents = await Intent.findAll();
const intent = intents.find(obj => obj.description === text);
console.log(intent, config.DEVICE_ID);
console.log(intents, intent);
if (intent) {
const commandId = await redis.client.xAdd(
@ -93,3 +93,27 @@ exports.getIntentCommand = async (req, res) => {
return res.status(500).send({message: err.message || "Internal server error."});
}
};
// Create intent
exports.createIntent = async (req, res) => {
try {
const {command, description, type} = req.body;
if (!command || !description || !type) {
return res.status(400).send({message: "Missing required fields: command, description, type"});
}
const intent = await Intent.create({
command,
description,
type
});
return res.status(201).send({message: "Intent created successfully.", intent});
} catch (err) {
console.error("createIntent error:", err);
return res.status(500).send({message: err.message || "Internal server error."});
}
};

View File

@ -18,4 +18,7 @@ router.get("/", /*[authJwt.verifyToken, authJwt.isAdmin],*/ controller.getAllInt
// Get intent command (for now by description)
router.post("/getintentcommand", controller.getIntentCommand);
// Create intent
router.post("/createintent", controller.createIntent);
module.exports = router;