diff --git a/webserve/app.js b/webserve/app.js index c8d9d0d0f2f8a43cdf1da58799e6a33d8a82eda8..c8836b9772eeed07214f79ef86b4813bdd9b134c 100644 --- a/webserve/app.js +++ b/webserve/app.js @@ -6,8 +6,10 @@ var logger = require('morgan'); var cors = require('cors') var indexRouter = require('./routes/index'); var usersRouter = require('./routes/users'); +let szhRouter = require('./routes/szh'); var app = express(); +app.use(cors()); // view engine setup app.set('views', path.join(__dirname, 'views')); @@ -21,6 +23,7 @@ app.use(express.static(path.join(__dirname, 'public'))); app.use('/', indexRouter); app.use('/users', usersRouter); +app.use('/szh',szhRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/webserve/model/db.js b/webserve/model/db.js index 5d6c9ca230b4934554f15c44b5491e629a49d934..559a4c8b08af681ba74b5c03d7bebc9dcfaa198d 100644 --- a/webserve/model/db.js +++ b/webserve/model/db.js @@ -1,8 +1,8 @@ const mongoose = require("mongoose") -mongoose.connect("mongodb://127.0.0.1:27017/库名").then(() => { +mongoose.connect("mongodb+srv://2968289424:Mf6aDRKrXDBc1m5p@cluster0.3o4hkpp.mongodb.net/zhihui_three").then(() => { console.log("mongodb connect ok!"); }).catch((err) => { console.log("err: ", err) }) -module.exports = mongoose \ No newline at end of file +module.exports = mongoose; \ No newline at end of file diff --git a/webserve/model/model.js b/webserve/model/model.js index f6f519984131cfd4adcddcdf6483f37a8732a0a9..4543f389a1e9cb2521d1010d25d208718a213d7f 100644 --- a/webserve/model/model.js +++ b/webserve/model/model.js @@ -1 +1,18 @@ -const mongoose = require('./db') +const mongoose = require('./db'); + +let carRegisterSchema = new mongoose.Schema({ + name: String, //司机名称 + phone: String, //司机电话 + code: String, //洗车编号 + carmark: String, //车牌号 + time: Date, //开始洗车时间 + etime: Date, //结束洗车时间 + type: Number, //洗车类型 + price: Number, //洗车价格 +}) + +let carRegisterModel = mongoose.model('carRegister', carRegisterSchema, 'carRegister') + +module.exports = { + carRegisterModel +} diff --git a/webserve/routes/szh/index.js b/webserve/routes/szh/index.js new file mode 100644 index 0000000000000000000000000000000000000000..7c290c993d09e0da2ec5231a7a86eb99f174d9e8 --- /dev/null +++ b/webserve/routes/szh/index.js @@ -0,0 +1,36 @@ +var express = require("express"); +const { carRegisterModel } = require("../../model/model"); +var router = express.Router(); + +router.get("/carRegister", async (req, res) => { + let { name, phone, code, catmark, time, type } = req.query; + let SearchValue = [{}]; + if (name) SearchValue.push({ name: RegExp(name) }); + let list = await carRegisterModel.find(); + res.send({ + code: 200, + list: list, + msg: "查询成功", + }); +}); + +router.post('/addRegister',(req,res)=>{ + let obj = req.body; + carRegisterModel.create(obj); + console.log(obj); + res.send({ + code:200, + msg:'添加成功' + }) +}); + +router.delete('/deleteRegister',async (req,res)=>{ + let id = req.query.id; + await carRegisterModel.deleteOne({_id:id}); + res.send({ + code:200, + msg:'删除成功' + }) +}) + +module.exports = router;