Skip to content

Commit

Permalink
Merge pull request #2200 from NMDSdevopsServiceAdm/test2live
Browse files Browse the repository at this point in the history
Deploy Staging to Preprod
  • Loading branch information
aaron-russell authored Jun 8, 2020
2 parents 1c8bf4e + a252266 commit fee07fb
Show file tree
Hide file tree
Showing 18 changed files with 773 additions and 50 deletions.
113 changes: 113 additions & 0 deletions migrations/20200528153134-IsRegulated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(t => {
Promise.all([
queryInterface.addColumn(
{
tableName: 'Establishment',
schema: 'cqc',
},
'IsRegulatedSavedAt',
{
type: Sequelize.DataTypes.DATE,
allowNull: true
},
{
transaction: t
}
),
queryInterface.addColumn(
{
tableName: 'Establishment',
schema: 'cqc',
},
'IsRegulatedChangedAt',
{
type: Sequelize.DataTypes.DATE,
allowNull: true
},
{
transaction: t
}
),
queryInterface.addColumn(
{
tableName: 'Establishment',
schema: 'cqc',
},
'IsRegulatedSavedBy',
{
type: Sequelize.DataTypes.TEXT,
allowNull: true
},
{
transaction: t
}
),
queryInterface.addColumn(
{
tableName: 'Establishment',
schema: 'cqc',
},
'IsRegulatedChangedBy',
{
type: Sequelize.DataTypes.TEXT,
allowNull: true
},
{
transaction: t
}
)
]);
});
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(t => {
Promise.all([
queryInterface.removeColumn(
{
tableName: 'Establishment',
schema: 'cqc'
},
'IsRegulatedSavedAt',
{
transaction: t
}
),
queryInterface.removeColumn(
{
tableName: 'Establishment',
schema: 'cqc'
},
'IsRegulatedChangedAt',
{
transaction: t
}
),
queryInterface.removeColumn(
{
tableName: 'Establishment',
schema: 'cqc'
},
'IsRegulatedSavedBy',
{
transaction: t
}
),
queryInterface.removeColumn(
{
tableName: 'Establishment',
schema: 'cqc'
},
'IsRegulatedChangedBy',
{
transaction: t
}
)
]);
});
}
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"server:test:integration": "mocha server/test/integration/**/*.spec.js",
"server:cover": "nyc --reporter=html mocha server/test/**/*.spec.js",
"server:cover:unit": "nyc --reporter=html mocha --exit 'server/test/unit/**/*.spec.js'",
"server:cover:integration": "nyc --reporter=html mocha server/test/integration/**/*.spec.js"
"server:cover:integration": "nyc --reporter=html mocha server/test/integration/**/*.spec.js",
"db:migration:generate": "sequelize migration:generate",
"db:migrate": "sequelize db:migrate"
},
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const address3Property = require("./properties/address3Property").Address3Proper
const townProperty = require("./properties/townProperty").TownProperty;
const countyProperty = require("./properties/countyProperty").CountyProperty;
const postcodeProperty = require("./properties/postcodeProperty").PostcodeProperty;
const isRegulatedProperty = require("./properties/isRegulatedProperty").IsRegulatedProperty;

