Problem
POST /opportunity-volunteer fails with a DB unique constraint violation when a link between the same (opportunityId, volunteerId) pair already exists. The entity has @Unique(["opportunityId", "volunteerId"]), so the DB rejects the INSERT and the FE shows "Something went wrong".
There is no intentional limitation on re-suggesting a volunteer for an opportunity — coordinators should be able to re-suggest (e.g. reset to pending) at any time.
Expected behaviour
POST /opportunity-volunteer with an existing (opportunityId, volunteerId) pair should update the existing record's status to the requested value instead of failing.
Fix
In src/server/routes/m2m/opportunity-volunteer.routes.ts, change the POST handler to upsert:
const opportunityVolunteer = new OpportunityVolunteer(request.body);
const existing = await opportunityVolunteerRepository.findOne({
where: {
opportunityId: opportunityVolunteer.opportunityId,
volunteerId: opportunityVolunteer.volunteerId,
},
});
if (existing) {
opportunityVolunteerRepository.merge(existing, { status: opportunityVolunteer.status });
await opportunityVolunteerRepository.save(existing);
} else {
await opportunityVolunteerRepository.save(opportunityVolunteer);
}
Affected file
src/server/routes/m2m/opportunity-volunteer.routes.ts
Problem
POST /opportunity-volunteerfails with a DB unique constraint violation when a link between the same(opportunityId, volunteerId)pair already exists. The entity has@Unique(["opportunityId", "volunteerId"]), so the DB rejects the INSERT and the FE shows "Something went wrong".There is no intentional limitation on re-suggesting a volunteer for an opportunity — coordinators should be able to re-suggest (e.g. reset to
pending) at any time.Expected behaviour
POST /opportunity-volunteerwith an existing(opportunityId, volunteerId)pair should update the existing record'sstatusto the requested value instead of failing.Fix
In
src/server/routes/m2m/opportunity-volunteer.routes.ts, change the POST handler to upsert:Affected file
src/server/routes/m2m/opportunity-volunteer.routes.ts