Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature branch/quals certificate #6420

Merged
merged 122 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
19adc57
merged training certificates and quals accordions
Jonopono123 Oct 8, 2024
d31e029
(WIP) temp store current changes
kapppa-joe Oct 8, 2024
b0743d7
add certificate related html elements to add-edit-qualification compo…
kapppa-joe Oct 9, 2024
1dba8be
amend css to allow certificate table display in full width
kapppa-joe Oct 9, 2024
0a56efc
add validation for cert upload
kapppa-joe Oct 9, 2024
8cc4044
add more unit tests
kapppa-joe Oct 9, 2024
1aa727d
added new qualificationCertificates table migration, moved training c…
Jonopono123 Oct 9, 2024
d374334
added new quals cert service
Jonopono123 Oct 10, 2024
075a78a
start adding certificate service to frontend
kapppa-joe Oct 11, 2024
c332a44
migrate certificate related method from trainingService to certficate…
kapppa-joe Oct 11, 2024
e0bc99d
migrate references for certificate related methods to CertificateService
kapppa-joe Oct 11, 2024
742ac78
remove commented out / duplicated code in add-edit-training component
kapppa-joe Oct 11, 2024
228beca
minor change in typings
kapppa-joe Oct 11, 2024
dbfa522
amend method name
kapppa-joe Oct 11, 2024
ee35b6e
move tests about upload button to the new shared component (select-up…
kapppa-joe Oct 11, 2024
cc50c57
amend one unit test
kapppa-joe Oct 11, 2024
f078f24
add logic to prevent submit button being triggered more than once
kapppa-joe Oct 11, 2024
1ffc9d9
clear error message on remove button clicked, css adjustment
kapppa-joe Oct 14, 2024
5057a9d
adjust css styling
kapppa-joe Oct 14, 2024
dc76c02
address PR comments
kapppa-joe Oct 14, 2024
5834ffe
Merge pull request #6385 from NMDSdevopsServiceAdm/feat/1525-add-a-ne…
kapppa-joe Oct 14, 2024
ba1f91d
Refactored tests for new workerCertificateService
Jonopono123 Oct 15, 2024
f3ed00b
added test suite around certificate endpoints
Jonopono123 Oct 16, 2024
d3668bf
refactored tests
Jonopono123 Oct 16, 2024
6a5389a
refactored training deletion tests
Jonopono123 Oct 16, 2024
4a1b036
further refactoring on tests
Jonopono123 Oct 16, 2024
554c32c
removed unneeded imports
Jonopono123 Oct 16, 2024
438ea78
fixed upload
Jonopono123 Oct 17, 2024
80b0180
resolved download payload issue
Jonopono123 Oct 17, 2024
699d3da
fixed and refactored failing tests
Jonopono123 Oct 17, 2024
32dd57f
Update backend/server/routes/establishments/qualification/index.js
Jonopono123 Oct 17, 2024
390b2d7
Remove unneeded log
Jonopono123 Oct 17, 2024
03c6b79
Rename param
Jonopono123 Oct 17, 2024
5344955
removed unneeded param formatting
Jonopono123 Oct 17, 2024
d34cc24
Merge branch 'feat/1526-qualsCertsBackend' of https://github.com/NMDS…
Jonopono123 Oct 17, 2024
3ac5fd0
renamed endpoint functions to avoid confusion
Jonopono123 Oct 17, 2024
ce1bbcb
fixed mismatched args/params
Jonopono123 Oct 18, 2024
6b1d64a
updated args in deleteCertificates call
Jonopono123 Oct 18, 2024
62f413f
Merge pull request #6387 from NMDSdevopsServiceAdm/feat/1526-qualsCer…
Jonopono123 Oct 18, 2024
ff4a09e
add test for summary page
kapppa-joe Oct 14, 2024
7af8c74
(WIP) implementing certificate cell for new-qualifications component
kapppa-joe Oct 14, 2024
62b3bb1
amend summary page and table component to use unified event type for …
kapppa-joe Oct 15, 2024
0facaab
implement event emitters at new-qualifications component
kapppa-joe Oct 15, 2024
ffaafe1
refactor tests setup at new-training-and-qualifications-record
kapppa-joe Oct 15, 2024
8ea8587
start adding unit tests for qualification certificate methods at summ…
kapppa-joe Oct 15, 2024
276f45f
add unit tests for qualification cert error message in summary page
kapppa-joe Oct 16, 2024
8e50c6a
refactor the way that new-training component displays error message
kapppa-joe Oct 16, 2024
617d6f1
tidy up
kapppa-joe Oct 16, 2024
33d68f3
remove commented out mock data for testing frontend
kapppa-joe Oct 16, 2024
9e1d731
unify the format of request and response body for cert endpoints
kapppa-joe Oct 18, 2024
0d83289
Merge pull request #6386 from NMDSdevopsServiceAdm/feat/1529-qualific…
kapppa-joe Oct 18, 2024
a747413
add qualification certificates when fetching qualification at backend
kapppa-joe Oct 22, 2024
00726f5
amend link text for downloading pdf, fix a bug that cause pdf to not …
kapppa-joe Oct 22, 2024
ac14068
add download all certificates link
kapppa-joe Oct 22, 2024
4c8b326
install @zip.js, add method to handle zipping file at frontend
kapppa-joe Oct 22, 2024
6be0091
Merge pull request #6392 from NMDSdevopsServiceAdm/feat/1545-update-G…
kapppa-joe Oct 23, 2024
60ca281
fixed failing tests for certs
Jonopono123 Oct 23, 2024
34b3a56
added tests to Qualification restore functionality
Jonopono123 Oct 23, 2024
123dae7
added test case to cover failed to load qual scenario
Jonopono123 Oct 23, 2024
7acfe08
Merge branch 'featureBranch/qualsCertificate' into feat/1527-delete-c…
Jonopono123 Oct 23, 2024
a5b232d
add type declaration and unit test to file util
kapppa-joe Oct 23, 2024
75ed1b0
added missing "await"
Jonopono123 Oct 23, 2024
58f0ca2
add unit tests for downloadAllCertificatesAsBlobs, try test downloadi…
kapppa-joe Oct 23, 2024
faa5cc4
add unit tests for download all certificates
kapppa-joe Oct 24, 2024
9718d95
add unit tests, rename method
kapppa-joe Oct 24, 2024
bf8b846
add logic to avoid download all button being triggered again while do…
kapppa-joe Oct 24, 2024
9e74707
add ngif to not display download all if worker has no certificates at…
kapppa-joe Oct 25, 2024
cf8260b
fix typo
kapppa-joe Oct 25, 2024
4bff689
Merge pull request #6394 from NMDSdevopsServiceAdm/feat/1527-delete-c…
Jonopono123 Oct 25, 2024
fccf840
capitalise the name of zip file and inner folders
kapppa-joe Oct 25, 2024
79139ae
rearrange method orders, remove console log
kapppa-joe Oct 25, 2024
e6115f9
tidy up
kapppa-joe Oct 25, 2024
7615422
fixed qualifications models tests not running
Jonopono123 Oct 25, 2024
65dc954
Merge pull request #6397 from NMDSdevopsServiceAdm/fix/qualifications…
Jonopono123 Oct 25, 2024
894de6f
Merge pull request #6396 from NMDSdevopsServiceAdm/feat/1528-download…
kapppa-joe Oct 28, 2024
ca8d042
merged featureBranch/training-certificates into featureBranch/qualsCe…
Jonopono123 Oct 31, 2024
b09b6ae
fixed failing tests resulting from merge
Jonopono123 Nov 1, 2024
8253d9a
resolved conflicts from pull
Jonopono123 Nov 1, 2024
b79564a
Merge latest changes from training certificates into branch
duncanc19 Nov 1, 2024
62f10a0
Add canEditWorker check for displaying qualification certificate link…
duncanc19 Nov 1, 2024
96d37b0
Update test names to say qualification instead of training
duncanc19 Nov 1, 2024
29aea0e
refactoring delete all certificates functionality
Jonopono123 Nov 1, 2024
70326f0
refactored functionality for deleting all training certificates
Jonopono123 Nov 1, 2024
3905a36
Merge pull request #6402 from NMDSdevopsServiceAdm/fix/hide-qualifica…
duncanc19 Nov 4, 2024
fb3294d
add a helper class to process bulk upload qualifications
kapppa-joe Oct 28, 2024
0631787
bugfix for DELETE qualification endpoint not working when qualificati…
kapppa-joe Oct 28, 2024
f979a7a
bugfix for DELETE training endpoint as well
kapppa-joe Oct 28, 2024
fa69c9a
amend backend workerCertificateService so that file key retrieval wor…
kapppa-joe Oct 30, 2024
43053f7
add unit tests to verify change
kapppa-joe Oct 30, 2024
1c66038
implementing deleteQualification
kapppa-joe Nov 1, 2024
945631b
add test for deleteQualification at bulk upload
kapppa-joe Nov 4, 2024
c39ee3f
ensure new logic only triggered in bulk upload process
kapppa-joe Nov 4, 2024
daa3547
tidy up
kapppa-joe Nov 4, 2024
d6ead32
minor fix
kapppa-joe Nov 4, 2024
1e40b69
remove console logs
kapppa-joe Nov 4, 2024
91a91bf
amend wording for clarity
kapppa-joe Nov 4, 2024
2e9fb06
address PR comment (about bulkUploaded boolean at helper class)
kapppa-joe Nov 4, 2024
5c7ce9d
add a missing await
kapppa-joe Nov 4, 2024
d8ffe68
Refactored training cert deletion
Jonopono123 Nov 4, 2024
5aa67e9
added bulk quals cert deletion functionality
Jonopono123 Nov 4, 2024
72e9239
remove redundant method verifyParentRecordExists / findParentRecord
kapppa-joe Nov 4, 2024
5200858
added delete all quals certs tests to workerCertificateService
Jonopono123 Nov 4, 2024
1fd06f7
refactor
kapppa-joe Nov 5, 2024
afa2a9a
added transaction to deleteCertificate function on qualificationCerti…
Jonopono123 Nov 5, 2024
abcb721
PR changes and some additional test cases
Jonopono123 Nov 5, 2024
f7211de
Removed BU Quals cert deletion and refactored error handling
Jonopono123 Nov 5, 2024
3f817dd
changed HttpErrors on training class back to regular Errors
Jonopono123 Nov 5, 2024
e90ae32
Merge pull request #6404 from NMDSdevopsServiceAdm/feat/1544-delete-q…
Jonopono123 Nov 6, 2024
a847fe9
Merge branch 'featureBranch/qualsCertificate' into feat/1549-bulk-upl…
kapppa-joe Nov 6, 2024
2e52321
Merge pull request #6403 from NMDSdevopsServiceAdm/feat/1549-bulk-upl…
kapppa-joe Nov 6, 2024
df6660e
Merge branch 'main' into featureBranch/qualsCertificate
kapppa-joe Nov 15, 2024
e512ee4
Create shared asc-training-and-quals-table class to match styling for…
duncanc19 Nov 19, 2024
65eb253
swapped the priority of the error messages for cert uploads
Jonopono123 Nov 19, 2024
98624ad
Merge pull request #6418 from NMDSdevopsServiceAdm/fix/qualification-…
duncanc19 Nov 19, 2024
fa8e46c
Merge pull request #6419 from NMDSdevopsServiceAdm/fix/upload-cert-er…
Jonopono123 Nov 20, 2024
077a779
Update deleteTrainingRecord endpoint to check for certificates correctly
duncanc19 Nov 20, 2024
e95d9f7
Refactor to remove if else nesting
duncanc19 Nov 20, 2024
6525781
Merge pull request #6421 from NMDSdevopsServiceAdm/fix/delete-certifi…
duncanc19 Nov 20, 2024
4298331
add CHGSUB to the if branch condition to call BulkUploadQualification…
kapppa-joe Nov 21, 2024
92ac039
Merge pull request #6424 from NMDSdevopsServiceAdm/fix/add-change-sub…
duncanc19 Nov 21, 2024
24775f4
Send default Internal server error message when unexpected errors occ…
duncanc19 Nov 22, 2024
7916e3a
Merge pull request #6425 from NMDSdevopsServiceAdm/fix/only-return-ex…
duncanc19 Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
return queryInterface.createTable(
'QualificationCertificates',
{
ID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
UID: {
type: Sequelize.DataTypes.UUID,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
unique: true,
},
WorkerQualificationsFK: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
references: {
model: {
tableName: 'WorkerQualifications',
schema: 'cqc',
},
key: 'ID',
},
},
WorkerFK: {
type: Sequelize.DataTypes.INTEGER,
allowNull: false,
references: {
model: {
tableName: 'Worker',
schema: 'cqc',
},
key: 'ID',
},
},
FileName: {
type: Sequelize.DataTypes.TEXT,
allowNull: false,
},
UploadDate: {
type: Sequelize.DataTypes.DATE,
allowNull: true,
},
Key: {
type: Sequelize.DataTypes.TEXT,
allowNull: false,
},
},
{ schema: 'cqc' },
);
},

