forked from rohit/spurrin-backend
popular topic
This commit is contained in:
parent
7d2a419bae
commit
56955d1be2
@ -1825,3 +1825,69 @@ exports.forgotPin = async (req, res) => {
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
}
|
||||
};
|
||||
|
||||
// Insert interaction log
|
||||
exports.insertInteractionLog = async (req, res) => {
|
||||
try {
|
||||
const { session_id, query, response } = req.body;
|
||||
const app_user_id = req.user.id;
|
||||
|
||||
// Validate required fields
|
||||
if (!session_id || !query || !response) {
|
||||
return res.status(400).json({
|
||||
error: "session_id, query, and response are required"
|
||||
});
|
||||
}
|
||||
|
||||
// Get hospital_code from app_user
|
||||
const userQuery = "SELECT hospital_code FROM app_users WHERE id = ?";
|
||||
const userResult = await db.query(userQuery, [app_user_id]);
|
||||
|
||||
if (userResult.length === 0) {
|
||||
return res.status(404).json({ error: "User not found" });
|
||||
}
|
||||
|
||||
const hospital_code = userResult[0].hospital_code;
|
||||
|
||||
// Insert into interaction_logs
|
||||
const insertQuery = `
|
||||
INSERT INTO interaction_logs (
|
||||
session_id,
|
||||
app_user_id,
|
||||
query,
|
||||
response,
|
||||
hospital_code,
|
||||
status,
|
||||
session_title
|
||||
) VALUES (?, ?, ?, ?, ?, 'Active', ?)
|
||||
`;
|
||||
|
||||
const sessionTitle = query.length > 50 ? query.substring(0, 50) + '...' : query;
|
||||
|
||||
const result = await db.query(insertQuery, [
|
||||
session_id,
|
||||
app_user_id,
|
||||
query,
|
||||
response,
|
||||
hospital_code,
|
||||
sessionTitle
|
||||
]);
|
||||
|
||||
res.status(201).json({
|
||||
message: "Interaction log created successfully",
|
||||
data: {
|
||||
id: result.insertId,
|
||||
session_id,
|
||||
app_user_id,
|
||||
query,
|
||||
response,
|
||||
hospital_code,
|
||||
created_at: new Date()
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error inserting interaction log:", error.message);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
}
|
||||
};
|
||||
@ -166,4 +166,7 @@ router.post('/logs/add-report', authMiddleware.authenticateToken, appUserControl
|
||||
|
||||
router.put('/acknowledge/:id',authMiddleware.authenticateToken, upload.none(), appUserController.updateChecked);
|
||||
|
||||
// Insert interaction log
|
||||
router.post('/interaction-log', authMiddleware.authenticateToken, upload.none(), appUserController.insertInteractionLog);
|
||||
|
||||
module.exports = router;
|
||||
Loading…
Reference in New Issue
Block a user