mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 17:57:45 +03:00
Refactor and reorganize codebase for better maintainability and clarity
- Rename DTOs to entities and move them to appropriate directories - Remove deprecated controllers and services - Update imports and dependencies - Implement new class transformer decorators for better serialization - Add VK authentication support - Improve error handling and validation - Update ESLint configuration and TypeScript settings - Refactor schedule parsing logic - Enhance user and authentication services - Update Prisma schema and related entities - Improve code organization and structure This commit introduces significant changes to improve the overall structure and maintainability of the codebase, including better organization of DTOs, enhanced authentication features, and updated tooling configurations.
This commit is contained in:
42
src/schedule/entities/day.entity.ts
Normal file
42
src/schedule/entities/day.entity.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
IsArray,
|
||||
IsDateString,
|
||||
IsOptional,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import Lesson from "./lesson.entity";
|
||||
|
||||
// noinspection JSClassNamingConvention
|
||||
export default class Day {
|
||||
/**
|
||||
* День недели
|
||||
* @example "Понедельник"
|
||||
*/
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Улица (v2)
|
||||
* @example "Железнодорожная, 13"
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
street?: string;
|
||||
|
||||
/**
|
||||
* Дата
|
||||
* @example "2024-10-06T20:00:00.000Z"
|
||||
*/
|
||||
@IsDateString()
|
||||
date: Date;
|
||||
|
||||
/**
|
||||
* Занятия
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Lesson)
|
||||
lessons: Array<Lesson>;
|
||||
}
|
||||
23
src/schedule/entities/group-schedule.entity.ts
Normal file
23
src/schedule/entities/group-schedule.entity.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { PickType } from "@nestjs/swagger";
|
||||
import { IsArray, IsObject, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import Schedule from "./schedule.entity";
|
||||
import Group from "./group.entity";
|
||||
|
||||
export default class GroupSchedule extends PickType(Schedule, ["updatedAt"]) {
|
||||
/**
|
||||
* Расписание группы
|
||||
*/
|
||||
@IsObject()
|
||||
@Type(() => Group)
|
||||
group: Group;
|
||||
|
||||
/**
|
||||
* Обновлённые дни с последнего изменения расписания
|
||||
* @example [5, 6]
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Number)
|
||||
updated: Array<number>;
|
||||
}
|
||||
20
src/schedule/entities/group.entity.ts
Normal file
20
src/schedule/entities/group.entity.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { IsArray, IsString, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import Day from "./day.entity";
|
||||
|
||||
export default class Group {
|
||||
/**
|
||||
* Название группы
|
||||
* @example "ИС-214/23"
|
||||
*/
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Расписание каждого дня
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Day)
|
||||
days: Array<Day>;
|
||||
}
|
||||
31
src/schedule/entities/lesson-sub-group.entity.ts
Normal file
31
src/schedule/entities/lesson-sub-group.entity.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { IsNumber, IsOptional, IsString } from "class-validator";
|
||||
import {
|
||||
ClassTransformerCtor,
|
||||
Ctor,
|
||||
} from "../../utility/class-trasformer/class-transformer-ctor";
|
||||
|
||||
@ClassTransformerCtor()
|
||||
export default class LessonSubGroup extends Ctor<LessonSubGroup> {
|
||||
/**
|
||||
* Номер подгруппы
|
||||
* @example 1
|
||||
*/
|
||||
@IsNumber()
|
||||
number: number;
|
||||
|
||||
/**
|
||||
* Кабинет
|
||||
* @example "с\з"
|
||||
* @example "42"
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
cabinet: string | null;
|
||||
|
||||
/**
|
||||
* ФИО преподавателя
|
||||
* @example "Хомченко Н. Е."
|
||||
*/
|
||||
@IsString()
|
||||
teacher: string;
|
||||
}
|
||||
22
src/schedule/entities/lesson-time.entity.ts
Normal file
22
src/schedule/entities/lesson-time.entity.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { IsDateString } from "class-validator";
|
||||
import {
|
||||
ClassTransformerCtor,
|
||||
Ctor,
|
||||
} from "../../utility/class-trasformer/class-transformer-ctor";
|
||||
|
||||
@ClassTransformerCtor()
|
||||
export default class LessonTime extends Ctor<LessonTime> {
|
||||
/**
|
||||
* Начало занятия
|
||||
* @example "2024-10-07T04:30:00.000Z"
|
||||
*/
|
||||
@IsDateString()
|
||||
start: Date;
|
||||
|
||||
/**
|
||||
* Конец занятия
|
||||
* @example "2024-10-07T04:40:00.000Z"
|
||||
*/
|
||||
@IsDateString()
|
||||
end: Date;
|
||||
}
|
||||
72
src/schedule/entities/lesson.entity.ts
Normal file
72
src/schedule/entities/lesson.entity.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import "reflect-metadata";
|
||||
|
||||
import { LessonType } from "../enum/lesson-type.enum";
|
||||
import {
|
||||
IsArray,
|
||||
IsEnum,
|
||||
IsOptional,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import { NullIf } from "../../utility/class-validators/conditional-field";
|
||||
import LessonTime from "./lesson-time.entity";
|
||||
import LessonSubGroup from "./lesson-sub-group.entity";
|
||||
import {
|
||||
ClassTransformerCtor,
|
||||
Ctor,
|
||||
} from "../../utility/class-trasformer/class-transformer-ctor";
|
||||
|
||||
@ClassTransformerCtor()
|
||||
export default class Lesson extends Ctor<Lesson> {
|
||||
/**
|
||||
* Тип занятия
|
||||
* @example DEFAULT
|
||||
*/
|
||||
@IsEnum(LessonType)
|
||||
type: LessonType;
|
||||
|
||||
/**
|
||||
* Индексы пар, если присутствуют
|
||||
* @example [1, 3]
|
||||
* @optional
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Number)
|
||||
@IsOptional()
|
||||
@NullIf((self: Lesson) => {
|
||||
return self.type !== LessonType.DEFAULT;
|
||||
})
|
||||
defaultRange: Array<number> | null;
|
||||
|
||||
/**
|
||||
* Название занятия
|
||||
* @example "Элементы высшей математики"
|
||||
* @optional
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@NullIf((self: Lesson) => {
|
||||
return self.type === LessonType.BREAK;
|
||||
})
|
||||
name: string | null;
|
||||
|
||||
/**
|
||||
* Начало и конец занятия
|
||||
*/
|
||||
@Type(() => LessonTime)
|
||||
time: LessonTime;
|
||||
|
||||
/**
|
||||
* Тип занятия
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => LessonSubGroup)
|
||||
@IsOptional()
|
||||
@NullIf((self: Lesson) => {
|
||||
return self.type !== LessonType.DEFAULT;
|
||||
})
|
||||
subGroups: Array<LessonSubGroup> | null;
|
||||
}
|
||||
28
src/schedule/entities/schedule.entity.ts
Normal file
28
src/schedule/entities/schedule.entity.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { IsArray, IsDate, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import Group from "./group.entity";
|
||||
import { ToMap } from "create-map-transform-fn";
|
||||
|
||||
export default class Schedule {
|
||||
/**
|
||||
* Дата когда последний раз расписание было скачано с сервера политехникума
|
||||
* @example "2024-10-18T21:50:06.680Z"
|
||||
*/
|
||||
@IsDate()
|
||||
updatedAt: Date;
|
||||
|
||||
/**
|
||||
* Расписание групп
|
||||
*/
|
||||
@ToMap({ mapValueClass: Group })
|
||||
groups: Map<string, Group>;
|
||||
|
||||
/**
|
||||
* Обновлённые дни с последнего изменения расписания
|
||||
* @example { "ИС-214/23": [4, 5] }
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Array<number>)
|
||||
updatedGroups: Array<Array<number>>;
|
||||
}
|
||||
46
src/schedule/entities/teacher-day.entity.ts
Normal file
46
src/schedule/entities/teacher-day.entity.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {
|
||||
IsArray,
|
||||
IsDateString,
|
||||
IsOptional,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import TeacherLesson from "./teacher-lesson.entity";
|
||||
import {
|
||||
ClassTransformerCtor,
|
||||
Ctor,
|
||||
} from "../../utility/class-trasformer/class-transformer-ctor";
|
||||
|
||||
@ClassTransformerCtor()
|
||||
export default class TeacherDay extends Ctor<TeacherDay> {
|
||||
/**
|
||||
* День недели
|
||||
* @example "Понедельник"
|
||||
*/
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Улица (v2)
|
||||
* @example "Железнодорожная, 13"
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
street?: string;
|
||||
|
||||
/**
|
||||
* Дата
|
||||
* @example "2024-10-06T20:00:00.000Z"
|
||||
*/
|
||||
@IsDateString()
|
||||
date: Date;
|
||||
|
||||
/**
|
||||
* Занятия
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => TeacherLesson)
|
||||
lessons: Array<TeacherLesson>;
|
||||
}
|
||||
18
src/schedule/entities/teacher-lesson.entity.ts
Normal file
18
src/schedule/entities/teacher-lesson.entity.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import Lesson from "./lesson.entity";
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
import { NullIf } from "../../utility/class-validators/conditional-field";
|
||||
import { LessonType } from "../enum/lesson-type.enum";
|
||||
|
||||
export default class TeacherLesson extends Lesson {
|
||||
/**
|
||||
* Название группы
|
||||
* @example "ИС-214/23"
|
||||
* @optional
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@NullIf((self: TeacherLesson) => {
|
||||
return self.type === LessonType.BREAK;
|
||||
})
|
||||
group: string | null;
|
||||
}
|
||||
22
src/schedule/entities/teacher-schedule.entity.ts
Normal file
22
src/schedule/entities/teacher-schedule.entity.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { PickType } from "@nestjs/swagger";
|
||||
import Schedule from "./schedule.entity";
|
||||
import { IsArray, IsObject, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import Teacher from "./teacher.entity";
|
||||
|
||||
export default class TeacherSchedule extends PickType(Schedule, ["updatedAt"]) {
|
||||
/**
|
||||
* Расписание преподавателя
|
||||
*/
|
||||
@IsObject()
|
||||
teacher: Teacher;
|
||||
|
||||
/**
|
||||
* Обновлённые дни с последнего изменения расписания
|
||||
* @example [5, 6]
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Number)
|
||||
updated: Array<number>;
|
||||
}
|
||||
25
src/schedule/entities/teacher.entity.ts
Normal file
25
src/schedule/entities/teacher.entity.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { IsArray, IsString, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
import TeacherDay from "./teacher-day.entity";
|
||||
import {
|
||||
ClassTransformerCtor,
|
||||
Ctor,
|
||||
} from "../../utility/class-trasformer/class-transformer-ctor";
|
||||
|
||||
@ClassTransformerCtor()
|
||||
export default class Teacher extends Ctor<Teacher> {
|
||||
/**
|
||||
* ФИО преподавателя
|
||||
* @example "Хомченко Н.Е."
|
||||
*/
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Расписание каждого дня
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => TeacherDay)
|
||||
days: Array<TeacherDay>;
|
||||
}
|
||||
Reference in New Issue
Block a user