diff --git a/gulpfile.js b/gulpfile.js index e701708..409e3fb 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,8 @@ const gulp = require('gulp') const del = require('del') const $ = require('gulp-load-plugins')() +// for project building + // 编译源代码 gulp.task('compile-src', function () { const project = $.typescript.createProject('tsconfig.json') diff --git a/src/apis/item/item.middleware.ts b/src/apis/item/item.middleware.ts index f90e812..f78eb8c 100755 --- a/src/apis/item/item.middleware.ts +++ b/src/apis/item/item.middleware.ts @@ -3,6 +3,8 @@ import { Request, Response, NextFunction } from 'express' import { ItemFilter } from '@/entities/item.model' import itemDao from '@/dao/item.dao' import AppError from '@/lib/error' +import { FileFilter } from '@/entities/file.model' +import fileDao from '@/dao/file.dao' /** * 验证params中的item是否存在。 @@ -18,3 +20,15 @@ export async function validateItemInParams(req: Request, res: Response, next: Ne next() } + +export async function validateAttachmentInParams(req: Request, res: Response, next: NextFunction) { + const attachmentId = req.params.attachmentId + + const filter: FileFilter = { _id: attachmentId } + + const [err, attachment] = await callAsync(fileDao.findOne(filter)) + if (err) return next(err) + if (!attachment) return next(new AppError({ message: '没有找到附件', statusCode: 404 })) + + next() +}