Create route for creating intents
This commit is contained in:
parent
36bcf3786d
commit
2d84f16e8a
@ -37,7 +37,7 @@ exports.getIntentCommand = async (req, res) => {
|
|||||||
const intents = await Intent.findAll();
|
const intents = await Intent.findAll();
|
||||||
const intent = intents.find(obj => obj.description === text);
|
const intent = intents.find(obj => obj.description === text);
|
||||||
|
|
||||||
console.log(intent, config.DEVICE_ID);
|
console.log(intents, intent);
|
||||||
|
|
||||||
if (intent) {
|
if (intent) {
|
||||||
const commandId = await redis.client.xAdd(
|
const commandId = await redis.client.xAdd(
|
||||||
@ -92,4 +92,28 @@ exports.getIntentCommand = async (req, res) => {
|
|||||||
|
|
||||||
return res.status(500).send({message: err.message || "Internal server error."});
|
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."});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
@ -18,4 +18,7 @@ router.get("/", /*[authJwt.verifyToken, authJwt.isAdmin],*/ controller.getAllInt
|
|||||||
// Get intent command (for now by description)
|
// Get intent command (for now by description)
|
||||||
router.post("/getintentcommand", controller.getIntentCommand);
|
router.post("/getintentcommand", controller.getIntentCommand);
|
||||||
|
|
||||||
|
// Create intent
|
||||||
|
router.post("/createintent", controller.createIntent);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
Loading…
Reference in New Issue
Block a user