fix: Places likes retrocompatibility & entities support#802
Merged
LautaroPetaccio merged 2 commits intomasterfrom Feb 17, 2026
Merged
fix: Places likes retrocompatibility & entities support#802LautaroPetaccio merged 2 commits intomasterfrom
LautaroPetaccio merged 2 commits intomasterfrom
Conversation
Pull Request Test Coverage Report for Build 22105385711Details
💛 - Coveralls |
braianj
approved these changes
Feb 17, 2026
| }) | ||
|
|
||
| if (!world) { | ||
| if (!entity) { |
Collaborator
There was a problem hiding this comment.
Maybe we can also validate if this is a world, WDYT?
Suggested change
| if (!entity) { | |
| if (!entity || !isWorld(entity)) { |
Contributor
Author
There was a problem hiding this comment.
Good catch! I have just changed the code to prevent places from being used in the worlds endpoints.
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.
The
PATCH /places/:entity_id/favoritesendpoint was broken. It accepted anentity_idroute parameter but internally calledgetPlace(ctx), which validated against a different schema requiringplace_idas a UUID. This caused a runtime error:Beyond this immediate bug, the
/places/:entity_id/favoritesand/places/:entity_id/likesendpoints were hardcoded to query onlyPlaceModel, meaning any world ID sent through these endpoints would silently fail with a 404. Older clients rely on these/places/endpoints for both places and worlds, so this broke world favoriting and liking for those clients.Approach
Unified entity lookup via ID format detection
Rather than duplicating place-vs-world branching in every route handler, we introduced
findEntityByIdWithAggregatesinsrc/entities/shared/entityInteractions.ts. This function inspects the entity ID format to decide which model to query:d5c08816-6745-...) are looked up viaPlaceModelmyworld.dcl.eth) are looked up viaWorldModelThis lets any endpoint that receives a generic entity ID resolve it without needing the caller to specify the type upfront.
Updated route handlers to use the shared lookup
The four mutation endpoints now use
findEntityByIdWithAggregatesfor the initial entity fetch:PATCH /places/:entity_id/favorites— was callinggetPlace(ctx), now uses the shared lookup and dispatchesupdateFavoritestoPlaceModelorWorldModelviaisWorld(entity)PATCH /places/:entity_id/likes— was queryingPlaceModeldirectly, same fixPATCH /worlds/:world_id/favorites— was queryingWorldModeldirectly, now uses the shared lookup (still only callsWorldModel.updateFavoritessince this is a world-specific endpoint)PATCH /worlds/:world_id/likes— same as above for likesThe
/places/endpoints have comments explaining why they handle world entities: older clients may send world IDs through these endpoints, and the dedicated/worlds/:world_id/favoritesand/worlds/:world_id/likesendpoints exist for newer clients.Removed UUID-only validation from
/places/schemasThe
entity_idparameter inUserFavorite/schema.tsandUserLikes/schema.tshadformat: "uuid", which rejected world names likemyworld.dcl.ethat the validation layer before the handler even ran. This was removed so both UUIDs and world names pass validation — the actual entity type resolution happens infindEntityByIdWithAggregates.Exported route handlers for testability
updateFavoritesandupdateLikewere private functions. They are now exported, consistent with the world route handlers (updateWorldFavorites,updateWorldLikes) which were already exported.Integration tests
Added 28 integration tests across 4 files in
test/integration/, using supertest against a real Express app backed by a PostgreSQL test database. Only external services (auth, Snapshot score, Slack, hot scenes, scene stats, worlds live data) are mocked — the models execute real SQL.updatePlaceFavorites.test.tsupdatePlaceLikes.test.tsupdateWorldFavorites.test.ts/places/endpointupdateWorldLikes.test.ts/places/endpointThe retro-compatibility tests verify that world IDs sent through the
/places/:entity_id/favoritesand/places/:entity_id/likesendpoints correctly persist to theworldstable — the key behavior this PR preserves.Supporting changes to the test infrastructure:
test/setup/server.ts— mounteduserFavoriteRouteanduserLikesRouteon the test Express apptest/setup/db.ts— addeduser_favoritesanduser_likesto the tables truncated between tests