const uploadModel = require('../models/uploadModel');

// 1. 문서 업로드
exports.createUpload = async (req, res) => {
  try {
    const doc = req.body;
    const id = await new Promise((resolve, reject) => {
      uploadModel.create(doc, (err, insertId) => (err ? reject(err) : resolve(insertId)));
    });
    res.status(201).json({ success: true, id });
  } catch (err) {
    res.status(500).json({ error: err.message || String(err) });
  }
};

// 2. 전체 업로드 문서 조회
exports.getUploads = async (req, res) => {
  try {
    const rows = await new Promise((resolve, reject) => {
      uploadModel.getAll((err, data) => (err ? reject(err) : resolve(data)));
    });
    res.json(rows);
  } catch (err) {
    res.status(500).json({ error: err.message || String(err) });
  }
};