Skip to content

Commit 4e6fe28

Browse files
committed
Refactor VarianceExplanation.reasons to convert null -> [] in the input stage
1 parent 11c8b31 commit 4e6fe28

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/components/progress-report/variance-explanation/variance-explanation.dto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ArrayMaxSize, IsIn } from 'class-validator';
33
import {
44
type ID,
55
IdField,
6+
ListField,
67
type RichTextDocument,
78
RichTextField,
89
SecuredRichTextNullable,
@@ -36,7 +37,10 @@ export abstract class ProgressReportVarianceExplanationInput {
3637
})
3738
readonly report: ID;
3839

39-
@Field(() => [String], { nullable: true })
40+
@ListField(() => String, {
41+
optional: true,
42+
transform: (prev) => (value) => value === null ? [] : prev(value),
43+
})
4044
@IsIn([...ReasonOptions.instance.all], {
4145
each: true,
4246
message: 'Reason is not one of our available choices',

src/components/progress-report/variance-explanation/variance-explanation.service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ export class ProgressReportVarianceExplanationService {
3737
}
3838

3939
const changes = this.repo.getActualChanges(existing, {
40-
reasons:
41-
input.reasons === undefined
42-
? existing.reasons.value
43-
: input.reasons === null
44-
? []
45-
: input.reasons,
40+
reasons: input.reasons,
4641
comments: input.comments,
4742
});
4843
if (Object.keys(changes).length === 0) {

0 commit comments

Comments
 (0)