Code Duplication    Length = 38-39 lines in 2 locations

skins/cat17/src/app/lib/state_aggregation/donation/payment_and_bank_data_are_valid.js 1 location

@@ 1-39 (lines=39) @@
1
'use strict';
2
3
var _ = require( 'underscore' ),
4
	validationResult = require( './../validation_result' ),
5
	PAYMENT_TYPE_DEBIT_VALUE = 'BEZ',
6
	hasValidDirectDebitPayment = function ( state ) {
7
		return (
8
			state.donationFormContent.paymentType === PAYMENT_TYPE_DEBIT_VALUE &&
9
			state.donationInputValidation.paymentType.isValid === true &&
10
			state.validity.bankData === true
11
		);
12
	},
13
	hasOtherValidPayment = function ( state ) {
14
		return (
15
			state.donationFormContent.paymentType !== PAYMENT_TYPE_DEBIT_VALUE &&
16
			state.donationInputValidation.paymentType.isValid === true
17
		);
18
	}
19
;
20
21
module.exports = function ( state ) {
22
	var result = _.clone( validationResult ),
23
		respectiveValidators = _.pick( state.donationInputValidation, [ 'paymentType', 'iban', 'bic', 'accountNumber', 'bankCode' ] )
24
	;
25
26
	result.dataEntered = _.contains( _.pluck( respectiveValidators, 'dataEntered' ), true );
27
28
	if ( hasValidDirectDebitPayment( state ) || hasOtherValidPayment( state ) ) {
29
		result.isValid = true;
30
	}
31
	else if ( !_.contains( _.pluck( respectiveValidators, 'isValid' ), false ) ) {
32
		result.isValid = null;
33
	}
34
	else {
35
		result.isValid = false;
36
	}
37
38
	return result;
39
};
40

skins/cat17/src/app/lib/state_aggregation/membership/payment_and_bank_data_are_valid.js 1 location

@@ 1-38 (lines=38) @@
1
'use strict';
2
3
var _ = require( 'underscore' ),
4
	validationResult = require( './../validation_result' ),
5
	PAYMENT_TYPE_DEBIT_VALUE = 'BEZ',
6
	hasValidDirectDebitPayment = function ( state ) {
7
		return (
8
			state.membershipFormContent.paymentType === PAYMENT_TYPE_DEBIT_VALUE &&
9
			state.validity.bankData === true
10
		);
11
	},
12
	hasOtherValidPayment = function ( state ) {
13
		return (
14
			state.membershipFormContent.paymentType !== PAYMENT_TYPE_DEBIT_VALUE &&
15
			state.membershipFormContent.paymentType !== null
16
		);
17
	}
18
;
19
20
module.exports = function ( state ) {
21
	var result = _.clone( validationResult ),
22
		respectiveValidators = _.pick( state.membershipInputValidation, [ 'iban', 'bic', 'accountNumber', 'bankCode' ] )
23
	;
24
25
	result.dataEntered = state.membershipFormContent.paymentType !== null || _.contains( _.pluck( respectiveValidators, 'dataEntered' ), true );
26
27
	if ( hasValidDirectDebitPayment( state ) || hasOtherValidPayment( state ) ) {
28
		result.isValid = true;
29
	}
30
	else if ( !_.contains( _.pluck( respectiveValidators, 'isValid' ), false ) ) {
31
		result.isValid = null;
32
	}
33
	else {
34
		result.isValid = false;
35
	}
36
37
	return result;
38
};
39