"use strict" ; import { APIGatewayProxyEvent } from "aws-lambda" ; export default class Validator { replaceAll ( string , search , replace ) { return string . split ( search ) . join ( replace ) ; } normalizePhone ( phone ) { return this . replaceAll ( phone , "-" , "" ) ; } hasProperty = ( obj , key ) : boolean => { return ! ! obj && Object . prototype . hasOwnProperty . call ( obj , key ) ; } ; jsonBody ( bodyData ) { if ( typeof bodyData === "string" ) { return JSON . parse ( bodyData ) ; } else { return bodyData ; } } checkDynamoGetResultEmpty ( res ) { if ( res == undefined ) return true ; if ( Object . keys ( res ) . length == 0 ) return true ; return false ; } checkDyanmoQueryResultEmpty ( res ) { if ( ! Object . keys ( res . Items ) . length ) { return true ; } else { return false ; } } checkCenterBody ( res ) { if ( ! this . hasProperty ( res , "centerName" ) && ! this . hasProperty ( res , "emergencyPhone" ) ) { return false ; } else { return true ; } } checkNurseBody ( res ) { if ( this . hasProperty ( res , "nurseId" ) ) { return true ; } else { return false ; } } checkPatientBody ( res ) { if ( this . hasProperty ( res , "phone" ) ) { return true ; } else { return false ; } } checkPatientPutBody ( res ) { if ( this . hasProperty ( res , "phone" ) ) { return true ; } else { return false ; } } checkPatientStatusBody ( res ) { if ( res == null || typeof res !== "object" ) { return false ; } const requiredParams = [ { name : "SpO2" , type : "number" } , { name : "body_temperature" , type : "number" } , { name : "pulse" , type : "number" } , ] ; return this . checkRequestBody ( res , requiredParams ) ; } checkPatientStatusSymptomBody ( res ) { if ( res == null ) { return true ; } if ( res != null && typeof res !== "object" ) { return false ; } const remarks = res . remarks ; if ( remarks != null && typeof remarks !== "string" ) { return false ; } const requiredParams = [ { name : "cough" , type : "boolean" } , { name : "phlegm" , type : "boolean" } , { name : "suffocation" , type : "boolean" } , { name : "headache" , type : "boolean" } , { name : "sore_throat" , type : "boolean" } , { name : "malaise" , type : "boolean" } , { name : "nausea" , type : "boolean" } , { name : "diarrhea" , type : "boolean" } , { name : "difficulty_eating" , type : "boolean" } , { name : "no_urination" , type : "boolean" } , ] ; return this . checkRequestBody ( res , requiredParams ) ; } checkRequestBody ( res , requiredParams ) { for ( let i = 0 ; i < requiredParams . length ; i ++ ) { const name = requiredParams [ i ] . name ; const type = requiredParams [ i ] . type ; if ( res [ name ] != null && typeof res [ name ] === type ) { continue ; } else { return false ; } } return true ; } isNurseAPI ( event ) { if ( ! event . path ) return false ; return ( event . path . startsWith ( "/api/nurse/" ) || event . path . startsWith ( "/stg/api/nurse/" ) || event . path . startsWith ( "/prd/api/nurse/" ) ) ; } isPatientAPI ( event ) { if ( ! event . path ) return false ; return ( event . path . startsWith ( "/api/patient/" ) || event . path . startsWith ( "/stg/api/patient/" ) || event . path . startsWith ( "/prd/api/patient/" ) ) ; } }