新增根据id查询对应的地址簿中的对象

uml-backend
P-Jhao 1 month ago
parent a168ff24b3
commit 49cecab299

@ -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) {

@ -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);

@ -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是数字类型

Loading…
Cancel
Save