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:
@@ -312,6 +312,84 @@ router.delete('/challenge/chain/:id', (req, res) => {
|
||||
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 =============
|
||||
|
||||
// GET /api/challenge/stats
|
||||
|
||||
Reference in New Issue
Block a user