diff --git a/feature/contact/controller/contact.controller.js b/feature/contact/controller/contact.controller.js new file mode 100644 index 0000000..f338853 --- /dev/null +++ b/feature/contact/controller/contact.controller.js @@ -0,0 +1,69 @@ +const ContactModel= require('../model/contact.model') + +//getAll : + +module.exports.getAll =(async(req,res)=>{ + const contacts= await ContactModel.find({}) + res.status(200).json({success: true, data: contacts}); +}) + + +//getById : + +module.exports.getById= (async(req,res)=>{ + const contact= await ContactModel.findById(req.params.id) + if(!contact){ + res.status(200).json({success: false,data: "NoData"}); + return; + } + res.status(200).json({success: true, data: contact}) +}) + + +//getOne : + +module.exports.getOne= (async(req,res)=>{ + const contact= await ContactModel.findOne({lastname: req.params.lastname}); + if(!contact){ + res.status(200).json({success: false,data: "NoData"}); + return; + } + res.status(200).json({success: true,data: contact}); +}) + + +//create : + +module.exports.create= (async(req,res)=>{ + let contact= req.body + contact= await ContactModel.create(contact); + res.status(200).json({success: true,data: contact}) +}) + + +//update : + +module.exports.update= async(req,res)=>{ + let contact= await ContactModel.findById(req.params.id); + if(!contact){ + res.status(200).json({success:false,data: "NoData"}) + return + } + await ContactModel.updateOne({_id: req.params.id},req.body) + contact= await ContactModel.findById(req.params.id) + res.status(200).json({success: true,data: contact}) +} + + +//delete : + +module.exports.delete= (async(req,res)=>{ + let contact= await contactModel.find({}) + if(!contact){ + res.status(200).json({sucess: false,data: "NoData"}) + return + } + await contactModel.deleteOne(req.params.id) + res.status(200).json({success: true, data: {}}) +}) + diff --git a/feature/contact/model/contact.model.js b/feature/contact/model/contact.model.js new file mode 100644 index 0000000..d04d8e0 --- /dev/null +++ b/feature/contact/model/contact.model.js @@ -0,0 +1,42 @@ +const mongoose = require('mongoose'); +const schema = new mongoose.Schema({ + codeObject: String, + lastname: { + type: String, + require: true, + maxLength: 70, + minLength: 2, + default: "" + }, + firstname: { + type: String, + require: true, + maxLength: 70, + default: "" + }, + phone: { + type: String, + require: true, + maxLength: 20, + default: "" + }, + mail: { + type: String, + require: true, + default: "" + }, + vehicle: { + type: mongoose.Schema.ObjectId, + ref: 'vehicle' + }, + status: String, + createdBy: { + type: String, + ref: 'user' + } +}, + { + timestamps:true + }) + +module.exports= mongoose.model('contact',schema) \ No newline at end of file diff --git a/feature/contact/route/contact.route.js b/feature/contact/route/contact.route.js new file mode 100644 index 0000000..1ea0368 --- /dev/null +++ b/feature/contact/route/contact.route.js @@ -0,0 +1,30 @@ +const contactController= require('../controller/contact.controller') + +const router= require('express').Router() + +//getAll : + +router.route('/').get(contactController.getAll) + +//getById : + +router.route('/:id').get(contactController.getById) + + +//getOne : + +router.route('/lastname/:lastname').get(contactController.getOne) + + +//create : + +router.route('/').post(contactController.create) + +//update : +router.route('/:id').put(contactController.update) + +//delete : + +router.route('/:id').delete(contactController.delete) + +module.exports=router; \ No newline at end of file diff --git a/feature/problem/controller/problem.controller.js b/feature/problem/controller/problem.controller.js new file mode 100644 index 0000000..6a7cbea --- /dev/null +++ b/feature/problem/controller/problem.controller.js @@ -0,0 +1,69 @@ +const ProblemModel= require('../model/problem.model') + +//getAll : + +module.exports.getAll =(async(req,res)=>{ + const problems= await ProblemModel.find({}); + res.status(200).json({success: true, data: problems}); +}) + + +//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 + } + await ProblemModel.deleteOne(req.params.id) + res.status(200).json({success: true, data: {}}) +}) + diff --git a/feature/problem/model/problem.model.js b/feature/problem/model/problem.model.js new file mode 100644 index 0000000..98004fb --- /dev/null +++ b/feature/problem/model/problem.model.js @@ -0,0 +1,36 @@ +const mongoose= require('mongoose') + +const schema= new mongoose.Schema({ + codeObject: String, + description: { + type: String, + default: "" + }, + date: { + type: Date, + default: "" + }, + state: { + type: String, + default: "" + }, + status: { + type: String, + default: "" + }, + vehicle: { + type: mongoose.Schema.ObjectId, + ref: 'vehicle' + }, + createdBy: { + type: mongoose.Schema.ObjectId, + ref: 'user' + } + + +}, + { + timestamps: true + }) + +module.exports=mongoose.model('problem',schema) \ No newline at end of file diff --git a/feature/problem/route/problem.route.js b/feature/problem/route/problem.route.js new file mode 100644 index 0000000..4f7df49 --- /dev/null +++ b/feature/problem/route/problem.route.js @@ -0,0 +1,31 @@ +const problemController= require('../controller/problem.controller') + +const router= require('express').Router() + +//getAll : + +router.route('/').get(problemController.getAll) + +//getById : + +router.route('/:id').get(problemController.getById) + + +//getOne : + +router.route('/lastname/:lastname').get(problemController.getOne) + + +//create : + +router.route('/').post(problemController.create) + +//update : +router.route('/:id').put(problemController.update) + +//delete : + +router.route('/:id').delete(problemController.delete) + +module.exports=router; + diff --git a/server.js b/server.js index 4bb9172..e4f4ed8 100644 --- a/server.js +++ b/server.js @@ -15,6 +15,15 @@ app.use(cors()); const vehicleRoute = require("./feature/vehicle/route/vehicle.route"); app.use("/vehicle", vehicleRoute); +//route contact : +const contactRoute= require('./feature/contact/route/contact.route') +app.use("/contact",contactRoute) + +//route problem : + +const problemRoute= require('./feature/problem/route/problem.route') +app.use("/problem",problemRoute) + const server = app.listen(5000, ()=>{ console.log('Vous êtés connecter au port 5000'.yellow.bold); })