link 2 exam

This commit is contained in:
Primakov Alexandr Alexandrovich 2024-08-29 09:55:05 +03:00
parent a8195cd627
commit 5911cdf8a8
6 changed files with 137 additions and 21 deletions

View File

@ -21,9 +21,9 @@ export const api = createApi({
init?: RequestInit | undefined, init?: RequestInit | undefined,
) => { ) => {
const response = await fetch(input, init) const response = await fetch(input, init)
if (response.status === 403) keycloak.login() if (response.status === 403) keycloak.login()
return response return response
}, },
headers: { headers: {
@ -40,8 +40,8 @@ export const api = createApi({
providesTags: ['CourseList'], providesTags: ['CourseList'],
}), }),
createUpdateCourse: builder.mutation< createUpdateCourse: builder.mutation<
BaseResponse<Course>, BaseResponse<Course>,
Partial<Course> & Pick<Course, 'name'> Partial<Course> & Pick<Course, 'name'>
>({ >({
query: (course) => ({ query: (course) => ({
url: '/course', url: '/course',
@ -54,8 +54,8 @@ export const api = createApi({
query: (courseId) => `/course/students/${courseId}`, query: (courseId) => `/course/students/${courseId}`,
}), }),
manualAddStudent: builder.mutation< manualAddStudent: builder.mutation<
BaseResponse<void>, BaseResponse<void>,
{ lessonId: string; user: User } { lessonId: string; user: User }
>({ >({
query: ({ lessonId, user }) => ({ query: ({ lessonId, user }) => ({
url: `/lesson/add-student/${lessonId}`, url: `/lesson/add-student/${lessonId}`,
@ -63,14 +63,14 @@ export const api = createApi({
body: user, body: user,
}), }),
}), }),
lessonList: builder.query<BaseResponse<Lesson[]>, string>({ lessonList: builder.query<BaseResponse<Lesson[]>, string>({
query: (courseId) => `/lesson/list/${courseId}`, query: (courseId) => `/lesson/list/${courseId}`,
providesTags: ['LessonList'], providesTags: ['LessonList'],
}), }),
createLesson: builder.mutation< createLesson: builder.mutation<
BaseResponse<Lesson>, BaseResponse<Lesson>,
Partial<Lesson> & Pick<Lesson, 'name' | 'date'> & { courseId: string } Partial<Lesson> & Pick<Lesson, 'name' | 'date'> & { courseId: string }
>({ >({
query: (data) => ({ query: (data) => ({
url: '/lesson', url: '/lesson',
@ -97,10 +97,10 @@ export const api = createApi({
lessonById: builder.query<BaseResponse<Lesson>, string>({ lessonById: builder.query<BaseResponse<Lesson>, string>({
query: (lessonId: string) => `/lesson/${lessonId}`, query: (lessonId: string) => `/lesson/${lessonId}`,
}), }),
createAccessCode: builder.query< createAccessCode: builder.query<
BaseResponse<AccessCode>, BaseResponse<AccessCode>,
{ lessonId: string } { lessonId: string }
>({ >({
query: ({ lessonId }) => ({ query: ({ lessonId }) => ({
url: '/lesson/access-code', url: '/lesson/access-code',
@ -109,8 +109,8 @@ export const api = createApi({
}), }),
}), }),
getAccess: builder.query< getAccess: builder.query<
BaseResponse<{ user: UserData; accessCode: AccessCode }>, BaseResponse<{ user: UserData; accessCode: AccessCode }>,
{ accessCode: string } { accessCode: string }
>({ >({
query: ({ accessCode }) => ({ query: ({ accessCode }) => ({
url: `/lesson/access-code/${accessCode}`, url: `/lesson/access-code/${accessCode}`,
@ -126,6 +126,7 @@ export const api = createApi({
query: (courseId) => ({ query: (courseId) => ({
url: `/course/toggle-exam-with-jury/${courseId}`, url: `/course/toggle-exam-with-jury/${courseId}`,
method: 'POST', method: 'POST',
body: {},
}), }),
invalidatesTags: ['Course'] invalidatesTags: ['Course']
}) })

View File

@ -15,6 +15,7 @@ import { useAppSelector } from '../../__data__/store'
import { isTeacher } from '../../utils/user' import { isTeacher } from '../../utils/user'
import { PopulatedCourse } from '../../__data__/model' import { PopulatedCourse } from '../../__data__/model'
import { api } from '../../__data__/api/api' import { api } from '../../__data__/api/api'
import { LinkIcon } from '@chakra-ui/icons'
type CourseDetailsProps = { type CourseDetailsProps = {
populatedCourse: PopulatedCourse; populatedCourse: PopulatedCourse;
@ -28,7 +29,16 @@ export const CourseDetails = ({ populatedCourse }: CourseDetailsProps) => {
return ( return (
<> <>
<Heading as="h3" mt={4} mb={3} size="lg"> <Heading as="h3" mt={4} mb={3} size="lg">
Экзамен: Экзамен: {exam?.name} {exam && <Tooltip label="Начать экзамен" fontSize="12px" top="16px">
<Button
leftIcon={<LinkIcon />}
as={'a'}
colorScheme="blue"
href={`/exam/${populatedCourse.id}/${exam.id}`}
>
Открыть
</Button>
</Tooltip>}
</Heading> </Heading>
{!Boolean(exam) && ( {!Boolean(exam) && (
<> <>
@ -36,7 +46,7 @@ export const CourseDetails = ({ populatedCourse }: CourseDetailsProps) => {
Не задан Не задан
</Heading> </Heading>
<Box mt={10}> <Box mt={10}>
<Tooltip label="Детали" fontSize="12px" top="16px"> <Tooltip label="Создать экзамен с жюри" fontSize="12px" top="16px">
<Button <Button
colorScheme="blue" colorScheme="blue"
mt={["16px", 0]} mt={["16px", 0]}

View File

@ -190,7 +190,7 @@ export const CoursesList = () => {
<VStack as="ul" align="stretch"> <VStack as="ul" align="stretch">
{data?.body?.map((c) => ( {data?.body?.map((c) => (
<CourseCard <CourseCard
key={c._id} key={c.id}
course={c} course={c}
/> />
))} ))}

View File

@ -9,11 +9,22 @@ const timer =
router.use(timer()) router.use(timer())
const config = {
examCreated: false
}
router.get('/course/list', (req, res) => { router.get('/course/list', (req, res) => {
res.send(require('../mocks/courses/list/success.json')) res.send(require('../mocks/courses/list/success.json'))
}) })
router.get('/course/:id', (_req, res) => { router.get('/course/:id', (req, res) => {
if(req.params.id === 'undefined')
return res.status(400).send({ success: false, error: 'Invalid course id' })
if (config.examCreated) {
config.examCreated = false
return res.send(require('../mocks/courses/by-id/with-exam.json'))
}
res.send(require('../mocks/courses/by-id/success.json')) res.send(require('../mocks/courses/by-id/success.json'))
}) })
@ -26,6 +37,7 @@ router.post('/course', (req, res) => {
}) })
router.post('/course/toggle-exam-with-jury/:id', (req, res) => { router.post('/course/toggle-exam-with-jury/:id', (req, res) => {
config.examCreated = true;
res.send({ success: true }) res.send({ success: true })
}) })

View File

@ -0,0 +1,94 @@
{
"success": true,
"body": {
"_id": "660b19fc865d7a5d914636c0",
"name": "Курс по JS",
"teachers": [],
"lessons": [
{
"_id": "661e7f4f69f40b0ebebcd5e4",
"name": "555",
"students": [
{
"sub": "f62905b1-e223-40ca-910f-c8d84c6137c1",
"email_verified": true,
"name": "Александр Примаков",
"preferred_username": "primakov",
"given_name": "Александр",
"family_name": "Примаков",
"email": "primakovpro@gmail.com"
}
],
"date": "2024-04-16T13:38:00.000Z",
"created": "2024-04-16T13:38:23.381Z",
"id": "661e7f4f69f40b0ebebcd5e4"
},
{
"_id": "66af1e60a0eef5a89f99aa94",
"name": "111",
"students": [
{
"sub": "f62905b1-e223-40ca-910f-c8d84c6137c1",
"email_verified": true,
"name": "Александр Примаков",
"preferred_username": "primakov",
"given_name": "Александр",
"family_name": "Примаков",
"email": "primakovpro@gmail.com"
}
],
"date": "2024-08-04T07:00:00.000Z",
"created": "2024-08-04T06:23:28.491Z",
"id": "66af1e60a0eef5a89f99aa94"
},
{
"_id": "66ba1a01a0eef5a89f99ab27",
"name": "11111",
"students": [
{
"sub": "f62905b1-e223-40ca-910f-c8d84c6137c1",
"email_verified": true,
"name": "Александр Примаков",
"preferred_username": "primakov",
"given_name": "Александр",
"family_name": "Примаков",
"email": "primakovpro@gmail.com"
}
],
"date": "2024-08-18T10:00:00.000Z",
"created": "2024-08-12T14:19:46.004Z",
"id": "66ba1a01a0eef5a89f99ab27"
},
{
"_id": "66ba1a0da0eef5a89f99ab2d",
"name": "2222",
"students": [],
"date": "2024-08-18T14:19:00.000Z",
"created": "2024-08-12T14:19:57.798Z",
"id": "66ba1a0da0eef5a89f99ab2d"
}
],
"startDt": "2024-06-01T00:00:00.000Z",
"creator": {
"sub": "f62905b1-e223-40ca-910f-c8d84c6137c1",
"email_verified": true,
"name": "Александр Примаков",
"preferred_username": "primakov",
"given_name": "Александр",
"family_name": "Примаков",
"email": "primakovpro@gmail.com"
},
"created": "2024-04-01T20:33:00.912Z",
"examWithJury": {
"_id": "66d01766ce794e1fdb2bf097",
"name": "Хакатон",
"description": "Сегодня командам предстоит Защитить свои проекты а жюри оценить по критериям",
"jury": [],
"criterias": [],
"date": "2024-08-29T06:38:30.678Z",
"created": "2024-08-29T06:38:30.678Z",
"id": "66d01766ce794e1fdb2bf097"
},
"id": "660b19fc865d7a5d914636c0"
}
}

View File

@ -22,11 +22,10 @@
}, },
"startDt": "2024-03-02T15:37:05.907Z", "startDt": "2024-03-02T15:37:05.907Z",
"examWithJury": "66cf3d3f4637d420d6271451", "examWithJury": "66cf3d3f4637d420d6271451",
"created": "2024-03-02T15:37:05.908Z", "created": "2024-03-02T15:37:05.908Z"
"__v": 2
}, },
{ {
"_id": "65e73c21ced789d2f679128z", "id": "65e73c21ced789d2f679128z",
"name": "KFU-24-2", "name": "KFU-24-2",
"teachers": [], "teachers": [],
"lessons": [ "lessons": [