diff --git a/dao/addressDao.js b/dao/addressDao.js index e05b4cb..f9aaa85 100644 --- a/dao/addressDao.js +++ b/dao/addressDao.js @@ -12,11 +12,10 @@ module.exports.getAddressDao = async function (senderId) { }; module.exports.getAddressByIdDao = async function (id) { - return handleArrayDaoData( - await addressModel.findOne({ - where: { id }, - }) - ); + const result = await addressModel.findOne({ + where: { id }, + }); + return handleArrayDaoData(result); }; module.exports.addAddressDao = async function (addressData) { diff --git a/routes/address.js b/routes/address.js index 595c4fc..2a7f64f 100644 --- a/routes/address.js +++ b/routes/address.js @@ -5,6 +5,7 @@ const { addAddressServices, updateAddressServices, deleteAddressServices, + getAddressByIdServices, } = require("../services/addressService"); const { formatResponse } = require("../utils/tools"); diff --git a/services/addressService.js b/services/addressService.js index 8039dbe..4114343 100644 --- a/services/addressService.js +++ b/services/addressService.js @@ -3,6 +3,7 @@ const { addAddressDao, updateAddressDao, deleteAddressDao, + getAddressByIdDao, } = require("../dao/addressDao"); module.exports.getAddressServices = async function (senderId) { @@ -10,7 +11,7 @@ module.exports.getAddressServices = async function (senderId) { }; module.exports.getAddressByIdServices = async function (id) { - return await getAddressByIdDao(id); + return await getAddressByIdDao(+id); }; module.exports.addAddressServices = async function (addressData) { diff --git a/utils/tools.js b/utils/tools.js index cdee465..8424e80 100644 --- a/utils/tools.js +++ b/utils/tools.js @@ -1,37 +1,41 @@ -const jwt = require("jsonwebtoken") -const md5 = require("md5") +const jwt = require("jsonwebtoken"); +const md5 = require("md5"); module.exports.formatResponse = function (code, msg, data) { - return { - code, - msg, - data - } -} + return { + code, + msg, + data, + }; +}; 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) { - let loginPeriod = 1; //默认记住一天 - return jwt.sign(payload, md5(process.env.JWT_SECRET), { - expiresIn: 60 * 60 * 24 * loginPeriod - }) -} + let loginPeriod = 1; //默认记住一天 + return jwt.sign(payload, md5(process.env.JWT_SECRET), { + expiresIn: 60 * 60 * 24 * loginPeriod, + }); +}; module.exports.getRandomExpressId = function () { - return "SF" + Math.floor(Math.random() * 1000000000000) -} + return "SF" + Math.floor(Math.random() * 1000000000000); +}; module.exports.handleArrayDaoData = function (arr) { - const result = [] - // for (const item of arr) { - // result.push(item.dataValues) - // } - //倒叙输出 + const result = []; + // for (const item of arr) { + // result.push(item.dataValues) + // } + //倒叙输出 + if (Array.isArray(arr)) { for (let i = arr.length - 1; i >= 0; i--) { - result.push(arr[i].dataValues) + result.push(arr[i].dataValues); } - return result -} \ No newline at end of file + } else { + result.push(arr.dataValues); + } + return result; +};