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

Updated the Event FindOne function to match the requirements for the frontend #41

Merged
merged 4 commits into from
Aug 14, 2024
Merged
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
15 changes: 15 additions & 0 deletions apps/backend/src/drink-action/dto/drinkAction-with-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Drink } from 'src/drinks/entities/drink.entity';
import { User } from 'src/users/entities/user.entity';

import { DrinkAction } from '../entities/drink-action.entity';

export class DrinkActionWithDrinkAndUser extends DrinkAction {
/**
* Drink that was consumed
*/
drink: Drink;
/*
* User data for the DrinkAction
*/
user: User;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DrinkActionWithDrinkAndUser } from 'src/drink-action/dto/drinkAction-with-user.dto';
import { User } from 'src/users/entities/user.entity';

import { Event } from '../entities/event.entity';

export class EventWithDrinkActionsAndUser extends Event {
/**
* List of DrinkActions associated with the event
*/
drinkActions: DrinkActionWithDrinkAndUser[];
/**
* The owner of the Event
*/
owner: User;
}
6 changes: 4 additions & 2 deletions apps/backend/src/events/events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiQuery, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiOkResponse, ApiQuery, ApiTags } from '@nestjs/swagger';
import { User } from 'src/users/entities/user.entity';

import { CreateEventDto } from './dto/create-event.dto';
import { EventWithDrinkActionsAndUser } from './dto/event-with-drinkActions-and-user.dto';
import { UpdateEventDto } from './dto/update-event.dto';
import { Event } from './entities/event.entity';
import { EventsService } from './events.service';
Expand Down Expand Up @@ -45,7 +46,8 @@ export class EventsController {
}

@Get(':id')
async findOne(@Param('id', new ParseUUIDPipe()) id: string): Promise<Event> {
@ApiOkResponse({ type: EventWithDrinkActionsAndUser })
async findOne(@Param('id', new ParseUUIDPipe()) id: string): Promise<EventWithDrinkActionsAndUser> {
return this.eventsService.findOne(id);
}

Expand Down
16 changes: 14 additions & 2 deletions apps/backend/src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PrismaService } from 'nestjs-prisma';
import { User } from 'src/users/entities/user.entity';

import { CreateEventDto } from './dto/create-event.dto';
import { EventWithDrinkActionsAndUser } from './dto/event-with-drinkActions-and-user.dto';
import { UpdateEventDto } from './dto/update-event.dto';

@Injectable()
Expand All @@ -29,8 +30,19 @@ export class EventsService {
});
}

async findOne(id: string): Promise<Event> {
const event = await this.prisma.event.findUnique({ where: { id } });
async findOne(id: string): Promise<EventWithDrinkActionsAndUser> {
const event = await this.prisma.event.findUnique({
where: { id },
include: {
owner: true,
drinkActions: {
include: {
drink: true,
user: true,
},
},
},
});
if (!event) {
throw new NotFoundException('Event not found');
}
Expand Down