Validate CLIN PoP against configurable contract start and end dates
This commit is contained in:
parent
5419e1c475
commit
e4ca027065
@ -2,6 +2,8 @@
|
|||||||
CAC_URL = http://localhost:8000/login-redirect
|
CAC_URL = http://localhost:8000/login-redirect
|
||||||
CA_CHAIN = ssl/server-certs/ca-chain.pem
|
CA_CHAIN = ssl/server-certs/ca-chain.pem
|
||||||
CLASSIFIED = false
|
CLASSIFIED = false
|
||||||
|
CONTRACT_START_DATE = 2019-09-14
|
||||||
|
CONTRACT_END_DATE = 2022-09-14
|
||||||
COOKIE_SECRET = some-secret-please-replace
|
COOKIE_SECRET = some-secret-please-replace
|
||||||
DISABLE_CRL_CHECK = false
|
DISABLE_CRL_CHECK = false
|
||||||
CRL_FAIL_OPEN = false
|
CRL_FAIL_OPEN = false
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import * as R from 'ramda'
|
||||||
|
|
||||||
import DateSelector from './date_selector'
|
import DateSelector from './date_selector'
|
||||||
import { emitEvent } from '../lib/emitters'
|
import { emitEvent } from '../lib/emitters'
|
||||||
import Modal from '../mixins/modal'
|
import Modal from '../mixins/modal'
|
||||||
@ -9,6 +11,12 @@ const END_DATE = 'end_date'
|
|||||||
const POP = 'period_of_performance'
|
const POP = 'period_of_performance'
|
||||||
const NUMBER = 'number'
|
const NUMBER = 'number'
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const ini = require('ini')
|
||||||
|
const config = ini.parse(fs.readFileSync('./config/base.ini', 'utf-8'))
|
||||||
|
const CONTRACT_START_DATE = new Date(config.default.CONTRACT_START_DATE)
|
||||||
|
const CONTRACT_END_DATE = new Date(config.default.CONTRACT_END_DATE)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'clin-fields',
|
name: 'clin-fields',
|
||||||
|
|
||||||
@ -44,7 +52,6 @@ export default {
|
|||||||
? new Date(this.initialEndDate)
|
? new Date(this.initialEndDate)
|
||||||
: undefined
|
: undefined
|
||||||
const popValidation = !this.initialStartDate ? false : start < end
|
const popValidation = !this.initialStartDate ? false : start < end
|
||||||
const showPopValidation = !this.initialStartDate ? false : !popValidation
|
|
||||||
const clinNumber = !!this.initialClinNumber
|
const clinNumber = !!this.initialClinNumber
|
||||||
? this.initialClinNumber
|
? this.initialClinNumber
|
||||||
: undefined
|
: undefined
|
||||||
@ -54,9 +61,22 @@ export default {
|
|||||||
startDate: start,
|
startDate: start,
|
||||||
endDate: end,
|
endDate: end,
|
||||||
popValid: popValidation,
|
popValid: popValidation,
|
||||||
showPopError: showPopValidation,
|
|
||||||
clinNumber: clinNumber,
|
clinNumber: clinNumber,
|
||||||
showClin: true,
|
popErrors: [],
|
||||||
|
validations: [
|
||||||
|
{
|
||||||
|
func: this.popDateOrder,
|
||||||
|
message: 'PoP start date must be before end date.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
func: this.popStartsAfterContract,
|
||||||
|
message: `PoP start date must be on or after ${CONTRACT_START_DATE}.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
func: this.popEndsBeforeContract,
|
||||||
|
message: `PoP end date must be before or on ${CONTRACT_END_DATE}.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -74,20 +94,41 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
checkPopValid: function() {
|
checkPopValid: function() {
|
||||||
return this.startDate < this.endDate
|
return (
|
||||||
|
this.popDateOrder() &&
|
||||||
|
this.popStartsAfterContract() &&
|
||||||
|
this.popEndsBeforeContract()
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
validatePop: function() {
|
validatePop: function() {
|
||||||
if (!!this.startDate && !!this.endDate) {
|
this.popValid = this.checkPopValid()
|
||||||
// only want to update popValid and showPopError if both dates are filled in
|
|
||||||
this.popValid = this.checkPopValid()
|
|
||||||
this.showPopError = !this.popValid
|
|
||||||
}
|
|
||||||
|
|
||||||
emitEvent('field-change', this, {
|
emitEvent('field-change', this, {
|
||||||
name: 'clins-' + this.clinIndex + '-' + POP,
|
name: 'clins-' + this.clinIndex + '-' + POP,
|
||||||
valid: this.checkPopValid(),
|
valid: this.popValid,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.popErrors = R.pipe(
|
||||||
|
R.map(validation =>
|
||||||
|
!validation.func() ? validation.message : undefined
|
||||||
|
),
|
||||||
|
R.filter(Boolean)
|
||||||
|
)(this.validations)
|
||||||
|
},
|
||||||
|
|
||||||
|
popStartsAfterContract: function() {
|
||||||
|
return this.startDate >= CONTRACT_START_DATE
|
||||||
|
},
|
||||||
|
|
||||||
|
popEndsBeforeContract: function() {
|
||||||
|
return this.endDate <= CONTRACT_END_DATE
|
||||||
|
},
|
||||||
|
|
||||||
|
popDateOrder: function() {
|
||||||
|
if (!!this.startDate && !!this.endDate) {
|
||||||
|
return this.startDate < this.endDate
|
||||||
|
}
|
||||||
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
handleFieldChange: function(event) {
|
handleFieldChange: function(event) {
|
||||||
|
@ -314,15 +314,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<p class="usa-input-error-message form-has-errors">
|
<div class="usa-input-error-message form-has-errors" v-for="error in popErrors" :key="error">
|
||||||
<template v-if='showPopError'>
|
<div v-html='error'></div>
|
||||||
{% if fields and fields.start_date.errors %}
|
</div>
|
||||||
{{ fields.start_date.errors[0] }}
|
|
||||||
{% else %}
|
|
||||||
{{ "forms.task_order.start_date_error" | translate }}
|
|
||||||
{% endif %}
|
|
||||||
</template>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user