Skip to content

Commit

Permalink
make it possible to set and update a warp group to a warp
Browse files Browse the repository at this point in the history
  • Loading branch information
MineFact committed Jan 24, 2024
1 parent 023797d commit 2461dbe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/routes/teams/POST_Warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) {
const schema = joi.object({
id: joi.string().optional(),
name: joi.string().required(),
warpgroup: joi.string().optional(),
countryCode: joi.string().required(),
countryCodeType: joi.string().required().valid('cca2', 'cca3', 'ccn3', 'cioc'),
subRegion: joi.string().required(),
Expand All @@ -46,6 +47,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) {

// Get the parameters from the request
const id = req.body.id; // The id of the warp.
const warpGroupID = req.body.warpGroupID // The id of the warp group.
const name = req.body.name; // The name of the warp.
const countryCode = req.body.countryCode; // Country Code that matches the countryCodeType.
const countryCodeType = req.body.countryCodeType; // Country Code Type like cca2, cca3, ccn3, or cioc.
Expand All @@ -63,7 +65,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) {


// Create a new warp
const promise = buildTeam.createWarp(id, name, countryCode, countryCodeType, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);
const promise = buildTeam.createWarp(id, warpGroupID, name, countryCode, countryCodeType, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);


// Wait for the promise to resolve
Expand Down
6 changes: 5 additions & 1 deletion src/routes/teams/PUT_Warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) {
// Validate the parameters with joi
const schema = joi.object({
id: joi.string().required(),
warpGroupID: joi.string().optional(),

name: joi.string().optional(),
countryCode: joi.string().optional(),
Expand Down Expand Up @@ -56,6 +57,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) {

// Get the parameters from the request
let id = warp.ID; // The ID of the warp.
let warpGroupID = warp.WarpGroupID; // The ID of the warp group.
let name = warp.Name; // The name of the warp.
let countryCode = warp.CountryCode; // Country Code that matches the countryCodeType.
let countryCodeType = "cca3"; // Country Code Type like cca2, cca3, ccn3, or cioc.
Expand All @@ -75,6 +77,8 @@ export async function initRoutes(app: Router, joi: any, network: Network) {
// If the parameter was specified, set it
if(req.body.id != null)
id = req.body.id;
if(req.body.warpGroupID != null)
warpGroupID = req.body.warpGroupID;
if(req.body.name != null)
name = req.body.name;
if(req.body.countryCode != null)
Expand Down Expand Up @@ -102,7 +106,7 @@ export async function initRoutes(app: Router, joi: any, network: Network) {


// Update the warp
const promise = buildTeam.updateWarp(id, name, countryCode, countryCodeType, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);
const promise = buildTeam.updateWarp(id, warpGroupID, name, countryCode, countryCodeType, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);


// Wait for the promise to resolve
Expand Down
22 changes: 12 additions & 10 deletions src/struct/core/buildteam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export default class BuildTeam {
/** Creates a new warp for the build team.
*
* @param id The ID of the warp
* @param warpGroupID The id of the warp group
* @param name The name of the warp
* @param countryCode Country Code that matches the countryCodeType
* @param countryCodeType Country Code Type like cca2, cca3, ccn3, or cioc
Expand All @@ -227,7 +228,7 @@ export default class BuildTeam {
*
* @returns Returns true if the warp was created successfully, otherwise false.
**/
async createWarp(id: string|null, name: string, countryCode: string, countryCodeType: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, y: number, yaw: number, pitch: number, isHighlight: boolean) {
async createWarp(id: string|null, warpGroupID: string, name: string, countryCode: string, countryCodeType: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, y: number, yaw: number, pitch: number, isHighlight: boolean) {
// Generate a new uuid if the id is null
if(id == null)
id = uuidv4();
Expand Down Expand Up @@ -266,13 +267,14 @@ export default class BuildTeam {
return false;
}

return await this.createWarpInDatabase(id, this.buildTeamID, name, finalCountryCode, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);
return await this.createWarpInDatabase(id, this.buildTeamID, warpGroupID, name, finalCountryCode, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);
}


/** Updates an existing warp of the build team.
*
* @param ID The new ID of the warp
* @param warpGroupID The new id of the warp group
* @param name The new name of the warp
* @param countryCode The new Country Code that matches the countryCodeType
* @param countryCodeType Country Code Type like cca2, cca3, ccn3, or cioc
Expand All @@ -288,7 +290,7 @@ export default class BuildTeam {
*
* @returns Returns true if the warp was created successfully, otherwise false.
**/
async updateWarp(ID: string, name: string, countryCode: string, countryCodeType: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, y: number, yaw: number, pitch: number, isHighlight: boolean) {
async updateWarp(ID: string, warpGroupID: string, name: string, countryCode: string, countryCodeType: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, y: number, yaw: number, pitch: number, isHighlight: boolean) {
// Validate that the build team id is loaded
if(this.buildTeamID == null)
await this.loadBuildTeamData();
Expand Down Expand Up @@ -328,7 +330,7 @@ export default class BuildTeam {
return false;
}

return await this.updateWarpInDatabase(ID, this.buildTeamID, name, finalCountryCode, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);
return await this.updateWarpInDatabase(ID, this.buildTeamID, warpGroupID, name, finalCountryCode, subRegion, city, worldName, lat, lon, y, yaw, pitch, isHighlight);
}


Expand Down Expand Up @@ -751,10 +753,10 @@ export default class BuildTeam {
return false;
}

private async createWarpInDatabase(ID: string, buildTeamID: string, name: string, countryCode: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, height: number, yaw: number, pitch: number, isHighlight: boolean) {
const SQL = "INSERT INTO BuildTeamWarps (ID, BuildTeam, Name, CountryCode, SubRegion, City, WorldName, Latitude, Longitude, Height, Yaw, Pitch, IsHighlight) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private async createWarpInDatabase(ID: string, buildTeamID: string, warpGroupID: string, name: string, countryCode: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, height: number, yaw: number, pitch: number, isHighlight: boolean) {
const SQL = "INSERT INTO BuildTeamWarps (ID, BuildTeam, WarpGroup, Name, CountryCode, SubRegion, City, WorldName, Latitude, Longitude, Height, Yaw, Pitch, IsHighlight) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

const result = await this.nwDatabase.query(SQL, [ID, buildTeamID, name, countryCode, subRegion, city, worldName, lat, lon, height, yaw, pitch, isHighlight]);
const result = await this.nwDatabase.query(SQL, [ID, buildTeamID, warpGroupID, name, countryCode, subRegion, city, worldName, lat, lon, height, yaw, pitch, isHighlight]);

if(result.affectedRows == 1)
return true;
Expand Down Expand Up @@ -790,10 +792,10 @@ export default class BuildTeam {
}

// Updates an existing warp in the database
private async updateWarpInDatabase(ID: string, buildTeamID: string, name: string, countryCode: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, height: number, yaw: number, pitch: number, isHighlight: boolean) {
const SQL = "UPDATE BuildTeamWarps SET ID = ?, BuildTeam = ?, Name = ?, CountryCode = ?, SubRegion = ?, City = ?, WorldName = ?, Latitude = ?, Longitude = ?, Height = ?, Yaw = ?, Pitch = ?, IsHighlight = ? WHERE ID = ? AND BuildTeam = ?";
private async updateWarpInDatabase(ID: string, buildTeamID: string, warpGroupID: string, name: string, countryCode: string, subRegion: string, city: string, worldName: string, lat: number, lon: number, height: number, yaw: number, pitch: number, isHighlight: boolean) {
const SQL = "UPDATE BuildTeamWarps SET ID = ?, BuildTeam = ?, WarpGroup = ?, Name = ?, CountryCode = ?, SubRegion = ?, City = ?, WorldName = ?, Latitude = ?, Longitude = ?, Height = ?, Yaw = ?, Pitch = ?, IsHighlight = ? WHERE ID = ? AND BuildTeam = ?";

const result = await this.nwDatabase.query(SQL, [ID, buildTeamID, name, countryCode, subRegion, city, worldName, lat, lon, height, yaw, pitch, isHighlight, ID, buildTeamID]);
const result = await this.nwDatabase.query(SQL, [ID, buildTeamID, warpGroupID, name, countryCode, subRegion, city, worldName, lat, lon, height, yaw, pitch, isHighlight, ID, buildTeamID]);

if(result.affectedRows == 1)
return true;
Expand Down
11 changes: 10 additions & 1 deletion swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@
"schema": {
"type": "object",
"properties": {
"warpGroupID": {
"type": "string",
"description": "The ID of the warp group."
},
"name": {
"type": "string",
"description": "The name of the warp."
Expand Down Expand Up @@ -774,7 +778,7 @@
},
"example": [
{
"id": "cf0d3acb-e3df-4cdf-9960-d5e90aadf165",
"warpGroupID": "b80196c1-7754-428c-808c-0bcde821e4ed",
"name": "My Test Warp",
"countryCode": "276",
"countryCodeType": "ccn3",
Expand Down Expand Up @@ -826,6 +830,11 @@
"description": "The ID of the warp.",
"required": true
},
"warpGroupID": {
"type": "string",
"description": "The ID of the warp group.",
"required": false
},
"name": {
"type": "string",
"description": "The name of the warp.",
Expand Down

0 comments on commit 2461dbe

Please sign in to comment.