1+ import { generateUniqueSlug } from '../utils/slug.js'
2+ import { createEventSchema } from '../validations/event.validation.js' ;
3+
14import type { FastifyInstance , FastifyRequest , FastifyReply } from 'fastify' ;
2- import { createEventSchema , joinEventSchema } from '../validations/event.validation.js' ;
35
4- import { generateUniqueSlug } from '../utils/slug.js'
56
67
78type EventDetails = {
@@ -63,7 +64,7 @@ export async function eventRoutes(app:FastifyInstance) {
6364 const server = request . server as any ;
6465 if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return }
6566 if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return }
66- try { await request . jwtVerify ( ) } catch ( e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
67+ try { await request . jwtVerify ( ) } catch ( _e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) }
6768 } ] } , async ( request : FastifyRequest < {
6869 Body : {
6970 name : string ,
@@ -81,8 +82,8 @@ export async function eventRoutes(app:FastifyInstance) {
8182
8283 const { name, description, startDate, endDate, isPublic , location} = parsed . data
8384
84- let finalSlug = await generateUniqueSlug ( name , async ( slug ) => {
85- const existing = await app . prisma . event . findUnique ( { where : { slug : slug } } )
85+ const finalSlug = await generateUniqueSlug ( name , async ( slug ) => {
86+ const existing = await app . prisma . event . findUnique ( { where : { slug} } )
8687
8788 return ! ! existing
8889 } )
@@ -96,7 +97,7 @@ export async function eventRoutes(app:FastifyInstance) {
9697 name,
9798 description,
9899 slug : finalSlug ,
99- location : location ,
100+ location,
100101 startDate : startDateObj ,
101102 endDate : endDateObj ,
102103 isPublic : isPublic ?? true ,
@@ -105,7 +106,7 @@ export async function eventRoutes(app:FastifyInstance) {
105106 } )
106107
107108 return reply . status ( 201 ) . send ( newEvent ) ;
108- } catch ( error ) {
109+ } catch ( _error ) {
109110 app . log . error ( 'Failed to create event' ) ;
110111 return reply . status ( 500 ) . send ( { error : 'Failed to create event' } )
111112 }
@@ -155,7 +156,7 @@ export async function eventRoutes(app:FastifyInstance) {
155156 return response ;
156157 } )
157158
158- app . post ( '/:slug/join' , { preHandler : [ async ( request , reply ) => { const server = request . server as any ; if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return } if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return } try { await request . jwtVerify ( ) } catch ( e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) } } ] } , async ( request : FastifyRequest < { Params : { slug : string } } > , reply : FastifyReply ) => {
159+ app . post ( '/:slug/join' , { preHandler : [ async ( request , reply ) => { const server = request . server as any ; if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return } if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return } try { await request . jwtVerify ( ) } catch ( _e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) } } ] } , async ( request : FastifyRequest < { Params : { slug : string } } > , reply : FastifyReply ) => {
159160 const userId = ( request . user as any ) . id ;
160161 const paramsSlug = request . params . slug ;
161162
@@ -173,7 +174,7 @@ export async function eventRoutes(app:FastifyInstance) {
173174 await app . prisma . eventAttendee . create ( {
174175 data : {
175176 eventId : event . id ,
176- userId : userId ,
177+ userId,
177178 joinedAt : new Date ( )
178179 }
179180 } )
@@ -189,7 +190,7 @@ export async function eventRoutes(app:FastifyInstance) {
189190
190191 } )
191192
192- app . delete ( '/:slug/leave' , { preHandler : [ async ( request , reply ) => { const server = request . server as any ; if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return } if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return } try { await request . jwtVerify ( ) } catch ( e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) } } ] } , async ( request : FastifyRequest < { Params : { slug : string } } > , reply : FastifyReply ) => {
193+ app . delete ( '/:slug/leave' , { preHandler : [ async ( request , reply ) => { const server = request . server as any ; if ( typeof server ?. authenticate === 'function' ) { await server . authenticate ( request , reply ) ; return } if ( typeof ( app as any ) . authenticate === 'function' ) { await ( app as any ) . authenticate ( request , reply ) ; return } try { await request . jwtVerify ( ) } catch ( _e ) { reply . status ( 401 ) . send ( { error : 'Unauthorized' } ) } } ] } , async ( request : FastifyRequest < { Params : { slug : string } } > , reply : FastifyReply ) => {
193194 const userId = ( request . user as any ) . id ;
194195 const paramsSlug = request . params . slug ;
195196
@@ -207,7 +208,7 @@ export async function eventRoutes(app:FastifyInstance) {
207208 await app . prisma . eventAttendee . delete ( {
208209 where : {
209210 userId_eventId : {
210- userId : userId ,
211+ userId,
211212 eventId : event . id
212213 }
213214 }
0 commit comments