Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add events endpoint #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions src/routes/events.ts
Original file line number Diff line number Diff line change
@@ -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<typeof findEventParams> }>({
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;
},
});
};