const router = require('express').Router()
const {MasterModel} = require('./model/master')

router.post('/master',  async (req, res,next) => {

   const {name, phone} =  req.body

   if (!name || !phone ){
        throw new Error('Enter name  and phone')
   }
    try {
        const master =  await MasterModel.create({name, phone})
        res.status(200).send({success: true, body: master})
    } catch (error) {
        next(error)
    }
})



router.get('/masters', async (req, res,next) => {
    try {
        const master = await MasterModel.find({})
        res.status(200).send({success: true, body: master})
    } catch (error) {
        next(error)
    }
})


router.get('/orders', (req, res) => {
    res
        .status(200)
        .send(require(`./json/arm-orders/success.json`))
})

module.exports = router
