Conversation
|
Instead of having a UUID generated for a seek/game on the playtak server it'd be more robust to set that I'd to the PNT game id (think about multiple seeks created for a single PNT game. Only if the last one is accepted does my current implementation work) Edit: Done in ae552cc |
So have a concern on this one is it going to effect the game id when it get's saved to the games.db? |
Currently my changes to the playtak-server don't affect what's saved to the DB (no extra column added, none altered). It works like this: When creating the seek, you pass in the PNT Game Id ( We could consider adding the PNT Game Id to the playtak-server games table to more easily link from a PlaytakServer Game to a PNT Game, but I don't think that's necessary - we could just add an index on the |
…er for currently existing seeks
…n the playtak server for the referenced gameId
… nestjs ValidationPipeline
…Notifications functional and configurable
|
|
||
| async getSeeks(): Promise<Array<SeekDto>> { | ||
|
|
||
| const response = await this.httpService.axiosRef.get<Array<SeekDto>>( |
There was a problem hiding this comment.
personally I prefer the try catch over the old school .catch I think it's cleaner but I'm not pushing a change maybe just considering consistency across the project
|
@nitzel per your tag This is very GraphQLesk, should be possible with transactions is probably how I'd do it or would need to build a custom sql query and do a nested few joins (I'd have to play with some data to write the query out). My only thought on this is you would have to know both the tournament id and stage id in order to pass in to the the groups and where would those come from? |
Thanks for your insight. I guess for now it's probably best to just keep it as it is: flat. |
Goal
This PR is meant to give us a good start in interfacing with the playtak-server's new Seek-API and GameUpdate-Notifications (see USTakAssociation/tak-server#2) to get started on running tournaments natively on playtak.com
An initial rough idea of how the database tables and entities could look like was written down here.
An essential part of this PR are the database entities that will make up a tournament. They're not quite complete yet though.
The other essential part is, that
Seekscan now be created through the playtak-api for tournamentGames in the database, taking into account theGameRulesconfigured in the database as well and the names of the players facing each other (seeMatchup). Also, the correspondingGameis updated by the playtak-api when the playtak-server notifies it aboutgame.startedorgame.endedevents.Please have a look at the Example Workflow at the bottom for a better explanation.
Todo
v1/groupsI'd prefer to query them with e.g.v1/tournaments/:tournamentId/:stageId/groupsand it would only return the groups related to:stageIdin:tournamentIdStageGroupTournament(GET allandGET by idare implemented, but there's nothing to create/edit)resultandplaytak_id, ...)/tournaments/game/updateto send game updateslogger.log("hello", obj)Prerequisites
properties.xmlconfiguring<event-subscriber-url>tohttp://localhost:3004/v1/tournaments/game/update(depending on the playtak-api's port).envsetPLAYTAK_API_URL=http://127.0.0.1:9998(or whatever port the playtak server's HTTP server runs on)API Overview
(May be out of date)
Workflow Example
This is not quite up to date, because as of recently one needs to specify the parents of an inserted entity by their ID (e.g. to insert a matchup, you need to pass in the group's id as well. I haven't managed to update the examples yet. Nor have I actually tested the entire workflow (create tournament, rules, stages, groups, matchups, games, seeks) again yet).
To follow along, consider using this Postman configurationplaytak-api.postman_collection.json.txt (github doesn't allow
.jsonfiles, so you may need to change the file extension)Create a GameRules entity
PUT http://localhost:3004/v1/tournaments/game-rules{ "name": "6s 15+10", "timeContingent": 900, "timeIncrement": 10, "extraTimeTriggerMove": 0, "extraTimeAmount": 0, "komi": 2, "boardSize": 6, "capstones": 1, "pieces": 30 }Create a Matchup
PUT http://localhost:3004/v1/tournaments/matchups{ "player1": "nitzel2", "player2": "kvothe", "group": 1 // groups not supported yet, choose any number }Create a Game in the Matchup with the GameRules
PUT http://localhost:3004/v1/tournaments/game{ "player1goesFirst": false, // if true, matchup.player1 is white, else it's matchup.player2 "matchup": 1, // use the id that was returned by the create-matchup endpoint "rules": 1 // use the id that was returned by the create-game-rules endpoint }Get a list of all tournament Games
GET http://localhost:3004/v1/tournaments/game[ { "id": 5, "player1goesFirst": true, "playtakId": null, "result": null }, // ... ]Create a seek on the playtak server for one of the games listed above
Make sure that your
player1is logged in - otherwise this fails.Here I chose to do it for the game with
id=5PUT http://localhost:3004/v1/tournaments/seeks/5Internally this passes on the PNT Game's
idaspntIdfor later reference. The seek is created and can be joined:Join, play and finish the game
Once the game has been joined by the opponent, the
game.playtakIdis set. Once it is over, the result is set as well:{ "id": 5, "player1goesFirst": true, "playtakId": 9, "result": "0-1" },The logs of the playtak-api during this last step were:
Side effects
class-validator,class-transformerforValidationPipeline@nestjs/axiosto send http requests to the playtak-servertypeorm.synchronize = Trueifenv.NODE_ENV == 'local'so that one can just amend the entities without having to worry about updating the table's columns manually. This must not be enabled in production, as mistakes can easily drop columns completely.>=debugis logged (so justverboseis excluded), otherwise onlyerror, warning, logare logged andverbose,debugare omitted.