邮递员未收到有关我的属性的帖子数据

问题描述

我以前使用过 Postman,它通常在我测试来自我的 MERN 项目的路由时有效。然而,post 请求并没有在 Postman 窗口的底部显示我的属性(姓名和职位),它只显示了 id、created_at 和 updated_at 属性

这是我的代码

运动员.model.js

const AthleteSchema = new mongoose.Schema({
    name: { type: String },position: { type: String }
},{ timestamps: true });
module.exports.Athlete = mongoose.model('Athlete',AthleteSchema);

athlete.controller.js

const { Athlete } = require('../models/athlete.model');

module.exports.index = (request,response) => {
    response.json({
        message: "Hello World"
    });
}


module.exports.createAthlete = (request,response) => {
    console.log('create method executed.')
    const { name,position } = request.body;
    Athlete.create({
        name,position
    })
        .then(athlete => response.json(athlete))
        .catch(err => response.json(err));
}

athlete.routes.js

const AthleteController = require('../controllers/athlete.controller');

module.exports = function(app){
    app.get('/api',AthleteController.index);
    app.post('/api/athletes',AthleteController.createAthlete);
}

任何帮助都将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)