Skip to content

Fix suggest volunteer to opportunity failing on duplicate pair #655

@nadavosa

Description

@nadavosa

Problem

The unique constraint `(opportunity_id, volunteer_id)` added in migration `1779738026660` means the POST `/api/opportunity-volunteer` fails with a constraint violation whenever the pair already exists (e.g. volunteers seeded as matched in `1779739039589`).

The route does a plain `save()` with no `id`, which always generates an INSERT:

```typescript
const opportunityVolunteer = new OpportunityVolunteer(request.body);
await opportunityVolunteerRepository.save(opportunityVolunteer);
```

Fix

Check for an existing row first. If found and not in a terminal status (matched/active/past), update it. If found in terminal status, return 201 without change. If not found, insert.

File

`src/server/routes/m2m/opportunity-volunteer.routes.ts`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions