diff --git a/apps/platform/api/src/booking/repository/getAllBooking.ts b/apps/platform/api/src/booking/repository/getAllBooking.ts new file mode 100644 index 0000000000..549042d8ac --- /dev/null +++ b/apps/platform/api/src/booking/repository/getAllBooking.ts @@ -0,0 +1,5 @@ +import { db } from '../../lib/db'; + +export const getAllBooking = async () => { + return await db.selectFrom('Booking').selectAll().execute(); +}; diff --git a/apps/platform/api/src/booking/repository/getBookingById.ts b/apps/platform/api/src/booking/repository/getBookingById.ts new file mode 100644 index 0000000000..1a77b4133d --- /dev/null +++ b/apps/platform/api/src/booking/repository/getBookingById.ts @@ -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(); +}; diff --git a/apps/platform/api/src/routes/booking/get.ts b/apps/platform/api/src/routes/booking/get.ts new file mode 100644 index 0000000000..2c7cf05b6e --- /dev/null +++ b/apps/platform/api/src/routes/booking/get.ts @@ -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 => { + 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;