forked from bro-students/multy-stub
feat: add fetch masters and add model
This commit is contained in:
parent
a37f7ea8a8
commit
1788f90cde
37
server/routers/dry-wash/arm.js
Normal file
37
server/routers/dry-wash/arm.js
Normal file
@ -0,0 +1,37 @@
|
||||
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,15 +1,8 @@
|
||||
const router = require('express').Router()
|
||||
const armRouter = require('./arm')
|
||||
|
||||
router.get('/arm/masters', (req, res) => {
|
||||
res
|
||||
.status(200)
|
||||
.send(require("./json/arm-masters/success.json"))
|
||||
})
|
||||
|
||||
router.get('/arm/orders', (req, res) => {
|
||||
res
|
||||
.status(200)
|
||||
.send(require(`./json/arm-orders/success.json`))
|
||||
})
|
||||
router.use('/arm', armRouter)
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
20
server/routers/dry-wash/model/master.js
Normal file
20
server/routers/dry-wash/model/master.js
Normal file
@ -0,0 +1,20 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const schema = new Schema({
|
||||
name: {type: String, required: true},
|
||||
phone: {type: String, required: true,unique: true,},
|
||||
created: {
|
||||
type: Date, default: () => new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
})
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
exports.MasterModel = model('dry-wash-master', schema)
|
30
server/routers/dry-wash/model/order.js
Normal file
30
server/routers/dry-wash/model/order.js
Normal file
@ -0,0 +1,30 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const schema = new Schema({
|
||||
startWashTime: {type: String, required: true},
|
||||
endWashTime: {type: String, required: true},
|
||||
orderDate: {type: String, required: true},
|
||||
location: {type: String, required: true},
|
||||
phone: {type: String, required: true},
|
||||
status: {type: String, required: true},
|
||||
carNumber: {type: String, required: true},
|
||||
created: {
|
||||
type: Date, default: () => new Date().toISOString(),
|
||||
},
|
||||
updated: {
|
||||
type: Date, default: () => new Date().toISOString(),
|
||||
},
|
||||
master: {type: Schema.Types.ObjectId, ref: 'dry-wash-master'},
|
||||
notes: String,
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
})
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
exports.OrderModel = model('dry-wash-order', schema)
|
@ -0,0 +1,60 @@
|
||||
{
|
||||
"info": {
|
||||
"_postman_id": "e91fbcf7-3c7b-420d-a49e-4dbb6199c14a",
|
||||
"name": "dry-wash",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||
"_exporter_id": "27705820"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "arm",
|
||||
"item": [
|
||||
{
|
||||
"name": "create master",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\":\"Anton\",\n \"phone\": \"89172420577\"\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{host}}/arm/master",
|
||||
"host": [
|
||||
"{{host}}"
|
||||
],
|
||||
"path": [
|
||||
"arm",
|
||||
"master"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "get masters",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{host}}/arm/masters",
|
||||
"host": [
|
||||
"{{host}}"
|
||||
],
|
||||
"path": [
|
||||
"arm",
|
||||
"masters"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user