Skip to content

Commit bbffa8f

Browse files
committed
refactor: extract learner building logic into factory modules
Reorganise learner construction by splitting monolithic functions into focused factory modules. Move files from src/utils to src/factories to better reflect their purpose as data builders rather than general utilities. - Extract reference number, learner details, health details, prior attainment, and employment logic into separate factory modules - Simplify pushLearners by composing learner objects from factory functions - Update imports to reflect new factory structure - Clean up formatting in main.js and buildLearningDeliveryArray
1 parent e16db96 commit bbffa8f

File tree

8 files changed

+66
-42
lines changed

8 files changed

+66
-42
lines changed

main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function createWindow() {
9292
win.webContents.toggleDevTools();
9393
});
9494
}
95+
9596
app.whenReady().then(() => {
9697
createWindow();
9798
app.on("activate", () => {
@@ -208,6 +209,4 @@ ipcMain.on("openSave", (event) => {
208209
saveDialogue();
209210
});
210211

211-
app.on("window-all-closed", () => {
212-
app.quit();
213-
});
212+
app.on("window-all-closed", () => { app.quit() });
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function buildHealthDetails(dataArray, i) {
2+
return {
3+
LLDDHealthProb: dataArray[i][13] != "99" ? 1 : 9,
4+
LLDDandHealthProblem: dataArray[i][13] != "99"
5+
? [{
6+
LLDDCat: dataArray[i][13],
7+
PrimaryLLDD: 1
8+
}]
9+
: undefined
10+
}
11+
}
12+
13+
module.exports = { buildHealthDetails };
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function buildLearnerDetails(dataArray, i) {
2+
return {
3+
FamilyName: dataArray[i][4].trim(),
4+
GivenNames: dataArray[i][3].trim(),
5+
DateOfBirth: dataArray[i][6],
6+
Ethnicity: dataArray[i][8],
7+
Sex: dataArray[i][5],
8+
NINumber: dataArray[i][7].replace(/\s+/g, "").trim(),
9+
PlanLearnHours: dataArray[i][16] || undefined,
10+
PostcodePrior: dataArray[i][9].trim(),
11+
Postcode: dataArray[i][10].trim(),
12+
AddLine1: dataArray[i][11].replace(/[^a-zA-Z0-9\s]/g, "").trim().substring(0, 50),
13+
TelNo: dataArray[i][12] || undefined
14+
}
15+
}
16+
17+
module.exports = { buildLearnerDetails };

src/utils/buildLearningDeliveryArray.js renamed to src/factories/buildLearningDeliveryArray.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ function buildLearningDeliveryArray(dataArray, i) {
396396
},
397397
]
398398
: []),
399-
],
399+
]
400400
}] : []
401401
),
402402
]
403403
}
404404

405-
module.exports = { buildLearningDeliveryArray };
405+
module.exports = { buildLearningDeliveryArray };
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function buildPriorAttainment(dataArray, i) {
2+
return {
3+
PriorAttain: {
4+
PriorLevel: dataArray[i][15],
5+
DateLevelApp: dataArray[i][14],
6+
},
7+
}
8+
}
9+
10+
module.exports = { buildPriorAttainment };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function buildReferenceNumbers(dataArray, i) {
2+
return {
3+
LearnRefNumber: dataArray[i][223],
4+
ULN: dataArray[i][2],
5+
PrevLearnRefNumber: dataArray[i][222]
6+
}
7+
}
8+
9+
module.exports = { buildReferenceNumbers };

src/utils/pushLearners.js

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,19 @@
1-
const { buildEmploymentArray } = require("./buildEmploymentArray");
2-
const { buildLearningDeliveryArray } = require("./buildLearningDeliveryArray");
1+
const { buildEmploymentArray } = require("../factories/buildEmploymentArray");
2+
const { buildHealthDetails } = require("../factories/buildHealthDetails");
3+
const { buildLearnerDetails } = require("../factories/buildLearnerDetails");
4+
const { buildLearningDeliveryArray } = require("../factories/buildLearningDeliveryArray");
5+
const { buildPriorAttainment } = require("../factories/buildPriorAttainment");
6+
const { buildReferenceNumbers } = require("../factories/buildReferenceNumbers");
37

48
function pushLearners(dataArray, xmlBase) {
5-
for (let i = 1; i < dataArray.length; i++) {
6-
const refNumber = i
7-
.toString()
8-
.padStart(4, "0");
9-
10-
const employmentStatusArray = buildEmploymentArray(dataArray, i);
11-
const learningDeliveryArray = buildLearningDeliveryArray(dataArray, i);
12-
9+
for (let i = 1; i <= dataArray.length; i++) {
1310
const learner = {
14-
LearnRefNumber: refNumber,
15-
ULN: dataArray[i][2],
16-
FamilyName: dataArray[i][4].trim(),
17-
GivenNames: dataArray[i][3].trim(),
18-
DateOfBirth: dataArray[i][6],
19-
Ethnicity: dataArray[i][8],
20-
Sex: dataArray[i][5],
21-
LLDDHealthProb: dataArray[i][12],
22-
NINumber: dataArray[i][7].replace(/\s+/g, "").trim(),
23-
PlanLearnHours: dataArray[i][16] || undefined,
24-
PostcodePrior: dataArray[i][9].trim(),
25-
Postcode: dataArray[i][10].trim(),
26-
AddLine1: dataArray[i][11]
27-
.replace(/[^a-zA-Z0-9\s]/g, "")
28-
.trim()
29-
.substring(0, 50),
30-
TelNo: dataArray[i][12] || undefined,
31-
LLDDHealthProb: dataArray[i][13] != "99" ? 1 : 9,
32-
PriorAttain: {
33-
PriorLevel: dataArray[i][15],
34-
DateLevelApp: dataArray[i][14],
35-
},
36-
LLDDandHealthProblem: dataArray[i][13] != "99"
37-
? [{ LLDDCat: dataArray[i][13], PrimaryLLDD: 1 }]
38-
: undefined,
39-
LearnerEmploymentStatus: employmentStatusArray,
40-
LearningDelivery: learningDeliveryArray
11+
...buildReferenceNumbers(dataArray, i),
12+
...buildLearnerDetails(dataArray, i),
13+
...buildHealthDetails(dataArray, i),
14+
...buildPriorAttainment(dataArray, i),
15+
LearnerEmploymentStatus: buildEmploymentArray(dataArray, i),
16+
LearningDelivery: buildLearningDeliveryArray(dataArray, i)
4117
}
4218

4319
xmlBase.Learner.push(learner);

0 commit comments

Comments
 (0)