feat: redesign detail page with stage modal and milestone APIs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,15 +16,26 @@ router.post('/upload/:taskId', upload.single('file'), async (req, res, next) =>
|
||||
const task = await prisma.task.findUnique({ where: { id: taskId } });
|
||||
if (!task) throw new AppError(404, '업무를 찾을 수 없습니다.');
|
||||
|
||||
const body = req.body as Record<string, string>;
|
||||
const milestoneId = body.milestoneId?.trim() || null;
|
||||
|
||||
if (milestoneId) {
|
||||
const milestone = await prisma.milestone.findFirst({
|
||||
where: { id: milestoneId, taskId },
|
||||
});
|
||||
if (!milestone) throw new AppError(404, '단계를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
const fileRecord = await prisma.file.create({
|
||||
data: {
|
||||
taskId,
|
||||
milestoneId,
|
||||
filename: req.file.filename,
|
||||
originalName: req.file.originalname,
|
||||
mimetype: req.file.mimetype,
|
||||
size: req.file.size,
|
||||
path: req.file.path,
|
||||
uploadedBy: (req.body as Record<string, string>).uploadedBy ?? 'system',
|
||||
uploadedBy: body.uploadedBy ?? 'system',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,29 @@ import { AppError } from '../middleware/errorHandler';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET /api/milestones/:taskId — 업무의 마일스톤 목록
|
||||
async function resolveUpdatedBy(taskId: string): Promise<string> {
|
||||
const task = await prisma.task.findUnique({ where: { id: taskId }, select: { creatorId: true } });
|
||||
if (task?.creatorId) return task.creatorId;
|
||||
const admin = await prisma.user.findFirst({ where: { role: 'ADMIN' }, select: { id: true } });
|
||||
if (!admin) throw new AppError(500, '피드백 작성자를 찾을 수 없습니다.');
|
||||
return admin.id;
|
||||
}
|
||||
|
||||
function normalizeLinks(links: unknown): string | null {
|
||||
if (!links) return null;
|
||||
if (typeof links === 'string') {
|
||||
try {
|
||||
JSON.parse(links);
|
||||
return links;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (Array.isArray(links)) return JSON.stringify(links);
|
||||
return null;
|
||||
}
|
||||
|
||||
// GET /api/milestones/:taskId
|
||||
router.get('/:taskId', async (req, res, next) => {
|
||||
try {
|
||||
const milestones = await prisma.milestone.findMany({
|
||||
@@ -17,52 +39,90 @@ router.get('/:taskId', async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/milestones/:taskId — 마일스톤 추가
|
||||
// POST /api/milestones/:taskId
|
||||
router.post('/:taskId', async (req, res, next) => {
|
||||
try {
|
||||
const { title, description, dueDate } = req.body as Record<string, string>;
|
||||
const taskId = req.params.taskId;
|
||||
const { title, description, startDate, dueDate, feedback, links } =
|
||||
req.body as Record<string, string>;
|
||||
|
||||
const count = await prisma.milestone.count({ where: { taskId: req.params.taskId } });
|
||||
if (!title?.trim()) throw new AppError(400, '단계 제목은 필수입니다.');
|
||||
|
||||
const count = await prisma.milestone.count({ where: { taskId } });
|
||||
|
||||
const milestone = await prisma.milestone.create({
|
||||
data: {
|
||||
taskId: req.params.taskId,
|
||||
title,
|
||||
description: description || null,
|
||||
taskId,
|
||||
title: title.trim(),
|
||||
description: description?.trim() || null,
|
||||
startDate: startDate ? new Date(startDate) : null,
|
||||
dueDate: dueDate ? new Date(dueDate) : null,
|
||||
links: normalizeLinks(links),
|
||||
order: count,
|
||||
},
|
||||
});
|
||||
|
||||
if (feedback?.trim()) {
|
||||
const updatedBy = await resolveUpdatedBy(taskId);
|
||||
await prisma.taskDetail.create({
|
||||
data: {
|
||||
taskId,
|
||||
milestoneId: milestone.id,
|
||||
content: feedback.trim(),
|
||||
updatedBy,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
res.status(201).json(milestone);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/milestones/item/:id — 마일스톤 수정 (완료 처리 포함)
|
||||
// PATCH /api/milestones/item/:id
|
||||
router.patch('/item/:id', async (req, res, next) => {
|
||||
try {
|
||||
const { title, description, dueDate, completed, order } = req.body as Record<string, string | boolean | number>;
|
||||
const { title, description, startDate, dueDate, feedback, links, completed, order } =
|
||||
req.body as Record<string, string | boolean | number>;
|
||||
|
||||
const existing = await prisma.milestone.findUnique({ where: { id: req.params.id } });
|
||||
if (!existing) throw new AppError(404, '단계를 찾을 수 없습니다.');
|
||||
|
||||
const milestone = await prisma.milestone.update({
|
||||
where: { id: req.params.id },
|
||||
data: {
|
||||
...(title !== undefined && { title: title as string }),
|
||||
...(description !== undefined && { description: description as string || null }),
|
||||
...(dueDate !== undefined && { dueDate: dueDate ? new Date(dueDate as string) : null }),
|
||||
...(order !== undefined && { order: Number(order) }),
|
||||
...(completed !== undefined && {
|
||||
...(title !== undefined && { title: String(title).trim() }),
|
||||
...(description !== undefined && { description: description ? String(description).trim() : null }),
|
||||
...(startDate !== undefined && { startDate: startDate ? new Date(startDate as string) : null }),
|
||||
...(dueDate !== undefined && { dueDate: dueDate ? new Date(dueDate as string) : null }),
|
||||
...(links !== undefined && { links: normalizeLinks(links) }),
|
||||
...(order !== undefined && { order: Number(order) }),
|
||||
...(completed !== undefined && {
|
||||
completedAt: completed ? new Date() : null,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
if (typeof feedback === 'string' && feedback.trim()) {
|
||||
const updatedBy = await resolveUpdatedBy(existing.taskId);
|
||||
await prisma.taskDetail.create({
|
||||
data: {
|
||||
taskId: existing.taskId,
|
||||
milestoneId: milestone.id,
|
||||
content: feedback.trim(),
|
||||
updatedBy,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
res.json(milestone);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/milestones/item/:id — 마일스톤 삭제
|
||||
// DELETE /api/milestones/item/:id
|
||||
router.delete('/item/:id', async (req, res, next) => {
|
||||
try {
|
||||
await prisma.milestone.delete({ where: { id: req.params.id } });
|
||||
|
||||
Reference in New Issue
Block a user