Skip to content

Commit

Permalink
Merge pull request #318 from metabrainz/fix-validator-typescript
Browse files Browse the repository at this point in the history
Fix type of author credit size in validators
  • Loading branch information
MonkeyDo authored Jun 27, 2024
2 parents 350fbe8 + b6fb914 commit 38bdde0
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 38bdde0

Please sign in to comment.