diff --git a/dao/expressDao.js b/dao/expressDao.js index be01a19..5f9ea13 100644 --- a/dao/expressDao.js +++ b/dao/expressDao.js @@ -17,4 +17,14 @@ module.exports.updateExpressDao = async function (expData) { } }) return handleArrayDaoData(await expressModel.findAll()) +} + +module.exports.deleteExpressDao = async function (id) { + console.log(id, "deleteId") + await expressModel.destroy({ + where: { + id + } + }) + return handleArrayDaoData(await expressModel.findAll()) } \ No newline at end of file diff --git a/routes/express.js b/routes/express.js index 13b782f..649c6db 100644 --- a/routes/express.js +++ b/routes/express.js @@ -3,7 +3,8 @@ const router = express.Router() const { getExpressServices, addExpressServices, - updateExpressServices + updateExpressServices, + deleteExpressServices } = require("../services/expressService") const { formatResponse @@ -24,4 +25,9 @@ router.put("/", async function (req, res, next) { res.send(formatResponse(0, "", data)) }) +router.delete("/", async function (req, res, next) { + const data = await deleteExpressServices(req.body) + res.send(formatResponse(0, "", data)) +}) + module.exports = router \ No newline at end of file diff --git a/services/expressService.js b/services/expressService.js index 70db178..9df2a7f 100644 --- a/services/expressService.js +++ b/services/expressService.js @@ -1,7 +1,8 @@ const { getExpressDao, addExpressDao, - updateExpressDao + updateExpressDao, + deleteExpressDao } = require("../dao/expressDao") const { getRandomExpressId @@ -23,4 +24,12 @@ module.exports.addExpressServices = async function (expData) { module.exports.updateExpressServices = async function (expData) { //这里需要提供id return await updateExpressDao(expData) +} + +module.exports.deleteExpressServices = async function ({ + id +}) { + return await deleteExpressDao( + id + ) } \ No newline at end of file