I need to update the status of the agent. If the status is verified, an API needs document_name(multiple) and reason. If the status is on hold and rejected, an API needs the only reason.
This is the object of an agent.
{
"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": "[email protected]",
"_id": "594f4665ae36b70029f80ba0",
"first_name": "pm",
"email": "[email protected]",
}
when submitting the status, I trigger the following action for a saga
this.props.updateAgentStatus(status, agent, accepted, reason);
satus is the status of agent(verified, on hold or rejected) agent is the detail of agent accepted is the document in case the status is verified reason is the reason for the status
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
)
);
}
Do I need to pass the whole object or just the document_name and reason if it's a verified status or just the reason if it's on hold and rejected status? If it's just document_name and reason, how can I send it considering all those statuses because in the case of verified additional document_name is needed?