Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actualizar producto (admin) completo #216

Merged
merged 5 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions restapi/routes/juguete.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ jugueteRouter.get("/withStock", async (req:Request,res:Response) =>{
jugueteRouter.get("/:nombre", async (req:Request,res:Response) =>{
try{
let filter ={nombre : req.params.nombre}
console.log(filter);
let juguete = await Juguete.findOne(filter);
console.log(juguete);
if(juguete){
res.json(juguete);
}
Expand Down Expand Up @@ -81,6 +83,7 @@ async function borrarImagen(imagen:String){
*/
jugueteRouter.post("/", async (req:Request,res:Response) =>{
try{
console.log("NUEVO JUGUETE");
let nuevoJuguete = {
nombre : req.body.nombre,
descripcion: req.body.descripcion,
Expand All @@ -89,6 +92,7 @@ jugueteRouter.post("/", async (req:Request,res:Response) =>{
categoria: req.body.categoria,
stock: req.body.stock
};
console.log(nuevoJuguete);
let juguete = await Juguete.findOne({nombre: nuevoJuguete.nombre});
if(juguete){
res.send("Este juguete ya existe");
Expand Down Expand Up @@ -116,8 +120,7 @@ jugueteRouter.post("/update/:nombre", async (req:Request,res:Response) =>{
try{
const filter = { nombre : req.params.nombre }
const update = { nombre : req.body.nombre, descripcion : req.body.descripcion,
precio : req.body.precio, imagen : req.body.imagen, categoria : req.body.categoria,
cantidad : req.body.cantidad, stock: req.body.stock}
categoria : req.body.categoria, precio : req.body.precio}
let jugueteActualizado = await Juguete.findOneAndUpdate(filter, update, { new:true});
if(jugueteActualizado){
res.send("El juguete se ha actualizado correctamente");
Expand Down
4 changes: 2 additions & 2 deletions restapi/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let bd = require('./modules/gestorDB')
let {config} = require('./modules/cloudinary');

const options: cors.CorsOptions = {
//origin: ['http://localhost:3000']
origin: ['https://dede-es2a-webapp.herokuapp.com']
origin: ['http://localhost:3000']
//origin: ['https://dede-es2a-webapp.herokuapp.com']
};

const metricsMiddleware:RequestHandler = promBundle({includeMethod: true});
Expand Down
Loading