add routes for booking
parent
035191125e
commit
630a1f38a1
|
@ -0,0 +1,5 @@
|
||||||
|
import { db } from '../../lib/db';
|
||||||
|
|
||||||
|
export const getAllBooking = async () => {
|
||||||
|
return await db.selectFrom('Booking').selectAll().execute();
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { db } from '../../lib/db';
|
||||||
|
|
||||||
|
export const getBookingById = async (id: number) => {
|
||||||
|
return await db.selectFrom('Booking').selectAll().where('id', '=', id).executeTakeFirst();
|
||||||
|
};
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { getAllBooking } from '../../booking/repository/getAllBooking';
|
||||||
|
import { getBookingById } from '../../booking/repository/getBookingById';
|
||||||
|
import type { FastifyPluginAsync } from 'fastify';
|
||||||
|
|
||||||
|
const get: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
||||||
|
fastify.get('/', async (request, reply) => {
|
||||||
|
const booking = getAllBooking();
|
||||||
|
|
||||||
|
return booking;
|
||||||
|
});
|
||||||
|
|
||||||
|
fastify.get<{ Params: { id: number } }>('/:id', async (request, reply) => {
|
||||||
|
const { id } = request.params;
|
||||||
|
const booking = getBookingById(id);
|
||||||
|
|
||||||
|
return booking;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default get;
|
Loading…
Reference in New Issue