【发布时间】:2020-11-13 08:22:41
【问题描述】:
我是一名想学习 javascript 的学生,但英语不太好.. 正如我之前告诉过你的,我试图制作可编辑的 mypage(profile)。 我使用了 mysql 和 sequelize,我确实得到了制作 mypage 的方法,但不能使用 post 方法 用户可以接近他们的信息(编辑)。 我只想使用昵称、生日、电话、介绍部分 如果我用邮递员,把照片吹掉, SyntaxError:意外的令牌/在 JSON 中的位置 113 出来.. 这是我的导师(用户)模型。
/* jshint indent: 2 */
module.exports = function (sequelize, DataTypes) {
return sequelize.define('Mentors', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
mentor_name: {
type: DataTypes.STRING(255),
allowNull: true,
},
nickname: {
type: DataTypes.STRING(255),
allowNull: true,
},
email: {
type: DataTypes.STRING(255),
allowNull: true,
},
password: {
type: DataTypes.STRING(255),
allowNull: true,
},
sex: {
type: DataTypes.STRING(255),
allowNull: true,
},
phone: {
type: DataTypes.STRING(255),
allowNull: true,
},
birthday: {
type: DataTypes.STRING(255),
allowNull: true,
},
certification_path: {
type: DataTypes.STRING(255),
allowNull: true,
},
intro: {
type: DataTypes.STRING(255),
allowNull: true,
},
}, {
sequelize,
tableName: 'Mentors',
timestamps: false,
});
};
这是我的导师(用户)页面,我想修复其中的 POST 部分。
const db = require('../../../models');
const { Mentors } = db;
module.exports = {
get: (req, res) => {
if (req.params.id) {
Mentors
.findOne({
where: {
id: req.params.id,
},
})
.then((result) => {
if (result) {
res.status(200).json(result);
} else {
res.status(409).send('Wrong Access');
}
})
.catch((err) => {
res.status(500).send(err);
});
}
},
post: (req, res) => {
Mentors
.findOne({
where: {
id: req.params.id,
},
})
.then((result) => {
if (result) {
res.status(200).json(result);
} else {
res.status(409).send('Wrong Access');
}
})
.catch((err) => {
res.status(500).send(err); // help me...
});
},
};
这是我用于测试的邮递员
请帮帮我~
【问题讨论】:
标签: javascript mysql post sequelize.js postman