Skip to content

Commit

Permalink
New endpoints, approve members
Browse files Browse the repository at this point in the history
  • Loading branch information
Danka Marcell committed Dec 12, 2024
1 parent fa6fcbe commit 45bc8f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions apps/backend/src/band/band.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 15 additions & 2 deletions apps/backend/src/band/band.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,7 +16,9 @@ export class BandService {
}

async findAll(): Promise<Band[]> {
const res = await this.prisma.band.findMany();
const res = await this.prisma.band.findMany({
include: { members: { include: { user: { select: { name: true } } } } },
});
return res;
}

Expand Down Expand Up @@ -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');
}
}
}

0 comments on commit 45bc8f0

Please sign in to comment.