## What does this PR do? Replaces direct instantiation of `FeaturesRepository` with the dependency-injected version using `getFeaturesRepository()` from the DI container in the feature flags router. **Key improvement:** The DI-ed version uses Redis caching, replacing the previous in-memory 5-minute cache implementation which was not ideal. This follows the established DI pattern in the codebase for loose coupling, better testability, and more robust caching across instances. ## Type of change - [x] Refactor (non-breaking change that improves code quality) ## Mandatory Tasks (DO NOT REMOVE) - [x] I have self-reviewed the code (A decent size PR without self-review might be rejected). - [x] I have updated the developer docs in /docs if this PR makes changes that would require a [documentation change](https://cal.com/docs). N/A - no documentation changes needed. - [x] I confirm automated tests are in place that prove my fix is effective or that my feature works. ## How should this be tested? 1. Verify feature flags functionality works as expected: - Feature flag list endpoint should return all features - Team feature check should work correctly 2. No environment variables needed beyond standard setup ## Checklist - [x] My code follows the style guidelines of this project - [x] I have checked if my changes generate no new warnings ## Human Review Checklist - [ ] Verify `getFeaturesRepository()` returns a properly configured instance from the DI container - [ ] Confirm the DI container properly injects the Prisma client - [ ] Verify Redis caching is working as expected for feature flag data --- **Link to Devin run:** https://app.devin.ai/sessions/2ff6e4551c8649e4b6178b31a2195327 **Requested by:** @eunjae-lee
26 lines
895 B
TypeScript
26 lines
895 B
TypeScript
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
|
|
import type { AppFlags } from "@calcom/features/flags/config";
|
|
import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure";
|
|
import { router } from "@calcom/trpc/server/trpc";
|
|
import { z } from "zod";
|
|
import { map } from "./procedures/map";
|
|
|
|
export const featureFlagRouter = router({
|
|
list: publicProcedure.query(async () => {
|
|
const featuresRepository = getFeaturesRepository();
|
|
return featuresRepository.getAllFeatures();
|
|
}),
|
|
checkTeamFeature: publicProcedure
|
|
.input(
|
|
z.object({
|
|
teamId: z.number(),
|
|
feature: z.string(),
|
|
})
|
|
)
|
|
.query(async ({ input }) => {
|
|
const featuresRepository = getFeaturesRepository();
|
|
return featuresRepository.checkIfTeamHasFeature(input.teamId, input.feature as keyof AppFlags);
|
|
}),
|
|
map,
|
|
});
|