Having a Lambda function that receives a JSON object from the Frontend over HTTPS, I need to perform validation on this object
The expected structure of the body should be as follows (Notifications):
interface Notifications {
type: NotificationType;
frequency: FrequencyType;
}
enum NotificationType {
SMS = 'SMS',
EMAIL = 'EMAIL'
}
enum FrequencyType {
INSTANT = 'INSTANT',
DAILY = 'DAILY',
WEEKLY = 'WEEKLY',
NEVER = 'NEVER'
}
Previous attempts using code from another stack post have not been successful
if (body && body.frequency in FrequencyType && body.type in NotificationType) {
//do stuff
}
Is there a more efficient way to ensure that the Frontend never sends an invalid notification type? Although typings are used on the Frontend, I am looking to implement validation on the backend as well
The TypeScript to JavaScript conversion for the enums looks like this:
var NotificationType;
(function(NotificationType2) {
NotificationType2["SMS"] = "SMS";
NotificationType2["EMAIL"] = "EMAIL";
})(NotificationType || (NotificationType = {}));
var FrequencyType;
(function(FrequencyType2) {
FrequencyType2["INSTANT"] = "INSTANT";
FrequencyType2["DAILY"] = "DAILY";
FrequencyType2["WEEKLY"] = "WEEKLY";
FrequencyType2["NEVER"] = "NEVER";
})(FrequencyType || (FrequencyType = {}));