@@ -48,27 +48,47 @@ app.get('/fetchReviews', async (req, res) => {
48
48
49
49
// Express route to fetch reviews by a particular dealer
50
50
app . get ( '/fetchReviews/dealer/:id' , async ( req , res ) => {
51
- try {
52
- const documents = await Reviews . find ( { dealership : req . params . id } ) ;
53
- res . json ( documents ) ;
54
- } catch ( error ) {
55
- res . status ( 500 ) . json ( { error : 'Error fetching documents' } ) ;
56
- }
51
+ try {
52
+ const documents = await Reviews . find ( { dealership : req . params . id } ) ;
53
+ res . json ( documents ) ;
54
+ } catch ( error ) {
55
+ res . status ( 500 ) . json ( { error : 'Error fetching documents' } ) ;
56
+ }
57
57
} ) ;
58
58
59
59
// Express route to fetch all dealerships
60
60
app . get ( '/fetchDealers' , async ( req , res ) => {
61
- //Write your code here
61
+ //Write your code here
62
+ try {
63
+ const documents = await Dealerships . find ( ) ;
64
+ res . json ( documents ) ;
65
+ } catch ( error ) {
66
+ res . status ( 500 ) . json ( { error : 'Error fetching documents' } ) ;
67
+ }
62
68
} ) ;
63
69
64
70
// Express route to fetch Dealers by a particular state
65
71
app . get ( '/fetchDealers/:state' , async ( req , res ) => {
66
- //Write your code here
67
- } ) ;
72
+ //Write your code here
73
+ try {
74
+ const stateParam = req . params . state ;
75
+ const documents = await Dealerships . find ( { state : new RegExp ( `^${ stateParam } $` , 'i' ) } ) ;
76
+ res . json ( documents ) ;
77
+ } catch ( error ) {
78
+ console . error ( 'Error fetching dealers by state:' , error ) ;
79
+ res . status ( 500 ) . json ( { error : 'Error fetching dealers by state' } ) ;
80
+ }
81
+ } ) ;
68
82
69
83
// Express route to fetch dealer by a particular id
70
84
app . get ( '/fetchDealer/:id' , async ( req , res ) => {
71
- //Write your code here
85
+ //Write your code here
86
+ try {
87
+ const documents = await Dealerships . find ( { id : req . params . id } ) ;
88
+ res . json ( documents ) ;
89
+ } catch ( error ) {
90
+ res . status ( 500 ) . json ( { error : 'Error fetching documents' } ) ;
91
+ }
72
92
} ) ;
73
93
74
94
//Express route to insert review
0 commit comments