Skip to content

Commit

Permalink
getLatestAnnotations() return null instead of undefined
Browse files Browse the repository at this point in the history
Refactor matchesScoreType()
  • Loading branch information
hirokiterashima committed Oct 16, 2023
1 parent 5191b41 commit 63332bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/app/services/annotationService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getLatestScoreAnnotation() {
function getLatestScoreAnnotation_NoMatch_ReturnNull() {
describe('no matching annotation is found', () => {
it('returns null', () => {
expect(service.getLatestScoreAnnotation('nodeX', 'componentX', 10, 'any')).toBeUndefined();
expect(service.getLatestScoreAnnotation('nodeX', 'componentX', 10, 'any')).toBeNull();
});
});
}
Expand Down
24 changes: 13 additions & 11 deletions src/assets/wise5/services/annotationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,24 +536,26 @@ export class AnnotationService {
workgroupId: number,
scoreType: 'score' | 'autoScore' | 'any' = 'any'
): Annotation {
return this.getAnnotations()
.filter(
(annotation) =>
annotation.nodeId == nodeId &&
annotation.componentId == componentId &&
annotation.toWorkgroupId == workgroupId &&
this.matchesScoreType(annotation, scoreType)
)
.at(-1);
return (
this.getAnnotations()
.filter(
(annotation) =>
annotation.nodeId == nodeId &&
annotation.componentId == componentId &&
annotation.toWorkgroupId == workgroupId &&
this.matchesScoreType(annotation, scoreType)
)
.at(-1) || null
);
}

private matchesScoreType(
annotation: Annotation,
scoreType: 'score' | 'autoScore' | 'any'
): boolean {
return (
['autoScore', 'score'].includes(annotation.type) &&
(scoreType === 'any' || annotation.type === scoreType)
(scoreType === 'any' && ['autoScore', 'score'].includes(annotation.type)) ||
annotation.type === scoreType
);
}

Expand Down

0 comments on commit 63332bd

Please sign in to comment.