fix: backend TypeScript build blocking Render deploy
Cast route params to string so tsc passes and the creatorId fix can reach production.
This commit is contained in:
@@ -65,7 +65,8 @@ router.post('/upload/:taskId', upload.single('file'), async (req, res, next) =>
|
||||
// GET /api/files/:id/view — 파일 미리보기 (브라우저에서 바로 열기)
|
||||
router.get('/:id/view', async (req, res, next) => {
|
||||
try {
|
||||
const file = await prisma.file.findUnique({ where: { id: req.params.id } });
|
||||
const fileId = String(req.params.id);
|
||||
const file = await prisma.file.findUnique({ where: { id: fileId } });
|
||||
if (!file) throw new AppError(404, '파일을 찾을 수 없습니다.');
|
||||
if (!fs.existsSync(file.path)) throw new AppError(404, '파일이 서버에 없습니다.');
|
||||
|
||||
@@ -80,7 +81,8 @@ router.get('/:id/view', async (req, res, next) => {
|
||||
// GET /api/files/:id/download — 파일 다운로드
|
||||
router.get('/:id/download', async (req, res, next) => {
|
||||
try {
|
||||
const file = await prisma.file.findUnique({ where: { id: req.params.id } });
|
||||
const fileId = String(req.params.id);
|
||||
const file = await prisma.file.findUnique({ where: { id: fileId } });
|
||||
if (!file) throw new AppError(404, '파일을 찾을 수 없습니다.');
|
||||
if (!fs.existsSync(file.path)) throw new AppError(404, '파일이 서버에 없습니다.');
|
||||
|
||||
@@ -96,7 +98,8 @@ router.post('/:id/replace', upload.single('file'), async (req, res, next) => {
|
||||
try {
|
||||
if (!req.file) throw new AppError(400, '파일이 없습니다.');
|
||||
|
||||
const existing = await prisma.file.findUnique({ where: { id: req.params.id } });
|
||||
const fileId = String(req.params.id);
|
||||
const existing = await prisma.file.findUnique({ where: { id: fileId } });
|
||||
if (!existing) throw new AppError(404, '파일을 찾을 수 없습니다.');
|
||||
|
||||
if (fs.existsSync(existing.path)) {
|
||||
@@ -104,7 +107,7 @@ router.post('/:id/replace', upload.single('file'), async (req, res, next) => {
|
||||
}
|
||||
|
||||
const file = await prisma.file.update({
|
||||
where: { id: req.params.id },
|
||||
where: { id: fileId },
|
||||
data: {
|
||||
filename: req.file.filename,
|
||||
originalName: fixOriginalName(req.file.originalname),
|
||||
@@ -123,12 +126,13 @@ router.post('/:id/replace', upload.single('file'), async (req, res, next) => {
|
||||
// PATCH /api/files/:id — 표시명·순서 수정
|
||||
router.patch('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const fileId = String(req.params.id);
|
||||
const { displayName, sortOrder } = req.body as { displayName?: string; sortOrder?: number };
|
||||
const existing = await prisma.file.findUnique({ where: { id: req.params.id } });
|
||||
const existing = await prisma.file.findUnique({ where: { id: fileId } });
|
||||
if (!existing) throw new AppError(404, '파일을 찾을 수 없습니다.');
|
||||
|
||||
const file = await prisma.file.update({
|
||||
where: { id: req.params.id },
|
||||
where: { id: fileId },
|
||||
data: {
|
||||
...(displayName !== undefined && { displayName: displayName?.trim() || null }),
|
||||
...(sortOrder !== undefined && { sortOrder: Number(sortOrder) }),
|
||||
@@ -144,7 +148,8 @@ router.patch('/:id', async (req, res, next) => {
|
||||
// DELETE /api/files/:id — 파일 삭제
|
||||
router.delete('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const file = await prisma.file.findUnique({ where: { id: req.params.id } });
|
||||
const fileId = String(req.params.id);
|
||||
const file = await prisma.file.findUnique({ where: { id: fileId } });
|
||||
if (!file) throw new AppError(404, '파일을 찾을 수 없습니다.');
|
||||
|
||||
// 실제 파일 삭제
|
||||
@@ -152,7 +157,7 @@ router.delete('/:id', async (req, res, next) => {
|
||||
fs.unlinkSync(file.path);
|
||||
}
|
||||
|
||||
await prisma.file.delete({ where: { id: req.params.id } });
|
||||
await prisma.file.delete({ where: { id: fileId } });
|
||||
res.status(204).send();
|
||||
} catch (err) {
|
||||
next(err);
|
||||
|
||||
Reference in New Issue
Block a user