Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
12 changes: 12 additions & 0 deletions src/backend/src/controllers/recruitment.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ export default class RecruitmentController {
}
}

static async getGuestDefinition(req: Request, res: Response, next: NextFunction) {
try {
const definition = await RecruitmentServices.getGuestDefinition(
req.organization.organizationId,
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.

send the whole organization not just the id

req.params.definitionId as 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.

follow the conventions for accessing a req.params
look at getSingleEvent in calendar.controllers.ts

);
res.status(200).json(definition);
} catch (error: unknown) {
next(error);
}
}

static async editGuestDefinition(req: Request, res: Response, next: NextFunction) {
try {
const { definitionId } = req.params as Record<string, string>;
Expand Down
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 @@ -64,6 +64,8 @@ recruitmentRouter.post(
RecruitmentController.createGuestDefinition
);

recruitmentRouter.get('/guestdefinition/:definitionId', RecruitmentController.getGuestDefinition);

recruitmentRouter.post(
'/guestDefinition/:guestId/edit',
nonEmptyString(body('term')),
Expand Down
19 changes: 19 additions & 0 deletions src/backend/src/services/recruitment.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,23 @@ export default class RecruitmentServices {
});
return guestDefinitionTransformer(updatedGuest);
}

/**
* Gets a single guest definition with the given user, organization, and definition ids
* @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 definition being found
* @returns a definition
* @throws if the definition is not found in the db
*/
static async getGuestDefinition(organizationId: string, definitionId: 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.

call this getSingleGuestDefinition so its use is clear

const guest = await prisma.guest_Definition.findUnique({
where: { organizationId, definitionId }
});

if (!guest) {
throw new NotFoundException('Guest Definition', definitionId);
}

return guestDefinitionTransformer(guest);
}
}
1 change: 1 addition & 0 deletions src/backend/src/utils/errors.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,5 @@ export type ExceptionObjectNames =
| 'Guest Definition'
| 'ProspectiveSponsor'
| 'SponsorTier'
| 'Guest Definition'
| 'Meeting Attendance';
24 changes: 24 additions & 0 deletions src/backend/tests/unit/recruitment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,30 @@ describe('Recruitment Tests', () => {
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a guest definition'));
});
});

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

it('Get a single guest definition fails', async () => {
const nonExistingDefinitionId = 'nonExistingDefinition';
await expect(async () => RecruitmentServices.getGuestDefinition(orgId, nonExistingDefinitionId)).rejects.toThrow(
new NotFoundException('Guest Definition', nonExistingDefinitionId)
);
});
});
describe('Edit Guest Definition', () => {
it('Fails if user is not an admin', async () => {
await expect(
Expand Down
Loading