Refactor research audience handling and validation

AH
4mo ago
+198-22
  • Updated getResearchAudienceHandler to use the new validateGetResearchAudienceRequest for request validation.
  • Introduced researchAudiencePlatforms.ts to define supported audience platforms.
  • Added validateGetResearchAudienceRequest to validate incoming requests for the audience endpoint, ensuring proper platform handling and defaults.
  • Created tests for validateGetResearchAudienceRequest to cover various scenarios including platform validation and defaults.
  • Refactored mapArtistAudienceSource to utilize the new platform definitions.

These changes enhance the clarity and maintainability of the audience research functionality.


Summary by cubic

Centralized audience platform handling and validation. Defaults platform to instagram, rejects invalid values, and hardens mapping against prototype keys.

  • Refactors
    • Added researchAudiencePlatforms.ts mapping allowed platforms to SongStats sources.
    • Introduced validateGetResearchAudienceRequest to validate auth/artist and platform; defaults to instagram and returns 400 on invalid input.
    • Updated getResearchAudienceHandler to use the new validator and validated.platform in the SongStats path.
    • Updated mapArtistAudienceSource to use the shared enum and Object.hasOwn to avoid prototype keys; added tests for known/unknown platforms and prototype handling.

Summary by CodeRabbit

  • Refactor
    • Centralized platform validation for research audience queries with enhanced error messaging for unsupported platforms.