我需要userIdin req.headers,但我无法正确输入,我该怎么做?
首先我尝试这样做:
interface ISpot{
thumbnail: File,
company: string,
price: number,
techs: string
}
interface IReqCustom<T> extends Request{
body: T,
}
export default {
async store (req: IReqCustom<ISpot>, res: Response): Promise<Response> {
const { filename } = req.file
const { company, techs, price } = req.body
const { userId } = req.headers
const user = await User.findById(userId)
if (!user) {
return res.status(400).json({ error: 'User doesn\'t exist' })
}
const spot = await Spot.create({
user: userId,
thumbnail: filename, …Run Code Online (Sandbox Code Playgroud)