You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
const { handleArrayDaoData } = require("../utils/tools");
|
|
const addressModel = require("./model/addressModel");
|
|
|
|
module.exports.getAddressDao = async function () {
|
|
return handleArrayDaoData(await addressModel.findAll());
|
|
};
|
|
|
|
module.exports.addAddressDao = async function (addressData) {
|
|
// 如果新增的是默认地址,需要先将其他地址设为非默认
|
|
if (addressData.isDefault === 1) {
|
|
await addressModel.update({ isDefault: 0 }, { where: {} });
|
|
}
|
|
await addressModel.create(addressData);
|
|
return handleArrayDaoData(await addressModel.findAll());
|
|
};
|
|
|
|
module.exports.updateAddressDao = async function (addressData) {
|
|
// 如果更新的是默认地址,需要先将其他地址设为非默认
|
|
if (addressData.isDefault === 1) {
|
|
await addressModel.update(
|
|
{ isDefault: 0 },
|
|
{
|
|
where: { id: { [Op.ne]: addressData.id } },
|
|
}
|
|
);
|
|
}
|
|
await addressModel.update(addressData, {
|
|
where: {
|
|
id: addressData.id,
|
|
},
|
|
});
|
|
return handleArrayDaoData(await addressModel.findAll());
|
|
};
|
|
|
|
module.exports.deleteAddressDao = async function (id) {
|
|
await addressModel.destroy({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
return handleArrayDaoData(await addressModel.findAll());
|
|
};
|