async down(queryInterface) {
/**
* Add reverting commands here.
*
* Example:
* await queryInterface.dropTable('users');
*/
return queryInterface.dropTable({
tableName: 'QualificationCertificates',
schema: 'cqc',
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { compact } = require('lodash');

const models = require('../../index');
const WorkerCertificateService = require('../../../routes/establishments/workerCertificate/workerCertificateService');

class BulkUploadQualificationHelper {
constructor({ workerId, workerUid, establishmentId, savedBy, externalTransaction }) {
this.workerId = workerId;
this.workerUid = workerUid;
this.establishmentId = establishmentId;
this.savedBy = savedBy;
this.bulkUploaded = true;
this.externalTransaction = externalTransaction;
this.qualificationCertificateService = WorkerCertificateService.initialiseQualifications();
}

async processQualificationsEntities(qualificationsEntities) {
const promisesToReturn = [];

const allQualificationRecords = await models.workerQualifications.findAll({
where: {
workerFk: this.workerId,
},
});

for (const bulkUploadEntity of qualificationsEntities) {
const currentQualificationId = bulkUploadEntity?._qualification?.id;
const existingQualification = allQualificationRecords.find(
(record) => record.qualificationFk === currentQualificationId,
);

if (existingQualification) {
promisesToReturn.push(this.updateQualification(existingQualification, bulkUploadEntity));
} else {
promisesToReturn.push(this.createNewQualification(bulkUploadEntity));
}
}

const bulkUploadQualificationFks = compact(qualificationsEntities.map((entity) => entity?._qualification?.id));
const qualificationsToDelete = allQualificationRecords.filter(
(qualification) => !bulkUploadQualificationFks.includes(qualification.qualificationFk),
);
for (const qualification of qualificationsToDelete) {
promisesToReturn.push(this.deleteQualification(qualification));
}

return promisesToReturn;
}

createNewQualification(entityFromBulkUpload) {
entityFromBulkUpload.workerId = this.workerId;
entityFromBulkUpload.workerUid = this.workerUid;
entityFromBulkUpload.establishmentId = this.establishmentId;

return entityFromBulkUpload.save(this.savedBy, this.bulkUploaded, 0, this.externalTransaction);
}

updateQualification(existingRecord, entityFromBulkUpload) {
const fieldsToUpdate = {
source: 'Bulk',
updatedBy: this.savedBy.toLowerCase(),
notes: entityFromBulkUpload.notes ?? existingRecord.notes,
year: entityFromBulkUpload.year ?? existingRecord.year,
};

existingRecord.set(fieldsToUpdate);

return existingRecord.save({ transaction: this.externalTransaction });
}

async deleteQualification(existingRecord) {
const certificatesFound = await existingRecord.getQualificationCertificates();
if (certificatesFound?.length) {
await this.qualificationCertificateService.deleteCertificatesWithTransaction(
certificatesFound,
this.externalTransaction,
);
}

return existingRecord.destroy({ transaction: this.externalTransaction });
}
}

module.exports = BulkUploadQualificationHelper;
47 changes: 45 additions & 2 deletions backend/server/models/classes/qualification.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Qualification extends EntityValidator {
this._qualification = null;
this._year = null;
this._notes = null;
this._qualificationCertificates = null;

// lifecycle properties
this._isNew = false;
Expand Down Expand Up @@ -105,7 +106,7 @@ class Qualification extends EntityValidator {
}

get workerId() {
return this._workerUid;
return this._workerId;
}
get workerUid() {
return this._workerUid;
Expand Down Expand Up @@ -139,6 +140,11 @@ class Qualification extends EntityValidator {
get created() {
return this._created;
}

get qualificationCertificates() {
return this._qualificationCertificates;
}

get updated() {
return this._updated;
}
Expand All @@ -156,9 +162,17 @@ class Qualification extends EntityValidator {
if (this._notes === null) return null;
return unescape(this._notes);
}

get qualificationCertificates() {
return this._qualificationCertificates;
}

set qualification(qualification) {
this._qualification = qualification;
}
set qualificationCertificates(qualificationCertificates) {
this._qualificationCertificates = qualificationCertificates;
}
set year(year) {
this._year = year;
}
Expand All @@ -171,6 +185,10 @@ class Qualification extends EntityValidator {
}
}

set qualificationCertificates(qualificationCertificates) {
this._qualificationCertificates = qualificationCertificates;
}

// used by save to initialise a new Qualification Record; returns true if having initialised this Qualification Record
_initialise() {
if (this._uid === null) {
Expand Down Expand Up @@ -542,6 +560,15 @@ class Qualification extends EntityValidator {
model: models.workerAvailableQualifications,
as: 'qualification',
},
{
model: models.qualificationCertificates,
as: 'qualificationCertificates',
attributes: ['uid', 'filename', 'uploadDate'],
order: [
[models.qualificationCertificates, 'uploadDate', 'DESC'],
[models.qualificationCertificates, 'filename', 'ASC'],
],
},
],
};

Expand All @@ -560,10 +587,12 @@ class Qualification extends EntityValidator {
};
this._year = fetchResults.year;
this._notes = fetchResults.notes !== null && fetchResults.notes.length === 0 ? null : fetchResults.notes;
this._qualificationCertificates = fetchResults.qualificationCertificates;

this._created = fetchResults.created;
this._updated = fetchResults.updated;
this._updatedBy = fetchResults.updatedBy;
this._qualificationCertificates = fetchResults.qualificationCertificates;

return true;
}
Expand All @@ -573,7 +602,7 @@ class Qualification extends EntityValidator {
// typically errors when making changes to model or database schema!
this._log(Qualification.LOG_ERROR, err);

throw new Error(`Failed to load Qualification record with uid (${this.uid})`);
throw new Error(`Failed to load Qualification record with uid (${uid})`);
}
}

Expand Down Expand Up @@ -618,6 +647,7 @@ class Qualification extends EntityValidator {
this._qualification = null;
this._year = null;
this._notes = null;
this._qualificationCertificates = null;

this._created = null;
this._updated = null;
Expand Down Expand Up @@ -655,6 +685,11 @@ class Qualification extends EntityValidator {
as: 'qualification',
attributes: ['id', 'group', 'title', 'level'],
},
{
model: models.qualificationCertificates,
as: 'qualificationCertificates',
attributes: ['uid', 'filename', 'uploadDate'],
},
],
order: [
//['completed', 'DESC'],
Expand All @@ -674,6 +709,13 @@ class Qualification extends EntityValidator {
},
year: thisRecord.year != null ? thisRecord.year : undefined,
notes: thisRecord.notes !== null && thisRecord.notes.length > 0 ? unescape(thisRecord.notes) : undefined,
qualificationCertificates: thisRecord.qualificationCertificates?.map((certificate) => {
return {
uid: certificate.uid,
filename: certificate.filename,
uploadDate: certificate.uploadDate?.toISOString(),
};
}),
created: thisRecord.created.toISOString(),
updated: thisRecord.updated.toISOString(),
updatedBy: thisRecord.updatedBy,
Expand Down Expand Up @@ -712,6 +754,7 @@ class Qualification extends EntityValidator {
qualification: this.qualification,
year: this.year !== null ? this.year : undefined,
notes: this._notes !== null ? this.notes : undefined,
qualificationCertificates: this.qualificationCertificates ?? [],
};

return myDefaultJSON;
Expand Down
54 changes: 23 additions & 31 deletions backend/server/models/classes/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ const JSON_DOCUMENT_TYPE = require('./worker/workerProperties').JSON_DOCUMENT;
const SEQUELIZE_DOCUMENT_TYPE = require('./worker/workerProperties').SEQUELIZE_DOCUMENT;

const TrainingCertificateRoute = require('../../routes/establishments/workerCertificate/trainingCertificate');
const WorkerCertificateService = require('../../routes/establishments/workerCertificate/workerCertificateService');

// WDF Calculator
const WdfCalculator = require('./wdfCalculator').WdfCalculator;

const BulkUploadQualificationHelper = require('./helpers/bulkUploadQualificationHelper');

const STOP_VALIDATING_ON = ['UNCHECKED', 'DELETE', 'DELETED', 'NOCHANGE'];

class Worker extends EntityValidator {
Expand Down Expand Up @@ -473,7 +476,6 @@ class Worker extends EntityValidator {
// and qualifications records
this._qualificationsEntities = [];
if (document.qualifications && Array.isArray(document.qualifications)) {
// console.log("WA DEBUG - document.qualifications: ", document.qualifications)
document.qualifications.forEach((thisQualificationRecord) => {
const newQualificationRecord = new Qualification(null, null);

Expand Down Expand Up @@ -528,7 +530,7 @@ class Worker extends EntityValidator {
}

async saveAssociatedEntities(savedBy, bulkUploaded = false, externalTransaction) {
const newQualificationsPromises = [];
const qualificationChangePromises = [];
const newTrainingPromises = [];

try {
Expand All @@ -551,29 +553,22 @@ class Worker extends EntityValidator {
});
}

// there is no change audit on qualifications; simply delete all that is there and recreate
if (this._qualificationsEntities && this._qualificationsEntities.length > 0) {
// delete all existing training records for this worker
await models.workerQualifications.destroy({
where: {
workerFk: this._id,
},
transaction: externalTransaction,
});

// now create new training records
this._qualificationsEntities.forEach((currentQualificationRecord) => {
currentQualificationRecord.workerId = this._id;
currentQualificationRecord.workerUid = this._uid;
currentQualificationRecord.establishmentId = this._establishmentId;
newQualificationsPromises.push(
currentQualificationRecord.save(savedBy, bulkUploaded, 0, externalTransaction),
);
if (bulkUploaded && ['NEW', 'UPDATE'].includes(this.status)) {
const qualificationHelper = new BulkUploadQualificationHelper({
workerId: this._id,
workerUid: this._uid,
establishmentId: this._establishmentId,
savedBy,
bulkUploaded,
externalTransaction,
});
const qualificationEntities = this._qualificationsEntities ? this._qualificationsEntities : [];
const promisesToPush = await qualificationHelper.processQualificationsEntities(qualificationEntities);
qualificationChangePromises.push(...promisesToPush);
}

await Promise.all(newTrainingPromises);
await Promise.all(newQualificationsPromises);
await Promise.all(qualificationChangePromises);
} catch (err) {
console.error('Worker::saveAssociatedEntities error: ', err);
// rethrow error to ensure the transaction is rolled back
Expand Down Expand Up @@ -1153,6 +1148,7 @@ class Worker extends EntityValidator {
}

await this.deleteAllTrainingCertificatesAssociatedWithWorker(thisTransaction);
await this.deleteAllQualificationCertificatesAssociatedWithWorker(thisTransaction);

// always recalculate WDF - if not bulk upload (this._status)
if (this._status === null) {
Expand Down Expand Up @@ -1900,17 +1896,13 @@ class Worker extends EntityValidator {
}

async deleteAllTrainingCertificatesAssociatedWithWorker(transaction) {
const trainingCertificates = await models.trainingCertificates.getAllTrainingCertificateRecordsForWorker(this._id);

if (!trainingCertificates.length) return;

const trainingCertificateUids = trainingCertificates.map((cert) => cert.uid);
const filesToDeleteFromS3 = trainingCertificates.map((cert) => {
return { Key: cert.key };
});
const workerTrainingCertificateService = WorkerCertificateService.initialiseTraining();
await workerTrainingCertificateService.deleteAllCertificates(this._id, transaction);
}

await models.trainingCertificates.deleteCertificate(trainingCertificateUids, transaction);
await TrainingCertificateRoute.deleteCertificatesFromS3(filesToDeleteFromS3);
async deleteAllQualificationCertificatesAssociatedWithWorker(transaction) {
const workerQualificationCertificateService = WorkerCertificateService.initialiseQualifications();
await workerQualificationCertificateService.deleteAllCertificates(this._id, transaction);
}
}

Expand Down
Loading
Loading