Add duplicate and clear submissions functionality for challenge chains; implement corresponding dialogs and API endpoints, enhancing user experience and task management. Update localization for new features in English and Russian.
This commit is contained in:
@@ -18,7 +18,7 @@ module.exports = {
|
|||||||
/* use https://admin.bro-js.ru/ to create config, navigations and features */
|
/* use https://admin.bro-js.ru/ to create config, navigations and features */
|
||||||
navigations: {
|
navigations: {
|
||||||
'challenge-admin.main': '/challenge-admin',
|
'challenge-admin.main': '/challenge-admin',
|
||||||
'link.challenge': '/challenge',
|
'link.challenge.main': '/challenge',
|
||||||
},
|
},
|
||||||
features: {
|
features: {
|
||||||
'challenge-admin': {
|
'challenge-admin': {
|
||||||
|
|||||||
@@ -112,6 +112,21 @@
|
|||||||
"challenge.admin.chains.delete.confirm.title": "Delete chain",
|
"challenge.admin.chains.delete.confirm.title": "Delete chain",
|
||||||
"challenge.admin.chains.delete.confirm.message": "Are you sure you want to delete chain \"{name}\"? This action cannot be undone.",
|
"challenge.admin.chains.delete.confirm.message": "Are you sure you want to delete chain \"{name}\"? This action cannot be undone.",
|
||||||
"challenge.admin.chains.delete.confirm.button": "Delete",
|
"challenge.admin.chains.delete.confirm.button": "Delete",
|
||||||
|
"challenge.admin.chains.duplicate.button": "Duplicate",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.title": "Duplicate chain",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.description": "Create a copy of chain \"{name}\" with the same tasks. The new chain will be created as inactive.",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name": "New chain name",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.placeholder": "Copy - {name}",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.helper": "Leave empty for auto-generated name",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.button.confirm": "Create copy",
|
||||||
|
"challenge.admin.chains.duplicate.success": "Chain successfully duplicated",
|
||||||
|
"challenge.admin.chains.duplicate.error": "Failed to duplicate chain",
|
||||||
|
"challenge.admin.chains.clear.submissions.button": "Clear submissions",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.title": "Clear chain submissions",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.message": "Are you sure you want to delete all submissions for chain \"{name}\"? This action is irreversible. All deleted submissions cannot be restored.",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.button.confirm": "Delete all submissions",
|
||||||
|
"challenge.admin.chains.clear.submissions.success": "Submissions successfully deleted",
|
||||||
|
"challenge.admin.chains.clear.submissions.error": "Failed to delete submissions",
|
||||||
"challenge.admin.dashboard.title": "Dashboard",
|
"challenge.admin.dashboard.title": "Dashboard",
|
||||||
"challenge.admin.dashboard.loading": "Loading statistics...",
|
"challenge.admin.dashboard.loading": "Loading statistics...",
|
||||||
"challenge.admin.dashboard.load.error": "Failed to load system statistics",
|
"challenge.admin.dashboard.load.error": "Failed to load system statistics",
|
||||||
|
|||||||
@@ -111,6 +111,21 @@
|
|||||||
"challenge.admin.chains.delete.confirm.title": "Удалить цепочку",
|
"challenge.admin.chains.delete.confirm.title": "Удалить цепочку",
|
||||||
"challenge.admin.chains.delete.confirm.message": "Вы уверены, что хотите удалить цепочку \"{name}\"? Это действие нельзя отменить.",
|
"challenge.admin.chains.delete.confirm.message": "Вы уверены, что хотите удалить цепочку \"{name}\"? Это действие нельзя отменить.",
|
||||||
"challenge.admin.chains.delete.confirm.button": "Удалить",
|
"challenge.admin.chains.delete.confirm.button": "Удалить",
|
||||||
|
"challenge.admin.chains.duplicate.button": "Дублировать",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.title": "Дублировать цепочку",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.description": "Создать копию цепочки \"{name}\" с теми же заданиями. Новая цепочка будет создана неактивной.",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name": "Название новой цепочки",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.placeholder": "Копия - {name}",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.helper": "Оставьте пустым для автоматического названия",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.button.confirm": "Создать копию",
|
||||||
|
"challenge.admin.chains.duplicate.success": "Цепочка успешно скопирована",
|
||||||
|
"challenge.admin.chains.duplicate.error": "Не удалось скопировать цепочку",
|
||||||
|
"challenge.admin.chains.clear.submissions.button": "Очистить попытки",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.title": "Очистить попытки по цепочке",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.message": "Вы уверены, что хотите удалить все попытки по цепочке \"{name}\"? Это действие необратимо. Все удаленные попытки невозможно восстановить.",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.button.confirm": "Удалить все попытки",
|
||||||
|
"challenge.admin.chains.clear.submissions.success": "Попытки успешно удалены",
|
||||||
|
"challenge.admin.chains.clear.submissions.error": "Не удалось удалить попытки",
|
||||||
"challenge.admin.dashboard.title": "Dashboard",
|
"challenge.admin.dashboard.title": "Dashboard",
|
||||||
"challenge.admin.dashboard.loading": "Загрузка статистики...",
|
"challenge.admin.dashboard.loading": "Загрузка статистики...",
|
||||||
"challenge.admin.dashboard.load.error": "Не удалось загрузить статистику системы",
|
"challenge.admin.dashboard.load.error": "Не удалось загрузить статистику системы",
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import type {
|
|||||||
UpdateTaskRequest,
|
UpdateTaskRequest,
|
||||||
CreateChainRequest,
|
CreateChainRequest,
|
||||||
UpdateChainRequest,
|
UpdateChainRequest,
|
||||||
|
DuplicateChainRequest,
|
||||||
|
ClearSubmissionsResponse,
|
||||||
SubmitRequest,
|
SubmitRequest,
|
||||||
TestSubmissionResult,
|
TestSubmissionResult,
|
||||||
ChainSubmissionsResponse,
|
ChainSubmissionsResponse,
|
||||||
@@ -115,6 +117,23 @@ export const api = createApi({
|
|||||||
}),
|
}),
|
||||||
invalidatesTags: ['Chain'],
|
invalidatesTags: ['Chain'],
|
||||||
}),
|
}),
|
||||||
|
duplicateChain: builder.mutation<ChallengeChain, { chainId: string; name?: string }>({
|
||||||
|
query: ({ chainId, name }) => ({
|
||||||
|
url: `/challenge/chain/${chainId}/duplicate`,
|
||||||
|
method: 'POST',
|
||||||
|
body: name ? { name } : {},
|
||||||
|
}),
|
||||||
|
transformResponse: (response: { body: ChallengeChain }) => response.body,
|
||||||
|
invalidatesTags: ['Chain'],
|
||||||
|
}),
|
||||||
|
clearChainSubmissions: builder.mutation<ClearSubmissionsResponse, string>({
|
||||||
|
query: (chainId) => ({
|
||||||
|
url: `/challenge/chain/${chainId}/submissions`,
|
||||||
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
transformResponse: (response: { body: ClearSubmissionsResponse }) => response.body,
|
||||||
|
invalidatesTags: ['Chain', 'Submission'],
|
||||||
|
}),
|
||||||
|
|
||||||
// Statistics
|
// Statistics
|
||||||
getSystemStats: builder.query<SystemStats, void>({
|
getSystemStats: builder.query<SystemStats, void>({
|
||||||
@@ -187,6 +206,8 @@ export const {
|
|||||||
useCreateChainMutation,
|
useCreateChainMutation,
|
||||||
useUpdateChainMutation,
|
useUpdateChainMutation,
|
||||||
useDeleteChainMutation,
|
useDeleteChainMutation,
|
||||||
|
useDuplicateChainMutation,
|
||||||
|
useClearChainSubmissionsMutation,
|
||||||
useGetSystemStatsQuery,
|
useGetSystemStatsQuery,
|
||||||
useGetSystemStatsV2Query,
|
useGetSystemStatsV2Query,
|
||||||
useGetUserStatsQuery,
|
useGetUserStatsQuery,
|
||||||
|
|||||||
77
src/components/ClearSubmissionsDialog.tsx
Normal file
77
src/components/ClearSubmissionsDialog.tsx
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
DialogRoot,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogBody,
|
||||||
|
DialogFooter,
|
||||||
|
DialogActionTrigger,
|
||||||
|
Button,
|
||||||
|
Text,
|
||||||
|
} from '@chakra-ui/react'
|
||||||
|
import { useClearChainSubmissionsMutation } from '../__data__/api/api'
|
||||||
|
import { toaster } from './ui/toaster'
|
||||||
|
import type { ChallengeChain } from '../types/challenge'
|
||||||
|
|
||||||
|
interface ClearSubmissionsDialogProps {
|
||||||
|
isOpen: boolean
|
||||||
|
onClose: () => void
|
||||||
|
chain: ChallengeChain | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ClearSubmissionsDialog: React.FC<ClearSubmissionsDialogProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
chain,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [clearSubmissions, { isLoading }] = useClearChainSubmissionsMutation()
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
if (!chain) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await clearSubmissions(chain.id).unwrap()
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.success'),
|
||||||
|
description: t('challenge.admin.chains.clear.submissions.success'),
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
onClose()
|
||||||
|
} catch (err) {
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.error'),
|
||||||
|
description: t('challenge.admin.chains.clear.submissions.error'),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chain) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogRoot open={isOpen} onOpenChange={(e) => !e.open && onClose()}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{t('challenge.admin.chains.clear.submissions.dialog.title')}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogBody>
|
||||||
|
<Text>{t('challenge.admin.chains.clear.submissions.dialog.message', { name: chain.name })}</Text>
|
||||||
|
</DialogBody>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogActionTrigger asChild>
|
||||||
|
<Button variant="outline" onClick={onClose} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.common.cancel')}
|
||||||
|
</Button>
|
||||||
|
</DialogActionTrigger>
|
||||||
|
<Button colorPalette="red" onClick={handleConfirm} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.chains.clear.submissions.dialog.button.confirm')}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</DialogRoot>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
106
src/components/DuplicateChainDialog.tsx
Normal file
106
src/components/DuplicateChainDialog.tsx
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import React, { useState } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
DialogRoot,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogBody,
|
||||||
|
DialogFooter,
|
||||||
|
DialogActionTrigger,
|
||||||
|
Button,
|
||||||
|
Field,
|
||||||
|
Input,
|
||||||
|
Text,
|
||||||
|
VStack,
|
||||||
|
} from '@chakra-ui/react'
|
||||||
|
import { useDuplicateChainMutation } from '../__data__/api/api'
|
||||||
|
import { toaster } from './ui/toaster'
|
||||||
|
import type { ChallengeChain } from '../types/challenge'
|
||||||
|
|
||||||
|
interface DuplicateChainDialogProps {
|
||||||
|
isOpen: boolean
|
||||||
|
onClose: () => void
|
||||||
|
chain: ChallengeChain | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DuplicateChainDialog: React.FC<DuplicateChainDialogProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
chain,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [name, setName] = useState('')
|
||||||
|
const [duplicateChain, { isLoading }] = useDuplicateChainMutation()
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setName('')
|
||||||
|
onClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
if (!chain) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await duplicateChain({
|
||||||
|
chainId: chain.id,
|
||||||
|
name: name.trim() || undefined,
|
||||||
|
}).unwrap()
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.success'),
|
||||||
|
description: t('challenge.admin.chains.duplicate.success'),
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
handleClose()
|
||||||
|
} catch (err) {
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.error'),
|
||||||
|
description: t('challenge.admin.chains.duplicate.error'),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chain) return null
|
||||||
|
|
||||||
|
const defaultPlaceholder = t('challenge.admin.chains.duplicate.dialog.field.name.placeholder', {
|
||||||
|
name: chain.name,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogRoot open={isOpen} onOpenChange={(e) => !e.open && handleClose()}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{t('challenge.admin.chains.duplicate.dialog.title')}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogBody>
|
||||||
|
<VStack gap={4} align="stretch">
|
||||||
|
<Text>{t('challenge.admin.chains.duplicate.dialog.description', { name: chain.name })}</Text>
|
||||||
|
<Field.Root>
|
||||||
|
<Field.Label>{t('challenge.admin.chains.duplicate.dialog.field.name')}</Field.Label>
|
||||||
|
<Input
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
placeholder={defaultPlaceholder}
|
||||||
|
/>
|
||||||
|
<Field.HelperText>
|
||||||
|
{t('challenge.admin.chains.duplicate.dialog.field.name.helper')}
|
||||||
|
</Field.HelperText>
|
||||||
|
</Field.Root>
|
||||||
|
</VStack>
|
||||||
|
</DialogBody>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogActionTrigger asChild>
|
||||||
|
<Button variant="outline" onClick={handleClose} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.common.cancel')}
|
||||||
|
</Button>
|
||||||
|
</DialogActionTrigger>
|
||||||
|
<Button colorPalette="teal" onClick={handleConfirm} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.chains.duplicate.dialog.button.confirm')}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</DialogRoot>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@ import { LoadingSpinner } from '../../components/LoadingSpinner'
|
|||||||
import { ErrorAlert } from '../../components/ErrorAlert'
|
import { ErrorAlert } from '../../components/ErrorAlert'
|
||||||
import { EmptyState } from '../../components/EmptyState'
|
import { EmptyState } from '../../components/EmptyState'
|
||||||
import { ConfirmDialog } from '../../components/ConfirmDialog'
|
import { ConfirmDialog } from '../../components/ConfirmDialog'
|
||||||
|
import { DuplicateChainDialog } from '../../components/DuplicateChainDialog'
|
||||||
|
import { ClearSubmissionsDialog } from '../../components/ClearSubmissionsDialog'
|
||||||
import type { ChallengeChain } from '../../types/challenge'
|
import type { ChallengeChain } from '../../types/challenge'
|
||||||
import { toaster } from '../../components/ui/toaster'
|
import { toaster } from '../../components/ui/toaster'
|
||||||
|
|
||||||
@@ -29,6 +31,8 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
|
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [chainToDelete, setChainToDelete] = useState<ChallengeChain | null>(null)
|
const [chainToDelete, setChainToDelete] = useState<ChallengeChain | null>(null)
|
||||||
|
const [chainToDuplicate, setChainToDuplicate] = useState<ChallengeChain | null>(null)
|
||||||
|
const [chainToClearSubmissions, setChainToClearSubmissions] = useState<ChallengeChain | null>(null)
|
||||||
const [updatingChainId, setUpdatingChainId] = useState<string | null>(null)
|
const [updatingChainId, setUpdatingChainId] = useState<string | null>(null)
|
||||||
const [updateChain] = useUpdateChainMutation()
|
const [updateChain] = useUpdateChainMutation()
|
||||||
|
|
||||||
@@ -182,6 +186,21 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
>
|
>
|
||||||
{t('challenge.admin.chains.list.button.edit')}
|
{t('challenge.admin.chains.list.button.edit')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => setChainToDuplicate(chain)}
|
||||||
|
>
|
||||||
|
{t('challenge.admin.chains.duplicate.button')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
colorPalette="red"
|
||||||
|
onClick={() => setChainToClearSubmissions(chain)}
|
||||||
|
>
|
||||||
|
{t('challenge.admin.chains.clear.submissions.button')}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -208,6 +227,18 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
confirmLabel={t('challenge.admin.chains.delete.confirm.button')}
|
confirmLabel={t('challenge.admin.chains.delete.confirm.button')}
|
||||||
isLoading={isDeleting}
|
isLoading={isDeleting}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<DuplicateChainDialog
|
||||||
|
isOpen={!!chainToDuplicate}
|
||||||
|
onClose={() => setChainToDuplicate(null)}
|
||||||
|
chain={chainToDuplicate}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ClearSubmissionsDialog
|
||||||
|
isOpen={!!chainToClearSubmissions}
|
||||||
|
onClose={() => setChainToClearSubmissions(null)}
|
||||||
|
chain={chainToClearSubmissions}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,16 @@ export interface UpdateChainRequest {
|
|||||||
isActive?: boolean
|
isActive?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DuplicateChainRequest {
|
||||||
|
name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ClearSubmissionsResponse {
|
||||||
|
deletedCount: number
|
||||||
|
chainId: string
|
||||||
|
userId?: string
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Stats v2 Types ==========
|
// ========== Stats v2 Types ==========
|
||||||
|
|
||||||
export type TaskProgressStatus = 'not_started' | 'pending' | 'in_progress' | 'needs_revision' | 'completed'
|
export type TaskProgressStatus = 'not_started' | 'pending' | 'in_progress' | 'needs_revision' | 'completed'
|
||||||
|
|||||||
@@ -312,6 +312,84 @@ router.delete('/challenge/chain/:id', (req, res) => {
|
|||||||
respond(res, { success: true });
|
respond(res, { success: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /api/challenge/chain/:chainId/duplicate
|
||||||
|
router.post('/challenge/chain/:chainId/duplicate', (req, res) => {
|
||||||
|
const chains = getChains();
|
||||||
|
const chainIndex = chains.findIndex(c => c.id === req.params.chainId);
|
||||||
|
|
||||||
|
if (chainIndex === -1) {
|
||||||
|
return respondError(res, 'Chain not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalChain = chains[chainIndex];
|
||||||
|
const { name } = req.body;
|
||||||
|
|
||||||
|
// Generate new name if not provided
|
||||||
|
const newName = name || `Копия - ${originalChain.name}`;
|
||||||
|
|
||||||
|
// Create duplicate with same tasks but inactive
|
||||||
|
const duplicatedChain = {
|
||||||
|
_id: `chain_${Date.now()}`,
|
||||||
|
id: `chain_${Date.now()}`,
|
||||||
|
name: newName,
|
||||||
|
tasks: originalChain.tasks.map(task => ({
|
||||||
|
_id: task._id,
|
||||||
|
id: task.id,
|
||||||
|
title: task.title,
|
||||||
|
description: task.description,
|
||||||
|
createdAt: task.createdAt,
|
||||||
|
updatedAt: task.updatedAt
|
||||||
|
})),
|
||||||
|
isActive: false,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
updatedAt: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
chains.push(duplicatedChain);
|
||||||
|
|
||||||
|
// Update stats
|
||||||
|
const stats = getStats();
|
||||||
|
stats.chains = chains.length;
|
||||||
|
|
||||||
|
respond(res, duplicatedChain);
|
||||||
|
});
|
||||||
|
|
||||||
|
// DELETE /api/challenge/chain/:chainId/submissions
|
||||||
|
router.delete('/challenge/chain/:chainId/submissions', (req, res) => {
|
||||||
|
const chains = getChains();
|
||||||
|
const submissions = getSubmissions();
|
||||||
|
|
||||||
|
const chain = chains.find(c => c.id === req.params.chainId);
|
||||||
|
|
||||||
|
if (!chain) {
|
||||||
|
return respondError(res, 'Chain not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get task IDs from chain
|
||||||
|
const taskIds = new Set(chain.tasks.map(t => t.id));
|
||||||
|
|
||||||
|
// Count and remove submissions for tasks in this chain
|
||||||
|
let deletedCount = 0;
|
||||||
|
for (let i = submissions.length - 1; i >= 0; i--) {
|
||||||
|
const sub = submissions[i];
|
||||||
|
const taskId = typeof sub.task === 'object' ? sub.task.id : sub.task;
|
||||||
|
|
||||||
|
if (taskIds.has(taskId)) {
|
||||||
|
submissions.splice(i, 1);
|
||||||
|
deletedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update stats
|
||||||
|
const stats = getStats();
|
||||||
|
stats.submissions.total = Math.max(0, stats.submissions.total - deletedCount);
|
||||||
|
|
||||||
|
respond(res, {
|
||||||
|
deletedCount: deletedCount,
|
||||||
|
chainId: chain.id
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ============= STATS =============
|
// ============= STATS =============
|
||||||
|
|
||||||
// GET /api/challenge/stats
|
// GET /api/challenge/stats
|
||||||
|
|||||||
Reference in New Issue
Block a user