Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 {
return ResponseErrorQuery(
"Error while retrieving the profile",
errorOrMaybeProfile.value
);
}
};
}
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;
// whether the user is a trusted application (i.e. can access all messages for any recipient)
const canListMessages = userAuth.groups.has(UserGroup.ApiMessageList);
// the user is allowed to see the message when he is either
// a trusted application or he is the sender of the message
const isUserAllowed =
canListMessages ||
retrievedMessage.senderServiceId === userAttributes.service.serviceId;
() =>
ResponseErrorNotFound(
"Service not found",
"The service you requested was not found in the system."
),
service => ResponseSuccessJson(retrievedServiceToPublic(service))
"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
);
if (isLeft(errorOrServiceFromPayload)) {
return ResponseErrorFromValidationErrors(Service)(
errorOrServiceFromPayload.value
);
}
const serviceFromPayload = errorOrServiceFromPayload.value;
return async (_, __, ___, serviceId) => {
const errorOrMaybeService = await serviceModel.findOneByServiceId(
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
);
}
};
}