refactor: convert TeamRepository to use dependency injection pattern (#22383)
* refactor: convert TeamRepository to use dependency injection pattern - Add constructor injection for PrismaClient in TeamRepository - Convert all static methods to instance methods using this.prismaClient - Update all usage sites to use two-step pattern: const teamRepo = new TeamRepository(prisma); teamRepo.method(...) - Optimize instance reuse within same function scopes where possible - Update test files to work with new instance pattern - Preserve all existing functionality and method signatures Follows the same dependency injection pattern as UserRepository refactoring Co-Authored-By: [email protected] <[email protected]> * chore: bump platform libs --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
15 files changed
+85
-55
No files matched your search
@@ -388,10 +388,13 @@ describe("CreditService", () => {
|
||||
|
||||
describe("getMonthlyCredits", () => {
|
||||
it("should return 0 if subscription is not active", async () => {
|
||||
vi.mocked(TeamRepository.findTeamWithMembers).mockResolvedValue({
|
||||
id: 1,
|
||||
members: [{ accepted: true }],
|
||||
} as any);
|
||||
const mockTeamRepo = {
|
||||
findTeamWithMembers: vi.fn().mockResolvedValue({
|
||||
id: 1,
|
||||
members: [{ accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as any);
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue("trialing"),
|
||||
@@ -405,10 +408,13 @@ describe("CreditService", () => {
|
||||
});
|
||||
|
||||
it("should calculate credits based on active members and price", async () => {
|
||||
vi.mocked(TeamRepository.findTeamWithMembers).mockResolvedValue({
|
||||
id: 1,
|
||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
||||
} as any);
|
||||
const mockTeamRepo = {
|
||||
findTeamWithMembers: vi.fn().mockResolvedValue({
|
||||
id: 1,
|
||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as any);
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue("active"),
|
||||
|
||||
@@ -532,7 +532,8 @@ export class CreditService {
|
||||
}
|
||||
|
||||
async getMonthlyCredits(teamId: number) {
|
||||
const team = await TeamRepository.findTeamWithMembers(teamId);
|
||||
const teamRepo = new TeamRepository(prisma);
|
||||
const team = await teamRepo.findTeamWithMembers(teamId);
|
||||
|
||||
if (!team) return 0;
|
||||
|
||||
|
||||
Reference in new issue
Block a user