diff --git a/dao/addressDao.js b/dao/addressDao.js index 0e7e805..a245a51 100644 --- a/dao/addressDao.js +++ b/dao/addressDao.js @@ -1,8 +1,14 @@ const { handleArrayDaoData } = require("../utils/tools"); const addressModel = require("./model/addressModel"); -module.exports.getAddressDao = async function () { - return handleArrayDaoData(await addressModel.findAll()); +module.exports.getAddressDao = async function (senderId) { + // 如果有senderId参数,则添加查询条件 + const whereCondition = senderId ? { senderId } : {}; + return handleArrayDaoData( + await addressModel.findAll({ + where: whereCondition, + }) + ); }; module.exports.addAddressDao = async function (addressData) { diff --git a/dao/model/addressModel.js b/dao/model/addressModel.js index a9c7d82..128d70a 100644 --- a/dao/model/addressModel.js +++ b/dao/model/addressModel.js @@ -4,6 +4,10 @@ const { DataTypes } = require("sequelize"); module.exports = sequelize.define( "address", { + senderId: { + type: DataTypes.STRING, + allowNull: false, + }, receiver: { type: DataTypes.STRING, allowNull: false, diff --git a/routes/address.js b/routes/address.js index e342c1e..c99d606 100644 --- a/routes/address.js +++ b/routes/address.js @@ -9,7 +9,9 @@ const { const { formatResponse } = require("../utils/tools"); router.get("/", async function (req, res, next) { - const data = await getAddressServices(); + // 从查询参数中获取senderId + const { senderId } = req.query; + const data = await getAddressServices(senderId); res.send(formatResponse(0, "", data)); }); diff --git a/services/addressService.js b/services/addressService.js index 253abe1..870ff83 100644 --- a/services/addressService.js +++ b/services/addressService.js @@ -5,8 +5,8 @@ const { deleteAddressDao, } = require("../dao/addressDao"); -module.exports.getAddressServices = async function () { - return await getAddressDao(); +module.exports.getAddressServices = async function (senderId) { + return await getAddressDao(senderId); }; module.exports.addAddressServices = async function (addressData) {