Skip to content

Commit 1bac4cb

Browse files
committed
Fix eslint error
1 parent 0aba6e1 commit 1bac4cb

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

0x05-Node_JS_basic/full_server/controllers/StudentsController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class StudentsController {
3232
`Number of students in ${field}: ${group.length}.`,
3333
'List:',
3434
group.map((student) => student.firstname).join(', '),
35-
].join(' ')
35+
].join(' '),
3636
);
3737
}
3838
response.status(200).send(responseParts.join('\n'));

0x05-Node_JS_basic/full_server/utils.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,40 @@ import fs from 'fs';
33
/**
44
* Reads the data of students in a CSV data file.
55
* @param {String} dataPath The path to the CSV data file.
6-
* @author Bezaleel Olakunori <https://github.com/B3zaleel>
76
* @returns {Promise<{
87
* String: {firstname: String, lastname: String, age: number}[]
98
* }>}
109
*/
11-
const readDatabase = (dataPath) =>
12-
new Promise((resolve, reject) => {
13-
if (!dataPath) {
14-
reject(new Error('Cannot load the database'));
15-
}
16-
if (dataPath) {
17-
fs.readFile(dataPath, (err, data) => {
18-
if (err) {
19-
reject(new Error('Cannot load the database'));
20-
}
21-
if (data) {
22-
const fileLines = data.toString('utf-8').trim().split('\n');
23-
const studentGroups = {};
24-
const dbFieldNames = fileLines[0].split(',');
25-
const stuPropNames = dbFieldNames.slice(0, dbFieldNames.length - 1);
10+
const readDatabase = (dataPath) => new Promise((resolve, reject) => {
11+
if (!dataPath) {
12+
reject(new Error('Cannot load the database'));
13+
}
14+
if (dataPath) {
15+
fs.readFile(dataPath, (err, data) => {
16+
if (err) {
17+
reject(new Error('Cannot load the database'));
18+
}
19+
if (data) {
20+
const fileLines = data.toString('utf-8').trim().split('\n');
21+
const studentGroups = {};
22+
const dbFieldNames = fileLines[0].split(',');
23+
const stuPropNames = dbFieldNames.slice(0, dbFieldNames.length - 1);
2624

27-
for (const line of fileLines.slice(1)) {
28-
const studentRecord = line.split(',');
29-
const studentPropValues = studentRecord.slice(0, studentRecord.length - 1);
30-
const field = studentRecord[studentRecord.length - 1];
31-
if (!Object.keys(studentGroups).includes(field)) {
32-
studentGroups[field] = [];
33-
}
34-
const studentEntries = stuPropNames.map((propName, idx) => [propName, studentPropValues[idx]]);
35-
studentGroups[field].push(Object.fromEntries(studentEntries));
25+
for (const line of fileLines.slice(1)) {
26+
const studentRecord = line.split(',');
27+
const stuPropValues = studentRecord.slice(0, studentRecord.length - 1);
28+
const field = studentRecord[studentRecord.length - 1];
29+
if (!Object.keys(studentGroups).includes(field)) {
30+
studentGroups[field] = [];
3631
}
37-
resolve(studentGroups);
32+
const stuEntries = stuPropNames.map((propName, idx) => [propName, stuPropValues[idx]]);
33+
studentGroups[field].push(Object.fromEntries(stuEntries));
3834
}
39-
});
40-
}
41-
});
35+
resolve(studentGroups);
36+
}
37+
});
38+
}
39+
});
4240

4341
export default readDatabase;
4442
module.exports = readDatabase;

0 commit comments

Comments
 (0)