Skip to content

Commit b022dee

Browse files
committed
#4076: created getGuestDefinition endpoint
1 parent f9bf6ed commit b022dee

4 files changed

Lines changed: 70 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,18 @@ export default class RecruitmentController {
115115
next(error);
116116
}
117117
}
118+
119+
static async getGuestDefinition(req: Request, res: Response, next: NextFunction) {
120+
try {
121+
const { userCreatedId, organizationId, definitionId } = req.params as {
122+
userCreatedId: string;
123+
organizationId: string;
124+
definitionId: string;
125+
};
126+
const definition = await RecruitmentServices.getGuestDefinition(userCreatedId, organizationId, definitionId);
127+
res.status(200).json(definition);
128+
} catch (error: unknown) {
129+
next(error);
130+
}
131+
}
118132
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,6 @@ recruitmentRouter.post(
6262
RecruitmentController.createGuestDefinition
6363
);
6464

65+
recruitmentRouter.get('/guestDefinition/:id', RecruitmentController.getGuestDefinition);
66+
6567
export default recruitmentRouter;

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Organization } from '@prisma/client';
1+
import { Guest_Definition, Organization } from '@prisma/client';
22
import { isAdmin, User } from 'shared';
33
import prisma from '../prisma/prisma.js';
44
import { AccessDeniedAdminOnlyException, DeletedException, NotFoundException } from '../utils/errors.utils.js';
@@ -253,4 +253,28 @@ export default class RecruitmentServices {
253253

254254
return definition;
255255
}
256+
257+
/**
258+
* Gets a single guest defenition with the given user, organization, and definition ids
259+
* @param userCreatedId the id of guest to retrieve
260+
* @param organizationId the organization the user is currently in
261+
* @param definitionId the id of the specific defenition being found
262+
* @returns a definition
263+
* @throws if the defenition is not found in the db
264+
*/
265+
static async getGuestDefinition(
266+
userCreatedId: string,
267+
organizationId: string,
268+
definitionId: string
269+
): Promise<Guest_Definition> {
270+
const guest = await prisma.guest_Definition.findFirst({
271+
where: { userCreatedId, organizationId, definitionId }
272+
});
273+
274+
if (!guest) {
275+
throw new NotFoundException('User', userCreatedId);
276+
}
277+
278+
return guest;
279+
}
256280
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,33 @@ describe('Recruitment Tests', () => {
377377
).rejects.toThrow(new AccessDeniedAdminOnlyException('create a guest definition'));
378378
});
379379
});
380+
381+
describe('Get a single guest defenition', () => {
382+
it('Get a single team type works', async () => {
383+
const guestDefinition = await RecruitmentServices.createGuestDefinition(
384+
superman,
385+
organization,
386+
'test term',
387+
'test description',
388+
2,
389+
'iconname',
390+
'buttonTxt',
391+
'buttonLink'
392+
);
393+
const result = await RecruitmentServices.getGuestDefinition(
394+
guestDefinition.userCreatedId,
395+
orgId,
396+
guestDefinition.definitionId
397+
);
398+
expect(result).toStrictEqual(guestDefinition);
399+
});
400+
401+
it('Get a single guest defenition fails', async () => {
402+
const nonExistingGuestId = 'nonExistingGuest';
403+
const nonExistingDefinitionId = 'nonExistingDefinition';
404+
await expect(async () =>
405+
RecruitmentServices.getGuestDefinition(nonExistingGuestId, orgId, nonExistingDefinitionId)
406+
).rejects.toThrow(new NotFoundException('User', nonExistingGuestId));
407+
});
408+
});
380409
});

0 commit comments

Comments
 (0)