class EstablishmentPropertyManager {
constructor() {
Expand All @@ -47,6 +48,7 @@ class EstablishmentPropertyManager {
this._thisManager.registerProperty(townProperty);
this._thisManager.registerProperty(countyProperty);
this._thisManager.registerProperty(postcodeProperty);
this._thisManager.registerProperty(isRegulatedProperty);
}

get manager() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// the IsRegulated property is a value property only
const ChangePropertyPrototype = require('../../properties/changePrototype').ChangePropertyPrototype;
const values = [true, false];

exports.IsRegulatedProperty = class IsRegulatedProperty extends ChangePropertyPrototype {
constructor() {
super('IsRegulated');
}

static clone() {
return new IsRegulatedProperty();
}

// concrete implementations
async restoreFromJson(document) {
if (values.includes(document.isRegulated)) {
this.property = document.isRegulated;
}
}

restorePropertyFromSequelize(document) {
return document.isRegulated;
}
savePropertyToSequelize() {
return {
isRegulated: this.property
};
}

isEqual(currentValue, newValue) {
// employer type is a simple string
return currentValue && newValue && currentValue === newValue;
}

toJSON(withHistory=false, showPropertyHistoryOnly=true) {
if (!withHistory) {
// simple form
return {
isRegulated: this.property
};
}

return {
isRegulated: {
currentValue: this.property,
... this.changePropsToJSON(showPropertyHistoryOnly)
}
};
}
};
20 changes: 20 additions & 0 deletions server/models/establishment.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ module.exports = function(sequelize, DataTypes) {
allowNull: false,
field: '"IsRegulated"'
},
IsRegulatedSavedAt : {
type: DataTypes.DATE,
allowNull: true,
field: '"IsRegulatedSavedAt"'
},
IsRegulatedChangedAt : {
type: DataTypes.DATE,
allowNull: true,
field: '"IsRegulatedChangedAt"'
},
IsRegulatedSavedBy : {
type: DataTypes.TEXT,
allowNull: true,
field: '"IsRegulatedSavedBy"'
},
IsRegulatedChangedBy : {
type: DataTypes.TEXT,
allowNull: true,
field: '"IsRegulatedChangedBy"'
},
overallWdfEligibility: {
type: DataTypes.DATE,
allowNull: true,
Expand Down
17 changes: 12 additions & 5 deletions server/routes/establishments/mainService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const router = express.Router({mergeParams: true});

// all user functionality is encapsulated
const Establishment = require('../../models/classes/establishment');
const filteredProperties = ['Name', 'MainServiceFK'];
const {correctCapacities} = require('../../utils/correctCapacities');

const filteredProperties = ['Name', 'MainServiceFK', 'CapacityServices'];

// gets current employer type for the known establishment
router.route('/').get(async (req, res) => {
Expand Down Expand Up @@ -41,7 +43,7 @@ router.route('/').get(async (req, res) => {

// updates the current employer type for the known establishment
router.route('/').post(async (req, res) => {
const establishmentId = req.establishmentId;
const establishmentId = req.establishmentId;
const thisEstablishment = new Establishment.Establishment(req.username);


Expand All @@ -54,13 +56,18 @@ router.route('/').post(async (req, res) => {
if (await thisEstablishment.restore(establishmentId)) {
// TODO: JSON validation

const capacities = await correctCapacities(thisEstablishment, req.body.mainService);

// by loading after the restore, only those properties defined in the
// POST body will be updated (peristed)
// With this endpoint we're only interested in name
const isValidEstablishment = await thisEstablishment.load({
mainService: req.body.mainService
mainService: req.body.mainService,
capacities
});

// do it here

// this is an update to an existing Establishment, so no mandatory properties!
if (isValidEstablishment) {
await thisEstablishment.save(req.username);
Expand All @@ -69,13 +76,13 @@ router.route('/').post(async (req, res) => {
} else {
return res.status(400).send('Unexpected Input.');
}

} else {
// not found worker
return res.status(404).send('Not Found');
}
} catch (err) {

if (err instanceof Establishment.EstablishmentExceptions.EstablishmentJsonException) {
console.error("Establishment::mainService POST: ", err.message);
return res.status(400).send(err.safe);
Expand Down
16 changes: 10 additions & 6 deletions server/routes/establishments/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const express = require('express');
const router = express.Router({mergeParams: true});

const Establishment = require('../../models/classes/establishment');
const filteredProperties = ['Name', 'OtherServices'];
const {correctCapacities} = require('../../utils/correctCapacities');

const filteredProperties = ['Name', 'OtherServices', 'CapacityServices'];

router.route('/').get(async (req, res) => {
const establishmentId = req.establishmentId;

const showHistory = req.query.history === 'full' || req.query.history === 'property' || req.query.history === 'timeline' ? true : false;
const showHistoryTime = req.query.history === 'timeline' ? true : false;
const showPropertyHistoryOnly = req.query.history === 'property' ? true : false;
Expand Down Expand Up @@ -52,11 +54,13 @@ router.route('/').post(async (req, res) => {
if (await thisEstablishment.restore(establishmentId)) {
// TODO: JSON validation

const capacities = await correctCapacities(thisEstablishment, null, req.body.services);
// by loading after the restore, only those properties defined in the
// POST body will be updated (peristed)
// With this endpoint we're only interested in services
const isValidEstablishment = await thisEstablishment.load({
services: req.body.services
services: req.body.services,
capacities
});

// this is an update to an existing Establishment, so no mandatory properties!
Expand All @@ -71,13 +75,13 @@ router.route('/').post(async (req, res) => {
} else {
return res.status(400).send('Unexpected Input.');
}

} else {
// not found worker
return res.status(404).send('Not Found');
}
} catch (err) {

if (err instanceof Establishment.EstablishmentExceptions.EstablishmentJsonException) {
console.error("Establishment::services POST: ", err.message);
return res.status(400).send(err.safe);
Expand All @@ -90,4 +94,4 @@ router.route('/').post(async (req, res) => {
}
});

module.exports = router;
module.exports = router;
Loading

0 comments on commit fee07fb

Please sign in to comment.