How to use the italia-ts-commons/lib/types.withoutUndefinedValues 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 / created_message_queue_handler.ts View on Github external
const notificationEvent = errorOrNotificationEvent.value;

  // output notification events (one for each channel)
  const outputBindings: OutputBindings = {
    emailNotification: maybeAllowedEmailNotification
      .map(() => notificationEvent)
      .toUndefined(),
    webhookNotification: maybeAllowedWebhookNotification
      .map(() => notificationEvent)
      .toUndefined()
  };

  // avoid to enqueue messages for non existing notifications
  return right(
    withoutUndefinedValues(outputBindings)
  );
}
github teamdigitale / io-functions / lib / created_message_queue_handler.ts View on Github external
`handleMessage|No channels configured for the user ${
        newMessageWithoutContent.fiscalCode
      } and no default address provided`
    );
    // return no notifications
    return right({});
  }

  // create and save notification object
  const newNotification: NewNotification = {
    ...createNewNotification(
      ulidGenerator,
      newMessageWithoutContent.fiscalCode,
      newMessageWithoutContent.id
    ),
    channels: withoutUndefinedValues({
      [NotificationChannelEnum.EMAIL]: maybeAllowedEmailNotification.toUndefined(),
      [NotificationChannelEnum.WEBHOOK]: maybeAllowedWebhookNotification.toUndefined()
    })
  };

  const errorOrNotificationEvent = await createNotification(
    lNotificationModel,
    senderMetadata,
    newMessageWithoutContent,
    createdMessageEvent.content,
    newNotification
  );

  if (isLeft(errorOrNotificationEvent)) {
    return left(errorOrNotificationEvent.value);
  }
github teamdigitale / io-functions / lib / controllers / messages.ts View on Github external
winston.debug(
      `CreateMessageHandler|message created|${userService.serviceId}|${
        retrievedMessage.id
      }`
    );

    //
    // emit created message event to the output queue
    //

    // prepare the created message event
    // we filter out undefined values as they are
    // deserialized to null(s) when enqueued
    const createdMessageEventOrError = CreatedMessageEvent.decode(
      withoutUndefinedValues({
        content: messagePayload.content,
        defaultAddresses: messagePayload.default_addresses,
        message: newMessageWithoutContent,
        senderMetadata: {
          departmentName: userAttributes.service.departmentName,
          organizationFiscalCode: userAttributes.service.organizationFiscalCode,
          organizationName: userAttributes.service.organizationName,
          serviceName: userAttributes.service.serviceName
        },
        serviceVersion: userAttributes.service.version
      })
    );

    if (isLeft(createdMessageEventOrError)) {
      winston.error(
        `CreateMessageHandler|Unable to decode CreatedMessageEvent|${
github teamdigitale / io-functions / lib / controllers / messages.ts View on Github external
);

    if (isLeft(errorOrMaybeContent)) {
      winston.error(
        `GetMessageHandler|${JSON.stringify(errorOrMaybeContent.value)}`
      );
      return ResponseErrorInternal(
        `${errorOrMaybeContent.value.name}: ${
          errorOrMaybeContent.value.message
        }`
      );
    }

    const message:
      | CreatedMessageWithContent
      | CreatedMessageWithoutContent = withoutUndefinedValues({
      content: errorOrMaybeContent.value.toUndefined(),
      ...retrievedMessageToPublic(retrievedMessage)
    });

    const errorOrNotificationStatuses = await getMessageNotificationStatuses(
      notificationModel,
      notificationStatusModel,
      retrievedMessage.id
    );

    if (isLeft(errorOrNotificationStatuses)) {
      return ResponseErrorInternal(
        `Error retrieving NotificationStatus: ${
          errorOrNotificationStatuses.value.name
        }|${errorOrNotificationStatuses.value.message}`
      );