36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
// backend/models/File.js
|
|
import pool from '../config/db.js';
|
|
|
|
const File = {
|
|
async createFile(fileData) {
|
|
const { user_id, file_name, file_path, file_type, status } = fileData;
|
|
try {
|
|
await pool.execute(
|
|
'INSERT INTO files (user_id, file_name, file_path, file_type, status) VALUES (?, ?, ?, ?, ?)',
|
|
[user_id, file_name, file_path, file_type, status]
|
|
);
|
|
} catch (error) {
|
|
throw new Error('Database error: Unable to create file');
|
|
}
|
|
},
|
|
|
|
async getUserFiles(user_id) {
|
|
try {
|
|
const [rows] = await pool.execute('SELECT * FROM files WHERE user_id = ?', [user_id]);
|
|
return rows;
|
|
} catch (error) {
|
|
throw new Error('Database error: Unable to fetch files');
|
|
}
|
|
},
|
|
|
|
async updateFileStatus(fileId, status, user_id) {
|
|
try {
|
|
await pool.execute('UPDATE files SET status = ? WHERE id = ? AND user_id = ?', [status, fileId, user_id]);
|
|
} catch (error) {
|
|
throw new Error('Database error: Unable to update file status');
|
|
}
|
|
},
|
|
};
|
|
|
|
export default File;
|