import { pool } from '../../config/db.js'; export async function findByEntity(entityType, entityId) { const [rows] = await pool.query( `SELECT c.id, c.entity_type, c.entity_id, c.user_id, u.name AS user_name, c.message, c.created_at FROM comments c JOIN users u ON u.id = c.user_id WHERE c.entity_type = ? AND c.entity_id = ? ORDER BY c.created_at`, [entityType, entityId] ); return rows; } export async function create({ entityType, entityId, userId, message }) { const [result] = await pool.query( 'INSERT INTO comments (entity_type, entity_id, user_id, message) VALUES (?, ?, ?, ?)', [entityType, entityId, userId, message] ); const [rows] = await pool.query( `SELECT c.id, c.entity_type, c.entity_id, c.user_id, u.name AS user_name, c.message, c.created_at FROM comments c JOIN users u ON u.id = c.user_id WHERE c.id = ?`, [result.insertId] ); return rows[0]; }