How to use the io-functions-commons/dist/src/utils/response.ResponseErrorQuery function in io-functions-commons

To help you get started, we’ve selected a few io-functions-commons 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 teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
preferredLanguages: profileModelPayload.preferred_languages
  };

  const errorOrMaybeProfile = await profileModel.update(
    existingProfile.id,
    existingProfile.fiscalCode,
    p => {
      return {
        ...p,
        ...profile
      };
    }
  );

  if (isLeft(errorOrMaybeProfile)) {
    return ResponseErrorQuery(
      "Error while updating the existing profile",
      errorOrMaybeProfile.value
    );
  }

  const maybeProfile = errorOrMaybeProfile.value;

  return maybeProfile.foldL<
    IResponseErrorInternal | IResponseSuccessJson
  >(
    () =>
      // this should never happen since if the profile doesn't exist this function
      // will never be called, but let's deal with this anyway, you never know
      ResponseErrorInternal(
        "Error while updating the existing profile, the profile does not exist!"
      ),
github teamdigitale / io-functions / lib / controllers / messages.ts View on Github external
return async (userAuth, _, userAttributes, fiscalCode, messageId) => {
    const errorOrMaybeDocument = await messageModel.findMessageForRecipient(
      fiscalCode,
      messageId
    );

    if (isLeft(errorOrMaybeDocument)) {
      // the query failed
      return ResponseErrorQuery(
        "Error while retrieving the message",
        errorOrMaybeDocument.value
      );
    }

    const maybeDocument = errorOrMaybeDocument.value;
    if (isNone(maybeDocument)) {
      // the document does not exist
      return ResponseErrorNotFound(
        "Message not found",
        "The message that you requested was not found in the system."
      );
    }

    const retrievedMessage = maybeDocument.value;
github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
return async (context, _, __, ___, fiscalCode, profileModelPayload) => {
    const errorOrMaybeProfile = await profileModel.findOneProfileByFiscalCode(
      fiscalCode
    );
    if (isLeft(errorOrMaybeProfile)) {
      return ResponseErrorQuery("Error", errorOrMaybeProfile.value);
    }
    const maybeProfile = errorOrMaybeProfile.value;

    if (isNone(maybeProfile)) {
      // create a new profile
      const response = await createNewProfileFromPayload(
        profileModel,
        fiscalCode,
        profileModelPayload
      );
      // if we successfully created the user's profile
      // broadcast a profile-created event
      if (response.kind === "IResponseSuccessJson") {
        // tslint:disable-next-line:no-object-mutation
        context.bindings.profileEvent = {
          fiscalCode,
github teamdigitale / io-functions / lib / controllers / services.ts View on Github external
      error => ResponseErrorQuery("Error while retrieving the service", error),
      maybeService =>
github teamdigitale / io-functions / lib / controllers / adm / services.ts View on Github external
serviceId
    );
    if (isRight(errorOrMaybeService)) {
      const maybeService = errorOrMaybeService.value;
      if (isNone(maybeService)) {
        return ResponseErrorNotFound(
          "Service not found",
          "The service you requested was not found in the system."
        );
      } else {
        return ResponseSuccessJson(
          retrievedServiceToPublic(maybeService.value)
        );
      }
    } else {
      return ResponseErrorQuery(
        "Error while retrieving the service",
        errorOrMaybeService.value
      );
    }
  };
}
github teamdigitale / io-functions / lib / controllers / adm / services.ts View on Github external
      error => ResponseErrorQuery("CreateServiceHandler error", error),
      createdService =>
github teamdigitale / io-functions / lib / controllers / adm / services.ts View on Github external
}
    const serviceFromPayload = errorOrServiceFromPayload.value;

    const errorOrMaybeUpdatedService = await serviceModel.update(
      existingService.id,
      existingService.serviceId,
      currentService => {
        return {
          ...currentService,
          ...serviceFromPayload,
          serviceId
        };
      }
    );
    if (isLeft(errorOrMaybeUpdatedService)) {
      return ResponseErrorQuery(
        "Error while updating the existing service",
        errorOrMaybeUpdatedService.value
      );
    }

    const maybeUpdatedService = errorOrMaybeUpdatedService.value;
    if (isNone(maybeUpdatedService)) {
      return ResponseErrorInternal("Error while updating the existing service");
    }

    return ResponseSuccessJson(
      retrievedServiceToPublic(maybeUpdatedService.value)
    );
  };
}
github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
acceptedTosVersion: profileModelPayload.accepted_tos_version,
    blockedInboxOrChannels: profileModelPayload.blocked_inbox_or_channels,
    email: profileModelPayload.email,
    fiscalCode,
    isInboxEnabled: profileModelPayload.is_inbox_enabled,
    isWebhookEnabled: profileModelPayload.is_webhook_enabled,
    preferredLanguages: profileModelPayload.preferred_languages
  };
  const errorOrProfile = await profileModel.create(profile, profile.fiscalCode);
  const errorOrProfileAsPublicExtendedProfile = errorOrProfile.map(
    toExtendedProfile
  );
  if (isRight(errorOrProfileAsPublicExtendedProfile)) {
    return ResponseSuccessJson(errorOrProfileAsPublicExtendedProfile.value);
  } else {
    return ResponseErrorQuery(
      "Error while creating a new profile",
      errorOrProfileAsPublicExtendedProfile.value
    );
  }
}
github teamdigitale / io-functions / lib / controllers / adm / services.ts View on Github external
return async (_, __, ___, serviceId, serviceModelPayload) => {
    if (serviceModelPayload.service_id !== serviceId) {
      return ResponseErrorValidation(
        "Error validating payload",
        "Value of `service_id` in the request body must match " +
          "the value of `service_id` path parameter"
      );
    }
    const errorOrMaybeService = await serviceModel.findOneByServiceId(
      serviceId
    );
    if (isLeft(errorOrMaybeService)) {
      return ResponseErrorQuery(
        "Error trying to retrieve existing service",
        errorOrMaybeService.value
      );
    }

    const maybeService = errorOrMaybeService.value;
    if (isNone(maybeService)) {
      return ResponseErrorNotFound(
        "Error",
        "Could not find a service with the provided serviceId"
      );
    }

    const existingService = maybeService.value;
    const errorOrServiceFromPayload = servicePayloadToService(
      serviceModelPayload

io-functions-commons

Common code for Azure functions

MIT
Latest version published 4 years ago

Package Health Score

50 / 100
Full package analysis

Similar packages