Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

model 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`)
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript loop over three-dimensional array 
Javascript :: how to create onclick event on css class js 
Javascript :: getattribute javascript 
Javascript :: how to check if input is string javascript 
Javascript :: find an object from array of objects javascript 
Javascript :: prevent duplicate entries in javascript array 
Javascript :: javascript convert timezone name to abbreviation 
Javascript :: how to make a github api using react 
Javascript :: js entries 
Javascript :: capitalize first letter of each word 
Javascript :: use $ instead of jQuery 
Javascript :: javascript detectar la pagina 
Javascript :: js store regex in variable and combine 
Javascript :: socket emit to specific room using nodejs socket.io 
Javascript :: check a date is between two dates in javascript 
Javascript :: javascript get tag child elements 
Javascript :: react semantic button 
Javascript :: js string explode 
Javascript :: regx to accept name 
Javascript :: react native text align vertical center 
Javascript :: jquery remove multiple class 
Javascript :: getting values for metaboxes in wordpress 
Javascript :: ajax is not a function 
Javascript :: populate example in mongoose 
Javascript :: storybook react router 
Javascript :: feet to cm javascript 
Javascript :: react-bootstrap problem-install new version 
Javascript :: change image onclick js 
Javascript :: how to make a check if letters are capital in discord js 
Javascript :: how to read json file with file input html 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =