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.
uml-task/routes/address.js

46 lines
1.3 KiB

const express = require("express");
const router = express.Router();
const {
getAddressServices,
addAddressServices,
updateAddressServices,
deleteAddressServices,
getAddressByIdServices,
} = require("../services/addressService");
const { formatResponse } = require("../utils/tools");
router.get("/", async function (req, res, next) {
// 从查询参数中获取senderId
const { senderId } = req.query;
const data = await getAddressServices(senderId);
res.send(formatResponse(0, "", data));
});
router.get("/:id", async function (req, res, next) {
const { id } = req.params;
const data = await getAddressByIdServices(id);
if (data) {
res.send(formatResponse(0, "", data));
} else {
res.send(formatResponse(1, "地址不存在", null));
}
});
router.post("/", async function (req, res, next) {
console.log(req, res);
const data = await addAddressServices(req.body);
res.send(formatResponse(0, "", data));
});
router.put("/", async function (req, res, next) {
const data = await updateAddressServices(req.body);
res.send(formatResponse(0, "", data));
});
router.delete("/", async function (req, res, next) {
const data = await deleteAddressServices(req.body);
res.send(formatResponse(0, "", data));
});
module.exports = router;