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
13 changes: 12 additions & 1 deletion backend/src/bounty/bounty.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ export class BountyController {
) {
return this.service.reviewWork(id, dto, req.user.userId);
}
}

/**
* Soft delete a bounty
* DELETE /bounties/:id
*/
@UseGuards(JwtAuthGuard)
@Delete(':id')
async remove(@Param('id') id: string, @Request() req: any) {
return this.service.remove(id, req.user.userId);
}

}
29 changes: 24 additions & 5 deletions backend/src/bounty/bounty.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BountyService {

async findOne(id: string) {
const bounty = await this.prisma.bounty.findUnique({
where: { id },
where: { id, deletedAt: null },
include: {
creator: true,
assignee: true,
Expand All @@ -47,7 +47,7 @@ export class BountyService {

async get(id: string) {
const bounty = await this.prisma.bounty.findUnique({
where: { id },
where: { id, deletedAt: null },
include: { creator: true, assignee: true },
});
if (!bounty) throw new NotFoundException('Bounty not found');
Expand All @@ -65,7 +65,7 @@ export class BountyService {
const page = filters.page ?? 0;
const size = filters.size ?? 20;

const where: any = {};
const where: any = { deletedAt: null };

// Default to OPEN status if no status filter provided
if (filters.status) {
Expand Down Expand Up @@ -108,7 +108,7 @@ export class BountyService {
}
: {};

const where: any = {};
const where: any = { deletedAt: null };
if (Object.keys(text).length) where.AND = [text];
if (guildId) where.guildId = guildId;

Expand Down Expand Up @@ -522,4 +522,23 @@ export class BountyService {
};
}
}
}

/**
* Soft delete a bounty (sets deletedAt timestamp)
* Only the creator can delete their own bounty
*/
async remove(id: string, userId: string) {
const bounty = await this.prisma.bounty.findUnique({
where: { id, deletedAt: null },
});
if (!bounty) throw new NotFoundException('Bounty not found');
if (bounty.creatorId !== userId)
throw new ForbiddenException('Only creator can delete bounty');

return this.prisma.bounty.update({
where: { id },
data: { deletedAt: new Date() },
});
}

}