Skip to content

Commit

Permalink
Se crea addProductForDelivery para guardar en la base de datos
Browse files Browse the repository at this point in the history
  • Loading branch information
Camilocsr committed Jul 7, 2024
1 parent 365cc22 commit 740f307
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const bodyParser = require('body-parser');
const cors = require('cors');
const productsRoutes = require('./routes/product');
const adminRoutes = require('./routes/admin');
const delivery = require('./routes/productsDelvery');

app = express();// creo la app express.

Expand All @@ -14,5 +15,6 @@ app.use(bodyParser.json())
app.use('/public',express.static(`${__dirname}/storage/imgs`));//direccion falsa la cual le aparecera al cliente.
app.use('/v1',productsRoutes);
app.use('/v1',adminRoutes);
app.use('/v1',delivery);

module.exports = app;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const productsWithDelivery = require('../../../models/productsWithDelivery.js');

async function addProductForDelivery(req, res) {
try {
const {
nameClient,
numberContact,
email,
address,
description,
numberProducts,
productsList,
delivery
} = req.body;

const newProduct = new productsWithDelivery({
nameClient,
numberContact,
email,
address,
description,
numberProducts,
productsList,
delivery
});

const productStored = await newProduct.save();

res.status(200).send({ productStored });
} catch (error) {
res.status(500).send({ message: error.message });
}
}

module.exports = { addProductForDelivery };
38 changes: 34 additions & 4 deletions Backend/models/productsWithDelivery.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const ProductListSchema = new Schema({
tipo: {
type: String,
required: true,
},
cantidad: {
type: Number,
required: true,
},
talla: {
type: String,
required: true,
},
Genero: {
type: String,
required: true,
},
ValorUnitario: {
type: Number,
required: true,
},
SumaDeLaCantidad: {
type: Number,
required: true,
},
});

const ProductSchema = new Schema({
nameClient: {
type: String,
required: true
required: true,
},
numberContact: {
type: String,
Expand All @@ -26,13 +53,16 @@ const ProductSchema = new Schema({
type: Number,
required: true,
},
productsList: [String],
productsList: {
type: [ProductListSchema],
required: true,
},
delivery: {
type: Boolean,
default: false
default: false,
},
}, {
timestamps: true
});

module.exports = mongoose.model('Product', ProductSchema);
module.exports = mongoose.model('ProductWithDelivery', ProductSchema);
7 changes: 7 additions & 0 deletions Backend/routes/productsDelvery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const express = require('express');
const { addProductForDelivery } = require('../controllers/products/productsWthDelivery/addProductsDelivery.js');
const api = express.Router();

api.post('/Delivery', addProductForDelivery)

module.exports = api;

0 comments on commit 740f307

Please sign in to comment.