I have a REST endpoint hosted in Azure Functions. When someone calls that endpoint, I handle the incoming request like this:
// Construct
const requestBody: RequestBody = new RequestBody(req.body)
// Class
export class RequestBody {
private _packages: IPackage[]
constructor(object: any) {
this._packages = object.packages
}
get packages(): IPackage[] {
return this._packages
}
}
// IPackage interface
export interface IPackage {
packageId: string
shipmentId: string
dimensions: IDimension
}
Where req.body is received from the trigger of an Azure Function (source if is relevant)
When receiving the message and constructing the object, what is a pattern that allows me to verify that all properties in the IPackage interface are present? The entire list needs to have all properties defined in the interface.