-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add route hasBuildTeamToolsInstalled
- Loading branch information
Showing
5 changed files
with
212 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Router } from "express"; | ||
import Network from "../../struct/core/network.js"; | ||
|
||
export async function initRoutes(app: Router, joi: any, network: Network) { | ||
|
||
app.get('/api/teams/:key/hasBuildTeamToolsInstalled', async function (req, res) { | ||
|
||
// Validate that the Key is a valid API Key or Build Team ID or Build Team Tag or BuildTeam Server ID | ||
const type = await network.validateKey(req, res) | ||
if(type == null) | ||
return; | ||
|
||
const buildTeam = await network.getBuildTeam(req.params.key, type); | ||
|
||
if(buildTeam == null) { | ||
res.status(400).send({ error: 'Build Team not found' }); | ||
return; | ||
} | ||
|
||
const value = await buildTeam.getBuildTeamInfo("hasBuildTeamToolsInstalled"); | ||
|
||
if(value == null) { | ||
res.status(400).send({ error: 'HasBuildTeamToolsInstalled variable for this Build Team not found' }); | ||
return; | ||
} | ||
|
||
res.setHeader('Content-Type', 'application/json'); | ||
res.send(JSON.stringify({hasBuildTeamToolsInstalled : value})) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Router } from "express"; | ||
import Network, { BuildTeamIdentifier } from "../../struct/core/network.js"; | ||
|
||
export async function initRoutes(app: Router, joi: any, network: Network) { | ||
|
||
app.put('/api/teams/:apikey/hasBuildTeamToolsInstalled', async function (req, res) { | ||
|
||
// Validate that the API key is a valid GUID | ||
if(!network.validateAPIKey(req, res)) | ||
return; | ||
|
||
const buildTeam = await network.getBuildTeam(req.params.apikey, BuildTeamIdentifier.APIKey); | ||
|
||
if(buildTeam == null) { | ||
res.status(400).send({ error: 'Build Team not found' }); | ||
return; | ||
} | ||
|
||
// Validate the parameters with joi | ||
const schema = joi.object({ | ||
hasBuildTeamToolsInstalled: joi.boolean().required() | ||
}); | ||
|
||
const validation = schema.validate(req.body); | ||
|
||
// If the validation failed, return an error | ||
if(validation.error != null){ | ||
res.status(400).send({success: false, error: validation.error.details[0].message}); | ||
return; | ||
} | ||
|
||
// Get the current warp | ||
const warps = await buildTeam.getWarps(); | ||
const warp = warps.find((warp: any) => warp.ID == req.body.ID); | ||
|
||
// If the warp was not found, return an error | ||
if(warp == null){ | ||
res.status(400).send({success: false, error: 'Warp not found in this team.'}); | ||
return; | ||
} | ||
|
||
// Get the parameters from the request | ||
let hasBuildTeamToolsInstalled = req.body.hasBuildTeamToolsInstalled; // The new value of the variable hasBuildTeamToolsInstalled | ||
|
||
// Update the variable | ||
const promise = buildTeam.setHasBuildTeamToolsInstalled(hasBuildTeamToolsInstalled); | ||
|
||
|
||
// Wait for the promise to resolve | ||
promise.then((success) => { | ||
// If the variable was not updated, return an error | ||
if(!success){ | ||
res.status(400).send({success: false, error: 'An error occurred while updating the variable hasBuildTeamToolsInstalled'}); | ||
return; | ||
} | ||
|
||
// Return the success message to the client | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.send({success: true}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters