forked from rohit/spurrin-backend
report flagged session
This commit is contained in:
parent
643a131d56
commit
e6a4c003a6
@ -9,3 +9,7 @@ CREATE TABLE IF NOT EXISTS document_views (
|
|||||||
|
|
||||||
ALTER TABLE interaction_logs
|
ALTER TABLE interaction_logs
|
||||||
ADD COLUMN is_flagged BOOLEAN DEFAULT FALSE;
|
ADD COLUMN is_flagged BOOLEAN DEFAULT FALSE;
|
||||||
|
|
||||||
|
ALTER TABLE interaction_logs
|
||||||
|
ADD COLUMN report_text TEXT AFTER is_flagged;
|
||||||
|
|
||||||
|
|||||||
@ -221,7 +221,9 @@ async function initializeDatabase() {
|
|||||||
created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
hospital_code VARCHAR(12) NOT NULL,
|
hospital_code VARCHAR(12) NOT NULL,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
KEY session_id (session_id)
|
KEY session_id (session_id),
|
||||||
|
report_text TEXT
|
||||||
|
|
||||||
)`,
|
)`,
|
||||||
|
|
||||||
// QA runtime cache table
|
// QA runtime cache table
|
||||||
|
|||||||
@ -224,7 +224,7 @@ WHERE app_user_id = ? AND session_id = ? AND id = ?
|
|||||||
message: 'Updated successfully',
|
message: 'Updated successfully',
|
||||||
data: {
|
data: {
|
||||||
app_user_id,
|
app_user_id,
|
||||||
session_id
|
session_id
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -242,6 +242,55 @@ WHERE app_user_id = ? AND session_id = ? AND id = ?
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.addReportText = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { session_id, report_text } = req.body;
|
||||||
|
const app_user_id = req.user.id;
|
||||||
|
|
||||||
|
// Validate input
|
||||||
|
if (!app_user_id || !session_id || typeof report_text !== 'string') {
|
||||||
|
return res.status(400).json({
|
||||||
|
status: 'error',
|
||||||
|
message: 'app_user_id, session_id, logid, and report_text are required',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update query
|
||||||
|
const updateQuery = `
|
||||||
|
UPDATE interaction_logs
|
||||||
|
SET report_text = ?
|
||||||
|
WHERE app_user_id = ? AND session_id = ?
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Execute update
|
||||||
|
const result = await db.query(updateQuery, [report_text, app_user_id, session_id]);
|
||||||
|
|
||||||
|
// Handle response
|
||||||
|
if (result.affectedRows > 0) {
|
||||||
|
return res.status(200).json({
|
||||||
|
status: 'success',
|
||||||
|
message: 'Session reported successfully. Admin will review your report',
|
||||||
|
data: {
|
||||||
|
app_user_id,
|
||||||
|
session_id,
|
||||||
|
report_text
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return res.status(404).json({
|
||||||
|
status: 'error',
|
||||||
|
message: 'No matching record found to update report text',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating report text:', error);
|
||||||
|
return res.status(500).json({
|
||||||
|
status: 'error',
|
||||||
|
message: 'Internal server error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.signup = async (req, res) => {
|
exports.signup = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -162,4 +162,7 @@ router.put('/like', upload.none(), authMiddleware.authenticateToken, appUserCont
|
|||||||
|
|
||||||
router.put('/flag', upload.none(), authMiddleware.authenticateToken, appUserController.hitFlag);
|
router.put('/flag', upload.none(), authMiddleware.authenticateToken, appUserController.hitFlag);
|
||||||
|
|
||||||
|
router.post('/logs/add-report', authMiddleware.authenticateToken, appUserController.addReportText);
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
Loading…
Reference in New Issue
Block a user