File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed
Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 11import notFound from "../Err/notfound.js" ;
2- import { authors } from "../models/index.js" ;
2+ import { authors , books } from "../models/index.js" ;
33
44
55class AuthorController {
@@ -23,6 +23,7 @@ class AuthorController{
2323 next ( err ) ;
2424 }
2525 } ;
26+
2627
2728 static listAuthorById = async ( req , res , next ) => {
2829 try {
@@ -63,6 +64,8 @@ class AuthorController{
6364 next ( new notFound ( "ID author not found" ) ) ;
6465 }
6566 } ;
67+
68+
6669}
6770
6871export default AuthorController ;
Original file line number Diff line number Diff line change @@ -16,6 +16,28 @@ class BookController{
1616 next ( err ) ;
1717 }
1818} ;
19+
20+ static byfilter = async ( req , res , next ) => {
21+ try {
22+ let { publisher, title} = req . query ;
23+
24+ const regex = new RegExp ( title , "i" ) ;
25+
26+ const search = { }
27+
28+ if ( publisher ) search . publisher = publisher ;
29+ if ( title ) search . title = { $regex : title , $options : "i" } ;
30+
31+ const result = await books . find ( {
32+ "publisher" :publisher ,
33+ "title" : title
34+ } )
35+ res . staus ( 200 ) . send ( result )
36+ }
37+ catch ( err ) {
38+ next ( err )
39+ }
40+ }
1941
2042 //GET BY ID
2143 static listarLivroPorId = async ( req , res , next ) => {
Original file line number Diff line number Diff line change 1- import globalValidator from "./globalValidator.js" ;
1+ // import globalValidator from "./globalValidator.js";
22import books from "./Books.js" ;
33import authors from "./Author.js" ;
44
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const router = express.Router();
55
66router
77 . get ( "/books" , BookController . listBooks )
8+ . get ( "/books/serach" , BookController . byfilter )
89 . get ( "/books/:id" , BookController . listBookById )
910 . post ( "/books" , BookController . registerBook )
1011 . put ( "/books/:id" , BookController . updateBook )
You can’t perform that action at this time.
0 commit comments