Skip to content
Open
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
37 changes: 16 additions & 21 deletions backend/src/events/dto/create-event.dto.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
import {
IsString,
IsNotEmpty,
IsOptional,
IsUrl,
IsDateString,
IsInt,
IsOptional,
Min,
IsEnum,
} from 'class-validator';
import { EventStatus } from '../entities/event.entity';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class CreateEventDto {
@ApiProperty()
@IsString()
@IsNotEmpty()
title: string;

@ApiProperty()
@IsString()
@IsNotEmpty()
description: string;

@IsOptional()
@IsUrl()
coverImageUrl?: string;
@ApiProperty()
@IsString()
hostName: string;

@ApiProperty({ example: '2026-07-01T10:00:00Z' })
@IsDateString()
@IsNotEmpty()
startDate: string;

@ApiProperty({ example: '2026-07-01T12:00:00Z' })
@IsDateString()
@IsNotEmpty()
endDate: string;

@ApiProperty()
@IsString()
@IsNotEmpty()
venue: string;
location: string;

@ApiProperty()
@IsInt()
@Min(1)
capacity: number;

@IsInt()
@Min(0)
price: number;

@ApiPropertyOptional()
@IsOptional()
@IsEnum(EventStatus)
status?: EventStatus;
}
@IsString()
imageUrl?: string;
}
53 changes: 50 additions & 3 deletions backend/src/events/dto/update-event.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateEventDto } from './create-event.dto';
import {
IsString,
IsDateString,
IsInt,
IsOptional,
Min,
} from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';

export class UpdateEventDto extends PartialType(CreateEventDto) {}
export class UpdateEventDto {
@ApiPropertyOptional()
@IsOptional()
@IsString()
title?: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
description?: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
hostName?: string;

@ApiPropertyOptional({ example: '2026-07-01T10:00:00Z' })
@IsOptional()
@IsDateString()
startDate?: string;

@ApiPropertyOptional({ example: '2026-07-01T12:00:00Z' })
@IsOptional()
@IsDateString()
endDate?: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
location?: string;

@ApiPropertyOptional()
@IsOptional()
@IsInt()
@Min(1)
capacity?: number;

@ApiPropertyOptional()
@IsOptional()
@IsString()
imageUrl?: string;
}
38 changes: 38 additions & 0 deletions backend/src/events/entities/event-rsvp.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
CreateDateColumn,
Unique,
JoinColumn,
} from 'typeorm';
import { Event } from './event.entity';
import { User } from '../../users/entities/user.entity';

@Entity('event_rsvps')
@Unique(['eventId', 'userId'])
export class EventRsvp {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column('uuid')
eventId: string;

@ManyToOne(() => Event, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'eventId' })
event: Event;

@Column('uuid')
userId: string;

@ManyToOne(() => User, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'userId' })
user: User;

@CreateDateColumn()
rsvpedAt: Date;

@Column({ default: false })
attended: boolean;
}
25 changes: 9 additions & 16 deletions backend/src/events/entities/event.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import {
UpdateDateColumn,
} from 'typeorm';

export enum EventStatus {
DRAFT = 'draft',
PUBLISHED = 'published',
CANCELLED = 'cancelled',
COMPLETED = 'completed',
}

