이렇게 만들고
import Employee from "../Model/employee.js";
import { db } from "../data/database.js";
const employeeController = {};
employeeController.makeOne = async (req, res) => {
const { fullName, city, position, employed } = req.body;
return db.execute(
'INSERT INTO new_table (id, fullName, city, position, employed) VALUES (?,?, ?, ?, ?)',
[fullName, city, position, employed]
).then((result)=> {
res.json({ status: "success", data: result });
})
}
// READ ALL
employeeController.getAll = async (req, res) => {
return db.execute('SELECT id, fullName, position, city, employed FROM new_table ORDER BY fullName')
.then(result => {
res.json({ status: "success", data: result[0] });
}
)
};
// UPDATE
employeeController.updateOne = async (req, res) => {
const { id } = req.params;
const { city, position, employed } = req.body;
return db.execute('UPDATE new_table SET city=?, position=?, employed=? WHERE id=?',[city, position, employed, id])
.then(()=> res.json({status:"success"}))
};
나름 깔끔히 만들겠다고 구현하고 있는중인데..
이정도는 기초인건지 궁금합니다..