diff --git a/server/routers/dry-wash/arm.js b/server/routers/dry-wash/arm.js new file mode 100644 index 0000000..e0a00e8 --- /dev/null +++ b/server/routers/dry-wash/arm.js @@ -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 diff --git a/server/routers/dry-wash/index.js b/server/routers/dry-wash/index.js index 4f4b95f..e9f1aaf 100644 --- a/server/routers/dry-wash/index.js +++ b/server/routers/dry-wash/index.js @@ -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 diff --git a/server/routers/dry-wash/model/master.js b/server/routers/dry-wash/model/master.js new file mode 100644 index 0000000..bf718df --- /dev/null +++ b/server/routers/dry-wash/model/master.js @@ -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) diff --git a/server/routers/dry-wash/model/order.js b/server/routers/dry-wash/model/order.js new file mode 100644 index 0000000..deb0c10 --- /dev/null +++ b/server/routers/dry-wash/model/order.js @@ -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) diff --git a/server/routers/dry-wash/postman/dry-wash.postman_collection.json b/server/routers/dry-wash/postman/dry-wash.postman_collection.json new file mode 100644 index 0000000..685bf02 --- /dev/null +++ b/server/routers/dry-wash/postman/dry-wash.postman_collection.json @@ -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": [] + } + ] + } + ] +}