feat: add fetch masters and add model #49

Merged
primakov merged 1 commits from feature/dry-wash-masters into master 2024-12-15 20:02:42 +03:00
5 changed files with 150 additions and 10 deletions
Showing only changes of commit 1788f90cde - Show all commits

View 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

View File

@ -1,15 +1,8 @@
const router = require('express').Router() 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) => { router.use('/arm', armRouter)
res
.status(200)
.send(require(`./json/arm-orders/success.json`))
})
module.exports = router module.exports = router

View 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)

View 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)

View File

@ -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": []
}
]
}
]
}