parent
3acbc3a9b9
commit
bf6a9bff1f
@ -0,0 +1,20 @@
|
||||
const {
|
||||
handleArrayDaoData
|
||||
} = require("../utils/tools")
|
||||
const expressModel = require("./model/expressModel")
|
||||
module.exports.getExpressDao = async function () {
|
||||
return handleArrayDaoData(await expressModel.findAll())
|
||||
}
|
||||
module.exports.addExpressDao = async function (expData) {
|
||||
await expressModel.create(expData)
|
||||
return handleArrayDaoData(await expressModel.findAll())
|
||||
}
|
||||
|
||||
module.exports.updateExpressDao = async function (expData) {
|
||||
await expressModel.update(expData, {
|
||||
where: {
|
||||
id: expData.id
|
||||
}
|
||||
})
|
||||
return handleArrayDaoData(await expressModel.findAll())
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
const sequelize = require("../dbConnect")
|
||||
const {
|
||||
DataTypes
|
||||
} = require("sequelize")
|
||||
|
||||
module.exports = sequelize.define("express", {
|
||||
expressId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
senderName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
senderCity: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
receiverName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
receiverCity: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
isSigned: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
signedTime: DataTypes.STRING
|
||||
|
||||
}, {
|
||||
freezeTableName: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
})
|
@ -1,6 +1,27 @@
|
||||
const express = require("express")
|
||||
const router = express.router
|
||||
const router = express.Router()
|
||||
const {
|
||||
getExpressServices,
|
||||
addExpressServices,
|
||||
updateExpressServices
|
||||
} = require("../services/expressService")
|
||||
const {
|
||||
formatResponse
|
||||
} = require("../utils/tools")
|
||||
|
||||
router.
|
||||
router.get("/", async function (req, res, next) {
|
||||
const data = await getExpressServices()
|
||||
res.send(formatResponse(0, "", data))
|
||||
})
|
||||
|
||||
router.post("/", async function (req, res, next) {
|
||||
const data = await addExpressServices(req.body)
|
||||
res.send(formatResponse(0, "", data))
|
||||
})
|
||||
|
||||
router.put("/", async function (req, res, next) {
|
||||
const data = await updateExpressServices(req.body)
|
||||
res.send(formatResponse(0, "", data))
|
||||
})
|
||||
|
||||
module.exports = router
|
@ -0,0 +1,26 @@
|
||||
const {
|
||||
getExpressDao,
|
||||
addExpressDao,
|
||||
updateExpressDao
|
||||
} = require("../dao/expressDao")
|
||||
const {
|
||||
getRandomExpressId
|
||||
} = require("../utils/tools")
|
||||
module.exports.getExpressServices = async function () {
|
||||
return await getExpressDao()
|
||||
}
|
||||
|
||||
module.exports.addExpressServices = async function (expData) {
|
||||
//获取的对象需要补充"expressId", "isSigned"
|
||||
const data = {
|
||||
expressId: getRandomExpressId(),
|
||||
isSigned: 0,
|
||||
...expData,
|
||||
}
|
||||
return await addExpressDao(data)
|
||||
}
|
||||
|
||||
module.exports.updateExpressServices = async function (expData) {
|
||||
//这里需要提供id
|
||||
return await updateExpressDao(expData)
|
||||
}
|
Loading…
Reference in new issue