generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADJUST1-28 Able to update an adjustment and the form for any adjustme… (
#15) * ADJUST1-28 Able to update an adjustment and the form for any adjustment type. * ADJUST1-28 improving generic views. * ADJUST1-28 fixing int test. * ADJUST1-28 linting.
- Loading branch information
Showing
31 changed files
with
640 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { components } from './index' | ||
|
||
export type AdjustmentDetails = components['schemas']['AdjustmentDetailsDto'] | ||
export type AdjustmentTypes = components['schemas']['AdjustmentDto']['adjustmentType'] | ||
export type Adjustment = components['schemas']['AdjustmentDto'] | ||
export type CreateResponse = components['schemas']['CreateResponseDto'] | ||
export type ValidationMessage = components['schemas']['ValidationMessage'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import dayjs from 'dayjs' | ||
import { Request } from 'express' | ||
import { Adjustment, AdjustmentTypes } from '../@types/adjustments/adjustmentsTypes' | ||
import { AdjustmentType } from './adjustmentTypes' | ||
import AdjustmentsForm from './adjustmentsForm' | ||
import RestoredAdditionalDaysForm from './restoredAdditionalDaysForm' | ||
import GenericAdjustmentForm, { GenericAdjustmentFormOptions } from './genericAdjustmentForm' | ||
|
||
export default class AdjustmentsFormFactory { | ||
static fromAdjustment<T extends AdjustmentsForm<unknown>>(adjustment: Adjustment): AdjustmentsForm<T> { | ||
if (adjustment.adjustmentType === 'RESTORATION_OF_ADDITIONAL_DAYS_AWARDED') { | ||
return new RestoredAdditionalDaysForm({ | ||
'from-day': dayjs(adjustment.fromDate).get('date').toString(), | ||
'from-month': (dayjs(adjustment.fromDate).get('month') + 1).toString(), | ||
'from-year': dayjs(adjustment.fromDate).get('year').toString(), | ||
days: adjustment.days.toString(), | ||
}) | ||
} | ||
return new GenericAdjustmentForm({ | ||
options: this.options(adjustment.adjustmentType), | ||
'from-day': dayjs(adjustment.fromDate).get('date').toString(), | ||
'from-month': (dayjs(adjustment.fromDate).get('month') + 1).toString(), | ||
'from-year': dayjs(adjustment.fromDate).get('year').toString(), | ||
'to-day': dayjs(adjustment.toDate).get('date').toString(), | ||
'to-month': (dayjs(adjustment.toDate).get('month') + 1).toString(), | ||
'to-year': dayjs(adjustment.toDate).get('year').toString(), | ||
days: adjustment.days.toString(), | ||
sentence: adjustment.sentenceSequence.toString(), | ||
}) | ||
} | ||
|
||
static fromType<T extends AdjustmentsForm<unknown>>(adjustmentType: AdjustmentType): AdjustmentsForm<T> { | ||
if (adjustmentType.value === 'RESTORATION_OF_ADDITIONAL_DAYS_AWARDED') { | ||
return new RestoredAdditionalDaysForm({}) | ||
} | ||
return new GenericAdjustmentForm({ | ||
options: this.options(adjustmentType.value), | ||
}) | ||
} | ||
|
||
static fromRequest<T extends AdjustmentsForm<unknown>>( | ||
req: Request, | ||
adjustmentType: AdjustmentType, | ||
): AdjustmentsForm<T> { | ||
if (adjustmentType.value === 'RESTORATION_OF_ADDITIONAL_DAYS_AWARDED') { | ||
return new RestoredAdditionalDaysForm(req.body) | ||
} | ||
return new GenericAdjustmentForm({ ...req.body, options: this.options(adjustmentType.value) }) | ||
} | ||
|
||
private static options(adjustmentType: AdjustmentTypes): GenericAdjustmentFormOptions { | ||
return { | ||
hasSentence: ['REMAND', 'TAGGED_BAIL'].indexOf(adjustmentType) !== -1, | ||
hasToDate: adjustmentType === 'REMAND', | ||
adjustmentType, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Adjustment } from '../@types/adjustments/adjustmentsTypes' | ||
import AbstractForm from './abstractForm' | ||
import { AdjustmentType } from './adjustmentTypes' | ||
|
||
export default abstract class AdjustmentsForm<T> extends AbstractForm<T> { | ||
abstract toAdjustment(bookingId: number, nomsId: string, idw: string): Adjustment | ||
|
||
abstract adjustmentType(): AdjustmentType | ||
|
||
abstract fragment(): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.