diff --git a/apps/backend/src/band/band.controller.ts b/apps/backend/src/band/band.controller.ts index 01d7846..2eab1f1 100644 --- a/apps/backend/src/band/band.controller.ts +++ b/apps/backend/src/band/band.controller.ts @@ -32,4 +32,24 @@ export class BandController { remove(@Param('id', ParseIntPipe) id: number) { return this.bandService.remove(id); } + + @Get(':id/members') + findMembers(@Param('id', ParseIntPipe) id: number) { + return this.bandService.findMembers(id); + } + + @Post(':id/members/:userId') + addMember(@Param('id', ParseIntPipe) bandId: number, @Param('userId', ParseIntPipe) userId: number) { + return this.bandService.addMember(bandId, userId); + } + + @Delete(':id/members/:userId') + removeMember(@Param('id', ParseIntPipe) bandId: number, @Param('userId', ParseIntPipe) userId: number) { + return this.bandService.removeMember(bandId, userId); + } + + @Patch(':id/members/:userId') + approveMember(@Param('id', ParseIntPipe) bandId: number, @Param('userId', ParseIntPipe) userId: number) { + return this.bandService.approveMember(bandId, userId); + } } diff --git a/apps/backend/src/band/band.service.ts b/apps/backend/src/band/band.service.ts index bc2a2c6..65ddc07 100644 --- a/apps/backend/src/band/band.service.ts +++ b/apps/backend/src/band/band.service.ts @@ -1,5 +1,5 @@ import { Injectable, NotFoundException } from '@nestjs/common'; -import { BandMembership } from '@prisma/client'; +import { BandMembership, BandMembershipStatus } from '@prisma/client'; import { PrismaService } from 'nestjs-prisma'; import { User } from 'src/users/entities/user.entity'; @@ -16,7 +16,9 @@ export class BandService { } async findAll(): Promise { - const res = await this.prisma.band.findMany(); + const res = await this.prisma.band.findMany({ + include: { members: { include: { user: { select: { name: true } } } } }, + }); return res; } @@ -77,4 +79,15 @@ export class BandService { throw new NotFoundException('No member found'); } } + + async approveMember(bandId: number, userId: number) { + try { + return await this.prisma.bandMembership.updateMany({ + where: { bandId, userId }, + data: { status: BandMembershipStatus.ACCEPTED }, + }); + } catch (error) { + throw new NotFoundException('No member found'); + } + } }