// controllers/pingController.js
const { getDb } = require('../dbPool');
const pingModel = require('../models/pingModel');

exports.ping = async (req, res) => {
  const data = pingModel.ping();
  try {
    // DB 연결 테스트
    const db = await getDb();
    await db.query('SELECT 1');
    return res.json({
      success: true,
      ...data,
      db: 'ok'
    });
  } catch (err) {
    console.error('[PING ERROR]', err);
    return res.status(500).json({
      success: false,
      message: 'db error',
      timestamp: data.timestamp,
      error: err.message
    });
  }
};