модель Nodejs
const mongoose = require("mongoose");
const doctorSchema = mongoose.Schema({
name: {
type: String,
require: true,
},
telNumber: {
type: String,
require: true,
},
login: {
type: String,
require: true,
},
parol: {
type: String,
require: true,
}
});
const DoctorModel = mongoose.model('DoctorModel' , doctorSchema)
module.exports = DoctorModel
const DoctorModel = require("./doctor.model");
async function getDoctor(req, res) {
try {
const doctor = await DoctorModel.find({});
res.status(200).send(doctor);
} catch (err) {
res.status(404).send(err);
}
}
async function addDoctor(req, res) {
try {
let doctor = await DoctorModel.create(req.body);
return res.status(200).send(doctor);
} catch (err) {
return res.status(400).send(err);
}
}
async function updateDoctor(req, res){
try{
let doctorId = req.params.id
let result = await DoctorModel.findByIdAndUpdate(doctorId, req.body)
return res.status(200).send(result)
} catch(err){
res.status(400).send(err)
}
}
async function deleteDoctor(req, res){
try{
let doctorId = req.params.id
let result = await DoctorModel.findByIdAndRemove(doctorId)
return res.status(200).send(result)
} catch(err){
res.status(400).send(err)
}
}
module.exports = {
getDoctor,
addDoctor,
updateDoctor,
deleteDoctor,
};
const express = require('express')
const router = express.Router()
const doctorController = require('./doctor.controller')
// get
router.route('/').get(doctorController.getDoctor)
// post
router.route('/').post(doctorController.addDoctor)
// put
router.route('/:id').put(doctorController.updateDoctor)
// delete
router.route('/:id').delete(doctorController.deleteDoctor)
module.exports = router
const express = require('express')
const router = express.Router()
const doctorRouter = require('./doctor/doctor.router');
const clientRouter = require('./clients/client.router');
const servicesRouter = require('./services/services.router');
router.use('/doctor' , doctorRouter);
router.use('/client' , clientRouter);
router.use('/services', servicesRouter);
router.use('/uploads',express.static((__dirname,"uploads")))
module.exports = router
const express = require('express')
const app = express()
const mongoose = require('mongoose')
const cors = require('cors')
const appRouter = require('./router')
app.use(express.json())
app.use(cors())
mongoose.connect("mongodb://localhost/tishbaza" ,
{
useNewUrlParser:true ,
useUnifiedTopology:true
}
)
.then(() => {
console.log('Bazaga ulandi')
})
.catch((err)=> {
console.log('Bazaga ulanishda hato')
})
app.use('/' , appRouter)
const port = process.env.PORT || 5001
app.listen(port , () => {
console.log(`${port}chi port ishga tushdi`)
})
Akmal