Skip to content

Commit

Permalink
feat: 20230911(2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanzhiwen committed Sep 11, 2023
1 parent 6aea2d5 commit f1cd5c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
14 changes: 14 additions & 0 deletions src/apis/item/item.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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是否存在。
Expand All @@ -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()
}

0 comments on commit f1cd5c1

Please sign in to comment.