@Entity('events')
export class Event {
@PrimaryGeneratedColumn('uuid')
Expand All @@ -24,8 +17,8 @@ export class Event {
@Column({ type: 'text' })
description: string;

@Column({ nullable: true })
coverImageUrl?: string;
@Column()
hostName: string;

@Column({ type: 'timestamptz' })
startDate: Date;
Expand All @@ -34,19 +27,19 @@ export class Event {
endDate: Date;

@Column()
venue: string;
location: string;

@Column({ type: 'int' })
capacity: number;

@Column({ type: 'int', default: 0 })
price: number;
@Column({ nullable: true })
imageUrl: string;

@Column({ type: 'enum', enum: EventStatus, default: EventStatus.DRAFT })
status: EventStatus;
@Column({ default: true })
isPublic: boolean;

@Column({ type: 'uuid', nullable: true })
createdBy: string;
@Column({ default: false })
isCancelled: boolean;

@CreateDateColumn()
createdAt: Date;
Expand Down
146 changes: 98 additions & 48 deletions backend/src/events/events.controller.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,124 @@
import { Controller, Post, Body, UseGuards, Get, Param, Patch, Delete, Query } from '@nestjs/common';
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
Query,
ParseUUIDPipe,
UseGuards,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { EventsService } from './events.service';
import { CreateEventDto } from './dto/create-event.dto';
import { UpdateEventDto } from './dto/update-event.dto';
import { JwtAuthGuard } from '../auth/guard/jwt.auth.guard';
import { RolesGuard } from '../auth/guard/roles.guard';
import { Roles } from '../auth/decorators/roles.decorators';
import { UserRole } from '../auth/common/enum/user-role-enum';
import { CurrentUser } from '../auth/decorators/current.user.decorators';
import { Public } from '../auth/decorators/public.decorator';
import { UserRole } from '../users/enums/userRoles.enum';
import { GetCurrentUser } from '../auth/decorators/getCurrentUser.decorator';

@ApiTags('events')
@ApiBearerAuth()
@Controller('events')
export class EventsController {
constructor(private readonly eventsService: EventsService) {}

@Post()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
create(@Body() createEventDto: CreateEventDto, @CurrentUser() user) {
return this.eventsService.create(createEventDto, user.id);
@UseGuards(RolesGuard)
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Create an event (Admin only)' })
async create(@Body() dto: CreateEventDto) {
const event = await this.eventsService.create(dto);
return { message: 'Event created successfully', data: event };
}

@Get('my')
@UseGuards(JwtAuthGuard)
getMyRegistrations(@CurrentUser() user) {
return this.eventsService.getMyRegistrations(user.id);
}

@Get()
@Public()
findAll(@CurrentUser() user) {
const isPublic = !user || user.role !== UserRole.ADMIN;
return this.eventsService.findAll(isPublic);
@Patch(':id')
@UseGuards(RolesGuard)
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
@ApiOperation({ summary: 'Update an event (Admin only)' })
async update(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: UpdateEventDto,
) {
const event = await this.eventsService.update(id, dto);
return { message: 'Event updated successfully', data: event };
}

@Get(':id')
@Public()
findOne(@Param('id') id: string) {
return this.eventsService.findOne(id);
@Delete(':id')
@UseGuards(RolesGuard)
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Cancel an event (Admin only, soft delete)' })
async cancel(@Param('id', ParseUUIDPipe) id: string) {
const event = await this.eventsService.cancel(id);
return { message: 'Event cancelled successfully', data: event };
}

@Patch(':id')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
update(@Param('id') id: string, @Body() updateEventDto: UpdateEventDto) {
return this.eventsService.update(id, updateEventDto);
@Get()
@ApiOperation({ summary: 'List upcoming non-cancelled events' })
@ApiQuery({ name: 'page', required: false })
@ApiQuery({ name: 'limit', required: false })
async findAll(
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
const result = await this.eventsService.findAll(
page ? Number(page) : undefined,
limit ? Number(limit) : undefined,
);
return { message: 'Events retrieved successfully', ...result };
}

@Delete(':id')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
remove(@Param('id') id: string) {
return this.eventsService.remove(id);
@Get(':id')
@ApiOperation({ summary: 'Get event details with RSVP count' })
async findOne(@Param('id', ParseUUIDPipe) id: string) {
const event = await this.eventsService.findById(id);
return { message: 'Event retrieved successfully', data: event };
}

@Post(':id/register')
@UseGuards(JwtAuthGuard)
register(@Param('id') id: string, @CurrentUser() user) {
return this.eventsService.register(id, user.id);
@Post(':id/rsvp')
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'RSVP to an event' })
async rsvp(
@Param('id', ParseUUIDPipe) id: string,
@GetCurrentUser('id') userId: string,
) {
const rsvp = await this.eventsService.rsvp(id, userId);
return { message: 'RSVP confirmed', data: rsvp };
}

@Delete(':id/register')
@UseGuards(JwtAuthGuard)
cancelRegistration(@Param('id') id: string, @CurrentUser() user) {
return this.eventsService.cancelRegistration(id, user.id);
@Delete(':id/rsvp')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Cancel your RSVP' })
async cancelRsvp(
@Param('id', ParseUUIDPipe) id: string,
@GetCurrentUser('id') userId: string,
) {
await this.eventsService.cancelRsvp(id, userId);
return { message: 'RSVP cancelled' };
}

@Get(':id/registrations')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
getRegistrations(@Param('id') id: string) {
return this.eventsService.getRegistrations(id);
@Get(':id/attendees')
@UseGuards(RolesGuard)
@Roles(UserRole.ADMIN, UserRole.SUPER_ADMIN)
@ApiOperation({ summary: 'List event attendees (Admin only)' })
@ApiQuery({ name: 'page', required: false })
@ApiQuery({ name: 'limit', required: false })
async findAttendees(
@Param('id', ParseUUIDPipe) id: string,
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
const result = await this.eventsService.findAttendees(
id,
page ? Number(page) : undefined,
limit ? Number(limit) : undefined,
);
return { message: 'Attendees retrieved successfully', ...result };
}
}
}
Loading
Loading