feat: add fetch masters and add model

This commit is contained in:
Ильназ 2024-12-15 17:53:45 +03:00
parent a37f7ea8a8
commit 1788f90cde
5 changed files with 150 additions and 10 deletions

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

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