我卡在 "The Shipped item's tracking number is required"
I am stuck at "The Shipped item's tracking number is required"
我有模型
const FormDataSchema = new mongoose.Schema({...})
// the Shipping schema
const ShippingSchema = new mongoose.Schema({
itemstrackno : {
type: String,
minlength: [3, "Minimum characters for this field is 3"],
maxlength: [100, "Maximum characters for this field is 100"],
required: [true, "The Shipped item's tracking number is required"],
trim: true,
unique: true
},
formData: [FormDataSchema]
}, {timestamps: true})
const Shipping = mongoose.model("Shipping", ShippingSchema)
module.exports = Shipping
我的post控制器
// post a shipment
exports.postShipment = async (req, res, next) => {
const {itemstrackno, formdata} = req.body
try {
const trackedItem = await Shipping.findOne({itemstrackno})
if(trackedItem){
return next(new ErrorResponse("An Item with this track number exists", 400))
}
const shipment = await Shipping.create({itemstrackno, formdata})
res.status(200).json({
success: true,
data: shipment
})
} catch (error) {
next(error)
}
}
当我向 postman 发送 post 请求时,我收到“需要已发货商品的跟踪编号”错误。我做错了什么?
THE POSTMAN IMAGE
您的请求中似乎有错字。您已按要求标记 itemstrackno
,但您发送的是 itemtrackno
我有模型
const FormDataSchema = new mongoose.Schema({...})
// the Shipping schema
const ShippingSchema = new mongoose.Schema({
itemstrackno : {
type: String,
minlength: [3, "Minimum characters for this field is 3"],
maxlength: [100, "Maximum characters for this field is 100"],
required: [true, "The Shipped item's tracking number is required"],
trim: true,
unique: true
},
formData: [FormDataSchema]
}, {timestamps: true})
const Shipping = mongoose.model("Shipping", ShippingSchema)
module.exports = Shipping
我的post控制器
// post a shipment
exports.postShipment = async (req, res, next) => {
const {itemstrackno, formdata} = req.body
try {
const trackedItem = await Shipping.findOne({itemstrackno})
if(trackedItem){
return next(new ErrorResponse("An Item with this track number exists", 400))
}
const shipment = await Shipping.create({itemstrackno, formdata})
res.status(200).json({
success: true,
data: shipment
})
} catch (error) {
next(error)
}
}
当我向 postman 发送 post 请求时,我收到“需要已发货商品的跟踪编号”错误。我做错了什么?
THE POSTMAN IMAGE
您的请求中似乎有错字。您已按要求标记 itemstrackno
,但您发送的是 itemtrackno