From 49cecab2992d53199511b96dea520234a13e8513 Mon Sep 17 00:00:00 2001 From: P-Jhao <2212688637@qq.com> Date: Mon, 28 Apr 2025 01:03:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=B9=E6=8D=AEid=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=AF=B9=E5=BA=94=E7=9A=84=E5=9C=B0=E5=9D=80=E7=B0=BF?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/addressDao.js | 8 ++++++++ routes/address.js | 10 ++++++++++ services/addressService.js | 4 ++++ 3 files changed, 22 insertions(+) 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是数字类型