Skip to content

MSPCA-7: Add activate/deactivate endpoints for volunteers and coordin… - #6

Open
pujitakalinadhabhotla wants to merge 1 commit into
mainfrom
MSPCA-7-activate-deactivate-account-by-id
Open

pujitakalinadhabhotla wants to merge 1 commit into
mainfrom
MSPCA-7-activate-deactivate-account-by-id

Conversation

@pujitakalinadhabhotla

Copy link
Copy Markdown

ℹ️ Issue

Closes MSPCA-7

📝 Description

Adds PATCH /volunteers/:id/deactivate, PATCH /volunteers/:id/activate, PATCH /coordinators/:id/deactivate, and PATCH /coordinators/:id/activate, letting coordinators toggle a volunteer's or coordinator's active status by ID without deleting any of their data. An unknown ID returns a 404, and a non-numeric or non-positive ID returns a 400.

  1. Added VolunteersService.deactivate/activate and CoordinatorsService.deactivate/activate. Each looks up the record by ID, throws NotFoundException if it doesn't exist, and otherwise flips only the active field and saves — no other fields are touched and no rows are deleted.
  2. Added the four corresponding controller endpoints in VolunteersController and CoordinatorsController, using the existing validateId util to validate the ID before it reaches the service layer.
  3. Wrote service and controller tests for all four endpoints, covering the success path, the 404 path (record not found), the 400 path (invalid ID), and an explicit assertion that repo.delete is never called during deactivation.

✔️ Verification

yarn test volunteers coordinators: all new and existing volunteer/coordinator suites pass.

@dburkhart07 dburkhart07 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few small things for each. very clean pr tho, ty pujita!!! 🦁

// return this.usersService.findOne(userId);
// }

@Patch('/:id/deactivate')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should've specified this in the ticket, but we are going to be documenting all of our endpoints so that they can be easily read within Swagger without having to go into our repo. To do this, we are gonna add Tags from NestJs. For all your endpoints, can you add an @apioperation, @ApiParam, and just one @apiresponse for the happy path, including the status code, description, and type it returns? We will do this for all API endpoints moving forward.

// }

async deactivate(id: number): Promise<FosterVolunteer> {
const volunteer = await this.repo.findOne({ where: { volunteerId: id } });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call to put this here. i think what we will do is, in cases where we are going to fetch the volunteer in the service function anyways, we don't need an existence check in the controller. in cases we aren't we will want one

);
expect(repo.save).not.toHaveBeenCalled();
});
it('should not delete the volunteer record', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can just add in line 65 into the first test


describe('deactivate', () => {
it('should call service.deactivate with the parsed id', async () => {
const volunteer = { volunteerId: 1, active: false };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we type cast this to a FosterVolunteer


describe('activate', () => {
it('should call service.activate with the parsed id', async () => {
const volunteer = { volunteerId: 1, active: true };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here


describe('deactivate', () => {
it('should call service.deactivate with the parsed id', async () => {
const coordinator = { coordinatorId: 1, active: false };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type cast


describe('activate', () => {
it('should call service.activate with the parsed id', async () => {
const coordinator = { coordinatorId: 1, active: true };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type cast

);
expect(repo.save).not.toHaveBeenCalled();
});
it('should not delete the coordinator record', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here as the volunteer service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants