From 7df83001ca74952ba58094048b178b545ef50fca Mon Sep 17 00:00:00 2001 From: shenzh <3584554312@qq.com> Date: Wed, 27 Nov 2024 11:30:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webserve/app.js | 3 +++ webserve/model/db.js | 4 ++-- webserve/model/model.js | 19 ++++++++++++++++++- webserve/routes/szh/index.js | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 webserve/routes/szh/index.js diff --git a/webserve/app.js b/webserve/app.js index c8d9d0d..c8836b9 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 5d6c9ca..559a4c8 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 f6f5199..4543f38 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 0000000..7c290c9 --- /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; -- Gitee