Skip to content

Commit

Permalink
Cambios obtención Orders usuario
Browse files Browse the repository at this point in the history
  • Loading branch information
UO271548 committed Apr 14, 2022
1 parent e2ef4d2 commit ef11fd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions restapi/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express, { Request, Response, Router } from 'express';
import {check} from 'express-validator';
import { addOrder, findOrdersByUserDni, getDeliveryCosts } from './controllers/OrderController';
import { addOrder, findOrdersByUserEmail, getDeliveryCosts } from './controllers/OrderController';
import {findRocks, addRock, deleteRock, findRocksSedimentary, findRocksMetamorphic, findRocksFiery, findByCritery} from './controllers/RockController';
import {findUsers, addUser, deleteUser, loginUser, logout} from './controllers/UserController';
const User = require("./models/User");
Expand Down Expand Up @@ -37,7 +37,7 @@ api.post("/rocks/add", addRock);
api.post("/rocks/delete", deleteRock);

//Methods for product of the app
api.get("/orders/userList", findOrdersByUserDni);
api.get("/orders/userList", findOrdersByUserEmail);

api.post("/orders/add", addOrder);

Expand Down
14 changes: 8 additions & 6 deletions restapi/controllers/OrderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ const geocoder = NodeGeocoder(options);
const Order = require("../models/Order");


export const findOrdersByUserDni = async (req:Request, res:Response) => {
let dni = req.body.dni;
let query = {userDni : dni.toString()};
export const findOrdersByUserEmail = async (req:Request, res:Response) => {
let email = req.body.email;
let query = {userEmail : email.toString()};
const users = await Order.find(query)
res.send(users).json();
res.setHeader('Content-Type', 'application/json');
res.send(users);
};


export const addOrder = async (req:Request, res:Response): Promise<any> => {
const crypto = require('crypto');
const orderId = crypto.randomBytes(60);

let userDni = req.body.dni;
let email = req.body.email;
let price = req.body.price;
let productId = req.body.productId;

let order = new Order({
orderId: orderId,
dni: userDni,
userEmail: email,
price: price,
productId: productId
});
Expand Down
2 changes: 1 addition & 1 deletion restapi/models/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mongooseOrders = require("mongoose")
const orderSchema = mongooseOrders.Schema({
orderId : String,
price : Number,
userDni : String,
userEmail : String,
productId : String
},{
versionKey: false
Expand Down

0 comments on commit ef11fd6

Please sign in to comment.