diff --git a/dao/addressDao.js b/dao/addressDao.js index a245a51..e05b4cb 100644 --- a/dao/addressDao.js +++ b/dao/addressDao.js @@ -11,6 +11,14 @@ module.exports.getAddressDao = async function (senderId) { ); }; +module.exports.getAddressByIdDao = async function (id) { + return handleArrayDaoData( + await addressModel.findOne({ + where: { id }, + }) + ); +}; + module.exports.addAddressDao = async function (addressData) { // 如果新增的是默认地址,需要先将其他地址设为非默认 if (addressData.isDefault === 1) { diff --git a/routes/address.js b/routes/address.js index c99d606..595c4fc 100644 --- a/routes/address.js +++ b/routes/address.js @@ -15,6 +15,16 @@ router.get("/", async function (req, res, next) { res.send(formatResponse(0, "", data)); }); +router.get("/:id", async function (req, res, next) { + const { id } = req.params; + const data = await getAddressByIdServices(id); + if (data) { + res.send(formatResponse(0, "", data)); + } else { + res.send(formatResponse(1, "地址不存在", null)); + } +}); + router.post("/", async function (req, res, next) { console.log(req, res); const data = await addAddressServices(req.body); diff --git a/services/addressService.js b/services/addressService.js index 870ff83..8039dbe 100644 --- a/services/addressService.js +++ b/services/addressService.js @@ -9,6 +9,10 @@ module.exports.getAddressServices = async function (senderId) { return await getAddressDao(senderId); }; +module.exports.getAddressByIdServices = async function (id) { + return await getAddressByIdDao(id); +}; + module.exports.addAddressServices = async function (addressData) { console.log(addressData); // 确保isDefault是数字类型