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.
TimeManager/src/workserver/controllers/team.js

105 lines
2.3 KiB

// 引用团队模版数据
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;