Skip to content

Commit 6778e98

Browse files
author
Luis Barbosa
committed
query bookings data from service created
1 parent dae180b commit 6778e98

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const Petshop = use('App/Models/Petshop');
4+
const Booking = use('App/Models/Booking');
5+
6+
class QueryServiceController {
7+
async index({params}){
8+
const petshop = await Petshop.findByOrFail('username', params.petshop_username);
9+
10+
const services = await petshop.services().fetch();
11+
12+
return services;
13+
}
14+
15+
async show({params}){
16+
const bookings = await Booking.query().where('service_id',params.id).fetch()
17+
18+
return bookings;
19+
}
20+
}
21+
22+
module.exports = QueryServiceController

start/routes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Route.group(()=>{
3232
Route.resource('pets', 'PetController').apiOnly();
3333
}).middleware('auth');
3434

35+
//QUERY SERVICE
36+
Route.group(()=>{
37+
Route.resource(':petshop_username/services', 'QueryServiceController').only(['index', 'show']);
38+
}).middleware('auth');
39+
3540
//PETSHOP
3641
Route.group(()=>{
3742
Route.resource('petshops', 'PetshopController').apiOnly();
@@ -50,4 +55,4 @@ Route.group(()=>{
5055
//VET SERVICE
5156
Route.group(()=>{
5257
Route.resource('vet/services', 'VetServiceController').apiOnly();
53-
}).middleware('auth');
58+
}).middleware('auth');

0 commit comments

Comments
 (0)