refactor: натравил форматтер на весь фронт

This commit is contained in:
2026-05-25 02:06:11 +03:00
parent 24df65a13c
commit 98aaa86ec4
43 changed files with 1947 additions and 657 deletions
+31 -8
View File
@@ -1,4 +1,12 @@
import type { Achievement, CoinTransaction, Lecture, Notification, Review, User, UserRole } from '@/types'
import type {
Achievement,
CoinTransaction,
Lecture,
Notification,
Review,
User,
UserRole,
} from '@/types'
import type {
AchievementDto,
CoinTransactionDto,
@@ -30,7 +38,10 @@ function getDefaultActiveRole(roles: UserRole[]): UserRole {
return 'student'
}
export function mapApiUser(user: UserAuthDto | UserDto | CurrentUserDto, stats?: UserStatsDto): User {
export function mapApiUser(
user: UserAuthDto | UserDto | CurrentUserDto,
stats?: UserStatsDto,
): User {
const roles = mapApiRoles(user.roles)
return {
id: user.id,
@@ -38,7 +49,7 @@ export function mapApiUser(user: UserAuthDto | UserDto | CurrentUserDto, stats?:
email: user.email || '',
roles,
activeRole: getDefaultActiveRole(roles),
avatar: 'avatarUrl' in user ? user.avatarUrl ?? undefined : undefined,
avatar: 'avatarUrl' in user ? (user.avatarUrl ?? undefined) : undefined,
institute: 'ЮФУ',
department: '',
year: 0,
@@ -50,7 +61,9 @@ export function mapApiUser(user: UserAuthDto | UserDto | CurrentUserDto, stats?:
nextLevelXp: stats?.nextLevelXp,
lecturesAttended: stats?.attendedLectures ?? 0,
hoursLearned: stats ? Math.round(stats.attendedLectures * 1.5 * 10) / 10 : 0,
achievements: stats ? Array.from({ length: stats.achievementsCount }, (_, index) => String(index + 1)) : [],
achievements: stats
? Array.from({ length: stats.achievementsCount }, (_, index) => String(index + 1))
: [],
activeEnrollments: stats?.activeEnrollments,
enrollmentSlotLimit: stats?.enrollmentSlotLimit,
enrollmentSlotRules: stats?.enrollmentSlotRules,
@@ -61,11 +74,13 @@ export function mapApiLecture(lecture: LectureDto): Lecture {
const startsAt = new Date(lecture.startsAt)
const endsAt = new Date(lecture.endsAt)
const durationMs = endsAt.getTime() - startsAt.getTime()
const duration = Number.isFinite(durationMs) && durationMs > 0 ? Math.round(durationMs / 60000) : 90
const duration =
Number.isFinite(durationMs) && durationMs > 0 ? Math.round(durationMs / 60000) : 90
const totalSeats = lecture.maxEnrollments || 0
const enrolled = lecture.enrollmentsCount || 0
const freeSeats = Math.max(totalSeats - enrolled, 0)
const locationName = lecture.locationName || (lecture.format === 'Online' ? 'Онлайн' : 'Аудитория уточняется')
const locationName =
lecture.locationName || (lecture.format === 'Online' ? 'Онлайн' : 'Аудитория уточняется')
return {
id: String(lecture.id),
@@ -96,9 +111,17 @@ export function mapApiLecture(lecture: LectureDto): Lecture {
export function mapApiReview(review: ReviewDto): Review {
const sentiment =
review.sentiment === 'Positive' ? 'positive' : review.sentiment === 'Negative' ? 'negative' : 'neutral'
review.sentiment === 'Positive'
? 'positive'
: review.sentiment === 'Negative'
? 'negative'
: 'neutral'
const status =
review.llmStatus === 'Rejected' ? 'rejected' : review.llmStatus === 'Analyzed' ? 'done' : 'pending'
review.llmStatus === 'Rejected'
? 'rejected'
: review.llmStatus === 'Analyzed'
? 'done'
: 'pending'
return {
id: String(review.id),