From 36b9e2f1d93d31903223a85f018586dd33dc90be Mon Sep 17 00:00:00 2001 From: Ethan Zitting Date: Mon, 17 Jan 2022 17:33:30 -0600 Subject: [PATCH] wip: fix merge conflicts --- src/app.ts | 2 ++ src/routes/events.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/routes/events.ts diff --git a/src/app.ts b/src/app.ts index 1af4f4c..05716d8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,7 @@ import fastifyTypeorm from 'fastify-typeorm-plugin'; import { dbConfig } from './database'; import { jobs } from './routes/jobs'; +import { events } from './routes/events'; import { auth } from './routes/auth'; export function build(opts: FastifyServerOptions = {}): FastifyInstance { @@ -12,6 +13,7 @@ export function build(opts: FastifyServerOptions = {}): FastifyInstance { app.register(fastifyTypeorm, dbConfig); app.register(jobs, { prefix: '/jobs' }); + app.register(events, { prefix: '/events'}); app.register(auth, { prefix: '/auth' }); return app; diff --git a/src/routes/events.ts b/src/routes/events.ts new file mode 100644 index 0000000..5ad2f9c --- /dev/null +++ b/src/routes/events.ts @@ -0,0 +1,29 @@ +import type { FastifyPluginAsync } from 'fastify'; +import type { FromSchema } from 'json-schema-to-ts'; +import { Event } from '../entities/Event'; + +const findEventParams = { + type: 'object', + properties: { + eventId: { type: 'number' }, + }, + required: ['eventId'], +} as const; + +export const events: FastifyPluginAsync = async (app) => { + app.get('/', async (req, reply) => { + const events = await app.orm.manager.find(Event); + return events; + }); + + app.route<{ Params: FromSchema }>({ + url: '/:eventId', + method: 'GET', + schema: { params: findEventParams }, + handler: async (req, reply) => { + const eventId = req.params.eventId; + const event = await app.orm.manager.findOne(Event,eventId); + return event; + }, + }); +};