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
|
||||
CA_CHAIN = ssl/server-certs/ca-chain.pem
|
||||
CLASSIFIED = false
|
||||
CONTRACT_START_DATE = 2019-09-14
|
||||
CONTRACT_END_DATE = 2022-09-14
|
||||
COOKIE_SECRET = some-secret-please-replace
|
||||
DISABLE_CRL_CHECK = false
|
||||
CRL_FAIL_OPEN = false
|
||||
|
@ -1,3 +1,5 @@
|
||||
import * as R from 'ramda'
|
||||
|
||||
import DateSelector from './date_selector'
|
||||
import { emitEvent } from '../lib/emitters'
|
||||
import Modal from '../mixins/modal'
|
||||
@ -9,6 +11,12 @@ const END_DATE = 'end_date'
|
||||
const POP = 'period_of_performance'
|
||||
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 {
|
||||
name: 'clin-fields',
|
||||
|
||||
@ -44,7 +52,6 @@ export default {
|
||||
? new Date(this.initialEndDate)
|
||||
: undefined
|
||||
const popValidation = !this.initialStartDate ? false : start < end
|
||||
const showPopValidation = !this.initialStartDate ? false : !popValidation
|
||||
const clinNumber = !!this.initialClinNumber
|
||||
? this.initialClinNumber
|
||||
: undefined
|
||||
@ -54,9 +61,22 @@ export default {
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
popValid: popValidation,
|
||||
showPopError: showPopValidation,
|
||||
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: {
|
||||
checkPopValid: function() {
|
||||
return this.startDate < this.endDate
|
||||
return (
|
||||
this.popDateOrder() &&
|
||||
this.popStartsAfterContract() &&
|
||||
this.popEndsBeforeContract()
|
||||
)
|
||||
},
|
||||
|
||||
validatePop: function() {
|
||||
if (!!this.startDate && !!this.endDate) {
|
||||
// only want to update popValid and showPopError if both dates are filled in
|
||||
this.popValid = this.checkPopValid()
|
||||
this.showPopError = !this.popValid
|
||||
}
|
||||
|
||||
this.popValid = this.checkPopValid()
|
||||
emitEvent('field-change', this, {
|
||||
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) {
|
||||
|
@ -314,15 +314,9 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-row">
|
||||
<p class="usa-input-error-message form-has-errors">
|
||||
<template v-if='showPopError'>
|
||||
{% if fields and fields.start_date.errors %}
|
||||
{{ fields.start_date.errors[0] }}
|
||||
{% else %}
|
||||
{{ "forms.task_order.start_date_error" | translate }}
|
||||
{% endif %}
|
||||
</template>
|
||||
</p>
|
||||
<div class="usa-input-error-message form-has-errors" v-for="error in popErrors" :key="error">
|
||||
<div v-html='error'></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user