Skip to content

Commit 4104980

Browse files
authored
Merge pull request #4149 from Northeastern-Electric-Racing/#4001-guest-definition-hooks
#4001 guest definition hooks
2 parents f4d2ffd + 2917949 commit 4104980

13 files changed

Lines changed: 176 additions & 16 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ export default class RecruitmentController {
9999

100100
static async createGuestDefinition(req: Request, res: Response, next: NextFunction) {
101101
try {
102-
const { term, description, order, icon, buttonText, buttonLink } = req.body;
102+
const { term, description, order, icon, type, buttonText, buttonLink } = req.body;
103103
const definition = await RecruitmentServices.createGuestDefinition(
104104
req.currentUser,
105105
req.organization,
106106
term,
107107
description,
108108
order,
109+
type,
109110
icon,
110111
buttonText,
111112
buttonLink
@@ -130,7 +131,7 @@ export default class RecruitmentController {
130131
static async editGuestDefinition(req: Request, res: Response, next: NextFunction) {
131132
try {
132133
const { definitionId } = req.params as Record<string, string>;
133-
const { term, description, order, icon, buttonText, buttonLink } = req.body;
134+
const { term, description, order, type, icon, buttonText, buttonLink } = req.body;
134135

135136
const definition = await RecruitmentServices.editGuestDefinition(
136137
req.currentUser,
@@ -139,6 +140,7 @@ export default class RecruitmentController {
139140
description,
140141
definitionId,
141142
order,
143+
type,
142144
icon,
143145
buttonText,
144146
buttonLink
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- CreateEnum
2+
CREATE TYPE "Guest_Definition_Type" AS ENUM ('PROJECT_MANAGEMENT', 'INFO_PAGE');
3+
4+
-- AlterTable
5+
ALTER TABLE "Guest_Definition" ADD COLUMN "type" "Guest_Definition_Type" NOT NULL DEFAULT 'INFO_PAGE';

src/backend/src/prisma/schema.prisma

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,21 +1787,27 @@ model Reimbursement_Request_Comment {
17871787
@@index([reimbursementRequestId])
17881788
}
17891789

1790+
enum Guest_Definition_Type {
1791+
PROJECT_MANAGEMENT
1792+
INFO_PAGE
1793+
}
1794+
17901795
model Guest_Definition {
1791-
definitionId String @id @default(uuid())
1796+
definitionId String @id @default(uuid())
17921797
term String
17931798
description String
17941799
order Int
1800+
type Guest_Definition_Type @default(INFO_PAGE)
17951801
buttonText String?
17961802
buttonLink String?
17971803
icon String?
1798-
dateCreated DateTime @default(now())
1804+
dateCreated DateTime @default(now())
17991805
dateDeleted DateTime?
1800-
userDeleted User? @relation(fields: [userDeletedId], references: [userId], name: "guestDefinitionDeleter")
1806+
userDeleted User? @relation(fields: [userDeletedId], references: [userId], name: "guestDefinitionDeleter")
18011807
userDeletedId String?
1802-
userCreated User @relation(fields: [userCreatedId], references: [userId], name: "guestDefinitionCreator")
1808+
userCreated User @relation(fields: [userCreatedId], references: [userId], name: "guestDefinitionCreator")
18031809
userCreatedId String
1804-
organization Organization @relation(fields: [organizationId], references: [organizationId])
1810+
organization Organization @relation(fields: [organizationId], references: [organizationId])
18051811
organizationId String
18061812
18071813
@@index([organizationId])

src/backend/src/prisma/seed.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ import { dbSeedAllTeams } from './seed-data/teams.seed.js';
2222
import { seedReimbursementRequests } from './seed-data/reimbursement-requests.seed.js';
2323
import ChangeRequestsService from '../services/change-requests.services.js';
2424
import TeamsService from '../services/teams.services.js';
25-
import { DayOfWeek, MaterialStatus, RoleEnum, StandardChangeRequest, WbsElementStatus, WorkPackageStage } from 'shared';
25+
import {
26+
DayOfWeek,
27+
GuestDefinitionType,
28+
MaterialStatus,
29+
RoleEnum,
30+
StandardChangeRequest,
31+
WbsElementStatus,
32+
WorkPackageStage
33+
} from 'shared';
2634
import TasksService from '../services/tasks.services.js';
2735
import { seedProject } from './seed-data/projects.seed.js';
2836
import { seedWorkPackage } from './seed-data/work-packages.seed.js';
@@ -5120,6 +5128,7 @@ const performSeed: () => Promise<void> = async () => {
51205128
term: 'NER',
51215129
description: 'A really awesome organization!',
51225130
order: 0,
5131+
type: 'INFO_PAGE',
51235132
organizationId,
51245133
userCreatedId: batman.userId
51255134
}
@@ -5131,6 +5140,7 @@ const performSeed: () => Promise<void> = async () => {
51315140
'Projects',
51325141
'This is the definition of a project. Projects are blah blah blah',
51335142
0,
5143+
GuestDefinitionType.PROJECT_MANAGEMENT,
51345144
'bar_chart',
51355145
'Click here to view all our projects!',
51365146
'/projects'
@@ -5142,6 +5152,7 @@ const performSeed: () => Promise<void> = async () => {
51425152
'Change Requests',
51435153
'This is the definiton for a change request. Changes requests are blah blah blah',
51445154
0,
5155+
GuestDefinitionType.PROJECT_MANAGEMENT,
51455156
'bar_chart',
51465157
'Click here to view all our change requests!',
51475158
'/change-requests'
@@ -5153,6 +5164,7 @@ const performSeed: () => Promise<void> = async () => {
51535164
'Gantt Chart',
51545165
'This is the definiton for a change request. Changes requests are blah blah blah',
51555166
0,
5167+
GuestDefinitionType.PROJECT_MANAGEMENT,
51565168
'bar_chart',
51575169
'Click here to view all our projects!',
51585170
'/gantt'
@@ -5164,6 +5176,7 @@ const performSeed: () => Promise<void> = async () => {
51645176
'Design Reviews',
51655177
'This is the definiton for a design review. Design reviews are blah blah blah',
51665178
0,
5179+
GuestDefinitionType.PROJECT_MANAGEMENT,
51675180
'bar_chart',
51685181
'Click here to view all our design reviews!',
51695182
'/design-reviews'

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ recruitmentRouter.post(
5757
nonEmptyString(body('term')),
5858
nonEmptyString(body('description')),
5959
body('order').isInt(),
60+
nonEmptyString(body('type')),
6061
nonEmptyString(body('icon')).optional(),
6162
nonEmptyString(body('buttonText')).optional(),
6263
nonEmptyString(body('buttonLink')).optional(),
@@ -67,10 +68,11 @@ recruitmentRouter.post(
6768
recruitmentRouter.get('/guestdefinition/:definitionId', RecruitmentController.getSingleGuestDefinition);
6869

6970
recruitmentRouter.post(
70-
'/guestDefinition/:guestId/edit',
71+
'/guestdefinition/:definitionId/edit',
7172
nonEmptyString(body('term')),
7273
nonEmptyString(body('description')),
7374
body('order').isInt(),
75+
nonEmptyString(body('type')),
7476
nonEmptyString(body('icon')).optional(),
7577
nonEmptyString(body('buttonText')).optional(),
7678
nonEmptyString(body('buttonLink')).optional(),

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Organization } from '@prisma/client';
2-
import { isAdmin, User } from 'shared';
2+
import { GuestDefinitionType, isAdmin, User } from 'shared';
33
import prisma from '../prisma/prisma.js';
44
import { AccessDeniedAdminOnlyException, DeletedException, NotFoundException } from '../utils/errors.utils.js';
55
import { userHasPermission } from '../utils/users.utils.js';
@@ -221,6 +221,7 @@ export default class RecruitmentServices {
221221
* @param description the definition of the term
222222
* @param order the order the term appears on the page
223223
* @param icon the icon associated with the term
224+
* @param type the type of the guest definition
224225
* @param buttonText the text displayed on the terms button
225226
* @param buttonLink where the terms button links to
226227
* @returns
@@ -231,6 +232,7 @@ export default class RecruitmentServices {
231232
term: string,
232233
description: string,
233234
order: number,
235+
type: GuestDefinitionType,
234236
icon?: string,
235237
buttonText?: string,
236238
buttonLink?: string
@@ -243,6 +245,7 @@ export default class RecruitmentServices {
243245
term,
244246
description,
245247
order,
248+
type,
246249
userCreatedId: creator.userId,
247250
organizationId: organization.organizationId,
248251
buttonText,
@@ -291,6 +294,7 @@ export default class RecruitmentServices {
291294
* @param description the definition of the term
292295
* @param order the order the term appears on the page
293296
* @param icon the icon associated with the term
297+
* @param type the type of the guest definition
294298
* @param buttonText the text displayed on the terms button
295299
* @param buttonLink where the terms button links to
296300
* @returns
@@ -302,6 +306,7 @@ export default class RecruitmentServices {
302306
description: string,
303307
definitionId: string,
304308
order: number,
309+
type: GuestDefinitionType,
305310
icon?: string,
306311
buttonText?: string,
307312
buttonLink?: string
@@ -332,6 +337,7 @@ export default class RecruitmentServices {
332337
description,
333338
order,
334339
icon,
340+
type,
335341
buttonText,
336342
buttonLink
337343
}

src/backend/src/transformers/recruitment-transformer.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Prisma } from '@prisma/client';
2-
import { FrequentlyAskedQuestion, GuestDefinition } from 'shared';
1+
import { Prisma, Guest_Definition_Type as PrismaGuestDefinitionType } from '@prisma/client';
2+
import { FrequentlyAskedQuestion, GuestDefinition, GuestDefinitionType } from 'shared';
33
import { FaqQueryArgs } from '../prisma-query-args/faq.query-args.js';
44
import { userTransformer } from './user.transformer.js';
55

@@ -12,12 +12,21 @@ export const faqTransformer = (faq: Prisma.FrequentlyAskedQuestionGetPayload<Faq
1212
dateDeleted: faq.dateDeleted ?? undefined
1313
});
1414

15+
export const definitionTypeTransformer = (type: PrismaGuestDefinitionType): GuestDefinitionType => {
16+
const mapping: Record<PrismaGuestDefinitionType, GuestDefinitionType> = {
17+
PROJECT_MANAGEMENT: GuestDefinitionType.PROJECT_MANAGEMENT,
18+
INFO_PAGE: GuestDefinitionType.INFO_PAGE
19+
};
20+
return mapping[type];
21+
};
22+
1523
export const guestDefinitionTransformer = (guestDefinition: Prisma.Guest_DefinitionGetPayload<{}>): GuestDefinition => ({
1624
definitionId: guestDefinition.definitionId,
1725
term: guestDefinition.term,
1826
description: guestDefinition.description,
1927
order: guestDefinition.order,
2028
buttonText: guestDefinition.buttonText ?? undefined,
2129
buttonLink: guestDefinition.buttonLink ?? undefined,
22-
icon: guestDefinition.icon ?? undefined
30+
icon: guestDefinition.icon ?? undefined,
31+
type: definitionTypeTransformer(guestDefinition.type)
2332
});

src/backend/tests/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ export const createTestGuestDefinition = async (user: User, organizationId: stri
986986
term: 'Term',
987987
description: 'Description',
988988
order: 0,
989+
type: 'INFO_PAGE',
989990
organizationId,
990991
userCreatedId: user.userId
991992
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
createTestUser,
1212
resetUsers
1313
} from '../test-utils.js';
14+
import { GuestDefinitionType } from 'shared';
1415
import {
1516
batmanAppAdmin,
1617
wonderwomanGuest,
@@ -351,6 +352,7 @@ describe('Recruitment Tests', () => {
351352
'test term',
352353
'test description',
353354
2,
355+
GuestDefinitionType.INFO_PAGE,
354356
'iconname',
355357
'buttonTxt',
356358
'buttonLink'
@@ -372,6 +374,7 @@ describe('Recruitment Tests', () => {
372374
'test term',
373375
'test description',
374376
2,
377+
GuestDefinitionType.INFO_PAGE,
375378
'iconname',
376379
'buttonTxt',
377380
'buttonLink'
@@ -414,6 +417,7 @@ describe('Recruitment Tests', () => {
414417
'test description',
415418
'test definition id',
416419
2,
420+
GuestDefinitionType.INFO_PAGE,
417421
'buttonTxt',
418422
'buttonLink'
419423
)
@@ -430,6 +434,7 @@ describe('Recruitment Tests', () => {
430434
'description',
431435
'definition id',
432436
2,
437+
GuestDefinitionType.INFO_PAGE,
433438
'buttonTxt',
434439
'buttonLink'
435440
)
@@ -443,6 +448,7 @@ describe('Recruitment Tests', () => {
443448
'test term',
444449
'test description',
445450
2,
451+
GuestDefinitionType.INFO_PAGE,
446452
'iconname',
447453
'buttonTxt',
448454
'buttonLink'
@@ -455,6 +461,7 @@ describe('Recruitment Tests', () => {
455461
'new description',
456462
def.definitionId,
457463
4,
464+
GuestDefinitionType.INFO_PAGE,
458465
'new icon',
459466
'new text',
460467
'new link'
@@ -475,6 +482,7 @@ describe('Recruitment Tests', () => {
475482
'test term',
476483
'test description',
477484
2,
485+
GuestDefinitionType.INFO_PAGE,
478486
'iconname',
479487
'buttonTxt',
480488
'buttonLink'
@@ -493,6 +501,7 @@ describe('Recruitment Tests', () => {
493501
'description',
494502
def.definitionId,
495503
2,
504+
GuestDefinitionType.INFO_PAGE,
496505
'buttonTxt',
497506
'buttonLink'
498507
)
@@ -579,6 +588,7 @@ describe('Recruitment Tests', () => {
579588
'test term',
580589
'test description',
581590
2,
591+
GuestDefinitionType.INFO_PAGE,
582592
'iconname',
583593
'buttonTxt',
584594
'buttonLink'
@@ -590,6 +600,7 @@ describe('Recruitment Tests', () => {
590600
'test term',
591601
'test description',
592602
2,
603+
GuestDefinitionType.INFO_PAGE,
593604
'iconname',
594605
'buttonTxt',
595606
'buttonLink'

src/frontend/src/apis/recruitment.api.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from '../utils/axios';
2-
import { MilestonePayload, FaqPayload } from '../hooks/recruitment.hooks';
2+
import { MilestonePayload, FaqPayload, GuestDefinitionPayload } from '../hooks/recruitment.hooks';
33
import { apiUrls } from '../utils/urls';
4-
import { dateToMidnightUTC, Milestone } from 'shared';
4+
import { dateToMidnightUTC, GuestDefinition, Milestone } from 'shared';
55
import { FrequentlyAskedQuestion } from 'shared';
66

77
export const getAllMilestones = () => {
@@ -49,3 +49,25 @@ export const editFaq = (payload: FaqPayload, id: string) => {
4949
export const deleteFaq = (faqId: string) => {
5050
return axios.delete<{ message: string }>(apiUrls.faqDelete(faqId));
5151
};
52+
53+
export const getAllGuestDefinitions = () => {
54+
return axios.get<GuestDefinition[]>(apiUrls.allGuestDefinitions(), {
55+
transformResponse: (data) => JSON.parse(data)
56+
});
57+
};
58+
59+
export const deleteGuestDefinition = (definitionId: string) => {
60+
return axios.delete<{ message: string }>(apiUrls.guestDefinitionDelete(definitionId));
61+
};
62+
63+
export const createGuestDefinition = (payload: GuestDefinitionPayload) => {
64+
return axios.post(apiUrls.guestDefinitionCreate(), {
65+
...payload
66+
});
67+
};
68+
69+
export const editGuestDefinition = (payload: GuestDefinitionPayload, id: string) => {
70+
return axios.post(apiUrls.guestDefintionEdit(id), {
71+
...payload
72+
});
73+
};

0 commit comments

Comments
 (0)