Compare commits

..

2 Commits

3 changed files with 49 additions and 55 deletions

10
package-lock.json generated
View File

@@ -49,6 +49,7 @@
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
"@types/jsdom": "^21.1.7", "@types/jsdom": "^21.1.7",
"@types/lodash": "^4.17.16",
"@types/multer": "^1.4.12", "@types/multer": "^1.4.12",
"@types/node": "^22.10.9", "@types/node": "^22.10.9",
"@types/object-hash": "^3.0.6", "@types/object-hash": "^3.0.6",
@@ -3946,6 +3947,13 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/lodash": {
"version": "4.17.16",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz",
"integrity": "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/long": { "node_modules/@types/long": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz",
@@ -9602,6 +9610,8 @@
}, },
"node_modules/lodash": { "node_modules/lodash": {
"version": "4.17.21", "version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/lodash.camelcase": { "node_modules/lodash.camelcase": {

View File

@@ -61,6 +61,7 @@
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
"@types/jsdom": "^21.1.7", "@types/jsdom": "^21.1.7",
"@types/lodash": "^4.17.16",
"@types/multer": "^1.4.12", "@types/multer": "^1.4.12",
"@types/node": "^22.10.9", "@types/node": "^22.10.9",
"@types/object-hash": "^3.0.6", "@types/object-hash": "^3.0.6",

View File

@@ -4,7 +4,6 @@ import * as XLSX from "xlsx";
import { Range, WorkSheet } from "xlsx"; import { Range, WorkSheet } from "xlsx";
import { toNormalString, trimAll } from "../../../utility/string.util"; import { toNormalString, trimAll } from "../../../utility/string.util";
import { plainToInstance, Type } from "class-transformer"; import { plainToInstance, Type } from "class-transformer";
import * as objectHash from "object-hash";
import LessonTime from "../../entities/lesson-time.entity"; import LessonTime from "../../entities/lesson-time.entity";
import { LessonType } from "../../enum/lesson-type.enum"; import { LessonType } from "../../enum/lesson-type.enum";
import LessonSubGroup from "../../entities/lesson-sub-group.entity"; import LessonSubGroup from "../../entities/lesson-sub-group.entity";
@@ -25,6 +24,8 @@ import {
import { ClassProperties } from "../../../utility/class-trasformer/class-transformer-ctor"; import { ClassProperties } from "../../../utility/class-trasformer/class-transformer-ctor";
import { ToMap } from "create-map-transform-fn"; import { ToMap } from "create-map-transform-fn";
import * as objectHash from "object-hash";
type InternalId = { type InternalId = {
/** /**
* Индекс строки * Индекс строки
@@ -353,74 +354,56 @@ export class ScheduleParser {
private static convertGroupsToTeachers( private static convertGroupsToTeachers(
groups: Map<string, Group>, groups: Map<string, Group>,
): Map<string, Teacher> { ): Map<string, Teacher> {
const result = new Map<string, Teacher>(); const teachers = new Map<string, Teacher>();
for (const groupName of groups.keys()) { const days = (() => {
const group = groups.get(groupName); const group = groups.values().next().value as Group;
for (const day of group.days) { return group.days.map((day) => {
for (const lesson of day.lessons) { return new TeacherDay({
if (lesson.type !== LessonType.DEFAULT) continue;
for (const subGroup of lesson.subGroups) {
let teacherDto: Teacher = result.get(subGroup.teacher);
if (!teacherDto) {
teacherDto = new Teacher({
name: subGroup.teacher,
days: [],
});
result.set(subGroup.teacher, teacherDto);
}
let teacherDay = teacherDto.days[
day.name
] as TeacherDay;
if (!teacherDay) {
teacherDay = teacherDto.days[day.name] =
new TeacherDay({
name: day.name, name: day.name,
street: day.street,
date: day.date, date: day.date,
lessons: [], lessons: [],
}); });
} });
})();
const teacherLesson = structuredClone( const cloneDays = () => structuredClone(days);
lesson,
) as TeacherLesson;
teacherLesson.group = groupName;
teacherDay.lessons.push(teacherLesson); for (const group of groups.values()) {
} group.days.forEach((day, dayIndex) => {
} for (const groupLesson of day.lessons) {
} if (groupLesson.type !== LessonType.DEFAULT) continue;
}
for (const teacherName of result.keys()) { for (const subGroup of groupLesson.subGroups) {
const teacher = result.get(teacherName); if (!teachers.has(subGroup.teacher)) {
teachers.set(
const days = teacher.days; subGroup.teacher,
new Teacher({
// eslint-disable-next-line @typescript-eslint/no-for-in-array name: subGroup.teacher,
for (const dayName in days) { days: cloneDays(),
const day = days[dayName]; }),
// eslint-disable-next-line @typescript-eslint/no-array-delete
delete days[dayName];
day.lessons.sort(
(a, b) => a.time.start.valueOf() - b.time.start.valueOf(),
); );
days.push(day);
} }
days.sort((a, b) => a.date.valueOf() - b.date.valueOf()); const teacherDay = teachers.get(subGroup.teacher).days[
dayIndex
];
const lesson = structuredClone(
groupLesson,
) as TeacherLesson;
lesson.group = group.name;
teacherDay.lessons.push(lesson);
}
}
});
} }
return result; return teachers;
} }
/** /**