Skip to content

Commit

Permalink
Merge pull request #163 from Arquisoft/Ignacio_BaseDeDatos
Browse files Browse the repository at this point in the history
Corrección Filtrado
  • Loading branch information
valydumitru01 authored Apr 14, 2022
2 parents f449733 + 2cc990e commit 1fe9118
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions restapi/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express, { Request, Response, Router } from 'express';
import {check} from 'express-validator';
import { addOrder, findOrdersByUserDni, getDeliveryCosts } from './controllers/OrderController';
import {findRocks, addRock, deleteRock, findRocksSedimentary, findRocksMetamorphic, findRocksFiery, findByCritery} from './controllers/RockController';
import {findRocks, addRock, deleteRock, findRocksSedimentary, findRocksMetamorphic, findRocksFiery, findByCriteryText, findByCriteryNumber} from './controllers/RockController';
import {findUsers, addUser, deleteUser, loginUser, logout} from './controllers/UserController';
const User = require("./models/User");
const Rock = require("./models/Rock");
Expand All @@ -28,7 +28,9 @@ api.get("/rocks/list/metamorphic", findRocksMetamorphic);

api.get("/rocks/list/fiery", findRocksFiery);

api.get("/rocks/list/critery", findByCritery);
api.get("/rocks/list/criteryText", findByCriteryText);

api.get("/rocks/list/criteryNumber", findByCriteryNumber);

api.post("/rocks/add", addRock);

Expand Down
12 changes: 10 additions & 2 deletions restapi/controllers/RockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ export const findRocksMetamorphic = async (req:Request, res:Response) => {
res.send(rocks);
};

export const findByCritery = async (req:Request, res:Response) => {
export const findByCriteryText = async (req:Request, res:Response) => {
let critery = req.body.critery;
const rocks = await Rock.find({critery})
const rocks = await Rock.find({$or:[{name : critery}, {type : critery}, {texture : critery} ]})
res.setHeader('Content-Type', 'application/json');
res.status(200);
res.send(rocks);
}

export const findByCriteryNumber = async (req:Request, res:Response) => {
let critery = req.body.critery;
const rocks = await Rock.find({$or:[{price : critery}, {mohsHardness : critery}, {density : critery}]})
res.setHeader('Content-Type', 'application/json');
res.status(200);
res.send(rocks);
Expand Down

0 comments on commit 1fe9118

Please sign in to comment.