forked from tf2pickup-org/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: update Game model to use team names (tf2pickup-org#434)
* update Game model to use team names * refactor pickTeams() * add migration Use 'blu' and 'red' to identify teams in the GameModel. Makes the 'teams' field obsolete. BREAKING CHANGE: Game.teams is now gone, GamePlayer.teamId is moved to GamePlayer.team
- Loading branch information
1 parent
8448a0a
commit 3fae9ca
Showing
22 changed files
with
616 additions
and
407 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"lastRun": "1592050029364-use-tf2-team-names.js", | ||
"migrations": [ | ||
{ | ||
"title": "1592050029364-use-tf2-team-names.js", | ||
"timestamp": 1592050148283 | ||
} | ||
] | ||
} |
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,37 @@ | ||
'use strict' | ||
|
||
const mongodb = require('mongodb'); | ||
require('dotenv').config(); | ||
|
||
let credentials = ''; | ||
if (process.env.MONGODB_USERNAME) { | ||
if (process.env.MONGODB_PASSWORD) { | ||
credentials = `${process.env.MONGODB_USERNAME}:${process.env.MONGODB_PASSWORD}@`; | ||
} else { | ||
credentials = `${process.env.MONGODB_USERNAME}@`; | ||
} | ||
} | ||
|
||
const uri = `mongodb://${credentials}${process.env.MONGODB_HOST}:${process.env.MONGODB_PORT}/${process.env.MONGODB_DB}`; | ||
|
||
module.exports.up = function (next) { | ||
mongodb.MongoClient.connect(uri, { useUnifiedTopology: true }) | ||
.then(client => client.db()) | ||
.then(db => { | ||
const Games = db.collection('games'); | ||
return Games.find().forEach(game => { | ||
game.slots.forEach(slot => { | ||
if (!slot.team) { | ||
slot.team = game.teams[slot.teamId].toLowerCase(); | ||
} | ||
}); | ||
|
||
return Games.save(game); | ||
}); | ||
}) | ||
.then(next); | ||
} | ||
|
||
module.exports.down = next => { | ||
next() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,4 @@ | ||
export enum Tf2Team { | ||
Red = 'red', | ||
Blu = 'blu', | ||
}; |
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
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
Oops, something went wrong.