【发布时间】:2021-03-19 15:37:36
【问题描述】:
我正在做一个反应项目,当我尝试使用邮递员存储我的数据时,它工作得很好。但另一方面,如果我使用 react-redux,它不会被传递到数据库中。我该如何解决这个问题?这是代码的一些sn-ps。
const mongoose = require('mongoose');
const verifySchema = new mongoose.Schema(
{
investment: {
type: mongoose.Schema.ObjectId,
ref: 'Investment',
},
topup: {
type: mongoose.Schema.ObjectId,
ref: 'TopUp',
},
verified: {
type: Boolean,
required: true,
},
verifiedBy: {
type: mongoose.Schema.ObjectId,
ref: 'Auth',
},
dateVerified: {
type: Date,
default: Date.now(),
required: true,
},
note: String,
createdAt: { type: Date, default: Date.now() },
paymentDates: [Date],
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true },
}
);
const Verify = mongoose.model('Verify', verifySchema);
module.exports = Verify;
这是提交处理程序
const submitHandler = (e) => {
e.preventDefault();
if (isConfirmed === true) {
const paymentDates = [];
for (let i = 1; i <= investment.investmentDuration; i += 1) {
paymentDates.push(
moment(dateConfirm).add(i, 'months').add(1, 'days').toISOString()
);
}
const data = new FormData();
data.append('verified', isConfirmed);
data.append('investment', investment._id);
data.append('dateVerify', dateConfirm);
data.append('verifiedBy', userInfo.data.user._id);
data.append('amount', investment.investmentAmount);
data.append('duration', investment.investmentDuration);
data.append('paymentDates', paymentDates);
data.append('note', note);
dispatch(verifyInvestment(data));
}
};
这是动作
export const verifyInvestment = (formData) => async (dispatch, getState) => {
try {
dispatch({ type: VERIFY_CREATE_REQUEST });
const {
userLogin: { userInfo },
} = getState();
for (var pair of formData.entries()) {
console.log(pair[0] + ', ' + pair[1]);
}
const config = {
headers: {
// Authorization: `Bearer ${userInfo.token}`,
'Content-Type': 'application/json',
},
};
const { data } = await axios.post(`/api/v1/verify`, formData, config);
dispatch({
type: VERIFY_CREATE_SUCCESS,
payload: data,
});
} catch (error) {
dispatch({
type: VERIFY_CREATE_FAIL,
payload:
error.response && error.response.data.message
? error.response.data.message
: error.message,
});
}
};
从我的控制台,我打印了这条消息
verified, true
verifyActions.js:16 investment, 5fcde10d1ec7da05d54942ed
verifyActions.js:16 dateVerify, 2020-12-31
verifyActions.js:16 verifiedBy, 5fcc8739b926611a541a5baf
verifyActions.js:16 amount, 400000
verifyActions.js:16 duration, 12
verifyActions.js:16 paymentDates, 2021-01-31T23:00:00.000Z,2021-02-28T23:00:00.000Z,2021-03-31T23:00:00.000Z,2021-04-30T23:00:00.000Z,2021-05-31T23:00:00.000Z,2021-06-30T23:00:00.000Z,2021-07-31T23:00:00.000Z,2021-08-31T23:00:00.000Z,2021-09-30T23:00:00.000Z,2021-10-31T23:00:00.000Z,2021-11-30T23:00:00.000Z,2021-12-31T23:00:00.000Z
verifyActions.js:16 note, Hello World
POST http://localhost:3000/api/v1/verify 500 (Internal Server Error)
我从该州收到此消息。
verify(pin):"验证验证失败:已验证:需要路径verified。"
我真的需要帮助来解决这个问题。 如果我尝试使用邮递员发布它,它会存储在数据库中,但对于这种情况,它不会。我不知道在发布数据之前我是否必须清空一些状态。
【问题讨论】:
标签: javascript reactjs mongoose redux