Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief description
This PR implements the requirements for tracking player class and character statistics, along with automated "Favorite" calculation. It also aligns the
Playermodel with updated profile requirements (Carbon Footprint, Playstyle, and Clan Coins).The core of this change moves the Service layer from returning raw Mongoose documents to sanitized plain objects. This ensures that calculated virtual fields (like
favouriteClass) are stable and not stripped during a "DTO transformation".Change list
Database & Schema (
Player.schema.ts):classStatisticsandcharacterStatisticsas Mongoose Maps to trackgamesPlayedandwins.carbonFootprint(Number),playstyle(String), andclanCoinsAccumulated(Number) fields.@Schemadecorators (NestJS stuff) to ensure virtuals and getters are included during transformation.Data Transfer Objects (
Player.dto.ts,CreatePlayer.dto.ts):CreatePlayerDtoto preventValidationPipefrom stripping incoming data.favouriteClassandfavouriteCharacterfields toPlayerDtoto expose calculated results to the client.Service Logic (
Player.service.ts)Implemented
getFavourite()helper using a "Highest Games Played" algorithm.Refactored
getPlayerByIdto convert documents to plain objects via.toObject()before injecting.Ensured data integrity by validating map existence before calculation to prevent
undefinederrors.Test Suite Alignment (
src/__tests__/...)Updated Contract: Modified existing tests (notably
getPlayerById.test.ts) to expect plain JavaScript objects instead of Mongoose documents.Removed
.toObject()calls: Since the Service now returns a plain object, internal test calls to.toObject()were removed to prevent TypeErrors.Drift Protection: Adjusted timestamp expectations to handle the millisecond drift between local execution and database persistence.
Why the Tests were Updated
The tests were updated because the "Service Contract" itself had to change. To support the dynamic calculation of favorites, the service now performs the transformation to a plain object internally. This makes the API more robust for the frontend but required the test suite to stop treating the returned data as a Mongoose Document instance.