Files
TK-FB-Project/api.hyungi.net/models/uploadModel.js

45 lines
1.1 KiB
JavaScript

const { getDb } = require('../dbPool');
// 1. 문서 업로드
const create = async (doc, callback) => {
try {
const db = await getDb();
const sql = `
INSERT INTO uploaded_documents
(title, tags, description, original_name, stored_name, file_path, file_type, file_size, submitted_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`;
const values = [
doc.title,
doc.tags,
doc.description,
doc.original_name,
doc.stored_name,
doc.file_path,
doc.file_type,
doc.file_size,
doc.submitted_by
];
const [result] = await db.query(sql, values);
callback(null, result.insertId);
} catch (err) {
callback(new Error(err.message || String(err)));
}
};
// 2. 전체 문서 목록 조회
const getAll = async (callback) => {
try {
const db = await getDb();
const [rows] = await db.query(`SELECT * FROM uploaded_documents ORDER BY created_at DESC`);
callback(null, rows);
} catch (err) {
callback(err);
}
};
// ✅ 내보내기
module.exports = {
create,
getAll
};