Skip to content

Commit 22e97fb

Browse files
authored
Merge pull request #4148 from Northeastern-Electric-Racing/#4076-created-getGuestDefinition-endpoint
#4076: created getGuestDefinition endpoint
2 parents d22204f + 1cc1ed2 commit 22e97fb

5 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/backend/src/controllers/recruitment.controllers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ export default class RecruitmentController {
116116
}
117117
}
118118

119+
static async getSingleGuestDefinition(req: Request, res: Response, next: NextFunction) {
120+
try {
121+
const { definitionId } = req.params as Record<string, string>;
122+
123+
const definition = await RecruitmentServices.getSingleGuestDefinition(req.organization, definitionId);
124+
res.status(200).json(definition);
125+
} catch (error: unknown) {
126+
next(error);
127+
}
128+
}
129+
119130
static async editGuestDefinition(req: Request, res: Response, next: NextFunction) {
120131
try {
121132
const { definitionId } = req.params as Record<string, string>;

src/backend/src/routes/recruitment.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ recruitmentRouter.post(
6464
RecruitmentController.createGuestDefinition
6565
);
6666

67+
recruitmentRouter.get('/guestdefinition/:definitionId', RecruitmentController.getSingleGuestDefinition);
68+
6769
recruitmentRouter.post(
6870
'/guestDefinition/:guestId/edit',
6971
nonEmptyString(body('term')),

src/backend/src/services/recruitment.services.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,23 @@ export default class RecruitmentServices {
338338
});
339339
return guestDefinitionTransformer(updatedGuest);
340340
}
341+
342+
/**
343+
* Gets a single guest definition with the given user, organization, and definition ids
344+
* @param organization the organization the user is currently in
345+
* @param definitionId the id of the specific definition being found
346+
* @returns a definition
347+
* @throws if the definition is not found in the db
348+
*/
349+
static async getSingleGuestDefinition(organization: Organization, definitionId: string) {
350+
const guest = await prisma.guest_Definition.findUnique({
351+
where: { organization, definitionId }
352+
});
353+
354+
if (!guest) {
355+
throw new NotFoundException('Guest Definition', definitionId);
356+
}
357+
358+
return guestDefinitionTransformer(guest);
359+
}
341360
}

src/backend/src/utils/errors.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,5 @@ export type ExceptionObjectNames =
214214
| 'Guest Definition'
215215
| 'ProspectiveSponsor'
216216
| 'SponsorTier'
217+
| 'Guest Definition'
217218
| 'Meeting Attendance';

src/backend/tests/unit/recruitment.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,30 @@ describe('Recruitment Tests', () => {
379379
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a guest definition'));
380380
});
381381
});
382+
383+
describe('Get a single guest definition', () => {
384+
it('Get a single guest definition works', async () => {
385+
const guestDefinition = await RecruitmentServices.createGuestDefinition(
386+
superman,
387+
organization,
388+
'test term',
389+
'test description',
390+
2,
391+
'iconname',
392+
'buttonTxt',
393+
'buttonLink'
394+
);
395+
const result = await RecruitmentServices.getSingleGuestDefinition(organization, guestDefinition.definitionId);
396+
expect(result).toStrictEqual(guestDefinition);
397+
});
398+
399+
it('Get a single guest definition fails', async () => {
400+
const nonExistingDefinitionId = 'nonExistingDefinition';
401+
await expect(async () =>
402+
RecruitmentServices.getSingleGuestDefinition(organization, nonExistingDefinitionId)
403+
).rejects.toThrow(new NotFoundException('Guest Definition', nonExistingDefinitionId));
404+
});
405+
});
382406
describe('Edit Guest Definition', () => {
383407
it('Fails if user is not an admin', async () => {
384408
await expect(

0 commit comments

Comments
 (0)