How to use the @requestnetwork/types.RequestLogic.REQUEST_LOGIC_ACTION_NAME function in @requestnetwork/types

To help you get started, we’ve selected a few @requestnetwork/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / request-logic / src / requestLogicCore.ts View on Github external
// Will throw if the request is not valid
    Request.checkRequest(requestCopied);

    if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.ACCEPT) {
      requestAfterApply = AcceptAction.applyActionToRequest(action, requestCopied);
    }

    if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.CANCEL) {
      requestAfterApply = CancelAction.applyActionToRequest(action, requestCopied);
    }

    if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.INCREASE_EXPECTED_AMOUNT) {
      requestAfterApply = IncreaseExpectedAmountAction.applyActionToRequest(action, requestCopied);
    }

    if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.REDUCE_EXPECTED_AMOUNT) {
      requestAfterApply = ReduceExpectedAmountAction.applyActionToRequest(action, requestCopied);
    }

    if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.ADD_EXTENSIONS_DATA) {
      requestAfterApply = AddExtensionsData.applyActionToRequest(action, requestCopied);
    }
  }

  if (!requestAfterApply) {
    throw new Error(`Unknown action ${action.data.name}`);
  }

  // skip extension application if no extension given or no advanced logic layer given
  if (action.data.parameters.extensionsData && advancedLogic) {
    // Apply the extension on the state
    requestAfterApply.extensions = action.data.parameters.extensionsData.reduce(
github RequestNetwork / requestNetwork / packages / request-logic / src / requestLogicCore.ts View on Github external
function applyActionToRequest(
  request: Types.IRequestLogicRequest | null,
  action: Types.IRequestLogicAction,
  advancedLogic?: AdvancedLogicTypes.IAdvancedLogic,
): Types.IRequestLogicRequest {
  if (!Action.isActionVersionSupported(action)) {
    throw new Error('action version not supported');
  }

  // we don't want to modify the original request state
  const requestCopied: Types.IRequestLogicRequest | null = request ? Utils.deepCopy(request) : null;

  let requestAfterApply: Types.IRequestLogicRequest | null = null;

  // Creation request
  if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.CREATE) {
    if (requestCopied) {
      throw new Error('no request is expected at the creation');
    }
    requestAfterApply = CreateAction.createRequest(action);
  } else {
    // Update request
    if (!requestCopied) {
      throw new Error('request is expected');
    }

    // Will throw if the request is not valid
    Request.checkRequest(requestCopied);

    if (action.data.name === Types.REQUEST_LOGIC_ACTION_NAME.ACCEPT) {
      requestAfterApply = AcceptAction.applyActionToRequest(action, requestCopied);
    }