Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am stuck at "The Shipped item's tracking number is required"

I have a model

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

my post controller

// 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)
}

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

when i send a post request with postman i get "The Shipped item’s tracking number is required" Error. What am i doing wrong?

THE POSTMAN IMAGE

>Solution :

Seems like you have a typo in the request. You have marked itemstrackno as required but you are sending itemtrackno

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading