From db8cb5be77b2b970685892344bf1860e3fe86fc6 Mon Sep 17 00:00:00 2001 From: MineFact Date: Fri, 2 Feb 2024 06:51:55 -0600 Subject: [PATCH] fix undefined error --- src/routes/teams/POST_Warp.ts | 7 ++++++- src/routes/teams/PUT_Warp.ts | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/routes/teams/POST_Warp.ts b/src/routes/teams/POST_Warp.ts index 5fc110e..65db454 100644 --- a/src/routes/teams/POST_Warp.ts +++ b/src/routes/teams/POST_Warp.ts @@ -54,7 +54,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) { const countryCodeType = req.body.countryCodeType; // Country Code Type like cca2, cca3, ccn3, or cioc. const address = req.body.address; // The address of the warp. const addressType: AddressType = convertStringToAddressType(req.body.addressType); // The type of address. (BUILDING, STREET, CITY, STATE, COUNTRY, CUSTOM) - const material = req.body.material; // The material of the warp. + let material = req.body.material; // The material of the warp. const worldName = req.body.worldName; // The name of the world the warp is in. const lat = req.body.lat; // The latitude of the warp. @@ -66,11 +66,16 @@ export async function initRoutes(app: Router, joi: any, network: Network) { const isHighlight = req.body.isHighlight; // Whether the warp is a highlight or not. + // If the addressType is CUSTOM and the address is not specified, return an error if(addressType == AddressType.CUSTOM && address == null){ res.status(400).send({success: false, error: 'Address must be specified when addressType is CUSTOM'}); return; } + // If the material is not specified, set it to null + if(material == undefined) + material = null; + // Create a new warp const promise = buildTeam.createWarp(id, warpGroupID, name, countryCode, countryCodeType, address, addressType, material, worldName, lat, lon, y, yaw, pitch, isHighlight); diff --git a/src/routes/teams/PUT_Warp.ts b/src/routes/teams/PUT_Warp.ts index 90bd1d8..f6b1a62 100644 --- a/src/routes/teams/PUT_Warp.ts +++ b/src/routes/teams/PUT_Warp.ts @@ -112,6 +112,9 @@ export async function initRoutes(app: Router, joi: any, network: Network) { return; } + if(material == undefined) + material = null; + // Update the warp const promise = buildTeam.updateWarp(id, warpGroupID, name, countryCode, countryCodeType, address, addressType, material, worldName, lat, lon, y, yaw, pitch, isHighlight);