Compare commits
2 Commits
a520692bc5
...
b3fd86da33
Author | SHA1 | Date | |
---|---|---|---|
b3fd86da33 | |||
276ef4033b |
87
server/routers/dry-wash/arm-master.js
Normal file
87
server/routers/dry-wash/arm-master.js
Normal file
@ -0,0 +1,87 @@
|
||||
const router = require('express').Router()
|
||||
const {MasterModel} = require('./model/master')
|
||||
const mongoose = require("mongoose")
|
||||
|
||||
|
||||
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.delete('/masters/:id', async (req, res,next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)){
|
||||
throw new Error('ID is required')
|
||||
}
|
||||
|
||||
try {
|
||||
const master = await MasterModel.findByIdAndDelete(id, {
|
||||
new: true,
|
||||
});
|
||||
if (!master) {
|
||||
throw new Error('master not found')
|
||||
}
|
||||
res.status(200).send({success: true, body: master})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
router.post('/masters', 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.patch('/masters/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
throw new Error('ID is required')
|
||||
}
|
||||
|
||||
const { name, phone } = req.body;
|
||||
|
||||
if (!name && !phone) {
|
||||
throw new Error('Enter name and phone')
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const updateData = {};
|
||||
if (name) updateData.name = name;
|
||||
if (phone) updateData.phone = phone;
|
||||
|
||||
const master = await MasterModel.findByIdAndUpdate(
|
||||
id,
|
||||
updateData,
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
if (!master) {
|
||||
throw new Error('master not found')
|
||||
}
|
||||
|
||||
res.status(200).send({ success: true, body: master });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router
|
9
server/routers/dry-wash/arm-orders.js
Normal file
9
server/routers/dry-wash/arm-orders.js
Normal file
@ -0,0 +1,9 @@
|
||||
const router = require('express').Router()
|
||||
|
||||
router.get('/orders', (req, res) => {
|
||||
res
|
||||
.status(200)
|
||||
.send(require(`./json/arm-orders/success.json`))
|
||||
})
|
||||
|
||||
module.exports = router
|
@ -1,37 +0,0 @@
|
||||
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
|
@ -1,8 +1,10 @@
|
||||
const router = require('express').Router()
|
||||
const armRouter = require('./arm')
|
||||
const armMasterRouter = require('./arm-master')
|
||||
const armOrdersRouter = require('./arm-orders')
|
||||
|
||||
|
||||
router.use('/arm', armRouter)
|
||||
router.use('/arm', armMasterRouter)
|
||||
router.use('/arm', armOrdersRouter)
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
@ -16,7 +16,7 @@
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\":\"Anton\",\n \"phone\": \"89172420577\"\n}",
|
||||
"raw": "{\n \"name\":\"Anto234\",\n \"phone\": \"89172420577\"\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
@ -42,13 +42,60 @@
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{host}}/arm/masters",
|
||||
"raw": "{{host}}/arm/master-list",
|
||||
"host": [
|
||||
"{{host}}"
|
||||
],
|
||||
"path": [
|
||||
"arm",
|
||||
"masters"
|
||||
"master-list"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "delete master",
|
||||
"request": {
|
||||
"method": "DELETE",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{host}}/arm/masters/{{id}}",
|
||||
"host": [
|
||||
"{{host}}"
|
||||
],
|
||||
"path": [
|
||||
"arm",
|
||||
"masters",
|
||||
"{{id}}"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "update master",
|
||||
"request": {
|
||||
"method": "PATCH",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\":\"Anto234\",\n \"phone\": \"89172420577\"\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{host}}/arm/masters/{{id}}",
|
||||
"host": [
|
||||
"{{host}}"
|
||||
],
|
||||
"path": [
|
||||
"arm",
|
||||
"masters",
|
||||
"{{id}}"
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -57,4 +104,4 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user