Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions src/backend/src/controllers/recruitment.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,18 @@ export default class RecruitmentController {
next(error);
}
}

static async getGuestDefinition(req: Request, res: Response, next: NextFunction) {
try {
const { userCreatedId, organizationId, definitionId } = req.params as {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We will only be extracting the definitionId from the parameters. You can get the organizationId directly from the request with req.organization.organizationId

userCreatedId: string;
organizationId: string;
definitionId: string;
};
const definition = await RecruitmentServices.getGuestDefinition(userCreatedId, organizationId, definitionId);
res.status(200).json(definition);
} catch (error: unknown) {
next(error);
}
}
}
2 changes: 2 additions & 0 deletions src/backend/src/routes/recruitment.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ recruitmentRouter.post(
RecruitmentController.createGuestDefinition
);

recruitmentRouter.get('/guestDefinition/:id', RecruitmentController.getGuestDefinition);

export default recruitmentRouter;
26 changes: 25 additions & 1 deletion src/backend/src/services/recruitment.services.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Organization } from '@prisma/client';
import { Guest_Definition, Organization } from '@prisma/client';
import { isAdmin, User } from 'shared';
import prisma from '../prisma/prisma.js';
import { AccessDeniedAdminOnlyException, DeletedException, NotFoundException } from '../utils/errors.utils.js';
Expand Down Expand Up @@ -253,4 +253,28 @@ export default class RecruitmentServices {

return definition;
}

/**
* Gets a single guest defenition with the given user, organization, and definition ids
* @param userCreatedId the id of guest to retrieve
* @param organizationId the organization the user is currently in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

update doc string

* @param definitionId the id of the specific defenition being found
* @returns a definition
* @throws if the defenition is not found in the db
*/
static async getGuestDefinition(
userCreatedId: string,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You will not need to take in the user created id, that does not matter when requesting a guest definition, so you can delete that parameter

organizationId: string,
definitionId: string
): Promise<Guest_Definition> {
const guest = await prisma.guest_Definition.findFirst({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can instead be findUnique, since there will only be one definition with the given definitionId

where: { userCreatedId, organizationId, definitionId }
});

if (!guest) {
throw new NotFoundException('User', userCreatedId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should instead be NotFoundException('Guest Definition', definitionId)

}

return guest;
}
}
29 changes: 29 additions & 0 deletions src/backend/tests/unit/recruitment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,33 @@ describe('Recruitment Tests', () => {
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a guest definition'));
});
});

describe('Get a single guest defenition', () => {
it('Get a single team type works', async () => {
const guestDefinition = await RecruitmentServices.createGuestDefinition(
superman,
organization,
'test term',
'test description',
2,
'iconname',
'buttonTxt',
'buttonLink'
);
const result = await RecruitmentServices.getGuestDefinition(
guestDefinition.userCreatedId,
orgId,
guestDefinition.definitionId
);
expect(result).toStrictEqual(guestDefinition);
});

it('Get a single guest defenition fails', async () => {
const nonExistingGuestId = 'nonExistingGuest';
const nonExistingDefinitionId = 'nonExistingDefinition';
await expect(async () =>
RecruitmentServices.getGuestDefinition(nonExistingGuestId, orgId, nonExistingDefinitionId)
).rejects.toThrow(new NotFoundException('User', nonExistingGuestId));
});
});
});