Skip to content

Commit

Permalink
Updated the Event FindOne function to match the requirements for the …
Browse files Browse the repository at this point in the history
…frontend (#41)

* Updated the Event FindOne function

* Requested Change
  • Loading branch information
VarMattew authored Aug 14, 2024
1 parent 875ccc3 commit 726f9a0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
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

0 comments on commit 726f9a0

Please sign in to comment.