aihua
parent
610538d5bf
commit
a76da18d62
@ -0,0 +1,104 @@
|
||||
// 引用团队模版数据
|
||||
const Team = require('../model/team');
|
||||
|
||||
const teamController = {
|
||||
// showTeam 获取团队数据并返回到页面
|
||||
showTeam: async function(req,res,next){
|
||||
try{
|
||||
let teamData;
|
||||
if(req.body.id){
|
||||
console.log(req.body.id)
|
||||
teamData= await Team.getById('id',req.body.id)
|
||||
}else{
|
||||
teamData = await Team.all()
|
||||
}
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "操作成功",
|
||||
data: teamData
|
||||
})
|
||||
}catch(e){
|
||||
res.json({ code: 0, message: "操作失败", data: e })
|
||||
}
|
||||
},
|
||||
// 新增团队
|
||||
addTeam: async function(req, res, next) {
|
||||
try {
|
||||
const teamData = req.body; // 从请求中获取团队数据
|
||||
|
||||
const result = await Team.insert(teamData);
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "团队添加成功",
|
||||
data: result
|
||||
});
|
||||
} catch (e) {
|
||||
res.json({
|
||||
code: 0,
|
||||
message: "团队添加失败",
|
||||
data: e
|
||||
});
|
||||
}
|
||||
},
|
||||
// 修改团队
|
||||
updateTeam: async function(req, res, next) {
|
||||
try {
|
||||
const teamId = req.body.id; // Assuming the team ID is passed as a parameter
|
||||
const teamData = req.body; // Updated team data
|
||||
console.log(teamId + " & " + JSON.stringify(teamData));
|
||||
const result = await Team.update(teamId, teamData); // Use an appropriate function to update the team
|
||||
if (result) {
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "团队修改成功",
|
||||
data: result
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
code: 404,
|
||||
message: "团队不存在",
|
||||
data: null
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
res.json({
|
||||
code: 0,
|
||||
message: "团队修改失败",
|
||||
data: e
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 删除团队
|
||||
deleteTeam: async function(req, res, next) {
|
||||
try {
|
||||
const teamId = req.body.id; // Assuming the team ID is passed as a parameter
|
||||
const result = await Team.delete(teamId); // Use an appropriate function to delete the team
|
||||
if (result) {
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "团队删除成功",
|
||||
data: result
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
code: 404,
|
||||
message: "团队不存在",
|
||||
data: null
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
res.json({
|
||||
code: 0,
|
||||
message: "团队删除失败",
|
||||
data: e
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = teamController;
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
|
||||
const Work = require('../model/work');
|
||||
|
||||
const workController = {
|
||||
// showWork 获取工作数据并返回到页面
|
||||
showWork: async function(req,res,next){
|
||||
try{
|
||||
let workData;
|
||||
if(req.body.id){
|
||||
console.log(req.body.id)
|
||||
workData= await Work.getById('id',req.body.id)
|
||||
}else{
|
||||
workData = await Work.all()
|
||||
}
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "操作成功",
|
||||
data: workData
|
||||
})
|
||||
}catch(e){
|
||||
res.json({ code: 0, message: "操作失败", data: e })
|
||||
}
|
||||
},
|
||||
// 新增工作
|
||||
addWork: async function(req, res, next) {
|
||||
try {
|
||||
const workData = req.body; // 从请求中获取工作数据
|
||||
|
||||
const result = await Work.insert(workData);
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "工作添加成功",
|
||||
data: result
|
||||
});
|
||||
} catch (e) {
|
||||
res.json({
|
||||
code: 0,
|
||||
message: "工作添加失败",
|
||||
data: e
|
||||
});
|
||||
}
|
||||
},
|
||||
// 修改工作
|
||||
updateWork: async function(req, res, next) {
|
||||
try {
|
||||
const workId = req.body.id; // Assuming the work ID is passed as a parameter
|
||||
const workData = req.body; // Updated work data
|
||||
console.log(workId + " & " + JSON.stringify(workData));
|
||||
const result = await Work.update(workId, workData); // Use an appropriate function to update the work
|
||||
if (result) {
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "工作修改成功",
|
||||
data: result
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
code: 404,
|
||||
message: "工作不存在",
|
||||
data: null
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
res.json({
|
||||
code: 0,
|
||||
message: "工作修改失败",
|
||||
data: e
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 删除工作
|
||||
deleteWork: async function(req, res, next) {
|
||||
try {
|
||||
const workId = req.body.id; // Assuming the work ID is passed as a parameter
|
||||
const result = await Work.delete(workId); // Use an appropriate function to delete the work
|
||||
if (result) {
|
||||
res.json({
|
||||
code: 200,
|
||||
message: "工作删除成功",
|
||||
data: result
|
||||
});
|
||||
} else {
|
||||
res.json({
|
||||
code: 404,
|
||||
message: "工作不存在",
|
||||
data: null
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
res.json({
|
||||
code: 0,
|
||||
message: "工作删除失败",
|
||||
data: e
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = workController;
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
const Base = require('./base');
|
||||
|
||||
class Team extends Base {
|
||||
// 定义参数默认值为 team 表
|
||||
constructor(props = 'teams'){
|
||||
super(props);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Team();
|
||||
@ -0,0 +1,10 @@
|
||||
const Base = require('./base');
|
||||
|
||||
class Work extends Base {
|
||||
// 定义参数默认值为 team 表
|
||||
constructor(props = 'works'){
|
||||
super(props);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Work();
|
||||
@ -1,11 +1,38 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
const userController = require('../controllers/user');
|
||||
|
||||
|
||||
const teamController = require('../controllers/team');
|
||||
const workController = require('../controllers/work');
|
||||
// 获取用户信息
|
||||
router.get('/get_user', userController.showUser);
|
||||
|
||||
router.post('/add_user', userController.addUser);
|
||||
|
||||
router.post('/update_user', userController.updateUser);
|
||||
|
||||
router.post('/delete_user', userController.deleteUser);
|
||||
//团队
|
||||
router.get('/get_team', teamController.showTeam);
|
||||
|
||||
router.post('/add_team', teamController.addTeam);
|
||||
|
||||
router.post('/update_team', teamController.updateTeam);
|
||||
|
||||
router.post('/delete_team', teamController.deleteTeam);
|
||||
//工作
|
||||
|
||||
router.get('/get_work', workController.showWork);
|
||||
|
||||
router.post('/add_work', workController.addWork);
|
||||
|
||||
router.post('/update_work', workController.updateWork);
|
||||
|
||||
router.post('/delete_work', workController.deleteWork);
|
||||
// 注册用户
|
||||
router.post('/register', userController.register);
|
||||
|
||||
// 用户登录
|
||||
router.post('/login', userController.login);
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Loading…
Reference in new issue