Skip to content

Commit

Permalink
Merge branch 'master' into PAF-129-Bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TemitopeAyokuHO authored Jan 30, 2024
2 parents 4d1f113 + abfac19 commit d9ba5c6
Show file tree
Hide file tree
Showing 39 changed files with 830 additions and 107 deletions.
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ steps:
branch: master
event: push


# Tear down pull request UAT environment.
- name: tear_down_branch
pull: if-not-exists
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ https://github.com/UKHomeOffice/ims-integration-documentation

### Prerequisities

- [Node.js](https://nodejs.org/en/) - Tested against LTS
- [Node.js](https://nodejs.org/en/) - Tested against LTS
- NPM (installed with Node.js) - Works with versions 2 and 3
- [Redis server](http://redis.io/download) running on the default port

Expand Down
38 changes: 37 additions & 1 deletion apps/paf/behaviours/save-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

const _ = require('lodash');
const config = require('../../../config');
const Model = require('../models/file-upload');
const fileSizeNum = size => size.match(/\d+/g)[0];

module.exports = name => superclass => class extends superclass {
process(req) {
Expand All @@ -20,7 +22,41 @@ module.exports = name => superclass => class extends superclass {
if (!Object.keys(req.form.errors).length) {
req.form.values['other-info-file-upload'] = null;
}
return super.locals(req, res, next);
const maxNum = fileSizeNum(config.upload.maxFileSize);
const maxSize = config.upload.maxFileSize.match(/[a-zA-Z]+/g)[0].toUpperCase();
return Object.assign({}, super.locals(req, res, next), {
maxFileSize: `${maxNum} ${maxSize}`
});
}

validateField(key, req) {
if (req.form.values['other-info-file-upload']) {
const fileUpload = _.get(req.files, `${name}`);
if (fileUpload) {
const uploadSize = fileUpload.size;
const mimetype = fileUpload.mimetype;
const uploadSizeTooBig = uploadSize > (fileSizeNum(config.upload.maxFileSize) * 1000000);
const uploadSizeBeyondServerLimits = uploadSize === null;
const invalidMimetype = !config.upload.allowedMimeTypes.includes(mimetype);
const invalidSize = uploadSizeTooBig || uploadSizeBeyondServerLimits;

if (invalidSize || invalidMimetype) {
return new this.ValidationError(key, {
key,
type: invalidSize ? 'maxFileSize' : 'fileType',
redirect: undefined
});
}
} else {
return new this.ValidationError(key, {
key,
type: 'required',
redirect: undefined
});
}
}

return super.validateField(key, req);
}

saveValues(req, res, next) {
Expand Down
84 changes: 84 additions & 0 deletions apps/paf/behaviours/set-transport-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
module.exports = superclass => class extends superclass {
locals(req, res) {
const locals = super.locals(req, res);

// set crime-transport-vehicle toggles
if (req.form.values['crime-car-group'] === 'car') {
locals.carChecked = true;
} else if (req.form.values['crime-car-group'] === 'car-transporter') {
locals.carTransporterChecked = true;
} else if (req.form.values['crime-hgv-group'] === 'hgv-canvas-sided') {
locals.hgvCSChecked = true;
} else if (req.form.values['crime-hgv-group'] === 'hgv-flatbed') {
locals.hgvFChecked = true;
} else if (req.form.values['crime-hgv-group'] === 'hgv-hard-sided') {
locals.hgvHSChecked = true;
} else if (req.form.values['crime-hgv-group'] === 'hgv-refrigerated') {
locals.hgvRChecked = true;
} else if (req.form.values['crime-hgv-group'] === 'hgv-tanker') {
locals.hgvTChecked = true;
} else if (req.form.values['crime-lorry-group'] === 'lorry') {
locals.lorryChecked = true;
} else if (req.form.values['crime-lorry-group'] === 'lorry-and-drag') {
locals.lorryDragChecked = true;
} else if (req.form.values['crime-van-group'] === 'van') {
locals.vanChecked = true;
} else if (req.form.values['crime-van-group'] === 'van-and-trailer') {
locals.vanTrailerChecked = true;
} else if (req.form.values['crime-van-group'] === 'van-other') {
locals.vanOtherChecked = true;
} else if (req.form.values['crime-van-group'] === 'seven-point-five-tonne-van') {
locals.sevenVanChecked = true;
}

// set crime-transport-boat toggles
if (req.form.values['crime-carrier-group'] === 'bulk-carrier') {
locals.bulkChecked = true;
} else if (req.form.values['crime-carrier-group'] === 'vehicle-carrier') {
locals.vehicleChecked = true;
} else if (req.form.values['crime-carrier-group'] === 'vessel-carrier') {
locals.vesselChecked = true;
} else if (req.form.values['crime-general-cargo-group'] === 'general-cargo') {
locals.generalChecked = true;
} else if (req.form.values['crime-general-cargo-group'] === 'general-cargo-with-container-capacity') {
locals.generalContainerChecked = true;
} else if (req.form.values['crime-vessel-group'] === 'research-vessel') {
locals.researchChecked = true;
} else if (req.form.values['crime-vessel-group'] === 'supply-vessel') {
locals.supplyChecked = true;
} else if (req.form.values['crime-vessel-group'] === 'support-vessel') {
locals.supportChecked = true;
}

// set report-person-transport toggles
if (req.form.values['report-person-transport-car-group'] === 'car') {
locals.personCarChecked = true;
} else if (req.form.values['report-person-transport-car-group'] === 'car-transporter') {
locals.personCarTransporterChecked = true;
} else if (req.form.values['report-person-transport-hgv-group'] === 'hgv-canvas-sided') {
locals.personHgvCSChecked = true;
} else if (req.form.values['report-person-transport-hgv-group'] === 'hgv-flatbed') {
locals.personHgvFChecked = true;
} else if (req.form.values['report-person-transport-hgv-group'] === 'hgv-hard-sided') {
locals.personHgvHSChecked = true;
} else if (req.form.values['report-person-transport-hgv-group'] === 'hgv-refrigerated') {
locals.personHgvRChecked = true;
} else if (req.form.values['report-person-transport-hgv-group'] === 'hgv-tanker') {
locals.personHgvTChecked = true;
} else if (req.form.values['report-person-transport-lorry-group'] === 'lorry') {
locals.personLorryChecked = true;
} else if (req.form.values['report-person-transport-lorry-group'] === 'lorry-and-drag') {
locals.personLorryDragChecked = true;
} else if (req.form.values['report-person-transport-van-group'] === 'van') {
locals.personVanChecked = true;
} else if (req.form.values['report-person-transport-van-group'] === 'van-and-trailer') {
locals.personVanTrailerChecked = true;
} else if (req.form.values['report-person-transport-van-group'] === 'van-other') {
locals.personVanOtherChecked = true;
} else if (req.form.values['report-person-transport-van-group'] === 'seven-point-five-tonne-van') {
locals.personSevenVanChecked = true;
}

return locals;
}
};
56 changes: 56 additions & 0 deletions apps/paf/behaviours/time-formatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable max-len */
const _ = require('lodash');

module.exports = superclass => class extends superclass {
configure(req, res, next) {
// preprend '0' if number is only a single digit
const pad = num => num !== '' && num.length < 2 ? `0${num}` : num;

if (req.sessionModel.get('time-crime-will-happen-hour')) {
req.sessionModel.set('time-crime-will-happen-hour', pad(req.sessionModel.get('time-crime-will-happen-hour')));
}
if (req.sessionModel.get('time-crime-will-happen-minute')) {
req.sessionModel.set('time-crime-will-happen-minute', pad(req.sessionModel.get('time-crime-will-happen-minute')));
}
// sets minutes to 00 if the hour field has been completed but the minute field left blank
if (req.sessionModel.get('time-crime-will-happen-hour') && req.sessionModel.get('time-crime-will-happen-minute') === '') {
req.sessionModel.set('time-crime-will-happen-minute', '00');
}

if (req.sessionModel.get('time-crime-will-happen-hour') && req.sessionModel.get('time-crime-will-happen-minute')) {
const time = req.sessionModel.get('time-crime-will-happen-hour').concat(' : ', req.sessionModel.get('time-crime-will-happen-minute'));
if (req.sessionModel.get('time-crime-will-happen-hour') < 12) {
req.sessionModel.set('time-crime-will-happen', time + ' am');
} else {
req.sessionModel.set('time-crime-will-happen', time + ' pm');
}
} else {
req.sessionModel.unset('time-crime-will-happen');
}

return super.configure(req, res, next);
}

locals(req, res) {
const locals = super.locals(req, res);
// set change link for for time-crime-will-happen field
if (locals.route === 'confirm') {
_.forEach(locals.rows, fields => {
locals.rows = locals.rows.map(row => {
if (row.section === 'The Crime - Duration') {
_.forEach(fields, sectionFields => {
_.forEach(sectionFields, field => {
if (field.field === 'time-crime-will-happen') {
field.changeLink = '/paf/date-time-crime-will-happen/edit#time-crime-will-happen-hour';
}
});
});
return row;
}
return row;
});
});
}
return locals;
}
};
28 changes: 22 additions & 6 deletions apps/paf/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function lettersAndSpacesOnly(value) {
return /^[A-Za-z\s]*$/.test(value);
}
const moment = require('moment');
const after1900Validator = { type: 'after', arguments: ['1900'] };
const PRETTY_DATE_FORMAT = 'Do MMMM YYYY';

module.exports = {
Expand Down Expand Up @@ -125,12 +126,24 @@ module.exports = {
options: [
'next-twenty-four-hours',
'more-than-twenty-four-hours',
'unknown'
'when-will-crime-happen-unknown'
]
},
'date-crime-will-happen': dateComponent('date-crime-will-happen', {
mixin: 'input-date'
}),
'time-crime-will-happen-hour': {
mixin: 'input-text',
className: ['govuk-input', 'govuk-date-input__input', 'govuk-input--width-2'],
attributes: [{ attribute: 'maxlength', value: '2' }],
validate: ['numeric', { type: 'min', arguments: 0}, { type: 'max', arguments: 23 }]
},
'time-crime-will-happen-minute': {
mixin: 'input-text',
className: ['govuk-input', 'govuk-date-input__input', 'govuk-input--width-2'],
attributes: [{ attribute: 'maxlength', value: '2' }],
validate: ['numeric', { type: 'min', arguments: 0}, { type: 'max', arguments: 59 }]
},
'time-crime-will-happen': {
mixin: 'input-text'
},
Expand Down Expand Up @@ -242,7 +255,7 @@ module.exports = {
'hgv-canvas-sided',
'hgv-flatbed',
'hgv-hard-sided',
'hgv-refridgerated',
'hgv-refrigerated',
'hgv-tanker'
],
dependent: {
Expand Down Expand Up @@ -678,7 +691,8 @@ module.exports = {
},
'report-person-dob': dateComponent('report-person-dob', {
isPageHeading: true,
mixin: 'input-date'
mixin: 'input-date',
validate: ['before', after1900Validator]
}),
'report-person-age-range': {
mixin: 'radio-group',
Expand Down Expand Up @@ -1039,7 +1053,7 @@ module.exports = {
'hgv-canvas-sided',
'hgv-flatbed',
'hgv-hard-sided',
'hgv-refridgerated',
'hgv-refrigerated',
'hgv-tanker'
],
dependent: {
Expand Down Expand Up @@ -1130,6 +1144,7 @@ module.exports = {
personAddDob: dateComponent('personAddDob', {
isPageHeading: true,
mixin: 'input-date',
validate: ['before', after1900Validator],
parse: d => d && moment(d).format(PRETTY_DATE_FORMAT)
}),
personAddAgeRange: {
Expand Down Expand Up @@ -1342,7 +1357,8 @@ module.exports = {
},
'about-you-dob': dateComponent('about-you-dob', {
isPageHeading: true,
mixin: 'input-date'
mixin: 'input-date',
validate: ['before', after1900Validator]
}),
'about-you-nationality': {
isPageHeading: true,
Expand All @@ -1361,7 +1377,7 @@ module.exports = {
'male',
'female',
'other',
'gender-unknown'
'prefer-not-to-say'
]
},
'about-you-contact': {
Expand Down
9 changes: 7 additions & 2 deletions apps/paf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const limitDocs = require('./behaviours/limit-documents');
const disableUpload = require('./behaviours/disable-file-upload');
const SummaryPageBehaviour = require('hof').components.summary;
const transportBehaviour = require('./behaviours/transport-behaviour');
const transportToggle = require('./behaviours/set-transport-toggle');
const Aggregate = require('./behaviours/aggregator');
const limitPerson = require('./behaviours/limit-person');
const personNumber = require('./behaviours/person-number');
Expand All @@ -15,6 +16,7 @@ const additionalPersonFormatter = require('./behaviours/additional-person-format
const vehicleToggleFormatter = require('./behaviours/vehicle-toggle-formatter');
const SendToSQS = require('./behaviours/send-to-sqs');
const UnsetCrimeCountry = require('./behaviours/unset-crime-country');
const timeFormatter = require('./behaviours/time-formatter');

module.exports = {
name: 'paf',
Expand Down Expand Up @@ -60,7 +62,7 @@ module.exports = {
}]
},
'/date-time-crime-will-happen': {
fields: ['date-crime-will-happen', 'time-crime-will-happen'],
fields: ['date-crime-will-happen', 'time-crime-will-happen-hour', 'time-crime-will-happen-minute'],
next: '/when-will-crime-happen-more-info'
},
'/when-will-crime-happen-more-info': {
Expand Down Expand Up @@ -116,6 +118,7 @@ module.exports = {
continueOnEdit: true
},
'/crime-transport-vehicle-type': {
behaviours: [transportToggle],
fields: ['vehicle-type',
'crime-car-group',
'crime-hgv-group',
Expand Down Expand Up @@ -165,6 +168,7 @@ module.exports = {
continueOnEdit: true
},
'/crime-transport-boat-type': {
behaviours: [transportToggle],
fields: ['boat-type',
'crime-carrier-group',
'crime-general-cargo-group',
Expand Down Expand Up @@ -547,6 +551,7 @@ module.exports = {
]
},
'/report-person-transport-type': {
behaviours: [transportToggle],
fields: ['report-person-transport-type',
'report-person-transport-car-group',
'report-person-transport-hgv-group',
Expand Down Expand Up @@ -772,7 +777,7 @@ module.exports = {
fields: ['are-you-eighteen', 'contact-number', 'when-to-contact']
},
'/confirm': {
behaviours: [SummaryPageBehaviour, personNumber],
behaviours: [SummaryPageBehaviour, personNumber, timeFormatter],
sections: require('./sections/summary-data-sections'),
next: '/declaration'
},
Expand Down
5 changes: 3 additions & 2 deletions apps/paf/models/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ module.exports = class UploadModel extends Model {

async save() {
const result = await new Promise((resolve, reject) => {
console.log("url: " + config.upload.hostname);
const attributes = {
url: config.upload.hostname
};
const reqConf = new url.URL(this.url(attributes));
const reqConf = url.parse(this.url(attributes));
reqConf.formData = {
document: {
value: this.get('data'),
Expand Down Expand Up @@ -59,7 +60,7 @@ module.exports = class UploadModel extends Model {
};

return new Promise((resolve, reject) => {
this._request(tokenReq, (err, response) => {
return this._request(tokenReq, (err, response) => {
const body = JSON.parse(response.body);

if (err || body.error) {
Expand Down
Loading

0 comments on commit d9ba5c6

Please sign in to comment.