【发布时间】:2017-11-28 08:16:58
【问题描述】:
我需要更新代理的状态。如果状态已验证,API 需要 document_name(multiple) 和原因。如果状态为暂停并被拒绝,则 API 需要唯一的原因。
这是代理的对象。
{
"active": true,
"agent_info": [], // an array of object where document_name and reason has to be updated with
"user_role": "enduser",
"last_name": "m",
"middle_name": null,
"username": "k@mail.com",
"_id": "594f4665ae36b70029f80ba0",
"first_name": "pm",
"email": "k@mail.com",
}
在提交状态时,我为一个传奇触发了以下操作
this.props.updateAgentStatus(status, agent, accepted, reason);
satus 是代理的状态(已验证、暂停或拒绝)代理是 接受代理的详细信息是状态为的文件 验证的原因是状态的原因
function* updateAgent(action) {
const agentId = action.agent._id;
const status = action.status;
let agent = yield select(selectAgent(), action);
let updatedAgent;
let statusUpdatedAgent = agent.set("agent_status", fromJS(action.status));
if (status === "verified") {
updatedAgent = statusUpdatedAgent
.setIn(["agent_info", 0, "approval_documents"], fromJS(action.accepted))
.setIn(["agent_info", 0, "reason"], fromJS(action.reason));
} else {
updatedAgent = statusUpdatedAgent.setIn(
["agent_info", 0, "reason"],
fromJS(action.reason)
);
}
console.log("updateAgentStatus", updatedAgent.toJS());
// above log gives me the whole object of agent by updating the agent_info object with
// document_name and reason which is inside of agent_info block and agent_status which is
// outside the agent_info block.
yield fork(
XcelTrip.put(
`api/agent/applicant/status/${agentId}/?status=${status}`,
agentStatusUpdated,
agentStatusUpdatingError,
updatedAgent.toJS(),
agentId,
status
)
);
}
如果它是已验证状态,我是否需要传递整个对象或仅传递 document_name 和原因,或者如果它处于暂停和拒绝状态,我是否需要传递原因?如果只是 document_name 和原因,我该如何考虑所有这些状态来发送它,因为在经过验证的情况下需要额外的 document_name?
【问题讨论】:
标签: javascript reactjs redux immutable.js redux-saga