Skip to content

Commit b6fb914

Browse files
committed
Fix type of author credit size in validators
1 parent b5cae45 commit b6fb914

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/validators/edition-group.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from './common';
3030

3131
import type {IdentifierTypeWithIdT} from '../types/identifiers';
32+
import {Iterable} from 'immutable';
3233
import _ from 'lodash';
3334
import {isIterable} from '../util';
3435

@@ -52,8 +53,13 @@ export function validateEditionGroup(
5253
validateAuthorCreditSectionMerge(get(formData, 'authorCredit', {}));
5354
}
5455
else if (!authorCreditEnable) {
55-
const emptyAuthorCredit = isIterable(formData) ? formData.get('authorCreditEditor')?.size === 0 :
56-
_.size(get(formData, 'authorCreditEditor', {})) === 0;
56+
let emptyAuthorCredit:boolean;
57+
if (isIterable(formData)) {
58+
emptyAuthorCredit = (formData.get('authorCreditEditor') as Iterable<unknown, unknown>)?.size === 0;
59+
}
60+
else {
61+
emptyAuthorCredit = _.size(get(formData, 'authorCreditEditor', {})) === 0;
62+
}
5763
if (!emptyAuthorCredit) {
5864
throw new ValidationError('Disabled author credit has to be empty', 'authorCreditEditor');
5965
}

src/validators/edition.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {ValidationError, get, validateDate, validatePositiveInteger, validateUUI
3333
import {convertMapToObject, isIterable} from '../util';
3434

3535
import {IdentifierTypeWithIdT} from '../types/identifiers';
36+
import {Iterable} from 'immutable';
3637
import _ from 'lodash';
3738

3839

@@ -127,8 +128,13 @@ export function validateEdition(
127128
validateAuthorCreditSectionMerge(get(formData, 'authorCredit', {}));
128129
}
129130
else if (!authorCreditEnable) {
130-
const emptyAuthorCredit = isIterable(formData) ? formData.get('authorCreditEditor')?.size === 0 :
131-
_.size(get(formData, 'authorCreditEditor', {})) === 0;
131+
let emptyAuthorCredit:boolean;
132+
if (isIterable(formData)) {
133+
emptyAuthorCredit = (formData.get('authorCreditEditor') as Iterable<unknown, unknown>)?.size === 0;
134+
}
135+
else {
136+
emptyAuthorCredit = _.size(get(formData, 'authorCreditEditor', {})) === 0;
137+
}
132138
if (!emptyAuthorCredit) {
133139
throw new ValidationError('Disabled author credit has to be empty', 'authorCreditEditor');
134140
}

0 commit comments

Comments
 (0)