coryas-formation-api/feature/problem/controller/problem.controller.js

70 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2024-08-20 17:18:34 +00:00
const ProblemModel= require('../model/problem.model')
//getAll :
module.exports.getAll =(async(req,res)=>{
2024-08-22 11:09:30 +00:00
// const problems= await ProblemModel.find({});
res.status(200).json(res.advancedResults);
2024-08-20 17:18:34 +00:00
})
//getById :
module.exports.getById= (async(req,res)=>{
const problem= await ProblemModel.findById(req.params.id)
if(!problem){
res.status(200).json({success: false,data: "NoData"});
return;
}
res.status(200).json({success: true, data: problem})
})
//getOne :
module.exports.getOne= (async(req,res)=>{
const problem= await ProblemModel.findOne({lastname: req.params.lastname});
if(!problem){
res.status(200).json({success: false,data: "NoData"});
return;
}
res.status(200).json({success: true,data: problem});
})
//create :
module.exports.create= (async(req,res)=>{
let problem= req.body
problem= await ProblemModel.create(problem);
res.status(200).json({success: true,data: problem})
})
//update :
module.exports.update= (async(req,res)=>{
let problem= await ProblemModel.findById(req.params.id);
if(!problem){
res.status(200).json({success:false,data: "NoData"})
return
}
await ProblemModel.updateOne({_id: req.params.id},req.body)
problem= await ProblemModel.findById(req.params.id)
res.status(200).json({success: true,data: problem})
})
//delete :
module.exports.delete= (async(req,res)=>{
let problem= await ProblemModel.find({})
if(!problem){
res.status(200).json({success: false,data: "NoData"})
return
}
2024-08-22 11:09:30 +00:00
await ProblemModel.deleteOne({_id: req.params.id})
2024-08-20 17:18:34 +00:00
res.status(200).json({success: true, data: {}})
})