diff --git a/backend/vkt/src/main/java/fi/oph/vkt/api/clerk/ClerkEnrollmentController.java b/backend/vkt/src/main/java/fi/oph/vkt/api/clerk/ClerkEnrollmentController.java index 60f923190..82bca461d 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/api/clerk/ClerkEnrollmentController.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/api/clerk/ClerkEnrollmentController.java @@ -4,14 +4,11 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_PDF_VALUE; -import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentMoveDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentStatusChangeDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentUpdateDTO; import fi.oph.vkt.api.dto.clerk.ClerkPaymentLinkDTO; -import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO; -import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO; import fi.oph.vkt.model.FeatureFlag; import fi.oph.vkt.service.ClerkEnrollmentService; import fi.oph.vkt.service.FeatureFlagService; @@ -78,26 +75,6 @@ public ClerkEnrollmentDTO move(@RequestBody @Valid final ClerkEnrollmentMoveDTO return clerkEnrollmentService.move(dto); } - @GetMapping(path = "/contact/{enrollmentContactId:\\d+}", consumes = ALL_VALUE) - @Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment contact request") - public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(@PathVariable final long enrollmentContactId) { - return clerkEnrollmentService.getEnrollmentContactRequest(enrollmentContactId); - } - - @PostMapping(path = "/contact/{enrollmentContactId:\\d+}/convertToAppointment", consumes = ALL_VALUE) - @Operation(tags = TAG_ENROLLMENT, summary = "Convert enrollment contact request to enrollment appointment") - public ExaminerEnrollmentAppointmentDTO enrollmentContactRequestToAppointment( - @PathVariable final long enrollmentContactId - ) { - return clerkEnrollmentService.convertToAppointment(enrollmentContactId); - } - - @GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}", consumes = ALL_VALUE) - @Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment appointment") - public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment(@PathVariable final long enrollmentAppointmentId) { - return clerkEnrollmentService.getEnrollmentAppointment(enrollmentAppointmentId); - } - @GetMapping(path = "/attachment", consumes = ALL_VALUE) @Operation(tags = TAG_ENROLLMENT, summary = "Download enrollment attachment") public void attachmentRedirect(final HttpServletResponse response, @RequestParam final String key) diff --git a/backend/vkt/src/main/java/fi/oph/vkt/api/examiner/ExaminerEnrollmentController.java b/backend/vkt/src/main/java/fi/oph/vkt/api/examiner/ExaminerEnrollmentController.java index 4443ab5cb..bd34dff45 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/api/examiner/ExaminerEnrollmentController.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/api/examiner/ExaminerEnrollmentController.java @@ -1,5 +1,8 @@ package fi.oph.vkt.api.examiner; +import static org.springframework.http.MediaType.ALL_VALUE; + +import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO; import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO; import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO; import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentUpdateDTO; @@ -22,23 +25,56 @@ public class ExaminerEnrollmentController { @PutMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}") @Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment") public ExaminerEnrollmentAppointmentDTO updateEnrollmentAppointment( + @PathVariable String oid, + @PathVariable Long enrollmentAppointmentId, @RequestBody @Valid final ExaminerEnrollmentAppointmentUpdateDTO dto ) { - return examinerEnrollmentService.updateAppointment(dto); + return examinerEnrollmentService.updateAppointment(oid, enrollmentAppointmentId, dto); } - @GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}/grades") - @Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment") - public ExaminerEnrollmentGradesDTO getEnrollmentAppointmentGrades(@PathVariable final long enrollmentAppointmentId) { - return examinerEnrollmentService.getAppointmentGrades(enrollmentAppointmentId); + @GetMapping(path = "/contact/{enrollmentContactId:\\d+}", consumes = ALL_VALUE) + @Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment contact request") + public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest( + @PathVariable String oid, + @PathVariable final long enrollmentContactId + ) { + return examinerEnrollmentService.getEnrollmentContactRequest(oid, enrollmentContactId); + } + + @PostMapping(path = "/contact/{enrollmentContactId:\\d+}/convertToAppointment", consumes = ALL_VALUE) + @Operation(tags = TAG_ENROLLMENT, summary = "Convert enrollment contact request to enrollment appointment") + public ExaminerEnrollmentAppointmentDTO enrollmentContactRequestToAppointment( + @PathVariable String oid, + @PathVariable final long enrollmentContactId + ) { + return examinerEnrollmentService.convertToAppointment(oid, enrollmentContactId); + } + + @GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}", consumes = ALL_VALUE) + @Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment appointment") + public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment( + @PathVariable String oid, + @PathVariable final long enrollmentAppointmentId + ) { + return examinerEnrollmentService.getEnrollmentAppointment(oid, enrollmentAppointmentId); } @PutMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}/grades") - @Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment") + @Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment grades") public ExaminerEnrollmentGradesDTO upsertEnrollmentAppointmentGrades( + @PathVariable String oid, @RequestBody @Valid final ExaminerEnrollmentGradesDTO dto, @PathVariable final long enrollmentAppointmentId ) { - return examinerEnrollmentService.upsertAppointmentGrades(enrollmentAppointmentId, dto); + return examinerEnrollmentService.upsertAppointmentGrades(oid, enrollmentAppointmentId, dto); + } + + @GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}/grades") + @Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment appointment grades") + public ExaminerEnrollmentGradesDTO getEnrollmentAppointmentGrades( + @PathVariable String oid, + @PathVariable final long enrollmentAppointmentId + ) { + return examinerEnrollmentService.getAppointmentGrades(oid, enrollmentAppointmentId); } } diff --git a/backend/vkt/src/main/java/fi/oph/vkt/service/ClerkEnrollmentService.java b/backend/vkt/src/main/java/fi/oph/vkt/service/ClerkEnrollmentService.java index 6f079b57b..ddfc7efe4 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/service/ClerkEnrollmentService.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/service/ClerkEnrollmentService.java @@ -1,32 +1,22 @@ package fi.oph.vkt.service; -import fi.oph.vkt.api.dto.EnrollmentGradeDTO; import fi.oph.vkt.api.dto.FreeEnrollmentDetails; import fi.oph.vkt.api.dto.PublicEducationDTO; -import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentMoveDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentStatusChangeDTO; import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentUpdateDTO; import fi.oph.vkt.api.dto.clerk.ClerkPaymentLinkDTO; -import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO; -import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO; import fi.oph.vkt.audit.AuditService; import fi.oph.vkt.audit.VktOperation; import fi.oph.vkt.audit.dto.ClerkEnrollmentAuditDTO; import fi.oph.vkt.model.Enrollment; -import fi.oph.vkt.model.EnrollmentAppointment; -import fi.oph.vkt.model.EnrollmentGrade; import fi.oph.vkt.model.ExamEvent; import fi.oph.vkt.model.FreeEnrollment; import fi.oph.vkt.model.Payment; -import fi.oph.vkt.model.type.EnrollmentAppointmentStatus; -import fi.oph.vkt.model.type.EnrollmentGradeType; import fi.oph.vkt.model.type.EnrollmentStatus; import fi.oph.vkt.model.type.FreeEnrollmentSource; import fi.oph.vkt.model.type.PaymentStatus; -import fi.oph.vkt.repository.EnrollmentAppointmentRepository; -import fi.oph.vkt.repository.EnrollmentGradesRepository; import fi.oph.vkt.repository.EnrollmentRepository; import fi.oph.vkt.repository.ExamEventRepository; import fi.oph.vkt.repository.FreeEnrollmentRepository; @@ -40,7 +30,6 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.List; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,8 +45,6 @@ public class ClerkEnrollmentService extends AbstractEnrollmentService { private static final Logger LOG = LoggerFactory.getLogger(ClerkEnrollmentService.class); private final EnrollmentRepository enrollmentRepository; - private final EnrollmentAppointmentRepository enrollmentAppointmentRepository; - private final EnrollmentGradesRepository enrollmentGradesRepository; private final ExamEventRepository examEventRepository; private final PaymentRepository paymentRepository; private final AuditService auditService; @@ -232,41 +219,4 @@ public void getAndSaveKoskiEducationDetailsForEnrollment(final long enrollmentId } koskiService.saveEducationsForEnrollment(freeEnrollment, enrollment.getExamEvent().getId(), educationDTOs); } - - @Transactional(readOnly = true) - public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(final long enrollmentContactId) { - final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( - enrollmentContactId - ); - - return ClerkEnrollmentUtil.createClerkEnrollmentContactDTO(enrollmentAppointment); - } - - @Transactional - public ExaminerEnrollmentAppointmentDTO convertToAppointment(final long enrollmentContactId) { - final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( - enrollmentContactId - ); - final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api"); - - enrollmentAppointment.setStatus(EnrollmentAppointmentStatus.WAITING_AUTHENTICATION); - - if (enrollmentAppointment.getAuthHash() == null) { - enrollmentAppointment.setAuthHash(uuidSource.getRandomNonce()); - } - - enrollmentAppointmentRepository.flush(); - - return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI); - } - - @Transactional(readOnly = true) - public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment(final long enrollmentAppointmentId) { - final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( - enrollmentAppointmentId - ); - final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api"); - - return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI); - } } diff --git a/backend/vkt/src/main/java/fi/oph/vkt/service/ExaminerEnrollmentService.java b/backend/vkt/src/main/java/fi/oph/vkt/service/ExaminerEnrollmentService.java index d6dc4d233..bd939627d 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/service/ExaminerEnrollmentService.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/service/ExaminerEnrollmentService.java @@ -1,18 +1,23 @@ package fi.oph.vkt.service; import fi.oph.vkt.api.dto.EnrollmentGradeDTO; +import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO; import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO; import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO; import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentUpdateDTO; import fi.oph.vkt.model.EnrollmentAppointment; import fi.oph.vkt.model.EnrollmentGrade; import fi.oph.vkt.model.ExaminerExamEvent; +import fi.oph.vkt.model.type.EnrollmentAppointmentStatus; import fi.oph.vkt.model.type.EnrollmentGradeType; import fi.oph.vkt.repository.EnrollmentAppointmentRepository; import fi.oph.vkt.repository.EnrollmentGradesRepository; import fi.oph.vkt.repository.ExaminerExamEventRepository; -import fi.oph.vkt.repository.ExaminerRepository; import fi.oph.vkt.util.ClerkEnrollmentUtil; +import fi.oph.vkt.util.UUIDSource; +import fi.oph.vkt.util.exception.APIException; +import fi.oph.vkt.util.exception.APIExceptionType; +import java.util.Objects; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; @@ -27,10 +32,25 @@ public class ExaminerEnrollmentService extends AbstractEnrollmentService { private final EnrollmentGradesRepository enrollmentGradesRepository; private final ExaminerExamEventRepository examinerExamEventRepository; private final Environment environment; + private final UUIDSource uuidSource; + + private static void checkExaminerOid(EnrollmentAppointment enrollmentAppointment, String oid) { + if (!enrollmentAppointment.getExaminer().getOid().equals(oid)) { + throw new APIException(APIExceptionType.EXAMINER_ENROLLMENT_OID_MISMATCH); + } + } @Transactional - public ExaminerEnrollmentAppointmentDTO updateAppointment(final ExaminerEnrollmentAppointmentUpdateDTO dto) { + public ExaminerEnrollmentAppointmentDTO updateAppointment( + final String oid, + final Long id, + final ExaminerEnrollmentAppointmentUpdateDTO dto + ) { + if (!Objects.equals(id, dto.id())) { + throw new APIException(APIExceptionType.EXAMINER_APPOINTMENT_ID_MISMATCH); + } final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(dto.id()); + checkExaminerOid(enrollmentAppointment, oid); final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api"); enrollmentAppointment.assertVersion(dto.version()); @@ -47,10 +67,44 @@ public ExaminerEnrollmentAppointmentDTO updateAppointment(final ExaminerEnrollme } @Transactional(readOnly = true) - public ExaminerEnrollmentGradesDTO getAppointmentGrades(final long enrollmentAppointmentId) { + public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest( + final String oid, + final long enrollmentContactId + ) { + final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( + enrollmentContactId + ); + checkExaminerOid(enrollmentAppointment, oid); + + return ClerkEnrollmentUtil.createClerkEnrollmentContactDTO(enrollmentAppointment); + } + + @Transactional + public ExaminerEnrollmentAppointmentDTO convertToAppointment(final String oid, final long enrollmentContactId) { + final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( + enrollmentContactId + ); + checkExaminerOid(enrollmentAppointment, oid); + + final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api"); + + enrollmentAppointment.setStatus(EnrollmentAppointmentStatus.WAITING_AUTHENTICATION); + + if (enrollmentAppointment.getAuthHash() == null) { + enrollmentAppointment.setAuthHash(uuidSource.getRandomNonce()); + } + + enrollmentAppointmentRepository.flush(); + + return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI); + } + + @Transactional(readOnly = true) + public ExaminerEnrollmentGradesDTO getAppointmentGrades(final String oid, final long enrollmentAppointmentId) { final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( enrollmentAppointmentId ); + checkExaminerOid(enrollmentAppointment, oid); final Optional enrollmentGradeOptional = enrollmentGradesRepository.findByEnrollmentAppointment( enrollmentAppointment ); @@ -58,14 +112,33 @@ public ExaminerEnrollmentGradesDTO getAppointmentGrades(final long enrollmentApp return enrollmentGradeOptional.map(this::createGradesDTO).orElse(null); } + @Transactional(readOnly = true) + public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment( + final String oid, + final long enrollmentAppointmentId + ) { + final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( + enrollmentAppointmentId + ); + + checkExaminerOid(enrollmentAppointment, oid); + + final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api"); + + return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI); + } + @Transactional public ExaminerEnrollmentGradesDTO upsertAppointmentGrades( + final String oid, final long enrollmentAppointmentId, final ExaminerEnrollmentGradesDTO dto ) { final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById( enrollmentAppointmentId ); + checkExaminerOid(enrollmentAppointment, oid); + final Optional enrollmentGradeOptional = enrollmentGradesRepository.findByEnrollmentAppointment( enrollmentAppointment ); diff --git a/backend/vkt/src/main/java/fi/oph/vkt/util/exception/APIExceptionType.java b/backend/vkt/src/main/java/fi/oph/vkt/util/exception/APIExceptionType.java index b14a32214..9ff6ee407 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/util/exception/APIExceptionType.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/util/exception/APIExceptionType.java @@ -44,7 +44,9 @@ public enum APIExceptionType { EXAMINER_NOT_FOUND, EXAMINER_EXAM_EVENT_NOT_FOUND, EXAMINER_MUNICIPALITY_MISMATCH, - EXAMINER_EXAM_EVENT_EXAMINER_MISMATCH; + EXAMINER_EXAM_EVENT_EXAMINER_MISMATCH, + EXAMINER_ENROLLMENT_OID_MISMATCH, + EXAMINER_APPOINTMENT_ID_MISMATCH; public String getCode() { final StringBuilder codeBuilder = new StringBuilder(); diff --git a/backend/vkt/src/test/java/fi/oph/vkt/service/ClerkEnrollmentServiceTest.java b/backend/vkt/src/test/java/fi/oph/vkt/service/ClerkEnrollmentServiceTest.java index a73c10792..9aa42bbe0 100644 --- a/backend/vkt/src/test/java/fi/oph/vkt/service/ClerkEnrollmentServiceTest.java +++ b/backend/vkt/src/test/java/fi/oph/vkt/service/ClerkEnrollmentServiceTest.java @@ -49,12 +49,6 @@ class ClerkEnrollmentServiceTest { @Resource private EnrollmentRepository enrollmentRepository; - @Resource - private EnrollmentAppointmentRepository enrollmentAppointmentRepository; - - @Resource - private EnrollmentGradesRepository enrollmentGradesRepository; - @Resource private FreeEnrollmentRepository freeEnrollmentRepository; @@ -86,8 +80,6 @@ public void setup() { clerkEnrollmentService = new ClerkEnrollmentService( enrollmentRepository, - enrollmentAppointmentRepository, - enrollmentGradesRepository, examEventRepository, paymentRepository, auditService, diff --git a/frontend/packages/vkt/src/enums/api.ts b/frontend/packages/vkt/src/enums/api.ts index 7e8ab7f78..9ab5f5c98 100644 --- a/frontend/packages/vkt/src/enums/api.ts +++ b/frontend/packages/vkt/src/enums/api.ts @@ -13,9 +13,6 @@ export enum APIEndpoints { ClerkUser = '/vkt/api/v1/clerk/user', PublicUser = '/vkt/api/v1/auth/info', ClerkEnrollment = '/vkt/api/v1/clerk/enrollment', - ClerkEnrollmentContactRequest = '/vkt/api/v1/clerk/enrollment/contact', - ClerkEnrollmentAppointment = '/vkt/api/v1/clerk/enrollment/appointment', - ExaminerEnrollmentAppointment = '/vkt/api/v1/tv/:oid/enrollment/appointment', ClerkPayment = '/vkt/api/v1/clerk/payment', FeatureFlags = '/vkt/api/v1/featureFlags', UploadPostPolicy = '/vkt/api/v1/uploadPostPolicy/:examEventId', @@ -25,6 +22,8 @@ export enum APIEndpoints { ExaminerDetails = '/vkt/api/v1/tv/:oid', ExaminerDetailsInit = '/vkt/api/v1/tv/:oid/init', ExaminerExamEvent = '/vkt/api/v1/tv/:oid/examEvent', + ExaminerEnrollmentAppointment = '/vkt/api/v1/tv/:oid/enrollment/appointment', + ExaminerEnrollmentContactRequest = '/vkt/api/v1/tv/:oid/enrollment/contact', } /** diff --git a/frontend/packages/vkt/src/pages/ClerkEnrollmentAppointmentOverviewPage.tsx b/frontend/packages/vkt/src/pages/ClerkEnrollmentAppointmentOverviewPage.tsx index ad70b063b..182192d52 100644 --- a/frontend/packages/vkt/src/pages/ClerkEnrollmentAppointmentOverviewPage.tsx +++ b/frontend/packages/vkt/src/pages/ClerkEnrollmentAppointmentOverviewPage.tsx @@ -40,9 +40,14 @@ export const ClerkEnrollmentAppointmentOverviewPage: FC< status === APIResponseStatus.NotStarted && params.enrollmentAppointmentId ) { - dispatch(loadClerkEnrollmentAppointment(+params.enrollmentAppointmentId)); + dispatch( + loadClerkEnrollmentAppointment({ + id: +params.enrollmentAppointmentId, + oid: params.oid || '', + }), + ); } - }, [dispatch, status, params.enrollmentAppointmentId]); + }, [dispatch, status, params.enrollmentAppointmentId, params.oid]); useEffect(() => { if (examEventsStatus === APIResponseStatus.NotStarted && params.oid) { diff --git a/frontend/packages/vkt/src/pages/ClerkEnrollmentContactRequestPage.tsx b/frontend/packages/vkt/src/pages/ClerkEnrollmentContactRequestPage.tsx index af82077a6..d855c99a4 100644 --- a/frontend/packages/vkt/src/pages/ClerkEnrollmentContactRequestPage.tsx +++ b/frontend/packages/vkt/src/pages/ClerkEnrollmentContactRequestPage.tsx @@ -36,13 +36,17 @@ export const ClerkEnrollmentContactRequestPage: FC = () => { useEffect(() => { if ( status === APIResponseStatus.NotStarted && - params.enrollmentContactRequestId + params.enrollmentContactRequestId && + params.oid ) { dispatch( - loadClerkEnrollmentContactRequest(+params.enrollmentContactRequestId), + loadClerkEnrollmentContactRequest({ + id: +params.enrollmentContactRequestId, + oid: params.oid, + }), ); } - }, [dispatch, status, params.enrollmentContactRequestId]); + }, [dispatch, status, params.enrollmentContactRequestId, params.oid]); useEffect(() => { if ( @@ -101,7 +105,12 @@ export const ClerkEnrollmentContactRequestPage: FC = () => { }; const onSubmit = () => { - dispatch(createClerkEnrollmentAppointment(enrollment.id)); + dispatch( + createClerkEnrollmentAppointment({ + id: enrollment.id, + oid: params.oid || '', + }), + ); }; const backTo = AppRoutes.ExaminerHomePage.replace(':oid', params.oid || ''); diff --git a/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentAppointment.ts b/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentAppointment.ts index 2c9b16bcd..fb3b34255 100644 --- a/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentAppointment.ts +++ b/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentAppointment.ts @@ -57,7 +57,13 @@ const clerkEnrollmentAppointmentSlice = createSlice({ state.examEvents = action.payload; state.examEventsStatus = APIResponseStatus.Success; }, - loadClerkEnrollmentAppointment(state, _action: PayloadAction) { + loadClerkEnrollmentAppointment( + state, + _action: PayloadAction<{ + id: number; + oid: string; + }>, + ) { state.status = APIResponseStatus.InProgress; }, storeClerkEnrollmentAppointment( diff --git a/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentContactRequest.ts b/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentContactRequest.ts index 311424ffb..ee83ddeb3 100644 --- a/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentContactRequest.ts +++ b/frontend/packages/vkt/src/redux/reducers/clerkEnrollmentContactRequest.ts @@ -18,7 +18,13 @@ const clerkEnrollmentContactRequestSlice = createSlice({ name: 'clerkEnrollmentContactRequest', initialState, reducers: { - loadClerkEnrollmentContactRequest(state, _action: PayloadAction) { + loadClerkEnrollmentContactRequest( + state, + _action: PayloadAction<{ + id: number; + oid: string; + }>, + ) { state.status = APIResponseStatus.InProgress; }, storeClerkEnrollmentContactRequest( @@ -31,7 +37,13 @@ const clerkEnrollmentContactRequestSlice = createSlice({ rejectClerkEnrollmentContactRequest(state) { state.status = APIResponseStatus.Error; }, - createClerkEnrollmentAppointment(state, _action: PayloadAction) { + createClerkEnrollmentAppointment( + state, + _action: PayloadAction<{ + id: number; + oid: string; + }>, + ) { state.createStatus = APIResponseStatus.InProgress; }, storeCreateClerkEnrollmentAppointment( diff --git a/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentAppointment.ts b/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentAppointment.ts index 7298c7fee..dcaa0113a 100644 --- a/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentAppointment.ts +++ b/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentAppointment.ts @@ -56,7 +56,7 @@ function* upsertClerkEnrollmentAppointmentGradesSaga( const apiResponse: AxiosResponse = yield call( axiosInstance.put, - `${APIEndpoints.ExaminerEnrollmentAppointment.replace(':oid', oid)}/${ + `${APIEndpoints.ExaminerEnrollmentAppointment.replace(/:oid/, oid)}/${ enrollment.id }/grades`, nonEmptyGrades, @@ -82,7 +82,7 @@ function* updateClerkEnrollmentAppointmentSaga( const apiResponse: AxiosResponse = yield call( axiosInstance.put, - `${APIEndpoints.ExaminerEnrollmentAppointment.replace(':oid', oid)}/${ + `${APIEndpoints.ExaminerEnrollmentAppointment.replace(/:oid/, oid)}/${ enrollment.id }`, SerializationUtils.serializeClerkEnrollmentAppointment(enrollment), @@ -100,10 +100,18 @@ function* updateClerkEnrollmentAppointmentSaga( } } -function* loadClerkEnrollmentAppointmentSaga(action: PayloadAction) { +function* loadClerkEnrollmentAppointmentSaga( + action: PayloadAction<{ + id: number; + oid: string; + }>, +) { try { - const appointmentId = action.payload; - const loadUrl = `${APIEndpoints.ClerkEnrollmentAppointment}/${appointmentId}`; + const { id, oid } = action.payload; + const loadUrl = `${APIEndpoints.ExaminerEnrollmentAppointment.replace( + /:oid/, + oid, + )}/${id}`; const response: AxiosResponse = yield call(axiosInstance.get, loadUrl); @@ -120,7 +128,7 @@ function* loadClerkEnrollmentAppointmentSaga(action: PayloadAction) { function* loadExaminerExamEventsSaga(action: PayloadAction) { try { const oid = action.payload; - const loadUrl = APIEndpoints.ExaminerExamEvent.replace(':oid', oid); + const loadUrl = APIEndpoints.ExaminerExamEvent.replace(/:oid/, oid); const response: AxiosResponse> = yield call(axiosInstance.get, loadUrl); diff --git a/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentContactRequest.ts b/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentContactRequest.ts index 35de27dc1..b4522fd1c 100644 --- a/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentContactRequest.ts +++ b/frontend/packages/vkt/src/redux/sagas/clerkEnrollmentContactRequest.ts @@ -15,10 +15,18 @@ import { } from 'redux/reducers/clerkEnrollmentContactRequest'; import { SerializationUtils } from 'utils/serialization'; -function* createClerkEnrollmentAppointmentSaga(action: PayloadAction) { +function* createClerkEnrollmentAppointmentSaga( + action: PayloadAction<{ + id: number; + oid: string; + }>, +) { try { - const contactId = action.payload; - const saveUrl = `${APIEndpoints.ClerkEnrollmentContactRequest}/${contactId}/convertToAppointment`; + const { id, oid } = action.payload; + const saveUrl = `${APIEndpoints.ExaminerEnrollmentContactRequest.replace( + /:oid/, + oid, + )}/${id}/convertToAppointment`; const response: AxiosResponse = yield call( axiosInstance.post, @@ -35,10 +43,18 @@ function* createClerkEnrollmentAppointmentSaga(action: PayloadAction) { } } -function* loadClerkEnrollmentContactRequestSaga(action: PayloadAction) { +function* loadClerkEnrollmentContactRequestSaga( + action: PayloadAction<{ + id: number; + oid: string; + }>, +) { try { - const contactId = action.payload; - const loadUrl = `${APIEndpoints.ClerkEnrollmentContactRequest}/${contactId}`; + const { id, oid } = action.payload; + const loadUrl = `${APIEndpoints.ExaminerEnrollmentContactRequest.replace( + /:oid/, + oid, + )}/${id}`; const response: AxiosResponse = yield call( axiosInstance.get,