修复了根据Id获取地址的bug

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

@ -12,11 +12,10 @@ module.exports.getAddressDao = async function (senderId) {
}; };
module.exports.getAddressByIdDao = async function (id) { module.exports.getAddressByIdDao = async function (id) {
return handleArrayDaoData( const result = await addressModel.findOne({
await addressModel.findOne({ where: { id },
where: { id }, });
}) return handleArrayDaoData(result);
);
}; };
module.exports.addAddressDao = async function (addressData) { module.exports.addAddressDao = async function (addressData) {

@ -5,6 +5,7 @@ const {
addAddressServices, addAddressServices,
updateAddressServices, updateAddressServices,
deleteAddressServices, deleteAddressServices,
getAddressByIdServices,
} = require("../services/addressService"); } = require("../services/addressService");
const { formatResponse } = require("../utils/tools"); const { formatResponse } = require("../utils/tools");

@ -3,6 +3,7 @@ const {
addAddressDao, addAddressDao,
updateAddressDao, updateAddressDao,
deleteAddressDao, deleteAddressDao,
getAddressByIdDao,
} = require("../dao/addressDao"); } = require("../dao/addressDao");
module.exports.getAddressServices = async function (senderId) { module.exports.getAddressServices = async function (senderId) {
@ -10,7 +11,7 @@ module.exports.getAddressServices = async function (senderId) {
}; };
module.exports.getAddressByIdServices = async function (id) { module.exports.getAddressByIdServices = async function (id) {
return await getAddressByIdDao(id); return await getAddressByIdDao(+id);
}; };
module.exports.addAddressServices = async function (addressData) { module.exports.addAddressServices = async function (addressData) {

@ -1,37 +1,41 @@
const jwt = require("jsonwebtoken") const jwt = require("jsonwebtoken");
const md5 = require("md5") const md5 = require("md5");
module.exports.formatResponse = function (code, msg, data) { module.exports.formatResponse = function (code, msg, data) {
return { return {
code, code,
msg, msg,
data data,
} };
} };
module.exports.analysisToken = function (token) { module.exports.analysisToken = function (token) {
return jwt.verify(token.split(" ")[1], md5(process.env.JWT_SECRET)) return jwt.verify(token.split(" ")[1], md5(process.env.JWT_SECRET));
} };
module.exports.getJwtToken = function (payload) { module.exports.getJwtToken = function (payload) {
let loginPeriod = 1; //默认记住一天 let loginPeriod = 1; //默认记住一天
return jwt.sign(payload, md5(process.env.JWT_SECRET), { return jwt.sign(payload, md5(process.env.JWT_SECRET), {
expiresIn: 60 * 60 * 24 * loginPeriod expiresIn: 60 * 60 * 24 * loginPeriod,
}) });
} };
module.exports.getRandomExpressId = function () { module.exports.getRandomExpressId = function () {
return "SF" + Math.floor(Math.random() * 1000000000000) return "SF" + Math.floor(Math.random() * 1000000000000);
} };
module.exports.handleArrayDaoData = function (arr) { module.exports.handleArrayDaoData = function (arr) {
const result = [] const result = [];
// for (const item of arr) { // for (const item of arr) {
// result.push(item.dataValues) // result.push(item.dataValues)
// } // }
//倒叙输出 //倒叙输出
if (Array.isArray(arr)) {
for (let i = arr.length - 1; i >= 0; i--) { for (let i = arr.length - 1; i >= 0; i--) {
result.push(arr[i].dataValues) result.push(arr[i].dataValues);
} }
return result } else {
} result.push(arr.dataValues);
}
return result;
};

Loading…
Cancel
Save