commit
16f7fb4d62
46 changed files with 4189 additions and 0 deletions
@ -0,0 +1,2 @@ |
|||
LOCAL=192.168.1.18 |
|||
DB=mongodb://192.168.1.18:27017/fanstock |
|||
@ -0,0 +1,5 @@ |
|||
FROM node:latest |
|||
WORKDIR /app |
|||
COPY . . |
|||
RUN npm install |
|||
CMD ["node","server.js"] |
|||
@ -0,0 +1,93 @@ |
|||
//Mock de base de datos
|
|||
const store = require("./store"); |
|||
|
|||
//Conexión por websockets
|
|||
const { socket } = require('../../socket'); |
|||
|
|||
function addCategory(name, products, description) { |
|||
return new Promise((resolve, reject) => { |
|||
if (!name || !description) { |
|||
console.error("[messageController]: No hay usuario o mensaje!"); |
|||
reject("Los datos son incorrectos!"); |
|||
} |
|||
const fullCategory = { |
|||
name: name, |
|||
products: products, |
|||
description: description, |
|||
statusDB: true, |
|||
}; |
|||
|
|||
store.add(fullCategory); |
|||
|
|||
socket.io.emit('listenCategories', fullCategory); |
|||
|
|||
resolve(fullCategory); |
|||
}); |
|||
} |
|||
|
|||
function getCategories(filterCategory) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.list(filterCategory)); |
|||
}); |
|||
} |
|||
|
|||
function pushProduct(newProduct) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.push(newProduct)); |
|||
}); |
|||
} |
|||
|
|||
// add product to Provider
|
|||
function addProductToCategory(idCategory, productId) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.addProductToCategory(idCategory, productId)); |
|||
}); |
|||
} |
|||
|
|||
//assign category
|
|||
function assignCategory(id, idProvider) { |
|||
console.log("ver"); |
|||
console.log(id); |
|||
console.log(idProvider); |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id || !idProvider) { |
|||
reject("Revisar datos"); |
|||
} |
|||
|
|||
const result = await store.assignCategory(id, idProvider); |
|||
resolve(result); |
|||
}); |
|||
} |
|||
|
|||
// function updateProvider(id, message) {
|
|||
// return new Promise(async (resolve, reject) => {
|
|||
// console.log(id)
|
|||
// console.log(message)
|
|||
// if(!id || !message){
|
|||
// reject('Invalid data')
|
|||
// return false
|
|||
// }
|
|||
// const result = await store.updateText(id, message);
|
|||
// resolve(result);
|
|||
// })
|
|||
// }
|
|||
|
|||
// function deleteProvider(id) {
|
|||
// return new Promise(async (resolve, reject) => {
|
|||
// if (!id) {
|
|||
// reject ('Id inválido')
|
|||
// }
|
|||
|
|||
// resolve(store.remove(id));
|
|||
// });
|
|||
// }
|
|||
|
|||
module.exports = { |
|||
addCategory, |
|||
getCategories, |
|||
pushProduct, |
|||
addProductToCategory, |
|||
assignCategory |
|||
// updateProvider,
|
|||
// deleteProvider,
|
|||
}; |
|||
@ -0,0 +1,29 @@ |
|||
//En este modulo se declara la estructura de los datos que ingresaran a la BD
|
|||
|
|||
const mongoose = require('mongoose'); |
|||
|
|||
const Schema = mongoose.Schema; |
|||
|
|||
const mySchema = new Schema({ |
|||
name: { |
|||
type: String, |
|||
//required: true
|
|||
}, |
|||
products: [{ |
|||
type: Schema.ObjectId, |
|||
ref: 'Supply', |
|||
|
|||
//En referencia se coloca el nombre del esquema al cual queremos acceder
|
|||
}], |
|||
statusDB: { |
|||
type: Boolean, |
|||
required: true |
|||
}, |
|||
description: { |
|||
type: String |
|||
} |
|||
|
|||
}); |
|||
|
|||
const model = mongoose.model('Categories', mySchema); |
|||
module.exports = model; |
|||
@ -0,0 +1,93 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
//Response
|
|||
const response = require("../../network/response"); |
|||
|
|||
//Agrega controlador
|
|||
const controller = require("./controller"); |
|||
|
|||
//redirecciona a metodo GET
|
|||
app.get("/", async function (req, res) { |
|||
try { |
|||
const filterCategories = req.query.id || null; |
|||
const categoryList = await controller.getCategories(filterCategories); |
|||
response.success(req, res, categoryList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
//redirecciona a metodo POST
|
|||
app.post("/", async (req, res) => { |
|||
try { |
|||
const fullCategories = await controller.addCategory( |
|||
req.body.name, |
|||
req.body.products, |
|||
req.body.description |
|||
); |
|||
response.success(req, res, fullCategories, 201); |
|||
} catch (error) { |
|||
console.log(res); |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
// push product id to provider
|
|||
app.put("/:id", async (req, res) => { |
|||
try { |
|||
const categoryId = req.params.id; |
|||
const productId = req.body.productId; |
|||
const result = await controller.addProductToCategory(categoryId, productId); |
|||
response.success(req, res, result, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
// assign provider
|
|||
app.patch("/assign/:id", async (req, res) => { |
|||
controller |
|||
.addProductToCategory(req.params.id, req.body.productId) |
|||
.then((data) => { |
|||
const message = `La categoría ${req.body.productId} fue agregado`; |
|||
response.success(req, res, message, 200); |
|||
}) |
|||
.catch((err) => { |
|||
response.error(req, res, err, 500); |
|||
}); |
|||
}); |
|||
|
|||
// app.put('/', async (req, res) => {
|
|||
// try{
|
|||
// const fullProvider = await controller.pushProduct(req.body.products);
|
|||
|
|||
// response.success(req, res, fullProvider, 201);
|
|||
// }catch(error){
|
|||
// console.log(res)
|
|||
// response.error(req, res, error, 401);
|
|||
// }
|
|||
// })
|
|||
|
|||
// app.patch('/:id', async (req, res) => {
|
|||
// try{
|
|||
// const editProvider = await controller.updateProvider(req.params.id, req.body.message);
|
|||
// response.success(req, res, editProvider, 201);
|
|||
// }catch(error){
|
|||
// response.error(req,res, error, 401)
|
|||
// }
|
|||
// })
|
|||
|
|||
// app.delete('/:id', async (req, res) => {
|
|||
// try{
|
|||
// const deleteProvider = await controller.deleteProvider(req.params.id, req.body.message);
|
|||
// response.success(req, res, deleteProvider, 201);
|
|||
// }catch(error){
|
|||
// response.error(req,res, error, 401)
|
|||
// }
|
|||
// })
|
|||
|
|||
module.exports = app; |
|||
@ -0,0 +1,92 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
|
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
const Model = require("./model"); |
|||
|
|||
//Agrega el mensaje a la BD
|
|||
function addCategory(message) { |
|||
const myMessage = new Model(message); |
|||
myMessage.save(); |
|||
} |
|||
|
|||
async function getCategories(filterUser) { |
|||
return new Promise((resolve, reject) => { |
|||
console.log(filterUser); |
|||
let filter = {}; |
|||
if (filterUser !== null) { |
|||
filter = { user: filterUser }; |
|||
} |
|||
|
|||
Model.find(filter) |
|||
//Busca por objectID en user y lo inserta en mensaje
|
|||
//.select("_id")
|
|||
.populate("products", "name description imageSupply") |
|||
.exec((error, populated) => { |
|||
if (error) { |
|||
console.log("···· Error ", error); |
|||
reject(error); |
|||
return false; |
|||
} |
|||
resolve(populated); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
function pushProducts(newProduct) { |
|||
console.log(newProduct); |
|||
return Model.findOneAndUpdate( |
|||
{ _id: "6256e9f747d474891f29acef" }, |
|||
{ $push: { products: newProduct } } |
|||
); |
|||
} |
|||
|
|||
//add product to Provider
|
|||
function addProductToCategory(idCategory, productId) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve( |
|||
Model.findOneAndUpdate( |
|||
{ _id: idCategory }, |
|||
{ $push: { products: productId } } |
|||
) |
|||
); |
|||
}); |
|||
} |
|||
|
|||
//assign provider
|
|||
async function assignCategory(id, idProvider) { |
|||
const foundSupply = await Model.findOneAndUpdate( |
|||
{ |
|||
_id: id, |
|||
}, |
|||
{ |
|||
$push: { |
|||
providers: idProvider, |
|||
}, |
|||
} |
|||
); |
|||
return foundSupply; |
|||
} |
|||
|
|||
// async function updateText(id, message) {
|
|||
// const foundMessage = await Model.findById(id)
|
|||
|
|||
// foundMessage.message = message;
|
|||
// const newMessage = await foundMessage.save();
|
|||
// }
|
|||
|
|||
// function deleteMessage(id) {
|
|||
// return Model.findByIdAndDelete(id)
|
|||
// }
|
|||
|
|||
module.exports = { |
|||
add: addCategory, |
|||
list: getCategories, |
|||
push: pushProducts, |
|||
addProductToCategory: addProductToCategory, |
|||
assignCategory: assignCategory |
|||
// updateText: updateText,
|
|||
// remove: deleteMessage,
|
|||
}; |
|||
@ -0,0 +1,97 @@ |
|||
//Mock de base de datos
|
|||
const store = require("./store"); |
|||
|
|||
//Conexión por websockets
|
|||
//const { socket } = require('../../socket');
|
|||
|
|||
function addOrder(idProduct, idProvider, amount, quantity, description) { |
|||
return new Promise((resolve, reject) => { |
|||
if (!idProduct) { |
|||
console.error("[messageController]: No hay usuario o mensaje!"); |
|||
reject("Los datos son incorrectos!"); |
|||
} |
|||
const fullOrder = { |
|||
idProduct: idProduct, |
|||
idProvider: idProvider, |
|||
amount: amount, |
|||
quantity: quantity, |
|||
description: description, |
|||
date: new Date(), |
|||
statusDB: true, |
|||
}; |
|||
|
|||
|
|||
|
|||
|
|||
//socket.io.emit('listenProviders', fullProvider);
|
|||
|
|||
resolve(store.add(fullOrder)); |
|||
}); |
|||
} |
|||
|
|||
function getOrders(filterOrders) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.list(filterOrders)); |
|||
}); |
|||
} |
|||
|
|||
function getListProviders(filterOrders) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.getListProviders(filterOrders)); |
|||
}); |
|||
} |
|||
|
|||
/* function pushProduct(newProduct) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.push(newProduct)); |
|||
}); |
|||
} |
|||
|
|||
// add product to Provider
|
|||
function addProductToProvider(idProvider, productId) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.addProductToProvider(idProvider, productId)); |
|||
}); |
|||
} |
|||
|
|||
// add price to provider and return the new price
|
|||
function addPriceToProvider(idProvider, price) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.addPriceToProvider(idProvider, price)); |
|||
}); |
|||
} */ |
|||
|
|||
|
|||
// function updateProvider(id, message) {
|
|||
// return new Promise(async (resolve, reject) => {
|
|||
// console.log(id)
|
|||
// console.log(message)
|
|||
// if(!id || !message){
|
|||
// reject('Invalid data')
|
|||
// return false
|
|||
// }
|
|||
// const result = await store.updateText(id, message);
|
|||
// resolve(result);
|
|||
// })
|
|||
// }
|
|||
|
|||
// function deleteProvider(id) {
|
|||
// return new Promise(async (resolve, reject) => {
|
|||
// if (!id) {
|
|||
// reject ('Id inválido')
|
|||
// }
|
|||
|
|||
// resolve(store.remove(id));
|
|||
// });
|
|||
// }
|
|||
|
|||
module.exports = { |
|||
addOrder, |
|||
getOrders, |
|||
getListProviders |
|||
/* pushProduct, |
|||
addProductToProvider, |
|||
addPriceToProvider, */ |
|||
// updateProvider,
|
|||
// deleteProvider,
|
|||
}; |
|||
@ -0,0 +1,33 @@ |
|||
//En este modulo se declara la estructura de los datos que ingresaran a la BD
|
|||
|
|||
const mongoose = require("mongoose"); |
|||
|
|||
const Schema = mongoose.Schema; |
|||
|
|||
const supplySchema = new Schema({ |
|||
|
|||
idProduct: { |
|||
type: Schema.ObjectId, |
|||
ref: "Supply" |
|||
}, |
|||
idProvider: { |
|||
type: Schema.ObjectId, |
|||
ref: "Provider" |
|||
}, |
|||
amount: { |
|||
type: Number, |
|||
}, |
|||
date: { |
|||
type: Date |
|||
}, |
|||
quantity: { |
|||
type: Number, |
|||
}, |
|||
description: { |
|||
type: String, |
|||
}, |
|||
|
|||
}); |
|||
|
|||
const model = mongoose.model("Order", supplySchema); |
|||
module.exports = model; |
|||
@ -0,0 +1,111 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
const Model = require("./model"); |
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
//Response
|
|||
const response = require("../../network/response"); |
|||
|
|||
//Agrega controlador
|
|||
const controller = require("./controller"); |
|||
|
|||
//redirecciona a metodo GET
|
|||
app.get("/", async function (req, res) { |
|||
try { |
|||
const filterOrders = req.query.id || null; |
|||
const orderList = await controller.getOrders(filterOrders); |
|||
response.success(req, res, orderList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
//redirecciona a metodo GET
|
|||
app.get("/listproviders", async function (req, res) { |
|||
try { |
|||
const filterOrders = req.query.id || null; |
|||
const orderList = await controller.getListProviders(filterOrders); |
|||
response.success(req, res, orderList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
//redirecciona a metodo POST
|
|||
app.post("/", async (req, res) => { |
|||
|
|||
try { |
|||
const fullOrder = await controller.addOrder( |
|||
req.body.idProduct, |
|||
req.body.idProvider, |
|||
req.body.amount, |
|||
req.body.quantity, |
|||
req.body.description |
|||
); |
|||
console.log(fullOrder); |
|||
response.success(req, res, fullOrder, 201); |
|||
} catch (error) { |
|||
console.log(res); |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
// push product id to provider
|
|||
/* app.put("/:id", async (req, res) => { |
|||
try { |
|||
const providerId = req.params.id; |
|||
const productId = req.body.productId; |
|||
const result = await controller.addProductToProvider(providerId, productId); |
|||
response.success(req, res, result, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
// put price to provider and return the new price
|
|||
app.put("/price/:id", async (req, res) => { |
|||
try { |
|||
const providerId = req.params.id; |
|||
const price = req.body.price; |
|||
const result = await controller.addPriceToProvider(providerId, price); |
|||
response.success(req, res, result, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); */ |
|||
|
|||
|
|||
// app.put('/', async (req, res) => {
|
|||
// try{
|
|||
// const fullProvider = await controller.pushProduct(req.body.products);
|
|||
|
|||
// response.success(req, res, fullProvider, 201);
|
|||
// }catch(error){
|
|||
// console.log(res)
|
|||
// response.error(req, res, error, 401);
|
|||
// }
|
|||
// })
|
|||
|
|||
// app.patch('/:id', async (req, res) => {
|
|||
// try{
|
|||
// const editProvider = await controller.updateProvider(req.params.id, req.body.message);
|
|||
// response.success(req, res, editProvider, 201);
|
|||
// }catch(error){
|
|||
// response.error(req,res, error, 401)
|
|||
// }
|
|||
// })
|
|||
|
|||
// app.delete('/:id', async (req, res) => {
|
|||
// try{
|
|||
// const deleteProvider = await controller.deleteProvider(req.params.id, req.body.message);
|
|||
// response.success(req, res, deleteProvider, 201);
|
|||
// }catch(error){
|
|||
// response.error(req,res, error, 401)
|
|||
// }
|
|||
// })
|
|||
|
|||
module.exports = app; |
|||
@ -0,0 +1,80 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
|
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
const Model = require("./model"); |
|||
const ModelSupply = require("../supplies/model"); |
|||
|
|||
//Agrega el mensaje a la BD
|
|||
async function addOrder(order) { |
|||
const myOrder = new Model(order); |
|||
const saved = myOrder.save(); |
|||
console.log(order.idProvider) |
|||
await ModelSupply.findOneAndUpdate({_id: order.idProduct, providers: {$ne: order.idProvider}}, {$addToSet: {providers: order.idProvider}}) |
|||
return saved; |
|||
} |
|||
|
|||
async function getOrders(filterOrders) { |
|||
return new Promise((resolve, reject) => { |
|||
console.log(filterOrders); |
|||
let filter = {}; |
|||
if (filterOrders !== null) { |
|||
filter = { idProduct: filterOrders }; |
|||
} |
|||
|
|||
Model.find(filter) |
|||
//Busca por objectID en user y lo inserta en mensaje
|
|||
//.select("_id")
|
|||
.populate("idProduct", 'name') |
|||
.populate("idProvider", "name") |
|||
.exec((error, populated) => { |
|||
if (error) { |
|||
console.log("···· Error ", error); |
|||
reject(error); |
|||
return false; |
|||
} |
|||
resolve(populated); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
|
|||
async function getListProviders(filterOrders) { |
|||
return new Promise((resolve, reject) => { |
|||
console.log(filterOrders); |
|||
let filter = {}; |
|||
if (filterOrders !== null) { |
|||
filter = { idProduct: filterOrders }; |
|||
} |
|||
|
|||
Model.find(filter) |
|||
//Busca por objectID en user y lo inserta en mensaje
|
|||
//.select("_id")
|
|||
.populate("idProduct", 'name') |
|||
.populate("idProvider", "name") |
|||
.select('idProvider') |
|||
.exec((error, populated) => { |
|||
if (error) { |
|||
console.log("···· Error ", error); |
|||
reject(error); |
|||
return false; |
|||
} |
|||
resolve(populated); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
|
|||
add: addOrder, |
|||
list: getOrders, |
|||
getListProviders |
|||
|
|||
}; |
|||
@ -0,0 +1,88 @@ |
|||
//Mock de base de datos
|
|||
const store = require("./store"); |
|||
|
|||
//Conexión por websockets
|
|||
const { socket } = require('../../socket'); |
|||
|
|||
function addProvider(name, products, description) { |
|||
return new Promise((resolve, reject) => { |
|||
if (!name) { |
|||
console.error("[messageController]: No hay usuario o mensaje!"); |
|||
reject("Los datos son incorrectos!"); |
|||
} |
|||
const fullProvider = { |
|||
name: name, |
|||
products: products, |
|||
description: description, |
|||
date: new Date(), |
|||
statusDB: true, |
|||
}; |
|||
|
|||
|
|||
store.add(fullProvider); |
|||
|
|||
socket.io.emit('listenProviders', fullProvider); |
|||
|
|||
resolve(fullProvider); |
|||
}); |
|||
} |
|||
|
|||
function getProviders(filterProvider) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.list(filterProvider)); |
|||
}); |
|||
} |
|||
|
|||
function pushProduct(newProduct) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.push(newProduct)); |
|||
}); |
|||
} |
|||
|
|||
// add product to Provider
|
|||
function addProductToProvider(idProvider, productId) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.addProductToProvider(idProvider, productId)); |
|||
}); |
|||
} |
|||
|
|||
// add price to provider and return the new price
|
|||
function addPriceToProvider(idProvider, price) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.addPriceToProvider(idProvider, price)); |
|||
}); |
|||
} |
|||
|
|||
|
|||
// function updateProvider(id, message) {
|
|||
// return new Promise(async (resolve, reject) => {
|
|||
// console.log(id)
|
|||
// console.log(message)
|
|||
// if(!id || !message){
|
|||
// reject('Invalid data')
|
|||
// return false
|
|||
// }
|
|||
// const result = await store.updateText(id, message);
|
|||
// resolve(result);
|
|||
// })
|
|||
// }
|
|||
|
|||
// function deleteProvider(id) {
|
|||
// return new Promise(async (resolve, reject) => {
|
|||
// if (!id) {
|
|||
// reject ('Id inválido')
|
|||
// }
|
|||
|
|||
// resolve(store.remove(id));
|
|||
// });
|
|||
// }
|
|||
|
|||
module.exports = { |
|||
addProvider, |
|||
getProviders, |
|||
pushProduct, |
|||
addProductToProvider, |
|||
addPriceToProvider, |
|||
// updateProvider,
|
|||
// deleteProvider,
|
|||
}; |
|||
@ -0,0 +1,47 @@ |
|||
//En este modulo se declara la estructura de los datos que ingresaran a la BD
|
|||
|
|||
const mongoose = require("mongoose"); |
|||
const Schema = mongoose.Schema; |
|||
|
|||
const supplySchema = require("./../supplies/model"); |
|||
|
|||
const mySchema = new Schema({ |
|||
name: { |
|||
type: String, |
|||
//required: true
|
|||
}, |
|||
products: [ |
|||
{ |
|||
type: Schema.ObjectId, |
|||
ref: "Supply", |
|||
}, |
|||
], |
|||
order: [ |
|||
{ |
|||
idProduct: { |
|||
type: Schema.ObjectId, |
|||
ref: "Supply" |
|||
}, |
|||
amount: { |
|||
type: Number, |
|||
}, |
|||
date: { |
|||
type: Date |
|||
}, |
|||
quantity: { |
|||
type: Number, |
|||
} |
|||
} |
|||
], |
|||
date: Date, |
|||
statusDB: { |
|||
type: Boolean, |
|||
required: false, |
|||
}, |
|||
description: { |
|||
type: String, |
|||
}, |
|||
}); |
|||
|
|||
const model = mongoose.model("Provider", mySchema); |
|||
module.exports = model; |
|||
@ -0,0 +1,96 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
const Model = require("./model"); |
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
//Response
|
|||
const response = require("../../network/response"); |
|||
|
|||
//Agrega controlador
|
|||
const controller = require("./controller"); |
|||
|
|||
//redirecciona a metodo GET
|
|||
app.get("/", async function (req, res) { |
|||
try { |
|||
const filterProviders = req.query.id || null; |
|||
const providerList = await controller.getProviders(filterProviders); |
|||
response.success(req, res, providerList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
//redirecciona a metodo POST
|
|||
app.post("/", async (req, res) => { |
|||
|
|||
try { |
|||
const fullProvider = await controller.addProvider( |
|||
req.body.name, |
|||
req.body.products, |
|||
req.body.description, |
|||
); |
|||
console.log(fullProvider); |
|||
response.success(req, res, fullProvider, 201); |
|||
} catch (error) { |
|||
console.log(res); |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
// push product id to provider
|
|||
app.put("/:id", async (req, res) => { |
|||
try { |
|||
const providerId = req.params.id; |
|||
const productId = req.body.productId; |
|||
const result = await controller.addProductToProvider(providerId, productId); |
|||
response.success(req, res, result, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
// put price to provider and return the new price
|
|||
app.put("/price/:id", async (req, res) => { |
|||
try { |
|||
const providerId = req.params.id; |
|||
const price = req.body.price; |
|||
const result = await controller.addPriceToProvider(providerId, price); |
|||
response.success(req, res, result, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
// app.put('/', async (req, res) => {
|
|||
// try{
|
|||
// const fullProvider = await controller.pushProduct(req.body.products);
|
|||
|
|||
// response.success(req, res, fullProvider, 201);
|
|||
// }catch(error){
|
|||
// console.log(res)
|
|||
// response.error(req, res, error, 401);
|
|||
// }
|
|||
// })
|
|||
|
|||
// app.patch('/:id', async (req, res) => {
|
|||
// try{
|
|||
// const editProvider = await controller.updateProvider(req.params.id, req.body.message);
|
|||
// response.success(req, res, editProvider, 201);
|
|||
// }catch(error){
|
|||
// response.error(req,res, error, 401)
|
|||
// }
|
|||
// })
|
|||
|
|||
// app.delete('/:id', async (req, res) => {
|
|||
// try{
|
|||
// const deleteProvider = await controller.deleteProvider(req.params.id, req.body.message);
|
|||
// response.success(req, res, deleteProvider, 201);
|
|||
// }catch(error){
|
|||
// response.error(req,res, error, 401)
|
|||
// }
|
|||
// })
|
|||
|
|||
module.exports = app; |
|||
@ -0,0 +1,47 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
|
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
const Model = require("./model"); |
|||
|
|||
//Agrega el mensaje a la BD
|
|||
function addProvider(message) { |
|||
const myMessage = new Model(message); |
|||
const saved = myMessage.save(); |
|||
return saved; |
|||
} |
|||
|
|||
async function getProvider(filterUser) { |
|||
return new Promise((resolve, reject) => { |
|||
console.log(filterUser); |
|||
let filter = {}; |
|||
if (filterUser !== null) { |
|||
filter = { user: filterUser }; |
|||
} |
|||
|
|||
Model.find(filter) |
|||
//Busca por objectID en user y lo inserta en mensaje
|
|||
//.select("_id")
|
|||
.populate("products", 'name category') |
|||
.exec((error, populated) => { |
|||
if (error) { |
|||
console.log("···· Error ", error); |
|||
reject(error); |
|||
return false; |
|||
} |
|||
resolve(populated); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
add: addProvider, |
|||
list: getProvider, |
|||
}; |
|||
@ -0,0 +1,200 @@ |
|||
//Mock de base de datos
|
|||
const store = require("./store"); |
|||
|
|||
require('dotenv').config(); |
|||
const localIP = process.env.LOCAL; |
|||
|
|||
function addSupply( |
|||
name, |
|||
unity, |
|||
providers, |
|||
imageSupply, |
|||
category, |
|||
description, |
|||
code, |
|||
location, |
|||
note, |
|||
quantity, |
|||
amount |
|||
) { |
|||
return new Promise((resolve, reject) => { |
|||
if (!name || !unity) { |
|||
console.error( |
|||
"[supplyController]: No se cargo correctamente la materia prima!" |
|||
); |
|||
reject("Los datos son incorrectos!"); |
|||
} |
|||
|
|||
imageUrl = ""; |
|||
if (imageSupply) { |
|||
imageUrl = |
|||
`http://${localIP}:1997/app/images/supplies/` + imageSupply.filename; |
|||
} |
|||
|
|||
const fullSupply = { |
|||
name: name, |
|||
unity: unity, |
|||
providers: providers, |
|||
code: code, |
|||
note: note, |
|||
category: category, |
|||
quantity: quantity, |
|||
location: location, |
|||
dateSupply: new Date(), |
|||
statusDB: true, |
|||
imageSupply: imageUrl, |
|||
description: description, |
|||
amount: amount |
|||
}; |
|||
|
|||
const fullOrder = { |
|||
idProvider: providers, |
|||
amount: amount, |
|||
quantity: quantity, |
|||
description: 'Es una orden', |
|||
date: new Date(), |
|||
statusDB: true, |
|||
}; |
|||
|
|||
store.add(fullSupply, fullOrder); |
|||
resolve(fullSupply); |
|||
}); |
|||
} |
|||
|
|||
function getSupplies(filterSupply) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.list(filterSupply)); |
|||
}); |
|||
} |
|||
|
|||
function listProviders(filterSupply) { |
|||
return new Promise((resolve, reject) => { |
|||
resolve(store.listProviders(filterSupply)); |
|||
}) |
|||
} |
|||
|
|||
|
|||
function getDeletedSupplies(){ |
|||
return new Promise ((resolve, reject) => { |
|||
resolve(store.getTrashSupplies()); |
|||
}) |
|||
} |
|||
|
|||
|
|||
function deleteSupply(id) { |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id) { |
|||
reject("Id inválido"); |
|||
} |
|||
|
|||
resolve(store.remove(id)); |
|||
}); |
|||
} |
|||
|
|||
//udpate Supply
|
|||
function update(id, name, image, description, location, category, code, providers, unity) { |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id/* || !name || !quantity || !unity || !category || !price */) { |
|||
reject("Revisar datos"); |
|||
}else{ |
|||
imageUrl = ""; |
|||
if (image) { |
|||
imageUrl = |
|||
`http://${localIP}:1997/app/images/supplies/` + image.filename; |
|||
} |
|||
const result = await store.update( |
|||
id, |
|||
name, |
|||
imageUrl, |
|||
description, |
|||
location, |
|||
category, |
|||
code, |
|||
providers, |
|||
unity |
|||
|
|||
|
|||
); |
|||
|
|||
resolve(result); |
|||
} |
|||
|
|||
|
|||
}); |
|||
} |
|||
|
|||
//delete supply statusDB false
|
|||
function updateStatusDB(id) { |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id) { |
|||
reject("Revisar datos"); |
|||
} |
|||
|
|||
const result = await store.changeStatusDB(id); |
|||
resolve(result); |
|||
}); |
|||
} |
|||
|
|||
//assign provider
|
|||
function assignProvider(id, idProvider) { |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id || !idProvider) { |
|||
reject("Revisar datos"); |
|||
} |
|||
|
|||
const result = await store.assignProvider(id, idProvider); |
|||
resolve(result); |
|||
}); |
|||
} |
|||
|
|||
//assign provider price
|
|||
function assignProviderPrice(id, provider, price) { |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id || !provider || !price) { |
|||
reject("Revisar datos"); |
|||
} |
|||
|
|||
const result = await store.assignProviderPrice(id, provider, price); |
|||
|
|||
resolve(result); |
|||
}); |
|||
} |
|||
|
|||
//remove provider
|
|||
function removeProvider(id, idProvider) { |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id || !idProvider) { |
|||
reject("Revisar datos"); |
|||
} |
|||
|
|||
const result = await store.removeProvider(id, idProvider); |
|||
resolve(result); |
|||
}); |
|||
} |
|||
|
|||
//update note
|
|||
function updateNote(id, note) { |
|||
console.log('desde controller', id, note) |
|||
return new Promise(async (resolve, reject) => { |
|||
if (!id) { |
|||
reject("revisar id"); |
|||
} else { |
|||
const result = await store.updateNote(id, note); |
|||
resolve(result); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
module.exports = { |
|||
addSupply, |
|||
getSupplies, |
|||
update, |
|||
deleteSupply, |
|||
updateStatusDB, |
|||
assignProvider, |
|||
assignProviderPrice, |
|||
removeProvider, |
|||
getDeletedSupplies, |
|||
listProviders, |
|||
updateNote |
|||
}; |
|||
@ -0,0 +1,49 @@ |
|||
//En este modulo se declara la estructura de los datos que ingresaran a la BD
|
|||
|
|||
const mongoose = require("mongoose"); |
|||
|
|||
const Schema = mongoose.Schema; |
|||
|
|||
const supplySchema = new Schema({ |
|||
name: { |
|||
type: String, |
|||
//required: true
|
|||
}, |
|||
unity: { |
|||
type: String, |
|||
}, |
|||
providers: [{ |
|||
type: Schema.ObjectId, |
|||
ref: 'Provider' |
|||
}], |
|||
code: { |
|||
type: String, |
|||
}, |
|||
dateSupply: Date, |
|||
statusDB: { |
|||
type: Boolean, |
|||
required: true, |
|||
}, |
|||
imageSupply: { |
|||
type: String, |
|||
}, |
|||
category: { |
|||
type: Schema.ObjectId, |
|||
ref: "Categories", |
|||
}, |
|||
description: { |
|||
type: String, |
|||
}, |
|||
location: { |
|||
type: String, |
|||
}, |
|||
note: { |
|||
type: String, |
|||
}, |
|||
quantity: { |
|||
type: Number, |
|||
}, |
|||
}); |
|||
|
|||
const model = mongoose.model("Supply", supplySchema); |
|||
module.exports = model; |
|||
@ -0,0 +1,181 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
|
|||
//subir archivos
|
|||
const multer = require("multer"); |
|||
|
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
//Response
|
|||
const response = require("../../network/response"); |
|||
|
|||
//Agrega controlador
|
|||
const controller = require("./controller"); |
|||
|
|||
const upload = multer({ |
|||
dest: "public/images/supplies", |
|||
}); |
|||
|
|||
//redirecciona a metodo GET
|
|||
app.get("/", async function (req, res) { |
|||
try { |
|||
const filterSupplies = req.query.id || null; |
|||
const supplyList = await controller.getSupplies(filterSupplies); |
|||
|
|||
response.success(req, res, supplyList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
//redirecciona a metodo GET
|
|||
app.get("/trash", async function (req, res) { |
|||
try { |
|||
const supplyList = await controller.getDeletedSupplies(); |
|||
|
|||
response.success(req, res, supplyList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
app.get("/listproviders", async function (req, res) { |
|||
try { |
|||
const filterSupplies = req.query.id || null; |
|||
const supplyList = await controller.listProviders(filterSupplies); |
|||
|
|||
response.success(req, res, supplyList, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
|
|||
//redirecciona a metodo POST
|
|||
app.post("/", upload.single("imageSupply"), async (req, res) => { |
|||
try { |
|||
console.log(req.body.amount) |
|||
const fullSupply = await controller.addSupply( |
|||
req.body.name, |
|||
req.body.unity, |
|||
req.body.providers, |
|||
req.file, |
|||
req.body.category, |
|||
req.body.description, |
|||
req.body.code, |
|||
req.body.location, |
|||
req.body.note, |
|||
req.body.quantity, |
|||
req.body.amount |
|||
); |
|||
response.success(req, res, fullSupply, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
///udpate Supply witch patch
|
|||
app.patch("/:id", upload.single("imageSupply"), async (req, res) => { |
|||
|
|||
try{ |
|||
const updatedSupply = await controller.update( |
|||
req.params.id, |
|||
req.body.name, |
|||
req.file, |
|||
req.body.description, |
|||
req.body.location, |
|||
req.body.category, |
|||
req.body.code, |
|||
req.body.providers, |
|||
req.body.unity, |
|||
|
|||
); |
|||
response.success(req, res, updatedSupply, 201); |
|||
} catch (error){ |
|||
response.error(req, res, error, 401); |
|||
} |
|||
|
|||
; |
|||
}); |
|||
|
|||
//delete supply statusDB false
|
|||
app.patch("/totrash/:id", async (req, res) => { |
|||
try{ |
|||
const stateStatusDb = await controller.updateStatusDB(req.params.id); |
|||
response.success(req, res, stateStatusDb, 201); |
|||
}catch (error){ |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
app.delete("/:id", async (req, res) => { |
|||
try { |
|||
const deletedSupply = await controller.deleteSupply( |
|||
req.params.id, |
|||
req.body.name |
|||
); |
|||
response.success(req, res, deletedSupply, 201); |
|||
} catch (error) { |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
// assign provider
|
|||
app.patch("/assign/:id", async (req, res) => { |
|||
controller |
|||
.assignProvider(req.params.id, req.body.idProvider) |
|||
.then((data) => { |
|||
const message = `El proveedor ${req.body.idProvider} fue agregado`; |
|||
response.success(req, res, message, 200); |
|||
}) |
|||
.catch((err) => { |
|||
response.error(req, res, err, 500); |
|||
}); |
|||
}); |
|||
|
|||
//assign provider and price
|
|||
app.patch("/assignPrice/:id/", async (req, res) => { |
|||
|
|||
controller |
|||
.assignProviderPrice( |
|||
req.params.id, |
|||
req.body.provider, |
|||
req.body.price |
|||
) |
|||
.then((data) => { |
|||
const message = `El proveedor ${req.params.provider} fue agregado`; |
|||
response.success(req, res, message, 200); |
|||
}) |
|||
.catch((err) => { |
|||
response.error(req, res, err, 500); |
|||
}); |
|||
}); |
|||
|
|||
|
|||
//remove provider
|
|||
app.patch("/remove/:id", async (req, res) => { |
|||
controller |
|||
.removeProvider(req.params.id, req.body.idProvider) |
|||
.then((data) => { |
|||
const message = `El proveedor ${req.body.idProvider} fue eliminado`; |
|||
response.success(req, res, message, 200); |
|||
}) |
|||
.catch((err) => { |
|||
response.error(req, res, err, 500); |
|||
}); |
|||
}); |
|||
|
|||
// udpate note
|
|||
app.patch("/updatenote/:id", async (req, res) => { |
|||
try{ |
|||
const note = req.body.note |
|||
const updateNote = await controller.updateNote(req.params.id, note); |
|||
response.success(req, res, updateNote, 201); |
|||
}catch (error){ |
|||
response.error(req, res, error, 401); |
|||
} |
|||
}); |
|||
|
|||
module.exports = app; |
|||
@ -0,0 +1,236 @@ |
|||
//Se declara express
|
|||
const express = require("express"); |
|||
|
|||
//Se inicializa express
|
|||
var app = express(); |
|||
|
|||
const storeOrders = require('../orders/store'); |
|||
|
|||
const ModelOrders = require('../orders/model'); |
|||
const ModelCategories = require('../categories/model'); |
|||
const ModelProviders = require("../providers/model"); |
|||
const Model = require("./model"); |
|||
|
|||
//Agrega el mensaje a la BD
|
|||
function addSupply(supply, order) { |
|||
console.log('Este es el idprovider' + order.idProvider); |
|||
const mySupply = new Model(supply); |
|||
const newOrder = {...order, idProduct: mySupply._id} |
|||
const myOrder = new ModelOrders(newOrder) |
|||
console.log('DESDE STOREEEEEEEEEEEEEE: ' + supply.amount) |
|||
|
|||
mySupply.save(); |
|||
myOrder.save(); |
|||
insertCategory(mySupply.category, mySupply._id); |
|||
insertProvider(mySupply.providers, mySupply._id, supply.amount, supply.quantity); |
|||
} |
|||
|
|||
async function getSupplies(filterSupply) { |
|||
return new Promise((resolve, reject) => { |
|||
let filter = {statusDB: true}; |
|||
if (filterSupply !== null) { |
|||
filter = { _id: filterSupply}; |
|||
} |
|||
Model.find(filter) |
|||
.populate('providers', 'name description') |
|||
.populate('category', 'name description') |
|||
.exec((err, supplies) => { |
|||
if (err) { |
|||
console.log(err) |
|||
reject("Error al obtener los insumos"); |
|||
} else { |
|||
resolve(supplies); |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
async function getTrashSupplies() { |
|||
return new Promise((resolve, reject) => { |
|||
const filter = {statusDB: false}; |
|||
Model.find(filter) |
|||
.populate('providers', 'name description') |
|||
.populate('category', 'name description') |
|||
.exec((err, supplies) => { |
|||
if (err) { |
|||
console.log(err) |
|||
reject("Error al obtener los insumos"); |
|||
} else { |
|||
resolve(supplies); |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
async function updateSupply(id, name, image, description, location, category, code, providers, unity) { |
|||
|
|||
const filter = {_id: id}; |
|||
var update = { |
|||
|
|||
name: name, |
|||
description: description, |
|||
location: location, |
|||
category: category, |
|||
code: code, |
|||
providers: providers, |
|||
unity: unity |
|||
|
|||
}; |
|||
const opts = { new: true }; |
|||
if(image != ""){ |
|||
update = {...update, imageSupply: image} |
|||
} |
|||
let updatedSupply = await Model.findByIdAndUpdate(filter, update, opts); |
|||
console.log(updatedSupply); |
|||
return updatedSupply; |
|||
|
|||
} |
|||
|
|||
function deleteSupply(id) { |
|||
return Model.findByIdAndDelete(id); |
|||
} |
|||
|
|||
|
|||
// delete Supply statusDB false
|
|||
async function changeStatusDB(id) { |
|||
let foundSupply = await Model.findById(id); |
|||
const filter = {_id: id}; |
|||
const opts = { new: true }; |
|||
var update = {} |
|||
if (foundSupply.statusDB == true){ |
|||
console.log('Está activo...moviendo a la basura'); |
|||
update = {statusDB: false}; |
|||
|
|||
}else{ |
|||
console.log('Está inactivo...restableciendolo'); |
|||
update = {statusDB: true}; |
|||
} |
|||
|
|||
foundSupply = await Model.findByIdAndUpdate(filter, update, opts); |
|||
console.log(foundSupply); |
|||
return foundSupply; |
|||
|
|||
|
|||
|
|||
|
|||
/* const newSupply = await foundSupply.save(); |
|||
return newSupply; */ |
|||
} |
|||
|
|||
async function listProviders(filterSupply){ |
|||
return new Promise((resolve, reject) => { |
|||
let filter = {statusDB: true}; |
|||
if (filterSupply !== null) { |
|||
filter = { _id: filterSupply}; |
|||
} |
|||
Model.find(filter) |
|||
.populate('providers', 'name description') |
|||
.populate('category', 'name description') |
|||
.exec(async (err, supplies) => { |
|||
if (err) { |
|||
console.log(err) |
|||
reject("Error al obtener los insumos"); |
|||
} else { |
|||
var listProviders = []; |
|||
var allOrders = []; |
|||
var total = 0; |
|||
const orders = await storeOrders.list(filterSupply); |
|||
supplies[0].providers.map((itemProvider, index) =>( |
|||
orders.map((itemOrder, index) => { |
|||
//console.log('itemProvider: ' + itemProvider._id + ' itemOrder: ' + itemOrder.idProvider._id + ' Nro: ' + index)
|
|||
if(String(itemProvider._id) === String(itemOrder.idProvider._id)){ |
|||
console.log('Its a match! ' + itemProvider._id + ' = ' + itemOrder.idProvider._id + ' Nro: ' + index); |
|||
allOrders.push({date: itemOrder.date, amount: itemOrder.amount, description: itemOrder.description, quantity: itemOrder.quantity}) |
|||
total += itemOrder.quantity; |
|||
console.log(allOrders) |
|||
} |
|||
}), |
|||
console.log(''), |
|||
listProviders.push({ name: itemProvider, orders: allOrders, total: total }), |
|||
allOrders = [], |
|||
total = 0 |
|||
)) |
|||
|
|||
|
|||
|
|||
resolve(listProviders); |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
//remove provider
|
|||
async function removeProvider(id, idProvider) { |
|||
const foundSupply = await Model.findOneAndUpdate( |
|||
{ |
|||
_id: id, |
|||
}, |
|||
{ |
|||
$pull: { |
|||
providers: idProvider, |
|||
}, |
|||
} |
|||
); |
|||
return foundSupply; |
|||
} |
|||
|
|||
|
|||
//Inserta el producto al proveedor una vez posteado el supply
|
|||
async function insertProvider(id, supply, amount, quantity) { |
|||
console.log("Este es el id del supply enviado: " + supply) |
|||
console.log(amount); |
|||
const filter = {_id: id}; |
|||
var update = {$push: { |
|||
products: supply, |
|||
order: [{idProduct: supply, amount: amount, quantity: quantity, date: new Date()}] |
|||
}}; |
|||
|
|||
const opts = { new: true }; |
|||
|
|||
await ModelProviders.findByIdAndUpdate(filter, update, opts); |
|||
|
|||
} |
|||
|
|||
async function insertCategory(id, supply) { |
|||
|
|||
const filter = {_id: id}; |
|||
var update = {$push: { |
|||
|
|||
products: supply, |
|||
|
|||
}}; |
|||
|
|||
const opts = { new: true }; |
|||
|
|||
await ModelCategories.findByIdAndUpdate(filter, update, opts); |
|||
|
|||
} |
|||
|
|||
|
|||
//update note
|
|||
async function updateNote(id, note) { |
|||
console.log(id,note) |
|||
const filter = { _id: id }; |
|||
var update = { |
|||
note: note, |
|||
}; |
|||
|
|||
const opts = { new: true }; |
|||
|
|||
let updatedSupply = await Model.findByIdAndUpdate(filter, update, opts); |
|||
console.log(updatedSupply); |
|||
return updatedSupply; |
|||
} |
|||
|
|||
|
|||
module.exports = { |
|||
add: addSupply, |
|||
list: getSupplies, |
|||
update: updateSupply, |
|||
remove: deleteSupply, |
|||
removeProvider: removeProvider, |
|||
changeStatusDB: changeStatusDB, |
|||
getTrashSupplies: getTrashSupplies, |
|||
listProviders: listProviders, |
|||
updateNote: updateNote |
|||
}; |
|||
@ -0,0 +1,15 @@ |
|||
const db = require('mongoose'); |
|||
|
|||
//se realiza la conexion a la BD
|
|||
db.Promise = global.Promise; |
|||
|
|||
async function connect(mongo_url){ |
|||
await db.connect(mongo_url); |
|||
console.log('Base de datos conectada con exito!'); |
|||
} |
|||
|
|||
module.exports = connect; |
|||
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,17 @@ |
|||
exports.success = function (req, res, message, status){ |
|||
//Recibe parametro message y lo imprime
|
|||
res.status(status || 200).send({ |
|||
error: '', |
|||
body: message |
|||
}); |
|||
} |
|||
|
|||
exports.error = function (req, res, message, status, details){ |
|||
//Muestra los errores internos a través de un log para no darle tanta informacion al cliente
|
|||
console.error(message); |
|||
|
|||
res.status(status || 500).send({ |
|||
error: message, |
|||
body: '' |
|||
}); |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
const express = require('express'); |
|||
const supply = require('../components/supplies/network'); |
|||
const provider = require('../components/providers/network'); |
|||
const category = require('../components/categories/network'); |
|||
const order = require('../components/orders/network'); |
|||
|
|||
|
|||
const routes = function(server) { |
|||
server.use('/api/supplies', supply) |
|||
server.use('/api/providers', provider) |
|||
server.use('/api/categories', category) |
|||
server.use('/api/orders', order) |
|||
} |
|||
|
|||
|
|||
|
|||
module.exports = routes; |
|||
File diff suppressed because it is too large
@ -0,0 +1,26 @@ |
|||
{ |
|||
"name": "backend-node", |
|||
"version": "0.1.0", |
|||
"description": "Es un backend hecho con node y websockets", |
|||
"main": "server.js", |
|||
"scripts": { |
|||
"test": "echo \"Error: no test specified\" && exit 1" |
|||
}, |
|||
"keywords": [ |
|||
"chat", |
|||
"telegram", |
|||
"backend", |
|||
"node" |
|||
], |
|||
"author": "matijego", |
|||
"license": "MIT", |
|||
"dependencies": { |
|||
"body-parser": "^1.19.1", |
|||
"cors": "^2.8.5", |
|||
"dotenv": "^16.0.1", |
|||
"express": "^4.17.2", |
|||
"mongoose": "^6.1.10", |
|||
"multer": "^1.4.4", |
|||
"socket.io": "^4.4.1" |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 52 KiB |
@ -0,0 +1,12 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|||
<title>Document</title> |
|||
</head> |
|||
<body> |
|||
<h1>Es un archivo estático!</h1> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,13 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|||
<title>Document</title> |
|||
</head> |
|||
<body> |
|||
<h1>una imagen</h1> |
|||
<img src="http://localhost:1997/app/images/supplies/7c993759144468fbff710bad57e8e931" alt="gg"> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,42 @@ |
|||
//Se declara express
|
|||
const express = require('express'); |
|||
const cors = require('cors'); |
|||
|
|||
|
|||
require('dotenv').config(); |
|||
|
|||
//Se inicializa express
|
|||
const app = express(); |
|||
app.use(express.json()); |
|||
app.use(express.urlencoded({extended : false})); |
|||
|
|||
|
|||
//WebSockets
|
|||
const server = require('http').Server(app); |
|||
const socket = require('./socket') |
|||
socket.connect(server); |
|||
app.use(cors()) |
|||
|
|||
|
|||
const mongodb = process.env.DB; |
|||
|
|||
//Declara la base de datos
|
|||
const db = require('./db') |
|||
db(mongodb); |
|||
|
|||
//Inicializa componentes
|
|||
//const router = require('./components/messages/network');
|
|||
const router = require('./network/routes'); |
|||
const { isPromise } = require('util/types'); |
|||
|
|||
|
|||
//Archivos estáticos
|
|||
app.use('/app', express.static('public')); |
|||
|
|||
//Inicializa las rutas
|
|||
router(app); |
|||
|
|||
//Configura el puerto
|
|||
server.listen(1997, function (){ |
|||
console.log('El back está corriendo en el puerto 1997'); |
|||
}); |
|||
@ -0,0 +1,18 @@ |
|||
const socketIO = require('socket.io') |
|||
const socket = {}; |
|||
|
|||
|
|||
function connect(server){ |
|||
socket.io = socketIO(server, { |
|||
cors: { |
|||
origin: "*" |
|||
} |
|||
}); |
|||
} |
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
connect, |
|||
socket, |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
version: '3' |
|||
|
|||
services: |
|||
back-fanstock: |
|||
image: back-fanstock |
|||
build: ./backend |
|||
container_name: back-fanstock |
|||
ports: |
|||
- "1997:1997" |
|||
restart: on-failure |
|||
|
|||
front-fanstock: |
|||
image: front-fanstock |
|||
build: ./frontend |
|||
container_name: front-fanstock |
|||
ports: |
|||
- "4000:3000" |
|||
restart: always |
|||
|
|||
# mongo: |
|||
# container_name: mongo_db |
|||
# image: mongo:4.4.8 |
|||
# ports: |
|||
# - "27017:27017" |
|||
@ -0,0 +1,5 @@ |
|||
FROM node:latest |
|||
WORKDIR /app |
|||
COPY . . |
|||
RUN npm i -g serve |
|||
CMD ["serve","-s","build"] |
|||
@ -0,0 +1,14 @@ |
|||
{ |
|||
"files": { |
|||
"main.css": "/static/css/main.ee0b948e.css", |
|||
"main.js": "/static/js/main.29b87aba.js", |
|||
"static/media/dificultades-tecnicas-1.jpg": "/static/media/dificultades-tecnicas-1.4a64df7c2cca305b6a21.jpg", |
|||
"index.html": "/index.html", |
|||
"main.ee0b948e.css.map": "/static/css/main.ee0b948e.css.map", |
|||
"main.29b87aba.js.map": "/static/js/main.29b87aba.js.map" |
|||
}, |
|||
"entrypoints": [ |
|||
"static/css/main.ee0b948e.css", |
|||
"static/js/main.29b87aba.js" |
|||
] |
|||
} |
|||
|
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,9 @@ |
|||
.container-fluid, |
|||
.row, |
|||
.col-6, |
|||
.col-12, |
|||
.col-4, |
|||
.col-2 { |
|||
margin: 0px; |
|||
padding: 0px; |
|||
} |
|||
@ -0,0 +1 @@ |
|||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><link rel="stylesheet" href="/style.css"/><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/><title>FanStock</title><script defer="defer" src="/static/js/main.29b87aba.js"></script><link href="/static/css/main.ee0b948e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html> |
|||
@ -0,0 +1,15 @@ |
|||
{ |
|||
"short_name": "FanStock", |
|||
"name": "FanStock", |
|||
"icons": [ |
|||
{ |
|||
"src": "favicon.ico", |
|||
"sizes": "64x64 32x32 24x24 16x16", |
|||
"type": "image/x-icon" |
|||
} |
|||
], |
|||
"start_url": ".", |
|||
"display": "standalone", |
|||
"theme_color": "#000000", |
|||
"background_color": "#ffffff" |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
# https://www.robotstxt.org/robotstxt.html |
|||
User-agent: * |
|||
Disallow: |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,97 @@ |
|||
/* |
|||
object-assign |
|||
(c) Sindre Sorhus |
|||
@license MIT |
|||
*/ |
|||
|
|||
/*! |
|||
Copyright (c) 2017 Jed Watson. |
|||
Licensed under the MIT License (MIT), see |
|||
http://jedwatson.github.io/classnames |
|||
*/ |
|||
|
|||
/*! ***************************************************************************** |
|||
Copyright (c) Microsoft Corporation. |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
|||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
|||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
|||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
|||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
|||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|||
PERFORMANCE OF THIS SOFTWARE. |
|||
***************************************************************************** */ |
|||
|
|||
/** @license MUI v5.3.0 |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v0.20.2 |
|||
* scheduler.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v16.13.1 |
|||
* react-is.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v17.0.2 |
|||
* react-dom-test-utils.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v17.0.2 |
|||
* react-dom.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v17.0.2 |
|||
* react-is.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v17.0.2 |
|||
* react-jsx-runtime.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
/** @license React v17.0.2 |
|||
* react.production.min.js |
|||
* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
* |
|||
* This source code is licensed under the MIT license found in the |
|||
* LICENSE file in the root directory of this source tree. |
|||
*/ |
|||
|
|||
//! goToAndStop must be relative to the start of the current segment |
|||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 52 KiB |
@ -0,0 +1,238 @@ |
|||
/* futureColor: #1d1d1d */ |
|||
|
|||
* { |
|||
margin: 0; |
|||
padding: 0; |
|||
list-style: none; |
|||
text-decoration: none; |
|||
border: none; |
|||
outline: none; |
|||
font-family: "Roboto", sans-serif; |
|||
} |
|||
|
|||
body { |
|||
background: #11181b; |
|||
} |
|||
|
|||
.link:link { |
|||
color: #fff; |
|||
font-size: 1.6rem; |
|||
line-height: 1.6rem; |
|||
text-decoration: none; |
|||
} |
|||
a:visited { |
|||
color: rgb(228, 228, 228); |
|||
} |
|||
a:hover { |
|||
color: rgb(228, 228, 228); |
|||
} |
|||
a:active { |
|||
color: whitesmoke; |
|||
} |
|||
|
|||
.active { |
|||
background-color: #3082aa; |
|||
color: black; |
|||
} |
|||
.active a { |
|||
color: #fff; |
|||
} |
|||
|
|||
.hide { |
|||
display: none; |
|||
} |
|||
|
|||
.myDIV:hover + .hide { |
|||
display: block; |
|||
color: grey; |
|||
} |
|||
|
|||
/* width */ |
|||
::-webkit-scrollbar { |
|||
width: 3px; |
|||
} |
|||
|
|||
/* Track */ |
|||
::-webkit-scrollbar-track { |
|||
box-shadow: inset 0 0 5px rgb(42, 42, 42); |
|||
border-radius: 10px; |
|||
} |
|||
|
|||
/* Handle */ |
|||
::-webkit-scrollbar-thumb { |
|||
background: rgb(180, 180, 180); |
|||
border-radius: 10px; |
|||
} |
|||
|
|||
.styleProSidebar > * { |
|||
color: whitesmoke !important; |
|||
background: #0d1214 !important; |
|||
} |
|||
|
|||
.styleProSidebarSM > * { |
|||
color: whitesmoke !important; |
|||
background: #0d1214 !important; |
|||
} |
|||
|
|||
.darkgrey { |
|||
background: #23282c; /* navbar */ |
|||
} |
|||
|
|||
.lightblue { |
|||
background: #3082aa; |
|||
} |
|||
|
|||
.lightblack { |
|||
background: #11181b; /* background bodi */ |
|||
} |
|||
|
|||
.MuiDataGrid-virtualScrollerContent * { |
|||
border: none !important; |
|||
} |
|||
|
|||
.MuiDataGrid-menuIcon * { |
|||
color: whitesmoke !important; |
|||
} |
|||
|
|||
p, |
|||
.MuiTablePagination-actions { |
|||
color: whitesmoke !important; |
|||
} |
|||
|
|||
.textField * { |
|||
color: rgb(172, 172, 172) !important; |
|||
border-color: rgb(59, 59, 59) !important; |
|||
} |
|||
|
|||
.darktext { |
|||
color: rgb(42, 42, 42) !important; |
|||
font-weight: 500 !important; |
|||
} |
|||
|
|||
.textGrey, |
|||
.Mui-disabled { |
|||
color: #7a7979 !important; |
|||
} |
|||
|
|||
|
|||
|
|||
.MuiPaper-root { |
|||
background: #23282c !important; |
|||
color: whitesmoke !important; |
|||
} |
|||
|
|||
#mui-1, |
|||
.MuiInput-root { |
|||
color: whitesmoke !important; |
|||
} |
|||
|
|||
.btn-hover:hover { |
|||
background-color: opacity(#000000, 0.9); |
|||
} |
|||
|
|||
.MuiDialog-paper { |
|||
border-color: #26698b !important; |
|||
background: #11181b !important; |
|||
-webkit-box-shadow: 5px 5px 15px 5px #000000 !important; |
|||
box-shadow: 5px 5px 15px 5px #000000 !important; |
|||
} |
|||
|
|||
.complete { |
|||
text-decoration: line-through !important; |
|||
} |
|||
|
|||
.css-1ps6pg7-MuiPaper-root, |
|||
.MuiDataGrid-panelContent, |
|||
.css-1sjjn1c-MuiDataGrid-panelContent { |
|||
background: #23282c !important; |
|||
} |
|||
|
|||
.MuiIconButton-sizeSmall * { |
|||
color: white !important ; |
|||
} |
|||
|
|||
table { |
|||
background-color: #23282c; |
|||
} |
|||
|
|||
.container-body { |
|||
display: flex; |
|||
flex-direction: column; |
|||
justify-content: center; |
|||
align-items: center; |
|||
min-height: 100vh; |
|||
width: 100vw; |
|||
} |
|||
|
|||
.container-body-paper { |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
justify-content: center; |
|||
min-height: 100vh; |
|||
width: 95vw; |
|||
} |
|||
|
|||
.wrapper-header { |
|||
width: 95vw; |
|||
display: flex; |
|||
justify-content: flex-end; |
|||
align-items: center; |
|||
} |
|||
|
|||
.header-title { |
|||
position: absolute; |
|||
left: 3%; |
|||
color: rgb(82, 82, 82); |
|||
font-size: 20px; |
|||
} |
|||
|
|||
.text-hover { |
|||
color: #3082aa !important; |
|||
} |
|||
|
|||
.wrapper-header-providers { |
|||
position: absolute; |
|||
width: 95vw; |
|||
display: flex; |
|||
justify-content: flex-end; |
|||
align-items: center; |
|||
top: 11%; |
|||
} |
|||
|
|||
.header-title-providers { |
|||
display: flex; |
|||
justify-content: space-between; |
|||
width: 93vw; |
|||
color: #3082aa; |
|||
font-size: 20px; |
|||
margin-bottom: 20px; |
|||
margin-top: 15%; |
|||
} |
|||
|
|||
.container-body-providers { |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
} |
|||
|
|||
|
|||
.header-title-neworder { |
|||
display: flex; |
|||
justify-content: space-between; |
|||
width: 65vw; |
|||
color: #3082aa; |
|||
font-size: 20px; |
|||
margin-bottom: 20px; |
|||
margin-top: 3%; |
|||
} |
|||
|
|||
.MuiMenuItem-root { |
|||
background: #23282c !important; |
|||
color: whitesmoke !important; |
|||
} |
|||
|
|||
.MuiMenuItem-paper { |
|||
background: #23282c !important; |
|||
color: whitesmoke !important; |
|||
} |
|||
Loading…
Reference in new issue