-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,696 additions
and
38 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
backend/migrations/20240827102746-addLevel2CareCertificate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
const table = { tableName: 'Worker', schema: 'cqc' }; | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.sequelize.transaction((transaction) => { | ||
return Promise.all([ | ||
queryInterface.addColumn( | ||
table, | ||
'Level2CareCertificateValue', | ||
{ | ||
type: Sequelize.DataTypes.TEXT, | ||
allowNull: true, | ||
}, | ||
{ transaction }, | ||
), | ||
queryInterface.addColumn( | ||
table, | ||
'Level2CareCertificateYear', | ||
{ | ||
type: Sequelize.DataTypes.INTEGER, | ||
allowNull: true, | ||
}, | ||
{ transaction }, | ||
), | ||
queryInterface.addColumn( | ||
table, | ||
'Level2CareCertificateSavedAt', | ||
{ | ||
type: Sequelize.DataTypes.DATE, | ||
allowNull: true, | ||
}, | ||
{ transaction }, | ||
), | ||
queryInterface.addColumn( | ||
table, | ||
'Level2CareCertificateChangedAt', | ||
{ | ||
type: Sequelize.DataTypes.DATE, | ||
allowNull: true, | ||
}, | ||
{ transaction }, | ||
), | ||
queryInterface.addColumn( | ||
table, | ||
'Level2CareCertificateSavedBy', | ||
{ | ||
type: Sequelize.DataTypes.TEXT, | ||
allowNull: true, | ||
}, | ||
{ transaction }, | ||
), | ||
queryInterface.addColumn( | ||
table, | ||
'Level2CareCertificateChangedBy', | ||
{ | ||
type: Sequelize.DataTypes.TEXT, | ||
allowNull: true, | ||
}, | ||
{ transaction }, | ||
), | ||
]); | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.sequelize.transaction((transaction) => { | ||
return Promise.all([ | ||
queryInterface.removeColumn(table, 'Level2CareCertificateValue', { transaction }), | ||
queryInterface.removeColumn(table, 'Level2CareCertificateYear', { transaction }), | ||
queryInterface.removeColumn(table, 'Level2CareCertificateSavedAt', { transaction }), | ||
queryInterface.removeColumn(table, 'Level2CareCertificateChangedAt', { transaction }), | ||
queryInterface.removeColumn(table, 'Level2CareCertificateSavedBy', { transaction }), | ||
queryInterface.removeColumn(table, 'Level2CareCertificateChangedBy', { transaction }), | ||
]); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
backend/server/models/classes/worker/properties/level2CareCertificateProperty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// the level 2 care certificate property is an enumeration | ||
const ChangePropertyPrototype = require('../../properties/changePrototype').ChangePropertyPrototype; | ||
|
||
const LEVEL_2_CARE_CERTIFICATE_TYPE = ['Yes, completed', 'Yes, started', 'No']; | ||
exports.WorkerLevel2CareCertificateProperty = class WorkerLevel2CareCertificateProperty extends ( | ||
ChangePropertyPrototype | ||
) { | ||
constructor() { | ||
super('Level2CareCertificate'); | ||
this._allowNull = true; | ||
} | ||
|
||
static clone() { | ||
return new WorkerLevel2CareCertificateProperty(); | ||
} | ||
|
||
// concrete implementations | ||
async restoreFromJson(document) { | ||
const completedInYearSinceLevel2CareCertIntroduced = (year) => { | ||
const yearLevel2CareCertificateIntroduced = 2024; | ||
const thisYear = new Date().getFullYear(); | ||
return year >= yearLevel2CareCertificateIntroduced && document.level2CareCertificate.year <= thisYear | ||
? true | ||
: false; | ||
}; | ||
|
||
if (document.level2CareCertificate) { | ||
if ( | ||
[LEVEL_2_CARE_CERTIFICATE_TYPE[1], LEVEL_2_CARE_CERTIFICATE_TYPE[2]].includes( | ||
document.level2CareCertificate.value, | ||
) | ||
) { | ||
this.property = { | ||
value: document.level2CareCertificate.value, | ||
year: null, | ||
}; | ||
return; | ||
} | ||
|
||
if (document.level2CareCertificate.value === LEVEL_2_CARE_CERTIFICATE_TYPE[0]) { | ||
if ( | ||
document.level2CareCertificate.year && | ||
Number.isInteger(document.level2CareCertificate.year) && | ||
completedInYearSinceLevel2CareCertIntroduced(document.level2CareCertificate.year) | ||
) { | ||
this.property = { | ||
value: document.level2CareCertificate.value, | ||
year: document.level2CareCertificate.year, | ||
}; | ||
} else { | ||
this.property = { | ||
value: document.level2CareCertificate.value, | ||
year: null, | ||
}; | ||
} | ||
return; | ||
} | ||
this.property = null; | ||
} | ||
} | ||
|
||
restorePropertyFromSequelize(document) { | ||
let level2CareCertificate = { | ||
value: document.Level2CareCertificateValue, | ||
year: document.Level2CareCertificateYear, | ||
}; | ||
return level2CareCertificate; | ||
} | ||
|
||
savePropertyToSequelize() { | ||
return { | ||
Level2CareCertificateValue: this.property.value, | ||
Level2CareCertificateYear: | ||
this.property.value === 'Yes, completed' && this.property.year ? this.property.year : null, | ||
}; | ||
} | ||
|
||
isEqual(currentValue, newValue) { | ||
// not a simple (enum'd) string compare; if "Yes, completed", also need to compare the year (just an integer) | ||
|
||
if (currentValue && newValue && currentValue.value === 'Yes, completed') { | ||
if (currentValue.year === newValue.year) { | ||
return currentValue.value === newValue.value; | ||
} | ||
return false; | ||
} | ||
|
||
return currentValue && newValue && currentValue.value === newValue.value; | ||
} | ||
|
||
toJSON(withHistory = false, showPropertyHistoryOnly = true) { | ||
if (!withHistory) { | ||
// simple form | ||
return { | ||
level2CareCertificate: this.property, | ||
}; | ||
} | ||
|
||
return { | ||
level2CareCertificate: { | ||
currentValue: this.property, | ||
...this.changePropsToJSON(showPropertyHistoryOnly), | ||
}, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.