Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// the user is sending a message by providing default addresses but he's
// not allowed to do so.
return ResponseErrorForbiddenNotAuthorizedForDefaultAddresses;
}
const requestedAmount = messagePayload.content.payment_data
? messagePayload.content.payment_data.amount
: undefined;
const hasExceededAmount =
requestedAmount &&
requestedAmount > (userService.maxAllowedPaymentAmount as number);
// check if the service wants to charge a valid amount to the user
if (hasExceededAmount) {
return ResponseErrorValidation(
"Error while sending payment metadata",
`The requested amount (${requestedAmount} cents) exceeds the maximum allowed for this service (${
userService.maxAllowedPaymentAmount
} cents)`
);
}
const id = generateObjectId();
// create a new message from the payload
// this object contains only the message metadata, the content of the
// message is handled separately (see below).
const newMessageWithoutContent: NewMessageWithoutContent = {
createdAt: new Date(),
fiscalCode,
id,
serviceName: userAttributes.service.serviceName
},
serviceVersion: userAttributes.service.version
})
);
if (isLeft(createdMessageEventOrError)) {
winston.error(
`CreateMessageHandler|Unable to decode CreatedMessageEvent|${
userService.serviceId
}|${retrievedMessage.id}|${readableReport(
createdMessageEventOrError.value
).replace(/\n/g, " / ")}`
);
return ResponseErrorValidation(
"Unable to decode CreatedMessageEvent",
readableReport(createdMessageEventOrError.value)
);
}
// queue the message to the created messages queue by setting
// the message to the output binding of this function
// tslint:disable-next-line:no-object-mutation
context.bindings.createdMessage = createdMessageEventOrError.value;
//
// generate appinsights event
//
// track the event that a message has been created
appInsightsClient.trackEvent({
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;