import DC_ACTION from '../../enum/dcAction'; import DC_SCENARIO from '../../enum/dcScenario'; import PARTY from '../../enum/party'; import USER_ROLE from '../../enum/userRole'; import envConfig from '../../env/env-config'; import { getNodeProfile } from '../../env/nodeProfile'; import { checkerApproverResponse, isWorkflowReadyForExecution } from '../apiUtil'; import { HTTP_METHOD } from '../httpMethod'; import { makeAuthenticatedRequest } from '../loginUtil'; import scenarioContext from '../scenarioContext'; import { executeDraftAndMapNewId } from '../updateDcId'; import { generateNominatedBankProceededDc } from './generateNominatedBankProceededDc'; import { checkForIdentitySwitching } from './multiIdentityUtil'; export async function generateAdvisingBankProceededDc( dcScenario, action = DC_ACTION.ADVISED, proceededUserRoles = USER_ROLE.MAKER + '.' + USER_ROLE.CHECKER_APPROVER, attachmentNum = 0, documentSourceDataTable = null ) { const roles = proceededUserRoles.split('.'); await generateNominatedBankProceededDc( dcScenario, DC_ACTION.ADVISED, USER_ROLE.MAKER + '.' + USER_ROLE.CHECKER_APPROVER, attachmentNum, documentSourceDataTable ); // Case with advising bank not equal confirming bank or nominated bank const validScenario = [DC_SCENARIO.SC1, DC_SCENARIO.SC5, DC_SCENARIO.SC10, DC_SCENARIO.SC11, DC_SCENARIO.SC2SPLIT]; if (validScenario.includes(dcScenario)) { const actionInfoMap = new Map() .set(DC_ACTION.ADVISED, { endPoint: 'locapp/advisingBank/approve/' + scenarioContext().dc.appRefId, json: { args: { lcReference: envConfig.scenario[dcScenario].advisedLCRef }, draftComment: null } }) .set(DC_ACTION.REJECTED, { endPoint: 'locapp/advisingBank/reject/' + scenarioContext().dc.appRefId, json: { args: {}, draftComment: null } }); scenarioContext().currentParty = PARTY.ADVISING_BANK; const endPoint = actionInfoMap.get(action).endPoint; const json = actionInfoMap.get(action).json; const advisingBankNode = scenarioContext().getPartyNode(dcScenario, PARTY.ADVISING_BANK); const nodeProfile = getNodeProfile(advisingBankNode); await checkForIdentitySwitching(PARTY.ADVISING_BANK, advisingBankNode, nodeProfile, roles[0]); let advisingBankAdviseResponse = await makeAuthenticatedRequest( advisingBankNode, roles[0], endPoint, HTTP_METHOD.PUT, JSON.stringify(json) ); advisingBankAdviseResponse = isWorkflowReadyForExecution(advisingBankAdviseResponse) ? advisingBankAdviseResponse : await checkerApproverResponse(advisingBankNode, roles[1], advisingBankAdviseResponse); await executeDraftAndMapNewId(advisingBankNode, await advisingBankAdviseResponse.id); } }