fix: stage save errors and add milestone progress field
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
23
backend/src/lib/resolveUser.ts
Normal file
23
backend/src/lib/resolveUser.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { prisma } from './prisma';
|
||||
import { AppError } from '../middleware/errorHandler';
|
||||
|
||||
/** task 작성자 또는 관리자 등 유효한 user id 반환 (FK 오류 방지) */
|
||||
export async function resolveTaskActorId(taskId: string): Promise<string> {
|
||||
const task = await prisma.task.findUnique({
|
||||
where: { id: taskId },
|
||||
select: { creatorId: true },
|
||||
});
|
||||
|
||||
if (task?.creatorId) {
|
||||
const creator = await prisma.user.findUnique({ where: { id: task.creatorId } });
|
||||
if (creator) return creator.id;
|
||||
}
|
||||
|
||||
const admin = await prisma.user.findFirst({ where: { role: 'ADMIN' }, select: { id: true } });
|
||||
if (admin) return admin.id;
|
||||
|
||||
const anyUser = await prisma.user.findFirst({ select: { id: true } });
|
||||
if (anyUser) return anyUser.id;
|
||||
|
||||
throw new AppError(500, '사용자를 찾을 수 없습니다. 관리자 계정을 먼저 생성해 주세요.');
|
||||
}
|
||||
Reference in New Issue
Block a user