Skip to content

Commit

Permalink
Merge pull request #2232 from ministryofjustice/update-api-types
Browse files Browse the repository at this point in the history
API model updates
  • Loading branch information
froddd authored Dec 3, 2024
2 parents 1a46ebe + 8e5bf67 commit 2eb6443
Show file tree
Hide file tree
Showing 27 changed files with 101 additions and 85 deletions.
11 changes: 7 additions & 4 deletions integration_tests/tests/manage/cancellation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Cancellation } from '@approved-premises/api'
import {
applicationFactory,
bookingFactory,
Expand Down Expand Up @@ -97,9 +98,11 @@ context('Cancellation', () => {
page.completeForm(cancellation)

// Then a cancellation should have been created in the API
cy.task('verifyApiPost', `/premises/${premises.id}/bookings/${booking.id}/cancellations`).then(({ reason }) => {
expect(reason).equal(cancellation.reason)
})
cy.task('verifyApiPost', `/premises/${premises.id}/bookings/${booking.id}/cancellations`).then(
({ reason }: Cancellation) => {
expect(reason).equal(cancellation.reason)
},
)

// And I should see a confirmation message
const confirmationPage = new BookingCancellationConfirmPage()
Expand Down Expand Up @@ -138,7 +141,7 @@ context('Cancellation', () => {
// Given a booking is available
const application = applicationFactory.build()
const placement = cas1SpaceBookingFactory.upcoming().build({ applicationId: application.id })
const premises = extendedPremisesSummaryFactory.build({ bookings: [placement], id: placement.premises.id })
const premises = premisesFactory.build({ id: placement.premises.id })

const placementId = placement.id
const premisesId = premises.id
Expand Down
8 changes: 4 additions & 4 deletions server/@types/shared/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export type { Cas1CruManagementArea } from './models/Cas1CruManagementArea';
export type { Cas1KeyWorkerAllocation } from './models/Cas1KeyWorkerAllocation';
export type { Cas1NewArrival } from './models/Cas1NewArrival';
export type { Cas1NewDeparture } from './models/Cas1NewDeparture';
export type { Cas1NewOutOfServiceBed } from './models/Cas1NewOutOfServiceBed';
export type { Cas1NewOutOfServiceBedCancellation } from './models/Cas1NewOutOfServiceBedCancellation';
export type { Cas1NewSpaceBooking } from './models/Cas1NewSpaceBooking';
export type { Cas1NewSpaceBookingCancellation } from './models/Cas1NewSpaceBookingCancellation';
export type { Cas1NonArrival } from './models/Cas1NonArrival';
export type { Cas1OutOfServiceBed } from './models/Cas1OutOfServiceBed';
export type { Cas1OutOfServiceBedCancellation } from './models/Cas1OutOfServiceBedCancellation';
Expand Down Expand Up @@ -179,10 +183,6 @@ export type { NewBedMove } from './models/NewBedMove';
export type { NewBooking } from './models/NewBooking';
export type { NewBookingNotMade } from './models/NewBookingNotMade';
export type { NewCancellation } from './models/NewCancellation';
export type { NewCas1OutOfServiceBed } from './models/NewCas1OutOfServiceBed';
export type { NewCas1OutOfServiceBedCancellation } from './models/NewCas1OutOfServiceBedCancellation';
export type { NewCas1SpaceBooking } from './models/NewCas1SpaceBooking';
export type { NewCas1SpaceBookingCancellation } from './models/NewCas1SpaceBookingCancellation';
export type { NewCas2ApplicationNote } from './models/NewCas2ApplicationNote';
export type { NewCas2Arrival } from './models/NewCas2Arrival';
export type { NewCas3Arrival } from './models/NewCas3Arrival';
Expand Down
1 change: 1 addition & 0 deletions server/@types/shared/models/ApprovedPremisesApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export type ApprovedPremisesApplication = (Application & {
caseManagerIsNotApplicant?: boolean;
caseManagerUserDetails?: Cas1ApplicationUserDetails;
genderForAp?: GenderForAp;
licenceExpiryDate?: string;
});

2 changes: 1 addition & 1 deletion server/@types/shared/models/ApprovedPremisesUserRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApprovedPremisesUserRole = 'assessor' | 'matcher' | 'manager' | 'legacy_manager' | 'future_manager' | 'workflow_manager' | 'cru_member' | 'cru_member_find_and_book_beta' | 'applicant' | 'role_admin' | 'report_viewer' | 'excluded_from_assess_allocation' | 'excluded_from_match_allocation' | 'excluded_from_placement_application_allocation' | 'appeals_manager' | 'janitor' | 'user_manager';
export type ApprovedPremisesUserRole = 'assessor' | 'matcher' | 'legacy_manager' | 'future_manager' | 'workflow_manager' | 'cru_member' | 'cru_member_find_and_book_beta' | 'applicant' | 'role_admin' | 'report_viewer' | 'excluded_from_assess_allocation' | 'excluded_from_match_allocation' | 'excluded_from_placement_application_allocation' | 'appeals_manager' | 'janitor' | 'user_manager';
2 changes: 1 addition & 1 deletion server/@types/shared/models/Cas1KeyWorkerAllocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import type { StaffMember } from './StaffMember';
export type Cas1KeyWorkerAllocation = {
keyWorker: StaffMember;
allocatedAt: string;
allocatedAt?: string;
};

8 changes: 7 additions & 1 deletion server/@types/shared/models/Cas1NewArrival.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
/* tslint:disable */
/* eslint-disable */
export type Cas1NewArrival = {
arrivalDateTime: string;
/**
* This is deprecated. Instead use arrivalDate and arrivalTime
* @deprecated
*/
arrivalDateTime?: string;
arrivalDate?: string;
arrivalTime?: string;
};

4 changes: 3 additions & 1 deletion server/@types/shared/models/Cas1NewDeparture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
/* tslint:disable */
/* eslint-disable */
export type Cas1NewDeparture = {
departureDateTime: string;
departureDateTime?: string;
departureDate?: string;
departureTime?: string;
reasonId: string;
moveOnCategoryId?: string;
notes?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type NewCas1OutOfServiceBed = {
export type Cas1NewOutOfServiceBed = {
startDate: string;
endDate: string;
reason: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type NewCas1OutOfServiceBedCancellation = {
export type Cas1NewOutOfServiceBedCancellation = {
notes?: string;
};

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* tslint:disable */
/* eslint-disable */
import type { Cas1SpaceBookingRequirements } from './Cas1SpaceBookingRequirements';
export type NewCas1SpaceBooking = {
export type Cas1NewSpaceBooking = {
arrivalDate: string;
departureDate: string;
premisesId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type NewCas1SpaceBookingCancellation = {
export type Cas1NewSpaceBookingCancellation = {
occurredAt: string;
reasonId: string;
reasonNotes?: string;
Expand Down
1 change: 1 addition & 0 deletions server/@types/shared/models/Cas1PremisesSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export type Cas1PremisesSummary = {
*/
outOfServiceBeds: number;
supportsSpaceBookings: boolean;
managerDetails?: string;
};

20 changes: 20 additions & 0 deletions server/@types/shared/models/Cas1SpaceBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Cas1SpaceBookingDates } from './Cas1SpaceBookingDates';
import type { Cas1SpaceBookingDeparture } from './Cas1SpaceBookingDeparture';
import type { Cas1SpaceBookingNonArrival } from './Cas1SpaceBookingNonArrival';
import type { Cas1SpaceBookingRequirements } from './Cas1SpaceBookingRequirements';
import type { Cas1SpaceBookingSummaryStatus } from './Cas1SpaceBookingSummaryStatus';
import type { NamedId } from './NamedId';
import type { Person } from './Person';
import type { User } from './User';
Expand All @@ -24,8 +25,26 @@ export type Cas1SpaceBooking = {
requestForPlacementId?: string;
expectedArrivalDate: string;
expectedDepartureDate: string;
/**
* Use actualArrivalDateOnly and actualArrivalTime
* @deprecated
*/
actualArrivalDate?: string;
actualArrivalDateOnly?: string;
/**
* This value may not be defined even if an arrival date is
*/
actualArrivalTime?: string;
/**
* Use actualDepartureDateOnly and actualDepartureTime
* @deprecated
*/
actualDepartureDate?: string;
actualDepartureDateOnly?: string;
/**
* This value may not be defined even if a departure date is
*/
actualDepartureTime?: string;
/**
* actual arrival date or, if not known, the expected arrival date
*/
Expand All @@ -41,5 +60,6 @@ export type Cas1SpaceBooking = {
cancellation?: Cas1SpaceBookingCancellation;
nonArrival?: Cas1SpaceBookingNonArrival;
deliusEventNumber?: string;
status?: Cas1SpaceBookingSummaryStatus;
};

2 changes: 1 addition & 1 deletion server/@types/shared/models/MigrationJobType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type MigrationJobType = 'update_all_users_from_community_api' | 'update_sentence_type_and_situation' | 'update_booking_status' | 'update_task_due_dates' | 'update_users_pdu_by_api' | 'update_cas2_applications_with_assessments' | 'update_cas2_status_updates_with_assessments' | 'update_cas2_notes_with_assessments' | 'update_cas1_fix_placement_app_links' | 'update_cas1_notice_types' | 'update_cas1_backfill_user_ap_area' | 'update_cas3_application_offender_name' | 'update_cas3_domain_event_type_for_person_departed_updated';
export type MigrationJobType = 'update_all_users_from_community_api' | 'update_sentence_type_and_situation' | 'update_booking_status' | 'update_task_due_dates' | 'update_users_pdu_by_api' | 'update_cas2_applications_with_assessments' | 'update_cas2_status_updates_with_assessments' | 'update_cas2_notes_with_assessments' | 'update_cas1_fix_placement_app_links' | 'update_cas1_notice_types' | 'update_cas1_backfill_user_ap_area' | 'update_cas3_application_offender_name' | 'update_cas3_domain_event_type_for_person_departed_updated' | 'update_cas1_applications_licence_expiry_date';
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export type SubmitApprovedPremisesApplication = (SubmitApplication & {
noticeType?: Cas1ApplicationTimelinessCategory;
reasonForShortNotice?: string;
reasonForShortNoticeOther?: string;
licenseExpiryDate?: string;
});

6 changes: 3 additions & 3 deletions server/controllers/manage/cancellationsController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Request, RequestHandler, Response } from 'express'

import type { NewCancellation, NewCas1SpaceBookingCancellation } from '@approved-premises/api'
import type { Cas1NewSpaceBookingCancellation, NewCancellation } from '@approved-premises/api'

import { BookingService, CancellationService, PlacementService } from '../../services'
import { catchValidationErrorOrPropogate, fetchErrorsAndUserInput } from '../../utils/validation'
Expand Down Expand Up @@ -76,11 +76,11 @@ export default class CancellationsController {
date,
} as NewCancellation

const spaceBookingCancellation = {
const spaceBookingCancellation: Cas1NewSpaceBookingCancellation = {
occurredAt: date,
reasonId: cancellation.reason,
reasonNotes: cancellation.otherReason,
} as NewCas1SpaceBookingCancellation
}

try {
if (bookingId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Request, RequestHandler, Response, TypedRequestHandler } from 'express'
import { ApType, NewCas1SpaceBooking as NewSpaceBooking } from '@approved-premises/api'
import type { ApType, Cas1NewSpaceBooking as NewSpaceBooking } from '@approved-premises/api'
import { PlacementRequestService, SpaceService } from '../../../services'
import { filterOutAPTypes, placementDates } from '../../../utils/match'
import { catchValidationErrorOrPropogate, fetchErrorsAndUserInput } from '../../../utils/validation'
Expand Down
4 changes: 2 additions & 2 deletions server/data/outOfServiceBedClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
NewCas1OutOfServiceBedCancellation as NewOutOfServiceBedCancellation,
import type {
Cas1NewOutOfServiceBedCancellation as NewOutOfServiceBedCancellation,
UpdateCas1OutOfServiceBed as UpdateOutOfServiceBed,
} from '@approved-premises/api'
import OutOfServiceBedClient from './outOfServiceBedClient'
Expand Down
6 changes: 3 additions & 3 deletions server/data/outOfServiceBedClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* istanbul ignore file */

import {
NewCas1OutOfServiceBed as NewOutOfServiceBed,
NewCas1OutOfServiceBedCancellation as NewOutOfServiceBedCancellation,
import type {
Cas1NewOutOfServiceBed as NewOutOfServiceBed,
Cas1NewOutOfServiceBedCancellation as NewOutOfServiceBedCancellation,
Cas1OutOfServiceBed as OutOfServiceBed,
Cas1OutOfServiceBedCancellation as OutOfServiceBedCancellation,
Cas1OutOfServiceBedSortField as OutOfServiceBedSortField,
Expand Down
4 changes: 2 additions & 2 deletions server/data/placementClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {
Cas1AssignKeyWorker,
Cas1NewArrival,
Cas1NewDeparture,
Cas1NewSpaceBookingCancellation,
Cas1NonArrival,
Cas1SpaceBooking,
NewCas1SpaceBookingCancellation,
} from '@approved-premises/api'
import RestClient from './restClient'
import config, { ApiConfig } from '../config'
Expand Down Expand Up @@ -55,7 +55,7 @@ export default class PlacementClient {
})
}

async cancel(premisesId: string, placementId: string, cancellation: NewCas1SpaceBookingCancellation) {
async cancel(premisesId: string, placementId: string, cancellation: Cas1NewSpaceBookingCancellation) {
return this.restClient.post({
path: paths.premises.placements.cancel({ premisesId, placementId }),
data: cancellation,
Expand Down
12 changes: 6 additions & 6 deletions server/data/spaceClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import config, { ApiConfig } from '../config'
import RestClient from './restClient'
import paths from '../paths/api'
import {
NewCas1SpaceBooking as NewSpaceBooking,
import type {
Cas1NewSpaceBooking as NewSpaceBooking,
PlacementRequest,
Cas1SpaceBooking as SpaceBooking,
Cas1SpaceSearchParameters as SpaceSearchParameters,
Cas1SpaceSearchResults as SpaceSearchResults,
} from '../@types/shared'
} from '@approved-premises/api'
import config, { ApiConfig } from '../config'
import RestClient from './restClient'
import paths from '../paths/api'

export default class SpaceClient {
restClient: RestClient
Expand Down
37 changes: 12 additions & 25 deletions server/services/outOfServiceBedService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { Cas1ReferenceData } from '@approved-premises/ui'
import type { Cas1ReferenceData, PaginatedResponse } from '@approved-premises/ui'
import type {
NewCas1OutOfServiceBed as NewOutOfServiceBed,
NewCas1OutOfServiceBedCancellation as NewOutOfServiceBedCancellation,
Cas1NewOutOfServiceBed as NewOutOfServiceBed,
Cas1NewOutOfServiceBedCancellation as NewOutOfServiceBedCancellation,
Cas1OutOfServiceBed as OutOfServiceBed,
Cas1OutOfServiceBedCancellation as OutOfServiceBedCancellation,
Cas1OutOfServiceBedSortField as OutOfServiceBedSortField,
Premises,
SortDirection,
Temporality,
UpdateCas1OutOfServiceBed as UpdateOutOfServiceBed,
} from '@approved-premises/api'
import { PaginatedResponse } from '@approved-premises/ui'
import type { Cas1ReferenceDataClient, OutOfServiceBedClient, RestClientBuilder } from '../data'
import { Premises } from '../@types/shared'

export type OutOfServiceBedReasons = Array<Cas1ReferenceData>

Expand All @@ -28,9 +27,7 @@ export default class OutOfServiceBedService {
): Promise<OutOfServiceBed> {
const outOfServiceBedClient = this.outOfServiceBedClientFactory(token)

const confirmedOutOfServiceBed = await outOfServiceBedClient.create(premisesId, outOfServiceBed)

return confirmedOutOfServiceBed
return outOfServiceBedClient.create(premisesId, outOfServiceBed)
}

async getOutOfServiceBed(
Expand All @@ -40,9 +37,7 @@ export default class OutOfServiceBedService {
): Promise<OutOfServiceBed> {
const outOfServiceBedClient = this.outOfServiceBedClientFactory(token)

const outOfServiceBed = await outOfServiceBedClient.find(premisesId, id)

return outOfServiceBed
return outOfServiceBedClient.find(premisesId, id)
}

async updateOutOfServiceBed(
Expand All @@ -53,24 +48,19 @@ export default class OutOfServiceBedService {
): Promise<OutOfServiceBed> {
const outOfServiceBedClient = this.outOfServiceBedClientFactory(token)

const updatedOutOfServiceBed = await outOfServiceBedClient.update(id, updateOutOfServiceBed, premisesId)

return updatedOutOfServiceBed
return outOfServiceBedClient.update(id, updateOutOfServiceBed, premisesId)
}

async getOutOfServiceBedReasons(token: string): Promise<OutOfServiceBedReasons> {
const cas1ReferenceDataClient = this.cas1ReferenceDataClientFactory(token)

const reasons = await cas1ReferenceDataClient.getReferenceData('out-of-service-bed-reasons')

return reasons
return cas1ReferenceDataClient.getReferenceData('out-of-service-bed-reasons')
}

async getOutOfServiceBedsForAPremises(token: string, premisesId: Premises['id']): Promise<Array<OutOfServiceBed>> {
const outOfServiceBedClient = this.outOfServiceBedClientFactory(token)
const outOfServiceBeds = await outOfServiceBedClient.getAllByPremises(premisesId)

return outOfServiceBeds
return outOfServiceBedClient.getAllByPremises(premisesId)
}

async getAllOutOfServiceBeds({
Expand All @@ -93,7 +83,8 @@ export default class OutOfServiceBedService {
perPage?: number
}): Promise<PaginatedResponse<OutOfServiceBed>> {
const outOfServiceBedClient = this.outOfServiceBedClientFactory(token)
const outOfServiceBeds = await outOfServiceBedClient.get({

return outOfServiceBedClient.get({
sortBy,
sortDirection,
page,
Expand All @@ -102,8 +93,6 @@ export default class OutOfServiceBedService {
apAreaId,
perPage,
})

return outOfServiceBeds
}

async cancelOutOfServiceBed(
Expand All @@ -114,8 +103,6 @@ export default class OutOfServiceBedService {
): Promise<OutOfServiceBedCancellation> {
const outOfServiceBedService = this.outOfServiceBedClientFactory(token)

const cancellation = await outOfServiceBedService.cancel(premisesId, outOfServiceBedId, data)

return cancellation
return outOfServiceBedService.cancel(premisesId, outOfServiceBedId, data)
}
}
Loading

0 comments on commit 2eb6443

Please sign in to comment.