How to use the italia-ts-commons/lib/responses.ResponseSuccessJson function in italia-ts-commons

To help you get started, we’ve selected a few italia-ts-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 / messages.ts View on Github external
const returnedMessage:
      | MessageResponseWithContent
      | MessageResponseWithoutContent = {
      message,
      notification: notificationStatuses.toUndefined(),
      // we do not return the status date-time
      status: maybeMessageStatus
        .map(messageStatus => messageStatus.status)
        // when the message has been received but a MessageStatus
        // does not exist yet, the message is considered to be
        // in the ACCEPTED state (not yet stored in the inbox)
        .getOrElse(MessageStatusValueEnum.ACCEPTED)
    };

    return ResponseSuccessJson(returnedMessage);
  };
}
github teamdigitale / io-functions / lib / controllers / debug.ts View on Github external
const getDebugHandler: GetDebug = (request, _, auth, userAttributes) => {
  return Promise.resolve(
    ResponseSuccessJson({
      auth: {
        ...auth,
        // must convert the Set to an Array
        // see https://stackoverflow.com/questions/31190885/json-stringify-a-set
        groups: Array.from(auth.groups.values())
      },
      body: request.body,
      headers: request.headers,
      params: request.params,
      user: userAttributes
    })
  );
};
github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
return async (auth, _, userAttributes, fiscalCode) => {
    const errorOrMaybeProfile = await profileModel.findOneProfileByFiscalCode(
      fiscalCode
    );
    if (isRight(errorOrMaybeProfile)) {
      const maybeProfile = errorOrMaybeProfile.value;
      if (isSome(maybeProfile)) {
        const profile = maybeProfile.value;
        if (auth.groups.has(UserGroup.ApiFullProfileRead)) {
          // if the client is a trusted application we return the
          // extended profile
          return ResponseSuccessJson(toExtendedProfile(profile));
        } else {
          // or else, we return a limited profile
          return ResponseSuccessJson(
            toLimitedProfile(
              profile,
              isSenderAllowed(
                profile.blockedInboxOrChannels,
                userAttributes.service.serviceId
              )
            )
          );
        }
      } else {
        return ResponseErrorNotFound(
          "Profile not found",
          "The profile you requested was not found in the system."
        );
      }
    } else {
github teamdigitale / io-functions / lib / controllers / openapi.ts View on Github external
return wrapRequestHandler(() =>
    Promise.resolve(ResponseSuccessJson(apiSpecs))
  );
github teamdigitale / io-functions / lib / controllers / services.ts View on Github external
          service => ResponseSuccessJson(retrievedServiceToPublic(service))
        )
github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
): Promise | IResponseErrorQuery> {
  const profile: Profile = {
    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
createdService =>
        ResponseSuccessJson(retrievedServiceToPublic(createdService))
    );
github teamdigitale / io-functions / lib / controllers / info.ts View on Github external
return new Promise(resolve => {
    const info: IResponseInfo = {
      status: "OK"
    };
    resolve(ResponseSuccessJson(info));
  });
};