添加了可以根据用户id查询对应的地址簿功能

uml-backend
P-Jhao 2 weeks ago
parent ed53fb0f5f
commit a168ff24b3

@ -1,8 +1,14 @@
const { handleArrayDaoData } = require("../utils/tools"); const { handleArrayDaoData } = require("../utils/tools");
const addressModel = require("./model/addressModel"); const addressModel = require("./model/addressModel");
module.exports.getAddressDao = async function () { module.exports.getAddressDao = async function (senderId) {
return handleArrayDaoData(await addressModel.findAll()); // 如果有senderId参数则添加查询条件
const whereCondition = senderId ? { senderId } : {};
return handleArrayDaoData(
await addressModel.findAll({
where: whereCondition,
})
);
}; };
module.exports.addAddressDao = async function (addressData) { module.exports.addAddressDao = async function (addressData) {

@ -4,6 +4,10 @@ const { DataTypes } = require("sequelize");
module.exports = sequelize.define( module.exports = sequelize.define(
"address", "address",
{ {
senderId: {
type: DataTypes.STRING,
allowNull: false,
},
receiver: { receiver: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,

@ -9,7 +9,9 @@ const {
const { formatResponse } = require("../utils/tools"); const { formatResponse } = require("../utils/tools");
router.get("/", async function (req, res, next) { 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)); res.send(formatResponse(0, "", data));
}); });

@ -5,8 +5,8 @@ const {
deleteAddressDao, deleteAddressDao,
} = require("../dao/addressDao"); } = require("../dao/addressDao");
module.exports.getAddressServices = async function () { module.exports.getAddressServices = async function (senderId) {
return await getAddressDao(); return await getAddressDao(senderId);
}; };
module.exports.addAddressServices = async function (addressData) { module.exports.addAddressServices = async function (addressData) {

Loading…
Cancel
Save