From 3ead13a0704d42321bc18f1ff18fb1693dea4fdf Mon Sep 17 00:00:00 2001 From: Oliver Scott Date: Fri, 13 Dec 2024 12:07:39 +0000 Subject: [PATCH] Change collection properties back to original models --- ...i-contract-to-client-model-mappers.spec.ts | 280 ++++++------------ .../api-contract-to-client-model-mappers.ts | 219 ++++++-------- .../src/app/common/model/vh-booking.ts | 121 +------- .../services/video-hearings.service.spec.ts | 83 ------ .../app/services/video-hearings.service.ts | 91 +----- 5 files changed, 184 insertions(+), 610 deletions(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.spec.ts index 39c9a0024..a6aa9f21c 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.spec.ts @@ -15,15 +15,13 @@ import { } from 'src/app/services/clients/api-client'; import { VHBooking } from './vh-booking'; import { + mapCaseResponseToCaseModel, + mapEndpointResponseToEndpointModel, mapHearingToVHBooking, - mapCaseToVHCase, - mapParticipantToVHParticipant, - mapLinkedParticipantResponseToVHLinkedParticipant, - mapAvailableLanguageToVHInterpreterSelected, - mapScreeningResponseToVHScreening, - mapJudiciaryParticipantToVHJudiciaryParticipant, - mapEndpointToVHEndpoint + mapLinkedParticipantResponseToLinkedParticipantModel, + mapParticipantResponseToParticipantModel } from './api-contract-to-client-model-mappers'; +import { JudicialMemberDto } from 'src/app/booking/judicial-office-holders/models/add-judicial-member.model'; const DEFENCE_COUNSEL_ID = 'defence-counsel-id'; @@ -55,200 +53,90 @@ describe('mapHearingToVHBooking', () => { }); }); -describe('mapCaseToVHCase', () => { - it('should map case', () => { - // Arrange - const caseResponse = createCases()[0]; - - // Act - const result = mapCaseToVHCase(caseResponse); - - // Assert - expect(result.number).toBe(caseResponse.number); - expect(result.name).toBe(caseResponse.name); - expect(result.isLeadCase).toBe(caseResponse.is_lead_case); +describe('mapParticipantResponseToParticipantModel', () => { + it('should map ParticipantResponse to ParticipantModel', () => { + const participants: ParticipantResponse[] = []; + const participant = new ParticipantResponse(); + participant.title = 'Mr'; + participant.first_name = 'Dan'; + participant.middle_names = 'Ivan'; + participant.last_name = 'Smith'; + participant.username = 'dan@hmcts.net'; + participant.display_name = 'Dan Smith'; + participant.contact_email = 'dan@hmcts.net'; + participant.telephone_number = '123123123'; + participant.hearing_role_name = 'Litigant in person'; + participant.user_role_name = 'Individual'; + participant.interpreter_language = null; + participants.push(participant); + + const judgeParticipant = new ParticipantResponse(); + judgeParticipant.title = 'Mr'; + judgeParticipant.first_name = 'Judge'; + judgeParticipant.middle_names = 'MiddleNames'; + judgeParticipant.last_name = 'Test'; + judgeParticipant.username = 'judge@hmcts.net'; + judgeParticipant.display_name = 'Judge Test'; + judgeParticipant.contact_email = 'judge@hmcts.net'; + judgeParticipant.telephone_number = '123123123'; + judgeParticipant.hearing_role_name = null; + judgeParticipant.user_role_name = 'Judge'; + judgeParticipant.interpreter_language = null; + participants.push(judgeParticipant); + + const model = mapParticipantResponseToParticipantModel(participants); + + expect(model[0].title).toEqual(participant.title); + expect(model[0].first_name).toEqual(participant.first_name); + expect(model[0].middle_names).toEqual(participant.middle_names); + expect(model[0].last_name).toEqual(participant.last_name); + expect(model[0].username).toEqual(participant.username); + expect(model[0].display_name).toEqual(participant.display_name); + expect(model[0].email).toEqual(participant.contact_email); + expect(model[0].phone).toEqual(participant.telephone_number); + expect(model[0].hearing_role_name).toEqual(participant.hearing_role_name); + expect(model[0].is_judge).toBeFalse(); + expect(model[0].interpretation_language).toBeNull(); + + expect(model[1].title).toEqual(judgeParticipant.title); + expect(model[1].first_name).toEqual(judgeParticipant.first_name); + expect(model[1].middle_names).toEqual(judgeParticipant.middle_names); + expect(model[1].last_name).toEqual(judgeParticipant.last_name); + expect(model[1].username).toEqual(judgeParticipant.username); + expect(model[1].display_name).toEqual(judgeParticipant.display_name); + expect(model[1].email).toEqual(judgeParticipant.contact_email); + expect(model[1].phone).toEqual(judgeParticipant.telephone_number); + expect(model[1].hearing_role_name).toEqual(judgeParticipant.hearing_role_name); + expect(model[1].is_judge).toBeTrue(); + expect(model[1].interpretation_language).toBeNull(); }); }); -describe('mapParticipantToVHParticipant', () => { - it('should map participant', () => { - // Arrange - const participant = createParticipants().find(p => p.representee !== null); - - // Act - const result = mapParticipantToVHParticipant(participant); - - // Assert - expect(result.id).toBe(participant.id); - expect(result.externalReferenceId).toBe(participant.external_reference_id); - expect(result.title).toBe(participant.title); - expect(result.first_name).toBe(participant.first_name); - expect(result.last_name).toBe(participant.last_name); - expect(result.middle_names).toBe(participant.middle_names); - expect(result.display_name).toBe(participant.display_name); - expect(result.username).toBe(participant.username); - expect(result.email).toBe(participant.contact_email); - expect(result.hearing_role_name).toBe(participant.hearing_role_name); - expect(result.hearing_role_code).toBe(participant.hearing_role_code); - expect(result.phone).toBe(participant.telephone_number); - expect(result.representee).toBe(participant.representee); - expect(result.company).toBe(participant.organisation); - expect(result.is_judge).toBe(false); - expect(result.linked_participants).toEqual( - participant.linked_participants?.map(linkedParticipant => mapLinkedParticipantResponseToVHLinkedParticipant(linkedParticipant)) - ); - expect(result.user_role_name).toBe(participant.user_role_name); - expect(result.is_staff_member).toBe(false); - expect(result.interpretation_language).toEqual(mapAvailableLanguageToVHInterpreterSelected(participant.interpreter_language)); - expect(result.screening).toEqual(mapScreeningResponseToVHScreening(participant.screening_requirement)); +describe('mapEndpointResponseToEndpointModel', () => { + it('should map EndpointResponse to EndpointModel', () => { + const endpoints: EndpointResponse[] = []; + const endpoint = new EndpointResponse(); + endpoint.display_name = 'endpoint 001'; + endpoint.interpreter_language = null; + endpoints.push(endpoint); + + const model = mapEndpointResponseToEndpointModel(endpoints, []); + expect(model[0].displayName).toEqual(endpoint.display_name); + expect(model[0].interpretationLanguage).toBeNull(); }); }); -describe('mapLinkedParticipantResponseToVHLinkedParticipant', () => { - it('should map linked participant', () => { - // Arrange +describe('mapLinkedParticipantResponseToLinkedParticipantModel', () => { + it('should map LinkedParticipantResponse to LinkedParticipantModel', () => { + const linkedParticipants: LinkedParticipantResponse[] = []; const linkedParticipant = new LinkedParticipantResponse(); linkedParticipant.type = LinkedParticipantType.Interpreter; - linkedParticipant.linked_id = 'linked-id'; - - // Act - const result = mapLinkedParticipantResponseToVHLinkedParticipant(linkedParticipant); - - // Assert - expect(result.linkType).toBe(linkedParticipant.type); - expect(result.linkedParticipantId).toBe(linkedParticipant.linked_id); - }); -}); + linkedParticipant.linked_id = '100'; + linkedParticipants.push(linkedParticipant); -describe('mapJudiciaryParticipantToVHJudiciaryParticipant', () => { - it('should map judiciary participant', () => { - // Arrange - const judiciaryParticipant = createJudiciaryParticipants()[0]; - - // Act - const result = mapJudiciaryParticipantToVHJudiciaryParticipant(judiciaryParticipant); - - // Assert - expect(result.firstName).toBe(judiciaryParticipant.first_name); - expect(result.lastName).toBe(judiciaryParticipant.last_name); - expect(result.fullName).toBe(judiciaryParticipant.full_name); - expect(result.email).toBe(judiciaryParticipant.email); - expect(result.telephone).toBe(judiciaryParticipant.work_phone); - expect(result.personalCode).toBe(judiciaryParticipant.personal_code); - expect(result.isGeneric).toBe(judiciaryParticipant.is_generic); - expect(result.optionalContactNumber).toBe(judiciaryParticipant.optional_contact_telephone); - expect(result.optionalContactEmail).toBe(judiciaryParticipant.optional_contact_email); - expect(result.roleCode).toBe(judiciaryParticipant.role_code); - expect(result.displayName).toBe(judiciaryParticipant.display_name); - expect(result.interpretationLanguage).toEqual( - mapAvailableLanguageToVHInterpreterSelected(judiciaryParticipant.interpreter_language) - ); - }); -}); - -describe('mapEndpointToVHEndpoint', () => { - it('should map endpoint', () => { - // Arrange - const endpoint = createEndpoints()[0]; - const participants = createParticipants(); - const defenceAdvocate = participants.find(p => p.id === endpoint.defence_advocate_id); - - // Act - const result = mapEndpointToVHEndpoint(endpoint, participants); - - // Assert - expect(result.id).toBe(endpoint.id); - expect(result.externalReferenceId).toBe(endpoint.external_reference_id); - expect(result.displayName).toBe(endpoint.display_name); - expect(result.sip).toBe(endpoint.sip); - expect(result.pin).toBe(endpoint.pin); - expect(result.defenceAdvocate).toBe(defenceAdvocate.contact_email); - expect(result.interpretationLanguage).toEqual(mapAvailableLanguageToVHInterpreterSelected(endpoint.interpreter_language)); - expect(result.screening).toEqual(mapScreeningResponseToVHScreening(endpoint.screening_requirement)); - }); -}); - -describe('mapAvailableLanguageToVHInterpreterSelected', () => { - it('should map verbal language', () => { - // Arrange - const language = new AvailableLanguageResponse(); - language.code = 'cym'; - language.description = 'Welsh'; - language.type = InterprepretationType.Verbal; - - // Act - const result = mapAvailableLanguageToVHInterpreterSelected(language); - - // Assert - expect(result.interpreterRequired).toBe(true); - expect(result.spokenLanguageCode).toBe(language.code); - expect(result.spokenLanguageCodeDescription).toBe(language.description); - expect(result.signLanguageCode).toBeNull(); - expect(result.signLanguageDescription).toBeNull(); - }); - - it('should map sign language', () => { - const language = new AvailableLanguageResponse(); - language.code = 'bfi'; - language.description = 'British Sign Language (BSL)'; - language.type = InterprepretationType.Sign; - - // Act - const result = mapAvailableLanguageToVHInterpreterSelected(language); - - // Assert - expect(result.interpreterRequired).toBe(true); - expect(result.signLanguageCode).toBe(language.code); - expect(result.signLanguageDescription).toBe(language.description); - expect(result.spokenLanguageCode).toBeNull(); - expect(result.spokenLanguageCodeDescription).toBeNull(); - }); - - it('should return null when no language specified', () => { - // Arrange & Act - const result = mapAvailableLanguageToVHInterpreterSelected(null); - - // Assert - expect(result).toBeNull(); - }); - - it('should throw error when invalid language specified', () => { - // Arrange - const language = new AvailableLanguageResponse(); - language.code = 'cym'; - language.description = 'Welsh'; - language.type = 'invalid' as InterprepretationType; - - // Act & Assert - expect(() => mapAvailableLanguageToVHInterpreterSelected(language)).toThrowError(`Unknown interpretation type ${language.type}`); - }); -}); - -describe('mapScreeningResponseToVHScreening', () => { - it('should map screening for All type', () => { - // Arrange - const screening = new ScreeningResponse(); - screening.protect_from = ['external-ref-id-1', 'external-ref-id-2']; - screening.type = ScreeningType.All; - - // Act - const result = mapScreeningResponseToVHScreening(screening); - - // Assert - expect(result.measureType).toBe('All'); - }); - - it('should map screening for Specific type', () => { - // Arrange - const screening = new ScreeningResponse(); - screening.protect_from = ['external-ref-id-1', 'external-ref-id-2']; - screening.type = ScreeningType.Specific; - - // Act - const result = mapScreeningResponseToVHScreening(screening); - - // Assert - expect(result.measureType).toBe('Specific'); + const model = mapLinkedParticipantResponseToLinkedParticipantModel(linkedParticipants); + expect(model[0].linkType).toEqual(linkedParticipant.type); + expect(model[0].linkedParticipantId).toEqual(linkedParticipant.linked_id); }); }); @@ -463,10 +351,10 @@ function verifyVHBooking(vhBooking: VHBooking, hearing: HearingDetailsResponse) expect(vhBooking.court_name).toBe(hearing.hearing_venue_name); expect(vhBooking.case_type_service_id).toBe(hearing.service_id); expect(vhBooking.case_type).toBe(hearing.case_type_name); - expect(vhBooking.case).toEqual(mapCaseToVHCase(hearing.cases[0])); - expect(vhBooking.participants).toEqual(hearing.participants.map(participant => mapParticipantToVHParticipant(participant))); + expect(vhBooking.case).toEqual(mapCaseResponseToCaseModel(hearing.cases)[0]); + expect(vhBooking.participants).toEqual(mapParticipantResponseToParticipantModel(hearing.participants)); expect(vhBooking.judiciaryParticipants).toEqual( - hearing.judiciary_participants.map(judiciaryParticipant => mapJudiciaryParticipantToVHJudiciaryParticipant(judiciaryParticipant)) + hearing.judiciary_participants.map(judiciaryParticipant => JudicialMemberDto.fromJudiciaryParticipantResponse(judiciaryParticipant)) ); expect(vhBooking.court_room).toBe(hearing.hearing_room_name); expect(vhBooking.other_information).toBe(hearing.other_information); @@ -476,7 +364,7 @@ function verifyVHBooking(vhBooking: VHBooking, hearing: HearingDetailsResponse) expect(vhBooking.updated_date).toEqual(hearing.updated_date); expect(vhBooking.status).toBe(hearing.status); expect(vhBooking.audio_recording_required).toBe(hearing.audio_recording_required); - expect(vhBooking.endpoints).toEqual(hearing.endpoints.map(endpoint => mapEndpointToVHEndpoint(endpoint, hearing.participants))); + expect(vhBooking.endpoints).toEqual(mapEndpointResponseToEndpointModel(hearing.endpoints, hearing.participants)); expect(vhBooking.originalScheduledDateTime).toEqual(hearing.scheduled_date_time); expect(vhBooking.supplier).toBe(hearing.conference_supplier); } diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.ts index 549229d12..a39f5809a 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/api-contract-to-client-model-mappers.ts @@ -1,38 +1,29 @@ import { - AvailableLanguageResponse, CaseResponse, - EndpointResponse, HearingDetailsResponse, - InterprepretationType, ParticipantResponse, - ScreeningResponse, - ScreeningType as ApiScreeningType, - JudiciaryParticipantResponse, - LinkedParticipantResponse + LinkedParticipantResponse, + EndpointResponse } from 'src/app/services/clients/api-client'; import { Constants } from 'src/app/common/constants'; -import { v4 as uuid } from 'uuid'; -import { - VHBooking, - VHCase, - VHParticipant, - VHLinkedParticipant, - VHJudiciaryParticipant, - VHJudicaryRoleCode, - VHEndpoint, - VHInterpreterSelected, - VHScreening -} from './vh-booking'; +import { VHBooking } from './vh-booking'; +import { CaseModel } from './case.model'; +import { InterpreterSelectedDto } from 'src/app/booking/interpreter-form/interpreter-selected.model'; +import { mapScreeningResponseToScreeningDto } from 'src/app/booking/screening/screening.model'; +import { ParticipantModel } from './participant.model'; +import { LinkedParticipantModel } from './linked-participant.model'; +import { JudicialMemberDto } from 'src/app/booking/judicial-office-holders/models/add-judicial-member.model'; +import { EndpointModel } from './endpoint.model'; export function mapHearingToVHBooking(hearing: HearingDetailsResponse): VHBooking { return { hearing_id: hearing.id, scheduled_date_time: new Date(hearing.scheduled_date_time), scheduled_duration: hearing.scheduled_duration, - case: mapCaseToVHCase(hearing.cases[0]), - participants: hearing.participants?.map(participant => mapParticipantToVHParticipant(participant)), + case: mapCaseResponseToCaseModel(hearing.cases)[0], + participants: mapParticipantResponseToParticipantModel(hearing.participants), judiciaryParticipants: hearing.judiciary_participants?.map(judiciaryParticipant => - mapJudiciaryParticipantToVHJudiciaryParticipant(judiciaryParticipant) + JudicialMemberDto.fromJudiciaryParticipantResponse(judiciaryParticipant) ), created_by: hearing.created_by, case_type: hearing.case_type_name, @@ -46,7 +37,7 @@ export function mapHearingToVHBooking(hearing: HearingDetailsResponse): VHBookin updated_date: new Date(hearing.updated_date), status: hearing.status, audio_recording_required: hearing.audio_recording_required, - endpoints: hearing.endpoints?.map(endpoint => mapEndpointToVHEndpoint(endpoint, hearing.participants)), + endpoints: mapEndpointResponseToEndpointModel(hearing.endpoints, hearing.participants), isMultiDay: hearing.group_id !== null, multiDayHearingLastDayScheduledDateTime: hearing.multi_day_hearing_last_day_scheduled_date_time, hearingsInGroup: hearing.hearings_in_group?.map(hearingInGroup => mapHearingToVHBooking(hearingInGroup)), @@ -55,120 +46,86 @@ export function mapHearingToVHBooking(hearing: HearingDetailsResponse): VHBookin }; } -export function mapCaseToVHCase(caseResponse: CaseResponse): VHCase { - return { - number: caseResponse.number, - name: caseResponse.name, - isLeadCase: caseResponse.is_lead_case - }; -} - -export function mapParticipantToVHParticipant(participant: ParticipantResponse): VHParticipant { - return { - id: participant.id, - externalReferenceId: participant.external_reference_id, - title: participant.title, - first_name: participant.first_name, - last_name: participant.last_name, - middle_names: participant.middle_names, - display_name: participant.display_name, - username: participant.username, - email: participant.contact_email, - hearing_role_name: participant.hearing_role_name, - hearing_role_code: participant.hearing_role_code, - phone: participant.telephone_number, - representee: participant.representee, - company: participant.organisation, - is_judge: participant.user_role_name === Constants.UserRoles.Judge, - linked_participants: participant.linked_participants?.map(linkedParticipant => - mapLinkedParticipantResponseToVHLinkedParticipant(linkedParticipant) - ), - user_role_name: participant.user_role_name, - is_staff_member: participant.user_role_name === Constants.UserRoles.StaffMember, - interpretation_language: mapAvailableLanguageToVHInterpreterSelected(participant.interpreter_language), - screening: mapScreeningResponseToVHScreening(participant.screening_requirement) - }; -} - -export function mapLinkedParticipantResponseToVHLinkedParticipant(linkedParticipant: LinkedParticipantResponse): VHLinkedParticipant { - return { - linkType: linkedParticipant.type, - linkedParticipantId: linkedParticipant.linked_id - }; -} - -export function mapJudiciaryParticipantToVHJudiciaryParticipant( - judiciaryParticipant: JudiciaryParticipantResponse -): VHJudiciaryParticipant { - return { - firstName: judiciaryParticipant.first_name, - lastName: judiciaryParticipant.last_name, - fullName: judiciaryParticipant.full_name, - email: judiciaryParticipant.email, - telephone: judiciaryParticipant.work_phone, - personalCode: judiciaryParticipant.personal_code, - isGeneric: judiciaryParticipant.is_generic, - optionalContactNumber: judiciaryParticipant.optional_contact_telephone, - optionalContactEmail: judiciaryParticipant.optional_contact_email, - roleCode: judiciaryParticipant.role_code as VHJudicaryRoleCode, - displayName: judiciaryParticipant.display_name, - interpretationLanguage: mapAvailableLanguageToVHInterpreterSelected(judiciaryParticipant.interpreter_language) - }; -} - -export function mapEndpointToVHEndpoint(endpoint: EndpointResponse, participants: ParticipantResponse[]): VHEndpoint { - const defenceAdvocate = participants.find(p => p.id === endpoint.defence_advocate_id); - return { - externalReferenceId: endpoint.external_reference_id || uuid(), - id: endpoint.id, - displayName: endpoint.display_name, - sip: endpoint.sip, - pin: endpoint.pin, - defenceAdvocate: defenceAdvocate?.contact_email, - interpretationLanguage: mapAvailableLanguageToVHInterpreterSelected(endpoint.interpreter_language), - screening: mapScreeningResponseToVHScreening(endpoint.screening_requirement) - }; +export function mapCaseResponseToCaseModel(casesResponse: CaseResponse[]): CaseModel[] { + const cases: CaseModel[] = []; + let caseRequest: CaseModel; + if (casesResponse && casesResponse.length > 0) { + casesResponse.forEach(c => { + caseRequest = new CaseModel(); + caseRequest.name = c.name; + caseRequest.number = c.number; + caseRequest.isLeadCase = c.is_lead_case; + cases.push(caseRequest); + }); + } + return cases; } -export function mapAvailableLanguageToVHInterpreterSelected(availableLanguage: AvailableLanguageResponse): VHInterpreterSelected { - if (!availableLanguage) { - return null; +export function mapParticipantResponseToParticipantModel(response: ParticipantResponse[]): ParticipantModel[] { + const participants: ParticipantModel[] = []; + let participant: ParticipantModel; + if (response && response.length > 0) { + response.forEach(p => { + participant = new ParticipantModel(); + participant.id = p.id; + participant.title = p.title; + participant.first_name = p.first_name; + participant.middle_names = p.middle_names; + participant.last_name = p.last_name; + participant.username = p.username; + participant.display_name = p.display_name; + participant.email = p.contact_email; + participant.phone = p.telephone_number; + participant.hearing_role_name = p.hearing_role_name; + participant.hearing_role_code = p.hearing_role_code; + participant.representee = p.representee; + participant.company = p.organisation; + participant.is_judge = p.user_role_name === Constants.UserRoles.Judge; + participant.is_staff_member = p.user_role_name === Constants.UserRoles.StaffMember; + participant.linked_participants = mapLinkedParticipantResponseToLinkedParticipantModel(p.linked_participants); + participant.user_role_name = p.user_role_name; + participant.interpretation_language = InterpreterSelectedDto.fromAvailableLanguageResponse(p.interpreter_language); + participant.screening = mapScreeningResponseToScreeningDto(p.screening_requirement); + if (p.external_reference_id) { + // only override the external reference id if it is not null else ParticipantModel will initialise to a UUID in the ctor + participant.externalReferenceId = p.external_reference_id; + } + participants.push(participant); + }); } + return participants; +} - const interpreterSelected: VHInterpreterSelected = { - interpreterRequired: true, - spokenLanguageCode: null, - spokenLanguageCodeDescription: null, - signLanguageCode: null, - signLanguageDescription: null - }; - switch (availableLanguage.type) { - case InterprepretationType.Verbal: - interpreterSelected.spokenLanguageCode = availableLanguage.code; - interpreterSelected.spokenLanguageCodeDescription = availableLanguage.description; - break; - case InterprepretationType.Sign: - interpreterSelected.signLanguageCode = availableLanguage.code; - interpreterSelected.signLanguageDescription = availableLanguage.description; - break; - default: - throw new Error(`Unknown interpretation type ${availableLanguage.type}`); +export function mapLinkedParticipantResponseToLinkedParticipantModel(response: LinkedParticipantResponse[]): LinkedParticipantModel[] { + const linkedParticipants: LinkedParticipantModel[] = []; + let linkedParticipant: LinkedParticipantModel; + if (response && response.length > 0) { + response.forEach(p => { + linkedParticipant = new LinkedParticipantModel(); + linkedParticipant.linkType = p.type; + linkedParticipant.linkedParticipantId = p.linked_id; + linkedParticipants.push(linkedParticipant); + }); } - - return interpreterSelected; + return linkedParticipants; } -export function mapScreeningResponseToVHScreening(response: ScreeningResponse): VHScreening { - if (!response) { - return undefined; +export function mapEndpointResponseToEndpointModel(response: EndpointResponse[], participants: ParticipantResponse[]): EndpointModel[] { + const endpoints: EndpointModel[] = []; + let endpoint: EndpointModel; + if (response && response.length > 0) { + response.forEach(e => { + const defenceAdvocate = participants.find(p => p.id === e.defence_advocate_id); + endpoint = new EndpointModel(e.external_reference_id); + endpoint.id = e.id; + endpoint.displayName = e.display_name; + endpoint.pin = e.pin; + endpoint.sip = e.sip; + endpoint.defenceAdvocate = defenceAdvocate?.contact_email; + endpoint.interpretationLanguage = InterpreterSelectedDto.fromAvailableLanguageResponse(e.interpreter_language); + endpoint.screening = mapScreeningResponseToScreeningDto(e.screening_requirement); + endpoints.push(endpoint); + }); } - - const mappedProtectFrom = response.protect_from.map(protectFrom => ({ - externalReferenceId: protectFrom - })); - - return { - measureType: response.type === ApiScreeningType.All ? 'All' : 'Specific', - protectFrom: mappedProtectFrom - }; + return endpoints; } diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/vh-booking.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/vh-booking.ts index 0f1a1fa1b..e4088301f 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/vh-booking.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/common/model/vh-booking.ts @@ -1,12 +1,17 @@ -import { LinkedParticipantType, VideoSupplier } from 'src/app/services/clients/api-client'; +import { VideoSupplier } from 'src/app/services/clients/api-client'; +import { CaseModel } from './case.model'; +import { ParticipantModel } from './participant.model'; +import { JudicialMemberDto } from 'src/app/booking/judicial-office-holders/models/add-judicial-member.model'; +import { EndpointModel } from './endpoint.model'; +import { LinkedParticipantModel } from './linked-participant.model'; export interface VHBooking { hearing_id?: string; scheduled_date_time?: Date; scheduled_duration?: number; - case?: VHCase; - participants?: VHParticipant[]; - judiciaryParticipants?: VHJudiciaryParticipant[]; + case?: CaseModel; + participants?: ParticipantModel[]; + judiciaryParticipants?: JudicialMemberDto[]; created_by?: string; case_type?: string; case_type_service_id?: string; @@ -21,11 +26,11 @@ export interface VHBooking { updated_date: Date; status?: string; audio_recording_required?: boolean; - endpoints?: VHEndpoint[]; + endpoints?: EndpointModel[]; isMultiDayEdit?: boolean; end_hearing_date_time?: Date; telephone_conference_id?: string; - linked_participants?: VHLinkedParticipant[]; + linked_participants?: LinkedParticipantModel[]; hearing_dates?: Date[]; isConfirmed?: boolean; isMultiDay?: boolean; @@ -48,107 +53,3 @@ export function createVHBooking(): VHBooking { supplier: VideoSupplier.Vodafone }; } - -export interface VHCase { - number?: string; - name?: string; - isLeadCase?: boolean; -} - -export interface VHParticipant { - id?: string; - externalReferenceId?: string; - title?: string; - first_name?: string; - last_name?: string; - middle_names?: string; - display_name?: string; - username?: string; - email?: string; - hearing_role_name?: string; - hearing_role_code?: string; - phone?: string; - representee?: string; - company?: string; - is_judge?: boolean; - is_exist_person?: boolean; - interpreterFor?: string; - linked_participants?: VHLinkedParticipant[]; - interpretee_name?: string; - is_interpretee?: boolean; - user_role_name?: string; - is_courtroom_account?: boolean; - addedDuringHearing?: boolean; - is_staff_member?: boolean; - contact_email?: string; - isJudiciaryMember?: boolean; - interpretation_language: VHInterpreterSelected; - screening?: VHScreening; -} - -export interface VHLinkedParticipant { - id?: string; - participantId?: string; - participantEmail?: string; - linkedParticipantId?: string; - linkedParticipantEmail?: string; - linkType?: LinkedParticipantType; -} - -export interface VHJudiciaryParticipant { - firstName: string; - lastName: string; - fullName: string; - email: string; - telephone: string; - personalCode: string; - isGeneric: boolean; - roleCode?: VHJudicaryRoleCode; - displayName: string; - optionalContactNumber: string; - optionalContactEmail: string; - interpretationLanguage: VHInterpreterSelected; -} - -export type VHJudicaryRoleCode = 'Judge' | 'PanelMember'; - -export interface VHEndpoint { - externalReferenceId: string; - id?: string; - displayName?: string; - sip?: string; - pin?: string; - /** - * Defence advocate email address, not their ID - */ - defenceAdvocate?: string; - username?: string; - contactEmail?: string; - interpretationLanguage: VHInterpreterSelected; - screening?: VHScreening; -} - -export interface VHVenue { - id: number; - name: string; - code: string; -} - -export interface VHInterpreterSelected { - interpreterRequired: boolean; - signLanguageCode?: string; - signLanguageDescription?: string; - spokenLanguageCode?: string; - spokenLanguageCodeDescription?: string; -} - -export interface VHScreening { - measureType: ScreeningType; - protectFrom: VHProtectFrom[]; -} - -export type ScreeningType = 'All' | 'Specific'; - -export interface VHProtectFrom { - externalReferenceId: string; -} diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.spec.ts index 9ae552bfd..7994be732 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.spec.ts @@ -7,12 +7,9 @@ import { CaseResponse, ClientSettingsResponse, EditMultiDayHearingRequest, - EndpointResponse, HearingDetailsResponse, JudiciaryParticipantResponse, - LinkedParticipantResponse, MultiHearingRequest, - ParticipantResponse, UpdateHearingInGroupRequest, VideoSupplier } from './clients/api-client'; @@ -245,63 +242,6 @@ describe('Video hearing service', () => { } }); - it('should map ParticipantResponse to ParticipantModel', () => { - const participants: ParticipantResponse[] = []; - const participant = new ParticipantResponse(); - participant.title = 'Mr'; - participant.first_name = 'Dan'; - participant.middle_names = 'Ivan'; - participant.last_name = 'Smith'; - participant.username = 'dan@hmcts.net'; - participant.display_name = 'Dan Smith'; - participant.contact_email = 'dan@hmcts.net'; - participant.telephone_number = '123123123'; - participant.hearing_role_name = 'Litigant in person'; - participant.user_role_name = 'Individual'; - participant.interpreter_language = null; - participants.push(participant); - - const judgeParticipant = new ParticipantResponse(); - judgeParticipant.title = 'Mr'; - judgeParticipant.first_name = 'Judge'; - judgeParticipant.middle_names = 'MiddleNames'; - judgeParticipant.last_name = 'Test'; - judgeParticipant.username = 'judge@hmcts.net'; - judgeParticipant.display_name = 'Judge Test'; - judgeParticipant.contact_email = 'judge@hmcts.net'; - judgeParticipant.telephone_number = '123123123'; - judgeParticipant.hearing_role_name = null; - judgeParticipant.user_role_name = 'Judge'; - judgeParticipant.interpreter_language = null; - participants.push(judgeParticipant); - - const model = service.mapParticipantResponseToParticipantModel(participants); - - expect(model[0].title).toEqual(participant.title); - expect(model[0].first_name).toEqual(participant.first_name); - expect(model[0].middle_names).toEqual(participant.middle_names); - expect(model[0].last_name).toEqual(participant.last_name); - expect(model[0].username).toEqual(participant.username); - expect(model[0].display_name).toEqual(participant.display_name); - expect(model[0].email).toEqual(participant.contact_email); - expect(model[0].phone).toEqual(participant.telephone_number); - expect(model[0].hearing_role_name).toEqual(participant.hearing_role_name); - expect(model[0].is_judge).toBeFalse(); - expect(model[0].interpretation_language).toBeNull(); - - expect(model[1].title).toEqual(judgeParticipant.title); - expect(model[1].first_name).toEqual(judgeParticipant.first_name); - expect(model[1].middle_names).toEqual(judgeParticipant.middle_names); - expect(model[1].last_name).toEqual(judgeParticipant.last_name); - expect(model[1].username).toEqual(judgeParticipant.username); - expect(model[1].display_name).toEqual(judgeParticipant.display_name); - expect(model[1].email).toEqual(judgeParticipant.contact_email); - expect(model[1].phone).toEqual(judgeParticipant.telephone_number); - expect(model[1].hearing_role_name).toEqual(judgeParticipant.hearing_role_name); - expect(model[1].is_judge).toBeTrue(); - expect(model[1].interpretation_language).toBeNull(); - }); - it('should map ParticipantModel toParticipantResponse', () => { const participants: ParticipantModel[] = []; const participant = new ParticipantModel(); @@ -465,18 +405,6 @@ describe('Video hearing service', () => { ); }); - it('should map EndpointResponse to EndpointModel', () => { - const endpoints: EndpointResponse[] = []; - const endpoint = new EndpointResponse(); - endpoint.display_name = 'endpoint 001'; - endpoint.interpreter_language = null; - endpoints.push(endpoint); - - const model = service.mapEndpointResponseToEndpointModel(endpoints, []); - expect(model[0].displayName).toEqual(endpoint.display_name); - expect(model[0].interpretationLanguage).toBeNull(); - }); - it('should map EndpointModel toEndpointResponse', () => { const endpoints: EndpointModel[] = []; const endpoint = new EndpointModel(null); @@ -558,17 +486,6 @@ describe('Video hearing service', () => { expect(model[1].participant_contact_email).toEqual(linkedParticipantModelList[1].participantEmail); expect(model[1].linked_participant_contact_email).toEqual(linkedParticipantModelList[1].linkedParticipantEmail); }); - it('should map LinkedParticipantResponse to LinkedParticipantModel', () => { - const linkedParticipants: LinkedParticipantResponse[] = []; - const linkedParticipant = new LinkedParticipantResponse(); - linkedParticipant.type = LinkedParticipantType.Interpreter; - linkedParticipant.linked_id = '100'; - linkedParticipants.push(linkedParticipant); - - const model = service.mapLinkedParticipantResponseToLinkedParticipantModel(linkedParticipants); - expect(model[0].linkType).toEqual(linkedParticipant.type); - expect(model[0].linkedParticipantId).toEqual(linkedParticipant.linked_id); - }); it('should rebook hearing', async () => { clientApiSpy.rebookHearing.and.returnValue(of(null)); diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.ts index 84b559804..b452f52bf 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/video-hearings.service.ts @@ -7,14 +7,12 @@ import { BookingStatus, CancelMultiDayHearingRequest, CaseRequest, - CaseResponse, EditCaseRequest, EditEndpointRequest, EditHearingRequest, EditMultiDayHearingRequest, EditParticipantRequest, EndpointRequest, - EndpointResponse, HearingDetailsResponse, HearingRoleResponse, HearingTypeResponse, @@ -22,16 +20,13 @@ import { JudiciaryParticipantRequest, LinkedParticipant, LinkedParticipantRequest, - LinkedParticipantResponse, MultiHearingRequest, ParticipantRequest, - ParticipantResponse, PhoneConferenceResponse, SpecialMeasureScreeningRequest, UpdateBookingStatusResponse, UpdateHearingInGroupRequest } from './clients/api-client'; -import { CaseModel } from '../common/model/case.model'; import { ParticipantModel } from '../common/model/participant.model'; import { EndpointModel } from '../common/model/endpoint.model'; import { LinkedParticipantModel } from '../common/model/linked-participant.model'; @@ -40,7 +35,7 @@ import * as moment from 'moment'; import { JudicialMemberDto } from '../booking/judicial-office-holders/models/add-judicial-member.model'; import { map, shareReplay } from 'rxjs/operators'; import { InterpreterSelectedDto } from '../booking/interpreter-form/interpreter-selected.model'; -import { mapScreeningResponseToScreeningDto, ScreeningDto } from '../booking/screening/screening.model'; +import { ScreeningDto } from '../booking/screening/screening.model'; import { ReferenceDataService } from './reference-data.service'; import { createVHBooking, VHBooking } from '../common/model/vh-booking'; import { mapHearingToVHBooking } from '../common/model/api-contract-to-client-model-mappers'; @@ -353,21 +348,6 @@ export class VideoHearingsService { return cases; } - mapCaseResponseToCaseModel(casesResponse: CaseResponse[]): CaseModel[] { - const cases: CaseModel[] = []; - let caseRequest: CaseModel; - if (casesResponse && casesResponse.length > 0) { - casesResponse.forEach(c => { - caseRequest = new CaseModel(); - caseRequest.name = c.name; - caseRequest.number = c.number; - caseRequest.isLeadCase = c.is_lead_case; - cases.push(caseRequest); - }); - } - return cases; - } - mapJudicialMemberDtoToJudiciaryParticipantRequest(judicialMemberDtos: JudicialMemberDto[]): JudiciaryParticipantRequest[] { return judicialMemberDtos.map(judicialMemberDto => { const judiciaryParticipantRequest: JudiciaryParticipantRequest = new JudiciaryParticipantRequest({ @@ -438,75 +418,6 @@ export class VideoHearingsService { }); } - mapParticipantResponseToParticipantModel(response: ParticipantResponse[]): ParticipantModel[] { - const participants: ParticipantModel[] = []; - let participant: ParticipantModel; - if (response && response.length > 0) { - response.forEach(p => { - participant = new ParticipantModel(); - participant.id = p.id; - participant.title = p.title; - participant.first_name = p.first_name; - participant.middle_names = p.middle_names; - participant.last_name = p.last_name; - participant.username = p.username; - participant.display_name = p.display_name; - participant.email = p.contact_email; - participant.phone = p.telephone_number; - participant.hearing_role_name = p.hearing_role_name; - participant.hearing_role_code = p.hearing_role_code; - participant.representee = p.representee; - participant.company = p.organisation; - participant.is_judge = p.user_role_name === Constants.UserRoles.Judge; - participant.is_staff_member = p.user_role_name === Constants.UserRoles.StaffMember; - participant.linked_participants = this.mapLinkedParticipantResponseToLinkedParticipantModel(p.linked_participants); - participant.user_role_name = p.user_role_name; - participant.interpretation_language = InterpreterSelectedDto.fromAvailableLanguageResponse(p.interpreter_language); - participant.screening = mapScreeningResponseToScreeningDto(p.screening_requirement); - if (p.external_reference_id) { - // only override the external reference id if it is not null else ParticipantModel will initialise to a UUID in the ctor - participant.externalReferenceId = p.external_reference_id; - } - participants.push(participant); - }); - } - return participants; - } - - mapLinkedParticipantResponseToLinkedParticipantModel(response: LinkedParticipantResponse[]): LinkedParticipantModel[] { - const linkedParticipants: LinkedParticipantModel[] = []; - let linkedParticipant: LinkedParticipantModel; - if (response && response.length > 0) { - response.forEach(p => { - linkedParticipant = new LinkedParticipantModel(); - linkedParticipant.linkType = p.type; - linkedParticipant.linkedParticipantId = p.linked_id; - linkedParticipants.push(linkedParticipant); - }); - } - return linkedParticipants; - } - - mapEndpointResponseToEndpointModel(response: EndpointResponse[], participants: ParticipantResponse[]): EndpointModel[] { - const endpoints: EndpointModel[] = []; - let endpoint: EndpointModel; - if (response && response.length > 0) { - response.forEach(e => { - const defenceAdvocate = participants.find(p => p.id === e.defence_advocate_id); - endpoint = new EndpointModel(e.external_reference_id); - endpoint.id = e.id; - endpoint.displayName = e.display_name; - endpoint.pin = e.pin; - endpoint.sip = e.sip; - endpoint.defenceAdvocate = defenceAdvocate?.contact_email; - endpoint.interpretationLanguage = InterpreterSelectedDto.fromAvailableLanguageResponse(e.interpreter_language); - endpoint.screening = mapScreeningResponseToScreeningDto(e.screening_requirement); - endpoints.push(endpoint); - }); - } - return endpoints; - } - mapLinkedParticipants(linkedParticipantModels: LinkedParticipantModel[] = []): LinkedParticipantRequest[] { return linkedParticipantModels.reduce((acc: LinkedParticipantRequest[], model: LinkedParticipantModel) => { const request = new LinkedParticipantRequest();