Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 01.11.2024 #412

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const app = new Elysia()
.use(routes)
.listen(port)

sequelize.sync()
await sequelize.sync()

console.log(
`Backend running at http://${app.server?.hostname}:${app.server?.port}`
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/models/Task/actions/save/tasksSaveOrGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const tasksSaveOrGet = async (
scheduleId,
topic: task?.topic ?? 'Не указано',
idFromDiary: task.id,
condition: task.condition ?? null,
taskTypeId
}
const promise = TaskModel.findOrCreate({
Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/models/Task/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type TaskModelType = {
scheduleId: bigint
taskTypeId: number
topic: string
condition: string | null
idFromDiary: number
}

Expand Down Expand Up @@ -43,6 +44,10 @@ export const TaskModel = sequelize.define<ITaskModel>('task', {
type: DataTypes.TEXT,
allowNull: false
},
condition: {
type: DataTypes.TEXT,
allowNull: true
},
idFromDiary: {
type: DataTypes.INTEGER,
allowNull: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ export const getFormattedGradebook = (
const lessonType = rd.lessonType.name
// Подготавливаем таски
const tasks: Task[] = rd.tasks?.map((t) => {
const { idFromDiary: id, topic } = t
const { idFromDiary: id, topic, condition } = t
const type = t.taskType.name
const isRequired = t.requireds?.[0].isRequired ?? false
const mark = t.marks?.[0].markValue.value ?? undefined
const mark = t.marks?.[0]?.markValue?.value ?? undefined
return {
id,
topic,
condition,
type,
isRequired,
mark,
Expand Down
39 changes: 37 additions & 2 deletions apps/api/src/utils/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
import ky from 'ky'
import ky, { type Input, type KyResponse, type Options } from 'ky'

export const fetcher = ky.extend({
const defaultKy = ky.extend({
timeout: 10000, // 10 seconds
retry: 2
})

const localFetcher = async (
method: 'GET' | 'POST',
url: Input,
options?: Options
) => {
let result: KyResponse | null = null

try {
switch (method) {
case 'GET':
result = await defaultKy.get(url, options)
break
case 'POST':
result = await defaultKy.post(url, options)
break
}
} catch {}

return {
ok: result ? result.ok : false,
status: result ? result.status : 0,
headers: result ? result.headers : ({} as Headers),
json: async <T>() => (result as KyResponse).json<T>()
}
}

export const fetcher = {
get: async (url: Input, options: Options) => {
return localFetcher('GET', url, options)
},
post: async (url: Input, options: Options) => {
return localFetcher('POST', url, options)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const updateUserCookie = async (

// 1. Авторизируемся
const rawResponse = await ky.post(`${SERVER_URL}/services/security/login`, {
body: JSON.stringify({
json: {
login: user.login,
password: user.password,
isRemember: true
})
}
})

// Если дневник вернул что-то другое...
Expand Down
19 changes: 17 additions & 2 deletions apps/shared/src/api/original/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,30 @@ export const AbsenceTypes: Record<
> = {
IsAbsent: 'Н',
IsLate: 'О',
IsAbsentByNotValidReason: 'НП'
IsAbsentByNotValidReason: 'НП',
SickLeave: 'Б',
IsAbsentByValidReason: 'УП'
}

export const AbsenceTypesColors: Record<AbsenceTypesKeys, ColorKeys> = {
IsAbsent: 'red',
IsLate: 'yellow',
IsAbsentByNotValidReason: 'red',
SickLeave: 'blue',
IsAbsentByValidReason: 'blue'
}

export type ColorKeys = 'red' | 'yellow' | 'blue'

export const AbsenceTypesDescription: Record<
AbsenceTypesDescriptionKeys,
string
> = {
Н: 'Отсутствие',
О: 'Опоздание',
НП: 'Неуважительное причина'
НП: 'Неуважительное причина',
УП: 'Уважительная причина',
Б: 'Пропуск по болезни'
}

export type TMark = MarkKeys
Expand All @@ -204,6 +218,7 @@ export interface Task {
isRequired: boolean
mark: MarkKeys
topic?: string
condition: string | null
type: TLesson
}

Expand Down
4 changes: 3 additions & 1 deletion apps/shared/src/api/original/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export type AbsenceTypesKeys =
| 'IsAbsent'
| 'IsLate'
| 'IsAbsentByNotValidReason'
| 'IsAbsentByValidReason'
| 'SickLeave'

export type AbsenceTypesDescriptionKeys = 'Н' | 'О' | 'НП'
export type AbsenceTypesDescriptionKeys = 'Н' | 'О' | 'НП' | 'УП' | 'Б'
export type AdditionalMarks = 'Д' | 'Зч'
export type ExaminationKeys = 'DifferentiatedTest' | 'Test' | 'Exam' | 'Other'
export type TermSubjectExaminationKeys =
Expand Down
14 changes: 7 additions & 7 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@elysiajs/eden": "1.1.3",
"@vkontakte/icons": "2.137.0",
"@vkontakte/vk-bridge": "^2.15.0",
"@vkontakte/vk-bridge": "^2.15.2",
"@vkontakte/vk-bridge-react": "^1.0.1",
"@vkontakte/vk-mini-apps-router": "1.4.6",
"@vkontakte/vkui": "6.6.0",
Expand All @@ -28,15 +28,15 @@
},
"devDependencies": {
"@diary-spo/shared": "workspace:*",
"@happy-dom/global-registrator": "^15.7.3",
"@rsbuild/core": "^1.0.1-rc.5",
"@rsbuild/plugin-react": "^1.0.1-rc.5",
"@happy-dom/global-registrator": "^15.7.4",
"@rsbuild/core": "^1.0.18",
"@rsbuild/plugin-react": "^1.0.5",
"@types/jsdom": "^21.1.7",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vkontakte/vk-miniapps-deploy": "^0.1.8",
"elysia": "1.1.12",
"gh-pages": "^6.1.1"
"gh-pages": "^6.2.0"
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ const Task: FC<Props> = ({ task, index }) => (
<Fragment key={`${task?.topic}_${index}`}>
<SimpleCell multiline after={<Mark mark={setDefaultMark(task)} size='s' />}>
<InfoRow header='Тип работы'>{LessonWorkType[task.type]}</InfoRow>
<InfoRow style={{ marginTop: 10 }} header='Описание'>
</SimpleCell>

<SimpleCell multiline>
<InfoRow style={{ marginTop: 10 }} header='Тема'>
<Text>{task?.topic}</Text>
</InfoRow>
{task?.condition && (
<InfoRow style={{ marginTop: 10 }} header='Описание'>
<Text>{task?.condition}</Text>
</InfoRow>
)}
</SimpleCell>

<Spacing size={16}>
Expand Down
11 changes: 7 additions & 4 deletions apps/web/src/pages/Schedule/ui/LessonSubtitle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { AbsenceTypes, type Gradebook, LessonType } from '@diary-spo/shared'
import {
AbsenceTypes,
AbsenceTypesColors,
type Gradebook,
LessonType
} from '@diary-spo/shared'
import type { FC } from 'react'

import { isDistant } from '../../../../shared'
Expand Down Expand Up @@ -34,9 +39,7 @@ const LessonSubtitle: FC<ILessonSubtitle> = ({
</SubtitleWithBorder>
)}
{gradebook?.absenceType && (
<SubtitleWithBorder
color={gradebook.absenceType === 'IsLate' ? 'yellow' : 'red'}
>
<SubtitleWithBorder color={AbsenceTypesColors[gradebook?.absenceType]}>
{AbsenceTypes[gradebook?.absenceType]}
</SubtitleWithBorder>
)}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/shared/config/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const VKUI_VIOLET = 'var(--vkui--color_accent_violet)'
export const GREEN = 'linear-gradient(to right, #56ab2f, #a8e063)'
export const RED = 'linear-gradient(to right, #ff416c, #ff4b2b)'
export const ORANGE = 'linear-gradient(to right, #e56d1f, #f5af19)'
export const BLUE = 'linear-gradient(to right, #62cff4, #2c67f2)'
export const VIOLET =
'linear-gradient(to right, rgb(73, 102, 207), rgb(154 80 255))'
export const GRAY = '#959595'
6 changes: 5 additions & 1 deletion apps/web/src/shared/ui/Mark/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Nullable } from '@diary-spo/shared'
import { GRAY, GREEN, ORANGE, RED, VIOLET } from '../../config'
import { BLUE, GRAY, GREEN, ORANGE, RED, VIOLET } from '../../config'
import type { ReturnedMark } from '../../types.ts'

export type Sizes = 'l' | 's'
Expand Down Expand Up @@ -39,7 +39,11 @@ export const getBackgroundColor = (score?: Nullable<ReturnedMark>): string => {
return ORANGE
case 'Н':
case 'Д':
case 'НП':
return RED
case 'Б':
case 'УП':
return BLUE
default:
return GRAY
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/shared/ui/SubtitleWithBorder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type SubtitleColors =
| 'red'
| 'green'
| 'yellow'
| 'blue'
| 'red-outline'
| 'green-outline'
| 'yellow-outline'
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/shared/ui/SubtitleWithBorder/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GREEN, ORANGE, RED } from '../../config'
import { BLUE, GREEN, ORANGE, RED } from '../../config'

export const colors = {
red: {
Expand Down Expand Up @@ -31,6 +31,12 @@ export const colors = {
borderRadius: '5px',
border: '1px solid #ffb060',
color: 'white'
},
blue: {
background: BLUE,
borderRadius: '5px',
border: '1px solid #2c67f2',
color: 'white'
}
}

Expand Down
Loading