add routes for booking

platform-api-poc-fastify
Ryukemeister 2023-10-26 13:05:07 +05:30
parent 035191125e
commit 630a1f38a1
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,5 @@
import { db } from '../../lib/db';
export const getAllBooking = async () => {
return await db.selectFrom('Booking').selectAll().execute();
};

View File

@ -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();
};

View File

@ -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;