Skip to content

Commit

Permalink
Fix type of author credit size in validators
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyDo committed Jun 26, 2024
1 parent b5cae45 commit b6fb914
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/validators/edition-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from './common';

import type {IdentifierTypeWithIdT} from '../types/identifiers';
import {Iterable} from 'immutable';
import _ from 'lodash';
import {isIterable} from '../util';

Expand All @@ -52,8 +53,13 @@ export function validateEditionGroup(
validateAuthorCreditSectionMerge(get(formData, 'authorCredit', {}));
}
else if (!authorCreditEnable) {
const emptyAuthorCredit = isIterable(formData) ? formData.get('authorCreditEditor')?.size === 0 :
_.size(get(formData, 'authorCreditEditor', {})) === 0;
let emptyAuthorCredit:boolean;
if (isIterable(formData)) {
emptyAuthorCredit = (formData.get('authorCreditEditor') as Iterable<unknown, unknown>)?.size === 0;
}
else {
emptyAuthorCredit = _.size(get(formData, 'authorCreditEditor', {})) === 0;
}
if (!emptyAuthorCredit) {
throw new ValidationError('Disabled author credit has to be empty', 'authorCreditEditor');
}
Expand Down
10 changes: 8 additions & 2 deletions src/validators/edition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {ValidationError, get, validateDate, validatePositiveInteger, validateUUI
import {convertMapToObject, isIterable} from '../util';

import {IdentifierTypeWithIdT} from '../types/identifiers';
import {Iterable} from 'immutable';
import _ from 'lodash';


Expand Down Expand Up @@ -127,8 +128,13 @@ export function validateEdition(
validateAuthorCreditSectionMerge(get(formData, 'authorCredit', {}));
}
else if (!authorCreditEnable) {
const emptyAuthorCredit = isIterable(formData) ? formData.get('authorCreditEditor')?.size === 0 :
_.size(get(formData, 'authorCreditEditor', {})) === 0;
let emptyAuthorCredit:boolean;
if (isIterable(formData)) {
emptyAuthorCredit = (formData.get('authorCreditEditor') as Iterable<unknown, unknown>)?.size === 0;
}
else {
emptyAuthorCredit = _.size(get(formData, 'authorCreditEditor', {})) === 0;
}
if (!emptyAuthorCredit) {
throw new ValidationError('Disabled author credit has to be empty', 'authorCreditEditor');
}
Expand Down

0 comments on commit b6fb914

Please sign in to comment.